RigsofRods
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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; }
138  void SetPrevPlayerActor(ActorPtr actor);
139  void ChangePlayerActor(ActorPtr actor);
140 
141  void ShowLoaderGUI(int type, const Ogre::String& instance, const Ogre::String& box);
142  void OnLoaderGuiCancel();
143  void OnLoaderGuiApply(RoR::LoaderType type, CacheEntryPtr entry, std::string sectionconfig);
144 
148 
149  void CreatePlayerCharacter();
152 
156  // (defined in Savegame.cpp)
157 
158  void LoadScene(std::string const& filename);
159  void SaveScene(std::string const& filename);
160  std::string GetQuicksaveFilename();
161  std::string ExtractSceneName(std::string const& filename);
162  std::string ExtractSceneTerrain(std::string const& filename);
163  void HandleSavegameHotkeys();
164 
168 
172  void TeleportPlayer(float x, float z);
174  void UpdateSimInputEvents(float dt);
175  void UpdateSkyInputEvents(float dt);
176  void UpdateCommonInputEvents(float dt);
177  void UpdateAirplaneInputEvents(float dt);
178  void UpdateBoatInputEvents(float dt);
179  void UpdateTruckInputEvents(float dt);
180 
182 
183 private:
184  // Message queue
187  std::mutex m_msg_mutex;
188 
189  // Terrain
191 
192  // Actors (physics and netcode)
198 
202  Ogre::String m_last_section_config;
205 
206  // Characters (simplified physics and netcode)
208 
209  // Gameplay feats (misc.)
213  Ogre::Timer m_timer;
214  Ogre::Vector3 prev_pos = Ogre::Vector3::ZERO;
215 };
216 
218 
219 } // namespace RoR
RoR::GameContext::ExtractSceneTerrain
std::string ExtractSceneTerrain(std::string const &filename)
Returns terrain filename.
Definition: Savegame.cpp:87
RaceSystem.h
Counterpart to Neorej16's race system script.
RoR::GameContext::ModifyActor
void ModifyActor(ActorModifyRequest &rq)
Definition: GameContext.cpp:369
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:200
RoR::GameContext::m_character_factory
CharacterFactory m_character_factory
Definition: GameContext.h:207
RoR::RaceSystem
Definition: RaceSystem.h:31
z
float z
Definition: (ValueTypes) quaternion.h:7
RoR::GameContext::m_actor_remotely_receiving_commands
ActorPtr m_actor_remotely_receiving_commands
Actor close enough to import command keys.
Definition: GameContext.h:197
RoR::GameContext::m_last_section_config
Ogre::String m_last_section_config
Definition: GameContext.h:202
RoR::GameContext::~GameContext
~GameContext()
Definition: GameContext.cpp:58
RoR::GameContext::UpdateCommonInputEvents
void UpdateCommonInputEvents(float dt)
Definition: GameContext.cpp:1320
RoR::GameContext::GetPlayerCharacter
Character * GetPlayerCharacter()
Definition: GameContext.cpp:897
RoR::GameContext::OnLoaderGuiApply
void OnLoaderGuiApply(RoR::LoaderType type, CacheEntryPtr entry, std::string sectionconfig)
GUI callback.
Definition: GameContext.cpp:704
RoR::Message::Message
Message(MsgType _type)
Definition: GameContext.h:53
RoR::GameContext::m_last_tuneup_selection
CacheEntryPtr m_last_tuneup_selection
Definition: GameContext.h:201
RoR::GameContext::TeleportPlayer
void TeleportPlayer(float x, float z)
Definition: GameContext.cpp:905
RoR::GameContext::UpdateActors
void UpdateActors()
Definition: GameContext.cpp:600
RoR::GameContext::RespawnLastActor
void RespawnLastActor()
Definition: GameContext.cpp:611
RoR::CharacterFactory
Definition: CharacterFactory.h:39
RoR::GameContext::m_actor_manager
ActorManager m_actor_manager
Definition: GameContext.h:193
RoR::GameContext::ExtractSceneName
std::string ExtractSceneName(std::string const &filename)
Definition: Savegame.cpp:75
RefCountingObjectPtr< Terrain >
ActorManager.h
CharacterFactory.h
RoR::ActorSpawnRequest
Definition: SimData.h:812
RoR::GameContext::GetRaceSystem
RaceSystem & GetRaceSystem()
Definition: GameContext.h:169
RoR::GameContext::SpawnActor
ActorPtr SpawnActor(ActorSpawnRequest &rq)
Definition: GameContext.cpp:193
RoR::ActorManager
Builds and manages softbody actors (physics on background thread, networking)
Definition: ActorManager.h:43
RoR::GameContext::UpdateGlobalInputEvents
void UpdateGlobalInputEvents()
Definition: GameContext.cpp:943
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:186
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:73
RoR::GameContext::GetSceneMouse
SceneMouse & GetSceneMouse()
Definition: GameContext.h:171
RoR::GameContext::m_current_selection
ActorSpawnRequest m_current_selection
Context of the loader UI.
Definition: GameContext.h:203
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:112
RoR::ActorModifyRequest
Definition: SimData.h:852
RoR::GameContext::PopMessage
Message PopMessage()
Definition: GameContext.cpp:96
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:194
RoR::GameContext::ChangePlayerActor
void ChangePlayerActor(ActorPtr actor)
Definition: GameContext.cpp:487
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:53
RoR::GameContext::DeleteActor
void DeleteActor(ActorPtr actor)
Definition: GameContext.cpp:438
RoR::GameContext::PushMessage
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
Definition: GameContext.cpp:66
RoR::Character
Definition: Character.h:39
RoR::GameContext::GetCharacterFactory
CharacterFactory * GetCharacterFactory()
Definition: GameContext.h:151
RoR::GameContext::m_last_cache_selection
CacheEntryPtr m_last_cache_selection
Vehicle/load.
Definition: GameContext.h:199
RoR::GameContext::SetPrevPlayerActor
void SetPrevPlayerActor(ActorPtr actor)
Definition: GameContext.cpp:835
RoR::GameContext::prev_pos
Ogre::Vector3 prev_pos
Definition: GameContext.h:214
RoR::LoaderType
LoaderType
< Search mode for ModCache::Query() & Operation mode for GUI::MainSelector
Definition: Application.h:306
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::GameContext::GetActorRemotelyReceivingCommands
const ActorPtr & GetActorRemotelyReceivingCommands()
Definition: GameContext.h:137
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:56
RoR::GameContext::m_timer
Ogre::Timer m_timer
Definition: GameContext.h:213
RoR::Message::description
std::string description
Definition: GameContext.h:58
RoR::GameContext::m_msg_queue
GameMsgQueue m_msg_queue
Definition: GameContext.h:185
RoR::MSG_INVALID
@ MSG_INVALID
Definition: Application.h:83
RoR::GameContext::UpdateAirplaneInputEvents
void UpdateAirplaneInputEvents(float dt)
Definition: GameContext.cpp:1602
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:590
RoR::GameContext::OnLoaderGuiCancel
void OnLoaderGuiCancel()
GUI callback.
Definition: GameContext.cpp:688
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:179
RoR::GameContext::m_prev_player_actor
ActorPtr m_prev_player_actor
Previous actor (vehicle or machine) mounted and controlled by player.
Definition: GameContext.h:195
RoR::GameContext::LoadScene
void LoadScene(std::string const &filename)
Matching terrain must be already loaded.
Definition: Savegame.cpp:64
RoR::GameContext::m_terrain
TerrainPtr m_terrain
Definition: GameContext.h:190
RoR::GameContext::UpdateSimInputEvents
void UpdateSimInputEvents(float dt)
Definition: GameContext.cpp:1058
RoR::GameContext::UpdateBoatInputEvents
void UpdateBoatInputEvents(float dt)
Definition: GameContext.cpp:1790
RoR::GameContext::m_recovery_mode
RepairMode m_recovery_mode
Aka 'advanced repair' or 'interactive reset'.
Definition: GameContext.h:211
Terrain.h
RoR::GameContext::ShowLoaderGUI
void ShowLoaderGUI(int type, const Ogre::String &instance, const Ogre::String &box)
Definition: GameContext.cpp:660
RepairMode.h
Actor feat - interactive recovery and repair mode.
RoR::GameContext::SaveScene
void SaveScene(std::string const &filename)
Definition: Savegame.cpp:70
RoR::GameContext::m_race_system
RaceSystem m_race_system
Definition: GameContext.h:210
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:624
RoR::GameContext::m_dummy_cache_selection
CacheEntryPtr m_dummy_cache_selection
Definition: GameContext.h:204
RoR::GameContext::m_last_spawned_actor
ActorPtr m_last_spawned_actor
Last actor spawned by user and still alive.
Definition: GameContext.h:196
RoR::GameContext::GetRepairMode
RepairMode & GetRepairMode()
Definition: GameContext.h:170
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:1850
RoR
Definition: AppContext.h:36
x
float x
Definition: (ValueTypes) quaternion.h:5
RoR::GameContext::FetchNextVehicleOnList
const ActorPtr & FetchNextVehicleOnList()
Definition: GameContext.cpp:595
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:605
RoR::GameContext::m_msg_mutex
std::mutex m_msg_mutex
Definition: GameContext.h:187
RoR::GameContext::CreatePlayerCharacter
void CreatePlayerCharacter()
Terrain must be loaded.
Definition: GameContext.cpp:840
RoR::GameContext::UpdateSkyInputEvents
void UpdateSkyInputEvents(float dt)
Definition: GameContext.cpp:1256
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:212
RoR::Message::type
MsgType type
Definition: GameContext.h:57
RoR::GameContext::HandleSavegameHotkeys
void HandleSavegameHotkeys()
Definition: Savegame.cpp:99
RoR::Message::Message
Message(MsgType _type, void *_data)
Definition: GameContext.h:55
RoR::GameContext::HasMessages
bool HasMessages()
Definition: GameContext.cpp:90