From 6f12b55c1e088c742381988ce8731315387cf5b6 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Tue, 24 Oct 2023 00:22:39 +0200 Subject: [PATCH] Fixed headers causing "use of undefined `Actor`" all around. :wrench: Headers should make do with forward decls and shouldn't `#include Actor.h` at all. This means no code (function body or even autogenerated ctor/dtor) which manipulates ActorPtr should be in header. --- source/main/ForwardDeclarations.h | 5 +++++ source/main/GameContext.cpp | 22 ++++++++++++++++++++ source/main/GameContext.h | 16 +++++++------- source/main/audio/SoundScriptManager.h | 1 - source/main/gameplay/Character.cpp | 2 ++ source/main/gameplay/Character.h | 3 +-- source/main/gameplay/CharacterFactory.cpp | 1 + source/main/gameplay/EngineSim.h | 1 - source/main/gameplay/RepairMode.cpp | 1 + source/main/gameplay/SceneMouse.h | 1 - source/main/gfx/EnvironmentMap.h | 2 -- source/main/gfx/GfxActor.cpp | 5 +++++ source/main/gfx/GfxActor.h | 3 +-- source/main/gfx/SimBuffers.h | 3 +++ source/main/gui/GUIManager.cpp | 2 ++ source/main/gui/panels/GUI_FlexbodyDebug.cpp | 1 + source/main/physics/Actor.cpp | 2 ++ source/main/physics/Actor.h | 2 -- source/main/physics/ActorManager.h | 1 - source/main/physics/SimData.h | 2 +- source/main/scripting/ScriptEngine.cpp | 10 +++++++++ source/main/scripting/ScriptEngine.h | 3 +++ source/main/terrain/Terrain.cpp | 1 + 23 files changed, 70 insertions(+), 20 deletions(-) diff --git a/source/main/ForwardDeclarations.h b/source/main/ForwardDeclarations.h index f3cdb5df2c..7dcd03cdf2 100644 --- a/source/main/ForwardDeclarations.h +++ b/source/main/ForwardDeclarations.h @@ -27,6 +27,9 @@ #include "RefCountingObjectPtr.h" +#include +#include + #pragma once namespace RoR @@ -177,6 +180,8 @@ namespace RoR typedef RefCountingObjectPtr TerrainPtr; typedef RefCountingObjectPtr VehicleAIPtr; + typedef std::vector ActorPtrVec; + namespace GUI { class ConsoleView; diff --git a/source/main/GameContext.cpp b/source/main/GameContext.cpp index 29d341a8a1..351d926884 100644 --- a/source/main/GameContext.cpp +++ b/source/main/GameContext.cpp @@ -49,6 +49,26 @@ using namespace RoR; +GameContextSB::GameContextSB() // Declared in 'gfx/SimBuffers.h' +{ + // Constructs `ActorPtr` - doesn't compile without `#include Actor.h` - not pretty if in header (even if auto-generated by C++). +} + +GameContextSB::~GameContextSB() // Declared in 'gfx/SimBuffers.h' +{ + // Destructs `ActorPtr` - doesn't compile without `#include Actor.h` - not pretty if in header (even if auto-generated by C++). +} + +GameContext::GameContext() +{ + // Constructs `ActorPtr` - doesn't compile without `#include Actor.h` - not pretty if in header (even if auto-generated by C++). +} + +GameContext::~GameContext() +{ + // Destructs `ActorPtr` - doesn't compile without `#include Actor.h` - not pretty if in header (even if auto-generated by C++). +} + // -------------------------------- // Message queue @@ -766,6 +786,8 @@ void GameContext::OnLoaderGuiApply(LoaderType type, CacheEntryPtr entry, std::st } } +void GameContext::SetPrevPlayerActor(ActorPtr actor) { m_prev_player_actor = actor; } + // -------------------------------- // Characters diff --git a/source/main/GameContext.h b/source/main/GameContext.h index 603376468f..e991f255a7 100644 --- a/source/main/GameContext.h +++ b/source/main/GameContext.h @@ -25,7 +25,6 @@ #pragma once -#include "Actor.h" #include "ActorManager.h" #include "CacheSystem.h" #include "CharacterFactory.h" @@ -98,6 +97,9 @@ class GameContext friend class AppContext; public: + GameContext(); + ~GameContext(); + /// @name Message queue /// @{ @@ -132,7 +134,7 @@ class GameContext const ActorPtr& GetPlayerActor() { return m_player_actor; } const ActorPtr& GetPrevPlayerActor() { return m_prev_player_actor; } const ActorPtr& GetLastSpawnedActor() { return m_last_spawned_actor; } //!< Last actor spawned by user and still alive. - void SetPrevPlayerActor(ActorPtr actor) { m_prev_player_actor = actor; } + void SetPrevPlayerActor(ActorPtr actor); void ChangePlayerActor(ActorPtr actor); void ShowLoaderGUI(int type, const Ogre::String& instance, const Ogre::String& box); @@ -188,12 +190,12 @@ class GameContext // Actors (physics and netcode) ActorManager m_actor_manager; - ActorPtr m_player_actor = nullptr; //!< Actor (vehicle or machine) mounted and controlled by player - ActorPtr m_prev_player_actor = nullptr; //!< Previous actor (vehicle or machine) mounted and controlled by player - ActorPtr m_last_spawned_actor = nullptr; //!< Last actor spawned by user and still alive. + ActorPtr m_player_actor; //!< Actor (vehicle or machine) mounted and controlled by player + ActorPtr m_prev_player_actor; //!< Previous actor (vehicle or machine) mounted and controlled by player + ActorPtr m_last_spawned_actor; //!< Last actor spawned by user and still alive. - CacheEntryPtr m_last_cache_selection = nullptr; //!< Vehicle/load - CacheEntryPtr m_last_skin_selection = nullptr; + CacheEntryPtr m_last_cache_selection; //!< Vehicle/load + CacheEntryPtr m_last_skin_selection; Ogre::String m_last_section_config; ActorSpawnRequest m_current_selection; //!< Context of the loader UI CacheEntryPtr m_dummy_cache_selection; diff --git a/source/main/audio/SoundScriptManager.h b/source/main/audio/SoundScriptManager.h index c596ac37c2..fe557fe5ab 100644 --- a/source/main/audio/SoundScriptManager.h +++ b/source/main/audio/SoundScriptManager.h @@ -23,7 +23,6 @@ #pragma once -#include "Actor.h" #include "AngelScriptBindings.h" #include "Application.h" #include "RefCountingObjectPtr.h" diff --git a/source/main/gameplay/Character.cpp b/source/main/gameplay/Character.cpp index 166599230d..087dd6c61a 100644 --- a/source/main/gameplay/Character.cpp +++ b/source/main/gameplay/Character.cpp @@ -544,6 +544,8 @@ void Character::SetActorCoupling(bool enabled, ActorPtr actor) #endif // USE_SOCKETW } +ActorPtr Character::GetActorCoupling() { return m_actor_coupling; } + // -------------------------------- // GfxCharacter diff --git a/source/main/gameplay/Character.h b/source/main/gameplay/Character.h index 61873e1987..253c27cace 100644 --- a/source/main/gameplay/Character.h +++ b/source/main/gameplay/Character.h @@ -21,7 +21,6 @@ #pragma once -#include "Actor.h" #include "ForwardDeclarations.h" #include "SurveyMapEntity.h" @@ -53,7 +52,7 @@ class Character std::string const & GetAnimName() const { return m_anim_name; } float GetAnimTime() const { return m_anim_time; } Ogre::Radian getRotation() const { return m_character_rotation; } - ActorPtr GetActorCoupling() { return m_actor_coupling; } + ActorPtr GetActorCoupling(); void setColour(int color) { this->m_color_number = color; } Ogre::Vector3 getPosition(); void setPosition(Ogre::Vector3 position); diff --git a/source/main/gameplay/CharacterFactory.cpp b/source/main/gameplay/CharacterFactory.cpp index 78a2e60665..05c980685d 100644 --- a/source/main/gameplay/CharacterFactory.cpp +++ b/source/main/gameplay/CharacterFactory.cpp @@ -21,6 +21,7 @@ #include "CharacterFactory.h" +#include "Actor.h" #include "Application.h" #include "Character.h" #include "GfxScene.h" diff --git a/source/main/gameplay/EngineSim.h b/source/main/gameplay/EngineSim.h index aa5aee020d..2fe04c68e0 100644 --- a/source/main/gameplay/EngineSim.h +++ b/source/main/gameplay/EngineSim.h @@ -22,7 +22,6 @@ #pragma once #include "Application.h" -#include "Actor.h" namespace RoR { diff --git a/source/main/gameplay/RepairMode.cpp b/source/main/gameplay/RepairMode.cpp index 65b9f5882b..b7552fcad0 100644 --- a/source/main/gameplay/RepairMode.cpp +++ b/source/main/gameplay/RepairMode.cpp @@ -21,6 +21,7 @@ #include "RepairMode.h" +#include "Actor.h" #include "GameContext.h" #include "InputEngine.h" diff --git a/source/main/gameplay/SceneMouse.h b/source/main/gameplay/SceneMouse.h index cacdc95299..f246823c07 100644 --- a/source/main/gameplay/SceneMouse.h +++ b/source/main/gameplay/SceneMouse.h @@ -28,7 +28,6 @@ #include "Application.h" #include "SimData.h" -#include #include #include diff --git a/source/main/gfx/EnvironmentMap.h b/source/main/gfx/EnvironmentMap.h index 64e1122267..b9a3f8f7c3 100644 --- a/source/main/gfx/EnvironmentMap.h +++ b/source/main/gfx/EnvironmentMap.h @@ -44,8 +44,6 @@ class GfxEnvmap static const unsigned int NUM_FACES = 6; - void InitEnvMap(Ogre::Vector3 center); - Ogre::Camera* m_cameras[NUM_FACES]; Ogre::RenderTarget* m_render_targets[NUM_FACES]; Ogre::TexturePtr m_rtt_texture; diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index d9f3e5e329..e491dc7fbf 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -194,6 +194,11 @@ RoR::GfxActor::~GfxActor() } } +ActorPtr RoR::GfxActor::GetActor() +{ + return m_actor; +} + void RoR::GfxActor::SetMaterialFlareOn(int flare_index, bool state_on) { for (FlareMaterial& entry: m_flare_materials) diff --git a/source/main/gfx/GfxActor.h b/source/main/gfx/GfxActor.h index 734df462e1..b748f8bd25 100644 --- a/source/main/gfx/GfxActor.h +++ b/source/main/gfx/GfxActor.h @@ -26,7 +26,6 @@ #pragma once -#include "Actor.h" #include "AutoPilot.h" #include "Differentials.h" #include "ForwardDeclarations.h" @@ -138,7 +137,7 @@ class GfxActor VideoCamState GetVideoCamState() const { return m_vidcam_state; } DebugViewType GetDebugView() const { return m_debug_view; } Ogre::String GetResourceGroup() { return m_custom_resource_group; } - ActorPtr GetActor() { return m_actor; } // Watch out for multithreading with this! + ActorPtr GetActor(); // Watch out for multithreading with this! Ogre::TexturePtr GetHelpTex() { return m_help_tex; } Ogre::MaterialPtr GetHelpMat() { return m_help_mat; } int FetchNumBeams() const ; diff --git a/source/main/gfx/SimBuffers.h b/source/main/gfx/SimBuffers.h index 2bd5fa46bb..099753067f 100644 --- a/source/main/gfx/SimBuffers.h +++ b/source/main/gfx/SimBuffers.h @@ -194,6 +194,9 @@ struct ActorSB struct GameContextSB { + GameContextSB(); // Defined in GameContext.cpp + ~GameContextSB(); // Defined in GameContext.cpp + ActorPtr simbuf_player_actor; Ogre::Vector3 simbuf_character_pos = Ogre::Vector3::ZERO; bool simbuf_sim_paused = false; diff --git a/source/main/gui/GUIManager.cpp b/source/main/gui/GUIManager.cpp index 4971b68dc5..91eaa59d56 100644 --- a/source/main/gui/GUIManager.cpp +++ b/source/main/gui/GUIManager.cpp @@ -24,11 +24,13 @@ #include "GUIManager.h" +#include "Actor.h" #include "AppContext.h" #include "ActorManager.h" #include "CameraManager.h" #include "ContentManager.h" #include "GameContext.h" +#include "GfxActor.h" #include "GfxScene.h" #include "GUIUtils.h" #include "InputEngine.h" diff --git a/source/main/gui/panels/GUI_FlexbodyDebug.cpp b/source/main/gui/panels/GUI_FlexbodyDebug.cpp index 2283708e31..8aa4898942 100644 --- a/source/main/gui/panels/GUI_FlexbodyDebug.cpp +++ b/source/main/gui/panels/GUI_FlexbodyDebug.cpp @@ -22,6 +22,7 @@ #include "GUI_FlexbodyDebug.h" +#include "Actor.h" #include "Application.h" #include "SimData.h" #include "Collisions.h" diff --git a/source/main/physics/Actor.cpp b/source/main/physics/Actor.cpp index b980047521..b2220edde9 100644 --- a/source/main/physics/Actor.cpp +++ b/source/main/physics/Actor.cpp @@ -77,6 +77,8 @@ using namespace RoR; static const Ogre::Vector3 BOUNDING_BOX_PADDING(0.05f, 0.05f, 0.05f); +beam_t::beam_t() { memset(this, 0, sizeof(beam_t)); } + Actor::~Actor() { // This class must be handled by `ActorManager::DeleteActorInternal()` (use MSG_SIM_DELETE_ACTOR_REQUESTED) which performs disposal. diff --git a/source/main/physics/Actor.h b/source/main/physics/Actor.h index 99459d8fd9..b42afd77e2 100644 --- a/source/main/physics/Actor.h +++ b/source/main/physics/Actor.h @@ -42,8 +42,6 @@ namespace RoR { /// @addtogroup Physics /// @{ -typedef std::vector ActorPtrVec; - /// Softbody object; can be anything from soda can to a space shuttle /// Former name: `Beam` (that's why scripting uses `BeamClass`) class Actor : public RefCountingObject diff --git a/source/main/physics/ActorManager.h b/source/main/physics/ActorManager.h index c687af630b..d7913a47c3 100644 --- a/source/main/physics/ActorManager.h +++ b/source/main/physics/ActorManager.h @@ -24,7 +24,6 @@ #pragma once -#include "Actor.h" #include "Application.h" #include "SimData.h" #include "CmdKeyInertia.h" diff --git a/source/main/physics/SimData.h b/source/main/physics/SimData.h index af4b2d6035..56ef49c7cc 100644 --- a/source/main/physics/SimData.h +++ b/source/main/physics/SimData.h @@ -340,7 +340,7 @@ struct node_t /// Simulation: An edge in the softbody structure struct beam_t { - beam_t() { memset(this, 0, sizeof(beam_t)); } + beam_t(); // Defined in Actor.cpp node_t* p1; node_t* p2; diff --git a/source/main/scripting/ScriptEngine.cpp b/source/main/scripting/ScriptEngine.cpp index 4c77af6509..cd4595f24a 100644 --- a/source/main/scripting/ScriptEngine.cpp +++ b/source/main/scripting/ScriptEngine.cpp @@ -74,6 +74,16 @@ const char* RoR::ScriptCategoryToString(ScriptCategory c) } } +ScriptUnit::ScriptUnit() +{ + // Constructs `ActorPtr` - doesn't compile without `#include Actor.h` - not pretty if in header (even if auto-generated by C++). +} + +ScriptUnit::~ScriptUnit() +{ + // Destructs `ActorPtr` - doesn't compile without `#include Actor.h` - not pretty if in header (even if auto-generated by C++). +} + // some hacky functions void logString(const std::string &str) diff --git a/source/main/scripting/ScriptEngine.h b/source/main/scripting/ScriptEngine.h index 690119e253..2fccca36d6 100644 --- a/source/main/scripting/ScriptEngine.h +++ b/source/main/scripting/ScriptEngine.h @@ -68,6 +68,9 @@ const char* ScriptCategoryToString(ScriptCategory c); /// Represents a loaded script and all associated resources/handles. struct ScriptUnit { + ScriptUnit(); + ~ScriptUnit(); + ScriptUnitId_t uniqueId = SCRIPTUNITID_INVALID; ScriptCategory scriptCategory = ScriptCategory::INVALID; unsigned int eventMask = 0; //!< filter mask for script events diff --git a/source/main/terrain/Terrain.cpp b/source/main/terrain/Terrain.cpp index 4d5e408eda..127d672046 100644 --- a/source/main/terrain/Terrain.cpp +++ b/source/main/terrain/Terrain.cpp @@ -21,6 +21,7 @@ #include "Terrain.h" +#include "Actor.h" #include "ActorManager.h" #include "CacheSystem.h" #include "Collisions.h"