ScriptLoader support imps

This commit is contained in:
Jack Andersen 2016-04-17 19:33:23 -10:00
parent 48e8de05c5
commit c614d2d2d1
12 changed files with 366 additions and 39 deletions

View File

@ -15,8 +15,8 @@ struct Actor : IScriptObject
Value<atVec3f> location; Value<atVec3f> location;
Value<atVec3f> orientation; Value<atVec3f> orientation;
Value<atVec3f> scale; Value<atVec3f> scale;
Value<atVec3f> unkown1; Value<atVec3f> collisionExtent;
Value<atVec3f> scanOffset; Value<atVec3f> centroid;
Value<float> unknown2; Value<float> unknown2;
Value<float> unknown3; Value<float> unknown3;
HealthInfo healthInfo; HealthInfo healthInfo;

View File

@ -98,7 +98,7 @@ CStateManager::CStateManager(const std::weak_ptr<CScriptMailbox>&,
x904_loaderFuncs[int(EScriptObjectType::Ripple)] = ScriptLoader::LoadRipple; x904_loaderFuncs[int(EScriptObjectType::Ripple)] = ScriptLoader::LoadRipple;
x904_loaderFuncs[int(EScriptObjectType::BallTrigger)] = ScriptLoader::LoadBallTrigger; x904_loaderFuncs[int(EScriptObjectType::BallTrigger)] = ScriptLoader::LoadBallTrigger;
x904_loaderFuncs[int(EScriptObjectType::TargetingPoint)] = ScriptLoader::LoadTargetingPoint; x904_loaderFuncs[int(EScriptObjectType::TargetingPoint)] = ScriptLoader::LoadTargetingPoint;
x904_loaderFuncs[int(EScriptObjectType::ElectroMagneticPulse)] = ScriptLoader::LoadElectroMagneticPulse; x904_loaderFuncs[int(EScriptObjectType::EMPulse)] = ScriptLoader::LoadEMPulse;
x904_loaderFuncs[int(EScriptObjectType::IceSheegoth)] = ScriptLoader::LoadIceSheegoth; x904_loaderFuncs[int(EScriptObjectType::IceSheegoth)] = ScriptLoader::LoadIceSheegoth;
x904_loaderFuncs[int(EScriptObjectType::PlayerActor)] = ScriptLoader::LoadPlayerActor; x904_loaderFuncs[int(EScriptObjectType::PlayerActor)] = ScriptLoader::LoadPlayerActor;
x904_loaderFuncs[int(EScriptObjectType::Flaahgra)] = ScriptLoader::LoadFlaahgra; x904_loaderFuncs[int(EScriptObjectType::Flaahgra)] = ScriptLoader::LoadFlaahgra;
@ -211,7 +211,7 @@ void CStateManager::MurderScriptInstanceNames()
{ {
} }
void CStateManager::HashInstanceName(CInputStream& in) const std::string* CStateManager::HashInstanceName(CInputStream& in)
{ {
} }

View File

@ -147,7 +147,7 @@ public:
void ResetEscapeSequenceTimer(float); void ResetEscapeSequenceTimer(float);
void SetupParticleHook(const CActor& actor) const; void SetupParticleHook(const CActor& actor) const;
void MurderScriptInstanceNames(); void MurderScriptInstanceNames();
void HashInstanceName(CInputStream& in); const std::string* HashInstanceName(CInputStream& in);
void SetActorAreaId(CActor& actor, TAreaId); void SetActorAreaId(CActor& actor, TAreaId);
void TouchSky() const; void TouchSky() const;
void DrawSpaceWarp(const zeus::CVector3f&, float) const; void DrawSpaceWarp(const zeus::CVector3f&, float) const;

View File

@ -30,11 +30,62 @@ class CAiFuncMap
/* TODO: Move these */ /* TODO: Move these */
class CHealthInfo class CHealthInfo
{
float x0_;
float x4_;
public:
CHealthInfo(CInputStream& in) : x0_(in.readFloatBig()), x4_(in.readFloatBig()) {}
};
enum class EVulnerability
{ {
}; };
class CDamageVulnerability class CDamageVulnerability
{ {
EVulnerability x0_power;
EVulnerability x4_ice;
EVulnerability x8_wave;
EVulnerability xc_plasma;
EVulnerability x10_bomb;
EVulnerability x14_powerbomb;
EVulnerability x18_missile;
EVulnerability x1c_boostBall;
EVulnerability x20_phazon;
EVulnerability x24_enemyWp1;
EVulnerability x28_enemyWp2Poison;
EVulnerability x2c_enemyWp3Lava;
EVulnerability x30_enemyWp4;
EVulnerability x34_unk1;
EVulnerability x38_unk2;
EVulnerability x3c_unk3;
#if 0
struct ChargedBeams : BigYAML
{
DECL_YAML
Value<atUint32> propertyCount;
Value<atUint32> power;
Value<atUint32> ice;
Value<atUint32> wave;
Value<atUint32> plasma;
Value<atUint32> phazon;
} chargedBeams;
struct BeamCombos : BigYAML
{
DECL_YAML
Value<atUint32> propertyCount;
Value<atUint32> superMissiles;
Value<atUint32> iceSpreader;
Value<atUint32> wavebuster;
Value<atUint32> flameThrower;
Value<atUint32> phazonCombo;
} beamCombos;
#endif
public:
CDamageVulnerability(CInputStream& in) {}
}; };
class CStateManager; class CStateManager;

View File

@ -0,0 +1,21 @@
#ifndef __URDE_CANIMATIONPARAMETERS_HPP__
#define __URDE_CANIMATIONPARAMETERS_HPP__
#include "RetroTypes.hpp"
namespace urde
{
class CAnimationParameters
{
ResId x0_ancs;
s32 x4_charIdx;
u32 x8_defaultAnim;
public:
CAnimationParameters(ResId ancs, s32 charIdx, u32 defaultAnim)
: x0_ancs(ancs), x4_charIdx(charIdx), x8_defaultAnim(defaultAnim) {}
};
}
#endif // __URDE_CANIMATIONPARAMETERS_HPP__

View File

@ -6,18 +6,25 @@ namespace urde
class CGrappleParameters class CGrappleParameters
{ {
float x0_; float x0_a;
float x4_; float x4_b;
float x8_; float x8_c;
float xc_; float xc_d;
float x10_; float x10_e;
float x14_; float x14_f;
float x18_; float x18_g;
float x1c_; float x1c_h;
float x20_; float x20_i;
float x24_; float x24_j;
float x28_; float x28_k;
bool x2c_; bool x2c_l;
public:
CGrappleParameters(float a, float b, float c, float d,
float e, float f, float g, float h,
float i, float j, float k, bool l)
: x0_a(a), x4_b(b), x8_c(c), xc_d(d),
x10_e(e), x14_f(f), x18_g(g), x1c_h(h),
x20_i(i), x24_j(j), x28_k(k), x2c_l(l) {}
}; };
} }

