2016-04-24 02:46:13 +00:00
|
|
|
#include "CWorld.hpp"
|
2016-07-23 21:41:18 +00:00
|
|
|
#include "CSimplePool.hpp"
|
2016-07-24 04:46:32 +00:00
|
|
|
#include "CStateManager.hpp"
|
|
|
|
#include "CInGameTweakManagerBase.hpp"
|
2016-08-01 04:35:42 +00:00
|
|
|
#include "Audio/CAudioGroupSet.hpp"
|
2017-02-08 06:48:43 +00:00
|
|
|
#include "CGameState.hpp"
|
2017-03-04 04:31:08 +00:00
|
|
|
#include "Graphics/CBooRenderer.hpp"
|
2017-09-12 15:27:48 +00:00
|
|
|
#include "World/CScriptAreaAttributes.hpp"
|
2016-04-24 02:46:13 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CWorld::CSoundGroupData::CSoundGroupData(int grpId, CAssetId agsc) : x0_groupId(grpId), x4_agscId(agsc)
|
2016-07-24 22:51:15 +00:00
|
|
|
{
|
|
|
|
x1c_groupData = g_SimplePool->GetObj(SObjectTag{FOURCC('AGSC'), agsc});
|
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CDummyWorld::CDummyWorld(CAssetId mlvlId, bool loadMap) : x4_loadMap(loadMap), xc_mlvlId(mlvlId)
|
2016-07-23 21:41:18 +00:00
|
|
|
{
|
|
|
|
SObjectTag tag{FOURCC('MLVL'), mlvlId};
|
2016-08-08 04:48:18 +00:00
|
|
|
static_cast<ProjectResourceFactoryBase*>(g_ResFactory)->LoadResourceAsync(tag, x34_loadBuf);
|
2016-07-23 21:41:18 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId CDummyWorld::IGetWorldAssetId() const { return xc_mlvlId; }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId CDummyWorld::IGetStringTableAssetId() const { return x10_strgId; }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId CDummyWorld::IGetSaveWorldAssetId() const { return x14_savwId; }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
const CMapWorld* CDummyWorld::IGetMapWorld() const { return x2c_mapWorld.GetObj(); }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
CMapWorld* CDummyWorld::IMapWorld() { return x2c_mapWorld.GetObj(); }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
const IGameArea* CDummyWorld::IGetAreaAlways(TAreaId id) const { return &x18_areas.at(id); }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
TAreaId CDummyWorld::IGetCurrentAreaId() const { return x3c_curAreaId; }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
TAreaId CDummyWorld::IGetAreaId(CAssetId id) const
|
2016-07-23 21:41:18 +00:00
|
|
|
{
|
2016-07-24 04:46:32 +00:00
|
|
|
int ret = 0;
|
|
|
|
if (id == -1)
|
|
|
|
return kInvalidAreaId;
|
|
|
|
for (const CDummyGameArea& area : x18_areas)
|
|
|
|
{
|
|
|
|
if (area.xc_mrea == id)
|
|
|
|
return ret;
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return kInvalidAreaId;
|
2016-07-23 21:41:18 +00:00
|
|
|
}
|
|
|
|
|
2016-08-09 03:58:19 +00:00
|
|
|
CWorld::CRelay::CRelay(CInputStream& in)
|
|
|
|
{
|
|
|
|
x0_relay = in.readUint32Big();
|
|
|
|
x4_target = in.readUint32Big();
|
|
|
|
x8_msg = in.readUint16Big();
|
|
|
|
xa_active = in.readBool();
|
|
|
|
}
|
|
|
|
|
2016-07-24 04:46:32 +00:00
|
|
|
std::vector<CWorld::CRelay> CWorld::CRelay::ReadMemoryRelays(athena::io::MemoryReader& r)
|
2016-07-23 21:41:18 +00:00
|
|
|
{
|
|
|
|
std::vector<CWorld::CRelay> ret;
|
|
|
|
u32 count = r.readUint32Big();
|
|
|
|
ret.reserve(count);
|
2017-01-07 01:58:05 +00:00
|
|
|
for (u32 i = 0; i < count; ++i)
|
2016-07-23 21:41:18 +00:00
|
|
|
ret.emplace_back(r);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
void CWorldLayers::ReadWorldLayers(athena::io::MemoryReader& r, int version, CAssetId mlvlId)
|
2016-07-23 21:41:18 +00:00
|
|
|
{
|
2017-02-08 06:48:43 +00:00
|
|
|
if (version <= 14)
|
|
|
|
return;
|
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
CWorldLayers ret;
|
|
|
|
|
|
|
|
u32 areaCount = r.readUint32Big();
|
|
|
|
ret.m_areas.reserve(areaCount);
|
2017-01-07 01:58:05 +00:00
|
|
|
for (u32 i = 0; i < areaCount; ++i)
|
2016-07-23 21:41:18 +00:00
|
|
|
{
|
|
|
|
ret.m_areas.emplace_back();
|
|
|
|
ret.m_areas.back().m_layerCount = r.readUint32Big();
|
|
|
|
ret.m_areas.back().m_layerBits = r.readUint64Big();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 nameCount = r.readUint32Big();
|
|
|
|
ret.m_names.reserve(areaCount);
|
2017-01-07 01:58:05 +00:00
|
|
|
for (u32 i = 0; i < nameCount; ++i)
|
2016-07-23 21:41:18 +00:00
|
|
|
ret.m_names.push_back(r.readString());
|
|
|
|
|
|
|
|
areaCount = r.readUint32Big();
|
2017-01-07 01:58:05 +00:00
|
|
|
for (u32 i = 0; i < areaCount; ++i)
|
2016-07-23 21:41:18 +00:00
|
|
|
ret.m_areas[i].m_startNameIdx = r.readUint32Big();
|
|
|
|
|
2017-02-08 06:48:43 +00:00
|
|
|
CWorldState& wldState = g_GameState->StateForWorld(mlvlId);
|
|
|
|
wldState.GetLayerState()->InitializeWorldLayers(ret.m_areas);
|
2016-07-23 21:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CDummyWorld::ICheckWorldComplete()
|
|
|
|
{
|
|
|
|
switch (x8_phase)
|
|
|
|
{
|
|
|
|
case Phase::Loading:
|
|
|
|
{
|
|
|
|
if (!x34_loadBuf)
|
|
|
|
return false;
|
|
|
|
athena::io::MemoryReader r(x34_loadBuf.get(), UINT32_MAX, false);
|
|
|
|
r.readUint32Big();
|
|
|
|
int version = r.readUint32Big();
|
|
|
|
x10_strgId = r.readUint32Big();
|
|
|
|
|
|
|
|
if (version >= 15)
|
|
|
|
x14_savwId = r.readUint32Big();
|
|
|
|
if (version >= 12)
|
|
|
|
r.readUint32Big();
|
|
|
|
if (version >= 17)
|
2016-07-24 04:46:32 +00:00
|
|
|
CWorld::CRelay::ReadMemoryRelays(r);
|
2016-07-23 21:41:18 +00:00
|
|
|
|
|
|
|
u32 areaCount = r.readUint32Big();
|
|
|
|
r.readUint32Big();
|
|
|
|
|
|
|
|
x18_areas.reserve(areaCount);
|
2017-01-07 01:58:05 +00:00
|
|
|
for (u32 i = 0; i < areaCount; ++i)
|
2016-07-23 21:41:18 +00:00
|
|
|
x18_areas.emplace_back(r, i, version);
|
|
|
|
|
|
|
|
x28_mapWorldId = r.readUint32Big();
|
|
|
|
if (x4_loadMap)
|
|
|
|
x2c_mapWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('MAPW'), x28_mapWorldId});
|
|
|
|
|
2016-10-08 20:32:36 +00:00
|
|
|
r.readByte();
|
|
|
|
r.readUint32Big();
|
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
if (version > 10)
|
|
|
|
{
|
|
|
|
u32 audioGroupCount = r.readUint32Big();
|
2017-01-07 01:58:05 +00:00
|
|
|
for (u32 i = 0; i < audioGroupCount; ++i)
|
2016-07-23 21:41:18 +00:00
|
|
|
{
|
|
|
|
r.readUint32Big();
|
|
|
|
r.readUint32Big();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (version > 12)
|
|
|
|
r.readString();
|
|
|
|
|
2017-02-08 06:48:43 +00:00
|
|
|
CWorldLayers::ReadWorldLayers(r, version, xc_mlvlId);
|
2016-07-23 21:41:18 +00:00
|
|
|
|
|
|
|
if (x4_loadMap)
|
|
|
|
x8_phase = Phase::LoadingMap;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x8_phase = Phase::Done;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case Phase::LoadingMap:
|
|
|
|
{
|
|
|
|
if (!x2c_mapWorld.IsLoaded() || !x2c_mapWorld.GetObj())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
x2c_mapWorld->SetWhichMapAreasLoaded(*this, 0, 9999);
|
|
|
|
x8_phase = Phase::LoadingMapAreas;
|
|
|
|
}
|
|
|
|
case Phase::LoadingMapAreas:
|
|
|
|
{
|
|
|
|
if (x2c_mapWorld->IsMapAreasStreaming())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
x8_phase = Phase::Done;
|
|
|
|
}
|
|
|
|
case Phase::Done:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
std::string CDummyWorld::IGetDefaultAudioTrack() const { return {}; }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
int CDummyWorld::IGetAreaCount() const { return x18_areas.size(); }
|
2016-07-24 04:46:32 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CWorld::CWorld(IObjectStore& objStore, IFactory& resFactory, CAssetId mlvlId)
|
2017-02-14 04:27:20 +00:00
|
|
|
: x8_mlvlId(mlvlId), x60_objectStore(objStore), x64_resFactory(resFactory)
|
2016-07-24 04:46:32 +00:00
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
x70_24_currentAreaNeedsAllocation = true;
|
2016-07-24 04:46:32 +00:00
|
|
|
SObjectTag tag{FOURCC('MLVL'), mlvlId};
|
2016-08-08 04:48:18 +00:00
|
|
|
static_cast<ProjectResourceFactoryBase&>(resFactory).LoadResourceAsync(tag, x40_loadBuf);
|
2016-07-23 21:41:18 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId CWorld::IGetWorldAssetId() const { return x8_mlvlId; }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId CWorld::IGetStringTableAssetId() const { return xc_strgId; }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId CWorld::IGetSaveWorldAssetId() const { return x10_savwId; }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
const CMapWorld* CWorld::IGetMapWorld() const { return const_cast<CWorld*>(this)->GetMapWorld(); }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
CMapWorld* CWorld::IMapWorld() { return const_cast<CMapWorld*>(GetMapWorld()); }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
const CGameArea* CWorld::GetAreaAlways(TAreaId id) const { return x18_areas.at(id).get(); }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
CGameArea* CWorld::GetArea(TAreaId id) { return const_cast<CGameArea*>(GetAreaAlways(id)); }
|
2016-08-09 03:58:19 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
const IGameArea* CWorld::IGetAreaAlways(TAreaId id) const { return GetAreaAlways(id); }
|
2016-08-09 03:58:19 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
TAreaId CWorld::IGetCurrentAreaId() const { return x68_curAreaId; }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
TAreaId CWorld::IGetAreaId(CAssetId id) const
|
2016-07-23 21:41:18 +00:00
|
|
|
{
|
2016-07-24 04:46:32 +00:00
|
|
|
int ret = 0;
|
|
|
|
if (id == -1)
|
|
|
|
return kInvalidAreaId;
|
|
|
|
for (const std::unique_ptr<CGameArea>& area : x18_areas)
|
|
|
|
{
|
|
|
|
if (area->x84_mrea == id)
|
|
|
|
return ret;
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return kInvalidAreaId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWorld::MoveToChain(CGameArea* area, EChain chain)
|
|
|
|
{
|
2016-08-14 03:00:58 +00:00
|
|
|
if (area->x138_curChain == chain)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (area->x138_curChain != EChain::Invalid)
|
|
|
|
if (x4c_chainHeads[int(chain)] == area)
|
|
|
|
x4c_chainHeads[int(chain)] = area->x130_next;
|
|
|
|
|
|
|
|
area->SetChain(x4c_chainHeads[int(chain)], chain);
|
|
|
|
x4c_chainHeads[int(chain)] = area;
|
2016-07-24 04:46:32 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 09:27:01 +00:00
|
|
|
void CWorld::MoveAreaToChain3(TAreaId aid)
|
|
|
|
{
|
2017-03-04 04:31:08 +00:00
|
|
|
MoveToChain(x18_areas[aid].get(), EChain::Alive);
|
2017-02-19 09:27:01 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
void CWorld::LoadSoundGroup(int groupId, CAssetId agscId, CSoundGroupData& data) {}
|
2016-07-24 22:51:15 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
void CWorld::LoadSoundGroups() {}
|
2016-07-24 22:51:15 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
bool CWorld::CheckWorldComplete(CStateManager* mgr, TAreaId id, CAssetId mreaId)
|
2016-07-24 04:46:32 +00:00
|
|
|
{
|
|
|
|
if (mreaId != -1)
|
|
|
|
{
|
|
|
|
x68_curAreaId = 0;
|
|
|
|
TAreaId aid = 0;
|
|
|
|
for (const std::unique_ptr<CGameArea>& area : x18_areas)
|
|
|
|
{
|
|
|
|
if (area->x84_mrea == mreaId)
|
|
|
|
{
|
|
|
|
x68_curAreaId = aid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++aid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
x68_curAreaId = id;
|
|
|
|
|
|
|
|
switch (x4_phase)
|
|
|
|
{
|
|
|
|
case Phase::Loading:
|
|
|
|
{
|
|
|
|
if (!x40_loadBuf)
|
|
|
|
return false;
|
2017-02-14 04:27:20 +00:00
|
|
|
athena::io::MemoryReader r(x40_loadBuf.get(), UINT32_MAX);
|
2016-07-24 04:46:32 +00:00
|
|
|
r.readUint32Big();
|
|
|
|
int version = r.readUint32Big();
|
|
|
|
xc_strgId = r.readUint32Big();
|
|
|
|
|
|
|
|
if (version >= 15)
|
|
|
|
x10_savwId = r.readUint32Big();
|
|
|
|
if (version >= 12)
|
|
|
|
{
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId skyboxId = r.readUint32Big();
|
2016-07-24 04:46:32 +00:00
|
|
|
if (skyboxId != -1 && mgr)
|
2016-07-24 22:51:15 +00:00
|
|
|
x94_skybox = g_SimplePool->GetObj(SObjectTag{FOURCC('CMDL'), skyboxId});
|
2016-07-24 04:46:32 +00:00
|
|
|
}
|
|
|
|
if (version >= 17)
|
|
|
|
x2c_relays = CWorld::CRelay::ReadMemoryRelays(r);
|
|
|
|
|
|
|
|
u32 areaCount = r.readUint32Big();
|
|
|
|
r.readUint32Big();
|
|
|
|
|
|
|
|
x18_areas.reserve(areaCount);
|
2017-01-07 01:58:05 +00:00
|
|
|
for (u32 i = 0; i < areaCount; ++i)
|
2016-07-24 04:46:32 +00:00
|
|
|
x18_areas.push_back(std::make_unique<CGameArea>(r, i, version));
|
|
|
|
|
|
|
|
if (x48_chainCount < 5)
|
|
|
|
{
|
2017-01-07 01:58:05 +00:00
|
|
|
for (int i = x48_chainCount; i < 5; ++i)
|
2016-07-24 04:46:32 +00:00
|
|
|
x4c_chainHeads[i] = nullptr;
|
|
|
|
x48_chainCount = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (std::unique_ptr<CGameArea>& area : x18_areas)
|
2017-04-13 19:28:31 +00:00
|
|
|
MoveToChain(area.get(), EChain::Deallocated);
|
2016-07-24 04:46:32 +00:00
|
|
|
|
|
|
|
x24_mapwId = r.readUint32Big();
|
|
|
|
x28_mapWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('MAPW'), x24_mapwId});
|
|
|
|
|
|
|
|
if (mgr)
|
|
|
|
{
|
|
|
|
std::vector<TEditorId> ids;
|
|
|
|
mgr->LoadScriptObjects(kInvalidAreaId, r, ids);
|
|
|
|
mgr->InitScriptObjects(ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (version > 10)
|
|
|
|
{
|
|
|
|
u32 audioGroupCount = r.readUint32Big();
|
|
|
|
x74_soundGroupData.reserve(audioGroupCount);
|
2017-01-07 01:58:05 +00:00
|
|
|
for (u32 i = 0; i < audioGroupCount; ++i)
|
2016-07-24 04:46:32 +00:00
|
|
|
{
|
|
|
|
int grpId = r.readUint32Big();
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId agscId = r.readUint32Big();
|
2016-07-24 04:46:32 +00:00
|
|
|
x74_soundGroupData.emplace_back(grpId, agscId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (version > 12)
|
|
|
|
{
|
|
|
|
x84_defAudioTrack = r.readString();
|
2017-08-13 05:26:14 +00:00
|
|
|
std::string trackKey = hecl::Format("WorldDefault: %8.8x", u32(x8_mlvlId.Value()));
|
2016-07-24 04:46:32 +00:00
|
|
|
if (g_TweakManager->HasTweakValue(trackKey))
|
2017-01-16 08:40:33 +00:00
|
|
|
x84_defAudioTrack = g_TweakManager->GetTweakValue(trackKey)->GetAudio().GetFileName();
|
2016-07-24 04:46:32 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 06:48:43 +00:00
|
|
|
CWorldLayers::ReadWorldLayers(r, version, x8_mlvlId);
|
2016-07-24 04:46:32 +00:00
|
|
|
|
|
|
|
x4_phase = Phase::LoadingMap;
|
|
|
|
}
|
|
|
|
case Phase::LoadingMap:
|
|
|
|
{
|
2016-07-24 22:51:15 +00:00
|
|
|
if (!x28_mapWorld.IsLoaded() || !x28_mapWorld.GetObj())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (x68_curAreaId == kInvalidAreaId)
|
|
|
|
x28_mapWorld->SetWhichMapAreasLoaded(*this, 0, 9999);
|
|
|
|
else
|
|
|
|
x28_mapWorld->SetWhichMapAreasLoaded(*this, x68_curAreaId, 3);
|
|
|
|
|
2016-07-24 04:46:32 +00:00
|
|
|
x4_phase = Phase::LoadingMapAreas;
|
|
|
|
}
|
|
|
|
case Phase::LoadingMapAreas:
|
|
|
|
{
|
2016-07-24 22:51:15 +00:00
|
|
|
if (x28_mapWorld->IsMapAreasStreaming())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
x4_phase = Phase::LoadingSkyBox;
|
|
|
|
}
|
|
|
|
case Phase::LoadingSkyBox:
|
|
|
|
{
|
2017-09-12 15:27:48 +00:00
|
|
|
x70_26_skyboxOverridden = true;
|
|
|
|
x70_27_needsSky = false;
|
2016-07-24 22:51:15 +00:00
|
|
|
|
|
|
|
if (!x94_skybox.IsLoaded())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
CModel* skybox = x94_skybox.GetObj();
|
|
|
|
if (!skybox)
|
|
|
|
return false;
|
|
|
|
|
2016-09-02 19:32:57 +00:00
|
|
|
skybox->GetInstance().Touch(0);
|
2016-07-24 22:51:15 +00:00
|
|
|
if (!skybox->IsLoaded(0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
xa4_skyboxB = x94_skybox;
|
|
|
|
|
|
|
|
for (CSoundGroupData& group : x74_soundGroupData)
|
|
|
|
group.x1c_groupData.Lock();
|
|
|
|
|
|
|
|
x4_phase = Phase::LoadingSoundGroups;
|
|
|
|
}
|
|
|
|
case Phase::LoadingSoundGroups:
|
|
|
|
{
|
|
|
|
bool allLoaded = true;
|
|
|
|
for (CSoundGroupData& group : x74_soundGroupData)
|
|
|
|
{
|
|
|
|
bool loaded = group.x1c_groupData.IsLoaded();
|
|
|
|
allLoaded &= loaded;
|
|
|
|
if (loaded)
|
|
|
|
{
|
|
|
|
CAudioGroupSet* groupData = group.x1c_groupData.GetObj();
|
|
|
|
if (groupData)
|
|
|
|
LoadSoundGroup(group.x0_groupId, group.x4_agscId, group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!allLoaded)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LoadSoundGroups();
|
2016-07-24 04:46:32 +00:00
|
|
|
x4_phase = Phase::Done;
|
|
|
|
}
|
|
|
|
case Phase::Done:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:51:15 +00:00
|
|
|
return false;
|
2016-07-23 21:41:18 +00:00
|
|
|
}
|
|
|
|
|
2016-08-14 03:00:58 +00:00
|
|
|
bool CWorld::ScheduleAreaToLoad(CGameArea* area, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
if (!area->xf0_24_postConstructed)
|
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
MoveToChain(area, EChain::Loading);
|
2016-08-14 03:00:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-04 04:31:08 +00:00
|
|
|
if (area->x138_curChain != EChain::Alive)
|
2016-08-14 03:00:58 +00:00
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
if (area->x138_curChain != EChain::AliveJudgement)
|
2016-08-14 03:00:58 +00:00
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
x70_24_currentAreaNeedsAllocation = true;
|
2016-08-14 03:00:58 +00:00
|
|
|
}
|
2017-03-04 04:31:08 +00:00
|
|
|
MoveToChain(area, EChain::Alive);
|
2016-08-14 03:00:58 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWorld::TravelToArea(TAreaId aid, CStateManager& mgr, bool skipLoadOther)
|
|
|
|
{
|
|
|
|
if (aid < 0 || aid >= x18_areas.size())
|
|
|
|
return;
|
2017-04-13 19:28:31 +00:00
|
|
|
x70_24_currentAreaNeedsAllocation = false;
|
2016-08-14 03:00:58 +00:00
|
|
|
x68_curAreaId = aid;
|
|
|
|
|
2017-04-13 19:28:31 +00:00
|
|
|
CGameArea* toDeallocateAreas = x4c_chainHeads[0];
|
|
|
|
while (toDeallocateAreas)
|
2016-08-14 03:00:58 +00:00
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
if (toDeallocateAreas->Invalidate(mgr))
|
2016-08-14 03:00:58 +00:00
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
MoveToChain(toDeallocateAreas, EChain::Deallocated);
|
2016-08-14 03:00:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-04-13 19:28:31 +00:00
|
|
|
toDeallocateAreas = toDeallocateAreas->x130_next;
|
2016-08-14 03:00:58 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 19:28:31 +00:00
|
|
|
CGameArea* aliveAreas = x4c_chainHeads[3];
|
|
|
|
while (aliveAreas)
|
2016-08-14 03:00:58 +00:00
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
MoveToChain(aliveAreas, EChain::AliveJudgement);
|
|
|
|
aliveAreas = aliveAreas->x130_next;
|
2016-08-14 03:00:58 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 19:28:31 +00:00
|
|
|
CGameArea* loadingAreas = x4c_chainHeads[2];
|
|
|
|
while (loadingAreas)
|
2016-08-14 03:00:58 +00:00
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
MoveToChain(loadingAreas, EChain::ToDeallocate);
|
|
|
|
loadingAreas = loadingAreas->x130_next;
|
2016-08-14 03:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CGameArea* area = x18_areas[aid].get();
|
2017-04-13 19:28:31 +00:00
|
|
|
if (area->x138_curChain != EChain::AliveJudgement)
|
|
|
|
x70_24_currentAreaNeedsAllocation = true;
|
2016-08-14 03:00:58 +00:00
|
|
|
area->Validate(mgr);
|
2017-03-04 04:31:08 +00:00
|
|
|
MoveToChain(area, EChain::Alive);
|
2017-03-31 19:51:40 +00:00
|
|
|
area->SetOcclusionState(CGameArea::EOcclusionState::Visible);
|
2016-08-14 03:00:58 +00:00
|
|
|
|
|
|
|
CGameArea* otherLoadArea = nullptr;
|
|
|
|
if (!skipLoadOther)
|
|
|
|
{
|
|
|
|
bool otherLoading = false;
|
|
|
|
for (CGameArea::Dock& dock : area->xcc_docks)
|
|
|
|
{
|
|
|
|
u32 dockRefCount = dock.GetDockRefs().size();
|
2017-01-07 01:58:05 +00:00
|
|
|
for (u32 i = 0; i < dockRefCount; ++i)
|
2016-08-14 03:00:58 +00:00
|
|
|
{
|
|
|
|
if (!dock.ShouldLoadOtherArea(i))
|
|
|
|
continue;
|
|
|
|
TAreaId connArea = dock.GetConnectedAreaId(i);
|
|
|
|
CGameArea* cArea = x18_areas[connArea].get();
|
|
|
|
if (!cArea->xf0_25_active)
|
|
|
|
continue;
|
|
|
|
if (!otherLoading)
|
|
|
|
{
|
|
|
|
otherLoading = ScheduleAreaToLoad(cArea, mgr);
|
|
|
|
if (!otherLoading)
|
|
|
|
continue;
|
|
|
|
otherLoadArea = cArea;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ScheduleAreaToLoad(cArea, mgr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-13 19:28:31 +00:00
|
|
|
CGameArea* judgementArea = x4c_chainHeads[4];
|
|
|
|
while (judgementArea)
|
2016-08-14 03:00:58 +00:00
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
MoveToChain(judgementArea, EChain::ToDeallocate);
|
|
|
|
judgementArea = judgementArea->x130_next;
|
2016-08-14 03:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t toStreamCount = 0;
|
2017-04-13 19:28:31 +00:00
|
|
|
toDeallocateAreas = x4c_chainHeads[0];
|
|
|
|
while (toDeallocateAreas)
|
2016-08-14 03:00:58 +00:00
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
toDeallocateAreas->RemoveStaticGeometry();
|
|
|
|
toDeallocateAreas = toDeallocateAreas->x130_next;
|
2016-08-14 03:00:58 +00:00
|
|
|
++toStreamCount;
|
|
|
|
}
|
|
|
|
|
2017-02-18 02:19:50 +00:00
|
|
|
if (!toStreamCount && otherLoadArea && !x70_25_paused)
|
2016-08-14 03:00:58 +00:00
|
|
|
otherLoadArea->StartStreamIn(mgr);
|
|
|
|
|
2017-04-15 05:32:25 +00:00
|
|
|
x28_mapWorld->SetWhichMapAreasLoaded(*this, aid, 3);
|
2016-08-14 03:00:58 +00:00
|
|
|
}
|
|
|
|
|
2017-02-18 02:19:50 +00:00
|
|
|
void CWorld::SetPauseState(bool paused)
|
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
for (auto it = GetChainHead(EChain::Loading) ; it != AliveAreasEnd() ; ++it)
|
2017-03-30 22:36:18 +00:00
|
|
|
it->SetPauseState(paused);
|
2017-02-18 02:19:50 +00:00
|
|
|
x70_25_paused = paused;
|
|
|
|
}
|
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
bool CWorld::ICheckWorldComplete() { return CheckWorldComplete(nullptr, kInvalidAreaId, -1); }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
std::string CWorld::IGetDefaultAudioTrack() const { return x84_defAudioTrack; }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
int CWorld::IGetAreaCount() const { return x18_areas.size(); }
|
|
|
|
|
|
|
|
bool CWorld::DoesAreaExist(TAreaId area) const { return (area >= 0 && area < x18_areas.size()); }
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
void CWorld::PropogateAreaChain(CGameArea::EOcclusionState occlusionState, CGameArea* area, CWorld* world)
|
2016-04-24 02:46:13 +00:00
|
|
|
{
|
2017-01-07 01:58:05 +00:00
|
|
|
if (!area->GetPostConstructed() || occlusionState == area->GetOcclusionState())
|
|
|
|
return;
|
2016-04-24 02:46:13 +00:00
|
|
|
|
2017-03-31 19:51:40 +00:00
|
|
|
if (occlusionState == CGameArea::EOcclusionState::Visible)
|
|
|
|
area->SetOcclusionState(CGameArea::EOcclusionState::Visible);
|
2017-01-07 01:58:05 +00:00
|
|
|
|
2017-03-30 22:36:18 +00:00
|
|
|
for (CGameArea& areaItr : *world)
|
2017-01-07 01:58:05 +00:00
|
|
|
{
|
2017-03-30 22:36:18 +00:00
|
|
|
if (&areaItr == area)
|
2017-01-07 01:58:05 +00:00
|
|
|
continue;
|
2017-03-31 19:51:40 +00:00
|
|
|
if (areaItr.IsPostConstructed() && areaItr.GetOcclusionState() == CGameArea::EOcclusionState::Visible)
|
2017-03-30 22:36:18 +00:00
|
|
|
areaItr.PrepTokens();
|
2017-01-07 01:58:05 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 22:36:18 +00:00
|
|
|
for (CGameArea& areaItr : *world)
|
2017-01-07 01:58:05 +00:00
|
|
|
{
|
2017-03-30 22:36:18 +00:00
|
|
|
if (&areaItr == area)
|
2017-01-07 01:58:05 +00:00
|
|
|
continue;
|
2017-03-31 19:51:40 +00:00
|
|
|
if (areaItr.IsPostConstructed() && areaItr.GetOcclusionState() == CGameArea::EOcclusionState::Occluded)
|
2017-03-30 22:36:18 +00:00
|
|
|
areaItr.PrepTokens();
|
2017-01-07 01:58:05 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 19:51:40 +00:00
|
|
|
if (occlusionState == CGameArea::EOcclusionState::Occluded)
|
|
|
|
area->SetOcclusionState(CGameArea::EOcclusionState::Occluded);
|
2017-01-07 01:58:05 +00:00
|
|
|
}
|
2017-03-03 07:18:12 +00:00
|
|
|
|
2017-03-24 05:30:16 +00:00
|
|
|
void CWorld::Update(float dt)
|
|
|
|
{
|
2017-09-12 15:27:48 +00:00
|
|
|
xc4_neededFx = EEnvFxType::None;
|
|
|
|
CAssetId skyModel;
|
|
|
|
bool needsSky = false;
|
|
|
|
CGameArea::EOcclusionState occlusionState = CGameArea::EOcclusionState::Occluded;
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2017-09-12 15:27:48 +00:00
|
|
|
u32 r26 = 0;
|
|
|
|
|
|
|
|
for (CGameArea* head = x4c_chainHeads[3] ;
|
|
|
|
head != skGlobalNonConstEnd ;
|
|
|
|
head = head->x130_next, ++r26)
|
|
|
|
{
|
|
|
|
head->AliveUpdate(dt);
|
|
|
|
|
|
|
|
if (head->DoesAreaNeedSkyNow())
|
|
|
|
{
|
|
|
|
const CScriptAreaAttributes* attrs = head->GetPostConstructed()->x10d8_areaAttributes;
|
|
|
|
|
|
|
|
if (attrs && attrs->GetSkyModel().IsValid())
|
|
|
|
skyModel = attrs->GetSkyModel();
|
|
|
|
|
|
|
|
needsSky = true;
|
|
|
|
occlusionState = (head->IsPostConstructed()
|
|
|
|
? head->GetPostConstructed()->x10dc_occlusionState
|
|
|
|
: CGameArea::EOcclusionState::Occluded);
|
|
|
|
}
|
|
|
|
|
|
|
|
EEnvFxType envFxType = head->DoesAreaNeedEnvFx();
|
|
|
|
if (envFxType != EEnvFxType::None)
|
|
|
|
xc4_neededFx = envFxType;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r26 == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (skyModel.IsValid() && needsSky)
|
|
|
|
{
|
|
|
|
x70_26_skyboxOverridden = true;
|
|
|
|
x70_27_needsSky = needsSky;
|
|
|
|
|
|
|
|
TToken<CModel> skybox = g_SimplePool->GetObj({SBIG('CMDL'), skyModel});
|
|
|
|
/* TODO: Finish */
|
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 07:18:12 +00:00
|
|
|
void CWorld::PreRender()
|
|
|
|
{
|
2017-03-04 04:58:33 +00:00
|
|
|
for (CGameArea* head = x4c_chainHeads[3] ;
|
|
|
|
head != skGlobalNonConstEnd ;
|
|
|
|
head = head->x130_next)
|
2017-03-03 07:18:12 +00:00
|
|
|
{
|
|
|
|
head->PreRender();
|
|
|
|
}
|
|
|
|
}
|
2017-03-04 04:31:08 +00:00
|
|
|
|
|
|
|
void CWorld::TouchSky()
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
if (xa4_skyboxB.IsLoaded())
|
|
|
|
xa4_skyboxB->Touch();
|
|
|
|
if (xb4_skyboxC.IsLoaded())
|
|
|
|
xb4_skyboxC->Touch();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWorld::DrawSky(const zeus::CTransform& xf) const
|
|
|
|
{
|
|
|
|
const CModel* model;
|
|
|
|
if (xa4_skyboxB)
|
|
|
|
model = xa4_skyboxB.GetObj();
|
|
|
|
else if (xb4_skyboxC)
|
|
|
|
model = xb4_skyboxC.GetObj();
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2017-09-12 15:27:48 +00:00
|
|
|
if (!x70_27_needsSky)
|
2017-03-04 04:31:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
CGraphics::DisableAllLights();
|
|
|
|
CGraphics::SetModelMatrix(xf);
|
|
|
|
g_Renderer->SetAmbientColor(zeus::CColor::skWhite);
|
|
|
|
CGraphics::SetDepthRange(0.999f, 1.f);
|
|
|
|
|
|
|
|
CModelFlags flags(0, 0, 1, zeus::CColor::skWhite);
|
|
|
|
model->Draw(flags);
|
|
|
|
|
|
|
|
CGraphics::SetDepthRange(0.125f, 1.f);
|
|
|
|
}
|
2017-07-07 12:23:20 +00:00
|
|
|
|
2017-07-07 12:26:53 +00:00
|
|
|
void CWorld::StopSound(s16)
|
2017-07-07 12:23:20 +00:00
|
|
|
{
|
|
|
|
}
|
2016-04-24 02:46:13 +00:00
|
|
|
}
|