RigsofRods
Soft-body Physics Simulation
EngineSim.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 
22 #pragma once
23 
24 #include "Application.h"
25 
26 namespace RoR {
27 
30 
33 
35 class EngineSim
36 {
37  friend class ActorSpawner;
38 
39 public:
40 
41  EngineSim(float min_rpm, float max_rpm, float torque, std::vector<float> gears, float dratio, ActorPtr actor);
42  ~EngineSim();
43 
46  void PushNetworkState(float engine_rpm, float acc, float clutch, int gear, bool running, bool contact, char auto_mode, char auto_select=-1);
47 
59  void SetEngineOptions(float einertia, char etype, float eclutch, float ctime, float stime, float pstime, float irpm, float srpm, float maximix, float minimix, float ebraking);
60 
65  void SetTurboOptions(int type, float tinertiaFactor, int nturbos, float param1, float param2, float param3, float param4, float param5, float param6, float param7, float param8, float param9, float param10, float param11);
66 
67  void SetAcceleration(float val);
69  void SetClutch(float clutch);
70  float GetAcceleration();
71  float GetClutch();
72  float GetClutchForce();
73  float GetCrankFactor();
74  float GetSmoke();
75  float GetTorque();
76  float GetTurboPsi();
78  void SetEngineRpm(float rpm);
79  void SetEnginePriming(bool p);
80  void SetHydroPumpWork(float work);
81  void SetWheelSpin(float rpm);
82  void SetTCaseRatio(float ratio);
83  void ToggleAutoShiftMode();
84  void OffStart();
85  void StartEngine();
86  int GetGear();
87  int GetGearRange();
88  void SetGear(int v);
89  void SetGearRange(int v);
90  void StopEngine();
91  float GetAccToHoldRPM();
92  bool HasTurbo() const { return m_engine_has_turbo; };
93  bool isRunning() const { return m_engine_is_running; };
94  int GetAutoMode() const { return static_cast<int>(m_auto_mode); };
95  char GetEngineType() const { return m_engine_type; };
96  float getIdleRPM() const { return m_engine_idle_rpm; };
97  float getMaxRPM() const { return m_engine_max_rpm; };
98  float getMinRPM() const { return m_engine_min_rpm; };
99  int getNumGears() const { return static_cast<int>(m_gear_ratios.size() - 2); };
100  int getNumGearsRanges() const{ return getNumGears() / 6 + 1; };
102  float GetEngineRpm() const { return m_cur_engine_rpm; }
103  float GetEngineTorque() const { return m_cur_engine_torque; }
105  float GetDriveRatio() { return m_gear_ratios[m_cur_gear + 1]; };
106  float GetEngineInertia() { return m_engine_inertia; };
108  float getEnginePower(float rpm);
109  float getTurboPower();
110  float getIdleMixture();
111  float getPrimeMixture();
112  int getAutoShift();
113  void autoSetAcc(float val);
114  void autoShiftDown();
115  void autoShiftSet(int mode);
116  void autoShiftUp();
117  void setManualClutch(float val);
118  void shift(int val);
119  void shiftTo(int val);
120  void updateShifts();
121  void UpdateEngineSim(float dt, int doUpdate);
122  void UpdateEngineAudio();
123  void UpdateInputEvents(float dt);
124 
125  // Ignition
126  void toggleContact();
127  bool hasContact() const { return m_contact; };
128 
130  {
137  };
138 
140  {
143  };
144 
145 private:
146 
148  {
154  };
155 
156  // Vehicle
158 
159  // Gearbox
165  std::vector<float> m_gear_ratios;
166 
167  // Clutch
172 
173  // Engine
181  float m_cur_acc;
184  float m_diff_ratio;
198 
199  // Ignition
200  bool m_contact;
201  bool m_starter;
202 
203  // Shifting
206  float m_shift_time;
211 
212  // Auto transmission
222  std::deque<float> m_rpms;
223  std::deque<float> m_accs;
224  std::deque<float> m_brakes;
225 
226  // Turbo
227 #define MAXTURBO 4
247 };
248 
251 
252 } // namespace RoR
RoR::EngineSim::m_braking_torque
float m_braking_torque
Engine attribute.
Definition: EngineSim.h:180
RoR::EngineSim::m_tcase_ratio
float m_tcase_ratio
Engine.
Definition: EngineSim.h:185
RoR::EngineSim::m_ref_wheel_revolutions
float m_ref_wheel_revolutions
Gears; estimated wheel revolutions based on current vehicle speed along the longi....
Definition: EngineSim.h:160
RoR::EngineSim::GetAutoMode
int GetAutoMode() const
Definition: EngineSim.h:94
RoR::EngineSim::UpdateEngineAudio
void UpdateEngineAudio()
Definition: EngineSim.cpp:791
RoR::EngineSim::SetEngineRpm
void SetEngineRpm(float rpm)
Set current engine RPM.
Definition: EngineSim.cpp:918
RoR::EngineSim::GetCrankFactor
float GetCrankFactor()
Definition: EngineSim.cpp:957
RoR::EngineSim::m_actor
ActorPtr m_actor
Definition: EngineSim.h:157
RoR::EngineSim::PushNetworkState
void PushNetworkState(float engine_rpm, float acc, float clutch, int gear, bool running, bool contact, char auto_mode, char auto_select=-1)
Sets current engine state;.
Definition: EngineSim.cpp:885
RoR::EngineSim::m_post_shift_clock
float m_post_shift_clock
Definition: EngineSim.h:205
RoR::EngineSim::getMaxRPM
float getMaxRPM() const
Definition: EngineSim.h:97
RoR::EngineSim::setManualClutch
void setManualClutch(float val)
Definition: EngineSim.cpp:1189
RoR::EngineSim::isRunning
bool isRunning() const
Definition: EngineSim.h:93
RoR::EngineSim::SetClutch
void SetClutch(float clutch)
Definition: EngineSim.cpp:970
RoR::EngineSim::m_air_pressure
float m_air_pressure
Definition: EngineSim.h:197
RoR::EngineSim::shift
void shift(int val)
Changes gear by a relative offset. Plays sounds.
Definition: EngineSim.cpp:1087
RoR::EngineSim::GetTurboPsi
float GetTurboPsi()
Definition: EngineSim.cpp:857
RoR::EngineSim::m_turbo_ver
int m_turbo_ver
Definition: EngineSim.h:228
RoR::EngineSim::m_hydropump_state
float m_hydropump_state
Engine.
Definition: EngineSim.h:187
RoR::EngineSim::GetGearRange
int GetGearRange()
low level gear changing
Definition: EngineSim.cpp:1052
RoR::EngineSim::MANUAL_RANGES
@ MANUAL_RANGES
Definition: EngineSim.h:153
RoR::EngineSim::m_engine_turbo_mode
int m_engine_turbo_mode
Engine attribute.
Definition: EngineSim.h:177
RoR::EngineSim::GetClutch
float GetClutch()
Definition: EngineSim.cpp:975
RoR::EngineSim::m_num_turbos
int m_num_turbos
Definition: EngineSim.h:231
RoR::EngineSim::autoShiftSet
void autoShiftSet(int mode)
Definition: EngineSim.cpp:1157
RoR::EngineSim::ToggleAutoShiftMode
void ToggleAutoShiftMode()
Definition: EngineSim.cpp:818
RoR::EngineSim::m_num_gears
int m_num_gears
Gears.
Definition: EngineSim.h:164
RoR::EngineSim::m_turbo_bov_rpm
float m_turbo_bov_rpm[MAXTURBO]
Definition: EngineSim.h:236
RoR::EngineSim::m_engine_has_air
bool m_engine_has_air
Engine attribute.
Definition: EngineSim.h:175
RoR::EngineSim::m_min_wastegate_psi
float m_min_wastegate_psi
Definition: EngineSim.h:239
RoR::EngineSim::m_antilag_rand_chance
float m_antilag_rand_chance
Definition: EngineSim.h:245
RoR::EngineSim::m_shift_val
int m_shift_val
Definition: EngineSim.h:210
RoR::EngineSim::m_full_rpm_range
float m_full_rpm_range
Definition: EngineSim.h:216
RoR::EngineSim::m_cur_engine_rpm
float m_cur_engine_rpm
Engine.
Definition: EngineSim.h:182
RoR::EngineSim::m_kickdown_delay_counter
int m_kickdown_delay_counter
Definition: EngineSim.h:221
RoR::EngineSim::m_torque_curve
TorqueCurve * m_torque_curve
Definition: EngineSim.h:196
RoR::EngineSim::MANUAL
@ MANUAL
Definition: EngineSim.h:151
RoR::EngineSim::m_cur_gear_range
int m_cur_gear_range
Gears.
Definition: EngineSim.h:163
RoR::EngineSim::REAR
@ REAR
Definition: EngineSim.h:131
RoR::EngineSim::m_turbo_engine_rpm_operation
float m_turbo_engine_rpm_operation
Definition: EngineSim.h:234
RoR::EngineSim::m_rpms
std::deque< float > m_rpms
Definition: EngineSim.h:222
RoR::EngineSim::m_turbo_wg_threshold_n
float m_turbo_wg_threshold_n
Definition: EngineSim.h:242
RoR::EngineSim::m_turbo_flutters
bool m_turbo_flutters
Definition: EngineSim.h:240
RoR::EngineSim::autoswitch
autoswitch
Definition: EngineSim.h:129
RoR::EngineSim::updateShifts
void updateShifts()
Changes gears. Plays sounds.
Definition: EngineSim.cpp:1116
RoR::EngineSim
A land vehicle engine + transmission.
Definition: EngineSim.h:35
RoR::TorqueCurve
This class loads and processes a torque curve for a vehicle.
Definition: TorqueCurve.h:42
RoR::EngineSim::getMinRPM
float getMinRPM() const
Definition: EngineSim.h:98
RoR::EngineSim::SetAutoMode
void SetAutoMode(RoR::SimGearboxMode mode)
Definition: EngineSim.cpp:847
RoR::EngineSim::HasTurbo
bool HasTurbo() const
Definition: EngineSim.h:92
RoR::EngineSim::m_cur_acc
float m_cur_acc
Engine.
Definition: EngineSim.h:181
RoR::EngineSim::GetDriveRatio
float GetDriveRatio()
Definition: EngineSim.h:105
RoR::EngineSim::m_engine_max_rpm
float m_engine_max_rpm
Engine attribute.
Definition: EngineSim.h:191
RoR::EngineSim::SetWheelSpin
void SetWheelSpin(float rpm)
Set current wheel spinning speed.
Definition: EngineSim.cpp:933
RoR::EngineSim::getTorqueCurve
TorqueCurve * getTorqueCurve()
Definition: EngineSim.h:101
RoR::EngineSim::m_antilag_min_rpm
float m_antilag_min_rpm
Definition: EngineSim.h:244
RoR::EngineSim::autoSetAcc
void autoSetAcc(float val)
Definition: EngineSim.cpp:1078
RoR::EngineSim::SetAcceleration
void SetAcceleration(float val)
Definition: EngineSim.cpp:852
RefCountingObjectPtr< Actor >
RoR::EngineSim::TWO
@ TWO
Definition: EngineSim.h:134
RoR::EngineSim::m_engine_type
char m_engine_type
Engine attribute {'t' = truck (default), 'c' = car}.
Definition: EngineSim.h:179
RoR::EngineSim::m_turbo_has_wastegate
bool m_turbo_has_wastegate
Definition: EngineSim.h:238
RoR::SimGearboxMode
SimGearboxMode
Definition: Application.h:192
RoR::ActorSpawner
Processes a RigDef::Document (parsed from 'truck' file format) into a simulated gameplay object (Acto...
Definition: ActorSpawner.h:70
RoR::EngineSim::~EngineSim
~EngineSim()
Definition: EngineSim.cpp:122
RoR::EngineSim::m_cur_clutch
float m_cur_clutch
Definition: EngineSim.h:170
RoR::EngineSim::UpdateEngineSim
void UpdateEngineSim(float dt, int doUpdate)
Definition: EngineSim.cpp:259
RoR::EngineSim::m_auto_cur_acc
float m_auto_cur_acc
Definition: EngineSim.h:215
RoR::EngineSim::getTurboPower
float getTurboPower()
Definition: EngineSim.cpp:1198
RoR::EngineSim::m_shifting
int m_shifting
Definition: EngineSim.h:209
RoR::EngineSim::m_engine_idle_rpm
float m_engine_idle_rpm
Engine attribute.
Definition: EngineSim.h:193
RoR::EngineSim::m_turbo_has_bov
bool m_turbo_has_bov
Definition: EngineSim.h:235
RoR::EngineSim::getIdleRPM
float getIdleRPM() const
Definition: EngineSim.h:96
RoR::EngineSim::getIdleMixture
float getIdleMixture()
Definition: EngineSim.cpp:1235
RoR::EngineSim::turbomode
turbomode
Definition: EngineSim.h:139
RoR::EngineSim::DRIVE
@ DRIVE
Definition: EngineSim.h:133
RoR::EngineSim::MANUALMODE
@ MANUALMODE
Definition: EngineSim.h:136
RoR::EngineSim::m_one_third_rpm_range
float m_one_third_rpm_range
Definition: EngineSim.h:217
RoR::EngineSim::shiftmodes
shiftmodes
Definition: EngineSim.h:147
RoR::EngineSim::GetEngineInertia
float GetEngineInertia()
Definition: EngineSim.h:106
RoR::EngineSim::SetTurboOptions
void SetTurboOptions(int type, float tinertiaFactor, int nturbos, float param1, float param2, float param3, float param4, float param5, float param6, float param7, float param8, float param9, float param10, float param11)
Sets turbo options.
Definition: EngineSim.cpp:129
RoR::EngineSim::m_engine_inertia
float m_engine_inertia
Engine attribute.
Definition: EngineSim.h:190
RoR::EngineSim::m_post_shift_time
float m_post_shift_time
Shift attribute.
Definition: EngineSim.h:204
RoR::EngineSim::m_engine_min_rpm
float m_engine_min_rpm
Engine attribute.
Definition: EngineSim.h:192
RoR::EngineSim::SetTCaseRatio
void SetTCaseRatio(float ratio)
Set current transfer case gear (reduction) ratio.
Definition: EngineSim.cpp:938
RoR::EngineSim::m_engine_stall_rpm
float m_engine_stall_rpm
Engine attribute.
Definition: EngineSim.h:194
RoR::EngineSim::m_upshift_delay_counter
int m_upshift_delay_counter
Definition: EngineSim.h:220
RoR::EngineSim::UpdateInputEvents
void UpdateInputEvents(float dt)
Definition: EngineSim.cpp:1263
RoR::EngineSim::GetTorque
float GetTorque()
Definition: EngineSim.cpp:913
RoR::EngineSim::ONE
@ ONE
Definition: EngineSim.h:135
RoR::EngineSim::m_cur_turbo_rpm
float m_cur_turbo_rpm[MAXTURBO]
Definition: EngineSim.h:229
RoR::EngineSim::GetAutoShiftMode
RoR::SimGearboxMode GetAutoShiftMode()
Definition: EngineSim.cpp:842
MAXTURBO
#define MAXTURBO
Definition: EngineSim.h:227
RoR::EngineSim::getNumGears
int getNumGears() const
Definition: EngineSim.h:99
RoR::EngineSim::m_post_shifting
int m_post_shifting
Definition: EngineSim.h:208
RoR::EngineSim::GetEngineRpm
float GetEngineRpm() const
Definition: EngineSim.h:102
RoR::EngineSim::m_engine_is_electric
bool m_engine_is_electric
Engine attribute.
Definition: EngineSim.h:174
RoR::EngineSim::m_auto_mode
int m_auto_mode
Transmission mode (.
Definition: EngineSim.h:213
RoR::EngineSim::hasContact
bool hasContact() const
Definition: EngineSim.h:127
Application.h
Central state/object manager and communications hub.
RoR::EngineSim::m_max_idle_mixture
float m_max_idle_mixture
Engine attribute.
Definition: EngineSim.h:189
RoR::EngineSim::m_half_rpm_range
float m_half_rpm_range
Definition: EngineSim.h:218
RoR::EngineSim::m_shift_clock
float m_shift_clock
Definition: EngineSim.h:207
RoR::EngineSim::SEMIAUTO
@ SEMIAUTO
Definition: EngineSim.h:150
RoR::EngineSim::GetAccToHoldRPM
float GetAccToHoldRPM()
estimate required throttle input to hold the current rpm
Definition: EngineSim.cpp:1072
RoR::EngineSim::m_min_idle_mixture
float m_min_idle_mixture
Engine attribute.
Definition: EngineSim.h:188
RoR::EngineSim::SetGear
void SetGear(int v)
low level gear changing
Definition: EngineSim.cpp:1047
RoR::EngineSim::GetGear
int GetGear()
low level gear changing
Definition: EngineSim.cpp:1041
RoR::EngineSim::EngineSim
EngineSim(float min_rpm, float max_rpm, float torque, std::vector< float > gears, float dratio, ActorPtr actor)
Definition: EngineSim.cpp:37
RoR::EngineSim::m_starter
bool m_starter
Ignition switch is in START position.
Definition: EngineSim.h:201
RoR::EngineSim::SetEngineOptions
void SetEngineOptions(float einertia, char etype, float eclutch, float ctime, float stime, float pstime, float irpm, float srpm, float maximix, float minimix, float ebraking)
Sets engine options.
Definition: EngineSim.cpp:197
RoR::EngineSim::NEW
@ NEW
Definition: EngineSim.h:142
RoR::EngineSim::m_cur_wheel_revolutions
float m_cur_wheel_revolutions
Gears; measured wheel revolutions.
Definition: EngineSim.h:161
RoR::EngineSim::toggleContact
void toggleContact()
Definition: EngineSim.cpp:985
RoR::EngineSim::AUTOMATIC
@ AUTOMATIC
Definition: EngineSim.h:149
RoR::EngineSim::StopEngine
void StopEngine()
stall engine
Definition: EngineSim.cpp:1062
RoR::EngineSim::autoShiftUp
void autoShiftUp()
Definition: EngineSim.cpp:1165
RoR::EngineSim::OLD
@ OLD
Definition: EngineSim.h:141
RoR::EngineSim::GetSmoke
float GetSmoke()
Definition: EngineSim.cpp:903
RoR::EngineSim::m_engine_has_turbo
bool m_engine_has_turbo
Engine attribute.
Definition: EngineSim.h:176
RoR::EngineSim::m_turbo_inertia_factor
float m_turbo_inertia_factor
Definition: EngineSim.h:230
RoR::EngineSim::getAutoShift
int getAutoShift()
Definition: EngineSim.cpp:1184
RoR::EngineSim::m_autoselect
autoswitch m_autoselect
Definition: EngineSim.h:214
RoR::EngineSim::m_cur_clutch_torque
float m_cur_clutch_torque
Definition: EngineSim.h:171
RoR::EngineSim::StartEngine
void StartEngine()
Quick engine start. Plays sounds.
Definition: EngineSim.cpp:998
RoR::EngineSim::m_engine_is_priming
bool m_engine_is_priming
Engine.
Definition: EngineSim.h:195
RoR::EngineSim::m_cur_gear
int m_cur_gear
Gears; Current gear {-1 = reverse, 0 = neutral, 1...21 = forward}.
Definition: EngineSim.h:162
RoR::EngineSim::m_diff_ratio
float m_diff_ratio
Engine.
Definition: EngineSim.h:184
RoR::EngineSim::MANUAL_STICK
@ MANUAL_STICK
Definition: EngineSim.h:152
RoR::EngineSim::GetAcceleration
float GetAcceleration()
Definition: EngineSim.cpp:880
RoR::EngineSim::m_gear_ratios
std::vector< float > m_gear_ratios
Gears.
Definition: EngineSim.h:165
RoR::EngineSim::OffStart
void OffStart()
Quick start of vehicle engine.
Definition: EngineSim.cpp:1016
RoR::EngineSim::shiftTo
void shiftTo(int val)
Changes gear to given value. Plays sounds.
Definition: EngineSim.cpp:1111
RoR::EngineSim::m_clutch_force
float m_clutch_force
Clutch attribute.
Definition: EngineSim.h:168
RoR::EngineSim::m_min_bov_psi
int m_min_bov_psi
Definition: EngineSim.h:237
RoR::EngineSim::m_contact
bool m_contact
Ignition switch is in ON/RUN position.
Definition: EngineSim.h:200
RoR::EngineSim::getEnginePower
float getEnginePower()
Definition: EngineSim.h:107
RoR::EngineSim::m_shift_behaviour
float m_shift_behaviour
Definition: EngineSim.h:219
RoR::EngineSim::GetClutchForce
float GetClutchForce()
Definition: EngineSim.cpp:980
RoR::EngineSim::getNumGearsRanges
int getNumGearsRanges() const
Definition: EngineSim.h:100
RoR::EngineSim::m_antilag_power_factor
float m_antilag_power_factor
Definition: EngineSim.h:246
RoR::EngineSim::getPrimeMixture
float getPrimeMixture()
Definition: EngineSim.cpp:1242
RoR::EngineSim::m_engine_addi_torque
float m_engine_addi_torque[MAXTURBO]
Definition: EngineSim.h:233
RoR::EngineSim::m_accs
std::deque< float > m_accs
Definition: EngineSim.h:223
RoR::EngineSim::NEUTRAL
@ NEUTRAL
Definition: EngineSim.h:132
RoR::EngineSim::SetHydroPumpWork
void SetHydroPumpWork(float work)
Set current hydro pump work.
Definition: EngineSim.cpp:928
RoR::EngineSim::m_clutch_time
float m_clutch_time
Clutch attribute.
Definition: EngineSim.h:169
RoR::EngineSim::GetInputShaftRpm
float GetInputShaftRpm()
Definition: EngineSim.h:104
RoR::EngineSim::autoShiftDown
void autoShiftDown()
Definition: EngineSim.cpp:1174
RoR::EngineSim::SetGearRange
void SetGearRange(int v)
low level gear changing
Definition: EngineSim.cpp:1057
RoR
Definition: AppContext.h:36
RoR::EngineSim::m_turbo_wg_threshold_p
float m_turbo_wg_threshold_p
Definition: EngineSim.h:241
RoR::EngineSim::m_shift_time
float m_shift_time
Shift attribute.
Definition: EngineSim.h:206
RoR::EngineSim::m_max_turbo_rpm
int m_max_turbo_rpm
Definition: EngineSim.h:232
RoR::EngineSim::GetEngineTorque
float GetEngineTorque() const
Definition: EngineSim.h:103
RoR::EngineSim::m_turbo_has_antilag
bool m_turbo_has_antilag
Definition: EngineSim.h:243
RoR::EngineSim::m_cur_engine_torque
float m_cur_engine_torque
Engine.
Definition: EngineSim.h:183
RoR::EngineSim::SetEnginePriming
void SetEnginePriming(bool p)
Set current engine prime.
Definition: EngineSim.cpp:923
RoR::EngineSim::m_brakes
std::deque< float > m_brakes
Definition: EngineSim.h:224
RoR::EngineSim::m_engine_is_running
bool m_engine_is_running
Engine state.
Definition: EngineSim.h:178
RoR::EngineSim::m_engine_torque
float m_engine_torque
Engine attribute.
Definition: EngineSim.h:186
RoR::EngineSim::GetEngineType
char GetEngineType() const
Definition: EngineSim.h:95