Cube  Diff

Differences From Artifact [a8778ab451]:

To Artifact [da94b33242]:


1
2
3
4


5
6
7
8
9
10
11
12
// world.cpp: core map management stuff

#include "cube.h"



extern char *entnames[]; // lookup from map entities above to strings

sqr *world = NULL;
int sfactor, ssize, cubicsize, mipsize;

header hdr;

void




>
>
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
// world.cpp: core map management stuff

#include "cube.h"

#include <memory>

extern OFString *entnames[]; // lookup from map entities above to strings

sqr *world = NULL;
int sfactor, ssize, cubicsize, mipsize;

header hdr;

void
54
55
56
57
58
59
60

61

62
63



64

65

66



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
}; // set for playing

void
trigger(int tag, int type, bool savegame)
{
	if (!tag)
		return;

	settag(tag, type);

	if (!savegame && type != 3)
		playsound(S_RUMBLE);



	sprintf_sd(aliasname)("level_trigger_%d", tag);

	if (identexists(aliasname))

		execute(aliasname);



	if (type == 2)
		endsp(false);
}
COMMAND(trigger, ARG_2INT)

// main geometric mipmapping routine, recursively rebuild mipmaps within block
// b. tries to produce cube out of 4 lower level mips as well as possible, sets
// defer to 0 if mipped cube is a perfect mip, i.e. can be rendered at this mip
// level indistinguishable from its constituent cubes (saves considerable
// rendering time if this is possible).

void
remip(block &b, int level)
{
	if (level >= SMALLEST_FACTOR)
		return;
	int lighterr = getvar("lighterror") * 3;
	sqr *w = wmip[level];
	sqr *v = wmip[level + 1];
	int ws = ssize >> level;
	int vs = ssize >> (level + 1);
	block s = b;
	if (s.x & 1) {
		s.x--;







>

>


>
>
>
|
>
|
>
|
>
>
>
















|







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
}; // set for playing

void
trigger(int tag, int type, bool savegame)
{
	if (!tag)
		return;

	settag(tag, type);

	if (!savegame && type != 3)
		playsound(S_RUMBLE);

	@autoreleasepool {
		OFString *aliasname =
		    [OFString stringWithFormat:@"level_trigger_%d", tag];

		if (identexists(aliasname)) {
			std::unique_ptr<char> cmd(strdup(aliasname.UTF8String));
			execute(cmd.get());
		}
	}

	if (type == 2)
		endsp(false);
}
COMMAND(trigger, ARG_2INT)

// main geometric mipmapping routine, recursively rebuild mipmaps within block
// b. tries to produce cube out of 4 lower level mips as well as possible, sets
// defer to 0 if mipped cube is a perfect mip, i.e. can be rendered at this mip
// level indistinguishable from its constituent cubes (saves considerable
// rendering time if this is possible).

void
remip(block &b, int level)
{
	if (level >= SMALLEST_FACTOR)
		return;
	int lighterr = getvar(@"lighterror") * 3;
	sqr *w = wmip[level];
	sqr *v = wmip[level + 1];
	int ws = ssize >> level;
	int vs = ssize >> (level + 1);
	block s = b;
	if (s.x & 1) {
		s.x--;
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
{
	int e = closestent();
	if (e < 0) {
		conoutf(@"no more entities");
		return;
	};
	int t = ents[e].type;

	conoutf(@"%s entity deleted", entnames[t]);

	ents[e].type = NOTUSED;
	addmsg(1, 10, SV_EDITENT, e, NOTUSED, 0, 0, 0, 0, 0, 0, 0);
	if (t == LIGHT)
		calclight();
};


int
findtype(char *what)
{

	loopi(MAXENTTYPES) if (strcmp(what, entnames[i]) == 0) return i;
	conoutf(@"unknown entity type \"%s\"", what);
	return NOTUSED;

}

entity *
newentity(int x, int y, int z, char *what, int v1, int v2, int v3, int v4)
{
	int type = findtype(what);
	persistent_entity e = {(short)x, (short)y, (short)z, (short)v1,
	    (uchar)type, (uchar)v2, (uchar)v3, (uchar)v4};
	switch (type) {
	case LIGHT:
		if (v1 > 32)







>
|
>




<
|
>

|

>
|
|
|
>



|







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
{
	int e = closestent();
	if (e < 0) {
		conoutf(@"no more entities");
		return;
	};
	int t = ents[e].type;
	@autoreleasepool {
		conoutf(@"%s entity deleted", entnames[t].UTF8String);
	}
	ents[e].type = NOTUSED;
	addmsg(1, 10, SV_EDITENT, e, NOTUSED, 0, 0, 0, 0, 0, 0, 0);
	if (t == LIGHT)
		calclight();

}

int
findtype(OFString *what)
{
	@autoreleasepool {
		loopi(MAXENTTYPES) if ([what isEqual:entnames[i]]) return i;
		conoutf(@"unknown entity type \"%s\"", what.UTF8String);
		return NOTUSED;
	}
}

entity *
newentity(int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4)
{
	int type = findtype(what);
	persistent_entity e = {(short)x, (short)y, (short)z, (short)v1,
	    (uchar)type, (uchar)v2, (uchar)v3, (uchar)v4};
	switch (type) {
	case LIGHT:
		if (v1 > 32)
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
	ents.add(*((entity *)&e)); // unsafe!
	if (type == LIGHT)
		calclight();
	return &ents.last();
};

void
clearents(char *name)
{
	int type = findtype(name);
	if (noteditmode() || multiplayer())
		return;
	loopv(ents)
	{
		entity &e = ents[i];
		if (e.type == type)
			e.type = NOTUSED;
	};
	if (type == LIGHT)
		calclight();
}
COMMAND(clearents, ARG_1CSTR)

void
scalecomp(uchar &c, int intens)
{
	int n = c * intens / 100;
	if (n > 255)
		n = 255;







|













|







358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
	ents.add(*((entity *)&e)); // unsafe!
	if (type == LIGHT)
		calclight();
	return &ents.last();
};

void
clearents(OFString *name)
{
	int type = findtype(name);
	if (noteditmode() || multiplayer())
		return;
	loopv(ents)
	{
		entity &e = ents[i];
		if (e.type == type)
			e.type = NOTUSED;
	};
	if (type == LIGHT)
		calclight();
}
COMMAND(clearents, ARG_1STR)

void
scalecomp(uchar &c, int intens)
{
	int n = c * intens / 100;
	if (n > 255)
		n = 255;