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