CGameArea imps

This commit is contained in:
Phillip Stephens 2017-11-04 19:08:05 -07:00
parent e98fc22a2c
commit 44df36d64a
14 changed files with 162 additions and 70 deletions

View File

@ -377,7 +377,7 @@ ProjectResourceFactoryBase::LoadResourceAsync(const urde::SObjectTag& tag, void*
std::shared_ptr<urde::IDvdRequest>
ProjectResourceFactoryBase::LoadResourcePartAsync(const urde::SObjectTag& tag,
u32 size, u32 off, void* target)
u32 off, u32 size, void* target)
{
if (!tag.id.IsValid())
Log.report(logvisor::Fatal, "attempted to access null id");
@ -404,8 +404,8 @@ std::unique_ptr<u8[]> ProjectResourceFactoryBase::LoadResourceSync(const urde::S
return fr->readUBytes(fr->length());
}
std::unique_ptr<u8[]> ProjectResourceFactoryBase::LoadResourcePartSync(const urde::SObjectTag& tag,
u32 size, u32 off)
std::unique_ptr<u8[]> ProjectResourceFactoryBase::LoadNewResourcePartSync(const urde::SObjectTag& tag,
u32 off, u32 size)
{
if (!tag.id.IsValid())
Log.report(logvisor::Fatal, "attempted to access null id");

View File

@ -162,9 +162,9 @@ public:
u32 ResourceSize(const SObjectTag& tag);
std::shared_ptr<urde::IDvdRequest> LoadResourceAsync(const urde::SObjectTag& tag, void* target);
std::shared_ptr<urde::IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 size, u32 off, void* target);
std::shared_ptr<urde::IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size, void* target);
std::unique_ptr<u8[]> LoadResourceSync(const urde::SObjectTag& tag);
std::unique_ptr<u8[]> LoadResourcePartSync(const urde::SObjectTag& tag, u32 size, u32 off);
std::unique_ptr<u8[]> LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size);
std::shared_ptr<AsyncTask> CookResourceAsync(const urde::SObjectTag& tag);

View File

@ -64,9 +64,9 @@ public:
return x4_loader.LoadResourceSync(tag);
}
std::unique_ptr<u8[]> LoadResourcePartSync(const urde::SObjectTag& tag, u32 size, u32 off)
std::unique_ptr<u8[]> LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size)
{
return x4_loader.LoadResourcePartSync(tag, size, off);
return x4_loader.LoadNewResourcePartSync(tag, off, size);
}
void GetTagListForFile(const char* pakName, std::vector<SObjectTag>& out) const
@ -79,9 +79,9 @@ public:
return x4_loader.LoadResourceAsync(tag, target);
}
std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 size, u32 off, void* target)
std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size, void* target)
{
return x4_loader.LoadResourcePartAsync(tag, size, off, target);
return x4_loader.LoadResourcePartAsync(tag, off, size, target);
}
const SObjectTag* GetResourceIdByName(const char* name) const

View File

@ -115,7 +115,7 @@ std::unique_ptr<u8[]> CResLoader::LoadResourceSync(const urde::SObjectTag& tag)
return ret;
}
std::unique_ptr<u8[]> CResLoader::LoadResourcePartSync(const urde::SObjectTag& tag, u32 size, u32 off)
std::unique_ptr<u8[]> CResLoader::LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size)
{
CPakFile* file = FindResourceForLoad(tag.id);
std::unique_ptr<u8[]> ret(new u8[size]);

View File

@ -33,10 +33,10 @@ public:
void LoadMemResourceSync(const SObjectTag& tag, std::unique_ptr<u8[]>& bufOut, int* sizeOut);
std::unique_ptr<CInputStream> LoadResourceFromMemorySync(const SObjectTag& tag, const void* buf);
std::unique_ptr<CInputStream> LoadNewResourceSync(const SObjectTag& tag, void* extBuf=nullptr);
std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const SObjectTag& tag, u32 length, u32 offset, void* buf);
std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const SObjectTag& tag, u32 offset, u32 length, void* buf);
std::shared_ptr<IDvdRequest> LoadResourceAsync(const SObjectTag& tag, void* buf);
std::unique_ptr<u8[]> LoadResourceSync(const urde::SObjectTag& tag);
std::unique_ptr<u8[]> LoadResourcePartSync(const urde::SObjectTag& tag, u32 size, u32 off);
std::unique_ptr<u8[]> LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size);
void GetTagListForFile(const char* pakName, std::vector<SObjectTag>& out) const;
bool GetResourceCompression(const SObjectTag& tag);
u32 ResourceSize(const SObjectTag& tag);

