metaforce/Runtime/World/CStateMachine.hpp

115 lines
2.4 KiB
C++
Raw Normal View History

2016-04-25 05:46:28 +00:00
#ifndef CSTATEMACHINE_HPP
#define CSTATEMACHINE_HPP
#include "RetroTypes.hpp"
#include "CAiFuncMap.hpp"
namespace urde
{
class CAiState;
class CStateManager;
class CAiTrigger
{
2016-08-15 20:43:04 +00:00
u32 x0_ = 0;
u32 x4_ = 0;
u32 x8_ = 0;
2016-04-25 05:46:28 +00:00
float xc_ = 0.f;
2016-08-15 20:43:04 +00:00
u32 x10_ = 0;
u32 x14_ = 0;
bool x18_ = false;
2016-04-25 05:46:28 +00:00
public:
CAiTrigger() = default;
bool GetAnd();
void GetState();
bool CallFunc(CStateManager&, CAi&)
{
return false;
}
void Setup(CAiTriggerFunc func, bool, float, CAiTrigger*);
void Setup(CAiTriggerFunc func, bool, float, CAiState*);
};
class CAiState
{
CAiStateFunc x0_func;
const char* x4_name;
u32 x8_;
u32 xc_;
u32 x10_;
u32 x14_;
u32 x18_;
u32 x1c_;
u32 x20_;
u32 x24_;
u32 x28_;
2016-08-15 20:43:04 +00:00
u32 x2c_numTriggers;
2016-04-25 05:46:28 +00:00
u32 x30_;
public:
CAiState(CAiStateFunc func, const char* name)
{}
2016-08-15 20:43:04 +00:00
s32 GetNumTriggers() const;
2016-04-25 05:46:28 +00:00
CAiTrigger& GetTrig(s32) const;
const char* GetName() const { return x4_name; }
2016-04-25 05:46:28 +00:00
void SetTriggers(CAiTrigger* triggers);
2016-08-15 20:43:04 +00:00
void SetNumTriggers(s32 numTriggers) { x2c_numTriggers = numTriggers; }
2016-04-25 05:46:28 +00:00
void CallFunc(CStateManager& mgr, CAi& ai, EStateMsg msg, float delta) const
{
if (x0_func)
(ai.*x0_func)(mgr, msg, delta);
}
};
class CStateMachine
{
std::vector<CAiState> x0_states;
std::vector<CAiTrigger> x10_triggers;
public:
CStateMachine(CInputStream& in);
2017-11-13 06:19:18 +00:00
s32 GetStateIndex(std::string_view state) const;
const std::vector<CAiState>& GetStateVector() const;
2016-04-25 05:46:28 +00:00
};
class CStateMachineState
{
2016-08-15 20:43:04 +00:00
const CStateMachine* x0_machine = nullptr;
2016-04-25 05:46:28 +00:00
CAiState* x4_state = nullptr;
float x8_time = 0.f;
float xc_ = 0.f;
float x10_ = 0.f;
2016-08-15 20:43:04 +00:00
union
{
struct
{
bool x18_24_ : 1;
};
u32 dummy = 0;
};
2016-04-25 05:46:28 +00:00
public:
CStateMachineState()=default;
2016-08-15 20:43:04 +00:00
void GetActorState() const;
float GetTime() const;
2016-04-25 05:46:28 +00:00
void Update(CStateManager& mgr, CAi& ai, float delta)
{
x8_time += delta;
2016-04-25 05:46:28 +00:00
if (x4_state)
x4_state->CallFunc(mgr, ai, EStateMsg::One, delta);
}
2016-08-15 20:43:04 +00:00
void SetState(CStateManager&, CAi&, s32);
2017-11-13 06:19:18 +00:00
void SetState(CStateManager&, CAi&, const CStateMachine*, std::string_view);
2016-08-15 20:43:04 +00:00
const std::vector<CAiState>* GetStateVector() const;
void Setup(const CStateMachine* machine);
std::string GetName() const;
void SetDelay(float);
void GetRandom() const;
float GetDelay() const;
2016-04-25 05:46:28 +00:00
};
}
#endif // CSTATEMACHINE_HPP