diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index e67c83e8e..ba4ff9a2f 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -1336,8 +1336,10 @@ std::pair CStateManager::LoadScriptObject(TAreaId aid, ESc if (error || ent == nullptr) { LogModule.report(logvisor::Error, fmt("Script load error while loading {}"), ScriptObjectTypeToStr(type)); return {kInvalidEditorId, kInvalidUniqueId}; - } else + } else { + LogModule.report(logvisor::Info, fmt("Loaded {} in area {}"), ent->GetName(), ent->GetAreaIdAlways()); return {id, ent->GetUniqueId()}; + } } std::pair CStateManager::GenerateObject(TEditorId eid) { diff --git a/Runtime/World/CScriptBeam.cpp b/Runtime/World/CScriptBeam.cpp index 9633c8ace..caf5a91b8 100644 --- a/Runtime/World/CScriptBeam.cpp +++ b/Runtime/World/CScriptBeam.cpp @@ -19,8 +19,7 @@ CScriptBeam::CScriptBeam(TUniqueId uid, std::string_view name, const CEntityInfo void CScriptBeam::Accept(IVisitor& visitor) { visitor.Visit(this); } void CScriptBeam::Think(float dt, CStateManager& mgr) { - CPlasmaProjectile* proj = static_cast(mgr.ObjectById(x154_projectileId)); - if (proj) { + if (CPlasmaProjectile* proj = static_cast(mgr.ObjectById(x154_projectileId))) { if (proj->GetActive()) proj->UpdateFx(x34_transform, dt, mgr); } else @@ -29,7 +28,16 @@ void CScriptBeam::Think(float dt, CStateManager& mgr) { void CScriptBeam::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& mgr) { if (msg == EScriptObjectMessage::Increment) { + if (CPlasmaProjectile* proj = static_cast(mgr.ObjectById(x154_projectileId))) { + proj->ResetBeam(mgr, true); + proj->Fire(GetTransform(), mgr, false); + } } else if (msg == EScriptObjectMessage::Decrement) { + if (CPlasmaProjectile* proj = static_cast(mgr.ObjectById(x154_projectileId))) { + if (proj->GetActive()) { + proj->ResetBeam(mgr, false); + } + } } else if (msg == EScriptObjectMessage::Registered) { x154_projectileId = mgr.AllocateUniqueId(); mgr.AddObject(new CPlasmaProjectile(xe8_weaponDescription, x10_name + "-Projectile", @@ -37,6 +45,7 @@ void CScriptBeam::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CSt EMaterialTypes::Projectile, x138_damageInfo, x8_uid, x4_areaId, x154_projectileId, {}, false, EProjectileAttrib::PlasmaProjectile)); } else if (msg == EScriptObjectMessage::Deleted) { + mgr.FreeScriptObject(x154_projectileId); } CActor::AcceptScriptMsg(msg, objId, mgr); diff --git a/Runtime/World/CScriptPlatform.cpp b/Runtime/World/CScriptPlatform.cpp index 1473af292..74f7af6a4 100644 --- a/Runtime/World/CScriptPlatform.cpp +++ b/Runtime/World/CScriptPlatform.cpp @@ -39,7 +39,6 @@ CScriptPlatform::CScriptPlatform( x34c_maxRainSplashes = maxRainSplashes; x350_rainGenRate = rainGenRate; x356_24_dead = false; - ; x356_25_controlledAnimation = false; x356_26_detectCollision = detectCollision; x356_27_squishedRider = false; diff --git a/Runtime/World/CWorld.cpp b/Runtime/World/CWorld.cpp index 1befb269a..1a1d067d6 100644 --- a/Runtime/World/CWorld.cpp +++ b/Runtime/World/CWorld.cpp @@ -294,7 +294,7 @@ bool CWorld::CheckWorldComplete(CStateManager* mgr, TAreaId id, CAssetId mreaId) if (version >= 12) { CAssetId skyboxId = r.readUint32Big(); if (skyboxId.IsValid() && mgr) - x94_skyboxWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('CMDL'), skyboxId}); + x94_skyboxWorld.emplace(g_SimplePool->GetObj(SObjectTag{FOURCC('CMDL'), skyboxId})); } if (version >= 17) x2c_relays = CWorld::CRelay::ReadMemoryRelays(r); @@ -372,18 +372,18 @@ bool CWorld::CheckWorldComplete(CStateManager* mgr, TAreaId id, CAssetId mreaId) x70_26_skyboxActive = true; x70_27_skyboxVisible = false; - if (!x94_skyboxWorld.IsLoaded()) - return false; + if (x94_skyboxWorld) { - CModel* skybox = x94_skyboxWorld.GetObj(); - if (!skybox) - return false; + CModel* skybox = x94_skyboxWorld->GetObj(); + if (!skybox) + return false; - skybox->GetInstance().Touch(0); - if (!skybox->IsLoaded(0)) - return false; + skybox->GetInstance().Touch(0); + if (!skybox->IsLoaded(0)) + return false; - xa4_skyboxWorldLoaded = x94_skyboxWorld; + xa4_skyboxWorldLoaded = x94_skyboxWorld; + } for (CSoundGroupData& group : x74_soundGroupData) group.x1c_groupData.Lock(); @@ -592,10 +592,10 @@ void CWorld::Update(float dt) { if (overrideSkyId.IsValid() && needsSky) { x70_26_skyboxActive = true; x70_27_skyboxVisible = skyVisible; - xb4_skyboxOverride = g_SimplePool->GetObj({SBIG('CMDL'), overrideSkyId}); + xb4_skyboxOverride = {g_SimplePool->GetObj({SBIG('CMDL'), overrideSkyId})}; xa4_skyboxWorldLoaded = TLockedToken(); if (x94_skyboxWorld) - x94_skyboxWorld.Unlock(); + x94_skyboxWorld->Unlock(); } else { xb4_skyboxOverride = TLockedToken(); if (!x94_skyboxWorld) { @@ -603,15 +603,15 @@ void CWorld::Update(float dt) { x70_27_skyboxVisible = false; } else if (!needsSky) { xa4_skyboxWorldLoaded = TLockedToken(); - x94_skyboxWorld.Unlock(); + x94_skyboxWorld->Unlock(); x70_26_skyboxActive = false; x70_27_skyboxVisible = false; } else { if (!xa4_skyboxWorldLoaded) { - x94_skyboxWorld.Lock(); - if (x94_skyboxWorld.IsLoaded()) { - x94_skyboxWorld->Touch(0); - if (x94_skyboxWorld->IsLoaded(0)) + x94_skyboxWorld->Lock(); + if (x94_skyboxWorld->IsLoaded()) { + x94_skyboxWorld.value()->Touch(0); + if (x94_skyboxWorld.value()->IsLoaded(0)) xa4_skyboxWorldLoaded = x94_skyboxWorld; } } @@ -628,18 +628,18 @@ void CWorld::PreRender() { } void CWorld::TouchSky() { - if (xa4_skyboxWorldLoaded.IsLoaded()) - xa4_skyboxWorldLoaded->Touch(0); - if (xb4_skyboxOverride.IsLoaded()) - xb4_skyboxOverride->Touch(0); + if (xa4_skyboxWorldLoaded && xa4_skyboxWorldLoaded->IsLoaded()) + xa4_skyboxWorldLoaded.value()->Touch(0); + if (xb4_skyboxOverride && xb4_skyboxOverride->IsLoaded()) + xb4_skyboxOverride.value()->Touch(0); } void CWorld::DrawSky(const zeus::CTransform& xf) const { const CModel* model; if (xa4_skyboxWorldLoaded) - model = xa4_skyboxWorldLoaded.GetObj(); + model = xa4_skyboxWorldLoaded->GetObj(); else if (xb4_skyboxOverride) - model = xb4_skyboxOverride.GetObj(); + model = xb4_skyboxOverride->GetObj(); else return; @@ -684,13 +684,11 @@ void CWorld::AddGlobalSound(const CSfxHandle& hnd) { bool CWorld::AreSkyNeedsMet() const { if (!x70_26_skyboxActive) return true; - if (xb4_skyboxOverride && xb4_skyboxOverride->IsLoaded(0)) + if (xb4_skyboxOverride && xb4_skyboxOverride.value()->IsLoaded(0)) return true; - if (xa4_skyboxWorldLoaded && xa4_skyboxWorldLoaded->IsLoaded(0)) + if (xa4_skyboxWorldLoaded && xa4_skyboxWorldLoaded.value()->IsLoaded(0)) return true; - if (x94_skyboxWorld && x94_skyboxWorld->IsLoaded(0)) - return true; - return false; + return x94_skyboxWorld && x94_skyboxWorld.value()->IsLoaded(0); } TAreaId CWorld::GetAreaIdForSaveId(s32 saveId) const { diff --git a/Runtime/World/CWorld.hpp b/Runtime/World/CWorld.hpp index dbe99f741..7ad576d33 100644 --- a/Runtime/World/CWorld.hpp +++ b/Runtime/World/CWorld.hpp @@ -143,9 +143,9 @@ private: }; std::vector x74_soundGroupData; std::string x84_defAudioTrack; - TLockedToken x94_skyboxWorld; - TLockedToken xa4_skyboxWorldLoaded; - TLockedToken xb4_skyboxOverride; + std::optional> x94_skyboxWorld; + std::optional> xa4_skyboxWorldLoaded; + std::optional> xb4_skyboxOverride; EEnvFxType xc4_neededFx = EEnvFxType::None; rstl::reserved_vector xc8_globalSfxHandles; diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index 13a9a69fc..97bc0c51e 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -1419,7 +1419,8 @@ CEntity* ScriptLoader::LoadMetroidBeta(CStateManager& mgr, CInputStream& in, int CModelData mData( CAnimRes(animParms.GetACSFile(), animParms.GetCharacter(), scale, animParms.GetInitialAnimation(), true)); - return new MP1::CMetroidBeta(mgr.AllocateUniqueId(), name, info, xf, std::move(mData), pInfo, actParms, metData); + return nullptr; + //return new MP1::CMetroidBeta(mgr.AllocateUniqueId(), name, info, xf, std::move(mData), pInfo, actParms, metData); } CEntity* ScriptLoader::LoadChozoGhost(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { @@ -2001,8 +2002,9 @@ CEntity* ScriptLoader::LoadMetroid(CStateManager& mgr, CInputStream& in, int pro CModelData mData( CAnimRes(animParms.GetACSFile(), animParms.GetCharacter(), scale, animParms.GetInitialAnimation(), true)); - return new MP1::CMetroid(mgr.AllocateUniqueId(), name, flavor, info, xf, std::move(mData), pInfo, actParms, metData, - kInvalidUniqueId); + return nullptr; + //return new MP1::CMetroid(mgr.AllocateUniqueId(), name, flavor, info, xf, std::move(mData), pInfo, actParms, metData, + // kInvalidUniqueId); } CEntity* ScriptLoader::LoadDebrisExtended(CStateManager& mgr, CInputStream& in, int propCount,