Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
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
42namespace RoR {
43
46
49
51struct 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
63typedef std::queue < Message, std::list<Message>> GameMsgQueue;
64
66
94
96{
97 friend class AppContext;
98public:
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
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);
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
183private:
184 // Message queue
187 std::mutex m_msg_mutex;
188
189 // Terrain
191
192 // Actors (physics and netcode)
198
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
A database of user-installed content alias 'mods' (vehicles, terrains...)
Counterpart to Neorej16's race system script.
Actor feat - interactive recovery and repair mode.
Mouse interaction with 3D scene.
Core data structures for simulation; Everything affected by by either physics, network or user intera...
Builds and manages softbody actors (physics on background thread, networking)
Central setup and event handler for input/windowing/rendering.
Definition AppContext.h:47
Central game state manager.
Definition GameContext.h:96
void SetPrevPlayerActor(ActorPtr actor)
Message * m_msg_chain_end
ActorPtr m_last_spawned_actor
Last actor spawned by user and still alive.
TerrainPtr m_terrain
void LoadScene(std::string const &filename)
Matching terrain must be already loaded.
Definition Savegame.cpp:64
void UpdateGlobalInputEvents()
std::mutex m_msg_mutex
void HandleSavegameHotkeys()
Definition Savegame.cpp:99
ActorPtr SpawnActor(ActorSpawnRequest &rq)
ActorPtr FindActorByCollisionBox(std::string const &ev_src_instance_name, std::string const &box_name)
Ogre::Vector3 prev_pos
Message PopMessage()
void UpdateSkyInputEvents(float dt)
ActorSpawnRequest m_current_selection
Context of the loader UI.
const ActorPtr & FetchNextVehicleOnList()
RaceSystem m_race_system
ActorPtr m_player_actor
Actor (vehicle or machine) mounted and controlled by player.
CharacterFactory * GetCharacterFactory()
void OnLoaderGuiApply(RoR::LoaderType type, CacheEntryPtr entry, std::string sectionconfig)
GUI callback.
const ActorPtr & FetchPrevVehicleOnList()
CacheEntryPtr m_last_skin_selection
CharacterFactory m_character_factory
Character * GetPlayerCharacter()
const ActorPtr & GetPlayerActor()
const TerrainPtr & GetTerrain()
const ActorPtr & GetPrevPlayerActor()
void ShowLoaderGUI(int type, const Ogre::String &instance, const Ogre::String &box)
ActorManager m_actor_manager
void UpdateTruckInputEvents(float dt)
std::string ExtractSceneTerrain(std::string const &filename)
Returns terrain filename.
Definition Savegame.cpp:87
Ogre::String m_last_section_config
void UpdateCommonInputEvents(float dt)
SceneMouse & GetSceneMouse()
CacheEntryPtr m_last_tuneup_selection
void ChangePlayerActor(ActorPtr actor)
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
void SpawnPreselectedActor(std::string const &preset_vehicle, std::string const &preset_veh_config)
needs Character to exist
bool LoadTerrain(std::string const &filename_part)
CacheEntryPtr m_dummy_cache_selection
const ActorPtr & GetLastSpawnedActor()
Last actor spawned by user and still alive.
Ogre::Timer m_timer
RepairMode m_recovery_mode
Aka 'advanced repair' or 'interactive reset'.
void CreatePlayerCharacter()
Terrain must be loaded.
ActorPtr m_actor_remotely_receiving_commands
Actor close enough to import command keys.
RepairMode & GetRepairMode()
void SaveScene(std::string const &filename)
Definition Savegame.cpp:70
void UpdateSimInputEvents(float dt)
void ChainMessage(Message m)
Add to last pushed message's chain.
void DeleteActor(ActorPtr actor)
void ModifyActor(ActorModifyRequest &rq)
std::string GetQuicksaveFilename()
For currently loaded terrain (cvar 'sim_terrain_name')
Definition Savegame.cpp:56
void TeleportPlayer(float x, float z)
const ActorPtr & GetActorRemotelyReceivingCommands()
GameMsgQueue m_msg_queue
void UpdateBoatInputEvents(float dt)
ActorPtr m_prev_player_actor
Previous actor (vehicle or machine) mounted and controlled by player.
ActorManager * GetActorManager()
CacheEntryPtr m_last_cache_selection
Vehicle/load.
void OnLoaderGuiCancel()
GUI callback.
SceneMouse m_scene_mouse
Mouse interaction with scene.
std::string ExtractSceneName(std::string const &filename)
Definition Savegame.cpp:75
RaceSystem & GetRaceSystem()
void UpdateAirplaneInputEvents(float dt)
Interactive recovery and repair mode, operates on player vehicle Formerly 'advanced repair' or 'inter...
Definition RepairMode.h:39
std::queue< Message, std::list< Message > > GameMsgQueue
Definition GameContext.h:63
MsgType
Global gameplay message loop, see struct Message in GameContext.h.
Definition Application.h:76
@ MSG_INVALID
Definition Application.h:84
LoaderType
< Search mode for ModCache::Query() & Operation mode for GUI::MainSelector
Unified game event system - all requests and state changes are reported using a message.
Definition GameContext.h:52
MsgType type
Definition GameContext.h:57
Message(MsgType _type, void *_data)
Definition GameContext.h:55
std::string description
Definition GameContext.h:58
void * payload
Definition GameContext.h:59
Message(MsgType _type, std::string const &_desc)
Definition GameContext.h:54
Message(MsgType _type)
Definition GameContext.h:53
std::vector< Message > chain
Posted after the message is processed.
Definition GameContext.h:60