Basic CGameAllocator implementation (WIP)

This commit is contained in:
Phillip Stephens 2017-09-12 08:27:48 -07:00
parent c0d5cee8b1
commit 001125429f
21 changed files with 363 additions and 59 deletions

View File

@ -0,0 +1,61 @@
#include "CGameAllocator.hpp"
namespace urde
{
logvisor::Module AllocLog("urde::CGameAllocator");
std::vector<CGameAllocator::SAllocationDescription> 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<SChunkDescription*>(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<SChunkDescription*>(ptr);
*chunkInfo = SChunkDescription();
chunkInfo->parent = &m_allocations.back();
chunkInfo->len = len;
return ptr + sizeof(SChunkDescription);
}
void CGameAllocator::Free(u8* ptr)
{
SChunkDescription* info = reinterpret_cast<SChunkDescription*>(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)));
}
}

View File

@ -0,0 +1,34 @@
#ifndef __URDE_CGAMEALLOCATOR_HPP__
#define __URDE_CGAMEALLOCATOR_HPP__
#include "RetroTypes.hpp"
namespace urde
{
class CGameAllocator
{
struct SAllocationDescription
{
std::unique_ptr<u8[]> 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<SAllocationDescription> m_allocations;
public:
static u8* Alloc(size_t len);
static void Free(u8* ptr);
};
}
#endif

View File

@ -67,7 +67,7 @@ CPersistentOptions::CPersistentOptions(CBitStreamReader& stream)
xc0_frozenFpsCount = stream.ReadEncoded(2); xc0_frozenFpsCount = stream.ReadEncoded(2);
xc4_frozenBallCount = stream.ReadEncoded(2); xc4_frozenBallCount = stream.ReadEncoded(2);
xc8_ = stream.ReadEncoded(1); xc8_powerBombAmmoCount = stream.ReadEncoded(1);
xcc_logScanPercent = stream.ReadEncoded(7); xcc_logScanPercent = stream.ReadEncoded(7);
xd0_24_fusionLinked = stream.ReadEncoded(1); xd0_24_fusionLinked = stream.ReadEncoded(1);
xd0_25_normalModeBeat = 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(xc0_frozenFpsCount, 2);
w.WriteEncoded(xc4_frozenBallCount, 2); w.WriteEncoded(xc4_frozenBallCount, 2);
w.WriteEncoded(xc8_, 1); w.WriteEncoded(xc8_powerBombAmmoCount, 1);
w.WriteEncoded(xcc_logScanPercent, 7); w.WriteEncoded(xcc_logScanPercent, 7);
w.WriteEncoded(xd0_24_fusionLinked, 1); w.WriteEncoded(xd0_24_fusionLinked, 1);
w.WriteEncoded(xd0_25_normalModeBeat, 1); w.WriteEncoded(xd0_25_normalModeBeat, 1);

View File

@ -61,7 +61,7 @@ class CPersistentOptions
u32 xbc_autoMapperKeyState = 0; u32 xbc_autoMapperKeyState = 0;
u32 xc0_frozenFpsCount = 0; u32 xc0_frozenFpsCount = 0;
u32 xc4_frozenBallCount = 0; u32 xc4_frozenBallCount = 0;
u32 xc8_ = 0; u32 xc8_powerBombAmmoCount = 0;
u32 xcc_logScanPercent = 0; u32 xcc_logScanPercent = 0;
union union
@ -104,6 +104,12 @@ public:
bool GetShowFrozenFpsMessage() const { return xc0_frozenFpsCount != 3; } bool GetShowFrozenFpsMessage() const { return xc0_frozenFpsCount != 3; }
void IncrementFrozenBallCount() { xc4_frozenBallCount = std::min(int(xc4_frozenBallCount + 1), 3); } void IncrementFrozenBallCount() { xc4_frozenBallCount = std::min(int(xc4_frozenBallCount + 1), 3); }
bool GetShowFrozenBallMessage() const { return xc4_frozenBallCount != 3; } bool GetShowFrozenBallMessage() const { return xc4_frozenBallCount != 3; }
bool GetShowPowerBombAmmoMessage() const { return xc8_powerBombAmmoCount != 1; }
void IncrementPowerBombAmmoCount()
{
xc8_powerBombAmmoCount = std::min<u32>(1, xc8_powerBombAmmoCount + 1);
}
void PutTo(CBitStreamWriter& w) const; void PutTo(CBitStreamWriter& w) const;
u8* GetNESState() { return x0_; } u8* GetNESState() { return x0_; }

View File

@ -65,6 +65,7 @@ add_library(RuntimeCommon
${WEAPON_SOURCES} ${WEAPON_SOURCES}
ITweak.hpp ITweak.hpp
IMain.hpp IMain.hpp
CGameAllocator.hpp CGameAllocator.cpp
CMemoryCardSys.hpp CMemoryCardSys.cpp CMemoryCardSys.hpp CMemoryCardSys.cpp
CScannableObjectInfo.hpp CScannableObjectInfo.cpp CScannableObjectInfo.hpp CScannableObjectInfo.cpp
CSaveWorld.hpp CSaveWorld.cpp CSaveWorld.hpp CSaveWorld.cpp

View File

@ -167,18 +167,18 @@ u32 CPlayerState::CalculateItemCollectionRate() const
total += GetItemCapacity(EItemType::GravitySuit); total += GetItemCapacity(EItemType::GravitySuit);
total += GetItemCapacity(EItemType::VariaSuit); total += GetItemCapacity(EItemType::VariaSuit);
total += GetItemCapacity(EItemType::EnergyTanks); total += GetItemCapacity(EItemType::EnergyTanks);
total += GetItemCapacity(EItemType::ArtifactOfTruth); total += GetItemCapacity(EItemType::Truth);
total += GetItemCapacity(EItemType::ArtifactOfStrength); total += GetItemCapacity(EItemType::Strength);
total += GetItemCapacity(EItemType::ArtifactOfElder); total += GetItemCapacity(EItemType::Elder);
total += GetItemCapacity(EItemType::ArtifactOfWild); total += GetItemCapacity(EItemType::Wild);
total += GetItemCapacity(EItemType::ArtifactOfLifegiver); total += GetItemCapacity(EItemType::Lifegiver);
total += GetItemCapacity(EItemType::ArtifactOfWarrior); total += GetItemCapacity(EItemType::Warrior);
total += GetItemCapacity(EItemType::ArtifactOfChozo); total += GetItemCapacity(EItemType::Chozo);
total += GetItemCapacity(EItemType::ArtifactOfNature); total += GetItemCapacity(EItemType::Nature);
total += GetItemCapacity(EItemType::ArtifactOfSun); total += GetItemCapacity(EItemType::Sun);
total += GetItemCapacity(EItemType::ArtifactOfWorld); total += GetItemCapacity(EItemType::World);
total += GetItemCapacity(EItemType::ArtifactOfSpirit); total += GetItemCapacity(EItemType::Spirit);
total += GetItemCapacity(EItemType::ArtifactOfNewborn); total += GetItemCapacity(EItemType::Newborn);
return total + GetItemCapacity(EItemType::Wavebuster); return total + GetItemCapacity(EItemType::Wavebuster);
} }
@ -332,7 +332,7 @@ u32 CPlayerState::GetItemAmount(CPlayerState::EItemType type) const
type == EItemType::Flamethrower || type == EItemType::Flamethrower ||
type == EItemType::EnergyTanks || type == EItemType::EnergyTanks ||
type == EItemType::Missiles || type == EItemType::Missiles ||
(type >= EItemType::ArtifactOfTruth && type <= EItemType::ArtifactOfNewborn)) (type >= EItemType::Truth && type <= EItemType::Newborn))
{ {
return x24_powerups[u32(type)].x0_amount; return x24_powerups[u32(type)].x0_amount;
} }
@ -364,18 +364,18 @@ void CPlayerState::IncrPickup(EItemType type, s32 amount)
case EItemType::ChargeBeam: case EItemType::ChargeBeam:
case EItemType::SpaceJumpBoots: case EItemType::SpaceJumpBoots:
case EItemType::EnergyTanks: case EItemType::EnergyTanks:
case EItemType::ArtifactOfTruth: case EItemType::Truth:
case EItemType::ArtifactOfStrength: case EItemType::Strength:
case EItemType::ArtifactOfElder: case EItemType::Elder:
case EItemType::ArtifactOfWild: case EItemType::Wild:
case EItemType::ArtifactOfLifegiver: case EItemType::Lifegiver:
case EItemType::ArtifactOfWarrior: case EItemType::Warrior:
case EItemType::ArtifactOfChozo: case EItemType::Chozo:
case EItemType::ArtifactOfNature: case EItemType::Nature:
case EItemType::ArtifactOfSun: case EItemType::Sun:
case EItemType::ArtifactOfWorld: case EItemType::World:
case EItemType::ArtifactOfSpirit: case EItemType::Spirit:
case EItemType::ArtifactOfNewborn: case EItemType::Newborn:
{ {
CPowerUp& pup = x24_powerups[u32(type)]; CPowerUp& pup = x24_powerups[u32(type)];
pup.x0_amount = std::min(pup.x0_amount + amount, pup.x4_capacity); pup.x0_amount = std::min(pup.x0_amount + amount, pup.x4_capacity);

View File

@ -47,18 +47,18 @@ public:
HealthRefill = 26, HealthRefill = 26,
UnknownItem2 = 27, UnknownItem2 = 27,
Wavebuster = 28, Wavebuster = 28,
ArtifactOfTruth = 29, Truth = 29,
ArtifactOfStrength = 30, Strength = 30,
ArtifactOfElder = 31, Elder = 31,
ArtifactOfWild = 32, Wild = 32,
ArtifactOfLifegiver = 33, Lifegiver = 33,
ArtifactOfWarrior = 34, Warrior = 34,
ArtifactOfChozo = 35, Chozo = 35,
ArtifactOfNature = 36, Nature = 36,
ArtifactOfSun = 37, Sun = 37,
ArtifactOfWorld = 38, World = 38,
ArtifactOfSpirit = 39, Spirit = 39,
ArtifactOfNewborn = 40, Newborn = 40,
/* This must remain at the end of the list */ /* This must remain at the end of the list */
Max Max

View File

@ -380,6 +380,7 @@ public:
TUniqueId GetSkipCinematicSpecialFunction() const { return xf38_skipCineSpecialFunc; } TUniqueId GetSkipCinematicSpecialFunction() const { return xf38_skipCineSpecialFunc; }
void SetSkipCinematicSpecialFunction(TUniqueId id) { xf38_skipCineSpecialFunc = id; } void SetSkipCinematicSpecialFunction(TUniqueId id) { xf38_skipCineSpecialFunc = id; }
float GetHUDMessageTime() const { return xf78_hudMessageTime; } float GetHUDMessageTime() const { return xf78_hudMessageTime; }
u32 GetHUDMessageFrameCount() const { return xf80_hudMessageFrameCount; }
CAssetId GetPauseHUDMessage() const { return xf08_pauseHudMessage; } CAssetId GetPauseHUDMessage() const { return xf08_pauseHudMessage; }
void IncrementHUDMessageFrameCounter() { ++xf80_hudMessageFrameCount; } void IncrementHUDMessageFrameCounter() { ++xf80_hudMessageFrameCount; }
bool ShouldQuitGame() const { return xf94_25_quitGame; } bool ShouldQuitGame() const { return xf94_25_quitGame; }
@ -441,6 +442,12 @@ public:
void SetThermalColdScale2(float s) { xf28_thermColdScale2 = s; } void SetThermalColdScale2(float s) { xf28_thermColdScale2 = s; }
float IntegrateVisorFog(float f) const; float IntegrateVisorFog(float f) const;
u32 GetUpdateFrameIndex() const { return x8d8_updateFrameIdx; } 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 float g_EscapeShakeCountdown;
static bool g_EscapeShakeCountdownInit; static bool g_EscapeShakeCountdownInit;

View File

@ -66,7 +66,7 @@ int CArtifactDoll::GetArtifactHeadScanIndex(CAssetId scanId)
CAssetId CArtifactDoll::GetArtifactHeadScanFromItemType(CPlayerState::EItemType item) 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 -1;
return g_ResFactory->TranslateOriginalToNew(ArtifactHeadScans[int(item) - 29]); return g_ResFactory->TranslateOriginalToNew(ArtifactHeadScans[int(item) - 29]);
} }

