Cube  Diff

Differences From Artifact [6994beff69]:

To Artifact [73cd19e8dc]:


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
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




+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+








-
-
-
-
-
-
-
-

-
-
+





-
+
-
+





+
-
+
-
+
+








-
+







// main.cpp: initialisation & main loop

#include "cube.h"

OF_APPLICATION_DELEGATE(Cube)
void
cleanup(char *msg) // single program exit point;

@implementation Cube
- (void)showMessage: (OFString *)msg
{
#ifdef _WIN32
	MessageBoxW(NULL, msg.UTF16String, L"cube fatal error",
	    MB_OK | MB_SYSTEMMODAL);
#else
	[OFStdOut writeString: msg];
#endif
}

- (void)applicationWillTerminate: (OFNotification *)notification
{
	stop();
	disconnect(true);
	writecfg();
	cleangl();
	cleansound();
	cleanupserver();
	SDL_ShowCursor(1);
	if (msg) {
#ifdef _WIN32
		MessageBox(
		    NULL, msg, "cube fatal error", MB_OK | MB_SYSTEMMODAL);
#else
		printf(msg);
#endif
	};
	SDL_Quit();
	exit(1);
};
}

void
quit() // normal exit
{
	writeservercfg();
	cleanup(NULL);
	[OFApplication.sharedApplication terminateWithStatus: 0];
};
}

void
fatal(char *s, char *o) // failure exit
{
	sprintf_sd(msg)("%s%s (%s)\n", s, o, SDL_GetError());
	OFApplication *app = OFApplication.sharedApplication;
	cleanup(msg);
	[(Cube *)app.delegate showMessage: @(msg)];
};
	[app terminateWithStatus: 1];
}

void *
alloc(int s) // for some big chunks... most other allocs use the memory pool
{
	void *b = calloc(1, s);
	if (!b)
		fatal("out of memory!");
	return b;
};
}

int scr_w = 640;
int scr_h = 480;

void
screenshot()
{
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
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
118
119
120
121
122
123







-
+









-
+







-
+
-





+
+
+
+
+
+
+







			sprintf_sd(buf)(
			    "screenshots/screenshot_%d.bmp", lastmillis);
			SDL_SaveBMP(temp, path(buf));
			SDL_FreeSurface(temp);
		};
		SDL_FreeSurface(image);
	};
};
}

COMMAND(screenshot, ARG_NONE);
COMMAND(quit, ARG_NONE);

void
keyrepeat(bool on)
{
	SDL_EnableKeyRepeat(
	    on ? SDL_DEFAULT_REPEAT_DELAY : 0, SDL_DEFAULT_REPEAT_INTERVAL);
};
}

VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100);
VARP(minmillis, 0, 5, 1000);

int islittleendian = 1;
int framesinmap = 0;

int
- (void)applicationDidFinishLaunching: (OFNotification *)notification
main(int argc, char **argv)
{
	bool dedicated = false;
	int fs = SDL_FULLSCREEN, par = 0, uprate = 0, maxcl = 4;
	char *sdesc = "", *ip = "", *master = NULL, *passwd = "";
	islittleendian = *((char *)&islittleendian);
	int argc, *argcPtr;
	char **argv, ***argvPtr;

	[OFApplication.sharedApplication getArgumentCount: &argcPtr
					andArgumentValues: &argvPtr];
	argc = *argcPtr;
	argv = *argvPtr;

	processInitQueue();

#define log(s) conoutf(@"init: %s", s)
	log("sdl");

	for (int i = 1; i < argc; i++) {
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
256
257
258
259
260
261
262

263
264
265
266
267
268
269
270







-
+







		if (framesinmap++ <
		    5) // cheap hack to get rid of initial sparklies, even when
		       // triple buffering etc.
		{
			player1->yaw += 5;
			gl_drawframe(scr_w, scr_h, fps);
			player1->yaw -= 5;
		};
		}
		gl_drawframe(scr_w, scr_h, fps);
		SDL_Event event;
		int lasttype = 0, lastbut = 0;
		while (SDL_PollEvent(&event)) {
			switch (event.type) {
			case SDL_QUIT:
				quit();
281
282
283
284
285
286
287
288
289
290



291

292

293
292
293
294
295
296
297
298



299
300
301
302
303

304








-
-
-
+
+
+

+
-
+
-
					break; // why?? get event twice without
					       // it
				keypress(-event.button.button,
				    event.button.state != 0, 0);
				lasttype = event.type;
				lastbut = event.button.button;
				break;
			};
		};
	};
			}
		}
	}
	quit();
}
	return 1;
@end
};