-
Notifications
You must be signed in to change notification settings - Fork 1k
/
main.cpp
2867 lines (2609 loc) · 105 KB
/
main.cpp
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2004-2015 Steve Baker <sjbaker1@airmail.net>
// Copyright (C) 2011-2015 Joerg Henrichs, Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/**
* \mainpage SuperTuxKart developer documentation
*
* This document contains the developer documentation for SuperTuxKart,
* including the list of modules, the list of classes, the API reference,
* and some pages that describe in more depth some parts of the code/engine.
*
* \section Overview
*
* Here is an overview of the high-level interactions between modules :
\dot
digraph interaction {
# race -> modes
race -> tracks
race -> karts
# modes -> tracks
# modes -> karts
tracks -> graphics
karts -> graphics
tracks -> items
items -> graphics
animations -> graphics
graphics -> "Antarctica/irrlicht"
# guiengine -> irrlicht
# states_screens -> guiengine
# input -> states_screens
input -> guiengine
guiengine -> font_system
karts -> physics
physics -> karts
tracks -> physics
ai -> controller
controller -> karts
input -> controller
tracks -> animations
physics -> animations
animations -> physics
karts -> audio
physics -> audio
"translations\n(too many connections\nto draw)"
"configuration\n(too many connections\nto draw)"
addons -> tracks
addons -> karts
guiengine -> addons
guiengine -> race
addons -> online_manager
challenges -> race
# challenges -> modes
guiengine -> challenges
online_manager -> addons
online_manager -> "STK Server"
"STK Server" -> online_manager
karts -> replay
replay
# force karts and tracks on the same level, looks better this way
subgraph {
rank = same; karts; tracks;
}
}
\enddot
Note that this graph is only an approximation because the real one would be
much too complicated :)
\section Modules
\li \ref addonsgroup :
Handles add-ons that can be downloaded.
\li \ref animations :
This module manages interpolation-based animation (of position, rotation
and/or scale)
\li \ref audio :
This module handles audio (sound effects and music).
\li \ref challenges :
This module handles the challenge system, which locks features (tracks, karts
modes, etc.) until the user completes some task.
\li \ref config :
This module handles the user configuration, the supertuxkart configuration
file (which contains options usually not edited by the player) and the input
configuration file.
\li \ref font :
This module stores font files and tools used to draw characters in STK.
\li \ref graphics :
This module contains the core graphics engine, that is mostly a thin layer
on top of irrlicht providing some additional features we need for STK
(like particles, more scene node types, mesh manipulation tools, material
management, etc...)
\li \ref guiengine :
Contains the generic GUI engine (contains the widgets and the backing logic
for event handling, the skin, screens and dialogs). See module @ref states_screens
for the actual STK GUI screens. Note that all input comes through this module
too.
\li \ref widgetsgroup :
Contains the various types of widgets supported by the GUI engine.
\li \ref input :
Contains classes for input management (keyboard and gamepad)
\li \ref io :
Contains generic utility classes for file I/O (especially XML handling).
\li \ref items :
Defines the various collectibles and weapons of STK.
\li \ref karts :
Contains classes that deal with the properties, models and physics
of karts.
\li \ref controller :
Contains kart controllers, which are either human players or AIs
(this module thus contains the AIs)
\li \ref modes :
Contains the logic for the various game modes (race, follow the leader,
battle, etc.)
\li \ref physics :
Contains various physics utilities.
\li \ref race :
Contains the race information that is conceptually above what you can find
in group Modes. Handles highscores, grands prix, number of karts, which
track was selected, etc.
\li \ref states_screens :
Contains the various screens and dialogs of the STK user interface,
using the facilities of the guiengine module. Also contains the
stack of menus and handles state management (in-game vs menu).
\li \ref tracks :
Contains information about tracks, namely drivelines, checklines and track
objects.
\li \ref tutorial :
Work in progress
*/
#ifdef WIN32
# ifdef __CYGWIN__
# include <unistd.h>
# endif
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# ifdef _MSC_VER
# include <direct.h>
# endif
#else
# include <signal.h>
# include <unistd.h>
#endif
#ifdef ANDROID
#include <SDL_system.h>
#include <jni.h>
#endif
#ifdef __SWITCH__
extern "C" {
#include <sys/iosupport.h>
#include <switch/kernel/svc.h>
#include <switch/runtime/nxlink.h>
#include <switch/runtime/diag.h>
#include <switch/services/ssl.h>
#define Event libnx_Event
#include <switch/services/set.h>
#include <switch/services/applet.h>
#include <switch/services/nifm.h>
#include <switch/runtime/pad.h>
#undef Event
#include <switch/runtime/devices/socket.h>
}
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#endif
#include <stdexcept>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <limits>
#include <IEventReceiver.h>
#include "main_loop.hpp"
#include "achievements/achievements_manager.hpp"
#include "addons/addons_manager.hpp"
#include "addons/news_manager.hpp"
#include "audio/music_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "challenges/story_mode_timer.hpp"
#include "challenges/unlock_manager.hpp"
#include "config/hardware_stats.hpp"
#include "config/player_manager.hpp"
#include "config/player_profile.hpp"
#include "config/stk_config.hpp"
#include "config/user_config.hpp"
#include "font/font_manager.hpp"
#include "graphics/camera/camera.hpp"
#include "graphics/camera/camera_debug.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/graphics_restrictions.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/particle_kind_manager.hpp"
#include "graphics/referee.hpp"
#include "graphics/sp/sp_base.hpp"
#include "graphics/sp/sp_shader.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/event_handler.hpp"
#include "guiengine/dialog_queue.hpp"
#include "guiengine/message_queue.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "input/keyboard_device.hpp"
#include "input/wiimote_manager.hpp"
#include "io/file_manager.hpp"
#include "items/attachment_manager.hpp"
#include "items/item_manager.hpp"
#include "items/network_item_manager.hpp"
#include "items/powerup_manager.hpp"
#include "items/projectile_manager.hpp"
#include "karts/combined_characteristic.hpp"
#include "karts/controller/ai_base_controller.hpp"
#include "karts/controller/network_ai_controller.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "karts/official_karts.hpp"
#include "modes/cutscene_world.hpp"
#include "modes/demo_world.hpp"
#include "network/protocols/connect_to_server.hpp"
#include "network/protocols/client_lobby.hpp"
#include "network/protocols/server_lobby.hpp"
#include "network/network.hpp"
#include "network/network_config.hpp"
#include "network/network_string.hpp"
#include "network/protocols/connect_to_server.hpp"
#include "network/protocols/client_lobby.hpp"
#include "network/protocols/server_lobby.hpp"
#include "network/race_event_manager.hpp"
#include "network/rewind_manager.hpp"
#include "network/rewind_queue.hpp"
#include "network/server.hpp"
#include "network/server_config.hpp"
#include "network/servers_manager.hpp"
#include "network/socket_address.hpp"
#include "network/stk_host.hpp"
#include "network/stk_peer.hpp"
#include "online/profile_manager.hpp"
#include "online/request_manager.hpp"
#include "race/grand_prix_manager.hpp"
#include "race/highscore_manager.hpp"
#include "race/history.hpp"
#include "race/race_manager.hpp"
#include "replay/replay_play.hpp"
#include "replay/replay_recorder.hpp"
#include "states_screens/main_menu_screen.hpp"
#include "states_screens/online/networking_lobby.hpp"
#include "states_screens/online/register_screen.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/options/user_screen.hpp"
#include "states_screens/dialogs/init_android_dialog.hpp"
#include "states_screens/dialogs/message_dialog.hpp"
#include "tips/tips_manager.hpp"
#include "tracks/arena_graph.hpp"
#include "tracks/track.hpp"
#include "tracks/track_manager.hpp"
#include "utils/command_line.hpp"
#include "utils/constants.hpp"
#include "utils/crash_reporting.hpp"
#include "utils/leak_check.hpp"
#include "utils/log.hpp"
#include "mini_glm.hpp"
#include "utils/profiler.hpp"
#include "utils/stk_process.hpp"
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
#include "io/rich_presence.hpp"
#include <IrrlichtDevice.h>
static void cleanSuperTuxKart();
static void cleanUserConfig();
void runUnitTests();
// ============================================================================
// gamepad visualisation screen
// ============================================================================
void gamepadVisualisation()
{
#ifndef SERVER_ONLY
input_manager = new InputManager();
#define GAMEPAD_COUNT 8 // const won't work
class EventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent (const irr::SEvent &event)
{
switch (event.EventType)
{
case EET_KEY_INPUT_EVENT:
{
const SEvent::SKeyInput& evt = event.KeyInput;
if (evt.PressedDown)
{
if (evt.Key == IRR_KEY_RETURN ||
evt.Key == IRR_KEY_ESCAPE ||
evt.Key == IRR_KEY_SPACE)
{
exit(0);
}
}
}
default:
// don't care about others
break;
}
return true;
}
};
EventReceiver* events = new EventReceiver();
irr_driver->getDevice()->setEventReceiver(events);
while (true)
{
if (!irr_driver->getDevice()->run()) break;
input_manager->update(0);
video::IVideoDriver* driver = irr_driver->getVideoDriver();
const core::dimension2du size = driver ->getCurrentRenderTargetSize();
driver->beginScene(true, true, video::SColor(255,0,0,0));
for (unsigned n = 0; n < input_manager->getGamepadCount(); n++)
{
if (n >= GAMEPAD_COUNT)
break;
const irr::SEvent& g = input_manager->getEventForGamePad(n);
const int MARGIN = 10;
const int x = (n & 1 ? size.Width/2 + MARGIN : MARGIN );
const int w = size.Width/2 - MARGIN*2;
const int h = size.Height/(GAMEPAD_COUNT/2) - MARGIN*2;
const int y = size.Height/(GAMEPAD_COUNT/2)*(n/2) + MARGIN;
driver->draw2DRectangleOutline( core::recti(x, y, x+w, y+h) );
const int btn_y = y + 5;
const int btn_x = x + 5;
const int BTN_SIZE =
(w - 10)/SEvent::SJoystickEvent::NUMBER_OF_BUTTONS;
for (int b=0; b<SEvent::SJoystickEvent::NUMBER_OF_BUTTONS; b++)
{
core::position2di pos(btn_x + b*BTN_SIZE, btn_y);
core::dimension2di size(BTN_SIZE, BTN_SIZE);
if (g.JoystickEvent.IsButtonPressed(b))
{
driver->draw2DRectangle (video::SColor(255,255,0,0),
core::recti(pos, size));
}
driver->draw2DRectangleOutline( core::recti(pos, size) );
}
const int axis_y = btn_y + BTN_SIZE + 5;
const int axis_x = btn_x;
const int axis_w = w - 10;
const int axis_h = (h - BTN_SIZE - 15)
/ SEvent::SJoystickEvent::NUMBER_OF_AXES;
for (int a=0; a<SEvent::SJoystickEvent::NUMBER_OF_AXES; a++)
{
const float rate = g.JoystickEvent.Axis[a] / 32767.0f;
core::position2di pos(axis_x, axis_y + a*axis_h);
core::dimension2di size(axis_w, axis_h);
// Assume a default deadzone value of 4096
const bool deadzone = (abs(g.JoystickEvent.Axis[a]) < 4096);
core::recti fillbar(core::position2di(axis_x + axis_w/2,
axis_y + a*axis_h),
core::dimension2di( (int)(axis_w/2*rate),
axis_h) );
fillbar.repair(); // dimension may be negative
driver->draw2DRectangle (deadzone ? video::SColor(255,255,0,0)
: video::SColor(255,0,255,0),
fillbar);
driver->draw2DRectangleOutline( core::recti(pos, size) );
}
}
driver->endScene();
}
#endif
} // gamepadVisualisation
// ============================================================================
/** Sets the hat mesh name depending on the current christmas mode
* m_xmas_mode (0: use current date, 1: always on, 2: always off).
*/
void handleXmasMode()
{
bool xmas = false;
switch(UserConfigParams::m_xmas_mode)
{
case 0:
{
int day, month;
StkTime::getDate(&day, &month);
// Christmat hats are shown between 17. of December
// and 5th of January
xmas = (month == 12 && day>=17) || (month == 1 && day <=5);
break;
}
case 1: xmas = true; break;
default: xmas = false; break;
} // switch m_xmas_mode
if(xmas)
kart_properties_manager->setHatMeshName("christmas_hat.spm");
} // handleXmasMode
// ============================================================================
/** Determines if Easter Ears should be used
* m_easter_ear_mode (0: use current date, 1: always on, 2: always off).
*/
bool isEasterMode(int day, int month, int year, int before_after_days)
{
if (UserConfigParams::m_easter_ear_mode == 1) {
return true;
}
if (UserConfigParams::m_easter_ear_mode == 0)
{
// Compute Easter date, based on wikipedia formula
// http://en.wikipedia.org/wiki/Computus
int a = year % 19;
int b = year >> 2;
int c = int(floor(b / 25)) + 1;
int d = (c * 3) >> 2;
int e = ((a * 19) - int(floor((c * 8 + 5) / 25)) + d + 15) % 30;
e += (29578 - a - e * 32) >> 10;
e -= ((year % 7) + b - d + e + 2) % 7;
d = e >> 5;
int easter_day = e - d * 31;
int easter_month = d + 3;
int easter_start_day = easter_day - before_after_days;
int easter_start_month = easter_month;
if (easter_start_day < 1)
{
easter_start_day += 31; // Month is April, going into March
easter_start_month--;
}
int easter_end_day = easter_day + before_after_days;
int easter_end_month = easter_month;
int month_length = easter_end_month == 3 ? 31 : 30;
if (easter_end_day > month_length)
{
easter_end_day -= month_length;
easter_end_month++;
}
return (month > easter_start_month || (month == easter_start_month && day >= easter_start_day)) &&
(month < easter_end_month || (month == easter_end_month && day <= easter_end_day));
}
return false;
} // isEasterMode(day, month, year, before_after_days)
// ============================================================================
/** Wrapper around handleEasterEarMode(day, month, year, before_after_days).
*/
void handleEasterEarMode()
{
int day, month, year;
StkTime::getDate(&day, &month, &year);
if (isEasterMode(day, month, year, /*before_after_days*/5))
kart_properties_manager->setHatMeshName("easter_ears.spm");
} // handleEasterMode
// ============================================================================
/** This function sets up all data structure for an immediate race start.
* It is used when the -N or -R command line options are used.
*/
void setupRaceStart()
{
// Skip the start screen. This esp. means that no login screen is
// displayed (if necessary), so we have to make sure there is
// a current player
PlayerManager::get()->enforceCurrentPlayer();
InputDevice *device;
// Use keyboard 0 by default in --no-start-screen
device = input_manager->getDeviceManager()->getKeyboard(0);
// Create player and associate player with keyboard
StateManager::get()->createActivePlayer(
PlayerManager::get()->getPlayer(0), device);
if (!kart_properties_manager->getKart(UserConfigParams::m_default_kart))
{
Log::warn("main", "Kart '%s' is unknown so will use the "
"default kart.",
UserConfigParams::m_default_kart.c_str());
RaceManager::get()->setPlayerKart(0,
UserConfigParams::m_default_kart.getDefaultValue());
}
else
{
// Set up race manager appropriately
if (RaceManager::get()->getNumPlayers() > 0)
RaceManager::get()->setPlayerKart(0, UserConfigParams::m_default_kart);
}
// ASSIGN should make sure that only input from assigned devices
// is read.
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
} // setupRaceStart
// ----------------------------------------------------------------------------
/** Prints help for command line options to stdout.
*/
void cmdLineHelp()
{
fprintf(stdout,
"Usage: %s [OPTIONS]\n\n"
"Run SuperTuxKart, a go-kart racing game that features "
"Tux and friends.\n\n"
"Options:\n"
" -N, --no-start-screen Immediately start race without showing a "
"menu.\n"
" -R, --race-now Same as -N but also skip the ready-set-go phase"
" and the music.\n"
" -t, --track=NAME Start track NAME.\n"
" --gp=NAME Start the specified Grand Prix.\n"
" --add-gp-dir=DIR Load Grand Prix files in DIR. Setting will be saved\n"
"in config.xml under additional_gp_directory. Use\n"
"--add-gp-dir=\"\" to unset.\n"
" --stk-config=FILE use ./data/FILE instead of "
"./data/stk_config.xml\n"
" -k, --numkarts=NUM Set number of karts on the racetrack.\n"
" --kart=NAME Use kart NAME.\n"
" --ai=a,b,... Use the karts a, b, ... for the AI, and additional player kart.\n"
" --aiNP=a,b,... Use the karts a, b, ... for the AI, no additional player kart.\n"
" --laps=N Define number of laps to N, if used in a server all races will use this value.\n"
" --mode=N N=0 Normal, N=1 Time trial, N=2 Battle, N=3 Soccer,\n"
" N=4 Follow The Leader, N=5 Capture The Flag. In configure server use --battle-mode=n\n"
" for battle server and --soccer-timed / goals for soccer server\n"
" to control verbosely, see below:\n"
" --difficulty=N N=0 Beginner, N=1 Intermediate, N=2 Expert, N=3 SuperTux.\n"
" --battle-mode=n Specify battle mode in network, 0 is Free-For-All and\n"
" 1 is Capture The Flag.\n"
" --soccer-timed Use time limit mode in network soccer game.\n"
" --soccer-goals Use goals limit mode in network soccer game.\n"
" --capture-limit Specify capture limit for CTF.\n"
" --time-limit Specify time limit for current game mode.\n"
" --reverse Play track in reverse (if allowed)\n"
" -f, --fullscreen Use fullscreen display.\n"
" -w, --windowed Use windowed display (default).\n"
" -s, --screensize=WxH Set the display size (e.g. 320x200).\n"
" -v, --version Print version of SuperTuxKart.\n"
" --trackdir=DIR A directory from which additional tracks are "
"loaded.\n"
" --seed=n Seed for random number generation to provide reproducible behavior.\n"
" --profile-laps=n Enable automatic driven profile mode for n "
"laps.\n"
" --profile-time=n Enable automatic driven profile mode for n "
"seconds.\n"
" --unlock-all Permanently unlock all karts and tracks for testing.\n"
" --no-unlock-all Disable unlock-all (i.e. base unlocking on player achievement).\n"
" --xmas=n Toggle Xmas/Christmas mode. n=0 Use current date, n=1, Always enable,\n"
" n=2, Always disable.\n"
" --easter=n Toggle Easter ears mode. n=0 Use current date, n=1, Always enable,\n"
" n=2, Always disable.\n"
" --no-graphics Do not display the actual race.\n"
" --sp-shader-debug Enables debug in sp shader, it will print all unavailable uniforms.\n"
" --demo-mode=t Enables demo mode after t seconds of idle time in "
"main menu.\n"
" --demo-tracks=t1,t2 List of tracks to be used in demo mode. No\n"
" spaces are allowed in the track names.\n"
" --demo-laps=n Number of laps to use in a demo.\n"
" --demo-karts=n Number of karts to use in a demo.\n"
" --history Replay history file 'history.dat'.\n"
" --server-config=file Specify the server_config.xml for server hosting, it will create\n"
" one if not found.\n"
" --network-console Enable network console.\n"
" --wan-server=name Start a Wan server (not a playing client).\n"
" --public-server Allow direct connection to the server (without stk server)\n"
" --lan-server=name Start a LAN server (not a playing client).\n"
" --server-password= Sets a password for a server (both client and server).\n"
" --connect-now=ip Connect to a server with IP or domain known now\n"
" (in format x.x.x.x:xxx(optional port)), the port should be its\n"
" public port, you can use [::] to replace x.x.x.x for IPv6 address.\n"
" --server-id=n Server id in stk addons for --connect-now.\n"
" --network-ai=n Numbers of AI for connecting to linear race server, used\n"
" together with --connect-now.\n"
" --login=s Automatically log in (set the login).\n"
" --password=s Automatically log in (set the password).\n"
" --init-user Save the above login and password (if set) in config.\n"
" --disable-polling Don't poll for logged in user.\n"
" --port=n Port number to use.\n"
" --auto-connect Automatically connect to first server and start race\n"
" --max-players=n Maximum number of clients (server only).\n"
" --min-players=n Minimum number of clients for ownerless server(server only).\n"
" --motd Message showing in all lobby of clients, can specify a .txt file.\n"
" --auto-end Automatically end network game after 1st player finished\n"
" for some time (currently his finished time * 0.25 + 15.0). \n"
" --no-auto-end Don't automatically end network game after 1st player finished\n"
" --team-choosing Enable choosing team in lobby for team game.\n"
" --no-team-choosing Disable choosing team in lobby for team game.\n"
" --network-gp=n Specify number of tracks used in network grand prix.\n"
" --graphical-server Enable graphical view in server.\n"
" --no-validation Allow non validated and unencrypted connection in wan.\n"
" --ranked Server will submit ranking to stk addons server.\n"
" --no-ranked Server will not submit ranking to stk addons server.\n"
" You require permission for that.\n"
" --owner-less Race will autostart and no one can kick players in server.\n"
" --no-owner-less Race will not autostart and server owner can kick players in server.\n"
" --firewalled-server Turn on all stun related code in server.\n"
" --no-firewalled-server Turn off all stun related code in server.\n"
" --connection-debug Print verbose info for sending or receiving packets.\n"
" --no-console-log Does not write messages in the console but to\n"
" stdout.log.\n"
" -h, --help Show this help.\n"
" --help-debug Show help for debugging options.\n"
" --log=N Set the verbosity to a value between\n"
" 0 (Debug) and 5 (Only Fatal messages)\n"
" --logbuffer=N Buffers up to N lines log lines before writing.\n"
" --root=DIR Path to add to the list of STK root directories.\n"
" You can specify more than one by separating them\n"
" with colons (:).\n"
" --cutscene=NAME Launch the specified track as a cutscene.\n"
" This is for internal debugging use only.\n"
" --enable-glow Enable glow effect.\n"
" --disable-glow Disable glow effect.\n"
" --enable-bloom Enable bloom effect.\n"
" --disable-bloom Disable bloom effect.\n"
" --enable-light-shaft Enable light shafts (God rays).\n"
" --disable-light-shaft Disable light shafts (God rays).\n"
" --enable-dof Enable depth of field.\n"
" --disable-dof Disable depth of field.\n"
" --enable-particles Enable particles.\n"
" --disable-particles Disable particles.\n"
" --enable-animated-characters Enable animated characters.\n"
" --disable-animated-characters Disable animated characters.\n"
" --enable-motion-blur Enable motion blur.\n"
" --disable-motion-blur Disable motion blur.\n"
" --enable-mlaa Enable anti-aliasing.\n"
" --disable-mlaa Disable anti-aliasing.\n"
" --enable-texture-compression Enable texture compression.\n"
" --disable-texture-compression Disable texture compression.\n"
" --enable-ssao Enable screen space ambient occlusion.\n"
" --disable-ssao Disable screen space ambient occlusion.\n"
" --enable-ibl Enable image based lighting.\n"
" --disable-ibl Disable image based lighting.\n"
" --enable-hd-textures Enable high definition textures.\n"
" --disable-hd-textures Disable high definition textures.\n"
" --enable-dynamic-lights Enable advanced pipeline.\n"
" --disable-dynamic-lights Disable advanced pipeline.\n"
" --anisotropic=n Anisotropic filtering quality (0 to disable).\n"
" Takes precedence over trilinear or bilinear\n"
" texture filtering.\n"
" --shadows=n Set resolution of shadows (0 to disable).\n"
" --render-driver=n Render driver to use (gl or directx9).\n"
" --disable-addon-karts Disable loading of addon karts.\n"
" --disable-addon-tracks Disable loading of addon tracks.\n"
" --dump-official-karts Dump official karts for current stk-assets.\n"
" --apitrace This will disable buffer storage and\n"
" writing gpu query strings to opengl, which\n"
" can be seen later in apitrace.\n"
#ifdef ENABLE_WIIUSE
" --wii Enable usage of Wii Remotes.\n"
#endif
#if defined(__linux__) || defined(__FreeBSD__)
"\n"
"Environment variables:\n"
" IRR_DEVICE_TYPE=[x11, wayland] Force x11/wayland device\n"
" IRR_DISABLE_NETWM=1 Force to use legacy fullscreen\n"
" IRR_VIDEO_OUTPUT=output_name Force to use selected monitor for\n"
" fullscreen window, eg. HDMI-0\n"
#endif
"\n"
"You can visit SuperTuxKart's homepage at "
"https://supertuxkart.net\n\n",
CommandLine::getExecName().c_str()
);
} // cmdLineHelp
void cmdDebugHelp()
{
fprintf(stdout,
"Usage: %s [OPTIONS]\n\n"
"Run SuperTuxKart, a go-kart racing game that features "
"Tux and friends.\n\n"
"Debug options (some work only if artist debug mode is enabled):\n"
" --debug=s s=all Log everything, s=addons Log addons management,\n"
" s=gui Log GUI events, s=flyable Log flyables,\n"
" s=memory Log memory usage, s=misc Log other events.\n"
" --gamepad-visuals Debug gamepads by visualising their values.\n"
" --no-high-scores Disable writing high scores.\n"
" --unit-testing Run unit tests and exit.\n"
" --gamepad-debug Enable verbose logging of gamepad button presses.\n"
" --keyboard-debug Enable verbose logging of keyboard key presses.\n"
" --wiimote-debug Enable verbose logging of Wii Remote button presses.\n"
" --tutorial-debug Enable verbose logging of the tutorial mode.\n"
" --track-debug Enable displaying the driveline in tracks.\n"
" --check-debug Enable displaying the checklines in tracks.\n"
" --kartsize-debug Enable verbose logging of kart dimensions\n"
" and mesh buffer counts.\n"
" --physics-debug Enable verbose logging of the physics system.\n"
" --material-debug Enable verbose logging of terrain specific slowdowns.\n"
" --ftl-debug Enable verbose logging in follow-the-leader mode.\n"
" --slipstream-debug Enable displaying of slipstreams more prominently.\n"
" --rendering-debug Enable displaying of ambient/diffuse/specularity\n"
" in RGB & all anisotropic.\n"
" --ai-debug Enable displaying of AI controllers as on-screen text.\n"
" Makes it easier to distinguish between different AI controllers.\n"
" --fps-debug Enable verbose logging of the FPS counter on every frame.\n"
" --rewind Enable the rewind manager.\n"
" --battle-ai-stats Enable verbose logging of AI karts in battle modes.\n"
" --soccer-ai-stats Enable verbose logging of AI karts in soccer mode.\n"
" --test-ai=n Use the test-ai for every n-th AI kart.\n"
" (so n=1 means all Ais will be the test ai)\n"
" --disable-item-collection Disable item collection. Useful for\n"
" debugging client/server item management.\n"
" --network-item-debugging Print item handling debug information.\n"
"\n"
"You can visit SuperTuxKart's homepage at "
"https://supertuxkart.net\n\n",
CommandLine::getExecName().c_str()
);
} // cmdDebugHelp
//=============================================================================
/** For base options that modify the output (loglevel/color) or exit right
* after being processed (version/help).
*/
int handleCmdLineOutputModifier()
{
if (CommandLine::has("--help") || CommandLine::has("-help") ||
CommandLine::has("-h"))
{
cmdLineHelp();
cleanUserConfig();
exit(0);
}
if (CommandLine::has("--help-debug"))
{
cmdDebugHelp();
cleanUserConfig();
exit(0);
}
if(CommandLine::has("--version") || CommandLine::has("-v"))
{
Log::info("main", "==============================");
Log::info("main", "SuperTuxKart, %s.", STK_VERSION ) ;
Log::info("main", "==============================");
cleanUserConfig();
exit(0);
}
int n;
if(CommandLine::has("--log", &n))
Log::setLogLevel(n);
if (CommandLine::has("--logbuffer", &n))
Log::setBufferSize(n);
if(CommandLine::has("--log=nocolor"))
{
Log::disableColor();
Log::verbose("main", "Colours disabled.");
}
if(CommandLine::has("--no-console-log"))
Log::toggleConsoleLog(false);
return 0;
}
//=============================================================================
/** For base options that don't need much to be inited (and, in some cases,
* that need to be read before initing stuff) - it only assumes that
* user config is loaded (necessary to check for blacklisted screen
* resolutions), but nothing else (esp. not kart_properties_manager and
* track_manager, since their search path might be extended by command
* line options).
*/
int handleCmdLinePreliminary()
{
if(CommandLine::has("--gamepad-visuals"))
UserConfigParams::m_gamepad_visualisation=true;
if(CommandLine::has("--debug=memory"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_MEMORY;
if(CommandLine::has("--debug=addons"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_ADDONS;
if(CommandLine::has("--debug=gui"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_GUI;
if(CommandLine::has("--debug=flyable"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_FLYABLE;
if(CommandLine::has("--debug=misc"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_MISC;
if(CommandLine::has("--debug=all") )
UserConfigParams::m_verbosity |= UserConfigParams::LOG_ALL;
if(CommandLine::has("--online"))
History::m_online_history_replay = true;
#if !(defined(SERVER_ONLY) || defined(ANDROID))
if(CommandLine::has("--apitrace"))
{
SP::sp_apitrace = true;
}
#endif
std::string s;
if(CommandLine::has("--stk-config", &s))
{
stk_config->load(file_manager->getAsset(s));
Log::info("main", "STK config will be read from %s.",s.c_str());
}
if(CommandLine::has("--render-driver", &s))
UserConfigParams::m_render_driver = s;
if(CommandLine::has("--trackdir", &s))
TrackManager::addTrackSearchDir(s);
if(CommandLine::has("--kartdir", &s))
KartPropertiesManager::addKartSearchDir(s);
if (CommandLine::has("--sp-shader-debug"))
SP::SPShader::m_sp_shader_debug = true;
if(CommandLine::has("--screensize", &s) || CommandLine::has("-s", &s))
{
//Check if fullscreen and new res is blacklisted
int width, height;
if (sscanf(s.c_str(), "%dx%d", &width, &height) == 2)
{
// Reassemble the string in case that the original width or
// height contained a leading 0
std::ostringstream o;
o << width << "x" << height;
std::string res = o.str();
if (!UserConfigParams::m_fullscreen ||
std::find(UserConfigParams::m_blacklist_res.begin(),
UserConfigParams::m_blacklist_res.end(),res) ==
UserConfigParams::m_blacklist_res.end())
{
UserConfigParams::m_prev_real_width =
UserConfigParams::m_real_width = width;
UserConfigParams::m_prev_real_height =
UserConfigParams::m_real_height = height;
Log::verbose("main", "You choose to use %dx%d.",
(int)UserConfigParams::m_real_width,
(int)UserConfigParams::m_real_height );
}
else
Log::warn("main", "Resolution %s has been blacklisted, so "
"it is not available!", res.c_str());
}
else
{
Log::fatal("main", "Error: --screensize argument must be "
"given as WIDTHxHEIGHT");
}
}
if(CommandLine::has("--fullscreen") || CommandLine::has("-f"))
{
// Check that current res is not blacklisted
std::ostringstream o;
o << UserConfigParams::m_width << "x" << UserConfigParams::m_height;
std::string res = o.str();
if (std::find(UserConfigParams::m_blacklist_res.begin(),
UserConfigParams::m_blacklist_res.end(),res)
== UserConfigParams::m_blacklist_res.end())
UserConfigParams::m_fullscreen = true;
else
Log::warn("main", "Resolution %s has been blacklisted, so it "
"is not available!", res.c_str());
}
if(CommandLine::has("--windowed") || CommandLine::has("-w"))
UserConfigParams::m_fullscreen = false;
// toggle graphical options
if (CommandLine::has("--enable-glow"))
UserConfigParams::m_glow = true;
else if (CommandLine::has("--disable-glow"))
UserConfigParams::m_glow = false;
if (CommandLine::has("--enable-bloom"))
UserConfigParams::m_bloom = true;
else if (CommandLine::has("--disable-bloom"))
UserConfigParams::m_bloom = false;
if (CommandLine::has("--enable-light-shaft"))
UserConfigParams::m_light_shaft = true;
else if (CommandLine::has("--disable-light-shaft"))
UserConfigParams::m_light_shaft = false;
if (CommandLine::has("--enable-dynamic-lights"))
UserConfigParams::m_dynamic_lights = true;
else if (CommandLine::has("--disable-dynamic-lights"))
UserConfigParams::m_dynamic_lights = false;
// depth of field
if (CommandLine::has("--enable-dof"))
UserConfigParams::m_dof = true;
else if (CommandLine::has("--disable-dof"))
UserConfigParams::m_dof = false;
// particles effects
if (CommandLine::has("--enable-particles"))
UserConfigParams::m_particles_effects = 2;
else if (CommandLine::has("--disable-particles"))
UserConfigParams::m_particles_effects = 0;
// animated characters
if (CommandLine::has("--enable-animated-characters"))
UserConfigParams::m_animated_characters = true;
else if (CommandLine::has("--disable-animated-characters"))
UserConfigParams::m_animated_characters = false;
if (CommandLine::has("--enable-motion-blur"))
UserConfigParams::m_motionblur = true;
else if (CommandLine::has("--disable-motion-blur"))
UserConfigParams::m_motionblur = false;
// anti-aliasing
if (CommandLine::has("--enable-mlaa"))
UserConfigParams::m_mlaa = true;
else if (CommandLine::has("--disable-mlaa"))
UserConfigParams::m_mlaa = false;
if (CommandLine::has("--enable-texture-compression"))
UserConfigParams::m_texture_compression = true;
else if (CommandLine::has("--disable-texture-compression"))
UserConfigParams::m_texture_compression = false;
// screen space ambient occluison
if (CommandLine::has("--enable-ssao"))
UserConfigParams::m_ssao = true;
else if (CommandLine::has("--disable-ssao"))
UserConfigParams::m_ssao = false;
// image based lighting
if (CommandLine::has("--enable-ibl"))
UserConfigParams::m_degraded_IBL = false;
else if (CommandLine::has("--disable-ibl"))
UserConfigParams::m_degraded_IBL = true;
// high definition textures user choice
if (CommandLine::has("--enable-hd-textures"))
UserConfigParams::m_high_definition_textures = 2 | 1;
else if (CommandLine::has("--disable-hd-textures"))
UserConfigParams::m_high_definition_textures = 2;
// Enable loading grand prix from local directory
if(CommandLine::has("--add-gp-dir", &s))
{
// Ensure that the path ends with a /
if (s[s.size()] == '/')
UserConfigParams::m_additional_gp_directory = s;
else
UserConfigParams::m_additional_gp_directory = s + "/";
Log::info("main", "Additional Grand Prix's will be loaded from %s",
UserConfigParams::m_additional_gp_directory.c_str());
}
int n;
if(CommandLine::has("--xmas", &n))
UserConfigParams::m_xmas_mode = n;
if (CommandLine::has("--easter", &n))
UserConfigParams::m_easter_ear_mode = n;
if (CommandLine::has("--shadows", &n))
UserConfigParams::m_shadows_resolution = n;
if (CommandLine::has("--anisotropic", &n))
UserConfigParams::m_anisotropic = n;
// Useful for debugging: the temple navmesh needs 12 minutes in debug
// mode to compute the distance matrix!!
if(CommandLine::has("--dont-load-navmesh"))
Track::m_dont_load_navmesh = true;
if (CommandLine::has("--no-sound"))
UserConfigParams::m_enable_sound = false;