Cube  Check-in [7c2704b3d7]

Overview
Comment:Convert to ObjC++
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7c2704b3d77d6e63d960e315bfb601fddbf6fce538b7c5db6da664e04fbce4c2
User & Date: js on 2024-07-21 12:02:07
Other Links: manifest | tags
Context
2024-08-02
11:09
Fix crash when compiled with Clang check-in: 5e7a0895eb user: js tags: trunk
2024-07-21
12:02
Convert to ObjC++ check-in: 7c2704b3d7 user: js tags: trunk
2024-07-20
21:49
Fix needing -fpermissive check-in: bd82b5a5b1 user: js tags: trunk
Changes

Modified configure.ac from [05470e5b2e] to [e3f3f558bf].

9
10
11
12
13
14
15
16
17
18










19
20
21
22
23
24
25
9
10
11
12
13
14
15



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32







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







	])
done

BUILDSYS_INIT

AC_PROG_CC
AC_PROG_CPP

AC_PROG_CXX
AC_PROG_CXXCPP
AC_PROG_OBJCXX(clang++ g++)
AC_PROG_OBJCXXCPP

AC_CHECK_TOOL(OBJFW_CONFIG, objfw-config)
AS_IF([test x"$OBJFW_CONFIG" = x""], [
	AC_MSG_ERROR(You need ObjFW and objfw-config installed!)
])
OBJCXXFLAGS="$OBJCXXFLAGS $($OBJFW_CONFIG --cppflags --objcflags)"
LDFLAGS="$($OBJFW_CONFIG --ldflags --rpath)"
LIBS="$($OBJFW_CONFIG --libs) $LIBS"

AC_PATH_TOOL(AR, ar)
AC_PATH_TOOL(RANLIB, ranlib)

