More script loaders

This commit is contained in:
Jack Andersen 2016-04-20 11:44:18 -10:00
parent fd3066e304
commit 0f6d1645ba
19 changed files with 388 additions and 25 deletions

View File

@ -14,6 +14,7 @@
#include "Runtime/Character/CAnimCharacterSet.hpp"
#include "Runtime/Character/CAllFormatsAnimSource.hpp"
#include "Runtime/Character/CAnimPOIData.hpp"
#include "Runtime/Collision/CCollidableOBBTreeGroup.hpp"
#include "Runtime/CDependencyGroup.hpp"
#include "DataSpec/DNACommon/TXTR.hpp"
@ -39,6 +40,7 @@ ProjectResourceFactoryMP1::ProjectResourceFactoryMP1(hecl::ClientProcess& client
m_factoryMgr.AddFactory(FOURCC('ANCS'), FFactoryFunc(FAnimCharacterSet));
m_factoryMgr.AddFactory(FOURCC('ANIM'), FFactoryFunc(AnimSourceFactory));
m_factoryMgr.AddFactory(FOURCC('EVNT'), FFactoryFunc(AnimPOIDataFactory));
m_factoryMgr.AddFactory(FOURCC('DCLN'), FFactoryFunc(FCollidableOBBTreeGroupFactory));
m_factoryMgr.AddFactory(FOURCC('DGRP'), FFactoryFunc(FDependencyGroupFactory));
}

View File

@ -0,0 +1,17 @@
#include "CCollidableOBBTreeGroup.hpp"
#include "CToken.hpp"
namespace urde
{
CCollidableOBBTreeGroup::CCollidableOBBTreeGroup(CInputStream& in)
{
}
CFactoryFnReturn FCollidableOBBTreeGroupFactory(const SObjectTag &tag, CInputStream &in,
const CVParamTransfer &vparms)
{
return TToken<CCollidableOBBTreeGroup>::GetIObjObjectFor(std::make_unique<CCollidableOBBTreeGroup>(in));
}
}

View File

@ -1,13 +1,21 @@
#ifndef __URDE_CCOLLIDABLEOBBTREEGROUP_HPP__
#define __URDE_CCOLLIDABLEOBBTREEGROUP_HPP__
#include "IOStreams.hpp"
#include "CFactoryMgr.hpp"
namespace urde
{
class CCollidableOBBTreeGroup
{
public:
CCollidableOBBTreeGroup(CInputStream& in);
};
CFactoryFnReturn FCollidableOBBTreeGroupFactory(const SObjectTag &tag, CInputStream &in,
const CVParamTransfer &vparms);
}
#endif // __URDE_CCOLLIDABLEOBBTREEGROUP_HPP__

View File

