Match and link TGameTypes

This commit is contained in:
Phillip Stephens 2022-10-09 19:27:35 -07:00
parent 66834fed19
commit 8787239165
11 changed files with 182 additions and 9 deletions

View File

@ -165,7 +165,7 @@ LIBS = [
"MetroidPrime/CDecalManager", "MetroidPrime/CDecalManager",
"MetroidPrime/ScriptObjects/CScriptSpiderBallWaypoint", "MetroidPrime/ScriptObjects/CScriptSpiderBallWaypoint",
"MetroidPrime/Enemies/CBloodFlower", "MetroidPrime/Enemies/CBloodFlower",
"MetroidPrime/TGameTypes", ["MetroidPrime/TGameTypes", True],
"MetroidPrime/CPhysicsActor", "MetroidPrime/CPhysicsActor",
["MetroidPrime/CPhysicsState", True], ["MetroidPrime/CPhysicsState", True],
"MetroidPrime/CRipple", "MetroidPrime/CRipple",

View File

@ -27,7 +27,7 @@ public:
void Get(void* dest, unsigned long len); void Get(void* dest, unsigned long len);
template < typename T > template < typename T >
inline T Get(const TType< T >& type) { inline T Get(const TType< T >& type = TType<T>()) {
return cinput_stream_helper(type, *this); return cinput_stream_helper(type, *this);
} }

View File

@ -9,7 +9,9 @@
class CArchitectureQueue { class CArchitectureQueue {
public: public:
void Push(const CArchitectureMessage&); // TODO bool Push(const CArchitectureMessage& msg) {
x0_queue.push_back(msg);
}
void Pop(); // TODO void Pop(); // TODO
void Clear(); // TODO void Clear(); // TODO
bool IsEmpty() const; // TODO bool IsEmpty() const; // TODO

View File

@ -9,11 +9,12 @@
class COsContext; class COsContext;
class IController; class IController;
class CArchitectureQueue;
class CInputGenerator { class CInputGenerator {
public: public:
CInputGenerator(COsContext*, float, float); CInputGenerator(COsContext*, float leftDiv, float rightDiv);
bool Update(float dt, CArchitectureQueue& queue);
IController* GetController() const { return x4_controller.get(); } IController* GetController() const { return x4_controller.get(); }
private: private:

View File

@ -1,6 +1,7 @@
#ifndef _DECODE #ifndef _DECODE
#define _DECODE #define _DECODE
#include "MetroidPrime/CArchitectureMessage.hpp"
#include "MetroidPrime/CArchMsgParmInt32.hpp" #include "MetroidPrime/CArchMsgParmInt32.hpp"
#include "MetroidPrime/CArchMsgParmInt32Int32VoidPtr.hpp" #include "MetroidPrime/CArchMsgParmInt32Int32VoidPtr.hpp"
#include "MetroidPrime/CArchMsgParmNull.hpp" #include "MetroidPrime/CArchMsgParmNull.hpp"
@ -9,6 +10,10 @@
#include "MetroidPrime/CArchMsgParmControllerStatus.hpp" #include "MetroidPrime/CArchMsgParmControllerStatus.hpp"
namespace MakeMsg { namespace MakeMsg {
CArchitectureMessage CreateControllerStatus(EArchMsgTarget target, ushort chan, bool connected);
CArchitectureMessage CreateUserInput(EArchMsgTarget target, const CFinalInput& input);
const CArchMsgParmReal32& GetParmTimerTick(const CArchitectureMessage& msg); const CArchMsgParmReal32& GetParmTimerTick(const CArchitectureMessage& msg);
} }

View File

@ -10,9 +10,9 @@ struct TAreaId;
struct TEditorId; struct TEditorId;
struct TUniqueId; struct TUniqueId;
extern TAreaId kInvalidAreaId; extern const TAreaId kInvalidAreaId;
extern TEditorId kInvalidEditorId; extern const TEditorId kInvalidEditorId;
extern TUniqueId kInvalidUniqueId; extern const TUniqueId kInvalidUniqueId;
struct TAreaId { struct TAreaId {
int value; int value;

View File

@ -0,0 +1,42 @@
#ifndef _CWORLDLIGHT
#define _CWORLDLIGHT
#include "Kyoto/Math/CVector3f.hpp"
#include "Kyoto/Graphics/CLight.hpp"
class CInputStream;
class CWorldLight {
static const CVector3f kDefaultPosition;
static const CVector3f kDefaultDirection;
public:
enum EWorldLightType {
kWLT_LocalAmbient,
kWLT_Directional,
kWLT_Custom,
kWLT_Spot,
kWLT_Spot2,
kWLT_LocalAmbient2,
};
CWorldLight(CInputStream& in);
CLight GetAsCGraphicsLight() const;
public:
EWorldLightType x0_type;
CVector3f x4_color;
CVector3f x10_position;
CVector3f x1c_direction;
float x28_q;
float x2c_cutoffAngle;
float x30_;
bool x34_castShadows;
float x38_;
EFalloffType x3c_falloff;
float x40_;
};
#endif // _CWORLDLIGHT

View File

@ -132,7 +132,7 @@ METROIDPRIME :=\
$(BUILD_DIR)/asm/MetroidPrime/CDecalManager.o\ $(BUILD_DIR)/asm/MetroidPrime/CDecalManager.o\
$(BUILD_DIR)/asm/MetroidPrime/ScriptObjects/CScriptSpiderBallWaypoint.o\ $(BUILD_DIR)/asm/MetroidPrime/ScriptObjects/CScriptSpiderBallWaypoint.o\
$(BUILD_DIR)/asm/MetroidPrime/Enemies/CBloodFlower.o\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CBloodFlower.o\
$(BUILD_DIR)/asm/MetroidPrime/TGameTypes.o\ $(BUILD_DIR)/src/MetroidPrime/TGameTypes.o\
$(BUILD_DIR)/asm/MetroidPrime/CPhysicsActor.o\ $(BUILD_DIR)/asm/MetroidPrime/CPhysicsActor.o\
$(BUILD_DIR)/src/MetroidPrime/CPhysicsState.o\ $(BUILD_DIR)/src/MetroidPrime/CPhysicsState.o\
$(BUILD_DIR)/asm/MetroidPrime/CRipple.o\ $(BUILD_DIR)/asm/MetroidPrime/CRipple.o\

View File

@ -0,0 +1,52 @@
#include "MetroidPrime/CInputGenerator.hpp"
#include "MetroidPrime/CArchitectureQueue.hpp"
#include "MetroidPrime/Decode.hpp"
#include "Kyoto/Basics/COsContext.hpp"
CInputGenerator::CInputGenerator(COsContext* ctx, float leftDiv, float rightDiv)
: x0_context(ctx)
, x4_controller(IController::Create(*ctx))
, xc_leftDiv(leftDiv)
, x10_rightDiv(rightDiv) {
for (uint i = 0; i <= kIOP_Player4; ++i) {
x8_connectedControllers[i] = false;
}
}
bool CInputGenerator::Update(float dt, CArchitectureQueue& queue) {
bool ret;
if (!x0_context->Update()) {
ret = false;
} else {
int availSlot = 0;
bool firstController = false;
if (!x4_controller.null()) {
x4_controller->Poll();
for (int i = 0; i < x4_controller->GetDeviceCount(); ++i) {
if (i == 0) {
firstController = true;
}
CControllerGamepadData cont = x4_controller->GetGamepadData(i);
if (cont.DeviceIsPresent()) {
queue.Push(MakeMsg::CreateUserInput(kAMT_Game,
CFinalInput(i, dt, cont, xc_leftDiv, x10_rightDiv)));
++availSlot;
}
if (x8_connectedControllers[i] != cont.DeviceIsPresent()) {
queue.Push(MakeMsg::CreateControllerStatus(kAMT_Game, i, cont.DeviceIsPresent()));
x8_connectedControllers[i] = cont.DeviceIsPresent();
}
}
}
if (firstController) {
queue.Push(MakeMsg::CreateUserInput(kAMT_Game, CFinalInput(availSlot, dt, *x0_context)));
} else {
queue.Push(MakeMsg::CreateUserInput(kAMT_Game, CFinalInput(0, dt, *x0_context)));
}
ret = true;
}
return ret;
}

View File

@ -0,0 +1,12 @@
#include "MetroidPrime/TGameTypes.hpp"
#include "Kyoto/Streams/CInputStream.hpp"
const TEditorId kInvalidEditorId = TEditorId(-1);
const TUniqueId kInvalidUniqueId = TUniqueId(-1, -1);
const TAreaId kInvalidAreaId = TAreaId(-1);
const TEditorId kUnkId = TEditorId(-1);
TEditorId::TEditorId(CInputStream& in)
: value(in.Get<uint>()) {}

View File

@ -0,0 +1,59 @@
#include "WorldFormat/CWorldLight.hpp"
#include "Kyoto/Streams/CInputStream.hpp"
#include <hacks.h>
#include <rstl/math.hpp>
const CVector3f CWorldLight::kDefaultPosition = CVector3f(0.f, 0.f, 0.f);
FORCEPADDING(sizeof(CVector3f)) kPadding;
const CVector3f CWorldLight::kDefaultDirection = CVector3f(0.f, 1.f, 0.f);
CWorldLight::CWorldLight(CInputStream& in)
: x0_type((EWorldLightType)in.Get< uint >())
, x4_color(in)
, x10_position(in)
, x1c_direction(in)
, x28_q(in.Get< float >())
, x2c_cutoffAngle(in.Get< float >())
, x30_(in.Get< float >())
, x34_castShadows(in.Get< bool >())
, x38_(in.Get< float >())
, x3c_falloff((EFalloffType)in.Get< uint >())
, x40_(in.Get< float >()) {}
CLight CWorldLight::GetAsCGraphicsLight() const {
float R = x4_color.GetX();
float G = x4_color.GetY();
float B = x4_color.GetZ();
CColor color(R, G, B);
float q = x28_q < FLT_EPSILON ? 0.000001f : x28_q;
if (x0_type == kWLT_LocalAmbient) {
R *= q;
G *= q;
B *= q;
R = rstl::min_val(1.f, R);
G = rstl::min_val(1.f, G);
B = rstl::min_val(1.f, B);
return CLight::BuildLocalAmbient(x10_position, CColor(R, G, B));
}
if (x0_type == kWLT_Directional) {
return CLight::BuildDirectional(x10_position, color);
}
if (x0_type == kWLT_Spot) {
CLight light =
CLight::BuildSpot(x10_position, x1c_direction.AsNormalized(), color, x2c_cutoffAngle * .5f);
float quadratic = x3c_falloff == kFT_Quadratic ? (25000.0f / q) : 0.f;
float linear = x3c_falloff == kFT_Linear ? (250.f / q) : 0.f;
float constant = x3c_falloff == kFT_Constant ? (2.0f / q) : 0.f;
light.SetAttenuation(constant, linear, quadratic);
return light;
}
float quadratic = x3c_falloff == kFT_Quadratic ? (25000.0f / q) : 0.f;
float linear = x3c_falloff == kFT_Linear ? (250.f / q) : 0.f;
float constant = x3c_falloff == kFT_Constant ? (2.0f / q) : 0.f;
return CLight::BuildCustom(x10_position, CVector3f(1.f, 0.f, 0.f), color, constant, linear,
quadratic, 1.f, 0.f, 0.f);
}