PKG_CHECK_MODULES(SDL, [
	sdl12_compat >= 1.2
	SDL_image >= 1.2

Modified src/Makefile from [0d0753c570] to [0d9a0e0a60].

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



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


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















-
-
+
+
+
PROG = client

SRCS = client.cxx		\
       clientextras.cxx		\
       clientgame.cxx		\
       clients2c.cxx		\
       command.cxx		\
       console.cxx		\
       editing.cxx		\
       entities.cxx		\
       main.cxx			\
       menus.cxx		\
       monster.cxx		\
       physics.cxx		\
       rendercubes.cxx		\
       renderextras.cxx		\
       rendergl.cxx		\
       rendermd2.cxx		\
       renderparticles.cxx	\
       rendertext.cxx		\
       rndmap.cxx		\
       savegamedemo.cxx		\
       server.cxx		\
       serverbrowser.cxx	\
       serverms.cxx		\
       serverutil.cxx		\
       sound.cxx		\
       tools.cxx		\
       weapon.cxx		\
       world.cxx		\
       worldio.cxx		\
       worldlight.cxx		\
       worldocull.cxx		\
       worldrender.cxx
SRCS = client.mm		\
       clientextras.mm		\
       clientgame.mm		\
       clients2c.mm		\
       command.mm		\
       console.mm		\
       editing.mm		\
       entities.mm		\
       main.mm			\
       menus.mm			\
       monster.mm		\
       physics.mm		\
       rendercubes.mm		\
       renderextras.mm		\
       rendergl.mm		\
       rendermd2.mm		\
       renderparticles.mm	\
       rendertext.mm		\
       rndmap.mm		\
       savegamedemo.mm		\
       server.mm		\
       serverbrowser.mm		\
       serverms.mm		\
       serverutil.mm		\
       sound.mm			\
       tools.mm			\
       weapon.mm		\
       world.mm			\
       worldio.mm		\
       worldlight.mm		\
       worldocull.mm		\
       worldrender.mm

include ../buildsys.mk
include ../extra.mk

CPPFLAGS += -I../enet/include	\
	    ${SDL_CFLAGS}	\
	    ${GL_CFLAGS}	\
	    ${GLU_CFLAGS}	\
	    ${X11_CFLAGS}	\
	    ${ZLIB_CFLAGS}
LIBS += -L../enet -lenet	\
	${SDL_LIBS}		\
	${GL_LIBS}		\
	${GLU_LIBS}		\
	${X11_LIBS}		\
	${ZLIB_LIBS}
LD = ${CXX}
	${ZLIB_LIBS}		\
	-lm
LD = ${OBJCXX}

Name change from src/client.cxx to src/client.mm.

Name change from src/clientextras.cxx to src/clientextras.mm.

Name change from src/clientgame.cxx to src/clientgame.mm.

Name change from src/clients2c.cxx to src/clients2c.mm.

Renamed and modified src/command.cxx [4e6af6f959] to src/command.mm [e3c08f18b8].

151
152
153
154
155
156
157
158
159
160



161
162
163

164
165
166

167
168
169
170
171
172
173
151
152
153
154
155
156
157



158
159
160
161
162

163
164
165

166
167
168
169
170
171
172
173







-
-
-
+
+
+


-
+


-
+







		return NULL;
	return newstring(word, p - word);
};

char *
lookup(char *n) // find value of ident referenced with $ in exp
{
	ident *id = idents->access(n + 1);
	if (id)
		switch (id->type) {
	ident *ID = idents->access(n + 1);
	if (ID)
		switch (ID->type) {
		case ID_VAR:
			string t;
			itoa(t, *(id->storage));
			itoa(t, *(ID->storage));
			return exchangestr(n, t);
		case ID_ALIAS:
			return exchangestr(n, id->action);
			return exchangestr(n, ID->action);
		};
	conoutf("unknown alias lookup: %s", n + 1);
	return n;
};

int
execute(char *p, bool isdown) // all evaluation happens here, recursively
198
199
200
201
202
203
204
205
206


207
208
209
210
211

212
213

214
215
216
217
218

219
220
221
222
223
224

225
226
227
228
229
230

231
232
233
234
235
236

237
238
239
240
241
242

243
244
245
246
247

248
249
250
251
252

253
254
255
256
257
258

259
260
261
262
263
264
265

266
267
268
269

270
271
272
273
274

275
276
277
278
279

280
281
282
283
284
285

286
287
288
289
290
291

292
293
294
295
296

297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315

316
317
318
319
320
321
322
323
324
325

326
327
328
329
330
331
332

333
334
335
336
337
338


339
340
341
342



343
344
345
346
347
348
349


350
351

352
353
354


355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374

375
376
377
378
379
380
381
198
199
200
201
202
203
204


205
206
207
208
209
210

211
212

213
214
215
216
217

218
219
220
221
222
223

224
225
226
227
228
229

230
231
232
233
234
235

236
237
238
239
240
241

242
243
244
245
246

247
248
249
250
251

252
253
254
255
256
257

258
259
260
261
262
263
264

265
266
267
268

269
270
271
272
273

274
275
276
277
278

279
280
281
282
283
284

285
286
287
288
289
290

291
292
293
294
295

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
322
323
324

325
326
327
328
329
330
331

332
333
334
335
336


337
338
339



340
341
342
343
344
345
346
347


348
349
350

351
352


353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373

374
375
376
377
378
379
380
381







-
-
+
+




-
+

-
+




-
+





-
+





-
+





-
+





-
+




-
+




-
+





-
+






-
+



-
+




-
+




-
+





-
+





-
+




-
+


















-
+









-
+






-
+




-
-
+
+

-
-
-
+
+
+





-
-
+
+

-
+

-
-
+
+



















-
+







		       0; // more statements if this isn't the end of the string
		char *c = w[0];
		if (*c == '/')
			c++; // strip irc-style command prefix
		if (!*c)
			continue; // empty statement

		ident *id = idents->access(c);
		if (!id) {
		ident *ID = idents->access(c);
		if (!ID) {
			val = ATOI(c);
			if (!val && *c != '0')
				conoutf("unknown command: %s", c);
		} else
			switch (id->type) {
			switch (ID->type) {
			case ID_COMMAND:          // game defined commands
				switch (id->narg) // use very ad-hoc function
				switch (ID->narg) // use very ad-hoc function
				                  // signature, and just call it
				{
				case ARG_1INT:
					if (isdown)
						((void(__cdecl *)(int))id->fun)(
						((void(__cdecl *)(int))ID->fun)(
						    ATOI(w[1]));
					break;
				case ARG_2INT:
					if (isdown)
						((void(__cdecl *)(
						    int, int))id->fun)(
						    int, int))ID->fun)(
						    ATOI(w[1]), ATOI(w[2]));
					break;
				case ARG_3INT:
					if (isdown)
						((void(__cdecl *)(int, int,
						    int))id->fun)(ATOI(w[1]),
						    int))ID->fun)(ATOI(w[1]),
						    ATOI(w[2]), ATOI(w[3]));
					break;
				case ARG_4INT:
					if (isdown)
						((void(__cdecl *)(int, int, int,
						    int))id->fun)(ATOI(w[1]),
						    int))ID->fun)(ATOI(w[1]),
						    ATOI(w[2]), ATOI(w[3]),
						    ATOI(w[4]));
					break;
				case ARG_NONE:
					if (isdown)
						((void(__cdecl *)())id->fun)();
						((void(__cdecl *)())ID->fun)();
					break;
				case ARG_1STR:
					if (isdown)
						((void(__cdecl *)(
						    char *))id->fun)(w[1]);
						    char *))ID->fun)(w[1]);
					break;
				case ARG_2STR:
					if (isdown)
						((void(__cdecl *)(
						    char *, char *))id->fun)(
						    char *, char *))ID->fun)(
						    w[1], w[2]);
					break;
				case ARG_3STR:
					if (isdown)
						((void(__cdecl *)(char *,
						    char *, char *))id->fun)(
						    char *, char *))ID->fun)(
						    w[1], w[2], w[3]);
					break;
				case ARG_5STR:
					if (isdown)
						((void(__cdecl *)(char *,
						    char *, char *, char *,
						    char *))id->fun)(w[1], w[2],
						    char *))ID->fun)(w[1], w[2],
						    w[3], w[4], w[5]);
					break;
				case ARG_DOWN:
					((void(__cdecl *)(bool))id->fun)(
					((void(__cdecl *)(bool))ID->fun)(
					    isdown);
					break;
				case ARG_DWN1:
					((void(__cdecl *)(bool,
					    char *))id->fun)(isdown, w[1]);
					    char *))ID->fun)(isdown, w[1]);
					break;
				case ARG_1EXP:
					if (isdown)
						val = ((int(__cdecl *)(
						    int))id->fun)(
						    int))ID->fun)(
						    execute(w[1]));
					break;
				case ARG_2EXP:
					if (isdown)
						val = ((int(__cdecl *)(int,
						    int))id->fun)(execute(w[1]),
						    int))ID->fun)(execute(w[1]),
						    execute(w[2]));
					break;
				case ARG_1EST:
					if (isdown)
						val = ((int(__cdecl *)(
						    char *))id->fun)(w[1]);
						    char *))ID->fun)(w[1]);
					break;
				case ARG_2EST:
					if (isdown)
						val = ((int(__cdecl *)(
						    char *, char *))id->fun)(
						    char *, char *))ID->fun)(
						    w[1], w[2]);
					break;
				case ARG_VARI:
					if (isdown) {
						string r; // limit, remove
						r[0] = 0;
						for (int i = 1; i < numargs;
						     i++) {
							strcat_s(r,
							    w[i]); // make
							           // string-list
							           // out of all
							           // arguments
							if (i == numargs - 1)
								break;
							strcat_s(r, " ");
						};
						((void(__cdecl *)(
						    char *))id->fun)(r);
						    char *))ID->fun)(r);
						break;
					}
				};
				break;

			case ID_VAR: // game defined variabled
				if (isdown) {
					if (!w[1][0])
						conoutf("%s = %d", c,
						    *id->storage); // var with
						    *ID->storage); // var with
						                   // no value
						                   // just
						                   // prints its
						                   // current
						                   // value
					else {
						if (id->min > id->max) {
						if (ID->min > ID->max) {
							conoutf("variable is "
							        "read-only");
						} else {
							int i1 = ATOI(w[1]);
							if (i1 < id->min ||
							    i1 > id->max) {
							if (i1 < ID->min ||
							    i1 > ID->max) {
								i1 =
								    i1 < id->min
								        ? id->min
								        : id->max; // clamp to valid range
								    i1 < ID->min
								        ? ID->min
								        : ID->max; // clamp to valid range
								conoutf(
								    "valid "
								    "range for "
								    "%s is "
								    "%d..%d",
								    c, id->min,
								    id->max);
								    c, ID->min,
								    ID->max);
							}
							*id->storage = i1;
							*ID->storage = i1;
						};
						if (id->fun)
							((void(__cdecl *)())id
						if (ID->fun)
							((void(__cdecl *)())ID
							        ->fun)(); // call
							                  // trigger
							                  // function
							                  // if
							                  // available
					};
				};
				break;

			case ID_ALIAS: // alias, also used as functions and
			               // (global) variables
				for (int i = 1; i < numargs; i++) {
					sprintf_sd(t)("arg%d",
					    i); // set any arguments as (global)
					        // arg values so functions can
					        // access them
					alias(t, w[i]);
				};
				char *action = newstring(
				    id->action); // create new string here
				    ID->action); // create new string here
				                 // because alias could rebind
				                 // itself
				val = execute(action, isdown);
				gp()->deallocstr(action);
				break;
			};
		loopj(numargs) gp()->deallocstr(w[j]);