@ -3,10 +3,10 @@
namespace urde
{
CActor::CActor(TUniqueId uid, bool active, const std::string&, const CEntityInfo& info,
CActor::CActor(TUniqueId uid, bool active, const std::string& name, const CEntityInfo& info,
const zeus::CTransform&, const CModelData&, const CMaterialList&,
const CActorParameters&, TUniqueId)
: CEntity(uid, info, active)
: CEntity(uid, info, active, name)
{
}

View File

@ -4,8 +4,9 @@
namespace urde
{
CEntity::CEntity(TUniqueId uniqueId, const CEntityInfo& info, bool active)
: m_uid(uniqueId), m_info(info), m_active(active) {}
CEntity::CEntity(TUniqueId uniqueId, const CEntityInfo& info, bool active, const std::string& name)
: x4_areaId(info.x0_areaId), x8_uid(uniqueId), xc_savwId(info.x14_savwId), x10_name(name),
x20_conns(info.x4_conns), x30_24_active(active) {}
void CEntity::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr)
{
@ -43,9 +44,9 @@ void CEntity::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateM
void CEntity::SendScriptMsgs(EScriptObjectState state, CStateManager& stateMgr, EScriptObjectMessage skipMsg)
{
for (const SConnection& conn : m_info.m_conns)
if (conn.state == state && conn.msg != skipMsg)
stateMgr.SendScriptMsg(m_uid, conn.objId, conn.msg, state);
for (const SConnection& conn : x20_conns)
if (conn.x0_state == state && conn.x4_msg != skipMsg)
stateMgr.SendScriptMsg(x8_uid, conn.x8_objId, conn.x4_msg, state);
}
}

View File

@ -11,39 +11,54 @@ class IVisitor;
struct SConnection
{
EScriptObjectState state;
EScriptObjectMessage msg;
TEditorId objId;
EScriptObjectState x0_state;
EScriptObjectMessage x4_msg;
TEditorId x8_objId;
};
class CEntityInfo
{
friend class CEntity;
TAreaId m_aid;
std::vector<SConnection> m_conns;
TAreaId x0_areaId;
std::vector<SConnection> x4_conns;
ResId x14_savwId;
public:
CEntityInfo(TAreaId aid, const std::vector<SConnection>& conns)
: m_aid(aid), m_conns(conns) {}
TAreaId GetAreaId() const {return m_aid;}
CEntityInfo(TAreaId aid, const std::vector<SConnection>& conns, ResId savwId=-1)
: x0_areaId(aid), x4_conns(conns) {}
TAreaId GetAreaId() const {return x0_areaId;}
};
class CEntity
{
protected:
TUniqueId m_uid;
CEntityInfo m_info;
bool m_active = false;
TAreaId x4_areaId;
TUniqueId x8_uid;
ResId xc_savwId;
std::string x10_name;
std::vector<SConnection> x20_conns;
union
{
struct
{
bool x30_24_active : 1;
bool x30_25_ : 1;
bool x30_26_ : 1;
};
u8 _dummy = 0;
};
public:
virtual ~CEntity() {}
CEntity(TUniqueId uid, const CEntityInfo& info, bool active);
CEntity(TUniqueId uid, const CEntityInfo& info, bool active, const std::string& name);
virtual void Accept(IVisitor&)=0;
virtual void PreThink(float, CStateManager&) {}
virtual void Think(float, CStateManager&) {}
virtual void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr);
virtual bool GetActive() const {return m_active;}
virtual void SetActive(bool active) {m_active = active;}
virtual bool GetActive() const {return x30_24_active;}
virtual void SetActive(bool active) {x30_24_active = active;}
TUniqueId GetUniqueId() const {return m_uid;}
TUniqueId GetUniqueId() const {return x8_uid;}
void SendScriptMsgs(EScriptObjectState state, CStateManager& stateMgr, EScriptObjectMessage msg);
};

View File

@ -21,6 +21,10 @@ add_library(RuntimeCommonWorld
CScriptTrigger.hpp CScriptTrigger.cpp
CScriptTimer.hpp CScriptTimer.cpp
CScriptCounter.hpp CScriptCounter.cpp
CScriptEffect.hpp CScriptEffect.cpp
CScriptPlatform.hpp CScriptPlatform.cpp
CScriptSound.hpp CScriptSound.cpp
CScriptGenerator.hpp CScriptGenerator.cpp
CGrappleParameters.hpp
CActorParameters.hpp
CLightParameters.hpp

View File

@ -5,7 +5,7 @@ namespace urde
CScriptCounter::CScriptCounter(TUniqueId uid, const std::string& name, const CEntityInfo& info,
u32, u32, bool, bool active)
: CEntity(uid, info, active)
: CEntity(uid, info, active, name)
{
}

View File

@ -0,0 +1,19 @@
#include "CScriptEffect.hpp"
#include "Character/CModelData.hpp"
#include "Collision/CMaterialList.hpp"
#include "CActorParameters.hpp"
namespace urde
{
CScriptEffect::CScriptEffect(TUniqueId uid, const std::string& name, const CEntityInfo& info,
const zeus::CTransform& xf, const zeus::CVector3f& scale,
ResId partId, ResId elscId, bool, bool, bool, bool active,
bool, float, float, float, float, bool, float, float, float,
bool, bool, bool, const CLightParameters& lParms, bool)
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(0),
CActorParameters::None(), kInvalidUniqueId)
{
}
}

View File

@ -0,0 +1,21 @@
#ifndef __URDE_CSCRIPEFFECT_HPP__
#define __URDE_CSCRIPEFFECT_HPP__
#include "CActor.hpp"
namespace urde
{
class CScriptEffect : public CActor
{
public:
CScriptEffect(TUniqueId, const std::string& name, const CEntityInfo& info,
const zeus::CTransform& xf, const zeus::CVector3f& scale,
ResId partId, ResId elscId, bool, bool, bool, bool active,
bool, float, float, float, float, bool, float, float, float,
bool, bool, bool, const CLightParameters& lParms, bool);
};
}
#endif // __URDE_CSCRIPEFFECT_HPP__

View File

@ -0,0 +1,12 @@
#include "CScriptGenerator.hpp"
namespace urde
{
CScriptGenerator::CScriptGenerator(TUniqueId uid, const std::string& name, const CEntityInfo& info,
u32, bool, const zeus::CVector3f&, bool, bool active, float, float)
: CEntity(uid, info, active, name)
{
}
}

View File

@ -0,0 +1,20 @@
#ifndef __URDE_CSCRIPTGENERATOR_HPP__
#define __URDE_CSCRIPTGENERATOR_HPP__
#include "CEntity.hpp"
#include "zeus/CVector3f.hpp"
namespace urde
{
class CScriptGenerator : public CEntity
{
public:
CScriptGenerator(TUniqueId uid, const std::string& name, const CEntityInfo& info,
u32, bool, const zeus::CVector3f&, bool, bool, float, float);
virtual void Accept(IVisitor&);
};
}
#endif // __URDE_CSCRIPTGENERATOR_HPP__

View File

@ -0,0 +1,28 @@
#include "CScriptPlatform.hpp"
#include "Collision/CMaterialList.hpp"
namespace urde
{
static CMaterialList MakePlatformMaterialList()
{
CMaterialList ret;
ret.x0_ |= 1ull << 19;
ret.x0_ |= 1ull << 43;
ret.x0_ |= 1ull << 49;
ret.x0_ |= 1ull << 42;
return ret;
}
CScriptPlatform::CScriptPlatform(TUniqueId uid, const std::string& name, const CEntityInfo& info,
const zeus::CTransform& xf, const CModelData& mData,
const CActorParameters& actParms, const zeus::CAABox& aabb,
float, bool, float, bool active, const CHealthInfo& hInfo,
const CDamageVulnerability& dInfo, const TLockedToken<CCollidableOBBTreeGroup>& dcln,
bool, u32, u32)
: CPhysicsActor(uid, active, name, info, xf, mData, MakePlatformMaterialList(),
aabb, SMoverData(15000.f), actParms, 0.3f, 0.1f)
{
}
}

View File

@ -0,0 +1,24 @@
#ifndef __URDE_CSCRIPTPLATFORM_HPP__
#define __URDE_CSCRIPTPLATFORM_HPP__
#include "CPhysicsActor.hpp"
#include "optional.hpp"
#include "CToken.hpp"
namespace urde
{
class CCollidableOBBTreeGroup;
class CScriptPlatform : public CPhysicsActor
{
public:
CScriptPlatform(TUniqueId, const std::string& name, const CEntityInfo& info,
const zeus::CTransform& xf, const CModelData& mData,
const CActorParameters& actParms, const zeus::CAABox& aabb,
float, bool, float, bool, const CHealthInfo& hInfo, const CDamageVulnerability& dInfo,
const TLockedToken<CCollidableOBBTreeGroup>& dcln, bool, u32, u32);
};
}
#endif // __URDE_CSCRIPTPLATFORM_HPP__

View File

@ -0,0 +1,17 @@
#include "CScriptSound.hpp"
#include "Character/CModelData.hpp"
#include "Collision/CMaterialList.hpp"
#include "CActorParameters.hpp"
namespace urde
{
CScriptSound::CScriptSound(TUniqueId uid, const std::string& name, const CEntityInfo& info,
const zeus::CTransform& xf, s16 soundId, bool active, float, float, float,
u32, u32, u32, u32, u32, bool, bool, bool, bool, bool, bool, bool, bool, u32)
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(),
CMaterialList(0), CActorParameters::None(), kInvalidUniqueId)
{
}
}