View File

@ -1,4 +1,5 @@
#include "CExplosion.hpp" #include "CExplosion.hpp"
#include "TCastTo.hpp"
namespace urde namespace urde
{ {
@ -22,4 +23,8 @@ CExplosion::CExplosion(const TLockedToken<CGenDescription>& particle, TUniqueId
xe8_particleGen->SetModulationColor(color); xe8_particleGen->SetModulationColor(color);
} }
void CExplosion::Accept(IVisitor& visitor)
{
visitor.Visit(this);
}
} }

View File

@ -22,6 +22,8 @@ public:
CExplosion(const TLockedToken<CGenDescription>& particle, TUniqueId uid, bool active, CExplosion(const TLockedToken<CGenDescription>& particle, TUniqueId uid, bool active,
const CEntityInfo& info, const std::string& name, const zeus::CTransform& xf, const CEntityInfo& info, const std::string& name, const zeus::CTransform& xf,
u32, const zeus::CVector3f& scale, const zeus::CColor& color); u32, const zeus::CVector3f& scale, const zeus::CColor& color);
void Accept(IVisitor&);
}; };
} }

View File

@ -480,9 +480,18 @@ float CGameArea::GetXRayFogDistance() const
return 1.f; 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 bool CGameArea::DoesAreaNeedSkyNow() const

View File

@ -17,6 +17,7 @@
#include "Graphics/CModel.hpp" #include "Graphics/CModel.hpp"
#include "CPathFindArea.hpp" #include "CPathFindArea.hpp"
#include "Editor/ProjectResourceFactoryBase.hpp" #include "Editor/ProjectResourceFactoryBase.hpp"
#include "World/CEnvFxManager.hpp"
namespace urde namespace urde
{ {
@ -311,7 +312,7 @@ public:
const CAreaFog* GetAreaFog() const { return GetPostConstructed()->x10c4_areaFog.get(); } const CAreaFog* GetAreaFog() const { return GetPostConstructed()->x10c4_areaFog.get(); }
CAreaFog* AreaFog() { return const_cast<CAreaFog*>(GetAreaFog()); } CAreaFog* AreaFog() { return const_cast<CAreaFog*>(GetAreaFog()); }
float GetXRayFogDistance() const; float GetXRayFogDistance() const;
bool DoesAreaNeedEnvFx() const; EEnvFxType DoesAreaNeedEnvFx() const;
bool DoesAreaNeedSkyNow() const; bool DoesAreaNeedSkyNow() const;
bool OtherAreaOcclusionChanged(); bool OtherAreaOcclusionChanged();
void PingOcclusionState(); void PingOcclusionState();

View File

@ -28,6 +28,8 @@ public:
bool GetNeedsSky() const { return x34_24_showSkybox; } bool GetNeedsSky() const { return x34_24_showSkybox; }
bool GetNeedsEnvFx() const { return x38_envFx != EEnvFxType::None; } 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 GetEnvFxDensity() const { return x3c_envFxDensity; }
float GetThermalHeat() const { return x40_thermalHeat; } float GetThermalHeat() const { return x40_thermalHeat; }
float GetXRayFogDistance() const { return x44_xrayFogDistance; } float GetXRayFogDistance() const { return x44_xrayFogDistance; }

View File

@ -1,19 +1,120 @@
#include "CScriptPickup.hpp" #include "CScriptPickup.hpp"
#include "Particle/CGenDescription.hpp"
#include "GameGlobalObjects.hpp"
#include "MP1/CArtifactDoll.hpp"
#include "CExplosion.hpp"
#include "CSimplePool.hpp"
#include "TCastTo.hpp" #include "TCastTo.hpp"
#include "CPlayer.hpp"
#include "CGameState.hpp"
#include "CGameOptions.hpp"
#include "MP1/CSamusHud.hpp"
#include "GuiSys/CStringTable.hpp"
namespace urde namespace urde
{ {
CScriptPickup::CScriptPickup(TUniqueId uid, const std::string& name, const CEntityInfo& info, CScriptPickup::CScriptPickup(TUniqueId uid, const std::string& name, const CEntityInfo& info,
const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& aParams, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& aParams,
const zeus::CAABox& aabb, s32, s32, s32, s32, float, float, float, float, bool active) const zeus::CAABox& aabb, CPlayerState::EItemType itemType, s32 amount, s32 capacity,
: CPhysicsActor(uid, active, name, info, xf, std::move(mData), CMaterialList(), aabb, SMoverData(1.f), aParams, CAssetId explosionEffect, float possibility, float f2, float f3, float f4, bool active)
0.3f, 0.1f) : 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<CPlayer>(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});
}
}
}
} }