450
451
452
453
454
455
456
457
458


459
460
461
462
463
464
465
466



467
468
469
470
471
472
473
450
451
452
453
454
455
456


457
458
459
460
461
462
463



464
465
466
467
468
469
470
471
472
473







-
-
+
+





-
-
-
+
+
+







	fprintf(f, "// automatically written on exit, do not modify\n// delete "
	           "this file to have defaults.cfg overwrite these "
	           "settings\n// modify settings in game, or put settings in "
	           "autoexec.cfg to override anything\n\n");
	writeclientinfo(f);
	fprintf(f, "\n");
	enumerate(
	    idents, ident *, id, if (id->type == ID_VAR && id->persist) {
		    fprintf(f, "%s %d\n", id->name, *id->storage);
	    idents, ident *, ID, if (ID->type == ID_VAR && ID->persist) {
		    fprintf(f, "%s %d\n", ID->name, *ID->storage);
	    };);
	fprintf(f, "\n");
	writebinds(f);
	fprintf(f, "\n");
	enumerate(
	    idents, ident *, id,
	    if (id->type == ID_ALIAS && !strstr(id->name, "nextmap_")) {
		    fprintf(f, "alias \"%s\" [%s]\n", id->name, id->action);
	    idents, ident *, ID,
	    if (ID->type == ID_ALIAS && !strstr(ID->name, "nextmap_")) {
		    fprintf(f, "alias \"%s\" [%s]\n", ID->name, ID->action);
	    };);
	fclose(f);
};

COMMAND(writecfg, ARG_NONE);

// below the commands that implement a small imperative language. thanks to the

Name change from src/console.cxx to src/console.mm.

Name change from src/editing.cxx to src/editing.mm.

Name change from src/entities.cxx to src/entities.mm.

Name change from src/main.cxx to src/main.mm.

Name change from src/menus.cxx to src/menus.mm.

Name change from src/monster.cxx to src/monster.mm.

Name change from src/physics.cxx to src/physics.mm.

Name change from src/rendercubes.cxx to src/rendercubes.mm.

Name change from src/renderextras.cxx to src/renderextras.mm.

Name change from src/rendergl.cxx to src/rendergl.mm.

Name change from src/rendermd2.cxx to src/rendermd2.mm.

Name change from src/renderparticles.cxx to src/renderparticles.mm.

Name change from src/rendertext.cxx to src/rendertext.mm.

Name change from src/rndmap.cxx to src/rndmap.mm.

Name change from src/savegamedemo.cxx to src/savegamedemo.mm.

Name change from src/server.cxx to src/server.mm.

Name change from src/serverbrowser.cxx to src/serverbrowser.mm.

Name change from src/serverms.cxx to src/serverms.mm.

Name change from src/serverutil.cxx to src/serverutil.mm.

Name change from src/sound.cxx to src/sound.mm.

Name change from src/tools.cxx to src/tools.mm.

Name change from src/weapon.cxx to src/weapon.mm.

Name change from src/world.cxx to src/world.mm.

Name change from src/worldio.cxx to src/worldio.mm.

Name change from src/worldlight.cxx to src/worldlight.mm.

Name change from src/worldocull.cxx to src/worldocull.mm.

Name change from src/worldrender.cxx to src/worldrender.mm.