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
|
#include "app.hpp"
#include "compat/assert.hpp"
#include "floormat/main.hpp"
#include "floormat/settings.hpp"
#include "src/loader.hpp"
#include "world.hpp"
#include <Corrade/Utility/Arguments.h>
namespace floormat {
app::app(fm_settings&& opts) :
M{floormat_main::create(*this, std::move(opts))},
_floor1{loader.tile_atlas("floor-tiles", {44, 4})},
_floor2{loader.tile_atlas("metal1", {2, 2})},
_wall1{loader.tile_atlas("wood2", {1, 1})},
_wall2{loader.tile_atlas("wood1", {1, 1})}
{
world& w = M->world();
chunk_coords coord{0 ,0};
maybe_initialize_chunk_(coord, w[coord]);
reset_camera_offset();
}
app::~app() // NOLINT(modernize-use-equals-default)
{
}
int app::exec()
{
return M->exec();
}
static const char* const true_values[] = { "1", "true", "yes", "y", "Y", "on", "ON", "enable", "enabled", };
static const char* const false_values[] = { "0", "false", "no", "n", "N", "off", "OFF", "disable", "disabled", };
template<typename T, typename U>
static inline bool find_arg(const T& list, const U& value) {
return std::find_if(std::cbegin(list), std::cend(list), [&](const auto& x) { return x == value; }) != std::cend(list);
}
static bool parse_bool(StringView name, const Corrade::Utility::Arguments& args, bool def)
{
StringView str = args.value<StringView>(name);
if (find_arg(true_values, str))
return true;
else if (find_arg(false_values, str))
return false;
fm_warn("invalid '--%s' argument '%s': should be true or false", name.data(), str.data());
return def;
}
int app::run_from_argv(const int argc, const char* const* const argv)
{
fm_settings opts;
Corrade::Utility::Arguments args{};
args.addOption("vsync", "1")
.addOption("gpu-debug", "1")
.addOption("msaa", "1")
.parse(argc, argv);
opts.vsync = parse_bool("vsync", args, opts.vsync);
opts.msaa = parse_bool("msaa", args, opts.msaa);
if (auto str = args.value<StringView>("gpu-debug"); str == "no-error" || str == "NO-ERROR")
opts.gpu_debug = fm_gpu_debug::no_error;
else if (str == "robust" || str == "ROBUST")
opts.gpu_debug = fm_gpu_debug::robust;
else
opts.gpu_debug = parse_bool("gpu-debug", args, opts.gpu_debug > fm_gpu_debug::off)
? fm_gpu_debug::on
: fm_gpu_debug::off;
int ret;
Pointer<floormat_main> ptr;
{
app application{std::move(opts)};
ret = application.exec();
ptr = std::move(application.M);
}
loader_::destroy();
return ret;
}
} // namespace floormat
int main(int argc, char** argv)
{
return floormat::app::run_from_argv(argc, argv);
}
#ifdef _MSC_VER
#include <cstdlib> // for __arg{c,v}
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wmain"
#endif
extern "C" int __stdcall WinMain(void*, void*, void*, int);
extern "C" int __stdcall WinMain(void*, void*, void*, int)
{
return main(__argc, __argv);
}
#ifdef __clang__
# pragma clang diagnostic pop
#endif
#endif
|