View File

@ -2,16 +2,37 @@
#define __URDE_CSCRIPTPICKUP_HPP__ #define __URDE_CSCRIPTPICKUP_HPP__
#include "CPhysicsActor.hpp" #include "CPhysicsActor.hpp"
#include "CPlayerState.hpp"
namespace urde namespace urde
{ {
class CScriptPickup : public CPhysicsActor 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<CGenDescription> x27c_explosionDesc;
u8 x28c_24_ : 1;
u8 x28c_25_ : 1;
u8 x28c_26_ : 1;
public: public:
CScriptPickup(TUniqueId, const std::string&, const CEntityInfo&, const zeus::CTransform&, CModelData&&, 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 Accept(IVisitor& visitor);
void Think(float, CStateManager&);
void Touch(CActor &, CStateManager &);
float GetPossibility() const { return x264_possibility; }
CPlayerState::EItemType GetItem() { return x258_itemType; }
}; };
} }

View File

@ -0,0 +1,13 @@
#ifndef __URDE_CTEAMAIMGR_HPP__
#define __URDE_CTEAMAIMGR_HPP__
namespace urde
{
class CTeamAiMgr
{
};
}
#endif // __URDE_CTEAMAIMGR_HPP__

View File

@ -5,6 +5,7 @@
#include "Audio/CAudioGroupSet.hpp" #include "Audio/CAudioGroupSet.hpp"
#include "CGameState.hpp" #include "CGameState.hpp"
#include "Graphics/CBooRenderer.hpp" #include "Graphics/CBooRenderer.hpp"
#include "World/CScriptAreaAttributes.hpp"
namespace urde namespace urde
{ {
@ -355,8 +356,8 @@ bool CWorld::CheckWorldComplete(CStateManager* mgr, TAreaId id, CAssetId mreaId)
} }
case Phase::LoadingSkyBox: case Phase::LoadingSkyBox:
{ {
x70_26_ = true; x70_26_skyboxOverridden = true;
x70_27_ = false; x70_27_needsSky = false;
if (!x94_skybox.IsLoaded()) if (!x94_skybox.IsLoaded())
return false; return false;
@ -560,7 +561,48 @@ void CWorld::PropogateAreaChain(CGameArea::EOcclusionState occlusionState, CGame
void CWorld::Update(float dt) 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<CModel> skybox = g_SimplePool->GetObj({SBIG('CMDL'), skyModel});
/* TODO: Finish */
}
} }
void CWorld::PreRender() void CWorld::PreRender()
@ -593,7 +635,7 @@ void CWorld::DrawSky(const zeus::CTransform& xf) const
else else
return; return;
if (!x70_27_) if (!x70_27_needsSky)
return; return;
CGraphics::DisableAllLights(); CGraphics::DisableAllLights();

