Cube  Check-in [1ee33c9983]

Overview
Comment:Don't depend on global constructors for commands

This breaks when using ObjC, as these can run before the ObjC module is initialized, resulting in non-working message sends as the selectors are not registered yet.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1ee33c99835abc029ac202afad1f9b3bf26028e55ea1c53c53416c7566ef749d
User & Date: js on 2024-08-03 14:50:31
Other Links: manifest | tags
Context
2024-08-03
15:12
Start migrating commands / variables to ObjC++ check-in: f4c57c1df0 user: js tags: trunk
14:50
Don't depend on global constructors for commands check-in: 1ee33c9983 user: js tags: trunk
13:17
Add server to meson.build check-in: 0cfe4b85e2 user: js tags: trunk
Changes

Modified meson.build from [db7a10eabb] to [e523f05d4d].

1
2
3
4


5


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

7
8
9
10
11
12
13
14
15




+
+
-
+
+







project('Cube', ['c', 'objcpp'],
  meson_version: '1.5.0')

add_global_arguments(
  [
    '-fobjc-arc',
  ['-fobjc-arc', '-fobjc-arc-exceptions'],
    '-fobjc-arc-exceptions'
  ],
  language: 'objcpp')

objfw_dep = dependency('objfw')
sdl12_dep = dependency('sdl12_compat')
sdlimage_dep = dependency('SDL_image')
sdlmixer_dep = dependency('SDL_mixer')
gl_dep = dependency('gl')
35
36
37
38
39
40
41

42
43
44
45
46
47
48
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52







+







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

Modified src/cube.h from [11dc4e9109] to [ac53062292].

1
2


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


+
+







// 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
386
387
388
389
390
391
392



393



394
395




396



397




398



399
400

401
402







403
404
405




406
407




408
409
410
411
412
413
414
388
389
390
391
392
393
394
395
396
397

398
399
400
401
402
403
404
405
406

407
408
409
410
411
412
413
414

415
416
417
418
419
420


421
422
423
424
425
426
427
428
429
430
431
432
433
434


435
436
437
438
439
440
441
442
443
444
445







+
+
+
-
+
+
+


+
+
+
+
-
+
+
+

+
+
+
+
-
+
+
+


+
-
-
+
+
+
+
+
+
+



+
+
+
+
-
-
+
+
+
+







	ARG_2EST,
	ARG_VARI
};

// nasty macros for registering script functions, abuses globals to avoid
// excessive infrastructure
#define COMMANDN(name, fun, nargs)                                             \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                                 \
	static bool __dummy_##fun = addcommand(#name, (void (*)())fun, nargs)
		  addcommand(#name, (void (*)())fun, nargs);                   \
		});                                                            \
	}
#define COMMAND(name, nargs) COMMANDN(name, name, nargs)
#define VARP(name, min, cur, max)                                              \
	int name;                                                              \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                                 \
	int name = variable(#name, min, cur, max, &name, NULL, true)
		  name = variable(#name, min, cur, max, &name, NULL, true);    \
		});                                                            \
	}
#define VAR(name, min, cur, max)                                               \
	int name;                                                              \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                                 \
	int name = variable(#name, min, cur, max, &name, NULL, false)
		  name = variable(#name, min, cur, max, &name, NULL, false);   \
		});                                                            \
	}
#define VARF(name, min, cur, max, body)                                        \
	void var_##name();                                                     \
	static int name;                                                       \
	static int name =                                                      \
	    variable(#name, min, cur, max, &name, var_##name, false);          \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                                 \
		  name = variable(                                             \
		      #name, min, cur, max, &name, var_##name, false);         \
		});                                                            \
	}                                                                      \
	void var_##name() { body; }
#define VARFP(name, min, cur, max, body)                                       \
	void var_##name();                                                     \
	static int name;                                                       \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                                 \
	static int name =                                                      \
	    variable(#name, min, cur, max, &name, var_##name, true);           \
		  name =                                                       \
		      variable(#name, min, cur, max, &name, var_##name, true); \
		});                                                            \
	}                                                                      \
	void var_##name() { body; }

#define ATOI(s) strtol(s, NULL, 0) // supports hexadecimal numbers

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

Added src/init.mm version [18cd3f3736].

Modified src/main.mm from [9f8b587f26] to [65508559f3].

99
100
101
102
103
104
105


106
107
108
109
110
111
112
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114







+
+







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++) {
		char *a = &argv[i][2];
		if (argv[i][0] == '-')

Modified src/protos.h from [1ced1650a0] to [135758e2d7].

19
20
21
22
23
24
25




26
27
28
29
30
31
32
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36







+
+
+
+







// console
extern void keypress(int code, bool isdown, int cooked);
extern void renderconsole();
extern void conoutf(const char *s, ...);
extern char *getcurcommand();
extern void writebinds(FILE *f);

// init
extern void enqueueInit(const char *name, void (^init)(void));
extern void processInitQueue(void);

// menus
extern bool rendermenu();
extern void menuset(int menu);
extern void menumanual(int m, int n, char *text);
extern void sortmenu(int start, int num);
extern bool menukey(int code, bool isdown);
extern void newmenu(char *name);