View File

@ -19,4 +19,5 @@ add_library(RuntimeCommonWorld
CActorParameters.hpp CActorParameters.hpp
CLightParameters.hpp CLightParameters.hpp
CScannableParameters.hpp CScannableParameters.hpp
CVisorParameters.hpp) CVisorParameters.hpp
CAnimationParameters.hpp)

View File

@ -10,6 +10,8 @@ class CScannableParameters
{ {
ResId x0_scanId = -1; ResId x0_scanId = -1;
public: public:
CScannableParameters() = default;
CScannableParameters(ResId id) : x0_scanId(id) {}
}; };
} }

View File

@ -8,12 +8,14 @@ namespace urde
class CVisorParameters class CVisorParameters
{ {
u8 mask : 4; u8 x0_mask : 4;
bool b1 : 1; bool x0_4_b1 : 1;
bool b2 : 1; bool x0_5_b2 : 1;
public: public:
CVisorParameters() CVisorParameters()
: mask(0xf), b1(false), b2(false) {} : x0_mask(0xf), x0_4_b1(false), x0_5_b2(false) {}
CVisorParameters(u8 mask, bool b1, bool b2)
: x0_mask(mask), x0_4_b1(b1), x0_5_b2(b2) {}
}; };
} }

View File

@ -1,4 +1,12 @@
#include "ScriptLoader.hpp" #include "ScriptLoader.hpp"
#include "CStateManager.hpp"
#include "CGrappleParameters.hpp"
#include "CActorParameters.hpp"
#include "CVisorParameters.hpp"
#include "CScannableParameters.hpp"
#include "CLightParameters.hpp"
#include "CAnimationParameters.hpp"
#include "GameGlobalObjects.hpp"
#include "logvisor/logvisor.hpp" #include "logvisor/logvisor.hpp"
namespace urde namespace urde
@ -16,12 +24,245 @@ static bool EnsurePropertyCount(int count, int expected, const char* structName)
return true; return true;
} }
struct SActorHead
{
std::string x0_name;
zeus::CTransform x10_transform;
};
struct SScaledActorHead : SActorHead
{
zeus::CVector3f x40_scale;
SScaledActorHead(SActorHead&& head) : SActorHead(std::move(head)) {}
};
static zeus::CTransform LoadEditorTransform(CInputStream& in)
{
zeus::CVector3f position;
position.readBig(in);
zeus::CVector3f orientation;
orientation.readBig(in);
return ScriptLoader::ConvertEditorEulerToTransform4f(orientation, position);
}
static zeus::CTransform LoadEditorTransformPivotOnly(CInputStream& in)
{
zeus::CVector3f position;
position.readBig(in);
zeus::CVector3f orientation;
orientation.readBig(in);
orientation.x = 0.f;
orientation.y = 0.f;
return ScriptLoader::ConvertEditorEulerToTransform4f(orientation, position);
}
static SActorHead LoadActorHead(CInputStream& in, CStateManager& stateMgr)
{
SActorHead ret;
ret.x0_name = *stateMgr.HashInstanceName(in);
ret.x10_transform = LoadEditorTransform(in);
return ret;
}
static SScaledActorHead LoadScaledActorHead(CInputStream& in, CStateManager& stateMgr)
{
SScaledActorHead ret = LoadActorHead(in, stateMgr);
ret.x40_scale.readBig(in);
return ret;
}
u32 ScriptLoader::LoadParameterFlags(CInputStream& in)
{
u32 count = in.readUint32Big();
u32 ret = 0;
for (u32 i=0 ; i<count ; ++i)
if (in.readBool())
ret |= 1 << i;
return ret;
}
CGrappleParameters ScriptLoader::LoadGrappleParameters(CInputStream& in)
{
float a = in.readFloatBig();
float b = in.readFloatBig();
float c = in.readFloatBig();
float d = in.readFloatBig();
float e = in.readFloatBig();
float f = in.readFloatBig();
float g = in.readFloatBig();
float h = in.readFloatBig();
float i = in.readFloatBig();
float j = in.readFloatBig();
float k = in.readFloatBig();
bool l = in.readBool();
return CGrappleParameters(a, b, c, d, e, f, g, h, i, j, k, l);
}
CActorParameters ScriptLoader::LoadActorParameters(CInputStream& in)
{
u32 propCount = in.readUint32Big();
if (propCount >= 5 && propCount <= 0xe)
{
CLightParameters lParms = ScriptLoader::LoadLightParameters(in);
CScannableParameters sParams;
if (propCount > 5)
sParams = LoadScannableParameters(in);
ResId xrayModel = in.readUint32Big();
ResId xraySkin = in.readUint32Big();
ResId infraModel = in.readUint32Big();
ResId infraSkin = in.readUint32Big();
bool b1 = true;
if (propCount > 7)
b1 = in.readBool();
float f1 = 1.f;
if (propCount > 8)
f1 = in.readFloatBig();
float f2 = 1.f;
if (propCount > 9)
f2 = in.readFloatBig();
CVisorParameters vParms;
if (propCount > 6)
vParms = LoadVisorParameters(in);
bool b2 = false;
if (propCount > 10)
b2 = in.readBool();
bool b3 = false;
if (propCount > 11)
b3 = in.readBool();
bool b4 = false;
if (propCount > 12)
b4 = in.readBool();
float f3 = 1.f;
if (propCount > 13)
f3 = in.readFloatBig();
std::pair<ResId, ResId> xray = {};
if (g_ResFactory->GetResourceTypeById(xrayModel))
xray = {xrayModel, xraySkin};
std::pair<ResId, ResId> infra = {};
if (g_ResFactory->GetResourceTypeById(infraModel))
infra = {infraModel, infraSkin};
return CActorParameters(lParms, sParams, xray, infra, vParms, b1, b2, b3, b4);
}
return CActorParameters::None();
}
CVisorParameters ScriptLoader::LoadVisorParameters(CInputStream& in)
{
u32 propCount = in.readUint32Big();
if (propCount >= 1 && propCount <= 3)
{
bool b1 = in.readBool();
bool b2 = false;
u8 mask = 0xf;
if (propCount > 1)
b2 = in.readBool();
if (propCount > 2)
mask = in.readUint32Big();
return CVisorParameters(mask, b1, b2);
}
return CVisorParameters();
}
CScannableParameters ScriptLoader::LoadScannableParameters(CInputStream& in)
{
u32 propCount = in.readUint32Big();
if (propCount == 1)
return CScannableParameters(in.readUint32Big());
return CScannableParameters();
}
CLightParameters ScriptLoader::LoadLightParameters(CInputStream& in)
{
u32 propCount = in.readUint32Big();
if (propCount == 14)
{
bool a = in.readBool();
float b = in.readFloatBig();
u32 c = in.readUint32Big();
float d = in.readFloatBig();
float e = in.readFloatBig();
zeus::CColor col;
col.readRGBABig(in);
bool f = in.readBool();
u32 g = in.readUint32Big();
u32 h = in.readUint32Big();
zeus::CVector3f vec;
vec.readBig(in);
s32 w1 = -1;
s32 w2 = -1;
if (propCount >= 0xc)
{
w1 = in.readUint32Big();
w2 = in.readUint32Big();
}
bool b1 = false;
if (propCount >= 0xd)
b1 = in.readBool();
s32 w3 = 0;
if (propCount >= 0xe)
w3 = in.readUint32Big();
return CLightParameters(a, b, c, d, e, col, f, g, h, vec, w1, w2, b1, w3);
}
return CLightParameters::None();
}
CAnimationParameters ScriptLoader::LoadAnimationParameters(CInputStream& in)
{
ResId ancs = in.readUint32Big();
s32 charIdx = in.readUint32Big();
u32 defaultAnim = in.readUint32Big();
return CAnimationParameters(ancs, charIdx, defaultAnim);
}
zeus::CTransform ScriptLoader::ConvertEditorEulerToTransform4f(const zeus::CVector3f& orientation,
const zeus::CVector3f& position)
{
return zeus::CTransform::RotateZ(zeus::degToRad(orientation.z)) *
zeus::CTransform::RotateY(zeus::degToRad(orientation.y)) *
zeus::CTransform::RotateX(zeus::degToRad(orientation.x)) + position;
}
CEntity* ScriptLoader::LoadActor(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) CEntity* ScriptLoader::LoadActor(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info)
{ {
if (!EnsurePropertyCount(propCount, 24, "Actor")) if (!EnsurePropertyCount(propCount, 24, "Actor"))
return nullptr; return nullptr;
SScaledActorHead head = LoadScaledActorHead(in, mgr);
zeus::CVector3f collisionExtent;
collisionExtent.readBig(in);
zeus::CVector3f centroid;
centroid.readBig(in);
float f1 = in.readFloatBig();
float f2 = in.readFloatBig();
CHealthInfo hInfo(in);
CDamageVulnerability dInfo(in);
// TODO: Finish
} }
CEntity* ScriptLoader::LoadWaypoint(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) CEntity* ScriptLoader::LoadWaypoint(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info)
@ -280,7 +521,7 @@ CEntity* ScriptLoader::LoadTargetingPoint(CStateManager& mgr, CInputStream& in,
{ {
} }
CEntity* ScriptLoader::LoadElectroMagneticPulse(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) CEntity* ScriptLoader::LoadEMPulse(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info)
{ {
} }
@ -528,14 +769,4 @@ CEntity* ScriptLoader::LoadEnergyBall(CStateManager& mgr, CInputStream& in, int
{ {
} }
u32 ScriptLoader::LoadParameterFlags(CInputStream& in)
{
u32 count = in.readUint32Big();
u32 ret = 0;
for (u32 i=0 ; i<count ; ++i)
if (in.readBool())
ret |= 1 << i;
return ret;
}
} }

View File

@ -2,6 +2,7 @@
#define __URDE_SCRIPTLOADER_HPP__ #define __URDE_SCRIPTLOADER_HPP__
#include "IOStreams.hpp" #include "IOStreams.hpp"
#include "zeus/CTransform.hpp"
namespace urde namespace urde
{ {
@ -9,6 +10,11 @@ class CStateManager;
class CEntityInfo; class CEntityInfo;
class CEntity; class CEntity;
class CGrappleParameters; class CGrappleParameters;
class CActorParameters;
class CVisorParameters;
class CScannableParameters;
class CLightParameters;
class CAnimationParameters;
using FScriptLoader = std::function<CEntity*(CStateManager& mgr, CInputStream& in, using FScriptLoader = std::function<CEntity*(CStateManager& mgr, CInputStream& in,
int propCount, const CEntityInfo& info)>; int propCount, const CEntityInfo& info)>;
@ -16,6 +22,16 @@ using FScriptLoader = std::function<CEntity*(CStateManager& mgr, CInputStream& i
class ScriptLoader class ScriptLoader
{ {
public: public:
static u32 LoadParameterFlags(CInputStream& in);
static CGrappleParameters LoadGrappleParameters(CInputStream& in);
static CActorParameters LoadActorParameters(CInputStream& in);
static CVisorParameters LoadVisorParameters(CInputStream& in);
static CScannableParameters LoadScannableParameters(CInputStream& in);
static CLightParameters LoadLightParameters(CInputStream& in);
static CAnimationParameters LoadAnimationParameters(CInputStream& in);
static zeus::CTransform ConvertEditorEulerToTransform4f(const zeus::CVector3f& orientation,
const zeus::CVector3f& position);
static CEntity* LoadActor(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadActor(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
static CEntity* LoadWaypoint(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadWaypoint(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
static CEntity* LoadDoorArea(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadDoorArea(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
@ -81,7 +97,7 @@ public:
static CEntity* LoadRipple(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadRipple(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
static CEntity* LoadBallTrigger(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadBallTrigger(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
static CEntity* LoadTargetingPoint(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadTargetingPoint(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
static CEntity* LoadElectroMagneticPulse(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadEMPulse(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
static CEntity* LoadIceSheegoth(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadIceSheegoth(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
static CEntity* LoadPlayerActor(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadPlayerActor(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
static CEntity* LoadFlaahgra(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadFlaahgra(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
@ -143,10 +159,6 @@ public:
static CEntity* LoadNewCameraShaker(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadNewCameraShaker(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
static CEntity* LoadShadowProjector(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadShadowProjector(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
static CEntity* LoadEnergyBall(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); static CEntity* LoadEnergyBall(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info);
static u32 LoadParameterFlags(CInputStream& in);
static CGrappleParameters LoadGrappleParameters(CInputStream& in);
}; };
} }

View File

@ -71,7 +71,7 @@ enum class EScriptObjectType
Ripple = 0x47, Ripple = 0x47,
BallTrigger = 0x48, BallTrigger = 0x48,
TargetingPoint = 0x49, TargetingPoint = 0x49,
ElectroMagneticPulse = 0x4A, EMPulse = 0x4A,
IceSheegoth = 0x4B, IceSheegoth = 0x4B,
PlayerActor = 0x4C, PlayerActor = 0x4C,
Flaahgra = 0x4D, Flaahgra = 0x4D,