View File

@ -137,8 +137,8 @@ private:
{ {
bool x70_24_currentAreaNeedsAllocation : 1; bool x70_24_currentAreaNeedsAllocation : 1;
bool x70_25_paused : 1; bool x70_25_paused : 1;
bool x70_26_ : 1; bool x70_26_skyboxOverridden : 1;
bool x70_27_ : 1; bool x70_27_needsSky : 1;
}; };
u16 dummy = 0; u16 dummy = 0;
}; };

View File

@ -891,7 +891,7 @@ CEntity* ScriptLoader::LoadPickup(CStateManager& mgr, CInputStream& in, int prop
SScaledActorHead head = LoadScaledActorHead(in, mgr); SScaledActorHead head = LoadScaledActorHead(in, mgr);
zeus::CVector3f extent = zeus::CVector3f::ReadBig(in); zeus::CVector3f extent = zeus::CVector3f::ReadBig(in);
zeus::CVector3f offset = 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 w2 = in.readUint32Big();
u32 w3 = in.readUint32Big(); u32 w3 = in.readUint32Big();
float f1 = in.readFloatBig(); float f1 = in.readFloatBig();
@ -902,7 +902,7 @@ CEntity* ScriptLoader::LoadPickup(CStateManager& mgr, CInputStream& in, int prop
CActorParameters actorParms = LoadActorParameters(in); CActorParameters actorParms = LoadActorParameters(in);
bool active = in.readBool(); bool active = in.readBool();
float f4 = in.readFloatBig(); float f4 = in.readFloatBig();
u32 w5 = in.readUint32Big(); CAssetId w4(in);
FourCC acsType = g_ResFactory->GetResourceTypeById(animParms.GetACSFile()); FourCC acsType = g_ResFactory->GetResourceTypeById(animParms.GetACSFile());
if (g_ResFactory->GetResourceTypeById(staticModel) == 0 && acsType == 0) 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()); aabb = data.GetBounds(head.x10_transform.getRotation());
return new CScriptPickup(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform, std::move(data), 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) CEntity* ScriptLoader::LoadMemoryRelay(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info)

View File

@ -227,7 +227,6 @@ enum class EScriptObjectMessage
RemovePhazonPoolInhabitant = 47, RemovePhazonPoolInhabitant = 47,
InternalMessage26 = 48 InternalMessage26 = 48
}; };
} }
#endif // __SCRIPT_OBJECT_SUPPORT_HPP__ #endif // __SCRIPT_OBJECT_SUPPORT_HPP__