View File

@ -0,0 +1,19 @@
#ifndef __URDE_CSCRIPTSOUND_HPP__
#define __URDE_CSCRIPTSOUND_HPP__
#include "CActor.hpp"
namespace urde
{
class CScriptSound : public CActor
{
public:
CScriptSound(TUniqueId, const std::string& name, const CEntityInfo& info,
const zeus::CTransform& xf, s16 soundId, bool, float, float, float,
u32, u32, u32, u32, u32, bool, bool, bool, bool, bool, bool, bool, bool, u32);
};
}
#endif // __URDE_CSCRIPTSOUND_HPP__

View File

@ -5,7 +5,7 @@ namespace urde
CScriptTimer::CScriptTimer(TUniqueId uid, const std::string& name, const CEntityInfo& info,
float, float, bool, bool, bool active)
: CEntity(uid, info, active)
: CEntity(uid, info, active, name)
{
}

View File

@ -9,7 +9,7 @@ namespace urde
CScriptWaypoint::CScriptWaypoint(TUniqueId uid, const std::string& name, const CEntityInfo& info,
const zeus::CTransform& xf, bool active, float, float,
u32, u32, u32, u32, u32, u32, u32)
: CActor(uid, active, name, info, xf, CModelData(), CMaterialList(1),
: CActor(uid, active, name, info, xf, CModelData(), CMaterialList(0),
CActorParameters::None(), kInvalidUniqueId)
{
}

View File

@ -19,7 +19,12 @@
#include "CScriptTimer.hpp"
#include "CScriptCounter.hpp"
#include "CScriptWater.hpp"
#include "CScriptEffect.hpp"
#include "CScriptPlatform.hpp"
#include "CScriptSound.hpp"
#include "CScriptGenerator.hpp"
#include "CSimplePool.hpp"
#include "Collision/CCollidableOBBTreeGroup.hpp"
#include "Editor/ProjectResourceFactoryMP1.hpp"
#include "logvisor/logvisor.hpp"
@ -534,21 +539,172 @@ CEntity* ScriptLoader::LoadCounter(CStateManager& mgr, CInputStream& in,
CEntity* ScriptLoader::LoadEffect(CStateManager& mgr, CInputStream& in,
int propCount, const CEntityInfo& info)
{
if (!EnsurePropertyCount(propCount, 24, "Effect"))
return nullptr;
SScaledActorHead head = LoadScaledActorHead(in, mgr);
ResId partId = in.readUint32Big();
ResId elscId = in.readUint32Big();
bool b1 = in.readBool();
bool b2 = in.readBool();
bool b3 = in.readBool();
bool b4 = in.readBool();
if (partId == 0xffffffff && elscId == 0xffffffff)
return nullptr;
if (!g_ResFactory->GetResourceTypeById(partId) &&
!g_ResFactory->GetResourceTypeById(elscId))
return nullptr;
bool b5 = in.readBool();
float f1 = in.readFloatBig();
float f2 = in.readFloatBig();
float f3 = in.readFloatBig();
float f4 = in.readFloatBig();
bool b6 = in.readBool();
float f5 = in.readFloatBig();
float f6 = in.readFloatBig();
float f7 = in.readFloatBig();
bool b7 = in.readBool();
bool b8 = in.readBool();
bool b9 = in.readBool();
bool b10 = in.readBool();
CLightParameters lParms = LoadLightParameters(in);
return new CScriptEffect(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform,
head.x40_scale, partId, elscId, b1, b2, b3, b4, b5, f1, f2, f3, f4,
b6, f5, f6, f7, b7, b8, b9, lParms, b10);
}
CEntity* ScriptLoader::LoadPlatform(CStateManager& mgr, CInputStream& in,
int propCount, const CEntityInfo& info)
{
if (!EnsurePropertyCount(propCount, 19, "Platform"))
return nullptr;
SScaledActorHead head = LoadScaledActorHead(in, mgr);
zeus::CVector3f extent;
extent.readBig(in);
zeus::CVector3f centroid;
centroid.readBig(in);
ResId staticId = in.readUint32Big();
CAnimationParameters aParms = LoadAnimationParameters(in);
CActorParameters actParms = LoadActorParameters(in);
float f1 = in.readFloatBig();
bool b1 = in.readBool();
ResId dclnId = in.readUint32Big();
CHealthInfo hInfo(in);
CDamageVulnerability dInfo(in);
bool b2 = in.readBool();
float f2 = in.readFloatBig();
bool b3 = in.readBool();
u32 w2 = in.readUint32Big();
u32 w3 = in.readUint32Big();
FourCC animType = g_ResFactory->GetResourceTypeById(aParms.x0_ancs);
if (!g_ResFactory->GetResourceTypeById(staticId) && !animType)
return nullptr;
zeus::CAABox aabb = GetCollisionBox(mgr, info.GetAreaId(), extent, centroid);
FourCC dclnType = g_ResFactory->GetResourceTypeById(dclnId);
TLockedToken<CCollidableOBBTreeGroup> dclnToken;
if (dclnType)
{
dclnToken = g_SimplePool->GetObj({SBIG('DCLN'), dclnId});
dclnToken.GetObj();
}
CModelData data;
if (animType == SBIG('ANCS'))
{
CAnimRes aRes;
aRes.x0_ancsId = aParms.x0_ancs;
aRes.x4_charIdx = aParms.x4_charIdx;
aRes.x8_scale = head.x40_scale;
aRes.x14_ = true;
aRes.x1c_defaultAnim = aParms.x8_defaultAnim;
data = aRes;
}
else
{
CStaticRes sRes;
sRes.x0_cmdlId = staticId;
sRes.x4_scale = head.x40_scale;
data = sRes;
}
if (extent.isZero())
aabb = data.GetBounds(head.x10_transform.getRotation());
return new CScriptPlatform(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform,
data, actParms, aabb, f1, b2, f2, b1, hInfo, dInfo, dclnToken, b3, w2, w3);
}
CEntity* ScriptLoader::LoadSound(CStateManager& mgr, CInputStream& in,
int propCount, const CEntityInfo& info)
{
if (!EnsurePropertyCount(propCount, 20, "Sound"))
return nullptr;
SActorHead head = LoadActorHead(in, mgr);
s32 soundId = in.readInt32Big();
bool b1 = in.readBool();
float f1 = in.readFloatBig();
float f2 = in.readFloatBig();
float f3 = in.readFloatBig();
u32 w2 = in.readUint32Big();
u32 w3 = in.readUint32Big();
u32 w4 = in.readUint32Big();
u32 w5 = in.readUint32Big();
bool b2 = in.readBool();
bool b3 = in.readBool();
bool b4 = in.readBool();
bool b5 = in.readBool();
bool b6 = in.readBool();
bool b7 = in.readBool();
bool b8 = in.readBool();
u32 w6 = in.readUint32Big();
if (soundId < 0)
return nullptr;
return new CScriptSound(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform,
soundId, b1, f1, f2, f3, w2, w3, w4, w5, w6, 0, b2, b3, b4, b5, b6, b7, b8, w6);
}
CEntity* ScriptLoader::LoadGenerator(CStateManager& mgr, CInputStream& in,
int propCount, const CEntityInfo& info)
{
if (!EnsurePropertyCount(propCount, 8, "Generator"))
return nullptr;
const std::string* name = mgr.HashInstanceName(in);
u32 w1 = in.readUint32Big();
bool b1 = in.readBool();
bool b2 = in.readBool();
zeus::CVector3f v1;
v1.readBig(in);
bool b3 = in.readBool();
float f1 = in.readFloatBig();
float f2 = in.readFloatBig();
return new CScriptGenerator(mgr.AllocateUniqueId(), *name, info, w1, b1, v1, b2, b3, f1, f2);
}
CEntity* ScriptLoader::LoadDock(CStateManager& mgr, CInputStream& in,