-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathhyper-main.cpp
105 lines (92 loc) · 2.09 KB
/
hyper-main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Hyperbolic Rogue
// Copyright (C) 2011-2019 Zeno Rogue, see 'hyper.cpp' for details
/** \file hyper.cpp
* \brief the hyper_main function
*/
#include "hyper.h"
#if ISLINUX
#include <sys/resource.h>
void moreStack() {
const rlim_t kStackSize = 1 << 28; // 28;
struct rlimit rl;
int result;
result = getrlimit(RLIMIT_STACK, &rl);
if(result == 0) {
if(rl.rlim_cur < kStackSize) {
// rl.rlim_cur = 1 << 19; // kStackSize;
result = setrlimit(RLIMIT_STACK, &rl);
if (result != 0) {
fprintf(stderr, "setrlimit returned result = %d\n", result);
}
}
}
}
#endif
namespace hr {
EX hookset<bool(int argc, char** argv)> hooks_main;
EX bool initialized = false;
/** convenience function for libhyper.so: initialize libhyper with given parameters */
EX int hyper_init(int argc, char **argv) {
#if ISWEB
emscripten_get_commandline();
#elif ISMOBILE
#else
arg::init(argc, argv);
#endif
if(callhandlers(false, hooks_main, argc, argv)) return 0;
#if !ISWEB
#if ISLINUX
moreStack();
#endif
#endif
#if CAP_COMMANDLINE
initializeCLI();
#endif
initAll();
#if CAP_COMMANDLINE
arg::read(3);
start_game();
#endif
initialized = true;
return 1;
}
EX int hyper_init() {
return hyper_init(0, nullptr);
}
/** \brief convenience function for libhyper.so: play the game loop
* sample use:
* ./mymake -O3 -shared
* cling -DFHS -DLINUX -I /usr/include/SDL -l libhyper.so -include hyper.h "-DRun=using namespace hr; hyper_loop();"
* Run
**/
EX void hyper_loop() {
if(!initialized) hyper_init();
quitmainloop = false;
mainloop();
}
EX int hyper_main(int argc, char **argv) {
try {
if(!hyper_init(argc, argv)) return 0;
#if !ISWEB
if(showstartmenu && !vid.skipstart) {
#if CAP_STARTANIM
startanims::pick();
#endif
pushScreen(showStartMenu);
}
#endif
progress_warning();
mainloop();
finishAll();
} catch(hr_exception& e) {
println(hlog, "exception not caught: ", e.what());
}
fflush(stdout);
return 0;
}
}
#ifndef NOMAIN
int main(int argc, char **argv) {
return hr::hyper_main(argc, argv);
}
#endif