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-2025 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#ifdef NDEBUG
11#include "message.hpp"
12#endif
13
14#ifdef JNGL_UWP
15#include <SDL.h>
16
17#define JNGL_MAIN_BEGIN /* NOLINT */ int SDL_main(int argc, char** argv) { \
18 jngl::Finally _ZtzNg47T5XSjogv(jngl::hideWindow);
19#define JNGL_MAIN_END return 0; } // NOLINT
20
21#undef main // SDL defines this to SDL_main
22#else
23
24#ifdef __APPLE__
25#include "TargetConditionals.h"
26#endif
27
28#if !defined(JNGL_MAIN_BEGIN)
29 #if defined(ANDROID)
30 #include <android_native_app_glue.h>
31
32 namespace jngl {
33 extern android_app* androidApp;
34 }
35 #define JNGL_MAIN_BEGIN void android_main(android_app* __androidApp) { \
36 jngl::androidApp = __androidApp;
37 #define JNGL_MAIN_END }
38 #elif defined(__APPLE__) && TARGET_OS_IPHONE // iOS
39 #define JNGL_MAIN_BEGIN void shouldNotBeCalled() {
40 #define JNGL_MAIN_END }
41 #else
42 #ifdef NDEBUG
43 #define JNGL_CATCH_EXCEPTION_TO_ERROR_MESSAGE try {
44 #else
45 #define JNGL_CATCH_EXCEPTION_TO_ERROR_MESSAGE
46 #endif
47 #define JNGL_MAIN_BEGIN /* NOLINT */ int main(int argc, char** argv) { \
48 JNGL_CATCH_EXCEPTION_TO_ERROR_MESSAGE \
49 { \
50 std::vector<std::string> tmp(argc - 1); \
51 for (int i = 1; i < argc; ++i) { \
52 tmp[i - 1] = argv[i]; \
53 } \
54 jngl::setArgs(tmp); \
55 } \
56 jngl::Finally _ZtzNg47T5XSjogv(jngl::hideWindow);
57 #ifdef NDEBUG
58 #define JNGL_MAIN_END /* NOLINT */ } catch (std::exception& e) { \
59 jngl::errorMessage(e.what()); \
60 return EXIT_FAILURE; \
61 } \
62 }
63 #else
64 #define JNGL_MAIN_END }
65 #endif
66 #endif
67#endif
68
69#endif
Contains jngl::Finally class.
JNGL's main namespace.
Miscellaneous functions.
Functions related to the main window.