Skip to content

Commit 5f19eef

Browse files
committed
SDL: move noexcept function to another name instead of main, since that may be replaced by "#define main SDL_main" and doesn't like the noexcept attribute
1 parent b50d5ae commit 5f19eef

File tree

1 file changed

+58
-52
lines changed

1 file changed

+58
-52
lines changed

src/executables/game/main.cpp

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -60,80 +60,86 @@ namespace {
6060
}
6161

6262

63-
} // namespace
63+
int main_no_sdl_replace(int argc, char** argv) noexcept {
6464

65-
int main(int argc, char** argv) noexcept {
65+
std::shared_ptr<Window> window{ nullptr };
6666

67-
std::shared_ptr<Window> window{ nullptr };
67+
try {
6868

69-
try {
69+
initialize_spdlog();
7070

71-
initialize_spdlog();
71+
std::vector<std::string> arguments_vector{};
72+
arguments_vector.reserve(argc);
73+
for (auto i = 0; i < argc; ++i) {
74+
arguments_vector.emplace_back(argv[i]); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
75+
}
7276

73-
std::vector<std::string> arguments_vector{};
74-
arguments_vector.reserve(argc);
75-
for (auto i = 0; i < argc; ++i) {
76-
arguments_vector.emplace_back(argv[i]); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
77-
}
77+
if (arguments_vector.empty()) {
78+
arguments_vector.emplace_back("oopetris");
79+
}
7880

79-
if (arguments_vector.empty()) {
80-
arguments_vector.emplace_back("oopetris");
81-
}
81+
auto parsed_arguments = helper::parse_args(arguments_vector);
8282

83-
auto parsed_arguments = helper::parse_args(arguments_vector);
83+
if (not parsed_arguments.has_value()) {
8484

85-
if (not parsed_arguments.has_value()) {
85+
spdlog::error("error parsing command line arguments: {}", parsed_arguments.error());
86+
return EXIT_FAILURE;
87+
}
8688

87-
spdlog::error("error parsing command line arguments: {}", parsed_arguments.error());
88-
return EXIT_FAILURE;
89-
}
89+
auto arguments = std::move(parsed_arguments.value());
9090

91-
auto arguments = std::move(parsed_arguments.value());
91+
[[maybe_unused]] constexpr auto window_name = constants::program_name.c_str();
9292

93-
[[maybe_unused]] constexpr auto window_name = constants::program_name.c_str();
9493

95-
96-
try {
94+
try {
9795
#if defined(__ANDROID__) or defined(__CONSOLE__)
98-
window = std::make_shared<Window>(window_name, WindowPosition::Centered);
96+
window = std::make_shared<Window>(window_name, WindowPosition::Centered);
9997
#else
100-
[[maybe_unused]] static constexpr int width = 1280;
101-
[[maybe_unused]] static constexpr int height = 720;
102-
window = std::make_shared<Window>(window_name, WindowPosition::Centered, width, height);
98+
[[maybe_unused]] static constexpr int width = 1280;
99+
[[maybe_unused]] static constexpr int height = 720;
100+
window = std::make_shared<Window>(window_name, WindowPosition::Centered, width, height);
103101
#endif
104-
} catch (const helper::GeneralError& general_error) {
105-
spdlog::error("Couldn't initialize window: {}", general_error.message());
106-
}
102+
} catch (const helper::GeneralError& general_error) {
103+
spdlog::error("Couldn't initialize window: {}", general_error.message());
104+
}
107105

108-
if (window == nullptr) {
109-
helper::MessageBox::show_simple(
110-
helper::MessageBox::Type::Error, "Initialization Error", "failed to create SDL window", nullptr
111-
);
112-
return EXIT_FAILURE;
113-
}
106+
if (window == nullptr) {
107+
helper::MessageBox::show_simple(
108+
helper::MessageBox::Type::Error, "Initialization Error", "failed to create SDL window", nullptr
109+
);
110+
return EXIT_FAILURE;
111+
}
114112

115-
Application app{ std::move(window), std::move(arguments) };
113+
Application app{ std::move(window), std::move(arguments) };
116114

117-
app.run();
118-
return EXIT_SUCCESS;
115+
app.run();
116+
return EXIT_SUCCESS;
119117

120-
} catch (const helper::GeneralError& general_error) {
121-
spdlog::error("{}", general_error.message());
118+
} catch (const helper::GeneralError& general_error) {
119+
spdlog::error("{}", general_error.message());
122120

123121

124-
if (window == nullptr) {
125-
helper::MessageBox::show_simple(
126-
helper::MessageBox::Type::Error, "Initialization Error", general_error.message(), nullptr
127-
);
128-
} else {
129-
window->show_simple(helper::MessageBox::Type::Error, "Initialization Error", general_error.message());
130-
}
122+
if (window == nullptr) {
123+
helper::MessageBox::show_simple(
124+
helper::MessageBox::Type::Error, "Initialization Error", general_error.message(), nullptr
125+
);
126+
} else {
127+
window->show_simple(helper::MessageBox::Type::Error, "Initialization Error", general_error.message());
128+
}
131129

132130

133-
return EXIT_FAILURE;
134-
} catch (const std::exception& error) {
135-
// this is the last resort, so using std::cerr and no sdl show_simple messagebox!
136-
std::cerr << error.what();
137-
return EXIT_FAILURE;
131+
return EXIT_FAILURE;
132+
} catch (const std::exception& error) {
133+
// this is the last resort, so using std::cerr and no sdl show_simple messagebox!
134+
std::cerr << error.what();
135+
return EXIT_FAILURE;
136+
}
138137
}
138+
139+
140+
} // namespace
141+
142+
143+
int main(int argc, char** argv) {
144+
return main_no_sdl_replace(argc, argv);
139145
}

0 commit comments

Comments
 (0)