Skip to content

Commit

Permalink
Fixed headers causing "use of undefined Actor" all around. 🔧
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ohlidalp committed Oct 23, 2023
1 parent d3e9095 commit 6f12b55
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 20 deletions.
5 changes: 5 additions & 0 deletions source/main/ForwardDeclarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

#include "RefCountingObjectPtr.h"

#include <limits>
#include <vector>

#pragma once

namespace RoR
Expand Down Expand Up @@ -177,6 +180,8 @@ namespace RoR
typedef RefCountingObjectPtr<Terrain> TerrainPtr;
typedef RefCountingObjectPtr<VehicleAI> VehicleAIPtr;

typedef std::vector<ActorPtr> ActorPtrVec;

namespace GUI
{
class ConsoleView;
Expand Down
22 changes: 22 additions & 0 deletions source/main/GameContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -766,6 +786,8 @@ void GameContext::OnLoaderGuiApply(LoaderType type, CacheEntryPtr entry, std::st
}
}

void GameContext::SetPrevPlayerActor(ActorPtr actor) { m_prev_player_actor = actor; }

// --------------------------------
// Characters

Expand Down
16 changes: 9 additions & 7 deletions source/main/GameContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#pragma once

#include "Actor.h"
#include "ActorManager.h"
#include "CacheSystem.h"
#include "CharacterFactory.h"
Expand Down Expand Up @@ -98,6 +97,9 @@ class GameContext
friend class AppContext;
public:

GameContext();
~GameContext();

/// @name Message queue
/// @{

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion source/main/audio/SoundScriptManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#pragma once

#include "Actor.h"
#include "AngelScriptBindings.h"
#include "Application.h"
#include "RefCountingObjectPtr.h"
Expand Down
2 changes: 2 additions & 0 deletions source/main/gameplay/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ void Character::SetActorCoupling(bool enabled, ActorPtr actor)
#endif // USE_SOCKETW
}

ActorPtr Character::GetActorCoupling() { return m_actor_coupling; }

// --------------------------------
// GfxCharacter

Expand Down
3 changes: 1 addition & 2 deletions source/main/gameplay/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#pragma once

#include "Actor.h"
#include "ForwardDeclarations.h"
#include "SurveyMapEntity.h"

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions source/main/gameplay/CharacterFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "CharacterFactory.h"

#include "Actor.h"
#include "Application.h"
#include "Character.h"
#include "GfxScene.h"
Expand Down
1 change: 0 additions & 1 deletion source/main/gameplay/EngineSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#pragma once

#include "Application.h"
#include "Actor.h"

namespace RoR {

Expand Down
1 change: 1 addition & 0 deletions source/main/gameplay/RepairMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "RepairMode.h"

#include "Actor.h"
#include "GameContext.h"
#include "InputEngine.h"

Expand Down
1 change: 0 additions & 1 deletion source/main/gameplay/SceneMouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include "Application.h"
#include "SimData.h"
#include <OIS.h>

#include <OIS.h>
#include <Ogre.h>
Expand Down
2 changes: 0 additions & 2 deletions source/main/gfx/EnvironmentMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions source/main/gfx/GfxActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions source/main/gfx/GfxActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#pragma once

#include "Actor.h"
#include "AutoPilot.h"
#include "Differentials.h"
#include "ForwardDeclarations.h"
Expand Down Expand Up @@ -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 ;
Expand Down
3 changes: 3 additions & 0 deletions source/main/gfx/SimBuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions source/main/gui/GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions source/main/gui/panels/GUI_FlexbodyDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "GUI_FlexbodyDebug.h"

#include "Actor.h"
#include "Application.h"
#include "SimData.h"
#include "Collisions.h"
Expand Down
2 changes: 2 additions & 0 deletions source/main/physics/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions source/main/physics/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ namespace RoR {
/// @addtogroup Physics
/// @{

typedef std::vector<ActorPtr> 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<Actor>
Expand Down
1 change: 0 additions & 1 deletion source/main/physics/ActorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#pragma once

#include "Actor.h"
#include "Application.h"
#include "SimData.h"
#include "CmdKeyInertia.h"
Expand Down
2 changes: 1 addition & 1 deletion source/main/physics/SimData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions source/main/scripting/ScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions source/main/scripting/ScriptEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions source/main/terrain/Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "Terrain.h"

#include "Actor.h"
#include "ActorManager.h"
#include "CacheSystem.h"
#include "Collisions.h"
Expand Down

0 comments on commit 6f12b55

Please sign in to comment.