From 001125429f184cf2bcf46a65093a1b104a5202f7 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Tue, 12 Sep 2017 08:27:48 -0700 Subject: [PATCH] Basic CGameAllocator implementation (WIP) --- Runtime/CGameAllocator.cpp | 61 +++++++++++++ Runtime/CGameAllocator.hpp | 34 ++++++++ Runtime/CGameOptions.cpp | 4 +- Runtime/CGameOptions.hpp | 8 +- Runtime/CMakeLists.txt | 1 + Runtime/CPlayerState.cpp | 50 +++++------ Runtime/CPlayerState.hpp | 24 ++--- Runtime/CStateManager.hpp | 7 ++ Runtime/MP1/CArtifactDoll.cpp | 2 +- Runtime/World/CExplosion.cpp | 5 ++ Runtime/World/CExplosion.hpp | 2 + Runtime/World/CGameArea.cpp | 13 ++- Runtime/World/CGameArea.hpp | 3 +- Runtime/World/CScriptAreaAttributes.hpp | 2 + Runtime/World/CScriptPickup.cpp | 111 ++++++++++++++++++++++-- Runtime/World/CScriptPickup.hpp | 23 ++++- Runtime/World/CTeamAiMgr.hpp | 13 +++ Runtime/World/CWorld.cpp | 48 +++++++++- Runtime/World/CWorld.hpp | 4 +- Runtime/World/ScriptLoader.cpp | 6 +- Runtime/World/ScriptObjectSupport.hpp | 1 - 21 files changed, 363 insertions(+), 59 deletions(-) create mode 100644 Runtime/CGameAllocator.cpp create mode 100644 Runtime/CGameAllocator.hpp diff --git a/Runtime/CGameAllocator.cpp b/Runtime/CGameAllocator.cpp new file mode 100644 index 000000000..9f51e5dee --- /dev/null +++ b/Runtime/CGameAllocator.cpp @@ -0,0 +1,61 @@ +#include "CGameAllocator.hpp" + +namespace urde +{ +logvisor::Module AllocLog("urde::CGameAllocator"); + +std::vector CGameAllocator::m_allocations; + +u8* CGameAllocator::Alloc(size_t len) +{ + size_t roundedLen = ROUND_UP_64(len + sizeof(SChunkDescription)); + for (SAllocationDescription& alloc : m_allocations) + { + /* We need to supply enough room for allocation information */ + if (alloc.freeOffset + roundedLen < alloc.allocSize) + { + u8* ptr = alloc.memptr.get() + alloc.freeOffset; + SChunkDescription* chunkInfo = reinterpret_cast(ptr); + *chunkInfo = SChunkDescription(); + chunkInfo->parent = &alloc; + chunkInfo->len = len; + alloc.freeOffset += roundedLen; + return ptr + sizeof(SChunkDescription); + } + } + + /* 1MiB minimum allocation to prevent constantly allocating small amounts of memory */ + size_t allocSz = len; + if (allocSz < (1 * 1024 * 1024 * 1024)) + allocSz = 1 * 1024 * 1024 * 1024; + + /* Pad size to allow for allocation information */ + allocSz = ROUND_UP_64(allocSz + sizeof(SChunkDescription)); + m_allocations.emplace_back(); + m_allocations.back().memptr.reset(new u8[allocSz]); + u8* ptr = m_allocations.back().memptr.get(); + m_allocations.back().allocSize = allocSz; + m_allocations.back().freeOffset += roundedLen; + SChunkDescription* chunkInfo = reinterpret_cast(ptr); + *chunkInfo = SChunkDescription(); + chunkInfo->parent = &m_allocations.back(); + chunkInfo->len = len; + return ptr + sizeof(SChunkDescription); +} + +void CGameAllocator::Free(u8* ptr) +{ + SChunkDescription* info = reinterpret_cast(ptr - sizeof(SChunkDescription)); + if (info->magic != 0xE8E8E8E8 || info->sentinal != 0xEFEFEFEF) + { + AllocLog.report(logvisor::Fatal, _S("Invalid chunk description, memory corruption!")); + return; + } + + SAllocationDescription& alloc = *info->parent; + size_t roundedLen = ROUND_UP_32(info->len + sizeof(SChunkDescription)); + alloc.freeOffset -= roundedLen; + /* Invalidate chunk allocation descriptor */ + memset(info, 0, ROUND_UP_64(info->len + sizeof(SChunkDescription))); +} +} diff --git a/Runtime/CGameAllocator.hpp b/Runtime/CGameAllocator.hpp new file mode 100644 index 000000000..48bad96ed --- /dev/null +++ b/Runtime/CGameAllocator.hpp @@ -0,0 +1,34 @@ +#ifndef __URDE_CGAMEALLOCATOR_HPP__ +#define __URDE_CGAMEALLOCATOR_HPP__ + +#include "RetroTypes.hpp" + +namespace urde +{ +class CGameAllocator +{ + struct SAllocationDescription + { + std::unique_ptr memptr; + size_t allocSize = 0; + ptrdiff_t freeOffset = 0; + }; + + struct SChunkDescription + { + u32 magic = 0xE8E8E8E8; + SAllocationDescription* parent; + size_t len = 0; + u32 sentinal = 0xEFEFEFEF; + }; + + static std::vector m_allocations; + +public: + + static u8* Alloc(size_t len); + static void Free(u8* ptr); +}; +} + +#endif diff --git a/Runtime/CGameOptions.cpp b/Runtime/CGameOptions.cpp index 67151de98..262cbee6e 100644 --- a/Runtime/CGameOptions.cpp +++ b/Runtime/CGameOptions.cpp @@ -67,7 +67,7 @@ CPersistentOptions::CPersistentOptions(CBitStreamReader& stream) xc0_frozenFpsCount = stream.ReadEncoded(2); xc4_frozenBallCount = stream.ReadEncoded(2); - xc8_ = stream.ReadEncoded(1); + xc8_powerBombAmmoCount = stream.ReadEncoded(1); xcc_logScanPercent = stream.ReadEncoded(7); xd0_24_fusionLinked = stream.ReadEncoded(1); xd0_25_normalModeBeat = stream.ReadEncoded(1); @@ -113,7 +113,7 @@ void CPersistentOptions::PutTo(CBitStreamWriter& w) const w.WriteEncoded(xc0_frozenFpsCount, 2); w.WriteEncoded(xc4_frozenBallCount, 2); - w.WriteEncoded(xc8_, 1); + w.WriteEncoded(xc8_powerBombAmmoCount, 1); w.WriteEncoded(xcc_logScanPercent, 7); w.WriteEncoded(xd0_24_fusionLinked, 1); w.WriteEncoded(xd0_25_normalModeBeat, 1); diff --git a/Runtime/CGameOptions.hpp b/Runtime/CGameOptions.hpp index 6adbc8662..420a58bb4 100644 --- a/Runtime/CGameOptions.hpp +++ b/Runtime/CGameOptions.hpp @@ -61,7 +61,7 @@ class CPersistentOptions u32 xbc_autoMapperKeyState = 0; u32 xc0_frozenFpsCount = 0; u32 xc4_frozenBallCount = 0; - u32 xc8_ = 0; + u32 xc8_powerBombAmmoCount = 0; u32 xcc_logScanPercent = 0; union @@ -104,6 +104,12 @@ public: bool GetShowFrozenFpsMessage() const { return xc0_frozenFpsCount != 3; } void IncrementFrozenBallCount() { xc4_frozenBallCount = std::min(int(xc4_frozenBallCount + 1), 3); } bool GetShowFrozenBallMessage() const { return xc4_frozenBallCount != 3; } + bool GetShowPowerBombAmmoMessage() const { return xc8_powerBombAmmoCount != 1; } + void IncrementPowerBombAmmoCount() + { + xc8_powerBombAmmoCount = std::min(1, xc8_powerBombAmmoCount + 1); + } + void PutTo(CBitStreamWriter& w) const; u8* GetNESState() { return x0_; } diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index ca63735b3..4ad0b5a92 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -65,6 +65,7 @@ add_library(RuntimeCommon ${WEAPON_SOURCES} ITweak.hpp IMain.hpp + CGameAllocator.hpp CGameAllocator.cpp CMemoryCardSys.hpp CMemoryCardSys.cpp CScannableObjectInfo.hpp CScannableObjectInfo.cpp CSaveWorld.hpp CSaveWorld.cpp diff --git a/Runtime/CPlayerState.cpp b/Runtime/CPlayerState.cpp index b36b5de8a..365061dc6 100644 --- a/Runtime/CPlayerState.cpp +++ b/Runtime/CPlayerState.cpp @@ -167,18 +167,18 @@ u32 CPlayerState::CalculateItemCollectionRate() const total += GetItemCapacity(EItemType::GravitySuit); total += GetItemCapacity(EItemType::VariaSuit); total += GetItemCapacity(EItemType::EnergyTanks); - total += GetItemCapacity(EItemType::ArtifactOfTruth); - total += GetItemCapacity(EItemType::ArtifactOfStrength); - total += GetItemCapacity(EItemType::ArtifactOfElder); - total += GetItemCapacity(EItemType::ArtifactOfWild); - total += GetItemCapacity(EItemType::ArtifactOfLifegiver); - total += GetItemCapacity(EItemType::ArtifactOfWarrior); - total += GetItemCapacity(EItemType::ArtifactOfChozo); - total += GetItemCapacity(EItemType::ArtifactOfNature); - total += GetItemCapacity(EItemType::ArtifactOfSun); - total += GetItemCapacity(EItemType::ArtifactOfWorld); - total += GetItemCapacity(EItemType::ArtifactOfSpirit); - total += GetItemCapacity(EItemType::ArtifactOfNewborn); + total += GetItemCapacity(EItemType::Truth); + total += GetItemCapacity(EItemType::Strength); + total += GetItemCapacity(EItemType::Elder); + total += GetItemCapacity(EItemType::Wild); + total += GetItemCapacity(EItemType::Lifegiver); + total += GetItemCapacity(EItemType::Warrior); + total += GetItemCapacity(EItemType::Chozo); + total += GetItemCapacity(EItemType::Nature); + total += GetItemCapacity(EItemType::Sun); + total += GetItemCapacity(EItemType::World); + total += GetItemCapacity(EItemType::Spirit); + total += GetItemCapacity(EItemType::Newborn); return total + GetItemCapacity(EItemType::Wavebuster); } @@ -332,7 +332,7 @@ u32 CPlayerState::GetItemAmount(CPlayerState::EItemType type) const type == EItemType::Flamethrower || type == EItemType::EnergyTanks || type == EItemType::Missiles || - (type >= EItemType::ArtifactOfTruth && type <= EItemType::ArtifactOfNewborn)) + (type >= EItemType::Truth && type <= EItemType::Newborn)) { return x24_powerups[u32(type)].x0_amount; } @@ -364,18 +364,18 @@ void CPlayerState::IncrPickup(EItemType type, s32 amount) case EItemType::ChargeBeam: case EItemType::SpaceJumpBoots: case EItemType::EnergyTanks: - case EItemType::ArtifactOfTruth: - case EItemType::ArtifactOfStrength: - case EItemType::ArtifactOfElder: - case EItemType::ArtifactOfWild: - case EItemType::ArtifactOfLifegiver: - case EItemType::ArtifactOfWarrior: - case EItemType::ArtifactOfChozo: - case EItemType::ArtifactOfNature: - case EItemType::ArtifactOfSun: - case EItemType::ArtifactOfWorld: - case EItemType::ArtifactOfSpirit: - case EItemType::ArtifactOfNewborn: + case EItemType::Truth: + case EItemType::Strength: + case EItemType::Elder: + case EItemType::Wild: + case EItemType::Lifegiver: + case EItemType::Warrior: + case EItemType::Chozo: + case EItemType::Nature: + case EItemType::Sun: + case EItemType::World: + case EItemType::Spirit: + case EItemType::Newborn: { CPowerUp& pup = x24_powerups[u32(type)]; pup.x0_amount = std::min(pup.x0_amount + amount, pup.x4_capacity); diff --git a/Runtime/CPlayerState.hpp b/Runtime/CPlayerState.hpp index 61bb0b442..97d047731 100644 --- a/Runtime/CPlayerState.hpp +++ b/Runtime/CPlayerState.hpp @@ -47,18 +47,18 @@ public: HealthRefill = 26, UnknownItem2 = 27, Wavebuster = 28, - ArtifactOfTruth = 29, - ArtifactOfStrength = 30, - ArtifactOfElder = 31, - ArtifactOfWild = 32, - ArtifactOfLifegiver = 33, - ArtifactOfWarrior = 34, - ArtifactOfChozo = 35, - ArtifactOfNature = 36, - ArtifactOfSun = 37, - ArtifactOfWorld = 38, - ArtifactOfSpirit = 39, - ArtifactOfNewborn = 40, + Truth = 29, + Strength = 30, + Elder = 31, + Wild = 32, + Lifegiver = 33, + Warrior = 34, + Chozo = 35, + Nature = 36, + Sun = 37, + World = 38, + Spirit = 39, + Newborn = 40, /* This must remain at the end of the list */ Max diff --git a/Runtime/CStateManager.hpp b/Runtime/CStateManager.hpp index 92b99a0ad..e554eb180 100644 --- a/Runtime/CStateManager.hpp +++ b/Runtime/CStateManager.hpp @@ -380,6 +380,7 @@ public: TUniqueId GetSkipCinematicSpecialFunction() const { return xf38_skipCineSpecialFunc; } void SetSkipCinematicSpecialFunction(TUniqueId id) { xf38_skipCineSpecialFunc = id; } float GetHUDMessageTime() const { return xf78_hudMessageTime; } + u32 GetHUDMessageFrameCount() const { return xf80_hudMessageFrameCount; } CAssetId GetPauseHUDMessage() const { return xf08_pauseHudMessage; } void IncrementHUDMessageFrameCounter() { ++xf80_hudMessageFrameCount; } bool ShouldQuitGame() const { return xf94_25_quitGame; } @@ -441,6 +442,12 @@ public: void SetThermalColdScale2(float s) { xf28_thermColdScale2 = s; } float IntegrateVisorFog(float f) const; u32 GetUpdateFrameIndex() const { return x8d8_updateFrameIdx; } + void sub_80043F2C(u32 frameCount, CAssetId msg, float f1) + { + xf84_ = frameCount; + xf88_ = msg; + xf8c_ = f1; + } static float g_EscapeShakeCountdown; static bool g_EscapeShakeCountdownInit; diff --git a/Runtime/MP1/CArtifactDoll.cpp b/Runtime/MP1/CArtifactDoll.cpp index 1169a89e3..9255735dc 100644 --- a/Runtime/MP1/CArtifactDoll.cpp +++ b/Runtime/MP1/CArtifactDoll.cpp @@ -66,7 +66,7 @@ int CArtifactDoll::GetArtifactHeadScanIndex(CAssetId scanId) CAssetId CArtifactDoll::GetArtifactHeadScanFromItemType(CPlayerState::EItemType item) { - if (item < CPlayerState::EItemType::ArtifactOfTruth || item > CPlayerState::EItemType::ArtifactOfNewborn) + if (item < CPlayerState::EItemType::Truth || item > CPlayerState::EItemType::Newborn) return -1; return g_ResFactory->TranslateOriginalToNew(ArtifactHeadScans[int(item) - 29]); } diff --git a/Runtime/World/CExplosion.cpp b/Runtime/World/CExplosion.cpp index a509ffcf1..816be8848 100644 --- a/Runtime/World/CExplosion.cpp +++ b/Runtime/World/CExplosion.cpp @@ -1,4 +1,5 @@ #include "CExplosion.hpp" +#include "TCastTo.hpp" namespace urde { @@ -22,4 +23,8 @@ CExplosion::CExplosion(const TLockedToken& particle, TUniqueId xe8_particleGen->SetModulationColor(color); } +void CExplosion::Accept(IVisitor& visitor) +{ + visitor.Visit(this); +} } diff --git a/Runtime/World/CExplosion.hpp b/Runtime/World/CExplosion.hpp index 5ccffd901..b10b1eea6 100644 --- a/Runtime/World/CExplosion.hpp +++ b/Runtime/World/CExplosion.hpp @@ -22,6 +22,8 @@ public: CExplosion(const TLockedToken& particle, TUniqueId uid, bool active, const CEntityInfo& info, const std::string& name, const zeus::CTransform& xf, u32, const zeus::CVector3f& scale, const zeus::CColor& color); + + void Accept(IVisitor&); }; } diff --git a/Runtime/World/CGameArea.cpp b/Runtime/World/CGameArea.cpp index 2bd97ecb7..9bcc0937a 100644 --- a/Runtime/World/CGameArea.cpp +++ b/Runtime/World/CGameArea.cpp @@ -480,9 +480,18 @@ float CGameArea::GetXRayFogDistance() const return 1.f; } -bool CGameArea::DoesAreaNeedEnvFx() const +EEnvFxType CGameArea::DoesAreaNeedEnvFx() const { - return false; + const CPostConstructed* postConstructed = GetPostConstructed(); + if (!postConstructed) + return EEnvFxType::None; + + const CScriptAreaAttributes* attrs = postConstructed->x10d8_areaAttributes; + if (attrs) + return EEnvFxType::None; + if (postConstructed->x10dc_occlusionState == EOcclusionState::Occluded) + return EEnvFxType::None; + return attrs->GetEnvFxType(); } bool CGameArea::DoesAreaNeedSkyNow() const diff --git a/Runtime/World/CGameArea.hpp b/Runtime/World/CGameArea.hpp index ca6f4cf5b..78c02ac80 100644 --- a/Runtime/World/CGameArea.hpp +++ b/Runtime/World/CGameArea.hpp @@ -17,6 +17,7 @@ #include "Graphics/CModel.hpp" #include "CPathFindArea.hpp" #include "Editor/ProjectResourceFactoryBase.hpp" +#include "World/CEnvFxManager.hpp" namespace urde { @@ -311,7 +312,7 @@ public: const CAreaFog* GetAreaFog() const { return GetPostConstructed()->x10c4_areaFog.get(); } CAreaFog* AreaFog() { return const_cast(GetAreaFog()); } float GetXRayFogDistance() const; - bool DoesAreaNeedEnvFx() const; + EEnvFxType DoesAreaNeedEnvFx() const; bool DoesAreaNeedSkyNow() const; bool OtherAreaOcclusionChanged(); void PingOcclusionState(); diff --git a/Runtime/World/CScriptAreaAttributes.hpp b/Runtime/World/CScriptAreaAttributes.hpp index 4c12b0003..8b68c48de 100644 --- a/Runtime/World/CScriptAreaAttributes.hpp +++ b/Runtime/World/CScriptAreaAttributes.hpp @@ -28,6 +28,8 @@ public: bool GetNeedsSky() const { return x34_24_showSkybox; } bool GetNeedsEnvFx() const { return x38_envFx != EEnvFxType::None; } + CAssetId GetSkyModel() const { return x4c_skybox; } + EEnvFxType GetEnvFxType() const { return x38_envFx; } float GetEnvFxDensity() const { return x3c_envFxDensity; } float GetThermalHeat() const { return x40_thermalHeat; } float GetXRayFogDistance() const { return x44_xrayFogDistance; } diff --git a/Runtime/World/CScriptPickup.cpp b/Runtime/World/CScriptPickup.cpp index 82796006f..1b775c20e 100644 --- a/Runtime/World/CScriptPickup.cpp +++ b/Runtime/World/CScriptPickup.cpp @@ -1,19 +1,120 @@ #include "CScriptPickup.hpp" +#include "Particle/CGenDescription.hpp" +#include "GameGlobalObjects.hpp" +#include "MP1/CArtifactDoll.hpp" +#include "CExplosion.hpp" +#include "CSimplePool.hpp" #include "TCastTo.hpp" +#include "CPlayer.hpp" +#include "CGameState.hpp" +#include "CGameOptions.hpp" +#include "MP1/CSamusHud.hpp" +#include "GuiSys/CStringTable.hpp" namespace urde { CScriptPickup::CScriptPickup(TUniqueId uid, const std::string& name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& aParams, - const zeus::CAABox& aabb, s32, s32, s32, s32, float, float, float, float, bool active) - : CPhysicsActor(uid, active, name, info, xf, std::move(mData), CMaterialList(), aabb, SMoverData(1.f), aParams, - 0.3f, 0.1f) + const zeus::CAABox& aabb, CPlayerState::EItemType itemType, s32 amount, s32 capacity, + CAssetId explosionEffect, float possibility, float f2, float f3, float f4, bool active) +: CPhysicsActor(uid, active, name, info, xf, std::move(mData), CMaterialList(), aabb, SMoverData(1.f), aParams, 0.3f, + 0.1f) +, x258_itemType(itemType) +, x25c_amount(amount) +, x260_capacity(capacity) +, x264_possibility(possibility) +, x268_(f3) +, x26c_(f2) +, x278_(f4) +, x28c_24_(false) +, x28c_25_(false) +, x28c_26_(false) { + if (explosionEffect.IsValid()) + x27c_explosionDesc = g_SimplePool->GetObj({SBIG('PART'), explosionEffect}); + + if (x64_modelData && x64_modelData->AnimationData()) + x64_modelData->AnimationData()->SetAnimation(CAnimPlaybackParms(0, -1, 1.f, true), false); + + if (x278_ != 0.f) + { + xb4_drawFlags = CModelFlags(5, 0, 3, zeus::CColor(1.f, 1.f, 1.f, 0.f)); + xb4_drawFlags.x2_flags &= 0xFFFC; + xb4_drawFlags.x2_flags |= 1; + } } -void CScriptPickup::Accept(IVisitor& visitor) +void CScriptPickup::Accept(IVisitor& visitor) { visitor.Visit(this); } + +void CScriptPickup::Think(float dt, CStateManager& mgr) { - visitor.Visit(this); + if (!GetActive()) + return; + + + if (x278_ >= 0.f) + { + CPhysicsActor::Stop(); + x278_ -= dt; + } + else + { + x270_ += dt; + if (x28c_25_) + { + + } + } } +void CScriptPickup::Touch(CActor& act, CStateManager& mgr) +{ + if (GetActive() && x278_ < 0.f && TCastToPtr(act)) + { + if (x258_itemType >= CPlayerState::EItemType::Truth && x258_itemType <= CPlayerState::EItemType::Newborn) + { + CAssetId id = MP1::CArtifactDoll::GetArtifactHeadScanFromItemType(x258_itemType); + if (id.IsValid()) + mgr.GetPlayerState()->SetScanTime(id, 0.5f); + } + + if (x27c_explosionDesc) + { + if (mgr.GetPlayerState()->GetActiveVisor(mgr) != CPlayerState::EPlayerVisor::Thermal) + { + mgr.AddObject(new CExplosion( + x27c_explosionDesc, mgr.AllocateUniqueId(), true, + CEntityInfo(GetAreaIdAlways(), CEntity::NullConnectionList, kInvalidEditorId), + "Explosion - Pickup Effect", x34_transform, 0, zeus::CVector3f::skOne, zeus::CColor::skWhite)); + } + } + + mgr.GetPlayerState()->InitializePowerUp(x258_itemType, x260_capacity); + mgr.GetPlayerState()->IncrPickup(x258_itemType, x25c_amount); + mgr.FreeScriptObject(GetUniqueId()); + SendScriptMsgs(EScriptObjectState::Arrived, mgr, EScriptObjectMessage::None); + + if (x260_capacity > 0) + { + u32 total = mgr.GetPlayerState()->GetPickupTotal(); + u32 colRate = mgr.GetPlayerState()->CalculateItemCollectionRate(); + if (total == colRate) + { + CPersistentOptions& opts = g_GameState->SystemOptions(); + mgr.sub_80043F2C(mgr.GetHUDMessageFrameCount() + 1, + g_ResFactory->GetResourceIdByName(opts.GetAllItemsCollected() ? + "STRG_AllPickupsFound_2" : + "STRG_AllPickupsFound_1")->id, 0.f); + opts.SetAllItemsCollected(true); + } + } + + if (x258_itemType == CPlayerState::EItemType::PowerBombs && + g_GameState->SystemOptions().GetShowPowerBombAmmoMessage()) + { + g_GameState->SystemOptions().IncrementPowerBombAmmoCount(); + MP1::CSamusHud::DisplayHudMemo(g_MainStringTable->GetString(109), {0.5f, true, false, false}); + } + } +} } diff --git a/Runtime/World/CScriptPickup.hpp b/Runtime/World/CScriptPickup.hpp index 0c755d47f..3c57feeed 100644 --- a/Runtime/World/CScriptPickup.hpp +++ b/Runtime/World/CScriptPickup.hpp @@ -2,16 +2,37 @@ #define __URDE_CSCRIPTPICKUP_HPP__ #include "CPhysicsActor.hpp" +#include "CPlayerState.hpp" namespace urde { class CScriptPickup : public CPhysicsActor { + CPlayerState::EItemType x258_itemType; + u32 x25c_amount; + u32 x260_capacity; + float x264_possibility; + float x268_; + float x26c_; + float x270_ = 0.f; + float x274_; + float x278_; + TLockedToken x27c_explosionDesc; + + u8 x28c_24_ : 1; + u8 x28c_25_ : 1; + u8 x28c_26_ : 1; + public: CScriptPickup(TUniqueId, const std::string&, const CEntityInfo&, const zeus::CTransform&, CModelData&&, - const CActorParameters&, const zeus::CAABox&, s32, s32, s32, s32, float, float, float, float, bool); + const CActorParameters&, const zeus::CAABox&, CPlayerState::EItemType, s32, s32, CAssetId, float, + float, float, float, bool); void Accept(IVisitor& visitor); + void Think(float, CStateManager&); + void Touch(CActor &, CStateManager &); + float GetPossibility() const { return x264_possibility; } + CPlayerState::EItemType GetItem() { return x258_itemType; } }; } diff --git a/Runtime/World/CTeamAiMgr.hpp b/Runtime/World/CTeamAiMgr.hpp index e69de29bb..98af078ec 100644 --- a/Runtime/World/CTeamAiMgr.hpp +++ b/Runtime/World/CTeamAiMgr.hpp @@ -0,0 +1,13 @@ +#ifndef __URDE_CTEAMAIMGR_HPP__ +#define __URDE_CTEAMAIMGR_HPP__ + + +namespace urde +{ +class CTeamAiMgr +{ + +}; +} + +#endif // __URDE_CTEAMAIMGR_HPP__ \ No newline at end of file diff --git a/Runtime/World/CWorld.cpp b/Runtime/World/CWorld.cpp index 2a6a8eebf..94541d218 100644 --- a/Runtime/World/CWorld.cpp +++ b/Runtime/World/CWorld.cpp @@ -5,6 +5,7 @@ #include "Audio/CAudioGroupSet.hpp" #include "CGameState.hpp" #include "Graphics/CBooRenderer.hpp" +#include "World/CScriptAreaAttributes.hpp" namespace urde { @@ -355,8 +356,8 @@ bool CWorld::CheckWorldComplete(CStateManager* mgr, TAreaId id, CAssetId mreaId) } case Phase::LoadingSkyBox: { - x70_26_ = true; - x70_27_ = false; + x70_26_skyboxOverridden = true; + x70_27_needsSky = false; if (!x94_skybox.IsLoaded()) return false; @@ -560,7 +561,48 @@ void CWorld::PropogateAreaChain(CGameArea::EOcclusionState occlusionState, CGame void CWorld::Update(float dt) { + xc4_neededFx = EEnvFxType::None; + CAssetId skyModel; + bool needsSky = false; + CGameArea::EOcclusionState occlusionState = CGameArea::EOcclusionState::Occluded; + 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 skybox = g_SimplePool->GetObj({SBIG('CMDL'), skyModel}); + /* TODO: Finish */ + } } void CWorld::PreRender() @@ -593,7 +635,7 @@ void CWorld::DrawSky(const zeus::CTransform& xf) const else return; - if (!x70_27_) + if (!x70_27_needsSky) return; CGraphics::DisableAllLights(); diff --git a/Runtime/World/CWorld.hpp b/Runtime/World/CWorld.hpp index af9d8a6a4..5660d82a3 100644 --- a/Runtime/World/CWorld.hpp +++ b/Runtime/World/CWorld.hpp @@ -137,8 +137,8 @@ private: { bool x70_24_currentAreaNeedsAllocation : 1; bool x70_25_paused : 1; - bool x70_26_ : 1; - bool x70_27_ : 1; + bool x70_26_skyboxOverridden : 1; + bool x70_27_needsSky : 1; }; u16 dummy = 0; }; diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index dc982ac88..df938fbd7 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -891,7 +891,7 @@ CEntity* ScriptLoader::LoadPickup(CStateManager& mgr, CInputStream& in, int prop SScaledActorHead head = LoadScaledActorHead(in, mgr); zeus::CVector3f extent = zeus::CVector3f::ReadBig(in); zeus::CVector3f offset = zeus::CVector3f::ReadBig(in); - u32 w1 = in.readUint32Big(); + CPlayerState::EItemType w1 = CPlayerState::EItemType(in.readUint32Big()); u32 w2 = in.readUint32Big(); u32 w3 = in.readUint32Big(); float f1 = in.readFloatBig(); @@ -902,7 +902,7 @@ CEntity* ScriptLoader::LoadPickup(CStateManager& mgr, CInputStream& in, int prop CActorParameters actorParms = LoadActorParameters(in); bool active = in.readBool(); float f4 = in.readFloatBig(); - u32 w5 = in.readUint32Big(); + CAssetId w4(in); FourCC acsType = g_ResFactory->GetResourceTypeById(animParms.GetACSFile()); if (g_ResFactory->GetResourceTypeById(staticModel) == 0 && acsType == 0) @@ -922,7 +922,7 @@ CEntity* ScriptLoader::LoadPickup(CStateManager& mgr, CInputStream& in, int prop aabb = data.GetBounds(head.x10_transform.getRotation()); return new CScriptPickup(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform, std::move(data), - actorParms, aabb, w1, w3, w2, w5, f1, f2, f3, f4, active); + actorParms, aabb, w1, w3, w2, w4, f1, f2, f3, f4, active); } CEntity* ScriptLoader::LoadMemoryRelay(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) diff --git a/Runtime/World/ScriptObjectSupport.hpp b/Runtime/World/ScriptObjectSupport.hpp index d5d3ee2ff..a2bfbf3d7 100644 --- a/Runtime/World/ScriptObjectSupport.hpp +++ b/Runtime/World/ScriptObjectSupport.hpp @@ -227,7 +227,6 @@ enum class EScriptObjectMessage RemovePhazonPoolInhabitant = 47, InternalMessage26 = 48 }; - } #endif // __SCRIPT_OBJECT_SUPPORT_HPP__