forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
114 lines (98 loc) · 2.18 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* Main Loop for cataclysm
* Linux only I guess
* But maybe not
* Who knows
*/
#include "cursesdef.h"
#include <ctime>
#include "game.h"
#include "color.h"
#include "options.h"
#include "mapbuffer.h"
#include "debug.h"
#include <sys/stat.h>
#include <cstdlib>
#include <signal.h>
void exit_handler(int s);
int main(int argc, char *argv[])
{
#ifdef ENABLE_LOGGING
setupDebug();
#endif
int seed = time(NULL);
//args: world seeding only.
argc--; argv++;
while (argc){
if(std::string(argv[0]) == "--seed"){
argc--; argv++;
if(argc){
seed = djb2_hash((unsigned char*)argv[0]);
argc--; argv++;
}
}
else // ignore unknown args.
argc--; argv++;
}
// ncurses stuff
load_options(); // For getting size options
initscr(); // Initialize ncurses
noecho(); // Don't echo keypresses
cbreak(); // C-style breaks (e.g. ^C to SIGINT)
keypad(stdscr, true); // Numpad is numbers
init_colors(); // See color.cpp
curs_set(0); // Invisible cursor
set_escdelay(10); // Make escape actually responsive
std::srand(seed);
bool quit_game = false;
bool delete_world = false;
game *g = new game;
MAPBUFFER.set_game(g);
MAPBUFFER.load();
#if (!(defined _WIN32 || defined WINDOWS))
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = exit_handler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
#endif
do {
g->setup();
while (!g->do_turn()) ;
if (g->uquit == QUIT_DELETE_WORLD)
delete_world = true;
if (g->game_quit())
quit_game = true;
} while (!quit_game);
if (delete_world)
{
g->delete_save();
} else {
MAPBUFFER.save_if_dirty();
}
exit_handler(-999);
return 0;
}
void exit_handler(int s) {
bool bExit = false;
if (s == 2) {
if (query_yn("Really Quit without saving?")) {
bExit = true;
}
} else if (s == -999) {
bExit = true;
} else {
//query_yn("Signal received: %d", s);
bExit = true;
}
if (bExit) {
erase(); // Clear screen
endwin(); // End ncurses
#if (defined _WIN32 || defined WINDOWS)
system("cls"); // Tell the terminal to clear itself
system("color 07");
#else
system("clear"); // Tell the terminal to clear itself
#endif
exit(1);
}
}