mirror of https://github.com/AxioDL/metaforce.git
More GameState imps
This commit is contained in:
parent
37a2d81ff2
commit
f73b1b641f
|
@ -58,7 +58,7 @@ add_library(RuntimeCommon
|
|||
CWeaponMgr.hpp CWeaponMgr.cpp
|
||||
CFluidPlaneManager.hpp CFluidPlaneManager.cpp
|
||||
CGameState.hpp CGameState.cpp
|
||||
CScriptMailbox.hpp CScriptMailbox.cpp
|
||||
CRelayTracker.hpp CRelayTracker.cpp
|
||||
CPlayerState.hpp CPlayerState.cpp
|
||||
CRandom16.hpp CRandom16.cpp
|
||||
CResFactory.hpp CResFactory.cpp
|
||||
|
|
|
@ -120,8 +120,6 @@ static const float unk[]
|
|||
|
||||
float CPlayerState::sub_80091204() const
|
||||
{
|
||||
|
||||
|
||||
return unk[u32(x8_currentBeam)];
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
#include "CRelayTracker.hpp"
|
||||
#include "CStateManager.hpp"
|
||||
#include "CSaveWorld.hpp"
|
||||
#include "World/CWorld.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
CRelayTracker::CRelayTracker(CBitStreamReader& in, const CSaveWorld& saveworld)
|
||||
{
|
||||
u32 relayCount = saveworld.GetRelayCount();
|
||||
if (saveworld.GetRelayCount())
|
||||
{
|
||||
std::vector<bool> relayStates(saveworld.GetRelayCount());
|
||||
for (u32 i=0 ; i<relayCount ; ++i)
|
||||
relayStates[i] = in.ReadEncoded(1);
|
||||
|
||||
for (u32 i=0 ; i<relayCount ; ++i)
|
||||
{
|
||||
if (!relayStates[i])
|
||||
continue;
|
||||
x0_relayStates.push_back(saveworld.GetRelayEditorId(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CRelayTracker::HasRelay(TEditorId id)
|
||||
{
|
||||
return std::find(x0_relayStates.begin(), x0_relayStates.end(), id) != x0_relayStates.end();
|
||||
}
|
||||
|
||||
void CRelayTracker::AddRelay(TEditorId id)
|
||||
{
|
||||
if (std::find(x0_relayStates.begin(), x0_relayStates.end(), id) == x0_relayStates.end())
|
||||
x0_relayStates.push_back(id);
|
||||
}
|
||||
|
||||
void CRelayTracker::RemoveRelay(TEditorId id)
|
||||
{
|
||||
if (std::find(x0_relayStates.begin(), x0_relayStates.end(), id) != x0_relayStates.end())
|
||||
x0_relayStates.erase(std::remove(x0_relayStates.begin(), x0_relayStates.end(), id), x0_relayStates.end());
|
||||
}
|
||||
|
||||
void CRelayTracker::SendMsgs(const TAreaId& areaId, CStateManager& stateMgr)
|
||||
{
|
||||
const CWorld* world = stateMgr.GetWorld();
|
||||
u32 relayCount = world->GetRelayCount();
|
||||
|
||||
bool hasInactiveRelays = false;
|
||||
for (u32 i=0 ; i<relayCount ; ++i)
|
||||
{
|
||||
const CWorld::CRelay& relay = world->GetRelay(i);
|
||||
if (((relay.GetRelayId() >> 16) & 0x3FF) != areaId)
|
||||
continue;
|
||||
|
||||
if (!HasRelay(relay.GetRelayId()))
|
||||
continue;
|
||||
|
||||
stateMgr.SendScriptMsg(kInvalidUniqueId, relay.GetTargetId(), EScriptObjectMessage(relay.GetMessage()),
|
||||
EScriptObjectState::Any);
|
||||
if (!relay.GetActive())
|
||||
hasInactiveRelays = true;
|
||||
}
|
||||
|
||||
if (!hasInactiveRelays)
|
||||
return;
|
||||
|
||||
for (u32 i=0 ; i<relayCount ; ++i)
|
||||
{
|
||||
const CWorld::CRelay& relay = world->GetRelay(i);
|
||||
if (((relay.GetRelayId() >> 16) & 0x3FF) != areaId)
|
||||
continue;
|
||||
|
||||
if (!HasRelay(relay.GetRelayId()))
|
||||
continue;
|
||||
|
||||
RemoveRelay(relay.GetRelayId());
|
||||
}
|
||||
}
|
||||
|
||||
void CRelayTracker::PutTo(CBitStreamWriter& out, const CSaveWorld& saveworld)
|
||||
{
|
||||
u32 relayCount = saveworld.GetRelayCount();
|
||||
std::vector<bool> relays(relayCount);
|
||||
|
||||
for (const TEditorId& id : x0_relayStates)
|
||||
relays[saveworld.GetRelayIndex(id)] = true;
|
||||
|
||||
for (u32 i=0 ; i<relayCount ; ++i)
|
||||
out.WriteEncoded(u32(relays[i]), 1);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef __URDE_CSCRIPTMAILBOX_HPP__
|
||||
#define __URDE_CSCRIPTMAILBOX_HPP__
|
||||
#ifndef __URDE_CRELAYTRACKER_HPP__
|
||||
#define __URDE_CRELAYTRACKER_HPP__
|
||||
|
||||
#include "IOStreams.hpp"
|
||||
#include "World/ScriptObjectSupport.hpp"
|
||||
|
@ -8,6 +8,8 @@
|
|||
namespace urde
|
||||
{
|
||||
class CStateManager;
|
||||
class CSaveWorld;
|
||||
#if 0
|
||||
struct CMailMessage
|
||||
{
|
||||
TEditorId x0_id;
|
||||
|
@ -19,20 +21,23 @@ struct CMailMessage
|
|||
bool operator==(const CMailMessage& other) const
|
||||
{ return (x0_id == other.x0_id && x4_msg == other.x4_msg); }
|
||||
};
|
||||
#endif
|
||||
|
||||
class CScriptMailbox
|
||||
|
||||
class CRelayTracker
|
||||
{
|
||||
rstl::reserved_vector<CMailMessage, 1024> x0_messages;
|
||||
std::vector<TEditorId> x0_relayStates;
|
||||
public:
|
||||
CScriptMailbox() = default;
|
||||
CScriptMailbox(CBitStreamReader&);
|
||||
CRelayTracker() = default;
|
||||
CRelayTracker(CBitStreamReader&, const CSaveWorld&);
|
||||
|
||||
void AddMsg(TEditorId, EScriptObjectMessage, bool);
|
||||
void RemoveMsg(TEditorId, EScriptObjectMessage, bool);
|
||||
bool HasRelay(TEditorId);
|
||||
void AddRelay(TEditorId);
|
||||
void RemoveRelay(TEditorId);
|
||||
void SendMsgs(const TAreaId&, CStateManager&);
|
||||
void PutTo(CBitStreamWriter&);
|
||||
void PutTo(CBitStreamWriter&, const CSaveWorld&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __URDE_CSCRIPTMAILBOX_HPP__
|
||||
#endif // __URDE_CRELAYTRACKER_HPP__
|
|
@ -61,11 +61,10 @@ u32 CSaveWorld::GetCinematicCount() const
|
|||
|
||||
s32 CSaveWorld::GetCinematicIndex(const TEditorId &id) const
|
||||
{
|
||||
for (u32 i=0 ; i<x4_cinematics.size() ; ++i)
|
||||
if (x4_cinematics.at(i) == id)
|
||||
return i;
|
||||
|
||||
auto it = std::find(x4_cinematics.begin(), x4_cinematics.end(), id);
|
||||
if (it == x4_cinematics.end())
|
||||
return -1;
|
||||
return x4_cinematics.begin() - it;
|
||||
}
|
||||
|
||||
u32 CSaveWorld::GetRelayCount() const
|
||||
|
@ -75,11 +74,15 @@ u32 CSaveWorld::GetRelayCount() const
|
|||
|
||||
s32 CSaveWorld::GetRelayIndex(const TEditorId &id) const
|
||||
{
|
||||
for (u32 i=0 ; i<x14_relays.size() ; ++i)
|
||||
if (x14_relays.at(i) == id)
|
||||
return i;
|
||||
|
||||
auto it = std::find(x14_relays.begin(), x14_relays.end(), id);
|
||||
if (it == x14_relays.end())
|
||||
return -1;
|
||||
return x14_relays.begin() - it;
|
||||
}
|
||||
|
||||
TEditorId CSaveWorld::GetRelayEditorId(u32 idx) const
|
||||
{
|
||||
return x14_relays[idx];
|
||||
}
|
||||
|
||||
u32 CSaveWorld::GetDoorCount() const
|
||||
|
@ -89,11 +92,10 @@ u32 CSaveWorld::GetDoorCount() const
|
|||
|
||||
s32 CSaveWorld::GetDoorIndex(const TEditorId &id) const
|
||||
{
|
||||
for (u32 i=0 ; i<x34_doors.size() ; ++i)
|
||||
if (x34_doors.at(i) == id)
|
||||
return i;
|
||||
|
||||
auto it = std::find(x34_doors.begin(), x34_doors.end(), id);
|
||||
if (it == x34_doors.end())
|
||||
return -1;
|
||||
return x34_doors.begin() - it;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
s32 GetCinematicIndex(const TEditorId& id) const;
|
||||
u32 GetRelayCount() const;
|
||||
s32 GetRelayIndex(const TEditorId& id) const;
|
||||
TEditorId GetRelayEditorId(u32 idx) const;
|
||||
u32 GetDoorCount() const;
|
||||
s32 GetDoorIndex(const TEditorId &id) const;
|
||||
};
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
#include "CScriptMailbox.hpp"
|
||||
#include "CStateManager.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
CScriptMailbox::CScriptMailbox(CBitStreamReader&)
|
||||
{
|
||||
}
|
||||
|
||||
void CScriptMailbox::AddMsg(TEditorId id, EScriptObjectMessage msg, bool flag)
|
||||
{
|
||||
/* TODO: Verify this behavior */
|
||||
CMailMessage mail{id, msg, flag};
|
||||
auto it = std::find(x0_messages.begin(), x0_messages.end(), mail);
|
||||
|
||||
if (it != x0_messages.end())
|
||||
*it = mail;
|
||||
else
|
||||
x0_messages.push_back(mail);
|
||||
}
|
||||
|
||||
void CScriptMailbox::RemoveMsg(TEditorId id, EScriptObjectMessage msg, bool flag)
|
||||
{
|
||||
CMailMessage mail{id, msg, flag};
|
||||
auto it = std::find(x0_messages.begin(), x0_messages.end(), mail);
|
||||
if (it != x0_messages.end())
|
||||
x0_messages.erase(it);
|
||||
}
|
||||
|
||||
void CScriptMailbox::SendMsgs(const TAreaId& areaId, CStateManager& stateMgr)
|
||||
{
|
||||
}
|
||||
|
||||
void CScriptMailbox::PutTo(CBitStreamWriter&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
namespace urde
|
||||
{
|
||||
|
||||
CStateManager::CStateManager(const std::weak_ptr<CScriptMailbox>&,
|
||||
CStateManager::CStateManager(const std::weak_ptr<CRelayTracker>&,
|
||||
const std::weak_ptr<CMapWorldInfo>&,
|
||||
const std::weak_ptr<CPlayerState>&,
|
||||
const std::weak_ptr<CWorldTransManager>&)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
namespace urde
|
||||
{
|
||||
class CScriptMailbox;
|
||||
class CRelayTracker;
|
||||
class CMapWorldInfo;
|
||||
class CPlayerState;
|
||||
class CWorldTransManager;
|
||||
|
@ -78,7 +78,7 @@ class CStateManager
|
|||
std::map<TEditorId, SScriptObjectStream> x8a4_loadedScriptObjects;
|
||||
|
||||
std::shared_ptr<CPlayerState> x8b8_playerState;
|
||||
std::shared_ptr<CScriptMailbox> x8bc_scriptMailbox;
|
||||
std::shared_ptr<CRelayTracker> x8bc_scriptMailbox;
|
||||
std::shared_ptr<CMapWorldInfo> x8c0_mapWorldInfo;
|
||||
std::shared_ptr<CWorldTransManager> x8c4_worldTransManager;
|
||||
|
||||
|
@ -139,7 +139,7 @@ public:
|
|||
{
|
||||
};
|
||||
|
||||
CStateManager(const std::weak_ptr<CScriptMailbox>&,
|
||||
CStateManager(const std::weak_ptr<CRelayTracker>&,
|
||||
const std::weak_ptr<CMapWorldInfo>&,
|
||||
const std::weak_ptr<CPlayerState>&,
|
||||
const std::weak_ptr<CWorldTransManager>&);
|
||||
|
|
|
@ -166,6 +166,8 @@ public:
|
|||
std::vector<std::unique_ptr<CGameArea>>& GetGameAreas() {return x18_areas;}
|
||||
|
||||
const CMapWorld* GetMapWorld() const {return x28_mapWorld.GetObj();}
|
||||
u32 GetRelayCount() const { return x2c_relays.size(); }
|
||||
CRelay GetRelay(u32 idx) const { return x2c_relays[idx]; }
|
||||
|
||||
ResId IGetWorldAssetId() const;
|
||||
ResId IGetStringTableAssetId() const;
|
||||
|
|
Loading…
Reference in New Issue