Cube  Check-in [9432e52ca0]

Overview
Comment:Migrate to OFApplicationDelegate
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9432e52ca0f52d0661ae65c0cebbf1fa9259a4d3459b4f6df4927fa4ac18c609
User & Date: js on 2025-03-02 14:02:43
Other Links: manifest | tags
Context
2025-03-02
14:42
Migrate to OFOptionsParser check-in: f642e9dfbf user: js tags: trunk
14:02
Migrate to OFApplicationDelegate check-in: 9432e52ca0 user: js tags: trunk
2024-08-05
00:31
Merge accidental fork check-in: f9d39991c5 user: js tags: trunk
Changes

Renamed and modified src/main.mm [6994beff69] to src/Cube.mm [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
// main.cpp: initialisation & main loop

#include "cube.h"


void










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

{
	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);
};


void
fatal(char *s, char *o) // failure exit
{
	sprintf_sd(msg)("%s%s (%s)\n", s, o, SDL_GetError());

	cleanup(msg);
};



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()
{




>
|
>
>
>
>
>
>
>
>
>
>
|
>








<
<
<
<
<
<
<
<

<
<
>





|
<
>





>
|
<
>
>








<
>







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)

@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);








	SDL_Quit();


}

void
quit() // normal exit
{
	writeservercfg();
	[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;
	[(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
			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
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);








	processInitQueue();

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

	for (int i = 1; i < argc; i++) {







<
>









<
>







|
<





>
>
>
>
>
>
>







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;

- (void)applicationDidFinishLaunching: (OFNotification *)notification

{
	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
		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();







<
>







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







<
<
<
>
>
>

>
|
<
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();
}
@end

Modified src/cube.h from [24088972ed] to [7ef12d6e13].

1
2
3
4
5



6
7
8
9
10
11
12
// one big bad include file for the whole engine... nasty!

#import <ObjFW/ObjFW.h>

#include "tools.h"




enum // block types, order matters!
{
	SOLID = 0, // entirely solid cube [only specifies wtex]
	CORNER,    // half full corner of a wall
	FHF,       // floor heightfield using neighbour vdelta values
	CHF,       // idem ceiling





>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// one big bad include file for the whole engine... nasty!

#import <ObjFW/ObjFW.h>

#include "tools.h"

@interface Cube: OFObject <OFApplicationDelegate>
@end

enum // block types, order matters!
{
	SOLID = 0, // entirely solid cube [only specifies wtex]
	CORNER,    // half full corner of a wall
	FHF,       // floor heightfield using neighbour vdelta values
	CHF,       // idem ceiling

Modified src/meson.build from [20649ef684] to [2ab6d94742].

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
executable('client',
  [

    'client.mm',
    'clientextras.mm',
    'clientgame.mm',
    'clients2c.mm',
    'command.mm',
    'console.mm',
    'editing.mm',
    'entities.mm',
    'init.mm',
    'main.mm',
    'menus.mm',
    'monster.mm',
    'physics.mm',
    'rendercubes.mm',
    'renderextras.mm',
    'rendergl.mm',
    'rendermd2.mm',


>









<







1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
executable('client',
  [
    'Cube.mm',
    'client.mm',
    'clientextras.mm',
    'clientgame.mm',
    'clients2c.mm',
    'command.mm',
    'console.mm',
    'editing.mm',
    'entities.mm',
    'init.mm',

    'menus.mm',
    'monster.mm',
    'physics.mm',
    'rendercubes.mm',
    'renderextras.mm',
    'rendergl.mm',
    'rendermd2.mm',