Cube  Diff

Differences From Artifact [d285e7fbb6]:

To Artifact [4e3991eb16]:


1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18










-
+







// one big bad include file for the whole engine... nasty!

#import <ObjFW/ObjFW.h>

#define gamma gamma__
#include <SDL2/SDL.h>
#undef gamma

#include "tools.h"

@interface Cube : OFObject <OFApplicationDelegate>
@interface Cube: OFObject <OFApplicationDelegate>
@property (class, readonly, nonatomic) Cube *sharedInstance;
@property (readonly, nonatomic) SDL_Window *window;
@property (readonly, nonatomic) OFIRI *gameDataIRI, *userDataIRI;
@property (nonatomic) bool repeatsKeys;
@property (nonatomic) int framesInMap;
@end

76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90







-
+







{
	short x, y, z; // cube aligned position
	short attr1;
	uchar type; // type is one of the above
	uchar attr2, attr3, attr4;
};

struct entity : public persistent_entity {
struct entity: public persistent_entity {
	bool spawned; // the only dynamic state of a map entity
};

#define MAPVERSION 5 // bump if map format changes, see worldio.cpp

struct header // map file format header
{
103
104
105
106
107
108
109
110
111


112
113
114
115
116
117
118
103
104
105
106
107
108
109


110
111
112
113
114
115
116
117
118







-
-
+
+







#define SW(w, x, y) SWS(w, x, y, ssize)
#define S(x, y) SW(world, x, y) // convenient lookup of a lowest mip cube
#define SMALLEST_FACTOR 6       // determines number of mips there can be
#define DEFAULT_FACTOR 8
#define LARGEST_FACTOR 11 // 10 is already insane
#define SOLID(x) ((x)->type == SOLID)
#define MINBORD 2 // 2 cubes from the edge of the world are always solid
#define OUTBORD(x, y)                                                          \
	((x) < MINBORD || (y) < MINBORD || (x) >= ssize - MINBORD ||           \
#define OUTBORD(x, y)                                                \
	((x) < MINBORD || (y) < MINBORD || (x) >= ssize - MINBORD || \
	    (y) >= ssize - MINBORD)

struct block {
	int x, y, xs, ys;
};

enum {
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
157
158
159
160
161
162
163

164
165
166
167
168
169
170
171







-
+







	int trigger; // millis at which transition to another monsterstate takes
	             // place
	OFVector3D attacktarget; // delayed attacks
	int anger;               // how many times already hit by fellow monster
	string name, team;
};

#define SAVEGAMEVERSION                                                        \
#define SAVEGAMEVERSION \
	4 // bump if dynent/netprotocol changes or any other savegame/demo data

enum { A_BLUE, A_GREEN, A_YELLOW }; // armour types... take 20/40/60 % off
enum {
	M_NONE = 0,
	M_SEARCH,
	M_HOME,
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
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







-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+

-
-
+
+

-
-
-
-
-
+
+
+
+
+


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







#define PIXELTAB (VIRTW / 12)

#define PI (3.1415927f)
#define PI2 (2 * PI)

// simplistic vector ops
#define dotprod(u, v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z)
#define vmul(u, f)                                                             \
	{                                                                      \
		(u).x *= (f);                                                  \
		(u).y *= (f);                                                  \
		(u).z *= (f);                                                  \
#define vmul(u, f)            \
	{                     \
		(u).x *= (f); \
		(u).y *= (f); \
		(u).z *= (f); \
	}
#define vdiv(u, f)                                                             \
	{                                                                      \
		(u).x /= (f);                                                  \
		(u).y /= (f);                                                  \
		(u).z /= (f);                                                  \
#define vdiv(u, f)            \
	{                     \
		(u).x /= (f); \
		(u).y /= (f); \
		(u).z /= (f); \
	}
#define vadd(u, v)                                                             \
	{                                                                      \
		(u).x += (v).x;                                                \
		(u).y += (v).y;                                                \
		(u).z += (v).z;                                                \
#define vadd(u, v)              \
	{                       \
		(u).x += (v).x; \
		(u).y += (v).y; \
		(u).z += (v).z; \
	};
#define vsub(u, v)                                                             \
	{                                                                      \
		(u).x -= (v).x;                                                \
		(u).y -= (v).y;                                                \
		(u).z -= (v).z;                                                \
#define vsub(u, v)              \
	{                       \
		(u).x -= (v).x; \
		(u).y -= (v).y; \
		(u).z -= (v).z; \
	};
#define vdist(d, v, e, s)                                                      \
	OFVector3D v = s;                                                      \
	vsub(v, e);                                                            \
#define vdist(d, v, e, s) \
	OFVector3D v = s; \
	vsub(v, e);       \
	float d = (float)sqrt(dotprod(v, v));
#define vreject(v, u, max)                                                     \
	((v).x > (u).x + (max) || (v).x < (u).x - (max) ||                     \
#define vreject(v, u, max)                                 \
	((v).x > (u).x + (max) || (v).x < (u).x - (max) || \
	    (v).y > (u).y + (max) || (v).y < (u).y - (max))
#define vlinterp(v, f, u, g)                                                   \
	{                                                                      \
		(v).x = (v).x * f + (u).x * g;                                 \
		(v).y = (v).y * f + (u).y * g;                                 \
		(v).z = (v).z * f + (u).z * g;                                 \
#define vlinterp(v, f, u, g)                   \
	{                                      \
		(v).x = (v).x * f + (u).x * g; \
		(v).y = (v).y * f + (u).y * g; \
		(v).z = (v).z * f + (u).z * g; \
	}

#define sgetstr()                                                              \
	{                                                                      \
		char *t = text;                                                \
		do {                                                           \
			*t = getint(p);                                        \
		} while (*t++);                                                \
#define sgetstr()                       \
	{                               \
		char *t = text;         \
		do {                    \
			*t = getint(p); \
		} while (*t++);         \
	} // used by networking

#define m_noitems (gamemode >= 4)
#define m_noitemsrail (gamemode <= 5)
#define m_arena (gamemode >= 8)
#define m_tarena (gamemode >= 10)
#define m_teammode (gamemode & 1 && gamemode > 2)
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
446
447
448
449
450
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
446
447
448
449
450







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


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

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












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







	ARG_1EST,
	ARG_2EST,
	ARG_VARI
};

// nasty macros for registering script functions, abuses globals to avoid
// excessive infrastructure
#define COMMANDN(name, fun, nargs)                                             \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(^{                                                 \
			addcommand(@ #name, (void (*)())fun, nargs);           \
		});                                                            \
#define COMMANDN(name, fun, nargs)                                   \
	OF_CONSTRUCTOR()                                             \
	{                                                            \
		enqueueInit(^{                                       \
			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 = variable(                                       \
			    @ #name, min, cur, max, &name, NULL, true);        \
		});                                                            \
#define VARP(name, min, cur, max)                                       \
	int name;                                                       \
	OF_CONSTRUCTOR()                                                \
	{                                                               \
		enqueueInit(^{                                          \
			name = variable(                                \
			    @ #name, min, cur, max, &name, NULL, true); \
		});                                                     \
	}
#define VAR(name, min, cur, max)                                               \
	int name;                                                              \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(^{                                                 \
			name = variable(                                       \
			    @ #name, min, cur, max, &name, NULL, false);       \
		});                                                            \
#define VAR(name, min, cur, max)                                         \
	int name;                                                        \
	OF_CONSTRUCTOR()                                                 \
	{                                                                \
		enqueueInit(^{                                           \
			name = variable(                                 \
			    @ #name, min, cur, max, &name, NULL, false); \
		});                                                      \
	}
#define VARF(name, min, cur, max, body)                                        \
	void var_##name();                                                     \
	static int name;                                                       \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(^{                                                 \
			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 = variable(                                       \
			    @ #name, min, cur, max, &name, var_##name, true);  \
		});                                                            \
	}                                                                      \
#define VARFP(name, min, cur, max, body)                                      \
	void var_##name();                                                    \
	static int name;                                                      \
	OF_CONSTRUCTOR()                                                      \
	{                                                                     \
		enqueueInit(^{                                                \
			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"