various implementation

This commit is contained in:
Jack Andersen 2015-08-18 19:48:57 -10:00
parent b9c3c8138e
commit e1d45fd01c
14 changed files with 300 additions and 10 deletions

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
project(RetroCommon) project(RetroCommon)
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(hecl) project(RetroCommon)
if(MSVC) if(MSVC)
# Shaddup MSVC # Shaddup MSVC
add_definitions(-DUNICODE=1 -D_UNICODE=1 -D_CRT_SECURE_NO_WARNINGS=1 /wd4267 /wd4244) add_definitions(-DUNICODE=1 -D_UNICODE=1 -D_CRT_SECURE_NO_WARNINGS=1 /wd4267 /wd4244)

View File

@ -4,7 +4,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include "RetroTemplates.hpp" #include "RetroTypes.hpp"
#include <Athena/IStreamReader.hpp> #include <Athena/IStreamReader.hpp>
#include <Athena/IStreamWriter.hpp> #include <Athena/IStreamWriter.hpp>

50
Runtime/CEntity.cpp Normal file
View File

@ -0,0 +1,50 @@
#include "CEntity.hpp"
namespace Retro
{
CEntity::CEntity(TUniqueId uniqueId, const CEntityInfo& info, bool active)
: m_uid(uniqueId), m_info(info), m_active(active) {}
void CEntity::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr)
{
switch (msg)
{
case MsgActivate:
if (!GetActive())
{
SetActive(true);
SendScriptMsgs(StActive, stateMgr, MsgNone);
}
break;
case MsgDeactivate:
if (GetActive())
{
SetActive(false);
SendScriptMsgs(StInactive, stateMgr, MsgNone);
}
break;
case MsgToggleActive:
if (GetActive())
{
SetActive(false);
SendScriptMsgs(StInactive, stateMgr, MsgNone);
}
else
{
SetActive(true);
SendScriptMsgs(StActive, stateMgr, MsgNone);
}
break;
default: break;
}
}
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);
}
}

48
Runtime/CEntity.hpp Normal file
View File

@ -0,0 +1,48 @@
#ifndef __RETRO_CENTITY_HPP__
#define __RETRO_CENTITY_HPP__
#include "RetroTypes.hpp"
#include "ScriptObjectSupport.hpp"
#include "CStateManager.hpp"
namespace Retro
{
struct SConnection
{
EScriptObjectState state;
EScriptObjectMessage msg;
TEditorId objId;
};
class CEntityInfo
{
friend class CEntity;
TAreaId m_aid;
std::vector<SConnection> m_conns;
public:
CEntityInfo(TAreaId aid, const std::vector<SConnection>& conns)
: m_aid(aid), m_conns(conns) {}
};
class CEntity
{
protected:
TUniqueId m_uid;
CEntityInfo m_info;
bool m_active = false;
public:
virtual ~CEntity() {}
CEntity(TUniqueId uid, const CEntityInfo& info, bool active);
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;}
void SendScriptMsgs(EScriptObjectState state, CStateManager& stateMgr, EScriptObjectMessage msg);
};
}
#endif // __RETRO_CENTITY_HPP__

View File

@ -31,9 +31,12 @@ add_library(RuntimeCommon
CGameOptions.hpp CGameOptions.cpp CGameOptions.hpp CGameOptions.cpp
CStaticInterference.hpp CStaticInterference.cpp CStaticInterference.hpp CStaticInterference.cpp
CCRC32.hpp CCRC32.cpp CCRC32.hpp CCRC32.cpp
CEntity.hpp CEntity.cpp
IFactory.hpp IFactory.hpp
ScriptObjectSupport.hpp ScriptObjectSupport.cpp
CObjectList.hpp CObjectList.cpp
GameGlobalObjects.hpp GameGlobalObjects.hpp
RetroTemplates.hpp RetroTypes.hpp
GCNTypes.hpp) GCNTypes.hpp)
add_subdirectory(MP1) add_subdirectory(MP1)

0
Runtime/CObjectList.cpp Normal file
View File

98
Runtime/CObjectList.hpp Normal file
View File

@ -0,0 +1,98 @@
#ifndef __RETRO_COBJECTLIST_HPP__
#define __RETRO_COBJECTLIST_HPP__
#include "CEntity.hpp"
#include "RetroTypes.hpp"
namespace Retro
{
enum EGameObjectList
{
ListAll,
ListActor,
ListPhysicsActor,
ListGameCamera,
ListGameLight,
ListListeningAi,
ListAiWaypoint,
ListPlatformAndDoor,
};
class CObjectList
{
struct SObjectListEntry
{
CEntity* entity = nullptr;
TUniqueId prev = -1;
TUniqueId next = -1;
};
SObjectListEntry m_list[1024];
EGameObjectList m_listEnum;
TUniqueId m_lastId = -1;
u16 m_count = 0;
public:
CObjectList(EGameObjectList listEnum)
: m_listEnum(listEnum)
{}
void AddObject(CEntity& entity)
{
if (IsQualified())
{
if (m_lastId != -1)
m_list[m_lastId].next = entity.m_uid & 0x3ff;
TUniqueId prevLast = m_lastId;
m_lastId = entity.m_uid & 0x3ff;
SObjectListEntry& newEnt = m_list[m_lastId];
newEnt.entity = &entity;
newEnt.prev = prevLast;
newEnt.next = -1;
++m_count;
}
}
void RemoveObject(TUniqueId uid)
{
uid = uid & 0x3ff;
SObjectListEntry& ent = m_list[uid];
if (!ent.entity || ent.entity->m_uid != uid)
return;
if (uid == m_lastId)
{
m_lastId = ent.prev;
if (ent.prev != -1)
m_list[ent.prev].next = -1;
}
else
{
if (ent.prev != -1)
m_list[ent.prev].next = -1;
m_list[ent.next].prev = -1;
}
ent.entity = nullptr;
ent.prev = -1;
ent.next = -1;
--m_count;
}
const CEntity* GetObjectById(TUniqueId uid) const
{
if (!uid)
return nullptr;
return m_list[uid & 0x3ff].entity;
}
CEntity* GetObjectById(TUniqueId uid)
{
if (!uid)
return nullptr;
return m_list[uid & 0x3ff].entity;
}
virtual bool IsQualified() {return true;}
};
}
#endif // __RETRO_COBJECTLIST_HPP__

