2018-10-07 03:42:33 +00:00
|
|
|
#pragma once
|
2016-04-17 22:38:05 +00:00
|
|
|
|
2019-09-23 19:00:23 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Runtime/RetroTypes.hpp"
|
|
|
|
#include "Runtime/rstl.hpp"
|
2020-03-26 05:10:51 +00:00
|
|
|
#include "Runtime/Audio/CAudioGroupSet.hpp"
|
2019-09-23 19:00:23 +00:00
|
|
|
#include "Runtime/Audio/CSfxManager.hpp"
|
|
|
|
#include "Runtime/AutoMapper/CMapWorld.hpp"
|
|
|
|
#include "Runtime/Graphics/CModel.hpp"
|
|
|
|
#include "Runtime/World/CEnvFxManager.hpp"
|
|
|
|
#include "Runtime/World/CGameArea.hpp"
|
|
|
|
#include "Runtime/World/ScriptObjectSupport.hpp"
|
2016-04-19 00:17:49 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2016-04-19 00:17:49 +00:00
|
|
|
class CGameArea;
|
2016-04-23 18:04:49 +00:00
|
|
|
class CResFactory;
|
2016-07-23 21:41:18 +00:00
|
|
|
class IGameArea;
|
2019-09-23 19:00:23 +00:00
|
|
|
class IObjectStore;
|
2016-04-17 22:38:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class IWorld {
|
2016-07-23 21:41:18 +00:00
|
|
|
public:
|
2018-12-08 05:30:43 +00:00
|
|
|
virtual ~IWorld() = default;
|
|
|
|
virtual CAssetId IGetWorldAssetId() const = 0;
|
|
|
|
virtual CAssetId IGetStringTableAssetId() const = 0;
|
|
|
|
virtual CAssetId IGetSaveWorldAssetId() const = 0;
|
|
|
|
virtual const CMapWorld* IGetMapWorld() const = 0;
|
2020-03-21 03:24:13 +00:00
|
|
|
virtual CMapWorld* IGetMapWorld() = 0;
|
2018-12-08 05:30:43 +00:00
|
|
|
virtual const IGameArea* IGetAreaAlways(TAreaId id) const = 0;
|
|
|
|
virtual TAreaId IGetCurrentAreaId() const = 0;
|
|
|
|
virtual TAreaId IGetAreaId(CAssetId id) const = 0;
|
|
|
|
virtual bool ICheckWorldComplete() = 0;
|
|
|
|
virtual std::string IGetDefaultAudioTrack() const = 0;
|
|
|
|
virtual int IGetAreaCount() const = 0;
|
2016-07-23 21:41:18 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class CDummyWorld : public IWorld {
|
|
|
|
bool x4_loadMap;
|
|
|
|
enum class Phase {
|
|
|
|
Loading,
|
|
|
|
LoadingMap,
|
|
|
|
LoadingMapAreas,
|
|
|
|
Done,
|
|
|
|
} x8_phase = Phase::Loading;
|
|
|
|
CAssetId xc_mlvlId;
|
|
|
|
CAssetId x10_strgId;
|
|
|
|
CAssetId x14_savwId;
|
|
|
|
std::vector<CDummyGameArea> x18_areas;
|
|
|
|
CAssetId x28_mapWorldId;
|
|
|
|
TLockedToken<CMapWorld> x2c_mapWorld;
|
|
|
|
std::shared_ptr<IDvdRequest> x30_loadToken;
|
|
|
|
std::unique_ptr<uint8_t[]> x34_loadBuf;
|
2019-03-09 08:58:27 +00:00
|
|
|
u32 x38_bufSz;
|
2018-12-08 05:30:43 +00:00
|
|
|
TAreaId x3c_curAreaId = kInvalidAreaId;
|
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
public:
|
2018-12-08 05:30:43 +00:00
|
|
|
CDummyWorld(CAssetId mlvlId, bool loadMap);
|
2019-08-09 12:45:18 +00:00
|
|
|
~CDummyWorld() override;
|
|
|
|
CAssetId IGetWorldAssetId() const override;
|
|
|
|
CAssetId IGetStringTableAssetId() const override;
|
|
|
|
CAssetId IGetSaveWorldAssetId() const override;
|
|
|
|
const CMapWorld* IGetMapWorld() const override;
|
2020-03-21 03:24:13 +00:00
|
|
|
CMapWorld* IGetMapWorld() override;
|
2019-08-09 12:45:18 +00:00
|
|
|
const IGameArea* IGetAreaAlways(TAreaId id) const override;
|
|
|
|
TAreaId IGetCurrentAreaId() const override;
|
|
|
|
TAreaId IGetAreaId(CAssetId id) const override;
|
|
|
|
bool ICheckWorldComplete() override;
|
|
|
|
std::string IGetDefaultAudioTrack() const override;
|
|
|
|
int IGetAreaCount() const override;
|
2016-07-23 21:41:18 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class CWorld : public IWorld {
|
|
|
|
friend class CStateManager;
|
2016-07-24 04:46:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
public:
|
|
|
|
class CRelay {
|
|
|
|
TEditorId x0_relay = kInvalidEditorId;
|
|
|
|
TEditorId x4_target = kInvalidEditorId;
|
|
|
|
s16 x8_msg = -1;
|
|
|
|
bool xa_active = false;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CRelay() = default;
|
2020-03-26 01:25:11 +00:00
|
|
|
explicit CRelay(CInputStream& in);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
TEditorId GetRelayId() const { return x0_relay; }
|
|
|
|
TEditorId GetTargetId() const { return x4_target; }
|
|
|
|
s16 GetMessage() const { return x8_msg; }
|
|
|
|
bool GetActive() const { return xa_active; }
|
|
|
|
|
|
|
|
static std::vector<CWorld::CRelay> ReadMemoryRelays(athena::io::MemoryReader& r);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CSoundGroupData {
|
|
|
|
int x0_groupId;
|
|
|
|
CAssetId x4_agscId;
|
|
|
|
std::string xc_name;
|
|
|
|
TCachedToken<CAudioGroupSet> x1c_groupData;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CSoundGroupData(int grpId, CAssetId agsc);
|
|
|
|
};
|
2016-07-24 04:46:32 +00:00
|
|
|
|
2016-05-03 08:27:28 +00:00
|
|
|
private:
|
2018-12-08 05:30:43 +00:00
|
|
|
enum class Phase {
|
|
|
|
Loading,
|
|
|
|
LoadingMap,
|
|
|
|
LoadingMapAreas,
|
|
|
|
LoadingSkyBox,
|
|
|
|
LoadingSoundGroups,
|
|
|
|
Done,
|
|
|
|
} x4_phase = Phase::Loading;
|
|
|
|
CAssetId x8_mlvlId;
|
|
|
|
CAssetId xc_strgId;
|
|
|
|
CAssetId x10_savwId;
|
|
|
|
std::vector<std::unique_ptr<CGameArea>> x18_areas;
|
|
|
|
CAssetId x24_mapwId;
|
|
|
|
TLockedToken<CMapWorld> x28_mapWorld;
|
|
|
|
std::vector<CRelay> x2c_relays;
|
2019-03-09 08:58:27 +00:00
|
|
|
std::shared_ptr<IDvdRequest> x3c_loadToken;
|
2018-12-08 05:30:43 +00:00
|
|
|
std::unique_ptr<uint8_t[]> x40_loadBuf;
|
2019-03-09 08:58:27 +00:00
|
|
|
u32 x44_bufSz;
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 x48_chainCount = 0;
|
|
|
|
CGameArea* x4c_chainHeads[5] = {};
|
|
|
|
|
|
|
|
IObjectStore& x60_objectStore;
|
|
|
|
IFactory& x64_resFactory;
|
|
|
|
TAreaId x68_curAreaId = kInvalidAreaId;
|
|
|
|
u32 x6c_loadedAudioGrpCount = 0;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
bool x70_24_currentAreaNeedsAllocation : 1;
|
|
|
|
bool x70_25_loadPaused : 1;
|
|
|
|
bool x70_26_skyboxActive : 1;
|
|
|
|
bool x70_27_skyboxVisible : 1;
|
2016-04-23 18:04:49 +00:00
|
|
|
};
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 dummy = 0;
|
|
|
|
};
|
|
|
|
std::vector<CSoundGroupData> x74_soundGroupData;
|
|
|
|
std::string x84_defAudioTrack;
|
2019-11-06 17:33:45 +00:00
|
|
|
std::optional<TLockedToken<CModel>> x94_skyboxWorld;
|
|
|
|
std::optional<TLockedToken<CModel>> xa4_skyboxWorldLoaded;
|
|
|
|
std::optional<TLockedToken<CModel>> xb4_skyboxOverride;
|
2018-12-08 05:30:43 +00:00
|
|
|
EEnvFxType xc4_neededFx = EEnvFxType::None;
|
|
|
|
rstl::reserved_vector<CSfxHandle, 10> xc8_globalSfxHandles;
|
|
|
|
|
|
|
|
void LoadSoundGroup(int groupId, CAssetId agscId, CSoundGroupData& data);
|
|
|
|
void LoadSoundGroups();
|
|
|
|
void UnloadSoundGroups();
|
|
|
|
void StopSounds();
|
2016-04-23 18:04:49 +00:00
|
|
|
|
2016-05-03 08:27:28 +00:00
|
|
|
public:
|
2018-12-08 05:30:43 +00:00
|
|
|
void MoveToChain(CGameArea* area, EChain chain);
|
|
|
|
void MoveAreaToAliveChain(TAreaId aid);
|
|
|
|
bool CheckWorldComplete(CStateManager* mgr, TAreaId id, CAssetId mreaId);
|
2020-03-26 01:25:11 +00:00
|
|
|
|
|
|
|
[[nodiscard]] auto GetChainHead(EChain chain) { return CGameArea::CChainIterator{x4c_chainHeads[size_t(chain)]}; }
|
|
|
|
[[nodiscard]] auto GetChainHead(EChain chain) const {
|
|
|
|
return CGameArea::CConstChainIterator{x4c_chainHeads[size_t(chain)]};
|
|
|
|
}
|
|
|
|
[[nodiscard]] auto begin() { return GetChainHead(EChain::Alive); }
|
|
|
|
[[nodiscard]] auto end() { return AliveAreasEnd(); }
|
|
|
|
[[nodiscard]] auto begin() const { return GetChainHead(EChain::Alive); }
|
|
|
|
[[nodiscard]] auto end() const { return GetAliveAreasEnd(); }
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool ScheduleAreaToLoad(CGameArea* area, CStateManager& mgr);
|
2020-03-25 05:27:53 +00:00
|
|
|
void TravelToArea(TAreaId aid, CStateManager& mgr, bool skipLoadOther);
|
2018-12-08 05:30:43 +00:00
|
|
|
void SetLoadPauseState(bool paused);
|
|
|
|
void CycleLoadPauseState();
|
|
|
|
|
|
|
|
CWorld(IObjectStore& objStore, IFactory& resFactory, CAssetId mlvlId);
|
|
|
|
~CWorld();
|
|
|
|
bool DoesAreaExist(TAreaId area) const;
|
|
|
|
const std::vector<std::unique_ptr<CGameArea>>& GetGameAreas() const { 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]; }
|
|
|
|
|
2019-08-09 12:45:18 +00:00
|
|
|
CAssetId IGetWorldAssetId() const override;
|
|
|
|
CAssetId IGetStringTableAssetId() const override;
|
|
|
|
CAssetId IGetSaveWorldAssetId() const override;
|
|
|
|
const CMapWorld* IGetMapWorld() const override;
|
2020-03-21 03:24:13 +00:00
|
|
|
CMapWorld* IGetMapWorld() override;
|
2020-03-25 05:27:53 +00:00
|
|
|
const CGameArea* GetAreaAlways(TAreaId id) const;
|
2018-12-08 05:30:43 +00:00
|
|
|
CGameArea* GetArea(TAreaId);
|
|
|
|
s32 GetNumAreas() const { return x18_areas.size(); }
|
2019-08-09 12:45:18 +00:00
|
|
|
const IGameArea* IGetAreaAlways(TAreaId id) const override;
|
|
|
|
TAreaId IGetCurrentAreaId() const override;
|
2018-12-08 05:30:43 +00:00
|
|
|
TAreaId GetCurrentAreaId() const { return x68_curAreaId; }
|
2019-08-09 12:45:18 +00:00
|
|
|
TAreaId IGetAreaId(CAssetId id) const override;
|
|
|
|
bool ICheckWorldComplete() override;
|
|
|
|
std::string IGetDefaultAudioTrack() const override;
|
|
|
|
int IGetAreaCount() const override;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-03-25 05:27:53 +00:00
|
|
|
static void PropogateAreaChain(CGameArea::EOcclusionState occlusionState, CGameArea* area, CWorld* world);
|
2020-03-26 01:25:11 +00:00
|
|
|
static constexpr CGameArea::CConstChainIterator GetAliveAreasEnd() { return CGameArea::CConstChainIterator{}; }
|
|
|
|
static constexpr CGameArea::CChainIterator AliveAreasEnd() { return CGameArea::CChainIterator{}; }
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
void Update(float dt);
|
|
|
|
void PreRender();
|
|
|
|
void TouchSky();
|
|
|
|
void DrawSky(const zeus::CTransform& xf) const;
|
|
|
|
void StopGlobalSound(u16 id);
|
|
|
|
bool HasGlobalSound(u16 id) const;
|
|
|
|
void AddGlobalSound(const CSfxHandle& hnd);
|
|
|
|
EEnvFxType GetNeededEnvFx() const { return xc4_neededFx; }
|
|
|
|
CAssetId GetWorldAssetId() const { return x8_mlvlId; }
|
|
|
|
bool AreSkyNeedsMet() const;
|
|
|
|
TAreaId GetAreaIdForSaveId(s32 saveId) const;
|
2016-07-23 21:41:18 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
struct CWorldLayers {
|
|
|
|
struct Area {
|
|
|
|
u32 m_startNameIdx;
|
|
|
|
u32 m_layerCount;
|
|
|
|
u64 m_layerBits;
|
|
|
|
};
|
|
|
|
std::vector<Area> m_areas;
|
|
|
|
std::vector<std::string> m_names;
|
|
|
|
static void ReadWorldLayers(athena::io::MemoryReader& r, int version, CAssetId mlvlId);
|
2016-04-17 22:38:05 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|