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 24, 2023
1 parent d3e9095 commit 7a0fefa
Show file tree
Hide file tree
Showing 27 changed files with 306 additions and 85 deletions.
6 changes: 3 additions & 3 deletions source/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ set(SOURCE_FILES
gfx/DustPool.{h,cpp}
gfx/EnvironmentMap.{h,cpp}
gfx/GfxActor.{h,cpp}
gfx/GfxData.h
gfx/GfxData.{h,cpp}
gfx/GfxScene.{h,cpp}
gfx/HydraxWater.{h,cpp}
gfx/IWater.h
gfx/MovableText.{h,cpp}
gfx/Renderdash.{h,cpp}
gfx/ShadowManager.{h,cpp}
gfx/SimBuffers.h
gfx/SimBuffers.{h,cpp}
gfx/Skidmark.{h,cpp}
gfx/SkyManager.{h,cpp}
gfx/SkyXManager.{h,cpp}
Expand Down Expand Up @@ -156,7 +156,7 @@ set(SOURCE_FILES
physics/Differentials.{h,cpp}
physics/Savegame.cpp
physics/SimConstants.h
physics/SimData.h
physics/SimData.{h,cpp}
physics/SlideNode.{h,cpp}
physics/air/AeroEngine.h
physics/air/AirBrake.{h,cpp}
Expand Down
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
12 changes: 12 additions & 0 deletions source/main/GameContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@

using namespace RoR;

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 +776,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
36 changes: 36 additions & 0 deletions source/main/gfx/GfxData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
This source file is part of Rigs of Rods
Copyright 2005-2012 Pierre-Michel Ricordel
Copyright 2007-2012 Thomas Fischer
Copyright 2013-2023 Petr Ohlidal
For more information, see http://www.rigsofrods.org/
Rigs of Rods is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3, as
published by the Free Software Foundation.
Rigs of Rods is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
*/

#include "SimBuffers.h"

#include "Actor.h"

using namespace RoR;

BeamGfx::BeamGfx()
{
// Constructs `ActorPtr` - doesn't compile without `#include Actor.h` - not pretty if in header (even if auto-generated by C++).
}

BeamGfx::~BeamGfx()
{
// Destructs `ActorPtr` - doesn't compile without `#include Actor.h` - not pretty if in header (even if auto-generated by C++).
}
5 changes: 4 additions & 1 deletion source/main/gfx/GfxData.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,17 @@ struct NodeGfx
/// Visuals of softbody beam (`beam_t` struct); Partially updated along with SimBuffer
struct BeamGfx
{
BeamGfx();
~BeamGfx();

// We don't keep pointer to the Ogre::Entity - we rely on the SceneNode keeping it attached all the time.
Ogre::SceneNode* rod_scenenode = nullptr;
uint16_t rod_beam_index = 0;
uint16_t rod_diameter_mm = 0; //!< Diameter in millimeters

NodeNum_t rod_node1 = NODENUM_INVALID; //!< Node index - may change during simulation!
NodeNum_t rod_node2 = NODENUM_INVALID; //!< Node index - may change during simulation!
ActorPtr rod_target_actor = nullptr;
ActorPtr rod_target_actor;
bool rod_is_visible = false;
};

Expand Down
36 changes: 36 additions & 0 deletions source/main/gfx/SimBuffers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
This source file is part of Rigs of Rods
Copyright 2005-2012 Pierre-Michel Ricordel
Copyright 2007-2012 Thomas Fischer
Copyright 2013-2023 Petr Ohlidal
For more information, see http://www.rigsofrods.org/
Rigs of Rods is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3, as
published by the Free Software Foundation.
Rigs of Rods is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
*/

#include "SimBuffers.h"

#include "Actor.h"

using namespace RoR;

GameContextSB::GameContextSB()
{
// Constructs `ActorPtr` - doesn't compile without `#include Actor.h` - not pretty if in header (even if auto-generated by C++).
}

GameContextSB::~GameContextSB()
{
// Destructs `ActorPtr` - doesn't compile without `#include Actor.h` - not pretty if in header (even if auto-generated by C++).
}
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();
~GameContextSB();

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: 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
Loading

0 comments on commit 7a0fefa

Please sign in to comment.