Annotation of brogue-ce/src/platform/main.c, Revision 1.1.1.1
1.1 rubenllo 1: #include <math.h>
2: #include <limits.h>
3: #include "platform.h"
4:
5: // Expanding a macro as a string constant requires two levels of macros
6: #define _str(x) #x
7: #define STRINGIFY(x) _str(x)
8:
9: struct brogueConsole currentConsole;
10:
11: char dataDirectory[BROGUE_FILENAME_MAX] = STRINGIFY(DATADIR);
12: boolean serverMode = false;
13: boolean hasGraphics = false;
14: boolean graphicsEnabled = false;
15: boolean isCsvFormat = false;
16:
17: static void printCommandlineHelp() {
18: printf("%s",
19: "--help -h print this help message\n"
20: "--version -V print the version (i.e., " BROGUE_VERSION_STRING ")\n"
21: "--scores dump scores to output and exit immediately\n"
22: "-n start a new game, skipping the menu\n"
23: "-s seed start a new game with the specified numerical seed\n"
24: "-o filename[.broguesave] open a save file (extension optional)\n"
25: "-v recording[.broguerec] view a recording (extension optional)\n"
26: #ifdef BROGUE_WEB
27: "--server-mode run the game in web-brogue server mode\n"
28: #endif
29: #ifdef BROGUE_SDL
30: "--size N starts the game at font size N (1 to 20)\n"
31: "--graphics -G enable graphical tiles\n"
32: "--full-screen -F enable full screen\n"
33: "--no-gpu disable hardware-accelerated graphics and HiDPI\n"
34: #endif
35: #ifdef BROGUE_CURSES
36: "--term -t run in ncurses-based terminal mode\n"
37: #endif
38: "--stealth -S display stealth range\n"
39: "--no-effects -E disable color effects\n"
40: "--wizard -W run in wizard mode, invincible with powerful items\n"
41: "[--csv] --print-seed-catalog [START NUM LEVELS]\n"
42: " (optional csv format)\n"
43: " prints a catalog of the first LEVELS levels of NUM\n"
44: " seeds from seed START (defaults: 1 1000 5)\n"
45: );
46: return;
47: }
48:
49: static void badArgument(const char *arg) {
50: printf("Bad argument: %s\n\n", arg);
51: printCommandlineHelp();
52: }
53:
54: int main(int argc, char *argv[])
55: {
56:
57: #if 0
58: #define TOD(x) ((double) (x) / FP_FACTOR)
59: fixpt y, x1 = 1, x2 = FP_FACTOR * 70 / 100;
60: for (int i=0; i < 10; i++) {
61: y = fp_pow(x2, x1); printf("%.5f ^ %i = %.5f (%lli)\n", TOD(x2), x1, TOD(y), y);
62: // y = fp_sqrt(x1); printf("sqrt(%.5f) = %.5f (%lli)\n", TOD(x1), TOD(y), y);
63: x1 += 1;
64: }
65: exit(0);
66: #endif
67:
68: #ifdef BROGUE_SDL
69: currentConsole = sdlConsole;
70: #elif BROGUE_WEB
71: currentConsole = webConsole;
72: #elif BROGUE_CURSES
73: currentConsole = cursesConsole;
74: #endif
75:
76: rogue.nextGame = NG_NOTHING;
77: rogue.nextGamePath[0] = '\0';
78: rogue.nextGameSeed = 0;
79: rogue.wizard = false;
80: rogue.displayAggroRangeMode = false;
81: rogue.trueColorMode = false;
82:
83: boolean initialGraphics = false;
84:
85: int i;
86: for (i = 1; i < argc; i++) {
87: if (strcmp(argv[i], "--scores") == 0) {
88: // just dump the scores and quit!
89: dumpScores();
90: return 0;
91: }
92:
93: if (strcmp(argv[i], "--seed") == 0 || strcmp(argv[i], "-s") == 0) {
94: // pick a seed!
95: if (i + 1 < argc) {
96: unsigned int seed = atof(argv[i + 1]); // plenty of precision in a double, and simpler than any other option
97: if (seed != 0) {
98: i++;
99: rogue.nextGameSeed = seed;
100: rogue.nextGame = NG_NEW_GAME_WITH_SEED;
101: continue;
102: }
103: }
104: }
105:
106: if (strcmp(argv[i], "-n") == 0) {
107: if (rogue.nextGameSeed == 0) {
108: rogue.nextGame = NG_NEW_GAME;
109: } else {
110: rogue.nextGame = NG_NEW_GAME_WITH_SEED;
111: }
112: continue;
113: }
114:
115: if (strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--open") == 0) {
116: if (i + 1 < argc) {
117: strncpy(rogue.nextGamePath, argv[i + 1], BROGUE_FILENAME_MAX);
118: rogue.nextGamePath[BROGUE_FILENAME_MAX - 1] = '\0';
119: rogue.nextGame = NG_OPEN_GAME;
120:
121: if (!endswith(rogue.nextGamePath, GAME_SUFFIX)) {
122: append(rogue.nextGamePath, GAME_SUFFIX, BROGUE_FILENAME_MAX);
123: }
124:
125: i++;
126: continue;
127: }
128: }
129:
130: if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--view") == 0) {
131: if (i + 1 < argc) {
132: strncpy(rogue.nextGamePath, argv[i + 1], BROGUE_FILENAME_MAX);
133: rogue.nextGamePath[BROGUE_FILENAME_MAX - 1] = '\0';
134: rogue.nextGame = NG_VIEW_RECORDING;
135:
136: if (!endswith(rogue.nextGamePath, RECORDING_SUFFIX)) {
137: append(rogue.nextGamePath, RECORDING_SUFFIX, BROGUE_FILENAME_MAX);
138: }
139:
140: i++;
141: continue;
142: }
143: }
144:
145: if (strcmp(argv[i], "--print-seed-catalog") == 0) {
146: if (i + 3 < argc) {
147: // Use convertions from types the next size up, because they're signed
148: unsigned long startingSeed = atof(argv[i + 1]);
149: unsigned long numberOfSeeds = atoll(argv[i + 2]);
150: unsigned int numberOfLevels = atol(argv[i + 3]);
151:
152: if (startingSeed > 0 && numberOfLevels <= 40) {
153: printSeedCatalog(startingSeed, numberOfSeeds, numberOfLevels, isCsvFormat);
154: return 0;
155: }
156: } else {
157: printSeedCatalog(1, 1000, 5, isCsvFormat);
158: return 0;
159: }
160: }
161:
162: if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
163: printf("%s\n", BROGUE_VERSION_STRING);
164: return 0;
165: }
166:
167: if (!(strcmp(argv[i], "-?") && strcmp(argv[i], "-h") && strcmp(argv[i], "--help"))) {
168: printCommandlineHelp();
169: return 0;
170: }
171:
172: if (strcmp(argv[i], "-G") == 0 || strcmp(argv[i], "--graphics") == 0) {
173: initialGraphics = true; // we call setGraphicsEnabled later
174: continue;
175: }
176:
177: if (strcmp(argv[i], "--csv") == 0 ) {
178: isCsvFormat = true; // we call printSeedCatalog later
179: continue;
180: }
181:
182: #ifdef BROGUE_SDL
183: if (strcmp(argv[i], "--size") == 0) {
184: if (i + 1 < argc) {
185: int size = atoi(argv[i + 1]);
186: if (size > 0 && size <= 20) {
187: windowWidth = round(pow(1.1, size) * 620.);
188: // Height set automatically
189: };
190:
191: i++;
192: continue;
193: }
194: }
195:
196: if (strcmp(argv[i], "-F") == 0 || strcmp(argv[i], "--full-screen") == 0) {
197: fullScreen = true;
198: continue;
199: }
200:
201: if (strcmp(argv[i], "--no-gpu") == 0) {
202: softwareRendering = true;
203: continue;
204: }
205: #endif
206:
207: #ifdef BROGUE_CURSES
208: if (strcmp(argv[i], "--term") == 0 || strcmp(argv[i], "-t") == 0) {
209: currentConsole = cursesConsole;
210: continue;
211: }
212: #endif
213:
214: #ifdef BROGUE_WEB
215: if(strcmp(argv[i], "--server-mode") == 0) {
216: currentConsole = webConsole;
217: rogue.nextGame = NG_NEW_GAME;
218: serverMode = true;
219: continue;
220: }
221: #endif
222:
223: if (strcmp(argv[i], "--stealth") == 0 || strcmp(argv[i], "-S") == 0) {
224: rogue.displayAggroRangeMode = true;
225: continue;
226: }
227:
228: if (strcmp(argv[i], "--no-effects") == 0 || strcmp(argv[i], "-E") == 0) {
229: rogue.trueColorMode = true;
230: continue;
231: }
232:
233: if (strcmp(argv[i], "--wizard") == 0 || strcmp(argv[i], "-W") == 0) {
234: rogue.wizard = true;
235: continue;
236: }
237:
238: // maybe it ends with .broguesave or .broguerec, then?
239: if (endswith(argv[i], GAME_SUFFIX)) {
240: strncpy(rogue.nextGamePath, argv[i], BROGUE_FILENAME_MAX);
241: rogue.nextGamePath[BROGUE_FILENAME_MAX - 1] = '\0';
242: rogue.nextGame = NG_OPEN_GAME;
243: continue;
244: }
245:
246: if (endswith(argv[i], RECORDING_SUFFIX)) {
247: strncpy(rogue.nextGamePath, argv[i], BROGUE_FILENAME_MAX);
248: rogue.nextGamePath[BROGUE_FILENAME_MAX - 1] = '\0';
249: rogue.nextGame = NG_VIEW_RECORDING;
250: continue;
251: }
252:
253: badArgument(argv[i]);
254: return 1;
255: }
256:
257: hasGraphics = (currentConsole.setGraphicsEnabled != NULL);
258: // Now actually set graphics. We do this to ensure there is exactly one
259: // call, whether true or false
260: graphicsEnabled = setGraphicsEnabled(initialGraphics);
261:
262: loadKeymap();
263: currentConsole.gameLoop();
264:
265: return 0;
266: }
267:
CVSweb