JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
main.hpp
Go to the documentation of this file.
1// Copyright 2015-2024 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include "Finally.hpp"
8#include "other.hpp"
9#include "window.hpp"
10
11#ifdef JNGL_UWP
12#include <SDL.h>
13
14#define JNGL_MAIN_BEGIN /* NOLINT */ int SDL_main(int argc, char** argv) { \
15 jngl::Finally _ZtzNg47T5XSjogv(jngl::hideWindow);
16#define JNGL_MAIN_END return 0; } // NOLINT
17
18#undef main // SDL defines this to SDL_main
19#else
20
21#ifdef __APPLE__
22#include "TargetConditionals.h"
23#endif
24
25#if !defined(JNGL_MAIN_BEGIN)
26 #if defined(ANDROID)
27 #include <android_native_app_glue.h>
28
29 namespace jngl {
30 extern android_app* androidApp;
31 }
32 #define JNGL_MAIN_BEGIN void android_main(android_app* __androidApp) { \
33 jngl::androidApp = __androidApp;
34 #define JNGL_MAIN_END }
35 #elif defined(__APPLE__) && TARGET_OS_IPHONE // iOS
36 #define JNGL_MAIN_BEGIN void shouldNotBeCalled() {
37 #define JNGL_MAIN_END }
38 #else
39 #ifdef NDEBUG
40 #define JNGL_CATCH_EXCEPTION_TO_ERROR_MESSAGE try {
41 #else
42 #define JNGL_CATCH_EXCEPTION_TO_ERROR_MESSAGE
43 #endif
44 #define JNGL_MAIN_BEGIN /* NOLINT */ int main(int argc, char** argv) { \
45 JNGL_CATCH_EXCEPTION_TO_ERROR_MESSAGE \
46 { \
47 std::vector<std::string> tmp(argc - 1); \
48 for (int i = 1; i < argc; ++i) { \
49 tmp[i - 1] = argv[i]; \
50 } \
51 jngl::setArgs(tmp); \
52 } \
53 jngl::Finally _ZtzNg47T5XSjogv(jngl::hideWindow);
54 #ifdef NDEBUG
55 #define JNGL_MAIN_END /* NOLINT */ } catch (std::exception& e) { \
56 jngl::errorMessage(e.what()); \
57 return EXIT_FAILURE; \
58 } \
59 }
60 #else
61 #define JNGL_MAIN_END }
62 #endif
63 #endif
64#endif
65
66#endif
Contains jngl::Finally class.
JNGL's main namespace.
Definition: Achievement.hpp:10
Miscellaneous functions.
Functions related to the main window.