2016-04-19 00:17:49 +00:00
|
|
|
#include "CGameArea.hpp"
|
2016-07-28 04:55:06 +00:00
|
|
|
#include "GameGlobalObjects.hpp"
|
|
|
|
#include "Graphics/CBooRenderer.hpp"
|
2016-08-07 00:20:02 +00:00
|
|
|
#include "CSimplePool.hpp"
|
|
|
|
#include "CStateManager.hpp"
|
2016-10-02 03:06:20 +00:00
|
|
|
#include "World/CScriptAreaAttributes.hpp"
|
2016-10-09 21:41:23 +00:00
|
|
|
#include "CGameState.hpp"
|
2017-04-18 23:41:01 +00:00
|
|
|
#include "DataSpec/DNAMP1/MREA.hpp"
|
2017-09-07 03:55:31 +00:00
|
|
|
#include "TCastTo.hpp"
|
2016-04-19 00:17:49 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2017-02-27 05:25:14 +00:00
|
|
|
static logvisor::Module Log("CGameArea");
|
|
|
|
|
|
|
|
CAreaRenderOctTree::CAreaRenderOctTree(const u8* buf)
|
|
|
|
: x0_buf(buf)
|
2016-08-07 00:20:02 +00:00
|
|
|
{
|
2017-11-02 12:33:28 +00:00
|
|
|
CMemoryInStream r(x0_buf + 8, INT32_MAX);
|
2016-08-07 00:20:02 +00:00
|
|
|
x8_bitmapCount = r.readUint32Big();
|
|
|
|
xc_meshCount = r.readUint32Big();
|
|
|
|
x10_nodeCount = r.readUint32Big();
|
|
|
|
x14_bitmapWordCount = (xc_meshCount + 31) / 32;
|
|
|
|
x18_aabb.readBoundingBoxBig(r);
|
|
|
|
|
2017-02-27 05:25:14 +00:00
|
|
|
x30_bitmaps = reinterpret_cast<const u32*>(x0_buf + 64);
|
2016-08-07 00:20:02 +00:00
|
|
|
u32 wc = x14_bitmapWordCount * x8_bitmapCount;
|
2016-12-21 19:27:15 +00:00
|
|
|
for (u32 i=0 ; i<wc ; ++i)
|
2017-02-27 05:25:14 +00:00
|
|
|
const_cast<u32*>(x30_bitmaps)[i] = hecl::SBig(x30_bitmaps[i]);
|
2016-08-07 00:20:02 +00:00
|
|
|
|
|
|
|
x34_indirectionTable = x30_bitmaps + wc;
|
2017-02-27 05:25:14 +00:00
|
|
|
x38_entries = reinterpret_cast<const u8*>(x34_indirectionTable + x10_nodeCount);
|
2016-12-21 19:27:15 +00:00
|
|
|
for (u32 i=0 ; i<x10_nodeCount ; ++i)
|
2016-08-07 00:20:02 +00:00
|
|
|
{
|
2017-02-27 05:25:14 +00:00
|
|
|
const_cast<u32*>(x34_indirectionTable)[i] = hecl::SBig(x34_indirectionTable[i]);
|
|
|
|
Node* n = reinterpret_cast<Node*>(const_cast<u8*>(x38_entries) + x34_indirectionTable[i]);
|
2016-08-07 00:20:02 +00:00
|
|
|
n->x0_bitmapIdx = hecl::SBig(n->x0_bitmapIdx);
|
|
|
|
n->x2_flags = hecl::SBig(n->x2_flags);
|
|
|
|
if (n->x2_flags)
|
|
|
|
{
|
|
|
|
u32 childCount = n->GetChildCount();
|
|
|
|
for (u32 c=0 ; c<childCount ; ++c)
|
|
|
|
n->x4_children[c] = hecl::SBig(n->x4_children[c]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const u32 ChildCounts[] = { 0, 2, 2, 4, 2, 4, 4, 8 };
|
|
|
|
u32 CAreaRenderOctTree::Node::GetChildCount() const
|
|
|
|
{
|
|
|
|
return ChildCounts[x2_flags];
|
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CAABox CAreaRenderOctTree::Node::GetNodeBounds(const zeus::CAABox& curAABB, int idx) const
|
|
|
|
{
|
|
|
|
zeus::CVector3f center = curAABB.center();
|
|
|
|
switch (x2_flags)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
return curAABB;
|
|
|
|
case 1:
|
|
|
|
if (idx == 0)
|
|
|
|
return {curAABB.min.x, curAABB.min.y, curAABB.min.z, center.x, curAABB.max.y, curAABB.max.z};
|
|
|
|
else
|
|
|
|
return {center.x, curAABB.min.y, curAABB.min.z, curAABB.max.x, curAABB.max.y, curAABB.max.z};
|
|
|
|
case 2:
|
|
|
|
if (idx == 0)
|
|
|
|
return {curAABB.min.x, curAABB.min.y, curAABB.min.z, curAABB.max.x, center.y, curAABB.max.z};
|
|
|
|
else
|
|
|
|
return {curAABB.min.x, center.y, curAABB.min.z, curAABB.max.x, curAABB.max.y, curAABB.max.z};
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
switch (idx)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
return {curAABB.min.x, curAABB.min.y, curAABB.min.z, center.x, center.y, curAABB.max.z};
|
|
|
|
case 1:
|
|
|
|
return {center.x, curAABB.min.y, curAABB.min.z, curAABB.max.x, center.y, curAABB.max.z};
|
|
|
|
case 2:
|
|
|
|
return {curAABB.min.x, center.y, curAABB.min.z, center.x, curAABB.max.y, curAABB.max.z};
|
|
|
|
case 3:
|
|
|
|
return {center.x, center.y, curAABB.min.z, curAABB.max.x, curAABB.max.y, curAABB.max.z};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
if (idx == 0)
|
|
|
|
return {curAABB.min.x, curAABB.min.y, curAABB.min.z, curAABB.max.x, curAABB.max.y, center.z};
|
|
|
|
else
|
|
|
|
return {curAABB.min.x, curAABB.min.y, center.z, curAABB.max.x, curAABB.max.y, curAABB.max.z};
|
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
switch (idx)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
return {curAABB.min.x, curAABB.min.y, curAABB.min.z, center.x, curAABB.max.y, center.z};
|
|
|
|
case 1:
|
|
|
|
return {center.x, curAABB.min.y, curAABB.min.z, curAABB.max.x, curAABB.max.y, center.z};
|
|
|
|
case 2:
|
|
|
|
return {curAABB.min.x, curAABB.min.y, center.z, center.x, curAABB.max.y, curAABB.max.z};
|
|
|
|
case 3:
|
|
|
|
return {center.x, curAABB.min.y, center.z, curAABB.max.x, curAABB.max.y, curAABB.max.z};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
switch (idx)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
return {curAABB.min.x, curAABB.min.y, curAABB.min.z, curAABB.max.x, center.y, center.z};
|
|
|
|
case 1:
|
|
|
|
return {curAABB.min.x, center.y, curAABB.min.z, curAABB.max.x, curAABB.max.y, center.z};
|
|
|
|
case 2:
|
|
|
|
return {curAABB.min.x, curAABB.min.y, center.z, curAABB.max.x, center.y, curAABB.max.z};
|
|
|
|
case 3:
|
|
|
|
return {curAABB.min.x, center.y, center.z, curAABB.max.x, curAABB.max.y, curAABB.max.z};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
switch (idx)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
return {curAABB.min.x, curAABB.min.y, curAABB.min.z, center.x, center.y, center.z};
|
|
|
|
case 1:
|
|
|
|
return {center.x, curAABB.min.y, curAABB.min.z, curAABB.max.x, center.y, center.z};
|
|
|
|
case 2:
|
|
|
|
return {curAABB.min.x, center.y, curAABB.min.z, center.x, curAABB.max.y, center.z};
|
|
|
|
case 3:
|
|
|
|
return {center.x, center.y, curAABB.min.z, curAABB.max.x, curAABB.max.y, center.z};
|
|
|
|
case 4:
|
|
|
|
return {curAABB.min.x, curAABB.min.y, center.z, center.x, center.y, curAABB.max.z};
|
|
|
|
case 5:
|
|
|
|
return {center.x, curAABB.min.y, center.z, curAABB.max.x, center.y, curAABB.max.z};
|
|
|
|
case 6:
|
|
|
|
return {curAABB.min.x, center.y, center.z, center.x, curAABB.max.y, curAABB.max.z};
|
|
|
|
case 7:
|
|
|
|
return {center.x, center.y, center.z, curAABB.max.x, curAABB.max.y, curAABB.max.z};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAreaRenderOctTree::Node::RecursiveBuildOverlaps(u32* bmpOut,
|
|
|
|
const CAreaRenderOctTree& parent,
|
|
|
|
const zeus::CAABox& curAABB,
|
|
|
|
const zeus::CAABox& testAABB) const
|
|
|
|
{
|
|
|
|
if (testAABB.intersects(curAABB))
|
|
|
|
{
|
2018-05-13 23:27:47 +00:00
|
|
|
u32 childCount = GetChildCount(); // HACK: Always return the smallest set of intersections
|
|
|
|
if (curAABB.inside(testAABB) || childCount == 0)
|
2016-08-07 00:20:02 +00:00
|
|
|
{
|
|
|
|
const u32* bmp = &parent.x30_bitmaps[x0_bitmapIdx * parent.x14_bitmapWordCount];
|
|
|
|
for (u32 c=0 ; c<parent.x14_bitmapWordCount ; ++c)
|
|
|
|
bmpOut[c] |= bmp[c];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (u32 c=0 ; c<childCount ; ++c)
|
|
|
|
{
|
|
|
|
zeus::CAABox childAABB = GetNodeBounds(curAABB, c);
|
2018-01-15 07:39:25 +00:00
|
|
|
reinterpret_cast<const Node*>(parent.x38_entries + parent.x34_indirectionTable[x4_children[c]])->
|
2016-08-07 00:20:02 +00:00
|
|
|
RecursiveBuildOverlaps(bmpOut, parent, childAABB, testAABB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAreaRenderOctTree::FindOverlappingModels(std::vector<u32>& out, const zeus::CAABox& testAABB) const
|
|
|
|
{
|
|
|
|
out.resize(x14_bitmapWordCount);
|
2018-01-15 07:39:25 +00:00
|
|
|
reinterpret_cast<const Node*>(x38_entries + x34_indirectionTable[0])->
|
2016-08-07 00:20:02 +00:00
|
|
|
RecursiveBuildOverlaps(out.data(), *this, x18_aabb, testAABB);
|
|
|
|
}
|
|
|
|
|
2017-03-03 07:18:12 +00:00
|
|
|
void CAreaRenderOctTree::FindOverlappingModels(u32* out, const zeus::CAABox& testAABB) const
|
|
|
|
{
|
2018-01-15 07:39:25 +00:00
|
|
|
reinterpret_cast<const Node*>(x38_entries + x34_indirectionTable[0])->
|
2017-03-03 07:18:12 +00:00
|
|
|
RecursiveBuildOverlaps(out, *this, x18_aabb, testAABB);
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:26:17 +00:00
|
|
|
void CGameArea::CAreaFog::SetCurrent() const
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
g_Renderer->SetWorldFog(x0_fogMode, x4_rangeCur[0], x4_rangeCur[1], x1c_colorCur);
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::CAreaFog::Update(float dt)
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
if (x0_fogMode == ERglFogMode::None)
|
|
|
|
return;
|
|
|
|
if (x1c_colorCur == x28_colorTarget && x4_rangeCur == xc_rangeTarget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
float colorDelta = x34_colorDelta * dt;
|
|
|
|
zeus::CVector2f rangeDelta = x14_rangeDelta * dt;
|
|
|
|
|
2016-12-21 19:27:15 +00:00
|
|
|
for (u32 i=0 ; i<3 ; ++i)
|
2016-08-08 04:48:18 +00:00
|
|
|
{
|
|
|
|
float delta = x28_colorTarget[i] - x1c_colorCur[i];
|
|
|
|
if (std::fabs(delta) <= colorDelta)
|
|
|
|
{
|
|
|
|
x1c_colorCur[i] = x28_colorTarget[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (delta < 0.f)
|
|
|
|
x1c_colorCur[i] -= colorDelta;
|
|
|
|
else
|
|
|
|
x1c_colorCur[i] += colorDelta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 19:27:15 +00:00
|
|
|
for (u32 i=0 ; i<2 ; ++i)
|
2016-08-08 04:48:18 +00:00
|
|
|
{
|
|
|
|
float delta = xc_rangeTarget[i] - x4_rangeCur[i];
|
|
|
|
if (std::fabs(delta) <= rangeDelta[i])
|
|
|
|
{
|
|
|
|
x4_rangeCur[i] = xc_rangeTarget[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (delta < 0.f)
|
|
|
|
x4_rangeCur[i] -= rangeDelta[i];
|
|
|
|
else
|
|
|
|
x4_rangeCur[i] += rangeDelta[i];
|
|
|
|
}
|
|
|
|
}
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
void CGameArea::CAreaFog::RollFogOut(float rangeDelta, float colorDelta, const zeus::CColor& color)
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
x14_rangeDelta = {rangeDelta, rangeDelta * 2.f};
|
|
|
|
xc_rangeTarget = {4096.f, 4096.f};
|
|
|
|
x34_colorDelta = colorDelta;
|
|
|
|
x28_colorTarget = color;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
void CGameArea::CAreaFog::FadeFog(ERglFogMode mode,
|
2016-07-23 00:26:17 +00:00
|
|
|
const zeus::CColor& color, const zeus::CVector2f& vec1,
|
2016-08-08 04:48:18 +00:00
|
|
|
float speed, const zeus::CVector2f& vec2)
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
if (x0_fogMode == ERglFogMode::None)
|
|
|
|
{
|
|
|
|
x1c_colorCur = color;
|
|
|
|
x28_colorTarget = color;
|
|
|
|
x4_rangeCur = {vec1[1], vec1[1]};
|
|
|
|
xc_rangeTarget = vec1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x28_colorTarget = color;
|
|
|
|
xc_rangeTarget = vec1;
|
|
|
|
}
|
|
|
|
x0_fogMode = mode;
|
|
|
|
x34_colorDelta = speed;
|
|
|
|
x14_rangeDelta = vec2;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
void CGameArea::CAreaFog::SetFogExplicit(ERglFogMode mode, const zeus::CColor& color, const zeus::CVector2f& range)
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
x0_fogMode = mode;
|
|
|
|
x1c_colorCur = color;
|
|
|
|
x28_colorTarget = color;
|
|
|
|
x4_rangeCur = range;
|
|
|
|
xc_rangeTarget = range;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameArea::CAreaFog::IsFogDisabled() const
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return x0_fogMode == ERglFogMode::None;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::CAreaFog::DisableFog()
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
x0_fogMode = ERglFogMode::None;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-07 00:20:02 +00:00
|
|
|
static std::vector<SObjectTag> ReadDependencyList(CInputStream& in)
|
|
|
|
{
|
|
|
|
std::vector<SObjectTag> ret;
|
|
|
|
u32 count = in.readUint32Big();
|
|
|
|
ret.reserve(count);
|
|
|
|
for (u32 i=0 ; i<count ; ++i)
|
|
|
|
{
|
|
|
|
ret.emplace_back();
|
|
|
|
ret.back().readMLVL(in);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-11-05 02:08:05 +00:00
|
|
|
std::pair<std::unique_ptr<u8[]>, s32> GetScriptingMemoryAlways(const IGameArea& area)
|
|
|
|
{
|
|
|
|
SObjectTag tag = {SBIG('MREA'), area.IGetAreaAssetId()};
|
2017-11-05 06:29:22 +00:00
|
|
|
std::unique_ptr<u8[]> data = std::move(g_ResFactory->LoadNewResourcePartSync(tag, 0, 96));
|
2017-11-05 02:08:05 +00:00
|
|
|
|
|
|
|
if (*reinterpret_cast<u32*>(data.get()) != SBIG(0xDEADBEEF))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
SMREAHeader header;
|
|
|
|
CMemoryInStream r(data.get() + 4, 96 - 4);
|
|
|
|
u32 version = r.readUint32Big();
|
|
|
|
if (!(version & 0x10000))
|
|
|
|
Log.report(logvisor::Fatal, "Attempted to load non-URDE MREA");
|
|
|
|
|
|
|
|
version &= ~0x10000;
|
|
|
|
header.version = (version >= 12 && version <= 15) ? version : 0;
|
|
|
|
if (!header.version)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
header.xf.read34RowMajor(r);
|
|
|
|
header.modelCount = r.readUint32Big();
|
|
|
|
header.secCount = r.readUint32Big();
|
|
|
|
header.geomSecIdx = r.readUint32Big();
|
|
|
|
header.sclySecIdx = r.readUint32Big();
|
|
|
|
header.collisionSecIdx = r.readUint32Big();
|
|
|
|
header.unkSecIdx = r.readUint32Big();
|
|
|
|
header.lightSecIdx = r.readUint32Big();
|
|
|
|
header.visiSecIdx = r.readUint32Big();
|
|
|
|
header.pathSecIdx = r.readUint32Big();
|
|
|
|
header.arotSecIdx = r.readUint32Big();
|
|
|
|
|
|
|
|
u32 dataLen = ROUND_UP_32(header.secCount * 4);
|
|
|
|
|
2017-11-05 06:29:22 +00:00
|
|
|
data = std::move(g_ResFactory->LoadNewResourcePartSync(tag, 96, dataLen));
|
2017-11-05 02:08:05 +00:00
|
|
|
|
2017-11-05 06:29:22 +00:00
|
|
|
r = CMemoryInStream(data.get(), dataLen);
|
2017-11-05 02:08:05 +00:00
|
|
|
|
|
|
|
std::vector<u32> secSizes(header.secCount);
|
|
|
|
u32 lastSize;
|
|
|
|
for (u32 i = 0; i < header.secCount; ++i)
|
|
|
|
{
|
|
|
|
lastSize = r.readUint32Big();
|
|
|
|
secSizes.push_back(lastSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Finish
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
CDummyGameArea::CDummyGameArea(CInputStream& in, int idx, int mlvlVersion)
|
|
|
|
{
|
|
|
|
x8_nameSTRG = in.readUint32Big();
|
|
|
|
x14_transform.read34RowMajor(in);
|
|
|
|
zeus::CAABox aabb;
|
|
|
|
aabb.readBoundingBoxBig(in);
|
|
|
|
xc_mrea = in.readUint32Big();
|
|
|
|
if (mlvlVersion > 15)
|
|
|
|
x10_areaId = in.readUint32Big();
|
|
|
|
|
|
|
|
u32 attachAreaCount = in.readUint32Big();
|
|
|
|
x44_attachedAreaIndices.reserve(attachAreaCount);
|
2016-07-24 06:05:12 +00:00
|
|
|
for (u32 i=0 ; i<attachAreaCount ; ++i)
|
2016-07-23 21:41:18 +00:00
|
|
|
x44_attachedAreaIndices.push_back(in.readUint16Big());
|
|
|
|
|
2016-08-07 00:20:02 +00:00
|
|
|
::urde::ReadDependencyList(in);
|
|
|
|
::urde::ReadDependencyList(in);
|
|
|
|
|
|
|
|
if (mlvlVersion > 13)
|
|
|
|
{
|
|
|
|
u32 depCount = in.readUint32Big();
|
|
|
|
for (u32 i=0 ; i<depCount ; ++i)
|
|
|
|
in.readUint32Big();
|
|
|
|
}
|
2016-07-23 21:41:18 +00:00
|
|
|
|
|
|
|
u32 dockCount = in.readUint32Big();
|
|
|
|
x54_docks.reserve(dockCount);
|
2016-07-24 06:05:12 +00:00
|
|
|
for (u32 i=0 ; i<dockCount ; ++i)
|
2016-07-23 21:41:18 +00:00
|
|
|
x54_docks.emplace_back(in, x14_transform);
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 02:10:50 +00:00
|
|
|
std::pair<std::unique_ptr<u8[]>, s32> CDummyGameArea::IGetScriptingMemoryAlways() const
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2017-11-05 02:08:05 +00:00
|
|
|
return GetScriptingMemoryAlways(*this);
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TAreaId CDummyGameArea::IGetAreaId() const
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return x10_areaId;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId CDummyGameArea::IGetAreaAssetId() const
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return xc_mrea;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CDummyGameArea::IIsActive() const
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return true;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
TAreaId CDummyGameArea::IGetAttachedAreaId(int idx) const
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return x44_attachedAreaIndices[idx];
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 CDummyGameArea::IGetNumAttachedAreas() const
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return x44_attachedAreaIndices.size();
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId CDummyGameArea::IGetStringTableAssetId() const
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return x8_nameSTRG;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const zeus::CTransform& CDummyGameArea::IGetTM() const
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return x14_transform;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-07-24 04:46:32 +00:00
|
|
|
CGameArea::CGameArea(CInputStream& in, int idx, int mlvlVersion)
|
2017-01-25 04:40:19 +00:00
|
|
|
: x4_selfIdx(idx)
|
2016-04-19 00:17:49 +00:00
|
|
|
{
|
2018-05-08 02:18:18 +00:00
|
|
|
xf0_24_postConstructed = false;
|
2017-01-25 04:40:19 +00:00
|
|
|
xf0_25_active = true;
|
2018-05-08 02:18:18 +00:00
|
|
|
xf0_26_tokensReady = false;
|
|
|
|
xf0_27_paused = false;
|
|
|
|
xf0_28_validated = false;
|
2016-04-19 00:17:49 +00:00
|
|
|
x8_nameSTRG = in.readUint32Big();
|
|
|
|
xc_transform.read34RowMajor(in);
|
|
|
|
x3c_invTransform = xc_transform.inverse();
|
|
|
|
x6c_aabb.readBoundingBoxBig(in);
|
2016-04-23 18:04:49 +00:00
|
|
|
|
2016-04-19 00:17:49 +00:00
|
|
|
x84_mrea = in.readUint32Big();
|
2016-04-23 18:04:49 +00:00
|
|
|
if (mlvlVersion > 15)
|
|
|
|
x88_areaId = in.readUint32Big();
|
|
|
|
else
|
|
|
|
x88_areaId = -1;
|
2016-04-19 00:17:49 +00:00
|
|
|
|
|
|
|
u32 attachedCount = in.readUint32Big();
|
|
|
|
x8c_attachedAreaIndices.reserve(attachedCount);
|
2016-07-24 06:05:12 +00:00
|
|
|
for (u32 i=0 ; i<attachedCount ; ++i)
|
2016-04-19 00:17:49 +00:00
|
|
|
x8c_attachedAreaIndices.push_back(in.readUint16Big());
|
|
|
|
|
2016-07-23 00:26:17 +00:00
|
|
|
x9c_deps1 = ::urde::ReadDependencyList(in);
|
|
|
|
xac_deps2 = ::urde::ReadDependencyList(in);
|
|
|
|
|
2016-08-07 00:20:02 +00:00
|
|
|
zeus::CAABox aabb = x6c_aabb.getTransformedAABox(xc_transform);
|
|
|
|
x6c_aabb = aabb;
|
|
|
|
|
|
|
|
if (mlvlVersion > 13)
|
|
|
|
{
|
|
|
|
u32 depCount = in.readUint32Big();
|
|
|
|
xbc_layerDepOffsets.reserve(depCount);
|
|
|
|
for (u32 i=0 ; i<depCount ; ++i)
|
|
|
|
xbc_layerDepOffsets.push_back(in.readUint32Big());
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 dockCount = in.readUint32Big();
|
|
|
|
xcc_docks.reserve(dockCount);
|
|
|
|
for (u32 i=0 ; i<dockCount ; ++i)
|
2018-05-02 00:43:31 +00:00
|
|
|
xcc_docks.push_back({in, xc_transform});
|
2016-08-07 00:20:02 +00:00
|
|
|
|
|
|
|
ClearTokenList();
|
|
|
|
|
|
|
|
for (CToken& tok : xdc_tokens)
|
|
|
|
xec_totalResourcesSize += g_ResFactory->ResourceSize(*tok.GetObjectTag());
|
|
|
|
|
|
|
|
xec_totalResourcesSize += g_ResFactory->ResourceSize(SObjectTag{FOURCC('MREA'), x84_mrea});
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2017-10-17 05:51:53 +00:00
|
|
|
CGameArea::CGameArea(CAssetId mreaId)
|
|
|
|
: x84_mrea(mreaId)
|
|
|
|
{
|
2018-05-08 02:18:18 +00:00
|
|
|
xf0_24_postConstructed = false;
|
|
|
|
xf0_25_active = false;
|
|
|
|
xf0_26_tokensReady = false;
|
|
|
|
xf0_27_paused = false;
|
|
|
|
xf0_28_validated = false;
|
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
while (StartStreamingMainArea())
|
|
|
|
for (auto& req : xf8_loadTransactions)
|
2017-10-27 10:10:32 +00:00
|
|
|
req->WaitUntilComplete();
|
2017-10-17 05:51:53 +00:00
|
|
|
|
2017-11-05 02:08:05 +00:00
|
|
|
SMREAHeader header = VerifyHeader();
|
2017-10-22 06:11:22 +00:00
|
|
|
x12c_postConstructed->x4c_insts.resize(header.modelCount);
|
2017-10-17 05:51:53 +00:00
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
FillInStaticGeometry(false);
|
2017-10-17 05:51:53 +00:00
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
CBooModel::SetDummyTextures(true);
|
2017-11-05 06:17:12 +00:00
|
|
|
CBooModel::EnableShadowMaps(g_Renderer->x220_sphereRamp.get(), zeus::CTransform::Identity());
|
2017-10-17 05:51:53 +00:00
|
|
|
CGraphics::CProjectionState backupProj = CGraphics::GetProjectionState();
|
|
|
|
zeus::CTransform backupViewPoint = CGraphics::g_ViewMatrix;
|
|
|
|
zeus::CTransform backupModel = CGraphics::g_GXModelMatrix;
|
|
|
|
CGraphics::SetViewPointMatrix(zeus::CTransform::Translate(0.f, -2048.f, 0.f));
|
|
|
|
CGraphics::SetOrtho(-2048.f, 2048.f, 2048.f, -2048.f, 0.f, 4096.f);
|
|
|
|
CModelFlags defaultFlags;
|
|
|
|
for (CMetroidModelInstance& inst : x12c_postConstructed->x4c_insts)
|
|
|
|
{
|
|
|
|
CGraphics::SetModelMatrix(zeus::CTransform::Translate(-inst.x34_aabb.center()));
|
|
|
|
inst.m_instance->UpdateUniformData(defaultFlags, nullptr, nullptr);
|
|
|
|
inst.m_instance->WarmupDrawSurfaces();
|
|
|
|
}
|
|
|
|
CGraphics::SetProjectionState(backupProj);
|
|
|
|
CGraphics::SetViewPointMatrix(backupViewPoint);
|
|
|
|
CGraphics::SetModelMatrix(backupModel);
|
|
|
|
CBooModel::DisableShadowMaps();
|
2017-10-22 06:11:22 +00:00
|
|
|
CBooModel::SetDummyTextures(false);
|
2017-10-17 05:51:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 03:02:30 +00:00
|
|
|
CGameArea::~CGameArea()
|
|
|
|
{
|
2018-05-08 05:10:24 +00:00
|
|
|
for (auto& lt : xf8_loadTransactions)
|
|
|
|
lt->PostCancelRequest();
|
|
|
|
|
2018-01-05 03:02:30 +00:00
|
|
|
if (xf0_24_postConstructed)
|
|
|
|
RemoveStaticGeometry();
|
|
|
|
else
|
|
|
|
while (!Invalidate(nullptr)) {}
|
|
|
|
}
|
|
|
|
|
2018-04-30 03:12:41 +00:00
|
|
|
bool CGameArea::IsFinishedOccluding() const
|
|
|
|
{
|
|
|
|
if (x12c_postConstructed->x10dc_occlusionState != EOcclusionState::Occluded)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return x12c_postConstructed->x1108_27_;
|
|
|
|
}
|
|
|
|
|
2017-11-05 02:10:50 +00:00
|
|
|
std::pair<std::unique_ptr<u8[]>, s32> CGameArea::IGetScriptingMemoryAlways() const
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2017-11-05 02:08:05 +00:00
|
|
|
return GetScriptingMemoryAlways(*this);
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameArea::IIsActive() const
|
|
|
|
{
|
2017-11-05 02:08:05 +00:00
|
|
|
return xf0_25_active;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
TAreaId CGameArea::IGetAttachedAreaId(int idx) const
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return x8c_attachedAreaIndices[idx];
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 CGameArea::IGetNumAttachedAreas() const
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return x8c_attachedAreaIndices.size();
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId CGameArea::IGetStringTableAssetId() const
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return x8_nameSTRG;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const zeus::CTransform& CGameArea::IGetTM() const
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return xc_transform;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-18 02:19:50 +00:00
|
|
|
void CGameArea::SetPauseState(bool paused)
|
|
|
|
{
|
|
|
|
if (xf0_26_tokensReady)
|
|
|
|
return;
|
|
|
|
xf0_27_paused = paused;
|
|
|
|
if (!paused)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (CToken& tok : xdc_tokens)
|
|
|
|
if (!tok.IsLoaded())
|
|
|
|
tok.Unlock();
|
|
|
|
}
|
|
|
|
|
2016-08-09 03:58:19 +00:00
|
|
|
void CGameArea::SetXRaySpeedAndTarget(float f1, float f2)
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x112c_xraySpeed = f1;
|
|
|
|
x12c_postConstructed->x1130_xrayTarget = f2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::SetThermalSpeedAndTarget(float speed, float target)
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x1120_thermalSpeed = speed;
|
|
|
|
x12c_postConstructed->x1124_thermalTarget = target;
|
|
|
|
}
|
|
|
|
|
2017-09-07 03:55:31 +00:00
|
|
|
void CGameArea::SetWeaponWorldLighting(float speed, float target)
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x1134_weaponWorldLightingSpeed = speed;
|
|
|
|
x12c_postConstructed->x1138_weaponWorldLightingTarget = target;
|
|
|
|
}
|
|
|
|
|
2017-03-04 04:31:08 +00:00
|
|
|
float CGameArea::GetXRayFogDistance() const
|
|
|
|
{
|
|
|
|
const CScriptAreaAttributes* attrs = x12c_postConstructed->x10d8_areaAttributes;
|
|
|
|
if (attrs)
|
|
|
|
return attrs->GetXRayFogDistance();
|
|
|
|
return 1.f;
|
|
|
|
}
|
|
|
|
|
2017-09-12 15:27:48 +00:00
|
|
|
EEnvFxType CGameArea::DoesAreaNeedEnvFx() const
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2017-09-12 15:27:48 +00:00
|
|
|
const CPostConstructed* postConstructed = GetPostConstructed();
|
|
|
|
if (!postConstructed)
|
|
|
|
return EEnvFxType::None;
|
|
|
|
|
|
|
|
const CScriptAreaAttributes* attrs = postConstructed->x10d8_areaAttributes;
|
2017-11-05 02:08:05 +00:00
|
|
|
if (!attrs)
|
2017-09-12 15:27:48 +00:00
|
|
|
return EEnvFxType::None;
|
|
|
|
if (postConstructed->x10dc_occlusionState == EOcclusionState::Occluded)
|
|
|
|
return EEnvFxType::None;
|
|
|
|
return attrs->GetEnvFxType();
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameArea::DoesAreaNeedSkyNow() const
|
|
|
|
{
|
2017-11-05 02:08:05 +00:00
|
|
|
const CPostConstructed* postConstructed = GetPostConstructed();
|
|
|
|
if (!postConstructed)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const CScriptAreaAttributes* attrs = postConstructed->x10d8_areaAttributes;
|
|
|
|
if (!attrs)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return attrs->GetNeedsSky();
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::UpdateFog(float dt)
|
|
|
|
{
|
2017-11-05 06:29:22 +00:00
|
|
|
CAreaFog* fog = GetPostConstructed()->x10c4_areaFog.get();
|
2017-11-05 02:08:05 +00:00
|
|
|
if (fog)
|
|
|
|
fog->Update(dt);
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 02:08:05 +00:00
|
|
|
void CGameArea::OtherAreaOcclusionChanged()
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2018-05-07 00:47:40 +00:00
|
|
|
if (GetPostConstructed()->x10e0_ == 3 && GetPostConstructed()->x10dc_occlusionState == EOcclusionState::Visible)
|
2017-11-05 02:08:05 +00:00
|
|
|
{
|
2018-05-07 00:47:40 +00:00
|
|
|
x12c_postConstructed->x1108_27_ = false;
|
2017-11-05 02:08:05 +00:00
|
|
|
}
|
2018-05-07 00:47:40 +00:00
|
|
|
else if (GetPostConstructed()->x10dc_occlusionState == EOcclusionState::Visible)
|
2017-11-05 02:08:05 +00:00
|
|
|
{
|
|
|
|
ReloadAllUnloadedTextures();
|
|
|
|
}
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::PingOcclusionState()
|
|
|
|
{
|
2017-11-05 02:08:05 +00:00
|
|
|
if (GetOcclusionState() == EOcclusionState::Occluded && GetPostConstructed()->x10e0_ < 2)
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x10e0_ += 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
x12c_postConstructed->x10e0_ = 3;
|
|
|
|
if (!x12c_postConstructed->x1108_27_)
|
|
|
|
{
|
|
|
|
bool unloaded = true;
|
|
|
|
bool transferred = true;
|
|
|
|
#if 0
|
|
|
|
unloaded = UnloadAllloadedTextures();
|
|
|
|
transferred = TransferTokens();
|
|
|
|
#endif
|
2018-05-07 00:47:40 +00:00
|
|
|
if (unloaded && transferred)
|
|
|
|
x12c_postConstructed->x1108_27_ = true;
|
2017-11-05 02:08:05 +00:00
|
|
|
}
|
2018-05-07 00:47:40 +00:00
|
|
|
x12c_postConstructed->x1108_26_ = true;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::PreRender()
|
|
|
|
{
|
2017-11-05 02:08:05 +00:00
|
|
|
if (!xf0_24_postConstructed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x12c_postConstructed->x1108_28_occlusionPinged)
|
|
|
|
x12c_postConstructed->x1108_28_occlusionPinged = false;
|
|
|
|
else
|
|
|
|
PingOcclusionState();
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 03:07:07 +00:00
|
|
|
void CGameArea::UpdateThermalVisor(float dt)
|
|
|
|
{
|
|
|
|
if (x12c_postConstructed->x1120_thermalSpeed == 0.f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
float influence = x12c_postConstructed->x111c_thermalCurrent;
|
|
|
|
|
|
|
|
float delta = x12c_postConstructed->x1120_thermalSpeed * dt;
|
|
|
|
if (std::fabs(x12c_postConstructed->x1124_thermalTarget -
|
|
|
|
x12c_postConstructed->x111c_thermalCurrent) < delta)
|
|
|
|
{
|
|
|
|
influence = x12c_postConstructed->x1124_thermalTarget;
|
|
|
|
x12c_postConstructed->x1120_thermalSpeed = 0.f;
|
|
|
|
}
|
|
|
|
else if (x12c_postConstructed->x1124_thermalTarget < influence)
|
|
|
|
influence -= delta;
|
|
|
|
else
|
|
|
|
influence += delta;
|
|
|
|
|
|
|
|
x12c_postConstructed->x111c_thermalCurrent = influence;
|
|
|
|
}
|
|
|
|
|
2017-09-07 03:55:31 +00:00
|
|
|
void CGameArea::UpdateWeaponWorldLighting(float dt)
|
|
|
|
{
|
|
|
|
float newLightingLevel = x12c_postConstructed->x1128_worldLightingLevel;
|
2018-05-10 02:56:54 +00:00
|
|
|
if (x12c_postConstructed->x112c_xraySpeed != 0.f)
|
2017-09-07 03:55:31 +00:00
|
|
|
{
|
|
|
|
float speed = dt * x12c_postConstructed->x112c_xraySpeed;
|
|
|
|
if (std::fabs(x12c_postConstructed->x1130_xrayTarget - newLightingLevel) < speed)
|
|
|
|
{
|
|
|
|
newLightingLevel = x12c_postConstructed->x1130_xrayTarget;
|
|
|
|
x12c_postConstructed->x1134_weaponWorldLightingSpeed = 0.f;
|
|
|
|
}
|
|
|
|
else if (x12c_postConstructed->x1130_xrayTarget < newLightingLevel)
|
|
|
|
{
|
|
|
|
newLightingLevel -= speed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newLightingLevel += speed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x12c_postConstructed->x1134_weaponWorldLightingSpeed != 0.f)
|
|
|
|
{
|
|
|
|
float newWeaponWorldLightingLevel = x12c_postConstructed->x1128_worldLightingLevel;
|
|
|
|
float speed = dt * x12c_postConstructed->x1134_weaponWorldLightingSpeed;
|
|
|
|
if (std::fabs(x12c_postConstructed->x1138_weaponWorldLightingTarget - newLightingLevel) < speed)
|
|
|
|
{
|
|
|
|
newWeaponWorldLightingLevel = x12c_postConstructed->x1138_weaponWorldLightingTarget;
|
|
|
|
x12c_postConstructed->x1134_weaponWorldLightingSpeed = 0.f;
|
|
|
|
}
|
|
|
|
else if (x12c_postConstructed->x1138_weaponWorldLightingTarget < newWeaponWorldLightingLevel)
|
|
|
|
{
|
|
|
|
newWeaponWorldLightingLevel -= speed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newWeaponWorldLightingLevel += speed;
|
|
|
|
}
|
|
|
|
if (x12c_postConstructed->x112c_xraySpeed != 0.f)
|
|
|
|
{
|
|
|
|
newLightingLevel = std::min(newLightingLevel, newWeaponWorldLightingLevel);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newLightingLevel = newWeaponWorldLightingLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (std::fabs(x12c_postConstructed->x1128_worldLightingLevel - newLightingLevel) >= 0.00001f)
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x1128_worldLightingLevel = newLightingLevel;
|
|
|
|
for (CEntity* ent : *x12c_postConstructed->x10c0_areaObjs)
|
|
|
|
if (TCastToPtr<CActor> act = ent)
|
|
|
|
act->SetWorldLightingDirty(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:26:17 +00:00
|
|
|
void CGameArea::AliveUpdate(float dt)
|
|
|
|
{
|
2017-03-31 19:51:40 +00:00
|
|
|
if (x12c_postConstructed->x10dc_occlusionState == EOcclusionState::Occluded)
|
2017-11-27 05:06:53 +00:00
|
|
|
x12c_postConstructed->x10e4_occludedTime += dt;
|
2016-07-23 03:07:07 +00:00
|
|
|
else
|
2017-11-27 05:06:53 +00:00
|
|
|
x12c_postConstructed->x10e4_occludedTime = 0.f;
|
2016-07-23 03:07:07 +00:00
|
|
|
UpdateFog(dt);
|
|
|
|
UpdateThermalVisor(dt);
|
2017-09-07 03:55:31 +00:00
|
|
|
UpdateWeaponWorldLighting(dt);
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::SetOcclusionState(EOcclusionState state)
|
|
|
|
{
|
2016-08-10 00:46:53 +00:00
|
|
|
if (!xf0_24_postConstructed || x12c_postConstructed->x10dc_occlusionState == state)
|
|
|
|
return;
|
|
|
|
|
2017-11-05 06:29:22 +00:00
|
|
|
if (state != EOcclusionState::Occluded)
|
2016-08-10 00:46:53 +00:00
|
|
|
{
|
|
|
|
ReloadAllUnloadedTextures();
|
|
|
|
AddStaticGeometry();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x1108_26_ = true;
|
|
|
|
x12c_postConstructed->x1108_27_ = false;
|
|
|
|
RemoveStaticGeometry();
|
|
|
|
}
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::RemoveStaticGeometry()
|
|
|
|
{
|
2016-08-10 00:46:53 +00:00
|
|
|
if (!xf0_24_postConstructed || !x12c_postConstructed ||
|
2017-03-31 19:51:40 +00:00
|
|
|
x12c_postConstructed->x10dc_occlusionState == EOcclusionState::Occluded)
|
2016-07-28 04:55:06 +00:00
|
|
|
return;
|
|
|
|
x12c_postConstructed->x10e0_ = 0;
|
2017-03-31 19:51:40 +00:00
|
|
|
x12c_postConstructed->x10dc_occlusionState = EOcclusionState::Occluded;
|
2016-07-28 04:55:06 +00:00
|
|
|
g_Renderer->RemoveStaticGeometry(&x12c_postConstructed->x4c_insts);
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::AddStaticGeometry()
|
|
|
|
{
|
2017-03-31 19:51:40 +00:00
|
|
|
if (x12c_postConstructed->x10dc_occlusionState != EOcclusionState::Visible)
|
2016-07-28 04:55:06 +00:00
|
|
|
{
|
|
|
|
x12c_postConstructed->x10e0_ = 0;
|
2017-03-31 19:51:40 +00:00
|
|
|
x12c_postConstructed->x10dc_occlusionState = EOcclusionState::Visible;
|
2017-04-18 23:41:01 +00:00
|
|
|
if (!x12c_postConstructed->x1108_25_modelsConstructed)
|
2016-07-28 04:55:06 +00:00
|
|
|
FillInStaticGeometry();
|
|
|
|
g_Renderer->AddStaticGeometry(&x12c_postConstructed->x4c_insts,
|
|
|
|
x12c_postConstructed->xc_octTree ?
|
|
|
|
&*x12c_postConstructed->xc_octTree : nullptr,
|
2017-11-19 23:48:09 +00:00
|
|
|
x4_selfIdx, &x12c_postConstructed->m_materialSet);
|
2016-07-28 04:55:06 +00:00
|
|
|
}
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-14 03:00:58 +00:00
|
|
|
EChain CGameArea::SetChain(CGameArea* next, EChain setChain)
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2016-08-14 03:00:58 +00:00
|
|
|
if (x138_curChain == setChain)
|
|
|
|
return x138_curChain;
|
|
|
|
|
|
|
|
if (x134_prev)
|
|
|
|
x134_prev->x130_next = x130_next;
|
|
|
|
if (x130_next)
|
|
|
|
x130_next->x134_prev = x134_prev;
|
|
|
|
|
|
|
|
x134_prev = nullptr;
|
|
|
|
x130_next = next;
|
|
|
|
if (next)
|
|
|
|
next->x134_prev = this;
|
|
|
|
|
|
|
|
EChain ret = x138_curChain;
|
|
|
|
x138_curChain = setChain;
|
|
|
|
return ret;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
bool CGameArea::StartStreamingMainArea()
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
if (xf0_24_postConstructed)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (xf4_phase)
|
|
|
|
{
|
2017-02-27 05:25:14 +00:00
|
|
|
case EPhase::LoadHeader:
|
2016-08-08 04:48:18 +00:00
|
|
|
{
|
|
|
|
x110_mreaSecBufs.reserve(3);
|
|
|
|
AllocNewAreaData(0, 96);
|
|
|
|
x12c_postConstructed.reset(new CPostConstructed());
|
2017-02-27 05:25:14 +00:00
|
|
|
xf4_phase = EPhase::LoadSecSizes;
|
2016-08-08 04:48:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-27 05:25:14 +00:00
|
|
|
case EPhase::LoadSecSizes:
|
2016-08-08 04:48:18 +00:00
|
|
|
{
|
|
|
|
CullDeadAreaRequests();
|
|
|
|
if (xf8_loadTransactions.size())
|
|
|
|
break;
|
2017-11-05 02:08:05 +00:00
|
|
|
SMREAHeader header = VerifyHeader();
|
2016-08-08 04:48:18 +00:00
|
|
|
AllocNewAreaData(x110_mreaSecBufs[0].second, ROUND_UP_32(header.secCount * 4));
|
2017-02-27 05:25:14 +00:00
|
|
|
xf4_phase = EPhase::ReserveSections;
|
2016-08-08 04:48:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-27 05:25:14 +00:00
|
|
|
case EPhase::ReserveSections:
|
2016-08-08 04:48:18 +00:00
|
|
|
{
|
|
|
|
CullDeadAreaRequests();
|
|
|
|
if (xf8_loadTransactions.size())
|
|
|
|
break;
|
2017-02-27 05:25:14 +00:00
|
|
|
//x110_mreaSecBufs.reserve(GetNumPartSizes() + 2);
|
2016-08-08 04:48:18 +00:00
|
|
|
x124_secCount = 0;
|
|
|
|
x128_mreaDataOffset = x110_mreaSecBufs[0].second + x110_mreaSecBufs[1].second;
|
2017-02-27 05:25:14 +00:00
|
|
|
xf4_phase = EPhase::LoadDataSections;
|
2016-08-08 04:48:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-27 05:25:14 +00:00
|
|
|
case EPhase::LoadDataSections:
|
2016-08-08 04:48:18 +00:00
|
|
|
{
|
|
|
|
CullDeadAreaRequests();
|
|
|
|
|
|
|
|
u32 totalSz = 0;
|
|
|
|
u32 secCount = GetNumPartSizes();
|
2017-02-27 05:25:14 +00:00
|
|
|
for (u32 i=0 ; i<secCount ; ++i)
|
2016-08-08 04:48:18 +00:00
|
|
|
totalSz += hecl::SBig(reinterpret_cast<u32*>(x110_mreaSecBufs[1].first.get())[i]);
|
|
|
|
|
|
|
|
AllocNewAreaData(x128_mreaDataOffset, totalSz);
|
|
|
|
|
|
|
|
m_resolvedBufs.reserve(secCount);
|
|
|
|
m_resolvedBufs.emplace_back(x110_mreaSecBufs[0].first.get(), x110_mreaSecBufs[0].second);
|
|
|
|
m_resolvedBufs.emplace_back(x110_mreaSecBufs[1].first.get(), x110_mreaSecBufs[1].second);
|
|
|
|
|
|
|
|
u32 curOff = 0;
|
2017-02-27 05:25:14 +00:00
|
|
|
for (u32 i=0 ; i<secCount ; ++i)
|
2016-08-08 04:48:18 +00:00
|
|
|
{
|
|
|
|
u32 size = hecl::SBig(reinterpret_cast<u32*>(x110_mreaSecBufs[1].first.get())[i]);
|
|
|
|
m_resolvedBufs.emplace_back(x110_mreaSecBufs[2].first.get() + curOff, size);
|
|
|
|
curOff += size;
|
|
|
|
}
|
|
|
|
|
2017-02-27 05:25:14 +00:00
|
|
|
xf4_phase = EPhase::WaitForFinish;
|
2016-08-08 04:48:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-02-27 05:25:14 +00:00
|
|
|
case EPhase::WaitForFinish:
|
2016-08-08 04:48:18 +00:00
|
|
|
{
|
|
|
|
CullDeadAreaRequests();
|
|
|
|
if (xf8_loadTransactions.size())
|
|
|
|
break;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-10 00:46:53 +00:00
|
|
|
void CGameArea::ReloadAllUnloadedTextures()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:26:17 +00:00
|
|
|
u32 CGameArea::GetNumPartSizes() const
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
return hecl::SBig(*reinterpret_cast<u32*>(x110_mreaSecBufs[0].first.get() + 60));
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
void CGameArea::AllocNewAreaData(int offset, int size)
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2016-08-08 19:07:30 +00:00
|
|
|
x110_mreaSecBufs.emplace_back(std::unique_ptr<u8[]>(new u8[size]), size);
|
2017-10-27 10:10:32 +00:00
|
|
|
xf8_loadTransactions.push_back(g_ResFactory->
|
2017-11-05 02:08:05 +00:00
|
|
|
LoadResourcePartAsync(SObjectTag{FOURCC('MREA'), x84_mrea}, offset, size,
|
2017-02-27 05:25:14 +00:00
|
|
|
x110_mreaSecBufs.back().first.get()));
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 12:33:28 +00:00
|
|
|
bool CGameArea::Invalidate(CStateManager* mgr)
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2018-05-08 02:18:18 +00:00
|
|
|
if (!xf0_24_postConstructed)
|
2017-11-02 12:33:28 +00:00
|
|
|
{
|
|
|
|
ClearTokenList();
|
2017-11-02 23:36:37 +00:00
|
|
|
|
2017-11-02 12:33:28 +00:00
|
|
|
for (auto it = xf8_loadTransactions.begin(); it != xf8_loadTransactions.end(); )
|
|
|
|
{
|
|
|
|
if (!(*it)->IsComplete())
|
2017-11-02 23:36:37 +00:00
|
|
|
{
|
2017-11-02 12:33:28 +00:00
|
|
|
(*it)->PostCancelRequest();
|
2017-11-02 23:36:37 +00:00
|
|
|
++it;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
it = xf8_loadTransactions.erase(it);
|
2017-11-02 12:33:28 +00:00
|
|
|
}
|
|
|
|
if (xf8_loadTransactions.size() != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
x12c_postConstructed.reset();
|
|
|
|
KillmAreaData();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mgr)
|
|
|
|
mgr->PrepareAreaUnload(GetAreaId());
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
dword_805a8eb0 -= GetPostConstructedSize();
|
|
|
|
#endif
|
|
|
|
RemoveStaticGeometry();
|
|
|
|
x12c_postConstructed.reset();
|
|
|
|
xf0_24_postConstructed = false;
|
|
|
|
xf0_28_validated = false;
|
|
|
|
xf4_phase = EPhase::LoadHeader;
|
|
|
|
xf8_loadTransactions.clear();
|
|
|
|
CullDeadAreaRequests();
|
|
|
|
KillmAreaData();
|
|
|
|
ClearTokenList();
|
|
|
|
if (mgr)
|
|
|
|
mgr->AreaUnloaded(GetAreaId());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::KillmAreaData()
|
|
|
|
{
|
|
|
|
x110_mreaSecBufs.clear();
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::CullDeadAreaRequests()
|
|
|
|
{
|
2016-08-08 04:48:18 +00:00
|
|
|
for (auto it = xf8_loadTransactions.begin() ; it != xf8_loadTransactions.end() ;)
|
|
|
|
{
|
2017-10-27 10:10:32 +00:00
|
|
|
if ((*it)->IsComplete())
|
2016-08-08 04:48:18 +00:00
|
|
|
{
|
|
|
|
it = xf8_loadTransactions.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::StartStreamIn(CStateManager& mgr)
|
|
|
|
{
|
2017-02-27 05:25:14 +00:00
|
|
|
if (xf0_24_postConstructed || xf0_27_paused)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VerifyTokenList(mgr);
|
|
|
|
|
|
|
|
if (!xf0_26_tokensReady)
|
|
|
|
{
|
|
|
|
u32 notLoaded = 0;
|
|
|
|
for (CToken& tok : xdc_tokens)
|
|
|
|
{
|
|
|
|
tok.Lock();
|
|
|
|
if (!tok.IsLoaded())
|
|
|
|
++notLoaded;
|
|
|
|
}
|
|
|
|
if (notLoaded)
|
|
|
|
return;
|
|
|
|
xf0_26_tokensReady = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
StartStreamingMainArea();
|
|
|
|
if (xf4_phase != EPhase::WaitForFinish)
|
|
|
|
return;
|
|
|
|
CullDeadAreaRequests();
|
|
|
|
if (xf8_loadTransactions.size())
|
|
|
|
return;
|
|
|
|
Validate(mgr);
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 09:27:01 +00:00
|
|
|
void CGameArea::Validate(CStateManager& mgr)
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2017-02-19 09:27:01 +00:00
|
|
|
if (xf0_24_postConstructed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (StartStreamingMainArea()) {}
|
|
|
|
|
|
|
|
for (auto& req : xf8_loadTransactions)
|
2017-10-27 10:10:32 +00:00
|
|
|
req->WaitUntilComplete();
|
2017-02-19 09:27:01 +00:00
|
|
|
|
|
|
|
if (xdc_tokens.empty())
|
|
|
|
{
|
|
|
|
VerifyTokenList(mgr);
|
|
|
|
for (CToken& tok : xdc_tokens)
|
|
|
|
tok.Lock();
|
|
|
|
for (CToken& tok : xdc_tokens)
|
|
|
|
tok.GetObj();
|
|
|
|
xf0_26_tokensReady = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
xf8_loadTransactions.clear();
|
|
|
|
|
|
|
|
PostConstructArea();
|
|
|
|
if (x4_selfIdx != kInvalidAreaId)
|
2017-11-12 05:14:57 +00:00
|
|
|
mgr.WorldNC()->MoveAreaToAliveChain(x4_selfIdx);
|
2017-02-19 09:27:01 +00:00
|
|
|
|
|
|
|
LoadScriptObjects(mgr);
|
|
|
|
|
|
|
|
CPVSAreaSet* pvs = x12c_postConstructed->xa0_pvs.get();
|
|
|
|
if (pvs && x12c_postConstructed->x1108_29_)
|
|
|
|
{
|
|
|
|
for (int i=0 ; i<pvs->GetNumActors() ; ++i)
|
|
|
|
{
|
|
|
|
TEditorId entId = pvs->GetEntityIdByIndex(i) | (x4_selfIdx << 16);
|
|
|
|
TUniqueId id = mgr.GetIdForScript(entId);
|
|
|
|
if (id != kInvalidUniqueId)
|
|
|
|
{
|
2017-08-10 13:40:07 +00:00
|
|
|
CPostConstructed::MapEntry& ent = x12c_postConstructed->xa8_pvsEntityMap[id.Value()];
|
2017-02-19 09:27:01 +00:00
|
|
|
ent.x0_id = i + (pvs->GetNumFeatures() - pvs->GetNumActors());
|
|
|
|
ent.x4_uid = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xf0_28_validated = true;
|
|
|
|
mgr.AreaLoaded(x4_selfIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::LoadScriptObjects(CStateManager& mgr)
|
|
|
|
{
|
|
|
|
CWorldLayerState& layerState = *mgr.LayerState();
|
|
|
|
u32 layerCount = layerState.GetAreaLayerCount(x4_selfIdx);
|
|
|
|
std::vector<TEditorId> objIds;
|
|
|
|
for (u32 i=0 ; i<layerCount ; ++i)
|
|
|
|
{
|
|
|
|
if (layerState.IsLayerActive(x4_selfIdx, i))
|
|
|
|
{
|
|
|
|
auto layerBuf = GetLayerScriptBuffer(i);
|
|
|
|
CMemoryInStream r(layerBuf.first, layerBuf.second);
|
|
|
|
mgr.LoadScriptObjects(x4_selfIdx, r, objIds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mgr.InitScriptObjects(objIds);
|
|
|
|
}
|
|
|
|
|
2017-02-27 05:25:14 +00:00
|
|
|
std::pair<const u8*, u32> CGameArea::GetLayerScriptBuffer(int layer)
|
2017-02-19 09:27:01 +00:00
|
|
|
{
|
|
|
|
if (!xf0_24_postConstructed)
|
|
|
|
return {};
|
|
|
|
return x12c_postConstructed->x110c_layerPtrs[layer];
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::PostConstructArea()
|
|
|
|
{
|
2017-11-05 02:08:05 +00:00
|
|
|
SMREAHeader header = VerifyHeader();
|
2016-08-07 00:20:02 +00:00
|
|
|
|
2017-02-27 05:25:14 +00:00
|
|
|
auto secIt = m_resolvedBufs.begin() + 2;
|
|
|
|
|
|
|
|
/* Materials */
|
|
|
|
++secIt;
|
|
|
|
|
|
|
|
u32 sec = 3;
|
2016-08-07 00:20:02 +00:00
|
|
|
|
|
|
|
/* Models */
|
2017-10-22 06:11:22 +00:00
|
|
|
x12c_postConstructed->x4c_insts.resize(header.modelCount);
|
2017-02-27 05:25:14 +00:00
|
|
|
for (u32 i=0 ; i<header.modelCount ; ++i)
|
2016-08-07 00:20:02 +00:00
|
|
|
{
|
2017-02-27 05:25:14 +00:00
|
|
|
u32 surfCount = hecl::SBig(*reinterpret_cast<const u32*>((secIt+4)->first));
|
|
|
|
secIt += 5 + surfCount;
|
|
|
|
sec += 5 + surfCount;
|
2016-08-07 00:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Render octree */
|
|
|
|
if (header.version == 15 && header.arotSecIdx != -1)
|
|
|
|
{
|
2017-02-27 05:25:14 +00:00
|
|
|
x12c_postConstructed->xc_octTree.emplace(secIt->first);
|
2016-08-07 00:20:02 +00:00
|
|
|
++secIt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scriptable layer section */
|
2017-02-27 05:25:14 +00:00
|
|
|
x12c_postConstructed->x10c8_sclyBuf = secIt->first;
|
2016-08-07 00:20:02 +00:00
|
|
|
x12c_postConstructed->x10d0_sclySize = secIt->second;
|
|
|
|
++secIt;
|
|
|
|
|
|
|
|
/* Collision section */
|
2017-02-27 05:25:14 +00:00
|
|
|
std::unique_ptr<CAreaOctTree> collision = CAreaOctTree::MakeFromMemory(secIt->first, secIt->second);
|
2016-08-07 00:20:02 +00:00
|
|
|
if (collision)
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x0_collision = std::move(collision);
|
|
|
|
x12c_postConstructed->x8_collisionSize = secIt->second;
|
|
|
|
}
|
|
|
|
++secIt;
|
|
|
|
|
|
|
|
/* Unknown section */
|
|
|
|
++secIt;
|
|
|
|
|
|
|
|
/* Lights section */
|
|
|
|
if (header.version > 6)
|
|
|
|
{
|
2017-02-27 05:25:14 +00:00
|
|
|
athena::io::MemoryReader r(secIt->first, secIt->second);
|
2016-08-07 00:20:02 +00:00
|
|
|
u32 magic = r.readUint32Big();
|
|
|
|
if (magic == 0xBABEDEAD)
|
|
|
|
{
|
|
|
|
u32 aCount = r.readUint32Big();
|
|
|
|
x12c_postConstructed->x60_lightsA.reserve(aCount);
|
|
|
|
x12c_postConstructed->x70_gfxLightsA.reserve(aCount);
|
|
|
|
for (u32 i=0 ; i<aCount ; ++i)
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x60_lightsA.emplace_back(r);
|
|
|
|
x12c_postConstructed->x70_gfxLightsA.push_back(
|
|
|
|
x12c_postConstructed->x60_lightsA.back().GetAsCGraphicsLight());
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 bCount = r.readUint32Big();
|
|
|
|
x12c_postConstructed->x80_lightsB.reserve(bCount);
|
|
|
|
x12c_postConstructed->x90_gfxLightsB.reserve(bCount);
|
|
|
|
for (u32 i=0 ; i<bCount ; ++i)
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x80_lightsB.emplace_back(r);
|
|
|
|
x12c_postConstructed->x90_gfxLightsB.push_back(
|
|
|
|
x12c_postConstructed->x80_lightsB.back().GetAsCGraphicsLight());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
++secIt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PVS section */
|
|
|
|
if (header.version > 7)
|
|
|
|
{
|
2017-02-27 05:25:14 +00:00
|
|
|
athena::io::MemoryReader r(secIt->first, secIt->second);
|
2016-08-07 00:20:02 +00:00
|
|
|
u32 magic = r.readUint32Big();
|
|
|
|
if (magic == 'VISI')
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x10a8_pvsVersion = r.readUint32Big();
|
|
|
|
if (x12c_postConstructed->x10a8_pvsVersion == 2)
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x1108_29_ = r.readBool();
|
|
|
|
x12c_postConstructed->x1108_30_ = r.readBool();
|
2017-02-27 05:25:14 +00:00
|
|
|
x12c_postConstructed->xa0_pvs = std::make_unique<CPVSAreaSet>(secIt->first + r.position(),
|
2017-02-19 09:27:01 +00:00
|
|
|
secIt->second - r.position());
|
2016-08-07 00:20:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
++secIt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pathfinding section */
|
|
|
|
if (header.version > 9)
|
|
|
|
{
|
2017-02-27 05:25:14 +00:00
|
|
|
athena::io::MemoryReader r(secIt->first, secIt->second);
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId pathId = r.readUint32Big();
|
2016-08-07 00:20:02 +00:00
|
|
|
x12c_postConstructed->x10ac_path = g_SimplePool->GetObj(SObjectTag{FOURCC('PATH'), pathId});
|
|
|
|
++secIt;
|
|
|
|
}
|
|
|
|
|
2017-01-15 03:59:37 +00:00
|
|
|
x12c_postConstructed->x10c0_areaObjs.reset(new CAreaObjectList(x4_selfIdx));
|
2016-08-07 00:20:02 +00:00
|
|
|
x12c_postConstructed->x10c4_areaFog.reset(new CAreaFog());
|
|
|
|
|
|
|
|
xf0_24_postConstructed = true;
|
|
|
|
|
|
|
|
/* Resolve layer pointers */
|
|
|
|
if (x12c_postConstructed->x10c8_sclyBuf)
|
|
|
|
{
|
2017-02-27 05:25:14 +00:00
|
|
|
athena::io::MemoryReader r(x12c_postConstructed->x10c8_sclyBuf, x12c_postConstructed->x10d0_sclySize);
|
2016-08-07 00:20:02 +00:00
|
|
|
u32 magic = r.readUint32Big();
|
|
|
|
if (magic == 'SCLY')
|
|
|
|
{
|
|
|
|
r.readUint32Big();
|
|
|
|
u32 layerCount = r.readUint32Big();
|
|
|
|
x12c_postConstructed->x110c_layerPtrs.resize(layerCount);
|
|
|
|
for (u32 l=0 ; l<layerCount ; ++l)
|
|
|
|
x12c_postConstructed->x110c_layerPtrs[l].second = r.readUint32Big();
|
2017-02-27 05:25:14 +00:00
|
|
|
const u8* ptr = x12c_postConstructed->x10c8_sclyBuf + r.position();
|
2016-08-07 00:20:02 +00:00
|
|
|
for (u32 l=0 ; l<layerCount ; ++l)
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x110c_layerPtrs[l].first = ptr;
|
|
|
|
ptr += x12c_postConstructed->x110c_layerPtrs[l].second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
void CGameArea::FillInStaticGeometry(bool textures)
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2017-10-22 06:11:22 +00:00
|
|
|
if (!x12c_postConstructed->x4c_insts.empty())
|
|
|
|
for (CMetroidModelInstance& inst : x12c_postConstructed->x4c_insts)
|
|
|
|
inst.Clear();
|
2016-08-08 04:48:18 +00:00
|
|
|
|
2017-04-18 23:41:01 +00:00
|
|
|
/* Materials */
|
2017-11-19 23:48:09 +00:00
|
|
|
SShader& matSet = x12c_postConstructed->m_materialSet;
|
2017-04-18 23:41:01 +00:00
|
|
|
auto secIt = m_resolvedBufs.begin() + 2;
|
|
|
|
{
|
|
|
|
athena::io::MemoryReader r(secIt->first, secIt->second);
|
2017-10-22 06:11:22 +00:00
|
|
|
matSet.m_matSet.read(r);
|
|
|
|
if (textures)
|
|
|
|
CBooModel::MakeTexturesFromMats(matSet.m_matSet, matSet.x0_textures, *g_SimplePool);
|
2017-11-19 23:48:09 +00:00
|
|
|
matSet.InitializeLayout(nullptr);
|
2017-04-18 23:41:01 +00:00
|
|
|
++secIt;
|
|
|
|
}
|
|
|
|
|
2017-11-05 06:17:12 +00:00
|
|
|
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
|
2017-04-18 23:41:01 +00:00
|
|
|
{
|
2018-01-15 07:39:25 +00:00
|
|
|
/* Shared geometry uniform buffer - one for normal render, one for shadow render */
|
|
|
|
for (int i=0 ; i<2 ; ++i)
|
|
|
|
matSet.m_geomLayout->m_sharedBuffer[i] =
|
|
|
|
ctx.newDynamicBuffer(boo::BufferUse::Uniform, matSet.m_geomLayout->m_geomBufferSize, 1);
|
2017-11-19 23:48:09 +00:00
|
|
|
|
2017-04-18 23:41:01 +00:00
|
|
|
/* Models */
|
2017-10-22 06:11:22 +00:00
|
|
|
for (CMetroidModelInstance& inst : x12c_postConstructed->x4c_insts)
|
2017-04-18 23:41:01 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
DataSpec::DNAMP1::MREA::MeshHeader header;
|
|
|
|
athena::io::MemoryReader r(secIt->first, secIt->second);
|
|
|
|
header.read(r);
|
|
|
|
inst.x0_visorFlags = header.visorFlags.flags;
|
|
|
|
inst.x4_xf = header.xfMtx;
|
|
|
|
inst.x34_aabb = zeus::CAABox(header.aabb[0], header.aabb[1]);
|
|
|
|
++secIt;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
athena::io::MemoryReader r(secIt->first, secIt->second);
|
2017-10-22 06:11:22 +00:00
|
|
|
inst.m_hmdlMeta.read(r);
|
2017-04-18 23:41:01 +00:00
|
|
|
}
|
|
|
|
++secIt;
|
|
|
|
|
2017-11-05 06:17:12 +00:00
|
|
|
boo::ObjToken<boo::IGraphicsBufferS> vbo;
|
|
|
|
boo::ObjToken<boo::IGraphicsBufferS> ibo;
|
|
|
|
boo::ObjToken<boo::IVertexFormat> vtxFmt;
|
2017-10-22 06:11:22 +00:00
|
|
|
vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, secIt->first, inst.m_hmdlMeta.vertStride,
|
|
|
|
inst.m_hmdlMeta.vertCount);
|
2017-04-18 23:41:01 +00:00
|
|
|
++secIt;
|
2017-10-22 06:11:22 +00:00
|
|
|
ibo = ctx.newStaticBuffer(boo::BufferUse::Index, secIt->first, 4, inst.m_hmdlMeta.indexCount);
|
2017-04-18 23:41:01 +00:00
|
|
|
++secIt;
|
2017-11-05 06:17:12 +00:00
|
|
|
vtxFmt = hecl::Runtime::HMDLData::NewVertexFormat(ctx, inst.m_hmdlMeta, vbo.get(), ibo.get());
|
2017-04-18 23:41:01 +00:00
|
|
|
|
|
|
|
u32 surfCount = hecl::SBig(*reinterpret_cast<const u32*>(secIt->first));
|
|
|
|
inst.m_surfaces.reserve(surfCount);
|
2017-11-21 10:36:18 +00:00
|
|
|
inst.m_shaders.reserve(surfCount);
|
2017-04-18 23:41:01 +00:00
|
|
|
++secIt;
|
2017-10-22 06:11:22 +00:00
|
|
|
for (u32 j=0 ; j<surfCount ; ++j)
|
2017-04-18 23:41:01 +00:00
|
|
|
{
|
|
|
|
inst.m_surfaces.emplace_back();
|
|
|
|
CBooSurface& surf = inst.m_surfaces.back();
|
2017-10-22 06:11:22 +00:00
|
|
|
surf.selfIdx = j;
|
2017-04-18 23:41:01 +00:00
|
|
|
athena::io::MemoryReader r(secIt->first, secIt->second);
|
|
|
|
surf.m_data.read(r);
|
|
|
|
++secIt;
|
|
|
|
}
|
|
|
|
|
|
|
|
TToken<CModel> nullModel;
|
|
|
|
inst.m_instance = std::make_unique<CBooModel>
|
2017-10-22 06:11:22 +00:00
|
|
|
(nullModel, nullptr, &inst.m_surfaces, matSet, vtxFmt, vbo, ibo,
|
|
|
|
inst.x34_aabb, inst.x0_visorFlags, 0, nullptr);
|
2017-04-18 23:41:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
for (CMetroidModelInstance& inst : x12c_postConstructed->x4c_insts)
|
|
|
|
{
|
|
|
|
for (CBooSurface& surf : inst.m_surfaces)
|
|
|
|
{
|
|
|
|
auto& shad = inst.m_shaders[surf.m_data.matIdx];
|
|
|
|
if (!shad)
|
|
|
|
shad = matSet.BuildShader(inst.m_hmdlMeta, matSet.m_matSet.materials[surf.m_data.matIdx]);
|
|
|
|
}
|
|
|
|
inst.m_instance->RemapMaterialData(matSet, inst.m_shaders);
|
|
|
|
}
|
|
|
|
|
2017-04-18 23:41:01 +00:00
|
|
|
x12c_postConstructed->x1108_25_modelsConstructed = true;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-07 00:20:02 +00:00
|
|
|
void CGameArea::VerifyTokenList(CStateManager& stateMgr)
|
2016-07-23 00:26:17 +00:00
|
|
|
{
|
2017-02-19 09:27:01 +00:00
|
|
|
if (xdc_tokens.size())
|
2016-08-07 00:20:02 +00:00
|
|
|
return;
|
|
|
|
ClearTokenList();
|
|
|
|
|
|
|
|
if (xac_deps2.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
u32 lastOff = 0;
|
|
|
|
int lidx = 0;
|
|
|
|
for (u32 off : xbc_layerDepOffsets)
|
|
|
|
{
|
2016-10-09 21:41:23 +00:00
|
|
|
if (stateMgr.LayerState()->IsLayerActive(x4_selfIdx, lidx))
|
2016-08-07 00:20:02 +00:00
|
|
|
{
|
|
|
|
auto it = xac_deps2.begin() + lastOff;
|
|
|
|
auto end = xac_deps2.begin() + off;
|
|
|
|
for (; it != end ; ++it)
|
|
|
|
{
|
|
|
|
xdc_tokens.push_back(g_SimplePool->GetObj(*it));
|
|
|
|
xdc_tokens.back().Lock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastOff = off;
|
|
|
|
++lidx;
|
|
|
|
}
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArea::ClearTokenList()
|
|
|
|
{
|
2016-08-07 00:20:02 +00:00
|
|
|
if (xdc_tokens.empty())
|
|
|
|
xdc_tokens.reserve(xac_deps2.size());
|
|
|
|
else
|
|
|
|
xdc_tokens.clear();
|
|
|
|
|
2017-02-19 09:27:01 +00:00
|
|
|
xf0_26_tokensReady = false;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
2016-04-19 00:17:49 +00:00
|
|
|
|
2016-07-23 00:26:17 +00:00
|
|
|
u32 CGameArea::GetPreConstructedSize() const
|
|
|
|
{
|
2016-07-24 06:05:12 +00:00
|
|
|
return 0;
|
2016-07-23 00:26:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 02:08:05 +00:00
|
|
|
SMREAHeader CGameArea::VerifyHeader() const
|
2016-08-07 00:20:02 +00:00
|
|
|
{
|
|
|
|
if (x110_mreaSecBufs.empty())
|
|
|
|
return {};
|
|
|
|
if (*reinterpret_cast<u32*>(x110_mreaSecBufs[0].first.get()) != SBIG(0xDEADBEEF))
|
|
|
|
return {};
|
|
|
|
|
2017-11-05 02:08:05 +00:00
|
|
|
SMREAHeader header;
|
|
|
|
CMemoryInStream r(x110_mreaSecBufs[0].first.get() + 4, x110_mreaSecBufs[0].second - 4);
|
2016-08-07 00:20:02 +00:00
|
|
|
u32 version = r.readUint32Big();
|
2017-02-27 05:25:14 +00:00
|
|
|
if (!(version & 0x10000))
|
|
|
|
Log.report(logvisor::Fatal, "Attempted to load non-URDE MREA");
|
|
|
|
version &= ~0x10000;
|
2016-08-07 00:20:02 +00:00
|
|
|
header.version = (version >= 12 && version <= 15) ? version : 0;
|
|
|
|
if (!header.version)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
header.xf.read34RowMajor(r);
|
|
|
|
header.modelCount = r.readUint32Big();
|
|
|
|
header.secCount = r.readUint32Big();
|
|
|
|
header.geomSecIdx = r.readUint32Big();
|
|
|
|
header.sclySecIdx = r.readUint32Big();
|
|
|
|
header.collisionSecIdx = r.readUint32Big();
|
|
|
|
header.unkSecIdx = r.readUint32Big();
|
|
|
|
header.lightSecIdx = r.readUint32Big();
|
|
|
|
header.visiSecIdx = r.readUint32Big();
|
|
|
|
header.pathSecIdx = r.readUint32Big();
|
|
|
|
header.arotSecIdx = r.readUint32Big();
|
|
|
|
|
|
|
|
return header;
|
2016-04-19 00:17:49 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 04:31:08 +00:00
|
|
|
TUniqueId CGameArea::LookupPVSUniqueID(TUniqueId id) const
|
|
|
|
{
|
2017-08-10 13:40:07 +00:00
|
|
|
return x12c_postConstructed->xa8_pvsEntityMap[id.Value()].x4_uid;
|
2017-03-04 04:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s16 CGameArea::LookupPVSID(TUniqueId id) const
|
|
|
|
{
|
2017-08-10 13:40:07 +00:00
|
|
|
return x12c_postConstructed->xa8_pvsEntityMap[id.Value()].x0_id;
|
2017-03-04 04:31:08 +00:00
|
|
|
}
|
|
|
|
|
2016-10-02 03:06:20 +00:00
|
|
|
void CGameArea::SetAreaAttributes(const CScriptAreaAttributes* areaAttributes)
|
|
|
|
{
|
|
|
|
x12c_postConstructed->x10d8_areaAttributes = areaAttributes;
|
|
|
|
if (areaAttributes == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
x12c_postConstructed->x111c_thermalCurrent = areaAttributes->GetThermalHeat();
|
|
|
|
x12c_postConstructed->x1128_worldLightingLevel = areaAttributes->GetWorldLightingLevel();
|
|
|
|
}
|
|
|
|
|
2017-01-15 03:59:37 +00:00
|
|
|
bool CGameArea::CAreaObjectList::IsQualified(const CEntity& ent)
|
|
|
|
{
|
2017-03-26 05:53:04 +00:00
|
|
|
return (ent.GetAreaIdAlways() == x200c_areaIdx);
|
2017-01-15 03:59:37 +00:00
|
|
|
}
|
2017-10-17 05:51:53 +00:00
|
|
|
void CGameArea::WarmupShaders(const SObjectTag& mreaTag)
|
|
|
|
{
|
|
|
|
// Calling this version of the constructor performs warmup implicitly
|
|
|
|
CGameArea area(mreaTag.id);
|
|
|
|
}
|
2017-01-15 03:59:37 +00:00
|
|
|
|
2016-04-19 00:17:49 +00:00
|
|
|
}
|