View File

@ -67,7 +67,7 @@ std::shared_ptr<IDvdRequest> CCharacterFactoryBuilder::CDummyFactory::LoadResour
}
std::shared_ptr<IDvdRequest> CCharacterFactoryBuilder::CDummyFactory::LoadResourcePartAsync(const urde::SObjectTag& tag,
u32 size, u32 off,
u32 off, u32 size,
void* target)
{
return {};
@ -78,8 +78,8 @@ std::unique_ptr<u8[]> CCharacterFactoryBuilder::CDummyFactory::LoadResourceSync(
return {};
}
std::unique_ptr<u8[]> CCharacterFactoryBuilder::CDummyFactory::LoadResourcePartSync(const urde::SObjectTag& tag,
u32 size, u32 off)
std::unique_ptr<u8[]> CCharacterFactoryBuilder::CDummyFactory::LoadNewResourcePartSync(const urde::SObjectTag& tag,
u32 off, u32 size)
{
return {};
}

View File

@ -29,9 +29,9 @@ public:
u32 ResourceSize(const urde::SObjectTag& tag);
std::shared_ptr<IDvdRequest> LoadResourceAsync(const urde::SObjectTag& tag, void* target);
std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 size, u32 off, void* target);
std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size, void* target);
std::unique_ptr<u8[]> LoadResourceSync(const urde::SObjectTag& tag);
std::unique_ptr<u8[]> LoadResourcePartSync(const urde::SObjectTag& tag, u32 size, u32 off);
std::unique_ptr<u8[]> LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size);
};
private:

View File

@ -95,7 +95,7 @@ std::shared_ptr<IDvdRequest> CCharacterFactory::CDummyFactory::LoadResourceAsync
}
std::shared_ptr<IDvdRequest> CCharacterFactory::CDummyFactory::LoadResourcePartAsync(const urde::SObjectTag& tag,
u32 size, u32 off,
u32 off, u32 size,
void* target)
{
return {};
@ -106,8 +106,8 @@ std::unique_ptr<u8[]> CCharacterFactory::CDummyFactory::LoadResourceSync(const u
return {};
}
std::unique_ptr<u8[]> CCharacterFactory::CDummyFactory::LoadResourcePartSync(const urde::SObjectTag& tag,
u32 size, u32 off)
std::unique_ptr<u8[]> CCharacterFactory::CDummyFactory::LoadNewResourcePartSync(const urde::SObjectTag& tag,
u32 off, u32 size)
{
return {};
}

View File

@ -38,9 +38,9 @@ public:
u32 ResourceSize(const urde::SObjectTag& tag);
std::shared_ptr<IDvdRequest> LoadResourceAsync(const urde::SObjectTag& tag, void* target);
std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 size, u32 off, void* target);
std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size, void* target);
std::unique_ptr<u8[]> LoadResourceSync(const urde::SObjectTag& tag);
std::unique_ptr<u8[]> LoadResourcePartSync(const urde::SObjectTag& tag, u32 size, u32 off);
std::unique_ptr<u8[]> LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size);
};
private:

View File

@ -45,9 +45,9 @@ public:
/* Non-factory versions, replaces CResLoader */
virtual u32 ResourceSize(const urde::SObjectTag& tag)=0;
virtual std::shared_ptr<IDvdRequest> LoadResourceAsync(const urde::SObjectTag& tag, void* target)=0;
virtual std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 size, u32 off, void* target)=0;
virtual std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size, void* target)=0;
virtual std::unique_ptr<u8[]> LoadResourceSync(const urde::SObjectTag& tag)=0;
virtual std::unique_ptr<u8[]> LoadResourcePartSync(const urde::SObjectTag& tag, u32 size, u32 off)=0;
virtual std::unique_ptr<u8[]> LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size)=0;
virtual void GetTagListForFile(const char* pakName, std::vector<SObjectTag>& out) const {}
virtual CAssetId TranslateOriginalToNew(CAssetId id) const { return -1; }

