This repository has been archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.cpp
90 lines (82 loc) · 2.14 KB
/
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
/*
* Bermuda Syndrome engine rewrite
* Copyright (C) 2007-2011 Gregory Montoir
*/
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#include "game.h"
#include "systemstub.h"
static const char *USAGE =
"Bermuda Syndrome\n"
"Usage: bs [OPTIONS]...\n"
" --datapath=PATH Path to data files (default 'DATA')\n"
" --savepath=PATH Path to save files (default '.')\n"
" --musicpath=PATH Path to music files (default 'MUSIC')\n";
static bool parseOption(const char *arg, const char *longCmd, const char **opt) {
bool handled = false;
if (arg[0] == '-' && arg[1] == '-') {
if (strncmp(arg + 2, longCmd, strlen(longCmd)) == 0) {
*opt = arg + 2 + strlen(longCmd);
handled = true;
}
}
return handled;
}
static Game *g_game;
static SystemStub *g_stub;
static void init(const char *dataPath, const char *savePath, const char *musicPath) {
g_stub = SystemStub_SDL_create();
g_game = new Game(g_stub, dataPath, savePath, musicPath);
g_game->init();
}
static void fini() {
g_game->fini();
delete g_game;
g_stub->destroy();
delete g_stub;
g_stub = 0;
}
#ifdef __EMSCRIPTEN__
static void mainLoop() {
if (!g_stub->_quit) {
g_game->mainLoop();
}
}
#endif
#undef main
int main(int argc, char *argv[]) {
const char *dataPath = "DATA";
const char *savePath = ".";
const char *musicPath = "MUSIC";
for (int i = 1; i < argc; ++i) {
bool opt = false;
if (strlen(argv[i]) >= 2) {
opt |= parseOption(argv[i], "datapath=", &dataPath);
opt |= parseOption(argv[i], "savepath=", &savePath);
opt |= parseOption(argv[i], "musicpath=", &musicPath);
}
if (!opt) {
printf("%s", USAGE);
return 0;
}
}
g_debugMask = DBG_INFO; // | DBG_GAME | DBG_OPCODES | DBG_DIALOGUE;
init(dataPath, savePath, musicPath);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(mainLoop, kCycleDelay, 0);
#else
uint32_t lastFrameTimeStamp = g_stub->getTimeStamp();
while (!g_stub->_quit) {
g_game->mainLoop();
const uint32_t end = lastFrameTimeStamp + kCycleDelay;
do {
g_stub->sleep(10);
g_stub->processEvents();
} while (!g_stub->_pi.fastMode && g_stub->getTimeStamp() < end);
lastFrameTimeStamp = g_stub->getTimeStamp();
}
fini();
#endif
return 0;
}