Additional vector elements

This commit is contained in:
Jack Andersen 2016-02-06 21:25:34 -10:00
parent 7ae8d21c55
commit 8dbd2f3819
6 changed files with 107 additions and 46 deletions

View File

@ -89,6 +89,10 @@ public:
x3_loading = false;
return x10_object;
}
const SObjectTag& GetObjectTag() const
{
return x4_objTag;
}
~CObjectReference()
{
if (x10_object)
@ -103,6 +107,7 @@ class CToken
CObjectReference* x0_objRef = nullptr;
bool x4_lockHeld = false;
public:
operator bool() const {return x0_objRef != nullptr;}
void Unlock()
{
if (x0_objRef && x4_lockHeld)
@ -157,7 +162,7 @@ public:
other.x4_lockHeld = false;
return *this;
}
CToken() {}
CToken() = default;
CToken(const CToken& other)
: x0_objRef(other.x0_objRef)
{
@ -180,6 +185,12 @@ public:
x0_objRef = obj;
++x0_objRef->x0_refCount;
}
const SObjectTag* GetObjectTag() const
{
if (!x0_objRef)
return nullptr;
return &x0_objRef->GetObjectTag();
}
~CToken()
{
if (x0_objRef)
@ -199,7 +210,7 @@ public:
{
return TObjOwnerDerivedFromIObj<T>::GetNewDerivedObject(std::move(obj));
}
TToken() {}
TToken() = default;
TToken(const CToken& other) : CToken(other) {}
TToken(T* obj)
: CToken(GetIObjObjectFor(std::unique_ptr<T>(obj))) {}

View File

@ -37,25 +37,25 @@ SParticleModel CParticleDataFactory::GetModel(CInputStream& in, CSimplePool* res
FourCC clsId = GetClassID(in);
if (clsId == SBIG('NONE'))
return {};
TResID id = in.readUint32Big();
TResId id = in.readUint32Big();
if (!id)
return {};
return {resPool->GetObj({FOURCC('CMDL'), id}), true};
}
SChildGeneratorDesc CParticleDataFactory::GetChildGeneratorDesc(TResID res, CSimplePool* resPool, const std::vector<TResID>& tracker)
SChildGeneratorDesc CParticleDataFactory::GetChildGeneratorDesc(TResId res, CSimplePool* resPool, const std::vector<TResId>& tracker)
{
if (std::count(tracker.cbegin(), tracker.cend(), res) == 0)
return {resPool->GetObj({FOURCC('PART'), res}), true};
return {};
}
SChildGeneratorDesc CParticleDataFactory::GetChildGeneratorDesc(CInputStream& in, CSimplePool* resPool, const std::vector<TResID>& tracker)
SChildGeneratorDesc CParticleDataFactory::GetChildGeneratorDesc(CInputStream& in, CSimplePool* resPool, const std::vector<TResId>& tracker)
{
FourCC clsId = GetClassID(in);
if (clsId == SBIG('NONE'))
return {};
TResID id = in.readUint32Big();
TResId id = in.readUint32Big();
if (!id)
return {};
return GetChildGeneratorDesc(id, resPool, tracker);
@ -66,7 +66,7 @@ SSwooshGeneratorDesc CParticleDataFactory::GetSwooshGeneratorDesc(CInputStream&
FourCC clsId = GetClassID(in);
if (clsId == SBIG('NONE'))
return {};
TResID id = in.readUint32Big();
TResId id = in.readUint32Big();
if (!id)
return {};
return {resPool->GetObj({FOURCC('SWHC'), id}), true};
@ -77,7 +77,7 @@ SElectricGeneratorDesc CParticleDataFactory::GetElectricGeneratorDesc(CInputStre
FourCC clsId = GetClassID(in);
if (clsId == SBIG('NONE'))
return {};
TResID id = in.readUint32Big();
TResId id = in.readUint32Big();
if (!id)
return {};
return {resPool->GetObj({FOURCC('ELSC'), id}), true};
@ -93,7 +93,7 @@ CUVElement* CParticleDataFactory::GetTextureElement(CInputStream& in, CSimplePoo
FourCC subId = GetClassID(in);
if (subId == SBIG('NONE'))
return nullptr;
TResID id = in.readUint32Big();
TResId id = in.readUint32Big();
TToken<CTexture> txtr = resPool->GetObj({FOURCC('TXTR'), id});
return new CUVEConstant(std::move(txtr));
}
@ -102,7 +102,7 @@ CUVElement* CParticleDataFactory::GetTextureElement(CInputStream& in, CSimplePoo
FourCC subId = GetClassID(in);
if (subId == SBIG('NONE'))
return nullptr;
TResID id = in.readUint32Big();
TResId id = in.readUint32Big();
CIntElement* a = GetIntElement(in);
CIntElement* b = GetIntElement(in);
CIntElement* c = GetIntElement(in);
@ -762,13 +762,13 @@ CIntElement* CParticleDataFactory::GetIntElement(CInputStream& in)
CGenDescription* CParticleDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool)
{
std::vector<TResID> tracker;
std::vector<TResId> tracker;
tracker.reserve(8);
return CreateGeneratorDescription(in, tracker, 0, resPool);
}
CGenDescription* CParticleDataFactory::CreateGeneratorDescription(CInputStream& in, std::vector<TResID>& tracker,
TResID resId, CSimplePool* resPool)
CGenDescription* CParticleDataFactory::CreateGeneratorDescription(CInputStream& in, std::vector<TResId>& tracker,
TResId resId, CSimplePool* resPool)
{
if (std::count(tracker.cbegin(), tracker.cend(), resId) == 0)
{
@ -786,7 +786,7 @@ CGenDescription* CParticleDataFactory::CreateGeneratorDescription(CInputStream&
}
bool CParticleDataFactory::CreateGPSM(CGenDescription* fillDesc, CInputStream& in,
std::vector<TResID>& tracker, CSimplePool* resPool)
std::vector<TResId>& tracker, CSimplePool* resPool)
{
FourCC clsId = GetClassID(in);
while (clsId != SBIG('_END'))

View File

@ -49,8 +49,8 @@ struct SElectricGeneratorDesc
class CParticleDataFactory
{
static SParticleModel GetModel(CInputStream& in, CSimplePool* resPool);
static SChildGeneratorDesc GetChildGeneratorDesc(TResID res, CSimplePool* resPool, const std::vector<TResID>& tracker);
static SChildGeneratorDesc GetChildGeneratorDesc(CInputStream& in, CSimplePool* resPool, const std::vector<TResID>& tracker);
static SChildGeneratorDesc GetChildGeneratorDesc(TResId res, CSimplePool* resPool, const std::vector<TResId>& tracker);
static SChildGeneratorDesc GetChildGeneratorDesc(CInputStream& in, CSimplePool* resPool, const std::vector<TResId>& tracker);
static SSwooshGeneratorDesc GetSwooshGeneratorDesc(CInputStream& in, CSimplePool* resPool);
static SElectricGeneratorDesc GetElectricGeneratorDesc(CInputStream& in, CSimplePool* resPool);
static CUVElement* GetTextureElement(CInputStream& in, CSimplePool* resPool);
@ -68,10 +68,10 @@ class CParticleDataFactory
public:
static CGenDescription* GetGeneratorDesc(CInputStream& in, CSimplePool* resPool);
static CGenDescription* CreateGeneratorDescription(CInputStream& in, std::vector<TResID>& tracker,
TResID resId, CSimplePool* resPool);
static CGenDescription* CreateGeneratorDescription(CInputStream& in, std::vector<TResId>& tracker,
TResId resId, CSimplePool* resPool);
static bool CreateGPSM(CGenDescription* fillDesc, CInputStream& in,
std::vector<TResID>& tracker, CSimplePool* resPool);
std::vector<TResId>& tracker, CSimplePool* resPool);
static void LoadGPSMTokens(CGenDescription* desc);
};

View File

@ -58,34 +58,84 @@ bool CVEKeyframeEmitter::GetValue(int frame, Zeus::CVector3f& valOut) const
}
CVECone::CVECone(CVectorElement* a, CRealElement* b)
: x4_a(a), x8_b(b)
: x4_direction(a), x8_magnitude(b)
{
Zeus::CVector3f av;
x4_a->GetValue(0, av);
x4_direction->GetValue(0, av);
Zeus::CVector3f avNorm = av.normalized();
if (avNorm[0] > 0.8)
xc_vec1 = av.cross(Zeus::CVector3f(0.f, 1.f, 0.f));
xc_xVec = avNorm.cross(Zeus::CVector3f(0.f, 1.f, 0.f));
else
xc_vec1 = av.cross(Zeus::CVector3f(1.f, 0.f, 0.f));
x18_vec2 = avNorm.cross(xc_vec1);
xc_xVec = avNorm.cross(Zeus::CVector3f(1.f, 0.f, 0.f));
x18_yVec = avNorm.cross(xc_xVec);
}
bool CVECone::GetValue(int frame, Zeus::CVector3f& valOut) const
{
float b;
x8_b->GetValue(frame, b);
Zeus::CVector3f av;
x4_a->GetValue(0, av);
x8_magnitude->GetValue(frame, b);
Zeus::CVector3f dir;
x4_direction->GetValue(frame, dir);
float b2 = std::min(1.f, b);
while (true)
float randX, randY;
do
{
float rand = CRandom16::GetRandomNumber()->Float() - 0.5f;
float c = 2.f * b2 * rand;
float rand1 = CRandom16::GetRandomNumber()->Float() - 0.5f;
randX = 2.f * b2 * rand1;
float rand2 = CRandom16::GetRandomNumber()->Float() - 0.5f;
randY = 2.f * b2 * rand2;
} while (randX * randX + randY * randY > 1.f);
valOut = xc_xVec * randX + x18_yVec * randY + dir;
return false;
}
c = c * c;
bool CVETimeChain::GetValue(int frame, Zeus::CVector3f& valOut) const
{
int v;
xc_swFrame->GetValue(frame, v);
if (frame >= v)
return x8_b->GetValue(frame, valOut);
else
return x4_a->GetValue(frame, valOut);
}
}
bool CVEAngleCone::GetValue(int frame, Zeus::CVector3f& valOut) const
{
float xc, yc, xr, yr;
x4_angleXConstant->GetValue(frame, xc);
x8_angleYConstant->GetValue(frame, yc);
xc_angleXRange->GetValue(frame, xr);
x10_angleYRange->GetValue(frame, yr);
float xtmp = CRandom16::GetRandomNumber()->Float() * xr;
float xang = (0.5f * xr - xtmp + xc) * M_PI / 180.f;
float ytmp = CRandom16::GetRandomNumber()->Float() * yr;
float yang = (0.5f * yr - ytmp + yc) * M_PI / 180.f;
float mag;
x14_magnitude->GetValue(frame, mag);
/* This takes a +Z vector and rotates it around X and Y axis (like a rotation matrix would) */
valOut = Zeus::CVector3f(cosf(xang) * -sinf(yang), sinf(xang), cosf(xang) * cosf(yang)) * Zeus::CVector3f(mag);
return false;
}
bool CVEAdd::GetValue(int frame, Zeus::CVector3f& valOut) const
{
Zeus::CVector3f a, b;
x4_a->GetValue(frame, a);
x8_b->GetValue(frame, b);
valOut = a + b;
return false;
}
bool CVECircleCluster::GetValue(int frame, Zeus::CVector3f& valOut) const
{
return false;
}
bool CVEMultiply::GetValue(int frame, Zeus::CVector3f& valOut) const

View File

@ -22,10 +22,10 @@ public:
class CVECone : public CVectorElement
{
std::unique_ptr<CVectorElement> x4_a;
std::unique_ptr<CRealElement> x8_b;
Zeus::CVector3f xc_vec1;
Zeus::CVector3f x18_vec2;
std::unique_ptr<CVectorElement> x4_direction;
std::unique_ptr<CRealElement> x8_magnitude;
Zeus::CVector3f xc_xVec;
Zeus::CVector3f x18_yVec;
public:
CVECone(CVectorElement* a, CRealElement* b);
bool GetValue(int frame, Zeus::CVector3f& valOut) const;
@ -35,23 +35,23 @@ class CVETimeChain : public CVectorElement
{
std::unique_ptr<CVectorElement> x4_a;
std::unique_ptr<CVectorElement> x8_b;
std::unique_ptr<CIntElement> xc_c;
std::unique_ptr<CIntElement> xc_swFrame;
public:
CVETimeChain(CVectorElement* a, CVectorElement* b, CIntElement* c)
: x4_a(a), x8_b(b), xc_c(c) {}
: x4_a(a), x8_b(b), xc_swFrame(c) {}
bool GetValue(int frame, Zeus::CVector3f& valOut) const;
};
class CVEAngleCone : public CVectorElement
{
std::unique_ptr<CRealElement> x4_a;
std::unique_ptr<CRealElement> x8_b;
std::unique_ptr<CRealElement> xc_c;
std::unique_ptr<CRealElement> x10_d;
std::unique_ptr<CRealElement> x14_e;
std::unique_ptr<CRealElement> x4_angleXConstant;
std::unique_ptr<CRealElement> x8_angleYConstant;
std::unique_ptr<CRealElement> xc_angleXRange;
std::unique_ptr<CRealElement> x10_angleYRange;
std::unique_ptr<CRealElement> x14_magnitude;
public:
CVEAngleCone(CRealElement* a, CRealElement* b, CRealElement* c, CRealElement* d, CRealElement* e)
: x4_a(a), x8_b(b), xc_c(c), x10_d(d), x14_e(e) {}
: x4_angleXConstant(a), x8_angleYConstant(b), xc_angleXRange(c), x10_angleYRange(d), x14_magnitude(e) {}
bool GetValue(int frame, Zeus::CVector3f& valOut) const;
};

View File

@ -12,12 +12,12 @@ namespace Retro
{
using FourCC = HECL::FourCC;
using TResID = u32;
using TResId = u32;
struct SObjectTag
{
FourCC type;
TResID id = -1;
TResId id = -1;
bool operator!=(const SObjectTag& other) const {return id != other.id;}
bool operator==(const SObjectTag& other) const {return id == other.id;}
};