View File

@ -293,6 +293,55 @@ static std::vector<SObjectTag> ReadDependencyList(CInputStream& in)
return ret;
}
std::pair<std::unique_ptr<u8[]>, s32> GetScriptingMemoryAlways(const IGameArea& area)
{
SObjectTag tag = {SBIG('MREA'), area.IGetAreaAssetId()};
std::unique_ptr<u8[]> data = std::move(g_ResFactory->LoadNewResourcePartSync(tag, 0, 96, data));
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);
data.reset(std::move(g_ResFactory->LoadNewResourcePartSync(tag, 96, dataLen)));
r = CMemoryInStream(data, dataLen);
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 {};
}
CDummyGameArea::CDummyGameArea(CInputStream& in, int idx, int mlvlVersion)
{
x8_nameSTRG = in.readUint32Big();
@ -326,7 +375,7 @@ CDummyGameArea::CDummyGameArea(CInputStream& in, int idx, int mlvlVersion)
bool CDummyGameArea::IGetScriptingMemoryAlways() const
{
return false;
return GetScriptingMemoryAlways(*this);
}
TAreaId CDummyGameArea::IGetAreaId() const
@ -418,7 +467,7 @@ CGameArea::CGameArea(CAssetId mreaId)
for (auto& req : xf8_loadTransactions)
req->WaitUntilComplete();
MREAHeader header = VerifyHeader();
SMREAHeader header = VerifyHeader();
x12c_postConstructed->x4c_insts.resize(header.modelCount);
FillInStaticGeometry(false);
@ -446,12 +495,12 @@ CGameArea::CGameArea(CAssetId mreaId)
bool CGameArea::IGetScriptingMemoryAlways() const
{
return false;
return GetScriptingMemoryAlways(*this);
}
bool CGameArea::IIsActive() const
{
return false;
return xf0_25_active;
}
TAreaId CGameArea::IGetAttachedAreaId(int idx) const
@ -520,7 +569,7 @@ EEnvFxType CGameArea::DoesAreaNeedEnvFx() const
return EEnvFxType::None;
const CScriptAreaAttributes* attrs = postConstructed->x10d8_areaAttributes;
if (attrs)
if (!attrs)
return EEnvFxType::None;
if (postConstructed->x10dc_occlusionState == EOcclusionState::Occluded)
return EEnvFxType::None;
@ -529,24 +578,73 @@ EEnvFxType CGameArea::DoesAreaNeedEnvFx() const
bool CGameArea::DoesAreaNeedSkyNow() const
{
return false;
const CPostConstructed* postConstructed = GetPostConstructed();
if (!postConstructed)
return false;
const CScriptAreaAttributes* attrs = postConstructed->x10d8_areaAttributes;
if (!attrs)
return false;
return attrs->GetNeedsSky();
}
void CGameArea::UpdateFog(float dt)
{
CAreaFog* fog = *GetPostConstructed()->x10c4_areaFog;
if (fog)
fog->Update(dt);
}
bool CGameArea::OtherAreaOcclusionChanged()
void CGameArea::OtherAreaOcclusionChanged()
{
return false;
if (GetPostConstructed()->x10e0_ == 3 && GetPostConstructed()->x10dc_occlusionState != EOcclusionState::Occluded)
{
#if 0
bool unloaded = UnloadAllloadedTextures();
bool transferred = TransferTokensToARAM();
x12c_postConstructed->x1108_27_ = (unloaded && transferred)
#endif
}
else
{
ReloadAllUnloadedTextures();
}
}
void CGameArea::PingOcclusionState()
{
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
if (unloaded && transferred)
x12c_postConstructed->x1108_27_ = true;
x12c_postConstructed->x1108_26_ = true;
}
}
void CGameArea::PreRender()
{
if (!xf0_24_postConstructed)
return;
if (x12c_postConstructed->x1108_28_occlusionPinged)
x12c_postConstructed->x1108_28_occlusionPinged = false;
else
PingOcclusionState();
}
void CGameArea::UpdateThermalVisor(float dt)
@ -722,7 +820,7 @@ bool CGameArea::StartStreamingMainArea()
CullDeadAreaRequests();
if (xf8_loadTransactions.size())
break;
MREAHeader header = VerifyHeader();
SMREAHeader header = VerifyHeader();
AllocNewAreaData(x110_mreaSecBufs[0].second, ROUND_UP_32(header.secCount * 4));
xf4_phase = EPhase::ReserveSections;
break;
@ -781,11 +879,6 @@ void CGameArea::ReloadAllUnloadedTextures()
{
}
void CGameArea::PrepTokens()
{
}
u32 CGameArea::GetNumPartSizes() const
{
return hecl::SBig(*reinterpret_cast<u32*>(x110_mreaSecBufs[0].first.get() + 60));
@ -795,7 +888,7 @@ void CGameArea::AllocNewAreaData(int offset, int size)
{
x110_mreaSecBufs.emplace_back(std::unique_ptr<u8[]>(new u8[size]), size);
xf8_loadTransactions.push_back(g_ResFactory->
LoadResourcePartAsync(SObjectTag{FOURCC('MREA'), x84_mrea}, size, offset,
LoadResourcePartAsync(SObjectTag{FOURCC('MREA'), x84_mrea}, offset, size,
x110_mreaSecBufs.back().first.get()));
}
@ -966,7 +1059,7 @@ std::pair<const u8*, u32> CGameArea::GetLayerScriptBuffer(int layer)
void CGameArea::PostConstructArea()
{
MREAHeader header = VerifyHeader();
SMREAHeader header = VerifyHeader();
auto secIt = m_resolvedBufs.begin() + 2;
@ -1223,15 +1316,15 @@ u32 CGameArea::GetPreConstructedSize() const
return 0;
}
CGameArea::MREAHeader CGameArea::VerifyHeader() const
SMREAHeader CGameArea::VerifyHeader() const
{
if (x110_mreaSecBufs.empty())
return {};
if (*reinterpret_cast<u32*>(x110_mreaSecBufs[0].first.get()) != SBIG(0xDEADBEEF))
return {};
MREAHeader header;
athena::io::MemoryReader r(x110_mreaSecBufs[0].first.get() + 4, x110_mreaSecBufs[0].second - 4);
SMREAHeader header;
CMemoryInStream r(x110_mreaSecBufs[0].first.get() + 4, x110_mreaSecBufs[0].second - 4);
u32 version = r.readUint32Big();
if (!(version & 0x10000))
Log.report(logvisor::Fatal, "Attempted to load non-URDE MREA");

View File

@ -23,6 +23,22 @@ namespace urde
{
class CStateManager;
class CScriptAreaAttributes;
struct SMREAHeader
{
u32 version = 0;
zeus::CTransform xf;
u32 modelCount;
u32 secCount;
u32 geomSecIdx;
u32 sclySecIdx;
u32 collisionSecIdx;
u32 unkSecIdx;
u32 lightSecIdx;
u32 visiSecIdx;
u32 pathSecIdx;
u32 arotSecIdx;
};
class CDummyGameArea : public IGameArea
{
friend class CDummyWorld;
@ -38,7 +54,7 @@ class CDummyGameArea : public IGameArea
public:
CDummyGameArea(CInputStream& in, int idx, int mlvlVersion);
bool IGetScriptingMemoryAlways() const;
std::pair<std::unique_ptr<u8[]>, s32> IGetScriptingMemoryAlways() const;
TAreaId IGetAreaId() const;
CAssetId IGetAreaAssetId() const;
bool IIsActive() const;
@ -237,7 +253,7 @@ public:
bool x1108_25_modelsConstructed : 1;
bool x1108_26_ : 1;
bool x1108_27_ : 1;
bool x1108_28_ : 1;
bool x1108_28_occlusionPinged : 1;
bool x1108_29_ : 1;
bool x1108_30_ : 1;
};
@ -269,22 +285,6 @@ private:
void UpdateThermalVisor(float dt);
void UpdateWeaponWorldLighting(float dt);
struct MREAHeader
{
u32 version = 0;
zeus::CTransform xf;
u32 modelCount;
u32 secCount;
u32 geomSecIdx;
u32 sclySecIdx;
u32 collisionSecIdx;
u32 unkSecIdx;
u32 lightSecIdx;
u32 visiSecIdx;
u32 pathSecIdx;
u32 arotSecIdx;
};
public:
CGameArea(CInputStream& in, int idx, int mlvlVersion);
@ -294,7 +294,7 @@ public:
void ReadDependencyList();
void SetPauseState(bool paused);
bool IGetScriptingMemoryAlways() const;
std::pair<std::unique_ptr<u8[]>, s32> IGetScriptingMemoryAlways() const;
TAreaId GetAreaId() const { return x4_selfIdx; }
TAreaId IGetAreaId() const { return x4_selfIdx; }
CAssetId IGetAreaAssetId() const { return x84_mrea; }
@ -304,8 +304,8 @@ public:
CAssetId IGetStringTableAssetId() const;
const zeus::CTransform& IGetTM() const;
void SetXRaySpeedAndTarget(float f1, float f2);
void SetThermalSpeedAndTarget(float f1, float f2);
void SetXRaySpeedAndTarget(float speed, float target);
void SetThermalSpeedAndTarget(float speed, float target);
void SetWeaponWorldLighting(float speed, float target);
CAssetId GetAreaAssetId() const { return x84_mrea; }
@ -314,7 +314,7 @@ public:
float GetXRayFogDistance() const;
EEnvFxType DoesAreaNeedEnvFx() const;
bool DoesAreaNeedSkyNow() const;
bool OtherAreaOcclusionChanged();
void OtherAreaOcclusionChanged();
void PingOcclusionState();
void PreRender();
void AliveUpdate(float dt);
@ -329,7 +329,6 @@ public:
//void UnloadAllLoadedTextures();
//void ReloadAllLoadedTextures();
void ReloadAllUnloadedTextures();
void PrepTokens();
u32 GetNumPartSizes() const;
void AllocNewAreaData(int, int);
bool Invalidate(CStateManager* mgr);
@ -344,7 +343,7 @@ public:
void VerifyTokenList(CStateManager& stateMgr);
void ClearTokenList();
u32 GetPreConstructedSize() const;
MREAHeader VerifyHeader() const;
SMREAHeader VerifyHeader() const;
TUniqueId LookupPVSUniqueID(TUniqueId id) const;
s16 LookupPVSID(TUniqueId id) const;
const CPVSAreaSet* GetAreaVisSet() const { return GetPostConstructed()->xa0_pvs.get(); }

View File

@ -547,7 +547,7 @@ void CWorld::PropogateAreaChain(CGameArea::EOcclusionState occlusionState, CGame
if (&areaItr == area)
continue;
if (areaItr.IsPostConstructed() && areaItr.GetOcclusionState() == CGameArea::EOcclusionState::Visible)
areaItr.PrepTokens();
areaItr.OtherAreaOcclusionChanged();
}
for (CGameArea& areaItr : *world)
@ -555,7 +555,7 @@ void CWorld::PropogateAreaChain(CGameArea::EOcclusionState occlusionState, CGame
if (&areaItr == area)
continue;
if (areaItr.IsPostConstructed() && areaItr.GetOcclusionState() == CGameArea::EOcclusionState::Occluded)
areaItr.PrepTokens();
areaItr.OtherAreaOcclusionChanged();
}
if (occlusionState == CGameArea::EOcclusionState::Occluded)

View File

@ -42,7 +42,7 @@ public:
void SetReferenceCount(s32 v) { x0_referenceCount = v; x48_isReferenced = true; }
};
virtual bool IGetScriptingMemoryAlways() const=0;
virtual std::pair<std::unique_ptr<u8[]>, s32> IGetScriptingMemoryAlways() const=0;
virtual TAreaId IGetAreaId() const=0;
virtual CAssetId IGetAreaAssetId() const=0;
virtual bool IIsActive() const=0;