View File

@ -1,7 +1,7 @@
#ifndef __RETRO_CPLAYERSTATE_HPP__ #ifndef __RETRO_CPLAYERSTATE_HPP__
#define __RETRO_CPLAYERSTATE_HPP__ #define __RETRO_CPLAYERSTATE_HPP__
#include "RetroTemplates.hpp" #include "RetroTypes.hpp"
#include "CStaticInterference.hpp" #include "CStaticInterference.hpp"
namespace Retro namespace Retro

View File

@ -3,4 +3,8 @@
namespace Retro namespace Retro
{ {
void CStateManager::SendScriptMsg(TUniqueId uid, TEditorId eid, EScriptObjectMessage msg, EScriptObjectState state)
{
}
} }

View File

@ -7,6 +7,7 @@
#include "CMapWorldInfo.hpp" #include "CMapWorldInfo.hpp"
#include "CPlayerState.hpp" #include "CPlayerState.hpp"
#include "CWorldTransManager.hpp" #include "CWorldTransManager.hpp"
#include "ScriptObjectSupport.hpp"
namespace Retro namespace Retro
{ {
@ -18,6 +19,15 @@ public:
const std::weak_ptr<CMapWorldInfo>&, const std::weak_ptr<CMapWorldInfo>&,
const std::weak_ptr<CPlayerState>&, const std::weak_ptr<CPlayerState>&,
const std::weak_ptr<CWorldTransManager>&); const std::weak_ptr<CWorldTransManager>&);
void GetObjectListById() const
{
}
void GetObjectById(TUniqueId uid) const
{
}
void SendScriptMsg(TUniqueId uid, TEditorId eid, EScriptObjectMessage msg, EScriptObjectState state);
}; };
} }

View File

@ -1,5 +1,5 @@
#ifndef __RETRO_TEMPLATES_HPP__ #ifndef __RETRO_TYPES_HPP__
#define __RETRO_TEMPLATES_HPP__ #define __RETRO_TYPES_HPP__
#include <utility> #include <utility>
#include "GCNTypes.hpp" #include "GCNTypes.hpp"
@ -8,13 +8,13 @@ namespace Retro
{ {
/** /**
* @brief Inheritable singleton static-allocator * @brief singleton static-allocator
*/ */
template<class T> template<class T>
class TOneStatic class TOneStatic
{ {
static u8 m_allocspace[sizeof(T)]; static u8 m_allocspace[sizeof(T)];
static uint32_t m_refCount; static u32 m_refCount;
public: public:
static T* GetAllocSpace() {return (T*)m_allocspace;} static T* GetAllocSpace() {return (T*)m_allocspace;}
static u32& ReferenceCount() {return m_refCount;} static u32& ReferenceCount() {return m_refCount;}
@ -42,6 +42,10 @@ public:
template<class T> u8 TOneStatic<T>::m_allocspace[sizeof(T)]; template<class T> u8 TOneStatic<T>::m_allocspace[sizeof(T)];
template<class T> u32 TOneStatic<T>::m_refCount; template<class T> u32 TOneStatic<T>::m_refCount;
using TUniqueId = s16;
using TEditorId = u32;
using TAreaId = u32;
} }
#endif // __RETRO_TEMPLATES_HPP__ #endif // __RETRO_TYPES_HPP__

View File

View File

@ -0,0 +1,73 @@
#ifndef __SCRIPT_OBJECT_SUPPORT_HPP__
#define __SCRIPT_OBJECT_SUPPORT_HPP__
namespace Retro
{
enum EScriptObjectState
{
StActive,
StArrived,
StClosed,
StEntered,
StExited,
StInactive,
StInside,
StMaxReached,
StOpen,
StZero,
StAttack,
StUNKS1,
StRetreat,
StPatrol,
StDead,
StCameraPath,
StCameraTarget,
StUNKS2,
StPlay,
StUNKS3,
StDeathRattle,
StUNKS4,
StDamage,
StUNKS6,
StUNKS5,
StModify,
StUNKS7,
StUNKS8,
StScanDone,
StUNKS9,
StDFST,
StReflectedDamage,
StInheritBounds
};
enum EScriptObjectMessage
{
MsgNone = -1,
MsgUNKM1 = 0,
MsgActivate,
MsgUNKM2,
MsgClose,
MsgDeactivate,
MsgDecrement,
MsgFollow,
MsgIncrement,
MsgNext,
MsgOpen,
MsgReset,
MsgResetAndStart,
MsgSetToMax,
MsgSetToZero,
MsgStart,
MsgStop,
MsgStopAndReset,
MsgToggleActive,
MsgUNKM3,
MsgAction,
MsgPlay,
MsgAlert
};
}
#endif // __SCRIPT_OBJECT_SUPPORT_HPP__

2
libBoo

@ -1 +1 @@
Subproject commit 2c2991d44ec275a31974e42eadfbcdd68c32a400 Subproject commit 3a6dd3f6b8277ffc0a3a34a933006176024c900a