This repository has been archived by the owner on May 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
wormhol.d
117 lines (100 loc) · 2.66 KB
/
wormhol.d
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
106
107
108
109
110
111
112
113
114
115
116
117
import misc.logger;
import std.stdio, std.file, std.path, sdl.all, std.conv, std.gc, std.string;
import std.c.stdlib;
import sdl.all;
import std.c.windows.windows;
import wormholprogram;
import misc.logger;
import res.settings;
import math.vec2;
version(Windows)
{
import std.c.windows.windows;
}
int mainProcedure(char[][] args)
{
chdir(getDirName(args[0]));
do {
loadSettings();
saveSettings(); // to save defaults and allow changing options manually
vec2i res = getResolution(selectedResolution);
bool fullscreen = selectedFullscreen;
currentResolution = selectedResolution;
currentFullscreen = selectedFullscreen;
useHDR = selectedUseHDR;
mustRestartApp = false;
{
auto scope app = new WormholProgram(res.x, res.y, 0.0, fullscreen, 1); // auto-detect ratio
std.gc.fullCollect;
std.gc.minimize;
app.run();
}
std.gc.fullCollect;
saveSettings();
// because it doesn't work
if (mustRestartApp)
{
mustRestartApp = false;
//info("Restart the app for enjoying your new settings.");
/*version(Windows) // warn the user
{
MessageBoxA(null, toStringz("Restart Wormhol for your new settings."), toStringz("Wormhol"), MB_OK);
}*/
}
} while(mustRestartApp);
return 0;
}
version(Windows)
{
debug
{
int main(char[][] args)
{
return mainProcedure(args);
}
}
else
{
import std.string;
import std.stream;
import std.math;
import std.c.stdlib;
import std.c.windows.windows;
import std.string;
extern (C)
{
void gc_init();
void gc_term();
void _minit();
void _moduleCtor();
}
extern (Windows) public int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
int result;
gc_init();
_minit();
try
{
_moduleCtor();
char exe[4096];
GetModuleFileNameA(null, exe.ptr, 4096);
char[][1] prog;
prog[0] = std.string.toString(exe.ptr);
result = mainProcedure(prog ~ std.string.split(std.string.toString(lpCmdLine)));
}
catch (Object o)
{
result = EXIT_FAILURE;
}
gc_term();
return result;
}
}
}
else
{
int main(char[][] args)
{
return mainProcedure(args);
}
}