RigsofRods
Soft-body Physics Simulation
SimBuffers.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 2016-2021 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 
22 #pragma once
23 
24 #include "AutoPilot.h"
25 #include "CameraManager.h"
26 #include "Differentials.h"
27 #include "SimData.h"
28 #include <Ogre.h>
29 
30 /*
31  @file
32  @brief Sim buffers are snapshots of simulation state, which are used for updating visual scene.
33 
34  HOW IT WORKS AND WHY
35  --------------------
36  This game uses quite a lot of CPU-intensive computations when updating visuals.
37  The biggest issue are flexbodies, submeshes and wheels, but also props and beams.
38  To avoid halting simulation until all these slow updates are done, the process is divided:
39  1. Simulation runs on it's own thread, at it's own pace (see PHYSICS_DT).
40  It only updates positons and forces, it doesn't deal with graphics at all.
41  2. When time comes for rendering, simulation is halted and all data relevant to graphics
42  are copied-out to simbuffers. Then, simulation is resumed.
43  3. The rendering thread processes the simbuffers and updates visual objects.
44 
45  OVERVIEW OF GAMEPLAY OBJECTS
46  ----------------------------
47  Following listing shows {SIMULATION / SIMBUFFER / GRAPHICAL} object triplets
48  and filenames where the objects live (to be cleaned up).
49  Note that for historical reasons, many simulation bits are actually done
50  on main thread, but the goal is to do all on sim. thread.
51 
52  GameContext (gamecontext.h) / GameContextSB / GfxScene (gfxscene.h)
53  Actor (actor.h) / ActorSB / GfxActor (gfxactor.h)
54  node_t (simdata.h) / NodeSB / NodeGfx (gfxdata.h)
55  beam_t (simdata.h) / - / BeamGfx (gfxdata.h)
56  command_t (simdata.h) / CommandKeySB / -
57  wheel_t (simdata.h) / - / WheelGfx (gfxdata.h)
58  wing_t (simdata.h) / - / -
59  Turbojet (turbojet.h) / AeroEngineSB / TurbojetVisual (turbojet.h)
60  Turboprop (turboprop.h) / AeroEngineSB / -
61  Airbrake (airbrake.h) / AirbrakeSB / AirbrakeGfx (gfxdata.h)
62  Screwprop (screwprop.h) / ScrewpropSB / -
63 */
64 
65 namespace RoR {
66 
67 struct NodeSB
68 {
69  Ogre::Vector3 AbsPosition; // classic name
71  bool nd_is_wet:1;
72 };
73 
75 {
78 };
79 
81 {
83 };
84 
86 {
88 };
89 
91 {
103 };
104 
106 {
108 };
109 
110 struct ActorSB
111 {
112  // PLEASE maintain the same order as in `GfxActor::UpdateSimDataBuffer()`
113 
114  // Gameplay state
116  bool simbuf_physics_paused = false;
118  std::string simbuf_net_username;
121 
122  // Movement
123  Ogre::Vector3 simbuf_pos = Ogre::Vector3::ZERO;
124  Ogre::Vector3 simbuf_node0_velo = Ogre::Vector3::ZERO;
125  float simbuf_rotation = 0;
126  Ogre::Vector3 simbuf_direction = Ogre::Vector3::ZERO;
128  float simbuf_top_speed = 0;
129  Ogre::AxisAlignedBox simbuf_aabb = Ogre::AxisAlignedBox::BOX_NULL;
132 
133  // Elements
134  std::vector<NodeSB> simbuf_nodes;
135  std::vector<ScrewpropSB> simbuf_screwprops;
136  std::array<CommandKeySB, MAX_COMMANDS+1> simbuf_commandkey;
137  std::vector<PropAnimKeySB> simbuf_prop_anim_keys;
138  std::vector<AeroEngineSB> simbuf_aeroengines;
139  std::vector<AirbrakeSB> simbuf_airbrakes;
140 
141  // Drivetrain
142  float simbuf_hydro_dir_state = 0; // State of steering actuator ('hydro'), for steeringwheel display
143  float simbuf_brake = 0;
144  bool simbuf_has_engine = false;
145  int simbuf_gear = 0;
147  float simbuf_engine_rpm = 0;
152  float simbuf_inputshaft_rpm = 0; // Land vehicle only
153  float simbuf_drive_ratio = 0; // Land vehicle only
155  float simbuf_clutch = 0;
158 
159  // Tyre pressure
162 
163  // Effects
165  bool simbuf_smoke_enabled = false;
166  bool simbuf_parking_brake = false;
167 
168  // Aerial
174  float simbuf_wing4_aoa = 0;
175 
176  // Autopilot
177  bool simbuf_has_autopilot = false;
181  int simbuf_ap_alt_value = 1000; // from AutoPilot::reset()
182  bool simbuf_ap_ias_mode = false;
183  int simbuf_ap_ias_value = 150; // from AutoPilot::reset()
184  bool simbuf_ap_gpws_mode = false;
189 
190  // GUI ('guisettings')
194 };
195 
197 {
198  GameContextSB();
199  ~GameContextSB();
200 
202  Ogre::Vector3 simbuf_character_pos = Ogre::Vector3::ZERO;
203  bool simbuf_sim_paused = false;
204  float simbuf_sim_speed = 1.f;
207 
208  // Race system
209  float simbuf_race_time = 0.f;
214  Ogre::Vector3 simbuf_dir_arrow_target = Ogre::Vector3::ZERO;
217 };
218 
219 } // namespace RoR
220 
RoR::CameraManager::CAMERA_BEHAVIOR_INVALID
@ CAMERA_BEHAVIOR_INVALID
Definition: CameraManager.h:55
RoR::ActorSB::simbuf_hydro_aileron_state
float simbuf_hydro_aileron_state
Definition: SimBuffers.h:169
RoR::ActorSB::simbuf_engine_accel
float simbuf_engine_accel
Definition: SimBuffers.h:150
RoR::ActorSB::simbuf_driveable
int simbuf_driveable
Definition: SimBuffers.h:120
RoR::CommandKeySB
Definition: SimBuffers.h:80
RoR::GameContextSB::simbuf_sim_speed
float simbuf_sim_speed
Definition: SimBuffers.h:204
RoR::NodeSB
Definition: SimBuffers.h:67
RoR::ActorSB::simbuf_lightmask
BitMask_t simbuf_lightmask
Definition: SimBuffers.h:164
RoR::AeroEngineSB::simbuf_ae_type
AeroEngineType simbuf_ae_type
Definition: SimBuffers.h:92
RoR::GameContextSB
Definition: SimBuffers.h:196
RoR::GameContextSB::simbuf_dir_arrow_visible
bool simbuf_dir_arrow_visible
Definition: SimBuffers.h:216
RoR::GameContextSB::simbuf_race_time
float simbuf_race_time
Definition: SimBuffers.h:209
RoR::PropAnimKeySB
Definition: SimBuffers.h:85
RoR::ActorSB::simbuf_ap_ias_value
int simbuf_ap_ias_value
Definition: SimBuffers.h:183
RoR::AeroEngineSB::simbuf_tp_aepitch
float simbuf_tp_aepitch
Turboprop pitch, used by animation "aepitch".
Definition: SimBuffers.h:97
RoR::ActorSB::simbuf_shifter_anim_time
float simbuf_shifter_anim_time
Definition: SimBuffers.h:193
RoR::ActorSB::simbuf_commandkey
std::array< CommandKeySB, MAX_COMMANDS+1 > simbuf_commandkey
BEWARE: commandkeys are indexed 1-MAX_COMMANDS!
Definition: SimBuffers.h:136
RoR::ActorSB::simbuf_screwprops
std::vector< ScrewpropSB > simbuf_screwprops
Definition: SimBuffers.h:135
RoR::ActorSB::simbuf_ap_ias_mode
bool simbuf_ap_ias_mode
Definition: SimBuffers.h:182
AutoPilot.h
RoR::ActorSB::simbuf_ap_alt_mode
int simbuf_ap_alt_mode
Definition: SimBuffers.h:180
RoR::ScrewpropSB
Definition: SimBuffers.h:74
RoR::ActorSB::simbuf_smoke_enabled
bool simbuf_smoke_enabled
Definition: SimBuffers.h:165
RoR::ActorSB::simbuf_aero_flap_state
int simbuf_aero_flap_state
Definition: SimBuffers.h:172
RoR::ActorSB::simbuf_clutch
float simbuf_clutch
Definition: SimBuffers.h:155
RoR::AeroEngineSB
Definition: SimBuffers.h:90
RoR::CameraManager::CameraBehaviors
CameraBehaviors
Definition: CameraManager.h:44
RoR::AeroEngineSB::simbuf_tj_exhaust_velo
float simbuf_tj_exhaust_velo
Turbojet afterburner.
Definition: SimBuffers.h:99
RoR::ActorSB::simbuf_node0_velo
Ogre::Vector3 simbuf_node0_velo
Definition: SimBuffers.h:124
RoR::GameContextSB::simbuf_camera_behavior
CameraManager::CameraBehaviors simbuf_camera_behavior
Definition: SimBuffers.h:206
CameraManager.h
RoR::GameContextSB::simbuf_sim_paused
bool simbuf_sim_paused
Definition: SimBuffers.h:203
RoR::GameContextSB::simbuf_dir_arrow_text
std::string simbuf_dir_arrow_text
Definition: SimBuffers.h:215
RoR::NodeSB::nd_is_wet
bool nd_is_wet
Definition: SimBuffers.h:71
RoR::ActorSB::simbuf_num_gears
int simbuf_num_gears
Gearbox.
Definition: SimBuffers.h:156
RoR::ActorSB::simbuf_aeroengines
std::vector< AeroEngineSB > simbuf_aeroengines
Definition: SimBuffers.h:138
RoR::ActorSB::simbuf_speedo_use_engine_max_rpm
bool simbuf_speedo_use_engine_max_rpm
Definition: SimBuffers.h:192
RoR::GameContextSB::simbuf_character_pos
Ogre::Vector3 simbuf_character_pos
Definition: SimBuffers.h:202
RoR::NOT_DRIVEABLE
@ NOT_DRIVEABLE
not drivable at all
Definition: SimData.h:92
Differentials.h
RoR::GameContextSB::simbuf_player_actor
ActorPtr simbuf_player_actor
Definition: SimBuffers.h:201
RoR::ActorSB::simbuf_direction
Ogre::Vector3 simbuf_direction
Output of Actor::getDirection()
Definition: SimBuffers.h:126
RoR::AirbrakeSB::simbuf_ab_ratio
float simbuf_ab_ratio
Definition: SimBuffers.h:107
RoR::ActorSB::simbuf_engine_crankfactor
float simbuf_engine_crankfactor
Definition: SimBuffers.h:148
RefCountingObjectPtr< Actor >
RoR::ActorSB::simbuf_aabb
Ogre::AxisAlignedBox simbuf_aabb
Definition: SimBuffers.h:129
RoR::NodeSB::nd_has_contact
bool nd_has_contact
Definition: SimBuffers.h:70
RoR::ActorSB::simbuf_parking_brake
bool simbuf_parking_brake
Definition: SimBuffers.h:166
RoR::GameContextSB::simbuf_race_best_time
float simbuf_race_best_time
Definition: SimBuffers.h:210
RoR::AeroEngineSB::simbuf_tp_aetorque
float simbuf_tp_aetorque
Turboprop torque, used by animation "aetorque".
Definition: SimBuffers.h:96
RoR::ActorSB::simbuf_rotation
float simbuf_rotation
Definition: SimBuffers.h:125
RoR::AeroEngineSB::simbuf_ae_rpm
float simbuf_ae_rpm
Definition: SimBuffers.h:93
RoR::ActorSB::simbuf_wing4_aoa
float simbuf_wing4_aoa
Definition: SimBuffers.h:174
RoR::GameContextSB::simbuf_race_in_progress
bool simbuf_race_in_progress
Definition: SimBuffers.h:212
RoR::ActorSB::simbuf_ap_heading_mode
int simbuf_ap_heading_mode
Definition: SimBuffers.h:178
RoR::NodeNum_t
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
Definition: ForwardDeclarations.h:52
SimData.h
Core data structures for simulation; Everything affected by by either physics, network or user intera...
RoR::CommandKeySB::simbuf_cmd_value
float simbuf_cmd_value
Definition: SimBuffers.h:82
RoR::ActorSB::simbuf_drive_ratio
float simbuf_drive_ratio
Definition: SimBuffers.h:153
RoR::GameContextSB::simbuf_race_time_diff
float simbuf_race_time_diff
Definition: SimBuffers.h:211
RoR::AeroEngineType
AeroEngineType
Definition: SimData.h:275
RoR::AeroEngineSB::simbuf_ae_rpmpc
float simbuf_ae_rpmpc
Definition: SimBuffers.h:94
RoR::ActorSB::simbuf_inputshaft_rpm
float simbuf_inputshaft_rpm
Definition: SimBuffers.h:152
RoR::ActorSB::simbuf_hydro_aero_rudder_state
float simbuf_hydro_aero_rudder_state
Definition: SimBuffers.h:171
RoR::ActorState::LOCAL_SLEEPING
@ LOCAL_SLEEPING
sleeping (local) actor
RoR::ActorSB::simbuf_airbrakes
std::vector< AirbrakeSB > simbuf_airbrakes
Definition: SimBuffers.h:139
RoR::ActorSB::simbuf_ap_gpws_mode
bool simbuf_ap_gpws_mode
Definition: SimBuffers.h:184
RoR::ActorSB::simbuf_ap_heading_value
int simbuf_ap_heading_value
Definition: SimBuffers.h:179
RoR::ActorSB::simbuf_wheel_speed
float simbuf_wheel_speed
Definition: SimBuffers.h:127
RoR::AirbrakeSB
Definition: SimBuffers.h:105
RoR::ActorSB::simbuf_ap_ils_hdev
float simbuf_ap_ils_hdev
Definition: SimBuffers.h:187
RoR::GameContextSB::simbuf_race_in_progress_prev
bool simbuf_race_in_progress_prev
Definition: SimBuffers.h:213
RoR::AeroEngineSB::simbuf_ae_throttle
float simbuf_ae_throttle
Definition: SimBuffers.h:95
RoR::ActorSB::simbuf_actor_state
ActorState simbuf_actor_state
Definition: SimBuffers.h:115
RoR::ActorSB::simbuf_engine_rpm
float simbuf_engine_rpm
Definition: SimBuffers.h:147
RoR::ActorSB::simbuf_ap_alt_value
int simbuf_ap_alt_value
Definition: SimBuffers.h:181
RoR::ActorSB::simbuf_pos
Ogre::Vector3 simbuf_pos
Definition: SimBuffers.h:123
RoR::ActorState
ActorState
Definition: SimData.h:265
RoR::ActorSB::simbuf_ap_ils_vdev
float simbuf_ap_ils_vdev
Definition: SimBuffers.h:186
RoR::ActorSB::simbuf_ap_vs_value
int simbuf_ap_vs_value
Definition: SimBuffers.h:188
RoR::ActorSB::simbuf_physics_paused
bool simbuf_physics_paused
Definition: SimBuffers.h:116
RoR::ActorSB::simbuf_hydro_elevator_state
float simbuf_hydro_elevator_state
Definition: SimBuffers.h:170
RoR::ActorSB::simbuf_brake
float simbuf_brake
Definition: SimBuffers.h:143
RoR::ActorSB::simbuf_diff_type
DiffType simbuf_diff_type
Definition: SimBuffers.h:154
RoR::ActorSB::simbuf_tyre_pressure
float simbuf_tyre_pressure
Definition: SimBuffers.h:160
RoR::NodeSB::AbsPosition
Ogre::Vector3 AbsPosition
Definition: SimBuffers.h:69
RoR::ActorSB::simbuf_top_speed
float simbuf_top_speed
Definition: SimBuffers.h:128
RoR::AeroEngineSB::simbuf_tj_ab_thrust
float simbuf_tj_ab_thrust
Definition: SimBuffers.h:98
RoR::ActorSB::simbuf_ap_ils_available
bool simbuf_ap_ils_available
Definition: SimBuffers.h:185
RoR::ActorSB::simbuf_engine_max_rpm
float simbuf_engine_max_rpm
Definition: SimBuffers.h:157
RoR::GameContextSB::~GameContextSB
~GameContextSB()
Definition: SimBuffers.cpp:33
RoR::ActorSB::simbuf_camera0_roll_node
NodeNum_t simbuf_camera0_roll_node
Definition: SimBuffers.h:131
RoR::Autopilot::HEADING_NONE
@ HEADING_NONE
Definition: AutoPilot.h:40
RoR::ActorSB::simbuf_gear
int simbuf_gear
Definition: SimBuffers.h:145
RoR::ActorSB::simbuf_airbrake_state
int simbuf_airbrake_state
Definition: SimBuffers.h:173
RoR::ActorSB::simbuf_net_colornum
int simbuf_net_colornum
Definition: SimBuffers.h:119
RoR::ScrewpropSB::simbuf_sp_rudder
float simbuf_sp_rudder
Definition: SimBuffers.h:76
RoR::ActorSB::simbuf_speedo_highest_kph
float simbuf_speedo_highest_kph
Definition: SimBuffers.h:191
RoR::ActorSB::simbuf_engine_turbo_psi
float simbuf_engine_turbo_psi
Definition: SimBuffers.h:149
RoR::ActorSB::simbuf_net_username
std::string simbuf_net_username
Definition: SimBuffers.h:118
RoR::DiffType
DiffType
Definition: Differentials.h:57
RoR::ActorSB::simbuf_prop_anim_keys
std::vector< PropAnimKeySB > simbuf_prop_anim_keys
Definition: SimBuffers.h:137
RoR::ActorSB
Definition: SimBuffers.h:110
RoR::ScrewpropSB::simbuf_sp_throttle
float simbuf_sp_throttle
Definition: SimBuffers.h:77
RoR::ActorSB::simbuf_hydro_dir_state
float simbuf_hydro_dir_state
Definition: SimBuffers.h:142
BitMask_t
uint32_t BitMask_t
Definition: BitFlags.h:7
RoR::ActorSB::simbuf_camera0_pos_node
NodeNum_t simbuf_camera0_pos_node
Definition: SimBuffers.h:130
RoR::AeroEngineSB::simbuf_ae_failed
bool simbuf_ae_failed
Definition: SimBuffers.h:101
RoR::GameContextSB::simbuf_dir_arrow_target
Ogre::Vector3 simbuf_dir_arrow_target
Definition: SimBuffers.h:214
RoR::SPLIT_DIFF
@ SPLIT_DIFF
Definition: Differentials.h:59
RoR::ActorSB::simbuf_autoshift
int simbuf_autoshift
Definition: SimBuffers.h:146
RoR::Autopilot::ALT_NONE
@ ALT_NONE
Definition: AutoPilot.h:48
RoR::ActorSB::simbuf_nodes
std::vector< NodeSB > simbuf_nodes
Definition: SimBuffers.h:134
RoR::ActorSB::simbuf_tyre_pressurizing
bool simbuf_tyre_pressurizing
Definition: SimBuffers.h:161
RoR::GameContextSB::GameContextSB
GameContextSB()
Definition: SimBuffers.cpp:28
RoR::ActorSB::simbuf_has_autopilot
bool simbuf_has_autopilot
Definition: SimBuffers.h:177
RoR::AeroEngineSB::simbuf_ae_ignition
bool simbuf_ae_ignition
Turbojet.
Definition: SimBuffers.h:100
RoR::PropAnimKeySB::simbuf_anim_active
bool simbuf_anim_active
Definition: SimBuffers.h:87
RoR::AeroEngineSB::simbuf_tj_afterburn
bool simbuf_tj_afterburn
Definition: SimBuffers.h:102
RoR
Definition: AppContext.h:36
RoR::ActorSB::simbuf_has_engine
bool simbuf_has_engine
Definition: SimBuffers.h:144
RoR::ActorSB::simbuf_engine_torque
float simbuf_engine_torque
Definition: SimBuffers.h:151
RoR::ActorSB::simbuf_cur_cinecam
int simbuf_cur_cinecam
Definition: SimBuffers.h:117