metaforce/Runtime/CArchitectureMessage.hpp

172 lines
4.9 KiB
C++
Raw Normal View History

2016-04-12 23:07:23 -07:00
#ifndef __URDE_CARCHITECTUREMESSAGE_HPP__
#define __URDE_CARCHITECTUREMESSAGE_HPP__
2015-08-19 19:52:07 -07:00
#include "GCNTypes.hpp"
#include "Input/CFinalInput.hpp"
2015-08-25 18:34:56 -07:00
#include "rstl.hpp"
2015-08-19 19:52:07 -07:00
2016-03-04 15:04:53 -08:00
namespace urde
2015-08-19 19:52:07 -07:00
{
class CIOWin;
2015-11-20 17:16:07 -08:00
enum class EArchMsgTarget
2015-08-19 19:52:07 -07:00
{
2015-11-20 17:16:07 -08:00
IOWinManager = 0,
2016-02-19 22:45:36 -08:00
Game = 1,
2016-03-04 15:04:53 -08:00
/* URDE targets, we start at 255 */
2016-02-19 22:45:36 -08:00
ArchitectureSupport = 255,
2015-08-19 19:52:07 -07:00
};
2015-11-20 17:16:07 -08:00
enum class EArchMsgType
2015-08-19 19:52:07 -07:00
{
2015-11-20 17:16:07 -08:00
RemoveIOWin = 0,
CreateIOWin = 1,
ChangeIOWinPriority = 2,
RemoveAllIOWins = 3,
TimerTick = 4,
UserInput = 5,
SetGameState = 6,
ControllerStatus = 7,
QuitGameplay = 8,
UpdateBegin = 10,
FrameBegin = 11,
2016-03-04 15:04:53 -08:00
/* URDE messages, we start at 255 */
2016-02-19 22:45:36 -08:00
ApplicationExit = 255,
2015-08-19 19:52:07 -07:00
};
struct IArchMsgParm
{
virtual ~IArchMsgParm() {}
};
struct CArchMsgParmInt32 : IArchMsgParm
{
2015-08-25 18:34:56 -07:00
u32 x4_parm;
CArchMsgParmInt32(u32 parm) : x4_parm(parm) {}
virtual ~CArchMsgParmInt32() {}
2015-08-25 18:34:56 -07:00
};
struct CArchMsgParmVoidPtr : IArchMsgParm
{
void* x4_parm1;
CArchMsgParmVoidPtr(void* parm1)
: x4_parm1(parm1) {}
virtual ~CArchMsgParmVoidPtr() {}
2015-08-19 19:52:07 -07:00
};
struct CArchMsgParmInt32Int32VoidPtr : IArchMsgParm
{
2015-08-25 18:34:56 -07:00
u32 x4_parm1;
u32 x8_parm2;
void* xc_parm3;
CArchMsgParmInt32Int32VoidPtr(u32 parm1, u32 parm2, void* parm3)
: x4_parm1(parm1), x8_parm2(parm2), xc_parm3(parm3) {}
virtual ~CArchMsgParmInt32Int32VoidPtr() {}
2015-08-19 19:52:07 -07:00
};
struct CArchMsgParmNull : IArchMsgParm
{
virtual ~CArchMsgParmNull() {}
2015-08-19 19:52:07 -07:00
};
struct CArchMsgParmReal32 : IArchMsgParm
{
2015-08-25 18:34:56 -07:00
float x4_parm;
CArchMsgParmReal32(float parm) : x4_parm(parm) {}
virtual ~CArchMsgParmReal32() {}
2015-08-19 19:52:07 -07:00
};
struct CArchMsgParmUserInput : IArchMsgParm
{
2015-08-25 18:34:56 -07:00
CFinalInput x4_parm;
CArchMsgParmUserInput(const CFinalInput& parm) : x4_parm(parm) {}
virtual ~CArchMsgParmUserInput() {}
2015-08-19 19:52:07 -07:00
};
struct CArchMsgParmControllerStatus : IArchMsgParm
{
2015-08-25 18:34:56 -07:00
u16 x4_parm1;
bool x6_parm2;
2015-08-19 19:52:07 -07:00
CArchMsgParmControllerStatus(u16 a, bool b)
2015-08-25 18:34:56 -07:00
: x4_parm1(a), x6_parm2(b) {}
virtual ~CArchMsgParmControllerStatus() {}
2015-08-19 19:52:07 -07:00
};
class CArchitectureMessage
{
2015-08-25 18:34:56 -07:00
EArchMsgTarget x0_target;
EArchMsgType x4_type;
std::shared_ptr<IArchMsgParm> x8_parm;
2015-08-19 19:52:07 -07:00
public:
CArchitectureMessage(EArchMsgTarget target, EArchMsgType type, IArchMsgParm* parm)
2015-08-25 18:34:56 -07:00
: x0_target(target), x4_type(type), x8_parm(parm) {}
2015-08-19 19:52:07 -07:00
2015-08-25 18:34:56 -07:00
EArchMsgTarget GetTarget() const {return x0_target;}
EArchMsgType GetType() const {return x4_type;}
2015-08-19 19:52:07 -07:00
template <class T>
2015-08-25 18:34:56 -07:00
const T* GetParm() const {return dynamic_cast<T*>(x8_parm.get());}
2015-08-19 19:52:07 -07:00
};
class MakeMsg
{
public:
static CArchitectureMessage CreateQuitGameplay(EArchMsgTarget target)
{
2015-11-20 17:16:07 -08:00
return CArchitectureMessage(target, EArchMsgType::QuitGameplay, new CArchMsgParmNull());
2015-08-19 19:52:07 -07:00
}
static CArchitectureMessage CreateControllerStatus(EArchMsgTarget target, u16 a, bool b)
{
2015-11-20 17:16:07 -08:00
return CArchitectureMessage(target, EArchMsgType::ControllerStatus, new CArchMsgParmControllerStatus(a, b));
2015-08-19 19:52:07 -07:00
}
static const CArchMsgParmInt32& GetParmNewGameflowState(const CArchitectureMessage& msg)
{
return *msg.GetParm<CArchMsgParmInt32>();
}
static const CArchMsgParmUserInput& GetParmUserInput(const CArchitectureMessage& msg)
{
return *msg.GetParm<CArchMsgParmUserInput>();
}
static CArchitectureMessage CreateUserInput(EArchMsgTarget target, const CFinalInput& input)
{
2015-11-20 17:16:07 -08:00
return CArchitectureMessage(target, EArchMsgType::UserInput, new CArchMsgParmUserInput(input));
2015-08-19 19:52:07 -07:00
}
static const CArchMsgParmReal32& GetParmTimerTick(const CArchitectureMessage& msg)
{
return *msg.GetParm<CArchMsgParmReal32>();
}
static CArchitectureMessage CreateTimerTick(EArchMsgTarget target, float val)
{
2015-11-20 17:16:07 -08:00
return CArchitectureMessage(target, EArchMsgType::TimerTick, new CArchMsgParmReal32(val));
2015-08-19 19:52:07 -07:00
}
static const CArchMsgParmInt32Int32VoidPtr& GetParmChangeIOWinPriority(const CArchitectureMessage& msg)
{
return *msg.GetParm<CArchMsgParmInt32Int32VoidPtr>();
}
static const CArchMsgParmInt32Int32VoidPtr& GetParmCreateIOWin(const CArchitectureMessage& msg)
{
return *msg.GetParm<CArchMsgParmInt32Int32VoidPtr>();
}
2015-08-25 18:34:56 -07:00
static CArchitectureMessage CreateCreateIOWin(EArchMsgTarget target, int pmin, int pmax, CIOWin* iowin)
2015-08-19 19:52:07 -07:00
{
2015-11-20 17:16:07 -08:00
return CArchitectureMessage(target, EArchMsgType::CreateIOWin, new CArchMsgParmInt32Int32VoidPtr(pmin, pmax, iowin));
2015-08-19 19:52:07 -07:00
}
2015-08-25 18:34:56 -07:00
static const CArchMsgParmVoidPtr& GetParmDeleteIOWin(const CArchitectureMessage& msg)
2015-08-19 19:52:07 -07:00
{
2015-08-25 18:34:56 -07:00
return *msg.GetParm<CArchMsgParmVoidPtr>();
2015-08-19 19:52:07 -07:00
}
2016-09-02 10:50:03 -07:00
static CArchitectureMessage CreateFrameBegin(EArchMsgTarget target, int a)
{
return CArchitectureMessage(target, EArchMsgType::FrameBegin, new CArchMsgParmInt32(a));
}
2016-03-04 15:04:53 -08:00
/* URDE Messages */
2016-02-19 22:45:36 -08:00
static CArchitectureMessage CreateApplicationExit(EArchMsgTarget target)
{
return CArchitectureMessage(target, EArchMsgType::ApplicationExit, new CArchMsgParmNull());
}
2015-08-19 19:52:07 -07:00
};
}
2016-04-12 23:07:23 -07:00
#endif // __URDE_CARCHITECTUREMESSAGE_HPP__