forked from RigsOfRods/rigs-of-rods
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Application.h
516 lines (453 loc) · 16.3 KB
/
Application.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
/*
This source file is part of Rigs of Rods
Copyright 2005-2012 Pierre-Michel Ricordel
Copyright 2007-2012 Thomas Fischer
Copyright 2013-2022 Petr Ohlidal
For more information, see http://www.rigsofrods.org/
Rigs of Rods is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3, as
published by the Free Software Foundation.
Rigs of Rods is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
*/
/// @file Application.h
/// @author Petr Ohlidal
/// @date 05/2014
/// @brief Central state/object manager and communications hub.
#pragma once
#include "BitFlags.h"
#include "CVar.h"
#include "ForwardDeclarations.h"
#include "Str.h"
#include <fmt/format.h>
#include <OgreStringConverter.h>
#include <assert.h>
#include <string>
#define ROR_ASSERT(_EXPR) assert(_EXPR)
#define CHARACTER_ANIM_NAME_LEN 10 // Restricted for networking
// Legacy macros
#define TOSTRING(x) Ogre::StringConverter::toString(x)
#define PARSEINT(x) Ogre::StringConverter::parseInt(x)
#define PARSEREAL(x) Ogre::StringConverter::parseReal(x)
#define HydraxLOG(msg) Ogre::LogManager::getSingleton().logMessage("[Hydrax] " + Ogre::String(msg));
namespace RoR {
// ------------------------------------------------------------------------------------------------
// Global definitions and enumerations
// ------------------------------------------------------------------------------------------------
/// @addtogroup GameState Game state
/// @{
/// @addtogroup MsgQueue Message queue
/// @{
/// Global gameplay message loop, see `struct Message` in GameContext.h
enum MsgType
{
MSG_INVALID,
// Application
MSG_APP_SHUTDOWN_REQUESTED,
MSG_APP_SCREENSHOT_REQUESTED,
MSG_APP_DISPLAY_FULLSCREEN_REQUESTED,
MSG_APP_DISPLAY_WINDOWED_REQUESTED,
MSG_APP_MODCACHE_LOAD_REQUESTED,
MSG_APP_MODCACHE_UPDATE_REQUESTED,
MSG_APP_MODCACHE_PURGE_REQUESTED,
MSG_APP_LOAD_SCRIPT_REQUESTED, //!< Payload = RoR::LoadScriptRequest* (owner)
MSG_APP_UNLOAD_SCRIPT_REQUESTED, //!< Payload = RoR::ScriptUnitId_t* (owner)
// Networking
MSG_NET_CONNECT_REQUESTED,
MSG_NET_CONNECT_STARTED,
MSG_NET_CONNECT_PROGRESS,
MSG_NET_CONNECT_SUCCESS,
MSG_NET_CONNECT_FAILURE,
MSG_NET_SERVER_KICK,
MSG_NET_DISCONNECT_REQUESTED,
MSG_NET_USER_DISCONNECT,
MSG_NET_RECV_ERROR,
MSG_NET_REFRESH_SERVERLIST_SUCCESS, //!< Payload = GUI::MpServerInfoVec* (owner)
MSG_NET_REFRESH_SERVERLIST_FAILURE, //!< Payload = RoR::CurlFailInfo* (owner)
MSG_NET_REFRESH_REPOLIST_SUCCESS, //!< Payload = GUI::ResourcesCollection* (owner)
MSG_NET_OPEN_RESOURCE_SUCCESS, //!< Payload = GUI::ResourcesCollection* (owner)
MSG_NET_REFRESH_REPOLIST_FAILURE, //!< Payload = RoR::CurlFailInfo* (owner)
MSG_NET_REFRESH_AI_PRESETS,
MSG_NET_DOWNLOAD_REPOTHUMB_SUCCESS, //!< Payload = int* (owner)
// Simulation
MSG_SIM_PAUSE_REQUESTED,
MSG_SIM_UNPAUSE_REQUESTED,
MSG_SIM_LOAD_TERRN_REQUESTED,
MSG_SIM_LOAD_SAVEGAME_REQUESTED,
MSG_SIM_UNLOAD_TERRN_REQUESTED,
MSG_SIM_SPAWN_ACTOR_REQUESTED, //!< Payload = RoR::ActorSpawnRequest* (owner)
MSG_SIM_MODIFY_ACTOR_REQUESTED, //!< Payload = RoR::ActorModifyRequest* (owner)
MSG_SIM_DELETE_ACTOR_REQUESTED, //!< Payload = RoR::ActorPtr* (owner)
MSG_SIM_SEAT_PLAYER_REQUESTED, //!< Payload = RoR::ActorPtr (owner) | nullptr
MSG_SIM_TELEPORT_PLAYER_REQUESTED, //!< Payload = Ogre::Vector3* (owner)
MSG_SIM_HIDE_NET_ACTOR_REQUESTED, //!< Payload = ActorPtr* (owner)
MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED, //!< Payload = ActorPtr* (owner)
MSG_SIM_SCRIPT_EVENT_TRIGGERED, //!< Payload = RoR::ScriptEventArgs* (owner)
MSG_SIM_SCRIPT_CALLBACK_QUEUED, //!< Payload = RoR::ScriptCallbackArgs* (owner)
MSG_SIM_ACTOR_LINKING_REQUESTED, //!< Payload = RoR::ActorLinkingRequest* (owner)
// GUI
MSG_GUI_OPEN_MENU_REQUESTED,
MSG_GUI_CLOSE_MENU_REQUESTED,
MSG_GUI_OPEN_SELECTOR_REQUESTED, //!< Payload = LoaderType* (owner), Description = GUID | empty
MSG_GUI_CLOSE_SELECTOR_REQUESTED,
MSG_GUI_MP_CLIENTS_REFRESH,
MSG_GUI_SHOW_MESSAGE_BOX_REQUESTED, //!< Payload = MessageBoxConfig* (owner)
MSG_GUI_DOWNLOAD_PROGRESS,
MSG_GUI_DOWNLOAD_FINISHED,
// Editing
MSG_EDI_MODIFY_GROUNDMODEL_REQUESTED, //!< Payload = RoR::ground_model_t* (weak)
MSG_EDI_ENTER_TERRN_EDITOR_REQUESTED,
MSG_EDI_LEAVE_TERRN_EDITOR_REQUESTED,
MSG_EDI_RELOAD_BUNDLE_REQUESTED, //!< Payload = RoR::CacheEntry* (weak)
};
const char* MsgTypeToString(MsgType type);
/// @} // addtogroup MsgQueue
enum class AppState
{
BOOTSTRAP, //!< Initial state
MAIN_MENU,
SIMULATION,
SHUTDOWN,
PRINT_HELP_EXIT,
PRINT_VERSION_EXIT,
};
enum class MpState
{
DISABLED, //!< Not connected for whatever reason.
CONNECTING,
CONNECTED,
};
enum class SimState
{
OFF,
RUNNING,
PAUSED,
EDITOR_MODE //!< Hacky, but whatever... added by Ulteq, 2016
};
/// @} // addtogroup GameState
/// @addtogroup Gameplay
/// @{
/// @addtogroup Trucks
/// @{
enum class SimGearboxMode
{
AUTO, //!< Automatic shift
SEMI_AUTO, //!< Manual shift with auto clutch
MANUAL, //!< Fully manual: sequential shift
MANUAL_STICK, //!< Fully manual: stick shift
MANUAL_RANGES, //!< Fully manual: stick shift with ranges
};
std::string ToLocalizedString(SimGearboxMode e);
/// @}
/// @}
enum class GfxShadowType
{
NONE,
PSSM
};
std::string ToLocalizedString(GfxShadowType e);
enum class GfxExtCamMode
{
NONE,
STATIC,
PITCHING,
};
std::string ToLocalizedString(GfxExtCamMode e);
enum class GfxTexFilter
{
NONE,
BILINEAR,
TRILINEAR,
ANISOTROPIC,
};
std::string ToLocalizedString(GfxTexFilter e);
enum class GfxVegetation
{
NONE,
x20PERC,
x50PERC,
FULL,
};
std::string ToLocalizedString(GfxVegetation e);
enum class GfxFlaresMode
{
NONE, //!< None (fastest)
NO_LIGHTSOURCES, //!< No light sources
CURR_VEHICLE_HEAD_ONLY, //!< Only current vehicle, main lights
ALL_VEHICLES_HEAD_ONLY, //!< All vehicles, main lights
ALL_VEHICLES_ALL_LIGHTS, //!< All vehicles, all lights
};
std::string ToLocalizedString(GfxFlaresMode e);
enum class GfxWaterMode
{
NONE, //!< None
BASIC, //!< Basic (fastest)
REFLECT, //!< Reflection
FULL_FAST, //!< Reflection + refraction (speed optimized)
FULL_HQ, //!< Reflection + refraction (quality optimized)
HYDRAX, //!< HydraX
};
std::string ToLocalizedString(GfxWaterMode e);
enum class GfxSkyMode
{
SANDSTORM, //!< Sandstorm (fastest)
CAELUM, //!< Caelum (best looking, slower)
SKYX, //!< SkyX (best looking, slower)
};
std::string ToLocalizedString(GfxSkyMode e);
enum class IoInputGrabMode
{
NONE,
ALL,
DYNAMIC,
};
std::string ToLocalizedString(IoInputGrabMode e);
enum class SimResetMode
{
HARD = 0, // 'sim_soft_reset=false'
SOFT = 1 // 'sim_soft_reset=true'
};
std::string ToLocalizedString(SimResetMode e);
enum VisibilityMasks
{
DEPTHMAP_ENABLED = BITMASK(1),
DEPTHMAP_DISABLED = BITMASK(2),
HIDE_MIRROR = BITMASK(3),
};
enum LoaderType //!< Operation mode for GUI::MainSelector
{
LT_None,
LT_Terrain, // Invocable from GUI; No script alias, used in main menu
LT_Vehicle, // Script "vehicle", ext: truck car
LT_Truck, // Script "truck", ext: truck car
LT_Car, // Script "car", ext: car
LT_Boat, // Script "boat", ext: boat
LT_Airplane, // Script "airplane", ext: airplane
LT_Trailer, // Script "trailer", ext: trailer
LT_Train, // Script "train", ext: train
LT_Load, // Script "load", ext: load
LT_Extension, // Script "extension", ext: trailer load
LT_Skin, // No script alias, invoked automatically
LT_AllBeam // Invocable from GUI; Script "all", ext: truck car boat airplane train load
};
// ------------------------------------------------------------------------------------------------
// Global variables
// ------------------------------------------------------------------------------------------------
namespace App {
// App
extern CVar* app_state;
extern CVar* app_language;
extern CVar* app_country;
extern CVar* app_skip_main_menu;
extern CVar* app_async_physics;
extern CVar* app_num_workers;
extern CVar* app_screenshot_format;
extern CVar* app_rendersys_override;
extern CVar* app_extra_mod_path;
extern CVar* app_force_cache_purge;
extern CVar* app_force_cache_update;
extern CVar* app_disable_online_api;
extern CVar* app_config_long_names;
extern CVar* app_custom_scripts;
extern CVar* app_recent_scripts;
// Simulation
extern CVar* sim_state;
extern CVar* sim_terrain_name;
extern CVar* sim_terrain_gui_name;
extern CVar* sim_spawn_running;
extern CVar* sim_replay_enabled;
extern CVar* sim_replay_length;
extern CVar* sim_replay_stepping;
extern CVar* sim_realistic_commands;
extern CVar* sim_races_enabled;
extern CVar* sim_no_collisions;
extern CVar* sim_no_self_collisions;
extern CVar* sim_gearbox_mode;
extern CVar* sim_soft_reset_mode;
extern CVar* sim_quickload_dialog;
extern CVar* sim_live_repair_interval; //!< Hold EV_COMMON_REPAIR_TRUCK to enter LiveRepair mode. 0 or negative interval disables.
// Multiplayer
extern CVar* mp_state;
extern CVar* mp_join_on_startup;
extern CVar* mp_chat_auto_hide;
extern CVar* mp_hide_net_labels;
extern CVar* mp_hide_own_net_label;
extern CVar* mp_pseudo_collisions;
extern CVar* mp_server_host;
extern CVar* mp_server_port;
extern CVar* mp_server_password;
extern CVar* mp_player_name;
extern CVar* mp_player_token;
extern CVar* mp_api_url;
// New remote API
extern CVar* remote_query_url;
// Diagnostic
extern CVar* diag_auto_spawner_report;
extern CVar* diag_camera;
extern CVar* diag_trace_globals;
extern CVar* diag_rig_log_node_import;
extern CVar* diag_rig_log_node_stats;
extern CVar* diag_truck_mass;
extern CVar* diag_envmap;
extern CVar* diag_videocameras;
extern CVar* diag_preset_terrain;
extern CVar* diag_preset_spawn_pos;
extern CVar* diag_preset_spawn_rot;
extern CVar* diag_preset_vehicle;
extern CVar* diag_preset_veh_config;
extern CVar* diag_preset_veh_enter;
extern CVar* diag_log_console_echo;
extern CVar* diag_log_beam_break;
extern CVar* diag_log_beam_deform;
extern CVar* diag_log_beam_trigger;
extern CVar* diag_simple_materials;
extern CVar* diag_warning_texture;
extern CVar* diag_hide_broken_beams;
extern CVar* diag_hide_beam_stress;
extern CVar* diag_hide_wheel_info;
extern CVar* diag_hide_wheels;
extern CVar* diag_hide_nodes;
extern CVar* diag_terrn_log_roads;
extern CVar* diag_actor_dump;
// System
extern CVar* sys_process_dir;
extern CVar* sys_user_dir;
extern CVar* sys_config_dir;
extern CVar* sys_cache_dir;
extern CVar* sys_thumbnails_dir;
extern CVar* sys_logs_dir;
extern CVar* sys_resources_dir;
extern CVar* sys_profiler_dir;
extern CVar* sys_savegames_dir;
extern CVar* sys_screenshot_dir;
// OS command line
extern CVar* cli_server_host;
extern CVar* cli_server_port;
extern CVar* cli_preset_vehicle;
extern CVar* cli_preset_veh_config;
extern CVar* cli_preset_terrain;
extern CVar* cli_preset_spawn_pos;
extern CVar* cli_preset_spawn_rot;
extern CVar* cli_preset_veh_enter;
extern CVar* cli_force_cache_update;
extern CVar* cli_resume_autosave;
extern CVar* cli_custom_scripts;
// Input - Output
extern CVar* io_analog_smoothing;
extern CVar* io_analog_sensitivity;
extern CVar* io_blink_lock_range;
extern CVar* io_ffb_enabled;
extern CVar* io_ffb_camera_gain;
extern CVar* io_ffb_center_gain;
extern CVar* io_ffb_master_gain;
extern CVar* io_ffb_stress_gain;
extern CVar* io_input_grab_mode;
extern CVar* io_arcade_controls;
extern CVar* io_hydro_coupling;
extern CVar* io_outgauge_mode;
extern CVar* io_outgauge_ip;
extern CVar* io_outgauge_port;
extern CVar* io_outgauge_delay;
extern CVar* io_outgauge_id;
extern CVar* io_discord_rpc;
// Audio
extern CVar* audio_master_volume;
extern CVar* audio_enable_creak;
extern CVar* audio_device_name;
extern CVar* audio_menu_music;
// Graphics
extern CVar* gfx_flares_mode;
extern CVar* gfx_polygon_mode;
extern CVar* gfx_shadow_type;
extern CVar* gfx_extcam_mode;
extern CVar* gfx_sky_mode;
extern CVar* gfx_sky_time_cycle;
extern CVar* gfx_sky_time_speed;
extern CVar* gfx_texture_filter;
extern CVar* gfx_vegetation_mode;
extern CVar* gfx_water_mode;
extern CVar* gfx_anisotropy;
extern CVar* gfx_water_waves;
extern CVar* gfx_particles_mode;
extern CVar* gfx_enable_videocams;
extern CVar* gfx_window_videocams;
extern CVar* gfx_surveymap_icons;
extern CVar* gfx_declutter_map;
extern CVar* gfx_envmap_enabled;
extern CVar* gfx_envmap_rate;
extern CVar* gfx_shadow_quality;
extern CVar* gfx_skidmarks_mode;
extern CVar* gfx_sight_range;
extern CVar* gfx_camera_height;
extern CVar* gfx_fov_external;
extern CVar* gfx_fov_external_default;
extern CVar* gfx_fov_internal;
extern CVar* gfx_fov_internal_default;
extern CVar* gfx_static_cam_fov_exp;
extern CVar* gfx_fixed_cam_tracking;
extern CVar* gfx_fps_limit;
extern CVar* gfx_speedo_digital;
extern CVar* gfx_speedo_imperial;
extern CVar* gfx_flexbody_cache;
extern CVar* gfx_reduce_shadows;
extern CVar* gfx_enable_rtshaders;
extern CVar* gfx_alt_actor_materials;
// Flexbodies
extern CVar* flexbody_defrag_enabled;
extern CVar* flexbody_defrag_const_penalty;
extern CVar* flexbody_defrag_prog_up_penalty;
extern CVar* flexbody_defrag_prog_down_penalty;
extern CVar* flexbody_defrag_reorder_indices;
extern CVar* flexbody_defrag_reorder_texcoords;
extern CVar* flexbody_defrag_invert_lookup;
// GUI
extern CVar* ui_show_live_repair_controls;
// ------------------------------------------------------------------------------------------------
// Global objects
// ------------------------------------------------------------------------------------------------
// Getters
AppContext* GetAppContext();
ContentManager* GetContentManager();
OverlayWrapper* GetOverlayWrapper();
GUIManager* GetGuiManager();
Console* GetConsole();
InputEngine* GetInputEngine();
CacheSystem* GetCacheSystem();
MumbleIntegration* GetMumble();
ThreadPool* GetThreadPool();
CameraManager* GetCameraManager();
GfxScene* GetGfxScene();
SoundScriptManager* GetSoundScriptManager();
LanguageEngine* GetLanguageEngine();
ScriptEngine* GetScriptEngine();
Network* GetNetwork();
GameContext* GetGameContext();
OutGauge* GetOutGauge();
DiscordRpc* GetDiscordRpc();
// Factories
void CreateOverlayWrapper();
void CreateGuiManager();
void CreateInputEngine();
void CreateMumble();
void CreateThreadPool();
void CreateCameraManager();
void CreateGfxScene();
void CreateSoundScriptManager();
void CreateScriptEngine();
// Setters
void SetCacheSystem (CacheSystem* obj);
// Cleanups
void DestroyOverlayWrapper();
} // namespace App
// ------------------------------------------------------------------------------------------------
// Logging
// ------------------------------------------------------------------------------------------------
void Log(const char* msg); //!< The ultimate, application-wide logging function. Adds a line (any length) in 'RoR.log' file.
void LogFormat(const char* format, ...); //!< Improved logging utility. Uses fixed 2Kb buffer.
} // namespace RoR
inline void LOG(const char* msg) { RoR::Log(msg); } //!< Legacy alias - formerly a macro
inline void LOG(std::string const & msg) { RoR::Log(msg.c_str()); } //!< Legacy alias - formerly a macro