Cube  Diff

Differences From Artifact [cfdf69a801]:

To Artifact [a9d5711584]:


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
103








104
105
106
107
108
109
110
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
103
104
105
106
107
108
109
110
111
112
113
114







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














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

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







{
	return s->type != FHF && s->type != CHF;
}

void
voptimize() // reset vdeltas on non-hf cubes
{
	loop(x, ssize) loop(y, ssize)
	for (int x = 0; x < ssize; x++) {
	{
		struct sqr *s = S(x, y);
		if (x && y) {
			if (nhf(s) && nhf(S(x - 1, y)) &&
			    nhf(S(x - 1, y - 1)) && nhf(S(x, y - 1)))
				s->vdelta = 0;
		} else
			s->vdelta = 0;
		for (int y = 0; y < ssize; y++) {
			struct sqr *s = S(x, y);

			if (x && y) {
				if (nhf(s) && nhf(S(x - 1, y)) &&
				    nhf(S(x - 1, y - 1)) && nhf(S(x, y - 1)))
					s->vdelta = 0;
			} else
				s->vdelta = 0;
		}
	}
}

static void
topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut)
{
	struct sqr *o[4];
	o[0] = SWS(s, 0, -1, ssize);
	o[1] = SWS(s, 0, 1, ssize);
	o[2] = SWS(s, 1, 0, ssize);
	o[3] = SWS(s, -1, 0, ssize);
	*wf = true;
	*uf = true;
	if (SOLID(s)) {
		for (int i = 0; i < 4; i++) {
		loopi(4) if (!SOLID(o[i]))
			if (!SOLID(o[i])) {
		{
			*wf = false;
			*wt = s->wtex;
			*ut = s->utex;
			return;
		}
				*wf = false;
				*wt = s->wtex;
				*ut = s->utex;
				return;
			}
		}
	} else {
		for (int i = 0; i < 4; i++) {
		loopi(4) if (!SOLID(o[i]))
			if (!SOLID(o[i])) {
		{
			if (o[i]->floor < s->floor) {
				*wt = s->wtex;
				*wf = false;
			}
			if (o[i]->ceil > s->ceil) {
				*ut = s->utex;
				*uf = false;
				if (o[i]->floor < s->floor) {
					*wt = s->wtex;
					*wf = false;
				}
				if (o[i]->ceil > s->ceil) {
					*ut = s->utex;
					*uf = false;
				}
			}
		}
	}
}

void
toptimize() // FIXME: only does 2x2, make atleast for 4x4 also
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
133
122
123
124
125
126
127
128

129

130
131
132
133
134
135
136







-
+
-







			topt(s[0], &wf[0], &uf[0], &wt, &ut);
			topt(s[1] = SWS(s[0], 0, 1, ssize), &wf[1], &uf[1], &wt,
			    &ut);
			topt(s[2] = SWS(s[0], 1, 1, ssize), &wf[2], &uf[2], &wt,
			    &ut);
			topt(s[3] = SWS(s[0], 1, 0, ssize), &wf[3], &uf[3], &wt,
			    &ut);
			loopi(4)
			for (int i = 0; i < 4; i++) {
			{
				if (wf[i])
					s[i]->wtex = wt;
				if (uf[i])
					s[i]->utex = ut;
			}
		}
	}
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
209
210
211
212
213
214
215

216

217
218
219
220
221
222
223







-
+
-







			gzputc(f, 255); \
			sc -= 255;      \
		} else {                \
			gzputc(f, sc);  \
			sc = 0;         \
		}                       \
	}
	loopk(cubicsize)
	for (int k = 0; k < cubicsize; k++) {
	{
		struct sqr *s = &world[k];
#define c(f) (s->f == t->f)
		// 4 types of blocks, to compress a bit:
		// 255 (2): same as previous block + count
		// 254 (3): same as previous, except light // deprecated
		// SOLID (5)
		// anything else (9)
281
282
283
284
285
286
287
288

289
290
291
292
293
294
295
296
283
284
285
286
287
288
289

290

291
292
293
294
295
296
297







-
+
-







	if (hdr.version >= 4) {
		gzread(f, &hdr.waterlevel, sizeof(int) * 16);
		endianswap(&hdr.waterlevel, sizeof(int), 16);
	} else {
		hdr.waterlevel = -100000;
	}
	[ents removeAllObjects];
	loopi(hdr.numents)
	for (int i = 0; i < hdr.numents; i++) {
	{
		struct persistent_entity tmp;
		gzread(f, &tmp, sizeof(struct persistent_entity));
		endianswap(&tmp, sizeof(short), 4);

		Entity *e = [Entity entity];
		e.x = tmp.x;
		e.y = tmp.y;
308
309
310
311
312
313
314

315

316
317

318
319
320
321
322
323
324
325
309
310
311
312
313
314
315
316

317
318

319

320
321
322
323
324
325
326







+
-
+

-
+
-







			if (e.attr1 > 32)
				e.attr1 = 32; // 12_03 and below
		}
	}
	free(world);
	setupworld(hdr.sfactor);
	char texuse[256];
	for (int i = 0; i < 256; i++)
	loopi(256) texuse[i] = 0;
		texuse[i] = 0;
	struct sqr *t = NULL;
	loopk(cubicsize)
	for (int k = 0; k < cubicsize; k++) {
	{
		struct sqr *s = &world[k];
		int type = gzgetc(f);
		switch (type) {
		case 255: {
			int n = gzgetc(f);
			for (int i = 0; i < n; i++, k++)
				memcpy(&world[k], t, sizeof(struct sqr));
378
379
380
381
382
383
384


385

386
387
388
389
390

391
392
393
394
395
396
397
398
399
400
401
402
403
379
380
381
382
383
384
385
386
387

388
389
390
391
392

393

394
395
396
397
398
399
400
401
402
403
404
405







+
+
-
+




-
+
-












		if (!SOLID(s))
			texuse[s->utex] = texuse[s->ftex] = texuse[s->ctex] = 1;
	}
	gzclose(f);
	calclight();
	settagareas();
	int xs, ys;
	for (int i = 0; i < 256; i++)
		if (texuse[i])
	loopi(256) if (texuse[i]) lookuptexture(i, &xs, &ys);
			lookuptexture(i, &xs, &ys);
	conoutf(@"read map %@ (%d milliseconds)", cgzname,
	    SDL_GetTicks() - lastmillis);
	conoutf(@"%s", hdr.maptitle);
	startmap(mname);
	loopl(256)
	for (int l = 0; l < 256; l++) {
	{
		// can this be done smarter?
		OFString *aliasname =
		    [OFString stringWithFormat:@"level_trigger_%d", l];
		if (identexists(aliasname))
			alias(aliasname, @"");
	}
	OFIRI *gameDataIRI = Cube.sharedInstance.gameDataIRI;
	execfile([gameDataIRI
	    IRIByAppendingPathComponent:@"data/default_map_settings.cfg"]);
	execfile([gameDataIRI IRIByAppendingPathComponent:pcfname]);
	execfile([gameDataIRI IRIByAppendingPathComponent:mcfname]);
}