1 #include "Application.hpp"
2 #include "Environment.hpp"
4 #include "WorldState.hpp"
18 string get_asset_path() {
19 char *base = SDL_GetBasePath();
30 Environment::Environment(Window &win)
34 , assets(get_asset_path())
40 Runtime::Runtime() noexcept
50 void Runtime::ReadArgs(int argc, const char *const *argv) {
51 if (argc <= 0) return;
57 for (int i = 1; i < argc; ++i) {
58 const char *arg = argv[i];
59 if (!arg || arg[0] == '\0') {
60 cerr << "warning: found empty argument at position " << i << endl;
63 if (options && arg[0] == '-') {
65 cerr << "warning: incomplete option list at position " << i << endl;
66 } else if (arg[1] == '-') {
72 if (strcmp(arg + 2, "no-vsync") == 0) {
74 } else if (strcmp(arg + 2, "no-keyboard") == 0) {
75 config.interface.keyboard_disabled = true;
76 } else if (strcmp(arg + 2, "no-mouse") == 0) {
77 config.interface.mouse_disabled = true;
78 } else if (strcmp(arg + 2, "no-hud") == 0) {
79 config.interface.visual_disabled = true;
80 } else if (strcmp(arg + 2, "no-audio") == 0) {
81 config.interface.audio_disabled = true;
83 cerr << "unknown option " << arg << endl;
89 for (int j = 1; arg[j] != '\0'; ++j) {
92 config.doublebuf = false;
96 if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') {
97 cerr << "missing argument to -m" << endl;
100 config.multisampling = strtoul(argv[i], nullptr, 10);
105 if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') {
106 cerr << "missing argument to -n" << endl;
109 n = strtoul(argv[i], nullptr, 10);
114 if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') {
115 cerr << "missing argument to -s" << endl;
118 config.world.gen.solid_seed = strtoul(argv[i], nullptr, 10);
119 config.world.gen.type_seed = config.world.gen.solid_seed;
124 if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') {
125 cerr << "missing argument to -t" << endl;
128 t = strtoul(argv[i], nullptr, 10);
136 cerr << "unknown option " << arg[j] << endl;
143 cerr << "unable to interpret argument "
144 << i << " (" << arg << ")" << endl;
156 mode = FIXED_FRAME_LIMIT;
167 int Runtime::Execute() {
172 Init init(config.doublebuf, config.multisampling);
174 Environment env(init.window);
175 env.viewport.VSync(config.vsync);
177 Application app(env);
179 WorldState state(env, config.interface, config.world);
180 app.PushState(&state);
193 case FIXED_FRAME_LIMIT: