1 #include "Application.hpp"
2 #include "Environment.hpp"
3 #include "PreloadState.hpp"
5 #include "WorldState.hpp"
19 string get_asset_path() {
20 char *base = SDL_GetBasePath();
31 Environment::Environment(Window &win)
35 , assets(get_asset_path())
41 Runtime::Runtime() noexcept
51 void Runtime::ReadArgs(int argc, const char *const *argv) {
52 if (argc <= 0) return;
58 for (int i = 1; i < argc; ++i) {
59 const char *arg = argv[i];
60 if (!arg || arg[0] == '\0') {
61 cerr << "warning: found empty argument at position " << i << endl;
64 if (options && arg[0] == '-') {
66 cerr << "warning: incomplete option list at position " << i << endl;
67 } else if (arg[1] == '-') {
73 if (strcmp(arg + 2, "no-vsync") == 0) {
75 } else if (strcmp(arg + 2, "no-keyboard") == 0) {
76 config.interface.keyboard_disabled = true;
77 } else if (strcmp(arg + 2, "no-mouse") == 0) {
78 config.interface.mouse_disabled = true;
79 } else if (strcmp(arg + 2, "no-hud") == 0) {
80 config.interface.visual_disabled = true;
81 } else if (strcmp(arg + 2, "no-audio") == 0) {
82 config.interface.audio_disabled = true;
84 cerr << "unknown option " << arg << endl;
90 for (int j = 1; arg[j] != '\0'; ++j) {
93 config.doublebuf = false;
97 if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') {
98 cerr << "missing argument to -m" << endl;
101 config.multisampling = strtoul(argv[i], nullptr, 10);
106 if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') {
107 cerr << "missing argument to -n" << endl;
110 n = strtoul(argv[i], nullptr, 10);
115 if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') {
116 cerr << "missing argument to -s" << endl;
119 config.world.gen.solid_seed = strtoul(argv[i], nullptr, 10);
120 config.world.gen.type_seed = config.world.gen.solid_seed;
125 if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') {
126 cerr << "missing argument to -t" << endl;
129 t = strtoul(argv[i], nullptr, 10);
137 cerr << "unknown option " << arg[j] << endl;
144 cerr << "unable to interpret argument "
145 << i << " (" << arg << ")" << endl;
157 mode = FIXED_FRAME_LIMIT;
168 int Runtime::Execute() {
173 Init init(config.doublebuf, config.multisampling);
175 Environment env(init.window);
176 env.viewport.VSync(config.vsync);
178 Application app(env);
180 WorldState world_state(env, config.interface, config.world);
181 app.PushState(&world_state);
183 PreloadState preloader(env, world_state.GetWorld().Loader());
184 app.PushState(&preloader);
197 case FIXED_FRAME_LIMIT: