RigsofRods
Soft-body Physics Simulation
GameContext.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
25 
26 #pragma once
27 
28 #include "ActorManager.h"
29 #include "CacheSystem.h"
30 #include "CharacterFactory.h"
31 #include "RaceSystem.h"
32 #include "RepairMode.h"
33 #include "SceneMouse.h"
34 #include "SimData.h"
35 #include "Terrain.h"
36 
37 #include <list>
38 #include <mutex>
39 #include <queue>
40 #include <string>
41 
42 namespace RoR {
43 
46 
49 
51 struct Message
52 {
53  Message(MsgType _type): type(_type) {}
54  Message(MsgType _type, std::string const& _desc): type(_type), description(_desc) {}
55  Message(MsgType _type, void* _data): type(_type), payload(_data) {}
56 
58  std::string description;
59  void* payload = nullptr;
60  std::vector<Message> chain;
61 };
62 
63 typedef std::queue < Message, std::list<Message>> GameMsgQueue;
64 
66 
94 
96 {
97  friend class AppContext;
98 public:
99 
100  GameContext();
101  ~GameContext();
102 
105 
106  void PushMessage(Message m);
107  void ChainMessage(Message m);
108  bool HasMessages();
110 
114 
115  bool LoadTerrain(std::string const& filename_part);
116  void UnloadTerrain();
117  const TerrainPtr& GetTerrain() { return m_terrain; }
118 
122 
125  void DeleteActor(ActorPtr actor);
126  void UpdateActors();
130  ActorPtr FindActorByCollisionBox(std::string const & ev_src_instance_name, std::string const & box_name);
131  void RespawnLastActor();
132  void SpawnPreselectedActor(std::string const& preset_vehicle, std::string const& preset_veh_config);
133 
136  const ActorPtr& GetLastSpawnedActor() { return m_last_spawned_actor; }
137  void SetPrevPlayerActor(ActorPtr actor);
138  void ChangePlayerActor(ActorPtr actor);
139 
140  void ShowLoaderGUI(int type, const Ogre::String& instance, const Ogre::String& box);
141  void OnLoaderGuiCancel();
142  void OnLoaderGuiApply(RoR::LoaderType type, CacheEntryPtr entry, std::string sectionconfig);
143 
147 
148  void CreatePlayerCharacter();
149  Character* GetPlayerCharacter();
151 
155  // (defined in Savegame.cpp)
156 
157  void LoadScene(std::string const& filename);
158  void SaveScene(std::string const& filename);
159  std::string GetQuicksaveFilename();
160  std::string ExtractSceneName(std::string const& filename);
161  std::string ExtractSceneTerrain(std::string const& filename);
162  void HandleSavegameHotkeys();
163 
167 
171  void TeleportPlayer(float x, float z);
173  void UpdateSimInputEvents(float dt);
174  void UpdateSkyInputEvents(float dt);
175  void UpdateCommonInputEvents(float dt);
176  void UpdateAirplaneInputEvents(float dt);
177  void UpdateBoatInputEvents(float dt);
178  void UpdateTruckInputEvents(float dt);
179 
181 
182 private:
183  // Message queue
186  std::mutex m_msg_mutex;
187 
188  // Terrain
190 
191  // Actors (physics and netcode)
196 
200  Ogre::String m_last_section_config;
203 
204  // Characters (simplified physics and netcode)
206 
207  // Gameplay feats (misc.)
211  Ogre::Timer m_timer;
212  Ogre::Vector3 prev_pos = Ogre::Vector3::ZERO;
213 };
214 
216 
217 } // namespace RoR
RoR::GameContext::ExtractSceneTerrain
std::string ExtractSceneTerrain(std::string const &filename)
Returns terrain filename.
Definition: Savegame.cpp:86
RaceSystem.h
Counterpart to Neorej16's race system script.
RoR::GameContext::ModifyActor
void ModifyActor(ActorModifyRequest &rq)
Definition: GameContext.cpp:357
RoR::Message::Message
Message(MsgType _type, std::string const &_desc)
Definition: GameContext.h:54
RoR::SceneMouse
Definition: SceneMouse.h:37
RoR::GameContext::m_last_skin_selection
CacheEntryPtr m_last_skin_selection
Definition: GameContext.h:198
RoR::CacheEntryPtr
RefCountingObjectPtr< CacheEntry > CacheEntryPtr
Definition: ForwardDeclarations.h:197
RoR::GameContext::m_character_factory
CharacterFactory m_character_factory
Definition: GameContext.h:205
RoR::RaceSystem
Definition: RaceSystem.h:31
z
float z
Definition: (ValueTypes) quaternion.h:7
RoR::GameContext::m_last_section_config
Ogre::String m_last_section_config
Definition: GameContext.h:200
RoR::GameContext::~GameContext
~GameContext()
Definition: GameContext.cpp:57
RoR::GameContext::UpdateCommonInputEvents
void UpdateCommonInputEvents(float dt)
Definition: GameContext.cpp:1255
RoR::GameContext::GetPlayerCharacter
Character * GetPlayerCharacter()
Definition: GameContext.cpp:872
RoR::GameContext::OnLoaderGuiApply
void OnLoaderGuiApply(RoR::LoaderType type, CacheEntryPtr entry, std::string sectionconfig)
GUI callback.
Definition: GameContext.cpp:683
RoR::Message::Message
Message(MsgType _type)
Definition: GameContext.h:53
RoR::GameContext::m_last_tuneup_selection
CacheEntryPtr m_last_tuneup_selection
Definition: GameContext.h:199
RoR::GameContext::TeleportPlayer
void TeleportPlayer(float x, float z)
Definition: GameContext.cpp:880
RoR::GameContext::UpdateActors
void UpdateActors()
Definition: GameContext.cpp:579
RoR::GameContext::RespawnLastActor
void RespawnLastActor()
Definition: GameContext.cpp:590
RoR::CharacterFactory
Definition: CharacterFactory.h:39
RoR::GameContext::m_actor_manager
ActorManager m_actor_manager
Definition: GameContext.h:192
RoR::GameContext::ExtractSceneName
std::string ExtractSceneName(std::string const &filename)
Definition: Savegame.cpp:74
RefCountingObjectPtr< Terrain >
ActorManager.h
CharacterFactory.h
RoR::ActorSpawnRequest
Definition: SimData.h:832
RoR::GameContext::GetRaceSystem
RaceSystem & GetRaceSystem()
Definition: GameContext.h:168
RoR::GameContext::SpawnActor
ActorPtr SpawnActor(ActorSpawnRequest &rq)
Definition: GameContext.cpp:190
RoR::ActorManager
Builds and manages softbody actors (physics on background thread, networking)
Definition: ActorManager.h:43
RoR::GameContext::UpdateGlobalInputEvents
void UpdateGlobalInputEvents()
Definition: GameContext.cpp:918
RoR::GameMsgQueue
std::queue< Message, std::list< Message > > GameMsgQueue
Definition: GameContext.h:63
RoR::GameContext::m_msg_chain_end
Message * m_msg_chain_end
Definition: GameContext.h:185
RoR::AppContext
Central setup and event handler for input/windowing/rendering.
Definition: AppContext.h:43
RoR::GameContext::ChainMessage
void ChainMessage(Message m)
Add to last pushed message's chain.
Definition: GameContext.cpp:72
RoR::GameContext::GetSceneMouse
SceneMouse & GetSceneMouse()
Definition: GameContext.h:170
RoR::GameContext::m_current_selection
ActorSpawnRequest m_current_selection
Context of the loader UI.
Definition: GameContext.h:201
SimData.h
Core data structures for simulation; Everything affected by by either physics, network or user intera...
RoR::GameContext::LoadTerrain
bool LoadTerrain(std::string const &filename_part)
Definition: GameContext.cpp:111
RoR::ActorModifyRequest
Definition: SimData.h:870
RoR::GameContext::PopMessage
Message PopMessage()
Definition: GameContext.cpp:95
CacheSystem.h
A database of user-installed content alias 'mods' (vehicles, terrains...)
RoR::GameContext::m_player_actor
ActorPtr m_player_actor
Actor (vehicle or machine) mounted and controlled by player.
Definition: GameContext.h:193
RoR::GameContext::ChangePlayerActor
void ChangePlayerActor(ActorPtr actor)
Definition: GameContext.cpp:466
RoR::RepairMode
Interactive recovery and repair mode, operates on player vehicle Formerly 'advanced repair' or 'inter...
Definition: RepairMode.h:38
RoR::GameContext::GameContext
GameContext()
Definition: GameContext.cpp:52
RoR::GameContext::DeleteActor
void DeleteActor(ActorPtr actor)
Definition: GameContext.cpp:417
RoR::GameContext::PushMessage
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
Definition: GameContext.cpp:65
RoR::GameContext::GetCharacterFactory
CharacterFactory * GetCharacterFactory()
Definition: GameContext.h:150
RoR::GameContext::m_last_cache_selection
CacheEntryPtr m_last_cache_selection
Vehicle/load.
Definition: GameContext.h:197
RoR::GameContext::SetPrevPlayerActor
void SetPrevPlayerActor(ActorPtr actor)
Definition: GameContext.cpp:814
RoR::GameContext::prev_pos
Ogre::Vector3 prev_pos
Definition: GameContext.h:212
RoR::LoaderType
LoaderType
< Search mode for ModCache::Query() & Operation mode for GUI::MainSelector
Definition: Application.h:289
RoR::MsgType
MsgType
Global gameplay message loop, see struct Message in GameContext.h.
Definition: Application.h:74
RoR::GameContext::GetPrevPlayerActor
const ActorPtr & GetPrevPlayerActor()
Definition: GameContext.h:135
RoR::Message::payload
void * payload
Definition: GameContext.h:59
RoR::Message::chain
std::vector< Message > chain
Posted after the message is processed.
Definition: GameContext.h:60
RoR::GameContext::GetQuicksaveFilename
std::string GetQuicksaveFilename()
For currently loaded terrain (cvar 'sim_terrain_name')
Definition: Savegame.cpp:55
RoR::GameContext::m_timer
Ogre::Timer m_timer
Definition: GameContext.h:211
RoR::Message::description
std::string description
Definition: GameContext.h:58
RoR::GameContext::m_msg_queue
GameMsgQueue m_msg_queue
Definition: GameContext.h:184
RoR::MSG_INVALID
@ MSG_INVALID
Definition: Application.h:83
RoR::GameContext::UpdateAirplaneInputEvents
void UpdateAirplaneInputEvents(float dt)
Definition: GameContext.cpp:1537
instance
or anywhere else will not be considered a but parsed as regular data ! Each line is treated as values separated by separators Possible i e animators Multiline description Single instance
Definition: ReadMe.txt:53
RoR::GameContext::FetchPrevVehicleOnList
const ActorPtr & FetchPrevVehicleOnList()
Definition: GameContext.cpp:569
RoR::GameContext::OnLoaderGuiCancel
void OnLoaderGuiCancel()
GUI callback.
Definition: GameContext.cpp:667
RoR::Message
Unified game event system - all requests and state changes are reported using a message.
Definition: GameContext.h:51
RoR::GameContext::UnloadTerrain
void UnloadTerrain()
Definition: GameContext.cpp:176
RoR::GameContext::m_prev_player_actor
ActorPtr m_prev_player_actor
Previous actor (vehicle or machine) mounted and controlled by player.
Definition: GameContext.h:194
RoR::GameContext::LoadScene
void LoadScene(std::string const &filename)
Matching terrain must be already loaded.
Definition: Savegame.cpp:63
RoR::ActorPtr
RefCountingObjectPtr< Actor > ActorPtr
Definition: ForwardDeclarations.h:194
RoR::GameContext::m_terrain
TerrainPtr m_terrain
Definition: GameContext.h:189
RoR::GameContext::UpdateSimInputEvents
void UpdateSimInputEvents(float dt)
Definition: GameContext.cpp:1033
RoR::GameContext::UpdateBoatInputEvents
void UpdateBoatInputEvents(float dt)
Definition: GameContext.cpp:1725
RoR::GameContext::m_recovery_mode
RepairMode m_recovery_mode
Aka 'advanced repair' or 'interactive reset'.
Definition: GameContext.h:209
Terrain.h
RoR::GameContext::ShowLoaderGUI
void ShowLoaderGUI(int type, const Ogre::String &instance, const Ogre::String &box)
Definition: GameContext.cpp:639
RepairMode.h
Actor feat - interactive recovery and repair mode.
RoR::GameContext::SaveScene
void SaveScene(std::string const &filename)
Definition: Savegame.cpp:69
RoR::GameContext::m_race_system
RaceSystem m_race_system
Definition: GameContext.h:208
RoR::GameContext
Central game state manager.
Definition: GameContext.h:95
RoR::GameContext::SpawnPreselectedActor
void SpawnPreselectedActor(std::string const &preset_vehicle, std::string const &preset_veh_config)
needs Character to exist
Definition: GameContext.cpp:603
RoR::GameContext::m_dummy_cache_selection
CacheEntryPtr m_dummy_cache_selection
Definition: GameContext.h:202
RoR::GameContext::m_last_spawned_actor
ActorPtr m_last_spawned_actor
Last actor spawned by user and still alive.
Definition: GameContext.h:195
RoR::GameContext::GetRepairMode
RepairMode & GetRepairMode()
Definition: GameContext.h:169
SceneMouse.h
Mouse interaction with 3D scene.
RoR::GameContext::GetPlayerActor
const ActorPtr & GetPlayerActor()
Definition: GameContext.h:134
RoR::GameContext::UpdateTruckInputEvents
void UpdateTruckInputEvents(float dt)
Definition: GameContext.cpp:1785
RoR
Definition: AppContext.h:36
x
float x
Definition: (ValueTypes) quaternion.h:5
RoR::GameContext::FetchNextVehicleOnList
const ActorPtr & FetchNextVehicleOnList()
Definition: GameContext.cpp:574
RoR::GameContext::GetActorManager
ActorManager * GetActorManager()
Definition: GameContext.h:127
RoR::GameContext::FindActorByCollisionBox
ActorPtr FindActorByCollisionBox(std::string const &ev_src_instance_name, std::string const &box_name)
Definition: GameContext.cpp:584
RoR::GameContext::m_msg_mutex
std::mutex m_msg_mutex
Definition: GameContext.h:186
RoR::GameContext::CreatePlayerCharacter
void CreatePlayerCharacter()
Terrain must be loaded.
Definition: GameContext.cpp:819
RoR::GameContext::UpdateSkyInputEvents
void UpdateSkyInputEvents(float dt)
Definition: GameContext.cpp:1191
RoR::GameContext::GetTerrain
const TerrainPtr & GetTerrain()
Definition: GameContext.h:117
RoR::GameContext::m_scene_mouse
SceneMouse m_scene_mouse
Mouse interaction with scene.
Definition: GameContext.h:210
RoR::Message::type
MsgType type
Definition: GameContext.h:57
RoR::GameContext::HandleSavegameHotkeys
void HandleSavegameHotkeys()
Definition: Savegame.cpp:98
RoR::Message::Message
Message(MsgType _type, void *_data)
Definition: GameContext.h:55
RoR::GameContext::HasMessages
bool HasMessages()
Definition: GameContext.cpp:89