1 /*
2  * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org
3  *
4  * Solarus is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Solarus is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef SOLARUS_NOMAIN
18 
19 #include "solarus/core/Arguments.h"
20 #include "solarus/core/Debug.h"
21 #include "solarus/core/MainLoop.h"
22 #include <iostream>
23 #include <string>
24 
25 // SDLmain is required in some platforms, i.e. Windows, for proper initialization.
26 // For instance, in Windows, SDLmain encodes argv in main() using UTF-8 by default.
27 #include <SDL.h>
28 
29 namespace Solarus {
30 
31 namespace {
32 
33 /**
34  * \brief Prints the usage of the program.
35  * \param argc number of command-line arguments
36  * \param argv command-line arguments
37  */
print_help(const Arguments & args)38 void print_help(const Arguments& args) {
39 
40   std::string binary_name = args.get_program_name();
41   if (binary_name.empty()) {
42     binary_name = "solarus";
43   }
44   std::cout << "Usage: " << binary_name << " [options] [quest_path]"
45     << std::endl << std::endl
46     << "The quest path is the name of a directory that contains either the data"
47     << std::endl
48     << "directory or the data archive (data.solarus or data.solarus.zip) of the game to run."
49     << std::endl
50     << "If the quest path is not specified, the default directory will be: '"
51     << SOLARUS_DEFAULT_QUEST << "'."
52     << std::endl
53     << std::endl
54     << "Options:"
55     << std::endl
56     << "  -help                         shows this help message and exits"
57     << std::endl
58     << "  -no-audio                     disables sounds and musics"
59     << std::endl
60     << "  -no-video                     disables displaying"
61     << std::endl
62     << "  -quest-size=<width>x<height>  sets the size of the drawing area (if compatible with the quest)"
63     << std::endl
64     << "  -lua-console=yes|no           accepts standard input lines as Lua commands (default yes)"
65     << std::endl
66     << "  -turbo=yes|no                 runs as fast as possible rather than simulating real time (default no)"
67     << std::endl
68     << "  -lag=X                        slows down each frame of X milliseconds to simulate slower systems for debugging (default 0)"
69     << std::endl
70     << "  -cursor-visible=yes|no        sets the mouse cursor visibility on start (default leave unchanged)"
71     << std::endl
72     << "  -fullscreen=yes|no            sets fullscreen mode on start (default leave unchanged)"
73     << std::endl
74     << "  -perf-sound-play=yes|no       enables performance reporting of sound playing (default no)"
75     << std::endl
76     << "  -perf-video-render=yes|no     enables performance reporting of video rendering, i.e. FPS (default no)"
77     << std::endl
78     << "  -joypad-deadzone=<value>      sets the joypad axis deadzone between 0-32767 (default 10000)"
79     << std::endl
80     << "  -quit-combo=<b1>+<b2>+...     enables joypad buttons combo for quitting (default disabled)"
81     << std::endl
82     << "  -s=<script>                   set a script to be executed before the main.lua of the quest."
83     << std::endl
84     << "  -force-software-rendering     force the engine to use SDL software rendering. Disabling opengl."
85     << std::endl;
86 }
87 
88 }  // Anonymous namespace.
89 
90 }  // namespace Solarus.
91 
92 /**
93  * \brief Usual entry point of the program.
94  *
95  * Usage: solarus [options] [quest_path]
96  *
97  * The quest path is the name of a directory that contains either the data
98  * directory ("data") or the data archive ("data.solarus" or
99  * "data.solarus.zip").
100  * If the quest path is not specified, it is set to the preprocessor constant
101  * SOLARUS_DEFAULT_QUEST, which is the current directory "." by default.
102  * In all cases, this quest path is relative to the working directory,
103  * or to the solarus executable directory if no quest is found in the working
104  * directory.
105  *
106  * The following options are supported:
107  *   -help                             Shows a help message.
108  *   -no-audio                         Disables sounds and musics.
109  *   -no-video                         Disables displaying (used for unit tests).
110  *   -quest-size=<width>x<height>      Sets the size of the drawing area (if compatible with the quest).
111  *   -lua-console=yes|no               Accepts lines from standard input as Lua commands (default: yes).
112  *   -turbo=yes|no                     Runs as fast as possible rather than simulating real time (default: no).
113  *   -lag=X                            (Advanced) Artificially slows down each frame of X milliseconds
114  *                                     to simulate slower systems for debugging (default: 0).
115  *
116  * \param argc Number of command-line arguments.
117  * \param argv Command-line arguments.
118  */
main(int argc,char ** argv)119 int main(int argc, char** argv) {
120 
121   using namespace Solarus;
122 
123   Debug::set_abort_on_die(true);  // Better for debugging (get a callstack).
124 
125   // Store the command-line arguments.
126   const Arguments args(argc, argv);
127 
128   // Check the -help option.
129   if (args.has_argument("-help")) {
130     // Print a help message.
131     print_help(args);
132   }
133   else {
134     // Run the main loop.
135     MainLoop(args).run();
136   }
137 
138   return 0;
139 }
140 
141 #endif
142 
143