diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/engine.cpp | 124 |
1 files changed, 68 insertions, 56 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index 69fa839..bde3058 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -72,15 +72,19 @@ using #define PI 3.1415926535f -#define MODE_HELP 0 -#define MODE_TERM 1 -#define MODE_GRAPHICAL 2 +enum class Mode { + help, + term, + graphical, +}; -#define GAME_PLANE 0 -#define GAME_SUZANNE 1 -#define GAME_PHYSICS 2 +enum class GameType { + plane, + suzanne, + plane_and_suzanne, +}; -#define GAME GAME_PHYSICS +constexpr GameType game_type { GameType::plane_and_suzanne }; static void print_usage(std::ostream& output_stream) { output_stream << "Usage: ./engine [-htg] [--help] [--term] [--graphical]\n" @@ -2660,18 +2664,18 @@ static std::vector<std::string_view> convert_args(int argc, char *argv[]) { return args; } -static void parse_args(const std::vector<std::string_view>& args, int& mode) { +static void parse_args(const std::vector<std::string_view>& args, Mode& mode) { for (auto args_iter = std::next(args.begin()); args_iter != args.end(); args_iter++) { const auto& arg = *args_iter; if (arg.size() >= 1 && arg[0] == '-') { if (arg.size() >= 2 && arg[1] == '-') { auto long_opt = arg.substr(2); if (long_opt == "help") { - mode = MODE_HELP; + mode = Mode::help; } else if (long_opt == "term") { - mode = MODE_TERM; + mode = Mode::term; } else if (long_opt == "graphical") { - mode = MODE_GRAPHICAL; + mode = Mode::graphical; } else { std::cerr << "Error: Unexpected option `--" << long_opt << "'." << std::endl; usage_error_exit(); @@ -2686,13 +2690,13 @@ static void parse_args(const std::vector<std::string_view>& args, int& mode) { const auto& opt = *arg_iter; switch (opt) { case 'h': - mode = MODE_HELP; + mode = Mode::help; break; case 't': - mode = MODE_TERM; + mode = Mode::term; break; case 'g': - mode = MODE_GRAPHICAL; + mode = Mode::graphical; break; default: std::cerr << "Error: Unexpected option `-" << opt << "'." << std::endl; @@ -2708,63 +2712,71 @@ static void parse_args(const std::vector<std::string_view>& args, int& mode) { } int main(int argc, char *argv[]) { - int mode = MODE_GRAPHICAL; + Mode mode = Mode::graphical; parse_args(convert_args(argc, argv), mode); Scene scene { { 90.f * PI / 180.f, { { 0.f, 1.8f, 7.f }, Quaternion::one(), { 1.f, 1.f, 1.f } } }, - { -#if GAME == GAME_PLANE - { - Mesh::plane(2.f, 2.f), - { - Vector3(0.f, 0.f, 0.f), - Quaternion::one(), - Vector3(1.f, 1.f, 1.f), - } - }, -#elif GAME == GAME_SUZANNE - { - engine::parse_object(DATADIR "/assets/suzanne.obj"), - { - Vector3(0.f, 0.f, 0.f), - Quaternion::one(), - Vector3(1.f, 1.f, 1.f), - } - }, -#elif GAME == GAME_PHYSICS - { - Mesh::plane(10.f, 10.f), - { - Vector3(0.f, 0.f, 0.f), - Quaternion::one(), - Vector3(1.f, 1.f, 1.f), - } - }, - { - engine::parse_object(DATADIR "/assets/suzanne.obj"), - { - Vector3(0.f, 1.f, 0.f), - Quaternion::one(), - Vector3(1.f, 1.f, 1.f), - } - }, -#endif - } + [&] constexpr -> std::vector<Object3D> { + switch (game_type) { + case GameType::plane: + return { + { + Mesh::plane(2.f, 2.f), + { + Vector3(0.f, 0.f, 0.f), + Quaternion::one(), + Vector3(1.f, 1.f, 1.f), + } + }, + }; + case GameType::suzanne: + return { + { + engine::parse_object(DATADIR "/assets/suzanne.obj"), + { + Vector3(0.f, 0.f, 0.f), + Quaternion::one(), + Vector3(1.f, 1.f, 1.f), + } + }, + }; + case GameType::plane_and_suzanne: + return { + { + Mesh::plane(10.f, 10.f), + { + Vector3(0.f, 0.f, 0.f), + Quaternion::one(), + Vector3(1.f, 1.f, 1.f), + } + }, + { + engine::parse_object(DATADIR "/assets/suzanne.obj"), + { + Vector3(0.f, 1.f, 0.f), + Quaternion::one(), + Vector3(1.f, 1.f, 1.f), + } + }, + }; + } + std::unreachable(); + }() }; switch (mode) { - case MODE_HELP: + case Mode::help: print_usage(std::cout); return EXIT_SUCCESS; - case MODE_TERM: + case Mode::term: #ifdef HAVE_NCURSES return main_term(scene); #else std::cerr << "Error: ncurses was not enabled during compilation." << std::endl; return EXIT_FAILURE; #endif - case MODE_GRAPHICAL: + case Mode::graphical: return main_graphical(scene); default: std::unreachable(); |
