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
DashBoardManager.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
29#include "Application.h"
30#include "RefCountingObject.h"
32
33#include <MyGUI.h>
34
35#include <string>
36#include <vector>
37
38namespace RoR {
39
40#define DD_MAXCHAR 255
41#define DD_MAX_SCREWPROP 6
42#define DD_MAX_AEROENGINE 6
43#define DD_MAX_WING 6
44#define DD_MAX_GEOMETRIC_ANIMATIONS 10
45
46#define MAX_CONTROLS 1024
47#define NO_RTT_DASHBOARD 0
48
50{
51 bool value_bool = false;
52 int value_int = 0;
53 float value_float = 0.f;
55};
56
57enum
58{
59 DC_MIN, // Used for validation
60
66
67 DC_MAX // Used for validation
68};
69
70typedef struct dashData_t
71{
72 char type; // DC_*
74 bool enabled;
75 std::string name; // char string of name
76
78 {
79 enabled = false;
80 }
81
82 dashData_t(char type, std::string name) : type(type), name(name)
83 {
84 enabled = true;
85 }
86} dashData_t;
87
88// DashData enum definition
89// important: if you add things here, also change the initialization in the constructor
91{
99
105
106 DD_ENGINE_CLUTCH, // the engines clutch
107
108 DD_BRAKE, // the brake application in % 0-1
109 DD_ACCELERATOR, // accelerator pedal in %, 0-1
110
111 DD_ROLL, // roll of the chassis
112 DD_ROLL_CORR, // correction roll of the chassis
113 DD_ROLL_CORR_ACTIVE, // correction rolling active
114
116
119
121
125
126 // water things
127 DD_SCREW_THROTTLE_0, // throttle for screwprop 0
132 DD_SCREW_THROTTLE_5, // if you add some, change DD_MAX_SCREWPROP and DD_SCREW_STEER_*
133
134 DD_SCREW_STEER_0, // steering direction of screw 0
135 DD_SCREW_STEER_1, // steering direction of screw 1
136 DD_SCREW_STEER_2, // steering direction of screw 2
137 DD_SCREW_STEER_3, // steering direction of screw 3
138 DD_SCREW_STEER_4, // steering direction of screw 4
139 DD_SCREW_STEER_5, // steering direction of screw 4, if you add some, change DD_MAX_SCREWPROP and DD_SCREW_THROTTLE_*
140
141 DD_WATER_DEPTH, // how much water is under the boat
142 DD_WATER_SPEED, // speed in knots
143
144 // airplane things
151
158
165
166 DD_AIRSPEED, // speed in air
167
174
177
180
181 // Lights (mirrors RoRnet::Lightmask)
182
193
202
206
207 DD_MAX // This is the starting point for custom inputs
209
216
217// this class is NOT intended to be thread safe - performance is required
218class DashBoardManager : public RefCountingObject<DashBoardManager>
219{
220public:
222 virtual ~DashBoardManager() override;
223
224 int registerCustomInput(Ogre::String name, int dataType);
225
226 // Getter / Setter
227 bool _getBool(size_t key) { return key < data.size() ? data[key].data.value_bool : false; };
228 int _getInt(size_t key) { return data[key].data.value_int; };
229 float _getFloat(size_t key) { return data[key].data.value_float; };
230 float getNumeric(size_t key);
231 char* getChar(size_t key) { return key < data.size() ? data[key].data.value_char : nullptr; };
232 bool getEnabled(size_t key) { return key < data.size() ? data[key].enabled : false; };
233
234 void setBool(size_t key, bool val) { if (key < data.size()) data[key].data.value_bool = val; };
235 void setInt(size_t key, int val) { if (key < data.size()) data[key].data.value_int = val; };
236 void setFloat(size_t key, float val) { if (key < data.size()) data[key].data.value_float = val; };
237 void setChar(size_t key, const char* val) { if (key < data.size()) strncpy(data[key].data.value_char, val, DD_MAXCHAR); };
238
239 void setEnabled(size_t key, bool val) { if (key < data.size()) data[key].enabled = val; };
240
241 int getDataType(size_t key) { return key < data.size() ? data[key].type : DC_INVALID; };
242
243 int getLinkIDForName(Ogre::String& str);
244 std::string getLinkNameForID(DashData id);
245
246 void loadDashBoard(const std::string& filename, BitMask_t flags);
247
248 void update(float dt);
249 void updateFeatures();
250
251 bool wasDashboardHudLoaded() const { return m_hud_loaded; };
252 bool wasDashboardRttLoaded() const { return m_rtt_loaded; };
253
254 void setVisible(bool visibility);
255 void setVisible3d(bool visibility);
256 bool getVisible() { return visible; };
257 void windowResized();
258 size_t getInputCount() { return data.size(); }
259protected:
260 std::string determineLayoutFromDashboardMod(CacheEntryPtr& entry, std::string const& basename);
261 std::string determineTruckLayoutFromDashboardMod(Ogre::FileInfoListPtr& filelist);
263 bool visible = false;
264 std::vector<dashData_t> data;
265 std::vector<DashBoard*> m_dashboards;
266 bool m_hud_loaded = false;
267 bool m_rtt_loaded = false;
271};
272
274{
275public:
277 ~DashBoard();
278
279 void loadScript(std::string scriptFilename, ActorPtr associatedActor);
280
281 void setVisible(bool visible, bool smooth = true);
282 bool getVisible() { return visible; };
283
284 bool getIsTextureLayer() { return textureLayerNum > 0; }
285
286 void update(float dt);
287 void updateFeatures();
288
289 void windowResized();
290
291 float getSmoothNumeric(int linkID, float& lastVal);
292
293protected:
295 Ogre::String filename;
297 MyGUI::VectorWidgetPtr widgets;
298 MyGUI::WindowPtr mainWidget;
300 std::string prefix;
302 std::string rttLayer;
303 std::string rttTexture;
304
305 enum
306 {
316 };
317
318 enum
319 {
325 };
326
327 enum
328 {
332 };
333
335 {
336 int linkID; // DD_*
337
338 char animationType; // ANIM_*
339
340 float wmin; // rotation/offset whatever (widget min/max)
341 float wmax;
342 float vmin; // value min/max
343 float vmax;
344 char direction; // DIRECTION_*
345 float lastVal;
346 } layoutGeometricAnimation_t;
347
349 {
350 int linkID; // DD_*
351
352 char animationType; // ANIM_*
353
354 int condition; // CONDITION_*
356 char format[255]; // string format
357 char texture[255]; // texture filename
358 char format_neg_zero[255];
359 float lastVal;
360 } layoutGraphicalAnimation_t;
361
362 // linking attributes
363 typedef struct layoutLink_t
364 {
366
367 char name[255]; // widget name
368
372
373 MyGUI::Widget* widget;
374 MyGUI::RotatingSkin* rotImg;
375 MyGUI::ImageBox* img;
376 MyGUI::TextBox* txt;
377 MyGUI::IntSize initialSize;
378 MyGUI::IntPoint initialPosition;
379
381 } layoutLink_t;
382
383 void loadLayoutInternal();
384 void loadLayoutRecursive(MyGUI::WidgetPtr ptr);
385 bool parseLink(std::string& linkArgs, int& linkID, char& condition, float& conditionArgument, const std::string& filename, const std::string& name);
388};
389
390} // namespace RoR
Central state/object manager and communications hub.
#define BITMASK(OFFSET)
Definition BitFlags.h:10
uint32_t BitMask_t
Definition BitFlags.h:7
#define DD_MAXCHAR
#define MAX_CONTROLS
#define DD_MAX_GEOMETRIC_ANIMATIONS
Self reference-counting objects, as requred by AngelScript garbage collector.
MyGUI::WindowPtr mainWidget
Ogre::String filename
layoutLink_t controls[MAX_CONTROLS]
ScriptUnitID_t scriptUnitID
void setVisible(bool visible, bool smooth=true)
std::string rttTexture
void update(float dt)
float getSmoothNumeric(int linkID, float &lastVal)
void loadScript(std::string scriptFilename, ActorPtr associatedActor)
bool parseLink(std::string &linkArgs, int &linkID, char &condition, float &conditionArgument, const std::string &filename, const std::string &name)
std::string rttLayer
MyGUI::VectorWidgetPtr widgets
DashBoardManager * manager
void loadLayoutRecursive(MyGUI::WidgetPtr ptr)
void setVisible(bool visibility)
bool wasDashboardRttLoaded() const
bool wasDashboardHudLoaded() const
bool _getBool(size_t key)
char * getChar(size_t key)
bool getEnabled(size_t key)
std::vector< dashData_t > data
int getLinkIDForName(Ogre::String &str)
void setVisible3d(bool visibility)
void loadDashboardModDetails(CacheEntryPtr &entry)
void setEnabled(size_t key, bool val)
int getDataType(size_t key)
float _getFloat(size_t key)
std::string determineTruckLayoutFromDashboardMod(Ogre::FileInfoListPtr &filelist)
int registerCustomInput(Ogre::String name, int dataType)
virtual ~DashBoardManager() override
std::string getLinkNameForID(DashData id)
std::vector< DashBoard * > m_dashboards
void setChar(size_t key, const char *val)
float getNumeric(size_t key)
void setInt(size_t key, int val)
void loadDashBoard(const std::string &filename, BitMask_t flags)
std::string determineLayoutFromDashboardMod(CacheEntryPtr &entry, std::string const &basename)
void setBool(size_t key, bool val)
void setFloat(size_t key, float val)
@ DD_ENGINE_RPM
@ DD_AEROENGINE_THROTTLE_4
@ DD_SCREW_STEER_2
@ DD_CUSTOM_LIGHT6
custom light 6 on
@ DD_CUSTOM_LIGHT7
custom light 7 on
@ DD_ODOMETER_TOTAL
@ DD_CUSTOM_LIGHT10
custom light 10 on
@ DD_ENGINE_BATTERY
@ DD_SCREW_THROTTLE_2
@ DD_CUSTOM_LIGHT2
custom light 2 on
@ DD_CUSTOM_LIGHT4
custom light 4 on
@ DD_ENGINE_NUM_GEAR
current gear
@ DD_AEROENGINE_FAILED_4
@ DD_SCREW_THROTTLE_4
@ DD_AEROENGINE_RPM_1
@ DD_LIGHTS_LEGACY
Alias of 'sidelights'.
@ DD_ENGINE_SPEEDO_KPH
@ DD_AEROENGINE_FAILED_5
@ DD_SCREW_STEER_5
@ DD_ENGINE_AUTOGEAR_STRING
string like "<current gear>/<max gear>"
@ DD_AEROENGINE_RPM_5
@ DD_AEROENGINE_FAILED_2
@ DD_SCREW_STEER_1
@ DD_AEROENGINE_RPM_4
@ DD_PARKINGBRAKE
chassis pitch
@ DD_AEROENGINE_THROTTLE_2
@ DD_SCREW_THROTTLE_3
@ DD_CUSTOM_LIGHT9
custom light 9 on
@ DD_ENGINE_GEAR_STRING
@ DD_SIGNAL_WARNING
The warning-blink indicator is lit.
@ DD_SCREW_STEER_4
@ DD_CUSTOM_LIGHT3
custom light 3 on
@ DD_BRAKE_LIGHTS
@ DD_ANTILOCKBRAKE_MODE
@ DD_SIGNAL_TURNLEFT
Left blinker is lit.
@ DD_ENGINE_SPEEDO_MPH
speedo in kilometer per hour
@ DD_AEROENGINE_FAILED_3
@ DD_SCREW_THROTTLE_1
@ DD_ENGINE_IGNITION
turbo gauge
@ DD_AEROENGINE_RPM_0
@ DD_CUSTOM_LIGHT8
custom light 8 on
@ DD_ROLL_CORR_ACTIVE
@ DD_AEROENGINE_THROTTLE_5
@ DD_ENGINE_GEAR
clutch warning lamp
@ DD_AEROENGINE_THROTTLE_0
@ DD_AEROENGINE_FAILED_0
@ DD_AEROENGINE_FAILED_1
@ DD_AEROENGINE_RPM_2
@ DD_SCREW_THROTTLE_5
@ DD_LOCKED
parking brake status
@ DD_ENGINE_AUTO_GEAR
string like "P R N G"
@ DD_ODOMETER_USER
@ DD_SCREW_STEER_3
@ DD_REVERSE_LIGHT
@ DD_SIGNAL_TURNRIGHT
Right blinker is lit.
@ DD_CUSTOM_LIGHT5
custom light 5 on
@ DD_ENGINE_CLUTCH_WARNING
battery lamp
@ DD_LOW_PRESSURE
locked lamp
@ DD_ENGINE_TURBO
speedo in miles per hour
@ DD_AEROENGINE_RPM_3
@ DD_ENGINE_CLUTCH
automatic gear
@ DD_CUSTOM_LIGHT1
custom light 1 on
@ DD_ALTITUDE_STRING
@ DD_TRACTIONCONTROL_MODE
low pressure
@ DD_AEROENGINE_THROTTLE_3
@ DD_SCREW_STEER_0
@ DD_SCREW_THROTTLE_0
ties locked
@ DD_AEROENGINE_THROTTLE_1
@ LOADDASHBOARD_RTT_TEXTURE
Will be drawn to texture. Unless STACKABLE, it prevents the default dashboard from loading.
@ LOADDASHBOARD_SCREEN_HUD
Will be drawn to screen. Unless STACKABLE, it prevents the default dashboard from loading.
@ LOADDASHBOARD_STACKABLE
Allows loading multiple dashboards at once (by default there's only one for screen and one for RTT).
int ScriptUnitID_t
Unique sequentially generated ID of a loaded and running scriptin session. Use ScriptEngine::getScrip...
static const ScriptUnitID_t SCRIPTUNITID_INVALID
char format_neg_zero[255]
Test for undesired '-0.0' on display. Only for link type "format". Empty if not applicable.
dataContainer_t data
dashData_t(char type, std::string name)
char value_char[DD_MAXCHAR]