2019-11-12 20:25:21 +00:00
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
|
2016-07-23 03:07:07 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2019-11-12 20:25:21 +00:00
|
|
|
#include "Runtime/AutoMapper/CMapWorldInfo.hpp"
|
|
|
|
#include "Runtime/Camera/CBallCamera.hpp"
|
|
|
|
#include "Runtime/Camera/CCameraShakeData.hpp"
|
|
|
|
#include "Runtime/Camera/CGameCamera.hpp"
|
|
|
|
#include "Runtime/CGameState.hpp"
|
|
|
|
#include "Runtime/CMemoryCardSys.hpp"
|
|
|
|
#include "Runtime/Collision/CCollidableSphere.hpp"
|
|
|
|
#include "Runtime/Collision/CGameCollision.hpp"
|
|
|
|
#include "Runtime/Collision/CMaterialFilter.hpp"
|
|
|
|
#include "Runtime/Collision/CollisionUtil.hpp"
|
|
|
|
#include "Runtime/CPlayerState.hpp"
|
|
|
|
#include "Runtime/CSortedLists.hpp"
|
|
|
|
#include "Runtime/CTimeProvider.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Graphics/CBooRenderer.hpp"
|
|
|
|
#include "Runtime/Graphics/CLight.hpp"
|
|
|
|
#include "Runtime/Input/ControlMapper.hpp"
|
|
|
|
#include "Runtime/Input/CRumbleManager.hpp"
|
|
|
|
#include "Runtime/MP1/CSamusHud.hpp"
|
|
|
|
#include "Runtime/MP1/MP1.hpp"
|
|
|
|
#include "Runtime/Particle/CDecalManager.hpp"
|
|
|
|
#include "Runtime/Particle/CParticleElectric.hpp"
|
|
|
|
#include "Runtime/Weapon/CProjectileWeapon.hpp"
|
|
|
|
#include "Runtime/Weapon/CWeapon.hpp"
|
|
|
|
#include "Runtime/Weapon/CWeaponMgr.hpp"
|
|
|
|
#include "Runtime/World/CDestroyableRock.hpp"
|
|
|
|
#include "Runtime/World/CGameLight.hpp"
|
|
|
|
#include "Runtime/World/CPathFindSearch.hpp"
|
|
|
|
#include "Runtime/World/CPatterned.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
#include "Runtime/World/CProjectedShadow.hpp"
|
|
|
|
#include "Runtime/World/CScriptDebris.hpp"
|
|
|
|
#include "Runtime/World/CScriptDock.hpp"
|
|
|
|
#include "Runtime/World/CScriptDoor.hpp"
|
|
|
|
#include "Runtime/World/CScriptEffect.hpp"
|
|
|
|
#include "Runtime/World/CScriptPlatform.hpp"
|
|
|
|
#include "Runtime/World/CScriptPlayerActor.hpp"
|
|
|
|
#include "Runtime/World/CScriptRoomAcoustics.hpp"
|
|
|
|
#include "Runtime/World/CScriptSpawnPoint.hpp"
|
|
|
|
#include "Runtime/World/CScriptSpecialFunction.hpp"
|
|
|
|
#include "Runtime/World/CScriptWater.hpp"
|
|
|
|
#include "Runtime/World/CSnakeWeedSwarm.hpp"
|
|
|
|
#include "Runtime/World/CWallCrawlerSwarm.hpp"
|
|
|
|
#include "Runtime/World/CWorld.hpp"
|
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
|
|
|
|
|
|
|
#include <hecl/CVarManager.hpp>
|
|
|
|
#include <zeus/CMRay.hpp>
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2018-06-13 03:20:49 +00:00
|
|
|
hecl::CVar* sm_logScripting = nullptr;
|
2017-01-15 03:59:37 +00:00
|
|
|
logvisor::Module LogModule("urde::CStateManager");
|
2016-10-09 07:45:04 +00:00
|
|
|
CStateManager::CStateManager(const std::weak_ptr<CRelayTracker>& relayTracker,
|
2018-12-08 05:30:43 +00:00
|
|
|
const std::weak_ptr<CMapWorldInfo>& mwInfo, const std::weak_ptr<CPlayerState>& playerState,
|
2016-10-09 07:45:04 +00:00
|
|
|
const std::weak_ptr<CWorldTransManager>& wtMgr,
|
|
|
|
const std::weak_ptr<CWorldLayerState>& layerState)
|
2017-03-24 05:30:16 +00:00
|
|
|
: x8b8_playerState(playerState)
|
2017-01-15 03:59:37 +00:00
|
|
|
, x8bc_relayTracker(relayTracker)
|
|
|
|
, x8c0_mapWorldInfo(mwInfo)
|
|
|
|
, x8c4_worldTransManager(wtMgr)
|
2020-04-20 04:57:50 +00:00
|
|
|
, x8c8_worldLayerState(layerState) {
|
2019-09-12 03:50:38 +00:00
|
|
|
x86c_stateManagerContainer = std::make_unique<CStateManagerContainer>();
|
2018-12-08 05:30:43 +00:00
|
|
|
x870_cameraManager = &x86c_stateManagerContainer->x0_cameraManager;
|
|
|
|
x874_sortedListManager = &x86c_stateManagerContainer->x3c0_sortedListManager;
|
|
|
|
x878_weaponManager = &x86c_stateManagerContainer->xe3d8_weaponManager;
|
|
|
|
x87c_fluidPlaneManager = &x86c_stateManagerContainer->xe3ec_fluidPlaneManager;
|
|
|
|
x880_envFxManager = &x86c_stateManagerContainer->xe510_envFxManager;
|
|
|
|
x884_actorModelParticles = &x86c_stateManagerContainer->xf168_actorModelParticles;
|
|
|
|
x88c_rumbleManager = &x86c_stateManagerContainer->xf250_rumbleManager;
|
|
|
|
|
|
|
|
g_Renderer->SetDrawableCallback(&CStateManager::RendererDrawCallback, this);
|
|
|
|
x908_loaderCount = int(EScriptObjectType::ScriptObjectTypeMAX);
|
2020-03-18 02:41:29 +00:00
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Actor)] = ScriptLoader::LoadActor;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Waypoint)] = ScriptLoader::LoadWaypoint;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Door)] = ScriptLoader::LoadDoor;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Trigger)] = ScriptLoader::LoadTrigger;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Timer)] = ScriptLoader::LoadTimer;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Counter)] = ScriptLoader::LoadCounter;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Effect)] = ScriptLoader::LoadEffect;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Platform)] = ScriptLoader::LoadPlatform;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Sound)] = ScriptLoader::LoadSound;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Generator)] = ScriptLoader::LoadGenerator;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Dock)] = ScriptLoader::LoadDock;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Camera)] = ScriptLoader::LoadCamera;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::CameraWaypoint)] = ScriptLoader::LoadCameraWaypoint;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::NewIntroBoss)] = ScriptLoader::LoadNewIntroBoss;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::SpawnPoint)] = ScriptLoader::LoadSpawnPoint;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::CameraHint)] = ScriptLoader::LoadCameraHint;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Pickup)] = ScriptLoader::LoadPickup;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::MemoryRelay)] = ScriptLoader::LoadMemoryRelay;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::RandomRelay)] = ScriptLoader::LoadRandomRelay;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Relay)] = ScriptLoader::LoadRelay;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Beetle)] = ScriptLoader::LoadBeetle;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::HUDMemo)] = ScriptLoader::LoadHUDMemo;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::CameraFilterKeyframe)] = ScriptLoader::LoadCameraFilterKeyframe;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::CameraBlurKeyframe)] = ScriptLoader::LoadCameraBlurKeyframe;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::DamageableTrigger)] = ScriptLoader::LoadDamageableTrigger;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Debris)] = ScriptLoader::LoadDebris;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::CameraShaker)] = ScriptLoader::LoadCameraShaker;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::ActorKeyframe)] = ScriptLoader::LoadActorKeyframe;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Water)] = ScriptLoader::LoadWater;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Warwasp)] = ScriptLoader::LoadWarWasp;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::SpacePirate)] = ScriptLoader::LoadSpacePirate;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::FlyingPirate)] = ScriptLoader::LoadFlyingPirate;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::ElitePirate)] = ScriptLoader::LoadElitePirate;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::MetroidBeta)] = ScriptLoader::LoadMetroidBeta;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::ChozoGhost)] = ScriptLoader::LoadChozoGhost;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::CoverPoint)] = ScriptLoader::LoadCoverPoint;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::SpiderBallWaypoint)] = ScriptLoader::LoadSpiderBallWaypoint;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::BloodFlower)] = ScriptLoader::LoadBloodFlower;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::FlickerBat)] = ScriptLoader::LoadFlickerBat;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::PathCamera)] = ScriptLoader::LoadPathCamera;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::GrapplePoint)] = ScriptLoader::LoadGrapplePoint;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::PuddleSpore)] = ScriptLoader::LoadPuddleSpore;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::DebugCameraWaypoint)] = ScriptLoader::LoadDebugCameraWaypoint;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::SpiderBallAttractionSurface)] = ScriptLoader::LoadSpiderBallAttractionSurface;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::PuddleToadGamma)] = ScriptLoader::LoadPuddleToadGamma;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::DistanceFog)] = ScriptLoader::LoadDistanceFog;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::FireFlea)] = ScriptLoader::LoadFireFlea;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Metaree)] = ScriptLoader::LoadMetaree;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::DockAreaChange)] = ScriptLoader::LoadDockAreaChange;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::ActorRotate)] = ScriptLoader::LoadActorRotate;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::SpecialFunction)] = ScriptLoader::LoadSpecialFunction;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::SpankWeed)] = ScriptLoader::LoadSpankWeed;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Parasite)] = ScriptLoader::LoadParasite;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::PlayerHint)] = ScriptLoader::LoadPlayerHint;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Ripper)] = ScriptLoader::LoadRipper;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::PickupGenerator)] = ScriptLoader::LoadPickupGenerator;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::AIKeyframe)] = ScriptLoader::LoadAIKeyframe;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::PointOfInterest)] = ScriptLoader::LoadPointOfInterest;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Drone)] = ScriptLoader::LoadDrone;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Metroid)] = ScriptLoader::LoadMetroid;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::DebrisExtended)] = ScriptLoader::LoadDebrisExtended;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Steam)] = ScriptLoader::LoadSteam;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Ripple)] = ScriptLoader::LoadRipple;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::BallTrigger)] = ScriptLoader::LoadBallTrigger;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::TargetingPoint)] = ScriptLoader::LoadTargetingPoint;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::EMPulse)] = ScriptLoader::LoadEMPulse;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::IceSheegoth)] = ScriptLoader::LoadIceSheegoth;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::PlayerActor)] = ScriptLoader::LoadPlayerActor;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Flaahgra)] = ScriptLoader::LoadFlaahgra;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::AreaAttributes)] = ScriptLoader::LoadAreaAttributes;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::FishCloud)] = ScriptLoader::LoadFishCloud;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::FishCloudModifier)] = ScriptLoader::LoadFishCloudModifier;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::VisorFlare)] = ScriptLoader::LoadVisorFlare;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::WorldTeleporter)] = ScriptLoader::LoadWorldTeleporter;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::VisorGoo)] = ScriptLoader::LoadVisorGoo;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::JellyZap)] = ScriptLoader::LoadJellyZap;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::ControllerAction)] = ScriptLoader::LoadControllerAction;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Switch)] = ScriptLoader::LoadSwitch;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::PlayerStateChange)] = ScriptLoader::LoadPlayerStateChange;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Thardus)] = ScriptLoader::LoadThardus;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::WallCrawlerSwarm)] = ScriptLoader::LoadWallCrawlerSwarm;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::AIJumpPoint)] = ScriptLoader::LoadAiJumpPoint;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::FlaahgraTentacle)] = ScriptLoader::LoadFlaahgraTentacle;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::RoomAcoustics)] = ScriptLoader::LoadRoomAcoustics;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::ColorModulate)] = ScriptLoader::LoadColorModulate;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::ThardusRockProjectile)] = ScriptLoader::LoadThardusRockProjectile;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Midi)] = ScriptLoader::LoadMidi;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::StreamedAudio)] = ScriptLoader::LoadStreamedAudio;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::WorldTeleporterToo)] = ScriptLoader::LoadWorldTeleporter;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Repulsor)] = ScriptLoader::LoadRepulsor;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::GunTurret)] = ScriptLoader::LoadGunTurret;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::FogVolume)] = ScriptLoader::LoadFogVolume;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Babygoth)] = ScriptLoader::LoadBabygoth;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Eyeball)] = ScriptLoader::LoadEyeball;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::RadialDamage)] = ScriptLoader::LoadRadialDamage;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::CameraPitchVolume)] = ScriptLoader::LoadCameraPitchVolume;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::EnvFxDensityController)] = ScriptLoader::LoadEnvFxDensityController;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Magdolite)] = ScriptLoader::LoadMagdolite;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::TeamAIMgr)] = ScriptLoader::LoadTeamAIMgr;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::SnakeWeedSwarm)] = ScriptLoader::LoadSnakeWeedSwarm;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::ActorContraption)] = ScriptLoader::LoadActorContraption;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Oculus)] = ScriptLoader::LoadOculus;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Geemer)] = ScriptLoader::LoadGeemer;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::SpindleCamera)] = ScriptLoader::LoadSpindleCamera;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::AtomicAlpha)] = ScriptLoader::LoadAtomicAlpha;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::CameraHintTrigger)] = ScriptLoader::LoadCameraHintTrigger;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::RumbleEffect)] = ScriptLoader::LoadRumbleEffect;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::AmbientAI)] = ScriptLoader::LoadAmbientAI;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::AtomicBeta)] = ScriptLoader::LoadAtomicBeta;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::IceZoomer)] = ScriptLoader::LoadIceZoomer;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Puffer)] = ScriptLoader::LoadPuffer;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Tryclops)] = ScriptLoader::LoadTryclops;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Ridley)] = ScriptLoader::LoadRidley;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Seedling)] = ScriptLoader::LoadSeedling;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::ThermalHeatFader)] = ScriptLoader::LoadThermalHeatFader;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::Burrower)] = ScriptLoader::LoadBurrower;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::ScriptBeam)] = ScriptLoader::LoadBeam;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::WorldLightFader)] = ScriptLoader::LoadWorldLightFader;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::MetroidPrimeStage2)] = ScriptLoader::LoadMetroidPrimeStage2;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::MetroidPrimeStage1)] = ScriptLoader::LoadMetroidPrimeStage1;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::MazeNode)] = ScriptLoader::LoadMazeNode;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::OmegaPirate)] = ScriptLoader::LoadOmegaPirate;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::PhazonPool)] = ScriptLoader::LoadPhazonPool;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::PhazonHealingNodule)] = ScriptLoader::LoadPhazonHealingNodule;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::NewCameraShaker)] = ScriptLoader::LoadNewCameraShaker;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::ShadowProjector)] = ScriptLoader::LoadShadowProjector;
|
|
|
|
x90c_loaderFuncs[size_t(EScriptObjectType::EnergyBall)] = ScriptLoader::LoadEnergyBall;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
CGameCollision::InitCollision();
|
|
|
|
ControlMapper::ResetCommandFilters();
|
|
|
|
x8f0_shadowTex = g_SimplePool->GetObj("DefaultShadow");
|
|
|
|
g_StateManager = this;
|
|
|
|
|
|
|
|
sm_logScripting = hecl::CVarManager::instance()->findOrMakeCVar(
|
|
|
|
"stateManager.logScripting"sv, "Prints object communication to the console", false,
|
|
|
|
hecl::CVar::EFlags::ReadOnly | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::Game);
|
|
|
|
}
|
|
|
|
|
|
|
|
CStateManager::~CStateManager() {
|
|
|
|
x88c_rumbleManager->HardStopAll();
|
|
|
|
x880_envFxManager->Cleanup();
|
|
|
|
x900_activeRandom = &x8fc_random;
|
|
|
|
ClearGraveyard();
|
|
|
|
for (auto it = x808_objLists[0]->begin(); it != x808_objLists[0]->end();) {
|
|
|
|
CEntity* ent = *it;
|
|
|
|
++it;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ent == x84c_player.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
ent->AcceptScriptMsg(EScriptObjectMessage::Deleted, kInvalidUniqueId, *this);
|
|
|
|
RemoveObject(ent->GetUniqueId());
|
|
|
|
std::default_delete<CEntity>()(ent);
|
|
|
|
}
|
|
|
|
ClearGraveyard();
|
|
|
|
x84c_player->AcceptScriptMsg(EScriptObjectMessage::Deleted, kInvalidUniqueId, *this);
|
|
|
|
RemoveObject(x84c_player->GetUniqueId());
|
|
|
|
x84c_player.reset();
|
|
|
|
CCollisionPrimitive::Uninitialize();
|
|
|
|
g_StateManager = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::UpdateThermalVisor() {
|
|
|
|
xf28_thermColdScale2 = 0.f;
|
|
|
|
xf24_thermColdScale1 = 0.f;
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
const auto visor = x8b8_playerState->GetActiveVisor(*this);
|
|
|
|
if (visor != CPlayerState::EPlayerVisor::Thermal || x8cc_nextAreaId == kInvalidAreaId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGameArea* area = x850_world->GetArea(x8cc_nextAreaId);
|
|
|
|
const zeus::CTransform& playerXf = x84c_player->GetTransform();
|
|
|
|
const zeus::CVector3f playerXYPos(playerXf.origin.x(), playerXf.origin.y(), 0.f);
|
|
|
|
CGameArea* lastArea = nullptr;
|
|
|
|
float closestDist = FLT_MAX;
|
|
|
|
for (const CGameArea::Dock& dock : area->GetDocks()) {
|
|
|
|
zeus::CVector3f dockCenter = (dock.GetPlaneVertices()[0] + dock.GetPlaneVertices()[1] + dock.GetPlaneVertices()[2] +
|
|
|
|
dock.GetPlaneVertices()[3]) *
|
|
|
|
0.25f;
|
|
|
|
dockCenter.z() = 0.f;
|
|
|
|
const float dist = (playerXYPos - dockCenter).magSquared();
|
|
|
|
if (dist < closestDist) {
|
|
|
|
const TAreaId connAreaId = dock.GetConnectedAreaId(0);
|
|
|
|
if (connAreaId != kInvalidAreaId) {
|
|
|
|
CGameArea* connArea = x850_world->GetArea(x8cc_nextAreaId);
|
|
|
|
if (connArea->IsPostConstructed()) {
|
|
|
|
const auto occState = connArea->GetPostConstructed()->x10dc_occlusionState;
|
|
|
|
if (occState == CGameArea::EOcclusionState::Visible) {
|
|
|
|
closestDist = dist;
|
|
|
|
lastArea = connArea;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-07-23 03:07:07 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-07-22 19:46:30 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-07-22 19:46:30 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (lastArea != nullptr) {
|
|
|
|
if (closestDist != 0.f) {
|
|
|
|
closestDist /= std::sqrt(closestDist);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
closestDist -= 2.f;
|
|
|
|
if (closestDist < 8.f) {
|
|
|
|
if (closestDist > 0.f) {
|
|
|
|
closestDist = (closestDist / 8.f) * 0.5f + 0.5f;
|
|
|
|
} else {
|
|
|
|
closestDist = 0.5f;
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
xf24_thermColdScale1 = (1.f - closestDist) * lastArea->GetPostConstructed()->x111c_thermalCurrent +
|
|
|
|
closestDist * area->GetPostConstructed()->x111c_thermalCurrent;
|
|
|
|
return;
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
xf24_thermColdScale1 = area->GetPostConstructed()->x111c_thermalCurrent;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
void CStateManager::RendererDrawCallback(void* drawable, void* ctx, int type) {
|
|
|
|
CStateManager& mgr = *static_cast<CStateManager*>(ctx);
|
2018-12-08 05:30:43 +00:00
|
|
|
switch (type) {
|
|
|
|
case 0: {
|
2020-04-09 17:28:20 +00:00
|
|
|
CActor& actor = *static_cast<CActor*>(drawable);
|
|
|
|
if (actor.xc8_drawnToken == mgr.x8dc_objectDrawToken) {
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
2020-04-09 17:28:20 +00:00
|
|
|
}
|
|
|
|
if (actor.xc6_nextDrawNode != kInvalidUniqueId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.RecursiveDrawTree(actor.xc6_nextDrawNode);
|
2020-04-09 17:28:20 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
actor.Render(mgr);
|
2020-04-09 17:28:20 +00:00
|
|
|
actor.xc8_drawnToken = mgr.x8dc_objectDrawToken;
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
2020-04-09 17:28:20 +00:00
|
|
|
static_cast<CSimpleShadow*>(drawable)->Render(mgr.x8f0_shadowTex);
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2020-04-09 17:28:20 +00:00
|
|
|
static_cast<CDecal*>(drawable)->Render();
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CStateManager::RenderLast(TUniqueId uid) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x86c_stateManagerContainer->xf39c_renderLast.size() == 20) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x86c_stateManagerContainer->xf39c_renderLast.push_back(uid);
|
|
|
|
return true;
|
2017-03-20 05:09:53 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
void CStateManager::AddDrawableActorPlane(CActor& actor, const zeus::CPlane& plane, const zeus::CAABox& aabb) const {
|
|
|
|
actor.SetAddedToken(x8dc_objectDrawToken + 1);
|
2020-03-17 00:01:57 +00:00
|
|
|
g_Renderer->AddPlaneObject(&actor, aabb, plane, 0);
|
2016-11-20 21:53:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
void CStateManager::AddDrawableActor(CActor& actor, const zeus::CVector3f& vec, const zeus::CAABox& aabb) const {
|
|
|
|
actor.SetAddedToken(x8dc_objectDrawToken + 1);
|
2020-03-17 00:01:57 +00:00
|
|
|
g_Renderer->AddDrawable(&actor, vec, aabb, 0, IRenderer::EDrawableSorting::SortedCallback);
|
2016-04-17 05:35:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CStateManager::SpecialSkipCinematic() {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (xf38_skipCineSpecialFunc == kInvalidUniqueId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-02-18 02:19:50 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
auto* ent = static_cast<CScriptSpecialFunction*>(ObjectById(xf38_skipCineSpecialFunc));
|
|
|
|
if (ent == nullptr || !ent->ShouldSkipCinematic(*this)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-02-18 02:19:50 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const bool hadRandom = x900_activeRandom != nullptr;
|
2018-12-08 05:30:43 +00:00
|
|
|
SetActiveRandomToDefault();
|
|
|
|
x870_cameraManager->SkipCinematic(*this);
|
|
|
|
ent->SkipCinematic(*this);
|
|
|
|
x900_activeRandom = hadRandom ? &x8fc_random : nullptr;
|
2017-02-18 02:19:50 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2017-02-18 02:19:50 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
TAreaId CStateManager::GetVisAreaId() const {
|
|
|
|
const CGameCamera* cam = static_cast<const CGameCamera*>(x870_cameraManager->GetCurrentCamera(*this));
|
|
|
|
const CBallCamera* ballCam = x870_cameraManager->GetBallCamera();
|
2020-05-09 21:32:12 +00:00
|
|
|
const TAreaId curArea = x850_world->x68_curAreaId;
|
|
|
|
if (cam != ballCam) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return curArea;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-03 07:18:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& camTranslation = ballCam->GetTranslation();
|
|
|
|
zeus::CAABox camAABB(camTranslation, camTranslation);
|
|
|
|
camAABB.accumulateBounds(x84c_player->GetTranslation());
|
|
|
|
rstl::reserved_vector<TUniqueId, 1024> nearList;
|
|
|
|
BuildNearList(nearList, camAABB,
|
|
|
|
CMaterialFilter(EMaterialTypes::AIBlock, CMaterialList(), CMaterialFilter::EFilterType::Include),
|
|
|
|
nullptr);
|
2020-05-09 21:32:12 +00:00
|
|
|
for (const TUniqueId id : nearList) {
|
|
|
|
if (const TCastToConstPtr<CScriptDock> dock = GetObjectById(id)) {
|
|
|
|
if (dock->GetAreaId() == curArea && dock->HasPointCrossedDock(*this, camTranslation)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return dock->GetCurrentConnectedAreaId(*this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-03 07:18:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return curArea;
|
2017-03-03 07:18:12 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2019-08-14 10:04:11 +00:00
|
|
|
s32 CStateManager::GetWeaponIdCount(TUniqueId uid, EWeaponType type) const {
|
2018-12-08 05:30:43 +00:00
|
|
|
return x878_weaponManager->GetNumActive(uid, type);
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::RemoveWeaponId(TUniqueId uid, EWeaponType type) { x878_weaponManager->DecrCount(uid, type); }
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::AddWeaponId(TUniqueId uid, EWeaponType type) { x878_weaponManager->IncrCount(uid, type); }
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::UpdateEscapeSequenceTimer(float dt) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (xf0c_escapeTimer <= 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
xf0c_escapeTimer = std::max(FLT_EPSILON, xf0c_escapeTimer - dt);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (xf0c_escapeTimer <= FLT_EPSILON) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x8b8_playerState->SetPlayerAlive(false);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!g_EscapeShakeCountdownInit) {
|
|
|
|
g_EscapeShakeCountdown = 0.f;
|
|
|
|
g_EscapeShakeCountdownInit = true;
|
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_EscapeShakeCountdown -= dt;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (g_EscapeShakeCountdown >= 0.f) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
const float factor = 1.f - xf0c_escapeTimer / xf10_escapeTotalTime;
|
|
|
|
const float factor2 = factor * factor;
|
|
|
|
const CCameraShakeData shakeData(1.f, factor2 * 0.2f * x900_activeRandom->Range(0.5f, 1.f));
|
|
|
|
x870_cameraManager->AddCameraShaker(shakeData, true);
|
|
|
|
x88c_rumbleManager->Rumble(*this, ERumbleFxId::EscapeSequenceShake, 0.75f, ERumblePriority::One);
|
|
|
|
g_EscapeShakeCountdown = -12.f * factor2 + 15.f;
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::ResetEscapeSequenceTimer(float time) {
|
|
|
|
xf0c_escapeTimer = time;
|
|
|
|
xf10_escapeTotalTime = time;
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::SetupParticleHook(const CActor& actor) const {
|
|
|
|
x884_actorModelParticles->SetupHook(actor.GetUniqueId());
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::MurderScriptInstanceNames() { xb40_uniqueInstanceNames.clear(); }
|
|
|
|
|
|
|
|
std::string CStateManager::HashInstanceName(CInputStream& in) {
|
2020-04-18 07:02:44 +00:00
|
|
|
return in.readString();
|
2016-04-17 05:35:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::SetActorAreaId(CActor& actor, TAreaId aid) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const TAreaId actorAid = actor.GetAreaIdAlways();
|
|
|
|
if (actorAid == aid) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (actorAid != kInvalidAreaId) {
|
|
|
|
CGameArea* area = x850_world->GetArea(actorAid);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (area->IsPostConstructed()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
area->GetAreaObjects()->RemoveObject(actor.GetUniqueId());
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
actor.x4_areaId = aid;
|
2017-12-19 03:05:50 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (aid == kInvalidAreaId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGameArea* area = x850_world->GetArea(aid);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!area->IsPostConstructed() || area->GetAreaObjects()->GetValidObjectById(actor.GetUniqueId())) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
area->GetAreaObjects()->AddObject(actor);
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::TouchSky() const { x850_world->TouchSky(); }
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::TouchPlayerActor() {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (xf6c_playerActorHead == kInvalidUniqueId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CEntity* ent = ObjectById(xf6c_playerActorHead)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
static_cast<CScriptPlayerActor*>(ent)->TouchModels(*this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-09-25 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::DrawSpaceWarp(const zeus::CVector3f& v, float strength) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
const CPlayerState::EPlayerVisor visor = x8b8_playerState->GetActiveVisor(*this);
|
|
|
|
|
|
|
|
if (visor != CPlayerState::EPlayerVisor::Scan && visor != CPlayerState::EPlayerVisor::Combat) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
const zeus::CVector3f screenV =
|
|
|
|
TCastToConstPtr<CGameCamera>(x870_cameraManager->GetCurrentCamera(*this))->ConvertToScreenSpace(v);
|
|
|
|
g_Renderer->DrawSpaceWarp(screenV, strength);
|
2016-04-17 05:35:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::DrawReflection(const zeus::CVector3f& reflectPoint) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CAABox aabb = x84c_player->GetBoundingBox();
|
|
|
|
const zeus::CVector3f playerPos = aabb.center();
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f surfToPlayer = playerPos - reflectPoint;
|
|
|
|
surfToPlayer.z() = 0.f;
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CVector3f viewPos = playerPos - surfToPlayer.normalized() * 3.5f;
|
|
|
|
const zeus::CTransform look = zeus::lookAt(viewPos, playerPos, {0.f, 0.f, -1.f});
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CTransform backupView = CGraphics::g_ViewMatrix;
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetViewPointMatrix(look);
|
2020-05-09 21:32:12 +00:00
|
|
|
const CGraphics::CProjectionState backupProj = CGraphics::GetProjectionState();
|
|
|
|
const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this);
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->SetPerspective(cam->GetFov(), g_Viewport.x8_width, g_Viewport.xc_height, cam->GetNearClipDistance(),
|
|
|
|
cam->GetFarClipDistance());
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x84c_player->RenderReflectedPlayer(*this);
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetViewPointMatrix(backupView);
|
|
|
|
CGraphics::SetProjectionState(backupProj);
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::ReflectionDrawer(void* ctx, const zeus::CVector3f& vec) {
|
2020-03-17 00:05:21 +00:00
|
|
|
static_cast<CStateManager*>(ctx)->DrawReflection(vec);
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::CacheReflection() { g_Renderer->CacheReflection(ReflectionDrawer, this, true); }
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CStateManager::CanCreateProjectile(TUniqueId uid, EWeaponType type, int maxAllowed) const {
|
|
|
|
return x878_weaponManager->GetNumActive(uid, type) < maxAllowed;
|
2017-03-26 19:36:07 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::BuildDynamicLightListForWorld() {
|
|
|
|
if (x8b8_playerState->GetActiveVisor(*this) == CPlayerState::EPlayerVisor::Thermal) {
|
2017-03-03 07:18:12 +00:00
|
|
|
x8e0_dynamicLights.clear();
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2020-07-07 10:14:41 +00:00
|
|
|
if (GetLightObjectList().size() == 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x8e0_dynamicLights.clear();
|
2020-05-09 21:32:12 +00:00
|
|
|
for (const CEntity* ent : GetLightObjectList()) {
|
|
|
|
const auto& light = static_cast<const CGameLight&>(*ent);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (light.GetActive()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const CLight l = light.GetLight();
|
|
|
|
if (l.GetIntensity() > FLT_EPSILON && l.GetRadius() > FLT_EPSILON) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x8e0_dynamicLights.push_back(l);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-26 19:36:07 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-26 19:36:07 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-15 06:29:41 +00:00
|
|
|
void CStateManager::DrawDebugStuff() const {
|
2020-04-18 07:02:44 +00:00
|
|
|
#ifndef NDEBUG
|
2018-12-15 06:29:41 +00:00
|
|
|
for (CEntity* ent : GetActorObjectList()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CPatterned> ai = ent) {
|
2018-12-15 06:29:41 +00:00
|
|
|
if (CPathFindSearch* path = ai->GetSearchPath()) {
|
|
|
|
path->DebugDraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-18 07:02:44 +00:00
|
|
|
#endif
|
2018-12-15 06:29:41 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
void CStateManager::RenderCamerasAndAreaLights() {
|
2018-12-08 05:30:43 +00:00
|
|
|
x870_cameraManager->RenderCameras(*this);
|
2020-04-09 17:28:20 +00:00
|
|
|
for (const CCameraFilterPassPoly& filter : xb84_camFilterPasses) {
|
2018-12-08 05:30:43 +00:00
|
|
|
filter.Draw();
|
2020-04-09 17:28:20 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 00:07:53 +00:00
|
|
|
void CStateManager::DrawE3DeathEffect() {
|
|
|
|
const CPlayer& player = *x84c_player;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (player.x9f4_deathTime <= 0.f) {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-17 00:07:53 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (player.x2f8_morphBallState != CPlayer::EPlayerMorphBallState::Unmorphed) {
|
|
|
|
const float blurAmt = zeus::clamp(0.f, (player.x9f4_deathTime - 1.f) / (6.f - 1.f), 1.f);
|
|
|
|
if (blurAmt > 0.f) {
|
|
|
|
CCameraBlurPass blur;
|
|
|
|
blur.SetBlur(EBlurType::HiBlur, 7.f * blurAmt, 0.f);
|
|
|
|
blur.Draw();
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
const float whiteAmt = zeus::clamp(0.f, 1.f - player.x9f4_deathTime / (0.05f * 6.f), 1.f);
|
|
|
|
zeus::CColor color = zeus::skWhite;
|
|
|
|
color.a() = whiteAmt;
|
|
|
|
m_deathWhiteout.draw(color);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 00:07:53 +00:00
|
|
|
void CStateManager::DrawAdditionalFilters() {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (xf0c_escapeTimer >= 1.f || xf0c_escapeTimer <= 0.f || x870_cameraManager->IsInCinematicCamera()) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
zeus::CColor color = zeus::skWhite;
|
|
|
|
color.a() = 1.f - xf0c_escapeTimer;
|
|
|
|
m_escapeWhiteout.draw(color);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CFrustum CStateManager::SetupDrawFrustum(const SViewport& vp) const {
|
|
|
|
zeus::CFrustum ret;
|
|
|
|
const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this);
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CTransform camXf = x870_cameraManager->GetCurrentCameraTransform(*this);
|
|
|
|
const int vpWidth = static_cast<int>(xf2c_viewportScale.x() * vp.x8_width);
|
|
|
|
const int vpHeight = static_cast<int>(xf2c_viewportScale.y() * vp.xc_height);
|
|
|
|
const int vpLeft = static_cast<int>((vp.x8_width - vpWidth) / 2 + vp.x0_left);
|
|
|
|
const int vpTop = static_cast<int>((vp.xc_height - vpHeight) / 2 + vp.x4_top);
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->SetViewport(vpLeft, vpTop, vpWidth, vpHeight);
|
2020-05-09 21:32:12 +00:00
|
|
|
const float fov = std::atan(std::tan(zeus::degToRad(cam->GetFov()) * 0.5f) * xf2c_viewportScale.y()) * 2.f;
|
|
|
|
const float width = xf2c_viewportScale.x() * vp.x8_width;
|
|
|
|
const float height = xf2c_viewportScale.y() * vp.xc_height;
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CProjection proj;
|
|
|
|
proj.setPersp(zeus::SProjPersp{fov, width / height, cam->GetNearClipDistance(), cam->GetFarClipDistance()});
|
|
|
|
ret.updatePlanes(camXf, proj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CFrustum CStateManager::SetupViewForDraw(const SViewport& vp) const {
|
|
|
|
const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this);
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CTransform camXf = x870_cameraManager->GetCurrentCameraTransform(*this);
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->SetWorldViewpoint(camXf);
|
|
|
|
CBooModel::SetNewPlayerPositionAndTime(x84c_player->GetTranslation());
|
2020-05-09 21:32:12 +00:00
|
|
|
const int vpWidth = static_cast<int>(xf2c_viewportScale.x() * vp.x8_width);
|
|
|
|
const int vpHeight = static_cast<int>(xf2c_viewportScale.y() * vp.xc_height);
|
|
|
|
const int vpLeft = static_cast<int>((vp.x8_width - vpWidth) / 2 + vp.x0_left);
|
|
|
|
const int vpTop = static_cast<int>((vp.xc_height - vpHeight) / 2 + vp.x4_top);
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->SetViewport(vpLeft, vpTop, vpWidth, vpHeight);
|
|
|
|
CGraphics::SetDepthRange(DEPTH_WORLD, DEPTH_FAR);
|
2020-05-09 21:32:12 +00:00
|
|
|
const float fov = std::atan(std::tan(zeus::degToRad(cam->GetFov()) * 0.5f) * xf2c_viewportScale.y()) * 2.f;
|
|
|
|
const float width = xf2c_viewportScale.x() * vp.x8_width;
|
|
|
|
const float height = xf2c_viewportScale.y() * vp.xc_height;
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->SetPerspective(zeus::radToDeg(fov), width, height, cam->GetNearClipDistance(), cam->GetFarClipDistance());
|
|
|
|
zeus::CFrustum frustum;
|
|
|
|
zeus::CProjection proj;
|
|
|
|
proj.setPersp(zeus::SProjPersp{fov, width / height, cam->GetNearClipDistance(), cam->GetFarClipDistance()});
|
|
|
|
frustum.updatePlanes(camXf, proj);
|
|
|
|
g_Renderer->SetClippingPlanes(frustum);
|
2019-02-24 07:15:54 +00:00
|
|
|
// g_Renderer->PrimColor(zeus::skWhite);
|
|
|
|
CGraphics::SetModelMatrix(zeus::CTransform());
|
2018-12-08 05:30:43 +00:00
|
|
|
x87c_fluidPlaneManager->StartFrame(false);
|
|
|
|
g_Renderer->SetDebugOption(IRenderer::EDebugOption::One, 1);
|
|
|
|
return frustum;
|
2017-03-03 07:18:12 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 03:41:01 +00:00
|
|
|
zeus::CFrustum CStateManager::SetupViewForCubeFaceDraw(const zeus::CVector3f& pos, int face) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CTransform mainCamXf = x870_cameraManager->GetCurrentCameraTransform(*this);
|
|
|
|
const zeus::CTransform camXf = zeus::CTransform(mainCamXf.basis * CGraphics::skCubeBasisMats[face], pos);
|
2019-06-01 03:41:01 +00:00
|
|
|
g_Renderer->SetWorldViewpoint(camXf);
|
|
|
|
CBooModel::SetNewPlayerPositionAndTime(x84c_player->GetTranslation());
|
|
|
|
constexpr float width = CUBEMAP_RES;
|
|
|
|
g_Renderer->SetViewport(0, 0, width, width);
|
|
|
|
CGraphics::SetDepthRange(DEPTH_WORLD, DEPTH_FAR);
|
|
|
|
constexpr float fov = zeus::degToRad(90.f);
|
|
|
|
g_Renderer->SetPerspective(zeus::radToDeg(fov), width, width, 0.2f, 750.f);
|
|
|
|
zeus::CFrustum frustum;
|
|
|
|
zeus::CProjection proj;
|
|
|
|
proj.setPersp(zeus::SProjPersp{fov, 1.f, 0.2f, 750.f});
|
|
|
|
frustum.updatePlanes(camXf, proj);
|
|
|
|
g_Renderer->SetClippingPlanes(frustum);
|
|
|
|
CGraphics::SetModelMatrix(zeus::CTransform());
|
|
|
|
return frustum;
|
|
|
|
}
|
|
|
|
|
2017-03-06 06:33:51 +00:00
|
|
|
void CStateManager::ResetViewAfterDraw(const SViewport& backupViewport,
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CTransform& backupViewMatrix) const {
|
|
|
|
g_Renderer->SetViewport(backupViewport.x0_left, backupViewport.x4_top, backupViewport.x8_width,
|
|
|
|
backupViewport.xc_height);
|
|
|
|
const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this);
|
|
|
|
|
|
|
|
zeus::CFrustum frustum;
|
2019-01-23 07:52:19 +00:00
|
|
|
frustum.updatePlanes(backupViewMatrix, zeus::SProjPersp(zeus::degToRad(cam->GetFov()), g_Viewport.aspect,
|
2018-12-08 05:30:43 +00:00
|
|
|
cam->GetNearClipDistance(), cam->GetFarClipDistance()));
|
|
|
|
g_Renderer->SetClippingPlanes(frustum);
|
|
|
|
|
|
|
|
g_Renderer->SetPerspective(cam->GetFov(), g_Viewport.x8_width, g_Viewport.xc_height, cam->GetNearClipDistance(),
|
|
|
|
cam->GetFarClipDistance());
|
|
|
|
}
|
|
|
|
|
2020-03-17 00:07:53 +00:00
|
|
|
void CStateManager::DrawWorld() {
|
2019-07-21 08:42:52 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::DrawWorld", zeus::skBlue);
|
2020-03-18 02:41:29 +00:00
|
|
|
const CTimeProvider timeProvider(xf14_curTimeMod900);
|
|
|
|
const SViewport backupViewport = g_Viewport;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
/* Area camera is in (not necessarily player) */
|
2020-03-18 02:41:29 +00:00
|
|
|
const TAreaId visAreaId = GetVisAreaId();
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
x850_world->TouchSky();
|
|
|
|
|
2019-06-01 03:41:01 +00:00
|
|
|
DrawWorldCubeFaces();
|
|
|
|
|
2020-03-18 02:41:29 +00:00
|
|
|
const zeus::CFrustum frustum = SetupViewForDraw(g_Viewport);
|
|
|
|
const zeus::CTransform backupViewMatrix = CGraphics::g_ViewMatrix;
|
2019-06-01 03:41:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
int areaCount = 0;
|
2020-03-18 02:41:29 +00:00
|
|
|
std::array<const CGameArea*, 10> areaArr;
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const CGameArea& area : *x850_world) {
|
2020-03-18 02:41:29 +00:00
|
|
|
if (areaCount == 10) {
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
CGameArea::EOcclusionState occState = CGameArea::EOcclusionState::Occluded;
|
2020-03-18 02:41:29 +00:00
|
|
|
if (area.IsPostConstructed()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
occState = area.GetOcclusionState();
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
|
|
|
if (occState == CGameArea::EOcclusionState::Visible) {
|
2018-12-08 05:30:43 +00:00
|
|
|
areaArr[areaCount++] = &area;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 02:41:29 +00:00
|
|
|
std::sort(areaArr.begin(), areaArr.begin() + areaCount, [visAreaId](const CGameArea* a, const CGameArea* b) {
|
|
|
|
if (a->x4_selfIdx == b->x4_selfIdx) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (visAreaId == a->x4_selfIdx) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (visAreaId == b->x4_selfIdx) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return CGraphics::g_ViewPoint.dot(a->GetAABB().center()) > CGraphics::g_ViewPoint.dot(b->GetAABB().center());
|
|
|
|
});
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
int pvsCount = 0;
|
2020-03-18 02:41:29 +00:00
|
|
|
std::array<CPVSVisSet, 10> pvsArr;
|
|
|
|
for (auto area = areaArr.cbegin(); area != areaArr.cbegin() + areaCount; ++area) {
|
2018-12-08 05:30:43 +00:00
|
|
|
const CGameArea* areaPtr = *area;
|
|
|
|
CPVSVisSet& pvsSet = pvsArr[pvsCount++];
|
|
|
|
pvsSet.Reset(EPVSVisSetState::OutOfBounds);
|
|
|
|
GetVisSetForArea(areaPtr->x4_selfIdx, visAreaId, pvsSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mask;
|
|
|
|
int targetMask;
|
2020-05-09 21:32:12 +00:00
|
|
|
const auto visor = x8b8_playerState->GetActiveVisor(*this);
|
|
|
|
const bool thermal = visor == CPlayerState::EPlayerVisor::Thermal;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (thermal) {
|
2020-03-17 00:07:53 +00:00
|
|
|
xf34_thermalFlag = EThermalDrawFlag::Cold;
|
2018-12-08 05:30:43 +00:00
|
|
|
mask = 0x34;
|
|
|
|
targetMask = 0;
|
|
|
|
} else {
|
2020-03-17 00:07:53 +00:00
|
|
|
xf34_thermalFlag = EThermalDrawFlag::Bypass;
|
2018-12-08 05:30:43 +00:00
|
|
|
mask = 1 << (visor == CPlayerState::EPlayerVisor::XRay ? 3 : 1);
|
|
|
|
targetMask = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_Renderer->SetThermal(thermal, g_tweakGui->GetThermalVisorLevel(), g_tweakGui->GetThermalVisorColor());
|
|
|
|
g_Renderer->SetThermalColdScale(xf28_thermColdScale2 + xf24_thermColdScale1);
|
|
|
|
|
|
|
|
for (int i = areaCount - 1; i >= 0; --i) {
|
|
|
|
const CGameArea& area = *areaArr[i];
|
|
|
|
SetupFogForArea(area);
|
|
|
|
g_Renderer->EnablePVS(pvsArr[i], area.x4_selfIdx);
|
|
|
|
g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel);
|
|
|
|
g_Renderer->UpdateAreaUniforms(area.x4_selfIdx);
|
|
|
|
g_Renderer->DrawUnsortedGeometry(area.x4_selfIdx, mask, targetMask);
|
|
|
|
}
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!SetupFogForDraw()) {
|
2019-02-24 07:15:54 +00:00
|
|
|
g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-04 04:31:08 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x850_world->DrawSky(zeus::CTransform::Translate(CGraphics::g_ViewPoint));
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (areaCount != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
SetupFogForArea(*areaArr[areaCount - 1]);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
for (const TUniqueId id : x86c_stateManagerContainer->xf370_) {
|
|
|
|
if (auto* ent = static_cast<CActor*>(ObjectById(id))) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!thermal || (ent->xe6_27_thermalVisorFlags & 1) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ent->Render(*this);
|
2020-04-09 17:28:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
bool morphingPlayerVisible = false;
|
|
|
|
int thermalActorCount = 0;
|
2020-03-18 02:41:29 +00:00
|
|
|
std::array<CActor*, 1024> thermalActorArr;
|
2018-12-08 05:30:43 +00:00
|
|
|
for (int i = 0; i < areaCount; ++i) {
|
|
|
|
const CGameArea& area = *areaArr[i];
|
|
|
|
CPVSVisSet& pvs = pvsArr[i];
|
2020-05-09 21:32:12 +00:00
|
|
|
const bool isVisArea = area.x4_selfIdx == visAreaId;
|
2018-12-08 05:30:43 +00:00
|
|
|
SetupFogForArea(area);
|
|
|
|
g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel);
|
|
|
|
for (CEntity* ent : *area.GetAreaObjects()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CActor> actor = ent) {
|
|
|
|
if (!actor->IsDrawEnabled()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
const TUniqueId actorId = actor->GetUniqueId();
|
|
|
|
if (!thermal && area.LookupPVSUniqueID(actorId) == actorId) {
|
|
|
|
if (pvs.GetVisible(area.LookupPVSID(actorId)) == EPVSVisSetState::EndOfTree) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x84c_player.get() == actor.GetPtr()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (thermal) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
switch (x84c_player->GetMorphballTransitionState()) {
|
|
|
|
case CPlayer::EPlayerMorphBallState::Unmorphed:
|
|
|
|
case CPlayer::EPlayerMorphBallState::Morphed:
|
|
|
|
x84c_player->AddToRenderer(frustum, *this);
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
morphingPlayerVisible = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!thermal || (actor->xe6_27_thermalVisorFlags & 1) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
actor->AddToRenderer(frustum, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
if (thermal && (actor->xe6_27_thermalVisorFlags & 2) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
thermalActorArr[thermalActorCount++] = actor.GetPtr();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-04 04:31:08 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (isVisArea && !thermal) {
|
|
|
|
CDecalManager::AddToRenderer(frustum, *this);
|
|
|
|
x884_actorModelParticles->AddStragglersToRenderer(*this);
|
2017-03-04 04:31:08 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 00:07:53 +00:00
|
|
|
++x8dc_objectDrawToken;
|
2017-03-04 04:31:08 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x84c_player->GetMorphBall()->DrawBallShadow(*this);
|
2017-03-04 04:31:08 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (xf7c_projectedShadow != nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xf7c_projectedShadow->Render(*this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-04 04:31:08 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->EnablePVS(pvs, area.x4_selfIdx);
|
|
|
|
g_Renderer->DrawSortedGeometry(area.x4_selfIdx, mask, targetMask);
|
|
|
|
}
|
2017-03-04 04:31:08 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x880_envFxManager->Render(*this);
|
2017-03-04 04:31:08 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (morphingPlayerVisible) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x84c_player->Render(*this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->PostRenderFogs();
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (thermal) {
|
|
|
|
if (x86c_stateManagerContainer->xf39c_renderLast.size()) {
|
|
|
|
CGraphics::SetDepthRange(DEPTH_SCREEN_ACTORS, DEPTH_GUN);
|
2020-04-09 17:28:20 +00:00
|
|
|
for (const TUniqueId id : x86c_stateManagerContainer->xf39c_renderLast) {
|
|
|
|
if (auto* actor = static_cast<CActor*>(ObjectById(id))) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if ((actor->xe6_27_thermalVisorFlags & 1) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
actor->Render(*this);
|
2020-04-09 17:28:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetDepthRange(DEPTH_WORLD, DEPTH_FAR);
|
2017-03-06 06:33:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->DoThermalBlendCold();
|
2020-03-17 00:07:53 +00:00
|
|
|
xf34_thermalFlag = EThermalDrawFlag::Hot;
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
for (const TUniqueId id : x86c_stateManagerContainer->xf370_) {
|
|
|
|
if (auto* actor = static_cast<CActor*>(ObjectById(id))) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if ((actor->xe6_27_thermalVisorFlags & 2) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
actor->Render(*this);
|
2020-04-09 17:28:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (int i = areaCount - 1; i >= 0; --i) {
|
|
|
|
const CGameArea& area = *areaArr[i];
|
|
|
|
CPVSVisSet& pvs = pvsArr[i];
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->EnablePVS(pvs, area.x4_selfIdx);
|
|
|
|
g_Renderer->DrawUnsortedGeometry(area.x4_selfIdx, mask, 0x20);
|
|
|
|
g_Renderer->DrawAreaGeometry(area.x4_selfIdx, mask, 0x10);
|
|
|
|
}
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2020-03-17 00:07:53 +00:00
|
|
|
++x8dc_objectDrawToken;
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (int i = 0; i < areaCount; ++i) {
|
|
|
|
const CGameArea& area = *areaArr[i];
|
|
|
|
CPVSVisSet& pvs = pvsArr[i];
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (int j = 0; j < thermalActorCount; ++j) {
|
|
|
|
CActor* actor = thermalActorArr[j];
|
2020-05-09 21:32:12 +00:00
|
|
|
if (actor->GetAreaIdAlways() != area.x4_selfIdx) {
|
|
|
|
if (actor->GetAreaIdAlways() != kInvalidAreaId || area.x4_selfIdx != visAreaId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
actor->AddToRenderer(frustum, *this);
|
|
|
|
}
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (areaCount - 1 == i) {
|
|
|
|
x884_actorModelParticles->AddStragglersToRenderer(*this);
|
|
|
|
CDecalManager::AddToRenderer(frustum, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x84c_player) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x84c_player->AddToRenderer(frustum, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2020-03-17 00:07:53 +00:00
|
|
|
++x8dc_objectDrawToken;
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->EnablePVS(pvs, area.x4_selfIdx);
|
|
|
|
g_Renderer->DrawSortedGeometry(area.x4_selfIdx, mask, 0x10);
|
2017-03-06 06:33:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->PostRenderFogs();
|
|
|
|
}
|
2017-03-06 06:33:51 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x87c_fluidPlaneManager->EndFrame();
|
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack);
|
2017-03-06 06:33:51 +00:00
|
|
|
|
|
|
|
#if 0
|
2020-05-09 21:32:12 +00:00
|
|
|
if (false) {
|
2017-03-06 06:33:51 +00:00
|
|
|
CacheReflection();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-06 06:33:51 +00:00
|
|
|
#endif
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x84c_player) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x84c_player->RenderGun(*this, x870_cameraManager->GetGlobalCameraTranslation(*this));
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x86c_stateManagerContainer->xf39c_renderLast.size()) {
|
|
|
|
CGraphics::SetDepthRange(DEPTH_SCREEN_ACTORS, DEPTH_GUN);
|
2020-04-09 17:28:20 +00:00
|
|
|
for (const TUniqueId id : x86c_stateManagerContainer->xf39c_renderLast) {
|
|
|
|
if (auto* actor = static_cast<CActor*>(ObjectById(id))) {
|
|
|
|
if (!thermal || actor->xe6_27_thermalVisorFlags & 0x2) {
|
2018-12-08 05:30:43 +00:00
|
|
|
actor->Render(*this);
|
2020-04-09 17:28:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetDepthRange(DEPTH_WORLD, DEPTH_FAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thermal) {
|
|
|
|
g_Renderer->DoThermalBlendHot();
|
2019-02-24 07:15:54 +00:00
|
|
|
g_Renderer->SetThermal(false, 0.f, zeus::skBlack);
|
2020-03-17 00:07:53 +00:00
|
|
|
xf34_thermalFlag = EThermalDrawFlag::Bypass;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DrawDebugStuff();
|
|
|
|
RenderCamerasAndAreaLights();
|
|
|
|
ResetViewAfterDraw(backupViewport, backupViewMatrix);
|
|
|
|
DrawE3DeathEffect();
|
|
|
|
DrawAdditionalFilters();
|
|
|
|
}
|
|
|
|
|
2019-06-01 03:41:01 +00:00
|
|
|
void CStateManager::DrawActorCubeFaces(CActor& actor, int& cubeInst) const {
|
|
|
|
if (!actor.m_reflectionCube ||
|
2019-08-11 15:14:52 +00:00
|
|
|
(!TCastToPtr<CPlayer>(actor) && (!actor.GetActive() || !actor.IsDrawEnabled() || actor.xe4_30_outOfFrustum)))
|
2019-06-01 03:41:01 +00:00
|
|
|
return;
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const TAreaId visAreaId = actor.GetAreaIdAlways();
|
|
|
|
const SViewport backupVp = g_Viewport;
|
2019-06-01 03:41:01 +00:00
|
|
|
|
|
|
|
int areaCount = 0;
|
2020-03-18 02:41:29 +00:00
|
|
|
std::array<const CGameArea*, 10> areaArr;
|
2019-06-01 03:41:01 +00:00
|
|
|
for (const CGameArea& area : *x850_world) {
|
2020-03-18 02:41:29 +00:00
|
|
|
if (areaCount == 10) {
|
2019-06-01 03:41:01 +00:00
|
|
|
break;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
auto occState = CGameArea::EOcclusionState::Occluded;
|
2020-03-18 02:41:29 +00:00
|
|
|
if (area.IsPostConstructed()) {
|
2019-06-01 03:41:01 +00:00
|
|
|
occState = area.GetOcclusionState();
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
|
|
|
if (occState == CGameArea::EOcclusionState::Visible) {
|
2019-06-01 03:41:01 +00:00
|
|
|
areaArr[areaCount++] = &area;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2019-06-01 03:41:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int f = 0; f < 6; ++f) {
|
2020-04-11 22:51:39 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CStateManager::DrawActorCubeFaces [{}] {} {} {}"), f,
|
2019-08-11 15:14:52 +00:00
|
|
|
actor.GetUniqueId(), actor.GetEditorId(), actor.GetName())
|
|
|
|
.c_str(),
|
|
|
|
zeus::skOrange);
|
2019-06-01 03:41:01 +00:00
|
|
|
CGraphics::g_BooMainCommandQueue->setRenderTarget(actor.m_reflectionCube, f);
|
|
|
|
SetupViewForCubeFaceDraw(actor.GetRenderBounds().center(), f);
|
|
|
|
CGraphics::g_BooMainCommandQueue->clearTarget();
|
|
|
|
|
2020-03-18 02:41:29 +00:00
|
|
|
std::sort(areaArr.begin(), areaArr.begin() + areaCount, [visAreaId](const CGameArea* a, const CGameArea* b) {
|
|
|
|
if (a->x4_selfIdx == b->x4_selfIdx) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (visAreaId == a->x4_selfIdx) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (visAreaId == b->x4_selfIdx) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return CGraphics::g_ViewPoint.dot(a->GetAABB().center()) > CGraphics::g_ViewPoint.dot(b->GetAABB().center());
|
|
|
|
});
|
2019-06-01 03:41:01 +00:00
|
|
|
|
|
|
|
int pvsCount = 0;
|
2020-03-18 02:41:29 +00:00
|
|
|
std::array<CPVSVisSet, 10> pvsArr;
|
|
|
|
for (auto area = areaArr.cbegin(); area != areaArr.cbegin() + areaCount; ++area) {
|
2019-06-01 03:41:01 +00:00
|
|
|
const CGameArea* areaPtr = *area;
|
|
|
|
CPVSVisSet& pvsSet = pvsArr[pvsCount++];
|
|
|
|
pvsSet.Reset(EPVSVisSetState::OutOfBounds);
|
|
|
|
GetVisSetForArea(areaPtr->x4_selfIdx, visAreaId, pvsSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = areaCount - 1; i >= 0; --i) {
|
|
|
|
const CGameArea& area = *areaArr[i];
|
|
|
|
SetupFogForArea(area);
|
|
|
|
g_Renderer->EnablePVS(pvsArr[i], area.x4_selfIdx);
|
|
|
|
g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel);
|
2019-06-21 06:02:56 +00:00
|
|
|
g_Renderer->UpdateAreaUniforms(area.x4_selfIdx, EWorldShadowMode::None, true, cubeInst * 6 + f);
|
2019-06-01 03:41:01 +00:00
|
|
|
g_Renderer->DrawUnsortedGeometry(area.x4_selfIdx, 0x2, 0x0);
|
|
|
|
}
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!SetupFogForDraw()) {
|
2019-06-01 03:41:01 +00:00
|
|
|
g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2019-06-01 03:41:01 +00:00
|
|
|
|
|
|
|
x850_world->DrawSky(zeus::CTransform::Translate(CGraphics::g_ViewPoint));
|
|
|
|
|
|
|
|
for (int i = 0; i < areaCount; ++i) {
|
|
|
|
const CGameArea& area = *areaArr[i];
|
|
|
|
CPVSVisSet& pvs = pvsArr[i];
|
|
|
|
SetupFogForArea(area);
|
|
|
|
g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel);
|
|
|
|
g_Renderer->EnablePVS(pvs, area.x4_selfIdx);
|
|
|
|
g_Renderer->DrawSortedGeometry(area.x4_selfIdx, 0x2, 0x0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CGraphics::g_BooMainCommandQueue->generateMipmaps(actor.m_reflectionCube);
|
|
|
|
|
|
|
|
CBooRenderer::BindMainDrawTarget();
|
|
|
|
g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height);
|
|
|
|
|
|
|
|
++cubeInst;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::DrawWorldCubeFaces() const {
|
2020-03-18 02:41:29 +00:00
|
|
|
size_t areaCount = 0;
|
|
|
|
std::array<const CGameArea*, 10> areaArr;
|
2019-06-01 03:41:01 +00:00
|
|
|
for (const CGameArea& area : *x850_world) {
|
2020-03-18 02:41:29 +00:00
|
|
|
if (areaCount == areaArr.size()) {
|
2019-06-01 03:41:01 +00:00
|
|
|
break;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
auto occState = CGameArea::EOcclusionState::Occluded;
|
2020-03-18 02:41:29 +00:00
|
|
|
if (area.IsPostConstructed()) {
|
2019-06-01 03:41:01 +00:00
|
|
|
occState = area.GetOcclusionState();
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
|
|
|
if (occState == CGameArea::EOcclusionState::Visible) {
|
2019-06-01 03:41:01 +00:00
|
|
|
areaArr[areaCount++] = &area;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2019-06-01 03:41:01 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 02:41:29 +00:00
|
|
|
for (size_t ai = 0; ai < areaCount; ++ai) {
|
2019-06-01 03:41:01 +00:00
|
|
|
const CGameArea& area = *areaArr[ai];
|
|
|
|
int cubeInst = 0;
|
|
|
|
for (CEntity* ent : *area.GetAreaObjects()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CActor> actor = ent) {
|
2019-06-01 03:41:01 +00:00
|
|
|
DrawActorCubeFaces(*actor, cubeInst);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2019-06-01 03:41:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-05 01:32:49 +00:00
|
|
|
void CStateManager::SetupFogForArea3XRange(TAreaId area) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (area == kInvalidAreaId) {
|
2020-03-05 01:32:49 +00:00
|
|
|
area = x8cc_nextAreaId;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 01:32:49 +00:00
|
|
|
const CGameArea* areaObj = x850_world->GetAreaAlways(area);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (areaObj->IsPostConstructed()) {
|
2020-03-05 01:32:49 +00:00
|
|
|
SetupFogForArea3XRange(*areaObj);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2020-03-05 01:32:49 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::SetupFogForArea(TAreaId area) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (area == kInvalidAreaId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
area = x8cc_nextAreaId;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const CGameArea* areaObj = x850_world->GetAreaAlways(area);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (areaObj->IsPostConstructed()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
SetupFogForArea(*areaObj);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2018-12-17 05:40:27 +00:00
|
|
|
void CStateManager::SetupFogForAreaNonCurrent(TAreaId area) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (area == kInvalidAreaId) {
|
2018-12-17 05:40:27 +00:00
|
|
|
area = x8cc_nextAreaId;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-17 05:40:27 +00:00
|
|
|
const CGameArea* areaObj = x850_world->GetAreaAlways(area);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (areaObj->IsPostConstructed()) {
|
2018-12-17 05:40:27 +00:00
|
|
|
SetupFogForAreaNonCurrent(*areaObj);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-17 05:40:27 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 01:32:49 +00:00
|
|
|
void CStateManager::SetupFogForArea3XRange(const CGameArea& area) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x8b8_playerState->GetActiveVisor(*this) != CPlayerState::EPlayerVisor::XRay) {
|
|
|
|
return;
|
2020-03-05 01:32:49 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
const float fogDist = area.GetXRayFogDistance();
|
|
|
|
const float farz = (g_tweakGui->GetXRayFogNearZ() * (1.f - fogDist) + g_tweakGui->GetXRayFogFarZ() * fogDist) * 3.f;
|
|
|
|
g_Renderer->SetWorldFog(ERglFogMode(g_tweakGui->GetXRayFogMode()), g_tweakGui->GetXRayFogNearZ(), farz,
|
|
|
|
g_tweakGui->GetXRayFogColor());
|
2020-03-05 01:32:49 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::SetupFogForArea(const CGameArea& area) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (SetupFogForDraw()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (x8b8_playerState->GetActiveVisor(*this) == CPlayerState::EPlayerVisor::XRay) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const float fogDist = area.GetXRayFogDistance();
|
|
|
|
const float farz = g_tweakGui->GetXRayFogNearZ() * (1.f - fogDist) + g_tweakGui->GetXRayFogFarZ() * fogDist;
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->SetWorldFog(ERglFogMode(g_tweakGui->GetXRayFogMode()), g_tweakGui->GetXRayFogNearZ(), farz,
|
|
|
|
g_tweakGui->GetXRayFogColor());
|
|
|
|
} else {
|
|
|
|
area.GetAreaFog()->SetCurrent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 05:40:27 +00:00
|
|
|
void CStateManager::SetupFogForAreaNonCurrent(const CGameArea& area) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (SetupFogForDraw()) {
|
2018-12-17 05:40:27 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-17 05:40:27 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x8b8_playerState->GetActiveVisor(*this) != CPlayerState::EPlayerVisor::XRay) {
|
|
|
|
return;
|
2018-12-17 05:40:27 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
const float fogDist = area.GetXRayFogDistance();
|
|
|
|
const float farz = g_tweakGui->GetXRayFogNearZ() * (1.f - fogDist) + g_tweakGui->GetXRayFogFarZ() * fogDist;
|
|
|
|
g_Renderer->SetWorldFog(ERglFogMode(g_tweakGui->GetXRayFogMode()), g_tweakGui->GetXRayFogNearZ(), farz,
|
|
|
|
g_tweakGui->GetXRayFogColor());
|
2018-12-17 05:40:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CStateManager::SetupFogForDraw() const {
|
|
|
|
switch (x8b8_playerState->GetActiveVisor(*this)) {
|
|
|
|
case CPlayerState::EPlayerVisor::Thermal:
|
2019-02-24 07:15:54 +00:00
|
|
|
g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack);
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
|
|
|
case CPlayerState::EPlayerVisor::XRay:
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
case CPlayerState::EPlayerVisor::Combat:
|
|
|
|
case CPlayerState::EPlayerVisor::Scan:
|
|
|
|
auto& fog = x870_cameraManager->Fog();
|
2020-05-09 21:32:12 +00:00
|
|
|
if (fog.IsFogDisabled()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
fog.SetCurrent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::PreRender() {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!xf94_24_readyToRender) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::PreRender", zeus::skBlue);
|
|
|
|
const zeus::CFrustum frustum = SetupDrawFrustum(g_Viewport);
|
|
|
|
x86c_stateManagerContainer->xf370_.clear();
|
|
|
|
x86c_stateManagerContainer->xf39c_renderLast.clear();
|
|
|
|
xf7c_projectedShadow = nullptr;
|
|
|
|
x850_world->PreRender();
|
|
|
|
BuildDynamicLightListForWorld();
|
|
|
|
for (const CGameArea& area : *x850_world) {
|
|
|
|
auto occState = CGameArea::EOcclusionState::Occluded;
|
|
|
|
if (area.IsPostConstructed()) {
|
|
|
|
occState = area.GetOcclusionState();
|
|
|
|
}
|
|
|
|
if (occState == CGameArea::EOcclusionState::Visible) {
|
|
|
|
for (CEntity* ent : *area.GetPostConstructed()->x10c0_areaObjs) {
|
|
|
|
if (const TCastToPtr<CActor> act = ent) {
|
|
|
|
if (act->IsDrawEnabled()) {
|
|
|
|
act->CalculateRenderBounds();
|
|
|
|
act->PreRender(*this, frustum);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-03 07:18:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
CacheReflection();
|
|
|
|
g_Renderer->PrepareDynamicLights(x8e0_dynamicLights);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::GetCharacterRenderMaskAndTarget(bool thawed, int& mask, int& target) const {
|
|
|
|
switch (x8b8_playerState->GetActiveVisor(*this)) {
|
|
|
|
case CPlayerState::EPlayerVisor::Combat:
|
|
|
|
case CPlayerState::EPlayerVisor::Scan:
|
|
|
|
mask = 0x1000;
|
|
|
|
target = 0x0;
|
|
|
|
break;
|
|
|
|
case CPlayerState::EPlayerVisor::XRay:
|
|
|
|
mask = 0x800;
|
|
|
|
target = 0x0;
|
|
|
|
break;
|
|
|
|
case CPlayerState::EPlayerVisor::Thermal:
|
|
|
|
if (thawed) {
|
|
|
|
if (xf34_thermalFlag == EThermalDrawFlag::Hot) {
|
|
|
|
mask = 0x600;
|
2018-11-08 00:53:38 +00:00
|
|
|
target = 0x0;
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
mask = 0x600;
|
|
|
|
target = 0x200;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (xf34_thermalFlag == EThermalDrawFlag::Cold) {
|
|
|
|
mask = 0x500;
|
2018-11-08 00:53:38 +00:00
|
|
|
target = 0x0;
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
mask = 0x500;
|
|
|
|
target = 0x100;
|
|
|
|
}
|
2018-11-08 00:53:38 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mask = 0x0;
|
|
|
|
target = 0x0;
|
|
|
|
break;
|
|
|
|
}
|
2018-11-08 00:53:38 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CStateManager::GetVisSetForArea(TAreaId a, TAreaId b, CPVSVisSet& setOut) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (b == kInvalidAreaId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-02-19 09:27:01 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CVector3f viewPoint = CGraphics::g_ViewMatrix.origin;
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f closestDockPoint = viewPoint;
|
|
|
|
bool hasClosestDock = false;
|
|
|
|
if (a != b) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const CGameArea& area = *x850_world->GetGameAreas()[b];
|
2018-12-08 05:30:43 +00:00
|
|
|
if (area.IsPostConstructed()) {
|
|
|
|
for (const CGameArea::Dock& dock : area.GetDocks()) {
|
|
|
|
for (int i = 0; i < dock.GetDockRefs().size(); ++i) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const TAreaId connArea = dock.GetConnectedAreaId(i);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (connArea == a) {
|
|
|
|
const auto& verts = dock.GetPlaneVertices();
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CVector3f dockCenter = (verts[0] + verts[1] + verts[2] + verts[3]) * 0.25f;
|
|
|
|
if (hasClosestDock) {
|
|
|
|
if ((dockCenter - viewPoint).magSquared() >= (closestDockPoint - viewPoint).magSquared()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
closestDockPoint = dockCenter;
|
|
|
|
hasClosestDock = true;
|
|
|
|
}
|
2017-02-19 09:27:01 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-02-19 09:27:01 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
hasClosestDock = true;
|
|
|
|
}
|
2017-02-19 09:27:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (hasClosestDock) {
|
|
|
|
if (CPVSAreaSet* pvs = x850_world->GetGameAreas()[a]->GetPostConstructed()->xa0_pvs.get()) {
|
|
|
|
const CPVSVisOctree& octree = pvs->GetVisOctree();
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CVector3f closestDockLocal = x850_world->GetGameAreas()[a]->GetInverseTransform() * closestDockPoint;
|
2018-12-08 05:30:43 +00:00
|
|
|
CPVSVisSet set;
|
|
|
|
set.SetTestPoint(octree, closestDockLocal);
|
|
|
|
|
|
|
|
if (set.GetState() == EPVSVisSetState::NodeFound) {
|
|
|
|
setOut = set;
|
|
|
|
return true;
|
|
|
|
}
|
2017-02-19 09:27:01 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-02-19 09:27:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2017-02-19 09:27:01 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
void CStateManager::RecursiveDrawTree(TUniqueId node) {
|
|
|
|
if (const TCastToPtr<CActor> actor = ObjectById(node)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x8dc_objectDrawToken != actor->xc8_drawnToken) {
|
2020-04-09 17:28:20 +00:00
|
|
|
if (actor->xc6_nextDrawNode != kInvalidUniqueId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
RecursiveDrawTree(actor->xc6_nextDrawNode);
|
2020-04-09 17:28:20 +00:00
|
|
|
}
|
|
|
|
if (x8dc_objectDrawToken == actor->xcc_addedToken) {
|
2018-12-08 05:30:43 +00:00
|
|
|
actor->Render(*this);
|
2020-04-09 17:28:20 +00:00
|
|
|
}
|
|
|
|
actor->xc8_drawnToken = x8dc_objectDrawToken;
|
2017-03-04 04:31:08 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-04 04:31:08 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::SendScriptMsg(CEntity* dest, TUniqueId src, EScriptObjectMessage msg) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (dest == nullptr || dest->x30_26_scriptingBlocked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sm_logScripting != nullptr && sm_logScripting->toBoolean()) {
|
|
|
|
LogModule.report(logvisor::Info, FMT_STRING("Sending '{}' to '{}' id= {}"), ScriptObjectMessageToStr(msg),
|
|
|
|
dest->GetName(), dest->GetUniqueId());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
dest->AcceptScriptMsg(msg, src, *this);
|
2016-07-24 04:46:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::SendScriptMsg(TUniqueId dest, TUniqueId src, EScriptObjectMessage msg) {
|
|
|
|
CEntity* ent = ObjectById(dest);
|
|
|
|
SendScriptMsg(ent, src, msg);
|
2016-08-14 03:00:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::SendScriptMsgAlways(TUniqueId dest, TUniqueId src, EScriptObjectMessage msg) {
|
|
|
|
CEntity* dst = ObjectById(dest);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (dst == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sm_logScripting != nullptr && sm_logScripting->toBoolean()) {
|
|
|
|
LogModule.report(logvisor::Info, FMT_STRING("Sending '{}' to '{}' id= {}"), ScriptObjectMessageToStr(msg),
|
|
|
|
dst->GetName(), dst->GetUniqueId());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
dst->AcceptScriptMsg(msg, src, *this);
|
2016-08-18 18:34:06 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::SendScriptMsg(TUniqueId src, TEditorId dest, EScriptObjectMessage msg, EScriptObjectState state) {
|
2020-03-05 01:32:49 +00:00
|
|
|
// CEntity* ent = GetObjectById(src);
|
2020-05-09 21:32:12 +00:00
|
|
|
const auto search = GetIdListForScript(dest);
|
|
|
|
if (search.first == x890_scriptIdMap.cend()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto it = search.first; it != search.second; ++it) {
|
|
|
|
const TUniqueId id = it->second;
|
|
|
|
CEntity* dobj = GetAllObjectList().GetObjectById(id);
|
|
|
|
SendScriptMsg(dobj, src, msg);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::FreeScriptObjects(TAreaId aid) {
|
2020-05-09 21:32:12 +00:00
|
|
|
for (const auto& p : x890_scriptIdMap) {
|
|
|
|
if (p.first.AreaNum() == aid) {
|
2018-12-08 05:30:43 +00:00
|
|
|
FreeScriptObject(p.second);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-14 04:27:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (auto it = x8a4_loadedScriptObjects.begin(); it != x8a4_loadedScriptObjects.end();) {
|
|
|
|
if (it->first.AreaNum() == aid) {
|
|
|
|
it = x8a4_loadedScriptObjects.erase(it);
|
|
|
|
continue;
|
2017-02-14 04:27:20 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
++it;
|
|
|
|
}
|
2017-02-14 04:27:20 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const CGameArea* area = x850_world->GetGameAreas()[aid].get();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (area->IsPostConstructed()) {
|
|
|
|
const CGameArea::CPostConstructed* pc = area->GetPostConstructed();
|
2020-05-09 21:32:12 +00:00
|
|
|
for (CEntity* ent : *pc->x10c0_areaObjs) {
|
|
|
|
if (ent != nullptr && !ent->IsInUse()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
FreeScriptObject(ent->GetUniqueId());
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-02-14 04:27:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::FreeScriptObject(TUniqueId id) {
|
|
|
|
CEntity* ent = ObjectById(id);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ent == nullptr || ent->IsInGraveyard()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-02-14 04:27:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
ent->SetIsInGraveyard(true);
|
|
|
|
x854_objectGraveyard.push_back(id);
|
|
|
|
ent->AcceptScriptMsg(EScriptObjectMessage::Deleted, kInvalidUniqueId, *this);
|
|
|
|
ent->SetIsScriptingBlocked(true);
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CActor> act = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x874_sortedListManager->Remove(act.GetPtr());
|
|
|
|
act->SetUseInSortedLists(false);
|
|
|
|
}
|
2017-11-26 03:04:25 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (sm_logScripting && sm_logScripting->toBoolean()) {
|
2020-04-11 22:51:39 +00:00
|
|
|
LogModule.report(logvisor::Info, FMT_STRING("Removed '{}'"), ent->GetName());
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-02-14 04:27:20 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::pair<const SScriptObjectStream*, TEditorId> CStateManager::GetBuildForScript(TEditorId id) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
const auto search = x8a4_loadedScriptObjects.find(id);
|
|
|
|
if (search == x8a4_loadedScriptObjects.cend()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return {nullptr, kInvalidEditorId};
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return {&search->second, search->first};
|
2017-02-14 04:27:20 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
TEditorId CStateManager::GetEditorIdForUniqueId(TUniqueId id) const {
|
|
|
|
const CEntity* ent = GetObjectById(id);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ent != nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return ent->GetEditorId();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return kInvalidEditorId;
|
2017-02-14 04:27:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
TUniqueId CStateManager::GetIdForScript(TEditorId id) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
const auto search = x890_scriptIdMap.find(id);
|
|
|
|
if (search == x890_scriptIdMap.cend()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return kInvalidUniqueId;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return search->second;
|
2017-02-14 04:27:20 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2017-01-15 03:59:37 +00:00
|
|
|
std::pair<std::multimap<TEditorId, TUniqueId>::const_iterator, std::multimap<TEditorId, TUniqueId>::const_iterator>
|
2018-12-08 05:30:43 +00:00
|
|
|
CStateManager::GetIdListForScript(TEditorId id) const {
|
|
|
|
auto ret = x890_scriptIdMap.equal_range(id);
|
|
|
|
if (ret.first != x890_scriptIdMap.cend() && ret.first->first != id) {
|
|
|
|
ret.first = x890_scriptIdMap.cend();
|
|
|
|
ret.second = x890_scriptIdMap.cend();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::LoadScriptObjects(TAreaId aid, CInputStream& in, std::vector<TEditorId>& idsOut) {
|
|
|
|
in.readUByte();
|
2020-05-09 21:16:51 +00:00
|
|
|
|
|
|
|
const u32 objCount = in.readUint32Big();
|
2018-12-08 05:30:43 +00:00
|
|
|
idsOut.reserve(idsOut.size() + objCount);
|
2020-05-09 21:16:51 +00:00
|
|
|
|
|
|
|
for (u32 i = 0; i < objCount; ++i) {
|
|
|
|
const auto objType = static_cast<EScriptObjectType>(in.readUByte());
|
|
|
|
const u32 objSize = in.readUint32Big();
|
|
|
|
const u32 pos = static_cast<u32>(in.position());
|
|
|
|
const auto id = LoadScriptObject(aid, objType, objSize, in);
|
|
|
|
if (id.first == kInvalidEditorId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto build = GetBuildForScript(id.first);
|
|
|
|
if (build.first) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:16:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x8a4_loadedScriptObjects[id.first] = SScriptObjectStream{objType, pos, objSize};
|
|
|
|
idsOut.push_back(id.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<TEditorId, TUniqueId> CStateManager::LoadScriptObject(TAreaId aid, EScriptObjectType type, u32 length,
|
|
|
|
CInputStream& in) {
|
2019-09-15 20:04:13 +00:00
|
|
|
const TEditorId id = in.readUint32Big();
|
|
|
|
const u32 connCount = in.readUint32Big();
|
2018-12-08 05:30:43 +00:00
|
|
|
length -= 8;
|
|
|
|
std::vector<SConnection> conns;
|
|
|
|
conns.reserve(connCount);
|
2019-09-15 20:04:13 +00:00
|
|
|
for (u32 i = 0; i < connCount; ++i) {
|
|
|
|
const auto state = EScriptObjectState(in.readUint32Big());
|
|
|
|
const auto msg = EScriptObjectMessage(in.readUint32Big());
|
|
|
|
const TEditorId target = in.readUint32Big();
|
2018-12-08 05:30:43 +00:00
|
|
|
length -= 12;
|
|
|
|
conns.push_back(SConnection{state, msg, target});
|
|
|
|
}
|
2019-09-15 20:04:13 +00:00
|
|
|
const u32 propCount = in.readUint32Big();
|
2018-12-08 05:30:43 +00:00
|
|
|
length -= 4;
|
2019-09-15 20:04:13 +00:00
|
|
|
const auto startPos = in.position();
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
bool error = false;
|
|
|
|
FScriptLoader loader = {};
|
2020-03-18 02:41:29 +00:00
|
|
|
if (type < EScriptObjectType::ScriptObjectTypeMAX && type >= EScriptObjectType::Actor) {
|
|
|
|
loader = x90c_loaderFuncs[size_t(type)];
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
CEntity* ent = nullptr;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (loader != nullptr) {
|
2020-04-20 01:20:25 +00:00
|
|
|
const CEntityInfo info(aid, std::move(conns), id);
|
2018-12-08 05:30:43 +00:00
|
|
|
ent = loader(*this, in, propCount, info);
|
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ent != nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
AddObject(ent);
|
2020-05-09 21:32:12 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
error = true;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const u32 readAmt = in.position() - startPos;
|
|
|
|
if (readAmt > length) {
|
|
|
|
LogModule.report(logvisor::Fatal, FMT_STRING("Script object overread while reading {}"),
|
|
|
|
ScriptObjectTypeToStr(type));
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const u32 leftover = length - readAmt;
|
|
|
|
for (u32 i = 0; i < leftover; ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
in.readByte();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (error || ent == nullptr) {
|
2020-04-20 01:09:30 +00:00
|
|
|
in.seek(startPos, athena::SeekOrigin::Begin);
|
2020-05-09 21:32:12 +00:00
|
|
|
const std::string name = HashInstanceName(in);
|
2020-04-20 01:40:08 +00:00
|
|
|
in.seek(startPos + length, athena::SeekOrigin::Begin);
|
2020-04-20 01:09:30 +00:00
|
|
|
LogModule.report(logvisor::Error, FMT_STRING("Script load error while loading {}, name: {}"),
|
|
|
|
ScriptObjectTypeToStr(type), name);
|
2017-01-24 17:23:10 +00:00
|
|
|
return {kInvalidEditorId, kInvalidUniqueId};
|
2019-11-06 17:33:45 +00:00
|
|
|
} else {
|
2020-04-11 22:51:39 +00:00
|
|
|
LogModule.report(logvisor::Info, FMT_STRING("Loaded {} in area {}"), ent->GetName(), ent->GetAreaIdAlways());
|
2018-12-08 05:30:43 +00:00
|
|
|
return {id, ent->GetUniqueId()};
|
2019-11-06 17:33:45 +00:00
|
|
|
}
|
2017-01-24 17:23:10 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::pair<TEditorId, TUniqueId> CStateManager::GenerateObject(TEditorId eid) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const std::pair<const SScriptObjectStream*, TEditorId> build = GetBuildForScript(eid);
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (build.first) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const CGameArea* area = x850_world->GetArea(build.second.AreaNum());
|
2018-12-08 05:30:43 +00:00
|
|
|
if (area->IsPostConstructed()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const std::pair<const u8*, u32> buf = area->GetLayerScriptBuffer(build.second.LayerNum());
|
2018-12-08 05:30:43 +00:00
|
|
|
CMemoryInStream stream(buf.first + build.first->x4_position, build.first->x8_length);
|
|
|
|
return LoadScriptObject(build.second.AreaNum(), build.first->x0_type, build.first->x8_length, stream);
|
2016-07-24 04:46:32 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return {kInvalidEditorId, kInvalidUniqueId};
|
2016-07-24 04:46:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::InitScriptObjects(const std::vector<TEditorId>& ids) {
|
2020-05-09 21:32:12 +00:00
|
|
|
for (const TEditorId id : ids) {
|
|
|
|
if (id == kInvalidEditorId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const TUniqueId uid = GetIdForScript(id);
|
2018-12-08 05:30:43 +00:00
|
|
|
SendScriptMsg(uid, kInvalidUniqueId, EScriptObjectMessage::InitializedInArea);
|
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
MurderScriptInstanceNames();
|
2017-03-26 19:36:07 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::InformListeners(const zeus::CVector3f& pos, EListenNoiseType type) {
|
|
|
|
for (CEntity* ent : GetListeningAiObjectList()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CAi> ai = ent) {
|
|
|
|
if (!ai->GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGameArea* area = x850_world->GetArea(ai->GetAreaIdAlways());
|
|
|
|
CGameArea::EOcclusionState occState = CGameArea::EOcclusionState::Occluded;
|
2020-05-09 21:32:12 +00:00
|
|
|
|
|
|
|
if (area->IsPostConstructed()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
occState = area->GetPostConstructed()->x10dc_occlusionState;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (occState != CGameArea::EOcclusionState::Occluded) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ai->Listen(pos, type);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::ApplyKnockBack(CActor& actor, const CDamageInfo& info, const CDamageVulnerability& vuln,
|
|
|
|
const zeus::CVector3f& pos, float dampen) {
|
2020-04-16 05:26:14 +00:00
|
|
|
if (vuln.GetVulnerability(info.GetWeaponMode(), false) == EVulnerability::Deflect) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const CHealthInfo* hInfo = actor.HealthInfo(*this);
|
2020-04-16 05:26:14 +00:00
|
|
|
if (hInfo == nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const float dampedPower = (1.f - dampen) * info.GetKnockBackPower();
|
|
|
|
if (const TCastToPtr<CPlayer> player = actor) {
|
2018-12-08 05:30:43 +00:00
|
|
|
KnockBackPlayer(*player, pos, dampedPower, hInfo->GetKnockbackResistance());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const TCastToPtr<CAi> ai = actor;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!ai && hInfo->GetHP() <= 0.f) {
|
|
|
|
if (dampedPower > hInfo->GetKnockbackResistance()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> physActor = actor) {
|
|
|
|
const zeus::CVector3f kbVec =
|
|
|
|
pos * (dampedPower - hInfo->GetKnockbackResistance()) * physActor->GetMass() * 1.5f;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (physActor->GetMaterialList().HasMaterial(EMaterialTypes::Immovable) ||
|
2020-04-16 05:26:14 +00:00
|
|
|
!physActor->GetMaterialList().HasMaterial(EMaterialTypes::Solid)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2019-02-24 07:15:54 +00:00
|
|
|
physActor->ApplyImpulseWR(kbVec, zeus::CAxisAngle());
|
2017-03-29 02:51:12 +00:00
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 05:26:14 +00:00
|
|
|
if (ai) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ai->KnockBack(pos, *this, info, dampen == 0.f ? EKnockBackType::Direct : EKnockBackType::Radius, false,
|
|
|
|
dampedPower);
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::KnockBackPlayer(CPlayer& player, const zeus::CVector3f& pos, float power, float resistance) {
|
2020-04-16 05:26:14 +00:00
|
|
|
if (player.GetMaterialList().HasMaterial(EMaterialTypes::Immovable)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
float usePower;
|
|
|
|
if (player.GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Morphed) {
|
|
|
|
usePower = power * 1000.f;
|
2020-05-09 21:32:12 +00:00
|
|
|
const auto surface =
|
2018-12-08 05:30:43 +00:00
|
|
|
player.x2b0_outOfWaterTicks == 2 ? player.x2ac_surfaceRestraint : CPlayer::ESurfaceRestraints::Water;
|
2020-04-16 05:26:14 +00:00
|
|
|
if (surface != CPlayer::ESurfaceRestraints::Normal && player.GetOrbitState() == CPlayer::EPlayerOrbitState::NoOrbit) {
|
2018-12-08 05:30:43 +00:00
|
|
|
usePower /= 7.f;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
usePower = power * 500.f;
|
|
|
|
}
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const float minVel = player.GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed ? 35.f : 70.f;
|
|
|
|
const float playerVel = player.x138_velocity.magnitude();
|
|
|
|
const float maxVel = std::max(playerVel, minVel);
|
|
|
|
const zeus::CVector3f negVel = -player.x138_velocity;
|
2018-12-08 05:30:43 +00:00
|
|
|
usePower *= (1.f - 0.5f * zeus::CVector3f::getAngleDiff(pos, negVel) / M_PIF);
|
2019-02-24 07:15:54 +00:00
|
|
|
player.ApplyImpulseWR(pos * usePower, zeus::CAxisAngle());
|
2018-12-08 05:30:43 +00:00
|
|
|
player.UseCollisionImpulses();
|
|
|
|
player.x2d4_accelerationChangeTimer = 0.25f;
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const float newVel = player.x138_velocity.magnitude();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (newVel > maxVel) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CVector3f vel = (1.f / newVel) * player.x138_velocity * maxVel;
|
2018-12-08 05:30:43 +00:00
|
|
|
player.SetVelocityWR(vel);
|
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::ApplyDamageToWorld(TUniqueId damager, const CActor& actor, const zeus::CVector3f& pos,
|
2018-12-08 05:30:43 +00:00
|
|
|
const CDamageInfo& info, const CMaterialFilter& filter) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CAABox aabb(pos - info.GetRadius(), pos + info.GetRadius());
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
bool bomb = false;
|
2020-05-09 21:32:12 +00:00
|
|
|
const TCastToConstPtr<CWeapon> weapon = actor;
|
2020-04-16 05:26:14 +00:00
|
|
|
if (weapon) {
|
2019-04-03 04:32:31 +00:00
|
|
|
bomb = True(weapon->GetAttribField() & (EProjectileAttrib::Bombs | EProjectileAttrib::PowerBombs));
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
rstl::reserved_vector<TUniqueId, 1024> nearList;
|
|
|
|
BuildNearList(nearList, aabb, filter, &actor);
|
2020-05-09 21:32:12 +00:00
|
|
|
for (const TUniqueId id : nearList) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity* ent = ObjectById(id);
|
2020-04-16 05:26:14 +00:00
|
|
|
if (ent == nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const TCastToPtr<CPlayer> player = ent;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (bomb && player) {
|
|
|
|
if (player->GetFrozenState()) {
|
|
|
|
g_GameState->SystemOptions().IncrementFrozenBallCount();
|
2019-08-26 01:29:25 +00:00
|
|
|
MP1::CSamusHud::DisplayHudMemo(u"", CHUDMemoParms{0.f, true, true, true});
|
2018-12-08 05:30:43 +00:00
|
|
|
player->UnFreeze(*this);
|
|
|
|
} else {
|
2020-04-16 05:26:14 +00:00
|
|
|
if ((weapon->GetAttribField() & EProjectileAttrib::Bombs) == EProjectileAttrib::Bombs) {
|
2018-12-08 05:30:43 +00:00
|
|
|
player->BombJump(pos, *this);
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
} else if (ent->GetUniqueId() != damager) {
|
|
|
|
TestBombHittingWater(actor, pos, static_cast<CActor&>(*ent));
|
2020-04-16 05:26:14 +00:00
|
|
|
if (TestRayDamage(pos, static_cast<CActor&>(*ent), nearList)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ApplyRadiusDamage(actor, pos, static_cast<CActor&>(*ent), info);
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CWallCrawlerSwarm> swarm = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
swarm->ApplyRadiusDamage(pos, info, *this);
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CSnakeWeedSwarm> swarm = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
swarm->ApplyRadiusDamage(pos, info, *this);
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::ProcessRadiusDamage(const CActor& damager, CActor& damagee, TUniqueId senderId,
|
|
|
|
const CDamageInfo& info, const CMaterialFilter& filter) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CAABox aabb(damager.GetTranslation() - info.GetRadius(), damager.GetTranslation() + info.GetRadius());
|
2018-12-08 05:30:43 +00:00
|
|
|
rstl::reserved_vector<TUniqueId, 1024> nearList;
|
|
|
|
BuildNearList(nearList, aabb, filter, nullptr);
|
2020-05-09 21:32:12 +00:00
|
|
|
for (const TUniqueId id : nearList) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity* ent = ObjectById(id);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ent == nullptr || ent->GetUniqueId() == damager.GetUniqueId() || ent->GetUniqueId() == senderId ||
|
|
|
|
ent->GetUniqueId() == damagee.GetUniqueId()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
TestBombHittingWater(damager, damager.GetTranslation(), static_cast<CActor&>(*ent));
|
2020-05-09 21:32:12 +00:00
|
|
|
if (TestRayDamage(damager.GetTranslation(), static_cast<CActor&>(*ent), nearList)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ApplyRadiusDamage(damager, damager.GetTranslation(), static_cast<CActor&>(*ent), info);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::ApplyRadiusDamage(const CActor& a1, const zeus::CVector3f& pos, CActor& a2,
|
|
|
|
const CDamageInfo& info) {
|
|
|
|
zeus::CVector3f delta = a2.GetTranslation() - pos;
|
2019-06-12 02:05:17 +00:00
|
|
|
std::optional<zeus::CAABox> bounds;
|
2019-01-05 03:28:02 +00:00
|
|
|
if (delta.magSquared() < info.GetRadius() * info.GetRadius() ||
|
|
|
|
((bounds = a2.GetTouchBounds()) &&
|
|
|
|
CCollidableSphere::Sphere_AABox_Bool(zeus::CSphere{pos, info.GetRadius()}, *bounds))) {
|
|
|
|
float rad = info.GetRadius();
|
2020-04-16 05:26:14 +00:00
|
|
|
if (rad > FLT_EPSILON) {
|
2019-01-05 03:28:02 +00:00
|
|
|
rad = delta.magnitude() / rad;
|
2020-04-16 05:26:14 +00:00
|
|
|
} else {
|
2019-01-05 03:28:02 +00:00
|
|
|
rad = 0.f;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
|
|
|
if (rad > 0.f) {
|
2019-01-05 03:28:02 +00:00
|
|
|
delta.normalize();
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2019-01-05 03:28:02 +00:00
|
|
|
|
|
|
|
bool alive = false;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const CHealthInfo* hInfo = a2.HealthInfo(*this)) {
|
2020-04-16 05:26:14 +00:00
|
|
|
if (hInfo->GetHP() > 0.f) {
|
2019-01-05 03:28:02 +00:00
|
|
|
alive = true;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-05 03:28:02 +00:00
|
|
|
|
2020-04-16 05:26:14 +00:00
|
|
|
const CDamageVulnerability* vuln = rad > 0.f ? a2.GetDamageVulnerability(pos, delta, info) : a2.GetDamageVulnerability();
|
2019-01-05 03:28:02 +00:00
|
|
|
|
|
|
|
if (vuln->WeaponHurts(info.GetWeaponMode(), true)) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const float dam = info.GetRadiusDamage(*vuln);
|
2020-04-16 05:26:14 +00:00
|
|
|
if (dam > 0.f) {
|
2019-01-05 03:28:02 +00:00
|
|
|
ApplyLocalDamage(pos, delta, a2, dam, info.GetWeaponMode());
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2019-01-05 03:28:02 +00:00
|
|
|
a2.SendScriptMsgs(EScriptObjectState::Damage, *this, EScriptObjectMessage::None);
|
|
|
|
SendScriptMsg(&a2, a1.GetUniqueId(), EScriptObjectMessage::Damage);
|
|
|
|
} else {
|
|
|
|
a2.SendScriptMsgs(EScriptObjectState::InvulnDamage, *this, EScriptObjectMessage::None);
|
|
|
|
SendScriptMsg(&a2, a1.GetUniqueId(), EScriptObjectMessage::InvulnDamage);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2019-01-05 03:28:02 +00:00
|
|
|
|
2020-04-16 05:26:14 +00:00
|
|
|
if (alive && info.GetKnockBackPower() > 0.f) {
|
2019-01-05 03:28:02 +00:00
|
|
|
ApplyKnockBack(a2, info, *vuln, (a2.GetTranslation() - a1.GetTranslation()).normalized(), rad);
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 22:36:18 +00:00
|
|
|
bool CStateManager::TestRayDamage(const zeus::CVector3f& pos, const CActor& damagee,
|
2018-12-08 05:30:43 +00:00
|
|
|
const rstl::reserved_vector<TUniqueId, 1024>& nearList) const {
|
|
|
|
const CHealthInfo* hInfo = const_cast<CActor&>(damagee).HealthInfo(const_cast<CStateManager&>(*this));
|
2020-05-09 21:32:12 +00:00
|
|
|
if (hInfo == nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
|
2020-04-09 18:52:49 +00:00
|
|
|
static constexpr CMaterialList incList(EMaterialTypes::Solid);
|
|
|
|
static constexpr CMaterialList exList(EMaterialTypes::ProjectilePassthrough, EMaterialTypes::Player,
|
|
|
|
EMaterialTypes::Occluder, EMaterialTypes::Character);
|
|
|
|
static constexpr CMaterialFilter filter(incList, exList, CMaterialFilter::EFilterType::IncludeExclude);
|
2017-03-29 02:51:12 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const std::optional<zeus::CAABox> bounds = damagee.GetTouchBounds();
|
|
|
|
if (!bounds) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CVector3f center = bounds->center();
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f dir = center - pos;
|
2017-03-29 02:51:12 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!dir.canBeNormalized()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
const float origMag = dir.magnitude();
|
2018-12-08 05:30:43 +00:00
|
|
|
dir = dir * (1.f / origMag);
|
2017-03-29 02:51:12 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (RayCollideWorld(pos, center, nearList, filter, &damagee)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CMRay ray(pos, dir, origMag);
|
|
|
|
if (!MultiRayCollideWorld(ray, filter)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float depth;
|
|
|
|
zeus::CVector3f norm;
|
2020-05-09 21:32:12 +00:00
|
|
|
const u32 count = CollisionUtil::RayAABoxIntersection(ray, *bounds, norm, depth);
|
|
|
|
if (count == 0 || count == 1) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return CGameCollision::RayDynamicIntersectionBool(*this, pos, dir, filter, nearList, &damagee, depth * origMag);
|
2017-03-29 02:51:12 +00:00
|
|
|
}
|
|
|
|
|
2017-08-18 01:30:15 +00:00
|
|
|
bool CStateManager::RayCollideWorld(const zeus::CVector3f& start, const zeus::CVector3f& end,
|
2018-12-08 05:30:43 +00:00
|
|
|
const CMaterialFilter& filter, const CActor* damagee) const {
|
|
|
|
zeus::CVector3f delta = end - start;
|
2020-05-09 21:32:12 +00:00
|
|
|
const float mag = delta.magnitude();
|
2018-12-08 05:30:43 +00:00
|
|
|
delta = delta / mag;
|
|
|
|
rstl::reserved_vector<TUniqueId, 1024> nearList;
|
|
|
|
BuildNearList(nearList, start, delta, mag, filter, damagee);
|
|
|
|
return RayCollideWorldInternal(start, end, filter, nearList, damagee);
|
2017-08-18 01:30:15 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 07:00:50 +00:00
|
|
|
bool CStateManager::RayCollideWorld(const zeus::CVector3f& start, const zeus::CVector3f& end,
|
2017-03-30 22:36:18 +00:00
|
|
|
const rstl::reserved_vector<TUniqueId, 1024>& nearList,
|
2018-12-08 05:30:43 +00:00
|
|
|
const CMaterialFilter& filter, const CActor* damagee) const {
|
|
|
|
return RayCollideWorldInternal(start, end, filter, nearList, damagee);
|
2017-03-30 22:36:18 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 07:00:50 +00:00
|
|
|
bool CStateManager::RayCollideWorldInternal(const zeus::CVector3f& start, const zeus::CVector3f& end,
|
2017-03-30 22:36:18 +00:00
|
|
|
const CMaterialFilter& filter,
|
|
|
|
const rstl::reserved_vector<TUniqueId, 1024>& nearList,
|
2018-12-08 05:30:43 +00:00
|
|
|
const CActor* damagee) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CVector3f delta = end - start;
|
|
|
|
if (!delta.canBeNormalized()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const float mag = delta.magnitude();
|
|
|
|
const zeus::CVector3f dir = delta * (1.f / mag);
|
|
|
|
if (!CGameCollision::RayStaticIntersectionBool(*this, start, dir, mag, filter)) {
|
2016-11-22 20:43:16 +00:00
|
|
|
return false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return CGameCollision::RayDynamicIntersectionBool(*this, start, dir, filter, nearList, damagee, mag);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CStateManager::MultiRayCollideWorld(const zeus::CMRay& ray, const CMaterialFilter& filter) const {
|
|
|
|
zeus::CVector3f crossed = {-ray.dir.z() * ray.dir.z() - ray.dir.y() * ray.dir.x(),
|
|
|
|
ray.dir.x() * ray.dir.x() - ray.dir.z() * ray.dir.y(),
|
|
|
|
ray.dir.y() * ray.dir.y() - ray.dir.x() * -ray.dir.z()};
|
|
|
|
|
|
|
|
crossed.normalize();
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CVector3f crossed2 = ray.dir.cross(crossed) * 0.35355338f;
|
|
|
|
const zeus::CVector3f negCrossed2 = -crossed2;
|
|
|
|
const zeus::CVector3f rms = crossed * 0.35355338f;
|
|
|
|
const zeus::CVector3f negRms = -rms;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CVector3f& useCrossed = (i & 2) != 0 ? negCrossed2 : crossed2;
|
|
|
|
const zeus::CVector3f& useRms = (i & 1) != 0 ? rms : negRms;
|
|
|
|
if (CGameCollision::RayStaticIntersectionBool(*this, ray.start + useCrossed + useRms, ray.dir, ray.length,
|
|
|
|
filter)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::TestBombHittingWater(const CActor& damager, const zeus::CVector3f& pos, CActor& damagee) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const TCastToConstPtr<CWeapon> wpn = damager;
|
|
|
|
if (!wpn) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (False(wpn->GetAttribField() & (EProjectileAttrib::Bombs | EProjectileAttrib::PowerBombs))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool powerBomb = (wpn->GetAttribField() & EProjectileAttrib::PowerBombs) == EProjectileAttrib::PowerBombs;
|
|
|
|
const TCastToPtr<CScriptWater> water = damagee;
|
|
|
|
if (!water) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const zeus::CAABox bounds = water->GetTriggerBoundsWR();
|
|
|
|
const zeus::CVector3f hitPos(pos.x(), pos.y(), bounds.max.z());
|
|
|
|
const float bombRad = powerBomb ? 4.f : 2.f;
|
|
|
|
const float delta = bounds.max.z() - pos.dot(zeus::skUp);
|
|
|
|
if (delta <= bombRad && delta > 0.f) {
|
|
|
|
// Below surface
|
|
|
|
const float rippleFactor = 1.f - delta / bombRad;
|
|
|
|
if (x87c_fluidPlaneManager->GetLastRippleDeltaTime(damager.GetUniqueId()) >= 0.15f) {
|
|
|
|
const float bombMag = powerBomb ? 1.f : 0.75f;
|
|
|
|
const float mag = 0.6f * bombMag + 0.4f * bombMag * std::sin(2.f * M_PIF * rippleFactor * 0.25f);
|
|
|
|
water->GetFluidPlane().AddRipple(mag, damager.GetUniqueId(), hitPos, *water, *this);
|
|
|
|
}
|
|
|
|
if (!powerBomb) {
|
|
|
|
x87c_fluidPlaneManager->CreateSplash(damager.GetUniqueId(), *this, *water, hitPos, rippleFactor, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Above surface
|
|
|
|
const float bombMag = powerBomb ? 2.f : 1.f;
|
|
|
|
if (delta <= -bombMag || delta >= 0.f) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const CRayCastResult res = RayStaticIntersection(pos, zeus::skDown, -delta, CMaterialFilter::skPassEverything);
|
|
|
|
if (res.IsInvalid() && x87c_fluidPlaneManager->GetLastRippleDeltaTime(damager.GetUniqueId()) >= 0.15f) {
|
|
|
|
// Not blocked by static geometry
|
|
|
|
const float mag = 0.6f * bombMag + 0.4f * bombMag * std::sin(2.f * M_PIF * -delta / bombMag * 0.25f);
|
|
|
|
water->GetFluidPlane().AddRipple(mag, damager.GetUniqueId(), hitPos, *water, *this);
|
2017-03-30 22:36:18 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-29 02:51:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CStateManager::ApplyLocalDamage(const zeus::CVector3f& pos, const zeus::CVector3f& dir, CActor& damagee, float dam,
|
|
|
|
const CWeaponMode& weapMode) {
|
|
|
|
CHealthInfo* hInfo = damagee.HealthInfo(*this);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (hInfo == nullptr || dam < 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-11-22 20:43:16 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (hInfo->GetHP() <= 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-11-22 20:43:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float mulDam = dam;
|
2016-11-22 20:43:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
TCastToPtr<CPlayer> player = damagee;
|
|
|
|
CAi* ai = TCastToPtr<CPatterned>(damagee).GetPtr();
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ai == nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ai = TCastToPtr<CDestroyableRock>(damagee).GetPtr();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-11-22 20:43:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (player) {
|
|
|
|
if (GetPlayerState()->CanTakeDamage()) {
|
|
|
|
if (x870_cameraManager->IsInCinematicCamera() ||
|
|
|
|
(weapMode.GetType() == EWeaponType::Phazon &&
|
2020-05-09 21:32:12 +00:00
|
|
|
x8b8_playerState->HasPowerUp(CPlayerState::EItemType::PhazonSuit))) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-06-13 19:36:11 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (g_GameState->GetHardMode()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mulDam *= g_GameState->GetHardModeDamageMultiplier();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-06-13 19:36:11 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float damReduction = 0.f;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x8b8_playerState->HasPowerUp(CPlayerState::EItemType::VariaSuit)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
damReduction = g_tweakPlayer->GetVariaDamageReduction();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
if (x8b8_playerState->HasPowerUp(CPlayerState::EItemType::GravitySuit)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
damReduction = std::max(g_tweakPlayer->GetGravityDamageReduction(), damReduction);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
if (x8b8_playerState->HasPowerUp(CPlayerState::EItemType::PhazonSuit)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
damReduction = std::max(g_tweakPlayer->GetPhazonDamageReduction(), damReduction);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-06-13 19:36:11 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
mulDam = -(damReduction * mulDam - mulDam);
|
2020-05-09 21:32:12 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
mulDam = 0.f;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-31 19:51:40 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const float newHp = hInfo->GetHP() - mulDam;
|
|
|
|
const bool significant = std::fabs(newHp - hInfo->GetHP()) >= 0.00001;
|
2018-12-15 06:29:41 +00:00
|
|
|
hInfo->SetHP(newHp);
|
2017-03-31 19:51:40 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (player && GetPlayerState()->CanTakeDamage()) {
|
|
|
|
player->TakeDamage(significant, pos, mulDam, weapMode.GetType(), *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (newHp <= 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x8b8_playerState->SetPlayerAlive(false);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-31 19:51:40 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ai != nullptr) {
|
|
|
|
if (significant) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ai->TakeDamage(dir, mulDam);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
if (newHp <= 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ai->Death(*this, dir, EScriptObjectState::DeathRattle);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-31 19:51:40 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return significant;
|
2017-03-31 19:51:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-20 05:23:22 +00:00
|
|
|
bool CStateManager::ApplyDamage(TUniqueId damagerId, TUniqueId damageeId, TUniqueId radiusSender,
|
2017-03-31 19:51:40 +00:00
|
|
|
const CDamageInfo& info, const CMaterialFilter& filter,
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& knockbackVec) {
|
|
|
|
CEntity* ent0 = ObjectById(damagerId);
|
|
|
|
CEntity* ent1 = ObjectById(damageeId);
|
2020-05-09 21:32:12 +00:00
|
|
|
const TCastToPtr<CActor> damager = ent0;
|
|
|
|
const TCastToPtr<CActor> damagee = ent1;
|
|
|
|
const bool isPlayer = TCastToPtr<CPlayer>(ent1);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (damagee) {
|
|
|
|
if (CHealthInfo* hInfo = damagee->HealthInfo(*this)) {
|
|
|
|
zeus::CVector3f position;
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CVector3f direction = zeus::skRight;
|
2020-05-09 21:32:12 +00:00
|
|
|
const bool alive = hInfo->GetHP() > 0.f;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (damager) {
|
|
|
|
position = damager->GetTranslation();
|
|
|
|
direction = damager->GetTransform().basis[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
const CDamageVulnerability* dVuln;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (damager || isPlayer) {
|
2018-12-08 05:30:43 +00:00
|
|
|
dVuln = damagee->GetDamageVulnerability(position, direction, info);
|
2020-05-09 21:32:12 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
dVuln = damagee->GetDamageVulnerability();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (info.GetWeaponMode().GetType() == EWeaponType::None || dVuln->WeaponHurts(info.GetWeaponMode(), false)) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (info.GetDamage() > 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ApplyLocalDamage(position, direction, *damagee, info.GetDamage(), info.GetWeaponMode());
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
damagee->SendScriptMsgs(EScriptObjectState::Damage, *this, EScriptObjectMessage::None);
|
|
|
|
SendScriptMsg(damagee.GetPtr(), damagerId, EScriptObjectMessage::Damage);
|
|
|
|
} else {
|
|
|
|
damagee->SendScriptMsgs(EScriptObjectState::InvulnDamage, *this, EScriptObjectMessage::None);
|
|
|
|
SendScriptMsg(damagee.GetPtr(), damagerId, EScriptObjectMessage::InvulnDamage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alive && damager && info.GetKnockBackPower() > 0.f) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CVector3f delta =
|
2018-12-08 05:30:43 +00:00
|
|
|
knockbackVec.isZero() ? (damagee->GetTranslation() - damager->GetTranslation()) : knockbackVec;
|
|
|
|
ApplyKnockBack(*damagee, info, *dVuln, delta.normalized(), 0.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (damager && info.GetRadius() > 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ProcessRadiusDamage(*damager, *damagee, radiusSender, info, filter);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CWallCrawlerSwarm> swarm = ent1) {
|
|
|
|
if (damager) {
|
2018-12-08 05:30:43 +00:00
|
|
|
swarm->ApplyRadiusDamage(damager->GetTranslation(), info, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::UpdateAreaSounds() {
|
|
|
|
rstl::reserved_vector<TAreaId, 10> areas;
|
|
|
|
for (CGameArea& area : *x850_world) {
|
2020-05-09 21:32:12 +00:00
|
|
|
auto occState = CGameArea::EOcclusionState::Occluded;
|
|
|
|
if (area.IsPostConstructed()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
occState = area.GetOcclusionState();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
if (occState == CGameArea::EOcclusionState::Visible) {
|
2018-12-08 05:30:43 +00:00
|
|
|
areas.push_back(area.GetAreaId());
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
CSfxManager::SetActiveAreas(areas);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::FrameEnd() { g_SimplePool->Flush(); }
|
|
|
|
|
|
|
|
void CStateManager::ProcessPlayerInput() {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x84c_player) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x84c_player->ProcessInput(xb54_finalInput, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::SetGameState(EGameState state) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x904_gameState == state) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x904_gameState == EGameState::SoftPaused) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x850_world->SetLoadPauseState(false);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case EGameState::Running:
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x88c_rumbleManager->IsDisabled()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x88c_rumbleManager->SetDisabled(false);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case EGameState::SoftPaused:
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!x88c_rumbleManager->IsDisabled()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x88c_rumbleManager->SetDisabled(true);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x850_world->SetLoadPauseState(true);
|
2019-02-18 05:47:46 +00:00
|
|
|
break;
|
2018-12-08 05:30:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
x904_gameState = state;
|
2017-04-03 01:39:23 +00:00
|
|
|
}
|
|
|
|
|
2017-03-24 05:30:16 +00:00
|
|
|
static const CFinalInput s_DisabledFinalInput = {};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::ProcessInput(const CFinalInput& input) {
|
|
|
|
if (input.ControllerIdx() == 0) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this);
|
2018-12-08 05:30:43 +00:00
|
|
|
bool disableInput = cam->x170_25_disablesInput;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x84c_player->x9c6_29_disableInput) {
|
2018-12-08 05:30:43 +00:00
|
|
|
disableInput = true;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (disableInput) {
|
|
|
|
xb54_finalInput = s_DisabledFinalInput;
|
|
|
|
xb54_finalInput.x0_dt = input.DeltaTime();
|
|
|
|
} else {
|
|
|
|
xb54_finalInput = input;
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
x870_cameraManager->ProcessInput(input, *this);
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::UpdateGraphicsTiming(float dt) {
|
|
|
|
xf14_curTimeMod900 += dt;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (xf14_curTimeMod900 > 900.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xf14_curTimeMod900 -= 900.f;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-12-19 03:05:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::Update(float dt) {
|
|
|
|
MP1::CMain::UpdateDiscordPresence(GetWorld()->IGetStringTableAssetId());
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CElementGen::SetGlobalSeed(x8d8_updateFrameIdx);
|
|
|
|
CParticleElectric::SetGlobalSeed(x8d8_updateFrameIdx);
|
|
|
|
CDecal::SetGlobalSeed(x8d8_updateFrameIdx);
|
|
|
|
CProjectileWeapon::SetGlobalSeed(x8d8_updateFrameIdx);
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
xf08_pauseHudMessage = {};
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CScriptEffect::ResetParticleCounts();
|
|
|
|
UpdateThermalVisor();
|
|
|
|
UpdateGameState();
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const bool dying = x84c_player->x9f4_deathTime > 0.f;
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x904_gameState == EGameState::Running) {
|
|
|
|
if (!TCastToPtr<CCinematicCamera>(x870_cameraManager->GetCurrentCamera(*this))) {
|
2019-12-11 04:51:33 +00:00
|
|
|
g_GameState->SetTotalPlayTime(g_GameState->GetTotalPlayTime() + dt);
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateHintState(dt);
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 02:41:29 +00:00
|
|
|
for (size_t i = 0; i < numCameraPasses; ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xb84_camFilterPasses[i].Update(dt);
|
|
|
|
xd14_camBlurPasses[i].Update(dt);
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x904_gameState != EGameState::Paused) {
|
|
|
|
PreThinkObjects(dt);
|
|
|
|
x87c_fluidPlaneManager->Update(dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x904_gameState == EGameState::Running) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!dying) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CDecalManager::Update(dt, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateSortedLists();
|
|
|
|
if (!dying) {
|
|
|
|
MovePlatforms(dt);
|
|
|
|
MoveActors(dt);
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
ProcessPlayerInput();
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x904_gameState != EGameState::SoftPaused) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CGameCollision::Move(*this, *x84c_player, dt, nullptr);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateSortedLists();
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!dying) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CrossTouchActors();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
ProcessPlayerInput();
|
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!dying && x904_gameState == EGameState::Running) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x884_actorModelParticles->Update(dt, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x904_gameState == EGameState::Running || x904_gameState == EGameState::SoftPaused) {
|
2018-12-08 05:30:43 +00:00
|
|
|
Think(dt);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x904_gameState != EGameState::SoftPaused) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x870_cameraManager->Update(dt, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
while (xf76_lastRelay != kInvalidUniqueId) {
|
|
|
|
if (CEntity* ent = ObjectById(xf76_lastRelay)) {
|
|
|
|
ent->Think(dt, *this);
|
|
|
|
} else {
|
|
|
|
xf76_lastRelay = kInvalidUniqueId;
|
|
|
|
break;
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x904_gameState != EGameState::Paused) {
|
2018-12-08 05:30:43 +00:00
|
|
|
PostUpdatePlayer(dt);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (xf84_ == xf80_hudMessageFrameCount) {
|
|
|
|
ShowPausedHUDMemo(xf88_, xf8c_);
|
|
|
|
--xf84_;
|
|
|
|
xf88_.Reset();
|
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!dying && x904_gameState == EGameState::Running && !x870_cameraManager->IsInCinematicCamera()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateEscapeSequenceTimer(dt);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x850_world->Update(dt);
|
|
|
|
x88c_rumbleManager->Update(dt);
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!dying) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x880_envFxManager->Update(dt, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateAreaSounds();
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
xf94_24_readyToRender = true;
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (xf94_27_inMapScreen) {
|
|
|
|
if (const CHintOptions::SHintState* hint = g_GameState->HintOptions().GetCurrentDisplayedHint()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (hint->CanContinue()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
g_GameState->HintOptions().DismissDisplayedHint();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-09-21 03:41:57 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
xf94_27_inMapScreen = false;
|
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!m_warping) {
|
|
|
|
g_GameState->CurrentWorldState().SetAreaId(x8cc_nextAreaId);
|
|
|
|
x850_world->TravelToArea(x8cc_nextAreaId, *this, false);
|
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
ClearGraveyard();
|
|
|
|
++x8d8_updateFrameIdx;
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::UpdateGameState() {
|
|
|
|
// Intentionally empty
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::UpdateHintState(float dt) {
|
|
|
|
CHintOptions& ho = g_GameState->HintOptions();
|
|
|
|
ho.Update(dt, *this);
|
|
|
|
u32 nextHintIdx = -1;
|
|
|
|
u32 pageIdx = -1;
|
|
|
|
if (const CHintOptions::SHintState* state = ho.GetCurrentDisplayedHint()) {
|
|
|
|
const CGameHintInfo::CGameHint& next = g_MemoryCardSys->GetHints()[ho.GetNextHintIdx()];
|
|
|
|
for (const CGameHintInfo::SHintLocation& loc : next.GetLocations()) {
|
|
|
|
const auto& mwInfo = g_GameState->StateForWorld(loc.x0_mlvlId).MapWorldInfo();
|
|
|
|
mwInfo->SetIsMapped(loc.x8_areaId, true);
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (state->x4_time < next.GetTextTime()) {
|
|
|
|
nextHintIdx = ho.GetNextHintIdx();
|
|
|
|
pageIdx = state->x4_time / 3.f;
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-05-15 02:56:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (xeec_hintIdx != nextHintIdx || xef0_hintPeriods != pageIdx) {
|
|
|
|
if (nextHintIdx == -1) {
|
|
|
|
CHUDMemoParms memoInfo = {0.f, true, true, true};
|
|
|
|
MP1::CSamusHud::DisplayHudMemo(u"", memoInfo);
|
|
|
|
} else {
|
|
|
|
const CGameHintInfo::CGameHint& data = g_MemoryCardSys->GetHints()[nextHintIdx];
|
|
|
|
CHUDMemoParms memoInfo = {0.f, true, false, true};
|
|
|
|
MP1::CSamusHud::DeferHintMemo(data.GetStringID(), pageIdx, memoInfo);
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
xeec_hintIdx = nextHintIdx;
|
|
|
|
xef0_hintPeriods = pageIdx;
|
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::PreThinkObjects(float dt) {
|
|
|
|
if (x84c_player->x9f4_deathTime > 0.f) {
|
|
|
|
x84c_player->DoPreThink(dt, *this);
|
2018-12-31 05:01:42 +00:00
|
|
|
} else if (x904_gameState == EGameState::SoftPaused) {
|
2020-05-09 21:32:12 +00:00
|
|
|
for (CEntity* ent : GetAllObjectList()) {
|
|
|
|
if (const TCastToPtr<CScriptEffect> effect = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
effect->PreThink(dt, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-31 05:01:42 +00:00
|
|
|
} else {
|
2020-05-09 21:32:12 +00:00
|
|
|
for (CEntity* ent : GetAllObjectList()) {
|
|
|
|
if (ent != nullptr && !GetCameraObjectList().GetObjectById(ent->GetUniqueId())) {
|
2018-12-31 05:01:42 +00:00
|
|
|
ent->PreThink(dt, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-31 05:01:42 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::MovePlatforms(float dt) {
|
|
|
|
for (CEntity* ent : GetPlatformAndDoorObjectList()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ent == nullptr || !GetPlatformAndDoorObjectList().IsPlatform(*ent)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto& plat = static_cast<CScriptPlatform&>(*ent);
|
|
|
|
if (!plat.GetActive() || plat.GetMass() == 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGameCollision::Move(*this, plat, dt, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::MoveActors(float dt) {
|
|
|
|
for (CEntity* ent : GetPhysicsActorObjectList()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ent == nullptr || !ent->GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto& physActor = static_cast<CPhysicsActor&>(*ent);
|
|
|
|
if (physActor.GetMass() == 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CAi> ai = physActor) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bool doThink = !xf94_29_cinematicPause;
|
|
|
|
if (doThink && ai->GetAreaIdAlways() != kInvalidAreaId) {
|
|
|
|
const CGameArea* area = x850_world->GetAreaAlways(ai->GetAreaIdAlways());
|
2020-05-09 21:32:12 +00:00
|
|
|
float occTime = 0.0f;
|
|
|
|
if (area->IsPostConstructed()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
occTime = area->GetPostConstructed()->x10e4_occludedTime;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
if (occTime > 5.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
doThink = false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
if (!doThink) {
|
|
|
|
SendScriptMsgAlways(ai->GetUniqueId(), kInvalidUniqueId, EScriptObjectMessage::SuspendedMove);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x84c_player.get() != ent) {
|
|
|
|
if (!GetPlatformAndDoorObjectList().IsPlatform(*ent)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CGameCollision::Move(*this, physActor, dt, nullptr);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::CrossTouchActors() {
|
2020-03-18 02:41:29 +00:00
|
|
|
std::array<bool, 1024> visits{};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (CEntity* ent : GetActorObjectList()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ent == nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto& actor = static_cast<CActor&>(*ent);
|
|
|
|
if (!actor.GetActive() || !actor.GetCallTouch()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const std::optional<zeus::CAABox> touchAABB = actor.GetTouchBounds();
|
2020-03-18 02:41:29 +00:00
|
|
|
if (!touchAABB) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
CMaterialFilter filter = CMaterialFilter::skPassEverything;
|
2020-03-18 02:41:29 +00:00
|
|
|
if (actor.GetMaterialList().HasMaterial(EMaterialTypes::Trigger)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
filter = CMaterialFilter::MakeExclude(EMaterialTypes::Trigger);
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
rstl::reserved_vector<TUniqueId, 1024> nearList;
|
|
|
|
BuildNearList(nearList, *touchAABB, filter, &actor);
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
for (const TUniqueId id : nearList) {
|
2020-03-18 02:41:29 +00:00
|
|
|
auto* ent2 = static_cast<CActor*>(ObjectById(id));
|
|
|
|
if (!ent2) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const std::optional<zeus::CAABox> touchAABB2 = ent2->GetTouchBounds();
|
2020-03-18 02:41:29 +00:00
|
|
|
if (!ent2->GetActive() || !touchAABB2) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2020-03-18 02:41:29 +00:00
|
|
|
if (visits[ent2->GetUniqueId().Value()]) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (touchAABB->intersects(*touchAABB2)) {
|
|
|
|
actor.Touch(*ent2, *this);
|
|
|
|
ent2->Touch(actor, *this);
|
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
visits[actor.GetUniqueId().Value()] = true;
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::Think(float dt) {
|
|
|
|
if (x84c_player->x9f4_deathTime > 0.f) {
|
|
|
|
x84c_player->DoThink(dt, *this);
|
|
|
|
return;
|
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x904_gameState == EGameState::SoftPaused) {
|
2020-05-09 21:32:12 +00:00
|
|
|
for (CEntity* ent : GetAllObjectList()) {
|
|
|
|
if (const TCastToPtr<CScriptEffect> effect = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
effect->Think(dt, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
for (CEntity* ent : GetAllObjectList()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CAi> ai = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bool doThink = !xf94_29_cinematicPause;
|
|
|
|
if (doThink && ai->GetAreaIdAlways() != kInvalidAreaId) {
|
|
|
|
const CGameArea* area = x850_world->GetAreaAlways(ai->GetAreaIdAlways());
|
2020-05-09 21:32:12 +00:00
|
|
|
float occTime = 0.0f;
|
|
|
|
if (area->IsPostConstructed()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
occTime = area->GetPostConstructed()->x10e4_occludedTime;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
if (occTime > 5.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
doThink = false;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-11-27 05:06:53 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!doThink) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!GetCameraObjectList().GetObjectById(ent->GetUniqueId())) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ent->Think(dt, *this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::PostUpdatePlayer(float dt) { x84c_player->PostUpdate(dt, *this); }
|
|
|
|
|
|
|
|
void CStateManager::ShowPausedHUDMemo(CAssetId strg, float time) {
|
|
|
|
xf78_hudMessageTime = time;
|
|
|
|
xf08_pauseHudMessage = strg;
|
|
|
|
DeferStateTransition(EStateManagerTransition::MessageScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::ClearGraveyard() {
|
2020-05-09 21:32:12 +00:00
|
|
|
for (const TUniqueId id : x854_objectGraveyard) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity* ent = GetAllObjectList().GetValidObjectById(id);
|
|
|
|
RemoveObject(id);
|
|
|
|
std::default_delete<CEntity>()(ent);
|
|
|
|
}
|
|
|
|
x854_objectGraveyard.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::FrameBegin(s32 frameCount) { x8d4_inputFrameIdx = frameCount; }
|
|
|
|
|
|
|
|
void CStateManager::InitializeState(CAssetId mlvlId, TAreaId aid, CAssetId mreaId) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const bool hadRandom = x900_activeRandom != nullptr;
|
2018-12-08 05:30:43 +00:00
|
|
|
SetActiveRandomToDefault();
|
|
|
|
|
|
|
|
if (xb3c_initPhase == EInitPhase::LoadWorld) {
|
|
|
|
CreateStandardGameObjects();
|
2019-09-12 03:50:38 +00:00
|
|
|
x850_world = std::make_unique<CWorld>(*g_SimplePool, *g_ResFactory, mlvlId);
|
2018-12-08 05:30:43 +00:00
|
|
|
xb3c_initPhase = EInitPhase::LoadFirstArea;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xb3c_initPhase == EInitPhase::LoadFirstArea) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!x8f0_shadowTex.IsLoaded()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x8f0_shadowTex.GetObj();
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!x850_world->CheckWorldComplete(this, aid, mreaId)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x8cc_nextAreaId = x850_world->x68_curAreaId;
|
|
|
|
CGameArea* area = x850_world->x18_areas[x8cc_nextAreaId].get();
|
|
|
|
if (x850_world->ScheduleAreaToLoad(area, *this)) {
|
|
|
|
area->StartStreamIn(*this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xb3c_initPhase = EInitPhase::Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCurrentAreaId(x8cc_nextAreaId);
|
|
|
|
g_GameState->CurrentWorldState().SetAreaId(x8cc_nextAreaId);
|
|
|
|
x850_world->TravelToArea(x8cc_nextAreaId, *this, true);
|
|
|
|
UpdateRoomAcoustics(x8cc_nextAreaId);
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
for (CEntity* ent : GetAllObjectList()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
SendScriptMsg(ent, kInvalidUniqueId, EScriptObjectMessage::WorldInitialized);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
for (CEntity* ent : GetAllObjectList()) {
|
|
|
|
CScriptSpawnPoint* sp = TCastToPtr<CScriptSpawnPoint>(ent);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (sp != nullptr && sp->x30_24_active && sp->FirstSpawn()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CTransform& xf = sp->GetTransform();
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CVector3f lookVec = xf.frontVector();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (lookVec.canBeNormalized()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const auto lookXf = zeus::lookAt(xf.origin, xf.origin + lookVec);
|
2018-12-08 05:30:43 +00:00
|
|
|
x84c_player->Teleport(lookXf, *this, true);
|
|
|
|
}
|
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!g_GameState->x228_25_initPowerupsAtFirstSpawn) {
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_GameState->x228_25_initPowerupsAtFirstSpawn = false;
|
|
|
|
for (int i = 0; i < int(CPlayerState::EItemType::Max); ++i) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const auto iType = CPlayerState::EItemType(i);
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 spawnPu = sp->GetPowerup(iType);
|
|
|
|
u32 statePu = x8b8_playerState->GetItemAmount(iType);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (statePu < spawnPu) {
|
2019-05-08 03:50:21 +00:00
|
|
|
x8b8_playerState->AddPowerUp(iType, spawnPu - statePu);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
spawnPu = sp->GetPowerup(iType);
|
|
|
|
statePu = x8b8_playerState->GetItemAmount(iType);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (statePu < spawnPu) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x8b8_playerState->IncrPickup(iType, spawnPu - statePu);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x84c_player->AsyncLoadSuit(*this);
|
|
|
|
x870_cameraManager->ResetCameras(*this);
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!hadRandom) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ClearActiveRandom();
|
2020-05-09 21:32:12 +00:00
|
|
|
} else {
|
2017-02-18 02:19:50 +00:00
|
|
|
SetActiveRandomToDefault();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-08-15 01:19:04 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x880_envFxManager->AsyncLoadResources(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::CreateStandardGameObjects() {
|
2019-09-12 03:50:38 +00:00
|
|
|
const float height = g_tweakPlayer->GetPlayerHeight();
|
|
|
|
const float xyHe = g_tweakPlayer->GetPlayerXYHalfExtent();
|
|
|
|
const float stepUp = g_tweakPlayer->GetStepUpHeight();
|
|
|
|
const float stepDown = g_tweakPlayer->GetStepDownHeight();
|
|
|
|
const float ballRadius = g_tweakPlayer->GetPlayerBallHalfExtent();
|
|
|
|
const zeus::CAABox pBounds = {{-xyHe, -xyHe, 0.f}, {xyHe, xyHe, height}};
|
|
|
|
const auto q = zeus::CQuaternion::fromAxisAngle(zeus::CVector3f{0.f, 0.f, 1.f}, zeus::degToRad(129.6f));
|
|
|
|
|
|
|
|
x84c_player = std::make_unique<CPlayer>(
|
|
|
|
AllocateUniqueId(), zeus::CTransform(q), pBounds, g_tweakPlayerRes->xc4_ballTransitionsANCS,
|
|
|
|
zeus::CVector3f{1.65f, 1.65f, 1.65f}, 200.f, stepUp, stepDown, ballRadius,
|
|
|
|
CMaterialList(EMaterialTypes::Player, EMaterialTypes::Solid, EMaterialTypes::GroundCollider));
|
2018-12-08 05:30:43 +00:00
|
|
|
AddObject(*x84c_player);
|
|
|
|
x870_cameraManager->CreateStandardCameras(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
CObjectList* CStateManager::ObjectListById(EGameObjectList type) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (type == EGameObjectList::Invalid) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return nullptr;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return x808_objLists[int(type)].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const CObjectList* CStateManager::GetObjectListById(EGameObjectList type) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (type == EGameObjectList::Invalid) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return nullptr;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return x808_objLists[int(type)].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::RemoveObject(TUniqueId uid) {
|
|
|
|
if (CEntity* ent = GetAllObjectList().GetValidObjectById(uid)) {
|
|
|
|
if (ent->GetEditorId() != kInvalidEditorId) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const auto search = x890_scriptIdMap.equal_range(ent->GetEditorId());
|
2018-12-08 05:30:43 +00:00
|
|
|
for (auto it = search.first; it != search.second;) {
|
|
|
|
if (it->second == uid) {
|
|
|
|
it = x890_scriptIdMap.erase(it);
|
|
|
|
continue;
|
2016-08-14 21:11:44 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
++it;
|
|
|
|
}
|
2016-08-14 21:11:44 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (ent->GetAreaIdAlways() != kInvalidAreaId) {
|
|
|
|
CGameArea* area = x850_world->GetArea(ent->GetAreaIdAlways());
|
2020-05-09 21:32:12 +00:00
|
|
|
if (area->IsPostConstructed()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
area->GetAreaObjects()->RemoveObject(uid);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CActor> act = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x874_sortedListManager->Remove(act.GetPtr());
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
for (auto& list : x808_objLists) {
|
2018-12-08 05:30:43 +00:00
|
|
|
list->RemoveObject(uid);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::UpdateRoomAcoustics(TAreaId aid) {
|
|
|
|
u32 updateCount = 0;
|
2020-03-18 02:41:29 +00:00
|
|
|
std::array<CScriptRoomAcoustics*, 10> updates;
|
2018-12-08 05:30:43 +00:00
|
|
|
for (CEntity* ent : GetAllObjectList()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CScriptRoomAcoustics> acoustics = ent) {
|
2020-03-18 02:41:29 +00:00
|
|
|
if (acoustics->GetAreaIdAlways() != aid || !acoustics->GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
updates[updateCount++] = acoustics.GetPtr();
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
2020-03-18 02:41:29 +00:00
|
|
|
if (updateCount >= updates.size()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
2020-03-18 02:41:29 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-10-01 19:00:16 +00:00
|
|
|
|
2020-03-18 02:41:29 +00:00
|
|
|
if (updateCount == 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CScriptRoomAcoustics::DisableAuxCallbacks();
|
|
|
|
return;
|
|
|
|
}
|
2016-10-01 19:00:16 +00:00
|
|
|
|
2020-03-18 02:41:29 +00:00
|
|
|
const auto idx = int(updateCount * x900_activeRandom->Float() * 0.99f);
|
2018-12-08 05:30:43 +00:00
|
|
|
updates[idx]->EnableAuxCallbacks();
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::SetCurrentAreaId(TAreaId aid) {
|
|
|
|
if (aid != x8cc_nextAreaId) {
|
|
|
|
x8d0_prevAreaId = x8cc_nextAreaId;
|
|
|
|
UpdateRoomAcoustics(aid);
|
|
|
|
x8cc_nextAreaId = aid;
|
|
|
|
}
|
2016-08-14 03:00:58 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (aid == kInvalidAreaId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
if (x8c0_mapWorldInfo->IsAreaVisited(aid)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x8c0_mapWorldInfo->SetAreaVisited(aid, true);
|
2020-03-21 03:24:13 +00:00
|
|
|
x850_world->IGetMapWorld()->RecalculateWorldSphere(*x8c0_mapWorldInfo, *x850_world);
|
2016-04-17 05:35:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::AreaUnloaded(TAreaId) {
|
|
|
|
// Intentionally empty
|
2017-03-31 19:51:40 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::PrepareAreaUnload(TAreaId aid) {
|
|
|
|
for (CEntity* ent : GetAllObjectList()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CScriptDoor> door = ent) {
|
|
|
|
if (door->IsConnectedToArea(*this, aid)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
door->ForceClosed(*this);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
FreeScriptObjects(aid);
|
2017-03-31 19:51:40 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::AreaLoaded(TAreaId aid) {
|
|
|
|
x8bc_relayTracker->SendMsgs(aid, *this);
|
|
|
|
x880_envFxManager->AreaLoaded();
|
2017-03-31 19:51:40 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2017-03-26 05:53:04 +00:00
|
|
|
void CStateManager::BuildNearList(rstl::reserved_vector<TUniqueId, 1024>& listOut, const zeus::CVector3f& v1,
|
|
|
|
const zeus::CVector3f& v2, float f1, const CMaterialFilter& filter,
|
2018-12-08 05:30:43 +00:00
|
|
|
const CActor* actor) const {
|
|
|
|
x874_sortedListManager->BuildNearList(listOut, v1, v2, f1, filter, actor);
|
2016-04-17 05:35:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 05:53:04 +00:00
|
|
|
void CStateManager::BuildColliderList(rstl::reserved_vector<TUniqueId, 1024>& listOut, const CActor& actor,
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CAABox& aabb) const {
|
|
|
|
x874_sortedListManager->BuildNearList(listOut, actor, aabb);
|
2016-04-17 05:35:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 05:53:04 +00:00
|
|
|
void CStateManager::BuildNearList(rstl::reserved_vector<TUniqueId, 1024>& listOut, const zeus::CAABox& aabb,
|
2018-12-08 05:30:43 +00:00
|
|
|
const CMaterialFilter& filter, const CActor* actor) const {
|
|
|
|
x874_sortedListManager->BuildNearList(listOut, aabb, filter, actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::UpdateActorInSortedLists(CActor& act) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!act.GetUseInSortedLists() || !act.xe4_27_notInSortedLists) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
const std::optional<zeus::CAABox> aabb = CalculateObjectBounds(act);
|
|
|
|
const bool actorInLists = x874_sortedListManager->ActorInLists(&act);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (actorInLists || aabb) {
|
|
|
|
act.xe4_27_notInSortedLists = false;
|
|
|
|
if (actorInLists) {
|
|
|
|
if (!act.GetActive() || !aabb) {
|
|
|
|
x874_sortedListManager->Remove(&act);
|
|
|
|
} else {
|
|
|
|
x874_sortedListManager->Move(&act, *aabb);
|
|
|
|
}
|
|
|
|
} else if (act.GetActive() && aabb) {
|
|
|
|
x874_sortedListManager->Insert(&act, *aabb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::UpdateSortedLists() {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!x850_world) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (CEntity* actor : GetActorObjectList()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateActorInSortedLists(static_cast<CActor&>(*actor));
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
std::optional<zeus::CAABox> CStateManager::CalculateObjectBounds(const CActor& actor) {
|
|
|
|
std::optional<zeus::CAABox> bounds = actor.GetTouchBounds();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (bounds) {
|
|
|
|
zeus::CAABox aabb;
|
|
|
|
aabb.accumulateBounds(bounds->min);
|
|
|
|
aabb.accumulateBounds(bounds->max);
|
|
|
|
if (TCastToConstPtr<CPhysicsActor> physAct = actor) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const zeus::CAABox physAabb = physAct->GetBoundingBox();
|
2018-12-08 05:30:43 +00:00
|
|
|
aabb.accumulateBounds(physAabb.min);
|
|
|
|
aabb.accumulateBounds(physAabb.max);
|
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
return aabb;
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToConstPtr<CPhysicsActor> physAct = actor) {
|
|
|
|
return physAct->GetBoundingBox();
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-09 21:32:12 +00:00
|
|
|
return std::nullopt;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CStateManager::AddObject(CEntity& ent) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ent.GetEditorId() != kInvalidEditorId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x890_scriptIdMap.insert(std::make_pair(ent.GetEditorId(), ent.GetUniqueId()));
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
for (auto& list : x808_objLists) {
|
2018-12-08 05:30:43 +00:00
|
|
|
list->AddObject(ent);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (ent.GetAreaIdAlways() == kInvalidAreaId && x84c_player && ent.GetUniqueId() != x84c_player->GetUniqueId()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ent.x4_areaId = x84c_player->GetAreaIdAlways();
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (ent.GetAreaIdAlways() != kInvalidAreaId) {
|
|
|
|
CGameArea* area = x850_world->GetArea(ent.GetAreaIdAlways());
|
2020-05-09 21:32:12 +00:00
|
|
|
if (area->IsPostConstructed()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
area->GetAreaObjects()->AddObject(ent);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (const TCastToPtr<CActor> act = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateActorInSortedLists(*act.GetPtr());
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
ent.AcceptScriptMsg(EScriptObjectMessage::Registered, kInvalidUniqueId, *this);
|
2017-11-26 03:04:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (ent.GetAreaIdAlways() != kInvalidAreaId && x850_world) {
|
|
|
|
CGameArea* area = x850_world->GetArea(ent.GetAreaIdAlways());
|
2020-05-09 21:32:12 +00:00
|
|
|
if (area->IsValidated()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
SendScriptMsg(&ent, kInvalidUniqueId, EScriptObjectMessage::InitializedInArea);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-13 03:20:49 +00:00
|
|
|
|
2020-05-09 21:32:12 +00:00
|
|
|
if (sm_logScripting != nullptr && sm_logScripting->toBoolean()) {
|
2020-04-11 22:51:39 +00:00
|
|
|
LogModule.report(logvisor::Info, FMT_STRING("Added '{}'"), ent.GetName());
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::AddObject(CEntity* ent) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (!ent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddObject(*ent);
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CRayCastResult CStateManager::RayStaticIntersection(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
|
|
|
|
float length, const CMaterialFilter& filter) const {
|
|
|
|
return CGameCollision::RayStaticIntersection(*this, pos, dir, length, filter);
|
2016-04-17 05:35:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 22:36:18 +00:00
|
|
|
CRayCastResult CStateManager::RayWorldIntersection(TUniqueId& idOut, const zeus::CVector3f& pos,
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& dir, float length,
|
|
|
|
const CMaterialFilter& filter,
|
|
|
|
const rstl::reserved_vector<TUniqueId, 1024>& list) const {
|
|
|
|
return CGameCollision::RayWorldIntersection(*this, idOut, pos, dir, length, filter, list);
|
2017-03-31 19:51:40 +00:00
|
|
|
}
|
2016-04-17 05:35:32 +00:00
|
|
|
|
2018-12-13 07:39:16 +00:00
|
|
|
zeus::CVector3f CStateManager::Random2f(float scaleMin, float scaleMax) {
|
|
|
|
zeus::CVector3f ret(x900_activeRandom->Float() - 0.5f, x900_activeRandom->Float() - 0.5f, 0.f);
|
2020-05-09 21:32:12 +00:00
|
|
|
if (std::fabs(ret.x()) < 0.001f) {
|
2018-12-13 07:39:16 +00:00
|
|
|
ret.x() = 0.001f;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-13 07:39:16 +00:00
|
|
|
ret.normalize();
|
|
|
|
return ret * ((scaleMax - scaleMin) * x900_activeRandom->Float() + scaleMin);
|
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::UpdateObjectInLists(CEntity& ent) {
|
|
|
|
for (auto& list : x808_objLists) {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (list->GetValidObjectById(ent.GetUniqueId())) {
|
|
|
|
if (!list->IsQualified(ent)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
list->RemoveObject(ent.GetUniqueId());
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!list->GetValidObjectById(ent.GetUniqueId())) {
|
2018-12-08 05:30:43 +00:00
|
|
|
list->AddObject(ent);
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TUniqueId CStateManager::AllocateUniqueId() {
|
|
|
|
const s16 lastIndex = x0_nextFreeIndex;
|
|
|
|
s16 ourIndex;
|
|
|
|
do {
|
|
|
|
ourIndex = x0_nextFreeIndex;
|
|
|
|
x0_nextFreeIndex = (x0_nextFreeIndex + 1) & 0x3ff;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x0_nextFreeIndex == lastIndex) {
|
2020-04-11 22:51:39 +00:00
|
|
|
LogModule.report(logvisor::Fatal, FMT_STRING("Object List Full!"));
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} while (GetAllObjectList().GetObjectByIndex(ourIndex) != nullptr);
|
2017-01-15 03:59:37 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_idArr[ourIndex] = (x8_idArr[ourIndex] + 1) & 0x3f;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (TUniqueId(ourIndex, x8_idArr[ourIndex]) == kInvalidUniqueId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_idArr[ourIndex] = 0;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2017-01-15 03:59:37 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return TUniqueId(ourIndex, x8_idArr[ourIndex]);
|
2015-08-19 05:48:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::DeferStateTransition(EStateManagerTransition t) {
|
|
|
|
if (t == EStateManagerTransition::InGame) {
|
|
|
|
if (xf90_deferredTransition != EStateManagerTransition::InGame) {
|
|
|
|
x850_world->SetLoadPauseState(false);
|
|
|
|
xf90_deferredTransition = EStateManagerTransition::InGame;
|
2017-02-18 02:19:50 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
if (xf90_deferredTransition == EStateManagerTransition::InGame) {
|
|
|
|
x850_world->SetLoadPauseState(true);
|
|
|
|
xf90_deferredTransition = t;
|
2017-02-18 02:19:50 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-02-18 02:19:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CStateManager::CanShowMapScreen() const {
|
|
|
|
const CHintOptions::SHintState* curDispHint = g_GameState->HintOptions().GetCurrentDisplayedHint();
|
2020-05-09 21:32:12 +00:00
|
|
|
if (curDispHint == nullptr || curDispHint->CanContinue()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2017-02-18 02:19:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::pair<u32, u32> CStateManager::CalculateScanCompletionRate() const {
|
|
|
|
u32 num = 0;
|
|
|
|
u32 denom = 0;
|
|
|
|
int idx = 0;
|
|
|
|
for (const std::pair<CAssetId, float>& scan : x8b8_playerState->GetScanTimes()) {
|
2020-05-09 21:32:12 +00:00
|
|
|
const auto category = g_MemoryCardSys->GetScanStates()[idx++].second;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (category != CSaveWorld::EScanCategory::None && category != CSaveWorld::EScanCategory::Research) {
|
|
|
|
++denom;
|
2020-05-09 21:32:12 +00:00
|
|
|
if (scan.second == 1.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
++num;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2016-12-20 21:51:50 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return {num, denom};
|
2016-12-20 21:51:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CStateManager::SetBossParams(TUniqueId bossId, float maxEnergy, u32 stringIdx) {
|
|
|
|
xf18_bossId = bossId;
|
|
|
|
xf1c_totalBossEnergy = maxEnergy;
|
2020-04-17 12:53:22 +00:00
|
|
|
xf20_bossStringIdx = stringIdx - (g_Main->IsUSA() && !g_Main->IsTrilogy() ? 0 : 6);
|
2017-04-04 05:48:13 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CStateManager::IntegrateVisorFog(float f) const {
|
2020-05-09 21:32:12 +00:00
|
|
|
if (x8b8_playerState->GetActiveVisor(*this) == CPlayerState::EPlayerVisor::Scan) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return (1.f - x8b8_playerState->GetVisorTransitionFactor()) * f;
|
2020-05-09 21:32:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return f;
|
2017-08-13 07:56:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 05:53:04 +00:00
|
|
|
float CStateManager::g_EscapeShakeCountdown;
|
|
|
|
bool CStateManager::g_EscapeShakeCountdownInit = false;
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|