Cube  Check-in [0d125c31da]

Overview
Comment:Migrate more strings
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0d125c31daf305a4363234402dbf375ecd71b24da762aa8e8c59751678cf47ec
User & Date: js on 2025-03-02 19:52:00
Other Links: manifest | tags
Context
2025-03-03
23:52
Migrate more strings check-in: e7b5d33cad user: js tags: trunk
00:30
Rename readme.txt -> README.md and update it check-in: 5570fb456d user: js tags: trunk
2025-03-02
19:52
Migrate more strings check-in: 0d125c31da user: js tags: trunk
14:56
Clean up enqueueInit check-in: d4f57c85c4 user: js tags: trunk
Changes

Modified src/Cube.mm from [d73ec16894] to [008a05c64e].

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
			SDL_SaveBMP(temp, path(buf));
			SDL_FreeSurface(temp);
		};
		SDL_FreeSurface(image);
	};
}

COMMAND(screenshot, ARG_NONE);
COMMAND(quit, ARG_NONE);

void
keyrepeat(bool on)
{
	SDL_EnableKeyRepeat(
	    on ? SDL_DEFAULT_REPEAT_DELAY : 0, SDL_DEFAULT_REPEAT_INTERVAL);
}







|
|







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
			SDL_SaveBMP(temp, path(buf));
			SDL_FreeSurface(temp);
		};
		SDL_FreeSurface(image);
	};
}

COMMAND(screenshot, ARG_NONE)
COMMAND(quit, ARG_NONE)

void
keyrepeat(bool on)
{
	SDL_EnableKeyRepeat(
	    on ? SDL_DEFAULT_REPEAT_DELAY : 0, SDL_DEFAULT_REPEAT_INTERVAL);
}
211
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
	exec("servers.cfg");
	if (!execfile("config.cfg"))
		execfile("data/defaults.cfg");
	exec("autoexec.cfg");

	log("localconnect");
	localconnect();
	changemap(
	    "metl3"); // if this map is changed, also change depthcorrect()


	log("mainloop");
	int ignore = 5;
	for (;;) {
		int millis = SDL_GetTicks() * gamespeed / 100;
		if (millis - lastmillis > 200)
			lastmillis = millis - 200;







<
|
>







211
212
213
214
215
216
217

218
219
220
221
222
223
224
225
226
	exec("servers.cfg");
	if (!execfile("config.cfg"))
		execfile("data/defaults.cfg");
	exec("autoexec.cfg");

	log("localconnect");
	localconnect();

	// if this map is changed, also change depthcorrect()
	changemap(@"metl3");

	log("mainloop");
	int ignore = 5;
	for (;;) {
		int millis = SDL_GetTicks() * gamespeed / 100;
		if (millis - lastmillis > 200)
			lastmillis = millis - 200;

Modified src/client.mm from [65bd73d8a9] to [72369d5670].

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
void
newteam(char *name)
{
	c2sinit = false;
	strn0cpy(player1->team, name, 5);
}

COMMANDN(team, newteam, ARG_1STR);
COMMANDN(name, newname, ARG_1STR);

void
writeclientinfo(FILE *f)
{
	fprintf(f, "name \"%s\"\nteam \"%s\"\n", player1->name, player1->team);
}








|
|







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
void
newteam(char *name)
{
	c2sinit = false;
	strn0cpy(player1->team, name, 5);
}

COMMANDN(team, newteam, ARG_1CSTR)
COMMANDN(name, newname, ARG_1CSTR)

void
writeclientinfo(FILE *f)
{
	fprintf(f, "name \"%s\"\nteam \"%s\"\n", player1->name, player1->team);
}

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

void
echo(char *text)
{
	conoutf(@"%s", text);
}

COMMAND(echo, ARG_VARI);
COMMANDN(say, toserver, ARG_VARI);
COMMANDN(connect, connects, ARG_1STR);
COMMANDN(disconnect, trydisconnect, ARG_NONE);

// collect c2s messages conveniently

vector<ivector> messages;

void
addmsg(int rel, int num, int type, ...)







|
|
|
|







167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

void
echo(char *text)
{
	conoutf(@"%s", text);
}

COMMAND(echo, ARG_VARI)
COMMANDN(say, toserver, ARG_VARI)
COMMANDN(connect, connects, ARG_1CSTR)
COMMANDN(disconnect, trydisconnect, ARG_NONE)

// collect c2s messages conveniently

vector<ivector> messages;

void
addmsg(int rel, int num, int type, ...)
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
server_err()
{
	conoutf(@"server network error, disconnecting...");
	disconnect();
}

int lastupdate = 0, lastping = 0;
string toservermap;
bool senditemstoserver =
    false; // after a map change, since server doesn't have map data

string clientpassword;
void
password(char *p)
{
	strcpy_s(clientpassword, p);
};

COMMAND(password, ARG_1STR);

bool
netmapstart()
{
	senditemstoserver = true;
	return clienthost != NULL;
};

void
initclientnet()
{
	ctext[0] = 0;
	toservermap[0] = 0;
	clientpassword[0] = 0;
	newname("unnamed");
	newteam("red");
};


void
sendpackettoserv(void *packet)
{
	if (clienthost) {
		enet_host_broadcast(clienthost, 0, (ENetPacket *)packet);
		enet_host_flush(clienthost);
	} else
		localclienttoserver((ENetPacket *)packet);
}

void
c2sinfo(dynent *d) // send update to the server
{

	if (clientnum < 0)
		return; // we haven't had a welcome message from the server yet

	if (lastmillis - lastupdate < 40)
		return; // don't update faster than 25fps
	ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, 0);
	uchar *start = packet->data;
	uchar *p = start + 2;
	bool serveriteminitdone = false;
	if (toservermap[0]) // suggest server to change map
	{ // do this exclusively as map change may invalidate rest of update

		packet->flags = ENET_PACKET_FLAG_RELIABLE;
		putint(p, SV_MAPCHANGE);
		sendstring(toservermap, p);
		toservermap[0] = 0;
		putint(p, nextmode);
	} else {
		putint(p, SV_POS);
		putint(p, clientnum);
		putint(

		    p, (int)(d->o.x * DMF)); // quantize coordinates to 1/16th
		                             // of a cube, between 1 and 3 bytes
		putint(p, (int)(d->o.y * DMF));
		putint(p, (int)(d->o.z * DMF));
		putint(p, (int)(d->yaw * DAF));
		putint(p, (int)(d->pitch * DAF));
		putint(p, (int)(d->roll * DAF));
		putint(
		    p, (int)(d->vel.x *
		             DVF)); // quantize to 1/100, almost always 1 byte
		putint(p, (int)(d->vel.y * DVF));
		putint(p, (int)(d->vel.z * DVF));
		// pack rest in 1 byte: strafe:2, move:2, onfloor:1, state:3


		putint(p, (d->strafe & 3) | ((d->move & 3) << 2) |
		              (((int)d->onfloor) << 4) |
		              ((editmode ? CS_EDITING : d->state) << 5));

		if (senditemstoserver) {
			packet->flags = ENET_PACKET_FLAG_RELIABLE;
			putint(p, SV_ITEMLIST);
			if (!m_noitems)
				putitems(p);
			putint(p, -1);
			senditemstoserver = false;
			serveriteminitdone = true;
		};
		if (ctext[0]) // player chat, not flood protected for now

		{
			packet->flags = ENET_PACKET_FLAG_RELIABLE;
			putint(p, SV_TEXT);
			sendstring(ctext, p);
			ctext[0] = 0;
		};
		if (!c2sinit) // tell other clients who I am
		{
			packet->flags = ENET_PACKET_FLAG_RELIABLE;
			c2sinit = true;
			putint(p, SV_INITC2S);
			sendstring(player1->name, p);
			sendstring(player1->team, p);
			putint(p, player1->lifesequence);
		};
		loopv(messages) // send messages collected during the previous
		                // frames
		{
			ivector &msg = messages[i];
			if (msg[1])
				packet->flags = ENET_PACKET_FLAG_RELIABLE;

			loopi(msg[0]) putint(p, msg[i + 2]);
		};
		messages.setsize(0);
		if (lastmillis - lastping > 250) {
			putint(p, SV_PING);
			putint(p, lastmillis);
			lastping = lastmillis;
		};
	};
	*(ushort *)start = ENET_HOST_TO_NET_16(p - start);
	enet_packet_resize(packet, p - start);
	incomingdemodata(start, p - start, true);
	if (clienthost) {
		enet_host_broadcast(clienthost, 0, packet);
		enet_host_flush(clienthost);
	} else
		localclienttoserver(packet);
	lastupdate = lastmillis;
	if (serveriteminitdone)
		loadgamerest(); // hack
};



void
gets2c() // get updates from the server
{
	ENetEvent event;
	if (!clienthost)
		return;







|








<
>
|












|



<
>














>
|
|
>
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
|
|
|

|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
>
>







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
server_err()
{
	conoutf(@"server network error, disconnecting...");
	disconnect();
}

int lastupdate = 0, lastping = 0;
OFString *toservermap;
bool senditemstoserver =
    false; // after a map change, since server doesn't have map data

string clientpassword;
void
password(char *p)
{
	strcpy_s(clientpassword, p);

}
COMMAND(password, ARG_1CSTR)

bool
netmapstart()
{
	senditemstoserver = true;
	return clienthost != NULL;
};

void
initclientnet()
{
	ctext[0] = 0;
	toservermap = @"";
	clientpassword[0] = 0;
	newname("unnamed");
	newteam("red");

}

void
sendpackettoserv(void *packet)
{
	if (clienthost) {
		enet_host_broadcast(clienthost, 0, (ENetPacket *)packet);
		enet_host_flush(clienthost);
	} else
		localclienttoserver((ENetPacket *)packet);
}

void
c2sinfo(dynent *d) // send update to the server
{
	@autoreleasepool {
		if (clientnum < 0)
			return; // we haven't had a welcome message from the
			        // server yet
		if (lastmillis - lastupdate < 40)
			return; // don't update faster than 25fps
		ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, 0);
		uchar *start = packet->data;
		uchar *p = start + 2;
		bool serveriteminitdone = false;
		if (toservermap.length > 0) // suggest server to change map
		{ // do this exclusively as map change may invalidate rest of
		  // update
			packet->flags = ENET_PACKET_FLAG_RELIABLE;
			putint(p, SV_MAPCHANGE);
			sendstring(toservermap.UTF8String, p);
			toservermap = @"";
			putint(p, nextmode);
		} else {
			putint(p, SV_POS);
			putint(p, clientnum);
			putint(
			    p, (int)(d->o.x *
			             DMF)); // quantize coordinates to 1/16th
			                    // of a cube, between 1 and 3 bytes
			putint(p, (int)(d->o.y * DMF));
			putint(p, (int)(d->o.z * DMF));
			putint(p, (int)(d->yaw * DAF));
			putint(p, (int)(d->pitch * DAF));
			putint(p, (int)(d->roll * DAF));
			putint(
			    p, (int)(d->vel.x * DVF)); // quantize to 1/100,
			                               // almost always 1 byte
			putint(p, (int)(d->vel.y * DVF));
			putint(p, (int)(d->vel.z * DVF));
			// pack rest in 1 byte: strafe:2, move:2, onfloor:1,
			// state:3
			putint(
			    p, (d->strafe & 3) | ((d->move & 3) << 2) |
			           (((int)d->onfloor) << 4) |
			           ((editmode ? CS_EDITING : d->state) << 5));

			if (senditemstoserver) {
				packet->flags = ENET_PACKET_FLAG_RELIABLE;
				putint(p, SV_ITEMLIST);
				if (!m_noitems)
					putitems(p);
				putint(p, -1);
				senditemstoserver = false;
				serveriteminitdone = true;
			};
			if (ctext[0]) // player chat, not flood protected for
			              // now
			{
				packet->flags = ENET_PACKET_FLAG_RELIABLE;
				putint(p, SV_TEXT);
				sendstring(ctext, p);
				ctext[0] = 0;
			};
			if (!c2sinit) // tell other clients who I am
			{
				packet->flags = ENET_PACKET_FLAG_RELIABLE;
				c2sinit = true;
				putint(p, SV_INITC2S);
				sendstring(player1->name, p);
				sendstring(player1->team, p);
				putint(p, player1->lifesequence);
			};
			loopv(messages) // send messages collected during the
			                // previous frames
			{
				ivector &msg = messages[i];
				if (msg[1])
					packet->flags =
					    ENET_PACKET_FLAG_RELIABLE;
				loopi(msg[0]) putint(p, msg[i + 2]);
			};
			messages.setsize(0);
			if (lastmillis - lastping > 250) {
				putint(p, SV_PING);
				putint(p, lastmillis);
				lastping = lastmillis;
			};
		};
		*(ushort *)start = ENET_HOST_TO_NET_16(p - start);
		enet_packet_resize(packet, p - start);
		incomingdemodata(start, p - start, true);
		if (clienthost) {
			enet_host_broadcast(clienthost, 0, packet);
			enet_host_flush(clienthost);
		} else
			localclienttoserver(packet);
		lastupdate = lastmillis;
		if (serveriteminitdone)
			loadgamerest(); // hack

	}
}

void
gets2c() // get updates from the server
{
	ENetEvent event;
	if (!clienthost)
		return;

Modified src/clientextras.mm from [3d0c884313] to [d11e243f24].

157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

196

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
		menumanual(0, scorelines.length() + 1, teamscores);
	};
};

// sendmap/getmap commands, should be replaced by more intuitive map downloading

void
sendmap(char *mapname)
{

	if (*mapname)
		save_world(mapname);
	changemap(mapname);
	mapname = getclientmap();
	int mapsize;
	uchar *mapdata = readmap(mapname, &mapsize);
	if (!mapdata)
		return;
	ENetPacket *packet = enet_packet_create(
	    NULL, MAXTRANS + mapsize, ENET_PACKET_FLAG_RELIABLE);
	uchar *start = packet->data;
	uchar *p = start + 2;
	putint(p, SV_SENDMAP);
	sendstring(mapname, p);
	putint(p, mapsize);
	if (65535 - (p - start) < mapsize) {
		conoutf(@"map %s is too large to send", mapname);
		free(mapdata);
		enet_packet_destroy(packet);
		return;
	};
	memcpy(p, mapdata, mapsize);
	p += mapsize;
	free(mapdata);
	*(ushort *)start = ENET_HOST_TO_NET_16(p - start);
	enet_packet_resize(packet, p - start);
	sendpackettoserv(packet);
	conoutf(@"sending map %s to server...", mapname);
	sprintf_sd(msg)(
	    "[map %s uploaded to server, \"getmap\" to receive it]", mapname);

	toserver(msg);

}

void
getmap()
{
	ENetPacket *packet =
	    enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
	uchar *start = packet->data;
	uchar *p = start + 2;
	putint(p, SV_RECVMAP);
	*(ushort *)start = ENET_HOST_TO_NET_16(p - start);
	enet_packet_resize(packet, p - start);
	sendpackettoserv(packet);
	conoutf(@"requesting map from server...");
}

COMMAND(sendmap, ARG_1STR);
COMMAND(getmap, ARG_NONE);







|

>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
>
















|
|
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
		menumanual(0, scorelines.length() + 1, teamscores);
	};
};

// sendmap/getmap commands, should be replaced by more intuitive map downloading

void
sendmap(const char *mapname)
{
	@autoreleasepool {
		if (*mapname)
			save_world(mapname);
		changemap(@(mapname));
		mapname = getclientmap().UTF8String;
		int mapsize;
		uchar *mapdata = readmap(mapname, &mapsize);
		if (!mapdata)
			return;
		ENetPacket *packet = enet_packet_create(
		    NULL, MAXTRANS + mapsize, ENET_PACKET_FLAG_RELIABLE);
		uchar *start = packet->data;
		uchar *p = start + 2;
		putint(p, SV_SENDMAP);
		sendstring(mapname, p);
		putint(p, mapsize);
		if (65535 - (p - start) < mapsize) {
			conoutf(@"map %s is too large to send", mapname);
			free(mapdata);
			enet_packet_destroy(packet);
			return;
		};
		memcpy(p, mapdata, mapsize);
		p += mapsize;
		free(mapdata);
		*(ushort *)start = ENET_HOST_TO_NET_16(p - start);
		enet_packet_resize(packet, p - start);
		sendpackettoserv(packet);
		conoutf(@"sending map %s to server...", mapname);
		sprintf_sd(msg)(
		    "[map %s uploaded to server, \"getmap\" to receive it]",
		    mapname);
		toserver(msg);
	}
}

void
getmap()
{
	ENetPacket *packet =
	    enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
	uchar *start = packet->data;
	uchar *p = start + 2;
	putint(p, SV_RECVMAP);
	*(ushort *)start = ENET_HOST_TO_NET_16(p - start);
	enet_packet_resize(packet, p - start);
	sendpackettoserv(packet);
	conoutf(@"requesting map from server...");
}

COMMAND(sendmap, ARG_1CSTR)
COMMAND(getmap, ARG_NONE)

Modified src/clientgame.mm from [8334b2a352] to [e35d803d58].

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
// clientgame.cpp: core game related stuff

#include "cube.h"

int nextmode = 0; // nextmode becomes gamemode after next map load
VAR(gamemode, 1, 0, 0);

void
mode(int n)
{
	addmsg(1, 2, SV_GAMEMODE, nextmode = n);
};
COMMAND(mode, ARG_1INT);

bool intermission = false;

dynent *player1 = newdynent(); // our client
dvector players;               // other clients

VARP(sensitivity, 0, 10, 10000);
VARP(sensitivityscale, 1, 1, 10000);
VARP(invmouse, 0, 0, 1);

int lastmillis = 0;
int curtime = 10;
string clientmap;

extern int framesinmap;

char *
getclientmap()
{
	return clientmap;
};


void
resetmovement(dynent *d)
{
	d->k_left = false;
	d->k_right = false;
	d->k_up = false;












|












|



|



<
>







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
// clientgame.cpp: core game related stuff

#include "cube.h"

int nextmode = 0; // nextmode becomes gamemode after next map load
VAR(gamemode, 1, 0, 0);

void
mode(int n)
{
	addmsg(1, 2, SV_GAMEMODE, nextmode = n);
};
COMMAND(mode, ARG_1INT)

bool intermission = false;

dynent *player1 = newdynent(); // our client
dvector players;               // other clients

VARP(sensitivity, 0, 10, 10000);
VARP(sensitivityscale, 1, 1, 10000);
VARP(invmouse, 0, 0, 1);

int lastmillis = 0;
int curtime = 10;
OFString *clientmap;

extern int framesinmap;

OFString *
getclientmap()
{
	return clientmap;

}

void
resetmovement(dynent *d)
{
	d->k_left = false;
	d->k_right = false;
	d->k_up = false;
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
respawn()
{
	if (player1->state == CS_DEAD) {
		player1->attacking = false;
		if (m_arena) {
			conoutf(@"waiting for new round to start...");
			return;
		};

		if (m_sp) {
			nextmode = gamemode;
			changemap(clientmap);
			return;
		}; // if we die in SP we try the same map again
		respawnself();
	};
};



int sleepwait = 0;
string sleepcmd;
void
sleepf(char *msec, char *cmd)
{
	sleepwait = atoi(msec) + lastmillis;
	strcpy_s(sleepcmd, cmd);
};
COMMANDN(sleep, sleepf, ARG_2STR);

void
updateworld(int millis) // main game update loop
{
	if (lastmillis) {
		curtime = millis - lastmillis;
		if (sleepwait && lastmillis > sleepwait) {







<
>




|

<
<
>
>









|







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
respawn()
{
	if (player1->state == CS_DEAD) {
		player1->attacking = false;
		if (m_arena) {
			conoutf(@"waiting for new round to start...");
			return;

		}
		if (m_sp) {
			nextmode = gamemode;
			changemap(clientmap);
			return;
		} // if we die in SP we try the same map again
		respawnself();


	}
}

int sleepwait = 0;
string sleepcmd;
void
sleepf(char *msec, char *cmd)
{
	sleepwait = atoi(msec) + lastmillis;
	strcpy_s(sleepcmd, cmd);
};
COMMANDN(sleep, sleepf, ARG_2STR)

void
updateworld(int millis) // main game update loop
{
	if (lastmillis) {
		curtime = millis - lastmillis;
		if (sleepwait && lastmillis > sleepwait) {
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
void
jumpn(bool on)
{
	if (!intermission && (player1->jumpnext = on))
		respawn();
};

COMMAND(backward, ARG_DOWN);
COMMAND(forward, ARG_DOWN);
COMMAND(left, ARG_DOWN);
COMMAND(right, ARG_DOWN);
COMMANDN(jump, jumpn, ARG_DOWN);
COMMAND(attack, ARG_DOWN);
COMMAND(showscores, ARG_DOWN);

void
fixplayer1range()
{
	const float MAXPITCH = 90.0f;
	if (player1->pitch > MAXPITCH)
		player1->pitch = MAXPITCH;







|
|
|
|
|
|
|







357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
void
jumpn(bool on)
{
	if (!intermission && (player1->jumpnext = on))
		respawn();
};

COMMAND(backward, ARG_DOWN)
COMMAND(forward, ARG_DOWN)
COMMAND(left, ARG_DOWN)
COMMAND(right, ARG_DOWN)
COMMANDN(jump, jumpn, ARG_DOWN)
COMMAND(attack, ARG_DOWN)
COMMAND(showscores, ARG_DOWN)

void
fixplayer1range()
{
	const float MAXPITCH = 90.0f;
	if (player1->pitch > MAXPITCH)
		player1->pitch = MAXPITCH;
480
481
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505

506

507
508
509
510
511
512
513
514
515
516
517

518
		players.add(NULL);
	return players[cn] ? players[cn] : (players[cn] = newdynent());
}

void
initclient()
{
	clientmap[0] = 0;
	initclientnet();
};


void
startmap(char *name) // called just after a map load
{
	if (netmapstart() && m_sp) {
		gamemode = 0;
		conoutf(@"coop sp not supported yet");
	}
	sleepwait = 0;
	monsterclear();
	projreset();
	spawncycle = -1;
	spawnplayer(player1);
	player1->frags = 0;
	loopv(players) if (players[i]) players[i]->frags = 0;
	resetspawns();

	strcpy_s(clientmap, name);

	if (editmode)
		toggleedit();
	setvar("gamespeed", 100);
	setvar("fog", 180);
	setvar("fogcolour", 0x8099B3);
	showscores(false);
	intermission = false;
	framesinmap = 0;
	conoutf(@"game mode is %s", modestr(gamemode));
};


COMMANDN(map, changemap, ARG_1STR);







|

<
>
















>
|
>









<
|
>
|
480
481
482
483
484
485
486
487
488

489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

518
519
520
		players.add(NULL);
	return players[cn] ? players[cn] : (players[cn] = newdynent());
}

void
initclient()
{
	clientmap = @"";
	initclientnet();

}

void
startmap(char *name) // called just after a map load
{
	if (netmapstart() && m_sp) {
		gamemode = 0;
		conoutf(@"coop sp not supported yet");
	}
	sleepwait = 0;
	monsterclear();
	projreset();
	spawncycle = -1;
	spawnplayer(player1);
	player1->frags = 0;
	loopv(players) if (players[i]) players[i]->frags = 0;
	resetspawns();
	@autoreleasepool {
		clientmap = @(name);
	}
	if (editmode)
		toggleedit();
	setvar("gamespeed", 100);
	setvar("fog", 180);
	setvar("fogcolour", 0x8099B3);
	showscores(false);
	intermission = false;
	framesinmap = 0;
	conoutf(@"game mode is %s", modestr(gamemode));

}

COMMANDN(map, changemap, ARG_1STR)

Modified src/clients2c.mm from [e92e9ee6ab] to [0783f692c0].

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
// client processing of the incoming network stream

#include "cube.h"

extern int clientnum;
extern bool c2sinit, senditemstoserver;
extern string toservermap;
extern string clientpassword;

void
neterr(char *s)
{
	conoutf(@"illegal network message (%s)", s);
	disconnect();
};


void
changemapserv(char *name, int mode) // forced map change from the server
{
	gamemode = mode;
	load_world(name);
};


void
changemap(char *name) // request map change, server may ignore
{
	strcpy_s(toservermap, name);
};


// update the position of other clients in the game in our world
// don't care if he's in the scenery or other players,
// just don't overlap with our client

void
updatepos(dynent *d)






|







<
>






<
|
>

|

|
<
>







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
// client processing of the incoming network stream

#include "cube.h"

extern int clientnum;
extern bool c2sinit, senditemstoserver;
extern OFString *toservermap;
extern string clientpassword;

void
neterr(char *s)
{
	conoutf(@"illegal network message (%s)", s);
	disconnect();

}

void
changemapserv(char *name, int mode) // forced map change from the server
{
	gamemode = mode;
	load_world(name);

}

void
changemap(OFString *name) // request map change, server may ignore
{
	toservermap = name;

}

// update the position of other clients in the game in our world
// don't care if he's in the scenery or other players,
// just don't overlap with our client

void
updatepos(dynent *d)
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
			if (prot != PROTOCOL_VERSION) {
				conoutf(@"you are using a different game "
				        @"protocol (you: %d, server: %d)",
				    PROTOCOL_VERSION, prot);
				disconnect();
				return;
			};
			toservermap[0] = 0;
			clientnum = cn; // we are now fully connected
			if (!getint(p))
				strcpy_s(toservermap,
				    getclientmap()); // we are the first client

				                     // on this server, set map
			sgetstr();
			if (text[0] && strcmp(text, clientpassword)) {
				conoutf(@"you need to set the correct password "
				        @"to join this server!");
				disconnect();
				return;
			};







|


<
|
>
|







78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
97
			if (prot != PROTOCOL_VERSION) {
				conoutf(@"you are using a different game "
				        @"protocol (you: %d, server: %d)",
				    PROTOCOL_VERSION, prot);
				disconnect();
				return;
			};
			toservermap = @"";
			clientnum = cn; // we are now fully connected
			if (!getint(p))

				// we are the first client on this server, set
				// map
				toservermap = getclientmap();
			sgetstr();
			if (text[0] && strcmp(text, clientpassword)) {
				conoutf(@"you need to set the correct password "
				        @"to join this server!");
				disconnect();
				return;
			};
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
					setspawn(n, true);
			break;
		}

		case SV_MAPRELOAD: // server requests next map
		{
			getint(p);

			sprintf_sd(nextmapalias)("nextmap_%s", getclientmap());
			char *map =
			    getalias(nextmapalias); // look up map in the cycle
			changemap(map ? map : getclientmap());
			break;
		}

		case SV_INITC2S: // another client either connected or changed
		                 // name/team
		{
			sgetstr();







>
|
|

|







156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
					setspawn(n, true);
			break;
		}

		case SV_MAPRELOAD: // server requests next map
		{
			getint(p);
			OFString *nextmapalias = [OFString
			    stringWithFormat:@"nextmap_%@", getclientmap()];
			OFString *map =
			    getalias(nextmapalias); // look up map in the cycle
			changemap(map != nil ? map : getclientmap());
			break;
		}

		case SV_INITC2S: // another client either connected or changed
		                 // name/team
		{
			sgetstr();

Modified src/command.mm from [56e5f5018d] to [a0d92d1a92].

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
53
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
// command.cpp: implements the parsing and execution of a tiny script language
// which is largely backwards compatible with the quake console language.

#include "cube.h"

enum { ID_VAR, ID_COMMAND, ID_ALIAS };

@interface Ident : OFObject
@property (nonatomic) int type; // one of ID_* above
@property (nonatomic) char *name;
@property (nonatomic) int min, max;  // ID_VAR
@property (nonatomic) int *storage;  // ID_VAR
@property (nonatomic) void (*fun)(); // ID_VAR, ID_COMMAND
@property (nonatomic) int narg;      // ID_VAR, ID_COMMAND
@property (nonatomic) char *action;  // ID_ALIAS
@property (nonatomic) bool persist;
@end

@implementation Ident
@end

void
itoa(char *s, int i)
{
	sprintf_s(s)("%d", i);
}

char *
exchangestr(char *o, char *n)
{
	gp()->deallocstr(o);
	return newstring(n);
}

// contains ALL vars/commands/aliases
OFMutableDictionary<OFString *, Ident *> *idents;

void
alias(char *name, char *action)
{
	@autoreleasepool {
		Ident *b = idents[@(name)];

		if (!b) {
			Ident *b = [[Ident alloc] init];
			b.type = ID_ALIAS;
			b.name = newstring(name);
			b.action = newstring(action);
			b.persist = true;

			idents[@(name)] = b;
		} else {
			if (b.type == ID_ALIAS)
				b.action = exchangestr(b.action, action);
			else
				conoutf(
				    @"cannot redefine builtin %s with an alias",
				    name);
		}
	}
}

COMMAND(alias, ARG_2STR)

int
variable(char *name, int min, int cur, int max, int *storage, void (*fun)(),
    bool persist)
{
	if (idents == nil)
		idents = [[OFMutableDictionary alloc] init];

	@autoreleasepool {
		Ident *v = [[Ident alloc] init];
		v.type = ID_VAR;
		v.name = name;
		v.min = min;
		v.max = max;
		v.storage = storage;
		v.fun = fun;
		v.persist = persist;

		idents[@(name)] = v;
	}

	return cur;
}

void
setvar(char *name, int i)









|
|
|
|
|
|













|

















|
|


|


|




















|






|







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
53
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
// command.cpp: implements the parsing and execution of a tiny script language
// which is largely backwards compatible with the quake console language.

#include "cube.h"

enum { ID_VAR, ID_COMMAND, ID_ALIAS };

@interface Ident : OFObject
@property (nonatomic) int type; // one of ID_* above
@property (copy, nonatomic) OFString *name;
@property (nonatomic) int min, max;           // ID_VAR
@property (nonatomic) int *storage;           // ID_VAR
@property (nonatomic) void (*fun)();          // ID_VAR, ID_COMMAND
@property (nonatomic) int narg;               // ID_VAR, ID_COMMAND
@property (copy, nonatomic) OFString *action; // ID_ALIAS
@property (nonatomic) bool persist;
@end

@implementation Ident
@end

void
itoa(char *s, int i)
{
	sprintf_s(s)("%d", i);
}

char *
exchangestr(char *o, const char *n)
{
	gp()->deallocstr(o);
	return newstring(n);
}

// contains ALL vars/commands/aliases
OFMutableDictionary<OFString *, Ident *> *idents;

void
alias(char *name, char *action)
{
	@autoreleasepool {
		Ident *b = idents[@(name)];

		if (!b) {
			Ident *b = [[Ident alloc] init];
			b.type = ID_ALIAS;
			b.name = @(name);
			b.action = @(action);
			b.persist = true;

			idents[b.name] = b;
		} else {
			if (b.type == ID_ALIAS)
				b.action = @(action);
			else
				conoutf(
				    @"cannot redefine builtin %s with an alias",
				    name);
		}
	}
}

COMMAND(alias, ARG_2STR)

int
variable(char *name, int min, int cur, int max, int *storage, void (*fun)(),
    bool persist)
{
	if (idents == nil)
		idents = [[OFMutableDictionary alloc] init];

	@autoreleasepool {
		Ident *v = [[Ident alloc] init];
		v.type = ID_VAR;
		v.name = @(name);
		v.min = min;
		v.max = max;
		v.storage = storage;
		v.fun = fun;
		v.persist = persist;

		idents[v.name] = v;
	}

	return cur;
}

void
setvar(char *name, int i)
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
identexists(char *name)
{
	@autoreleasepool {
		return (idents[@(name)] != nil);
	}
}

char *
getalias(char *name)
{
	@autoreleasepool {
		Ident *i = idents[@(name)];
		return i != nil && i.type == ID_ALIAS ? i.action : NULL;
	}
}

bool
addcommand(char *name, void (*fun)(), int narg)
{
	if (idents == nil)
		idents = [[OFMutableDictionary alloc] init];

	@autoreleasepool {
		Ident *c = [[Ident alloc] init];
		c.type = ID_COMMAND;
		c.name = name;
		c.fun = fun;
		c.narg = narg;

		idents[@(name)] = c;
	}

	return false;
}

char *
parseexp(char *&p, int right) // parse any nested set of () or []







|
|

<
|
|
<



|











|







105
106
107
108
109
110
111
112
113
114

115
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
identexists(char *name)
{
	@autoreleasepool {
		return (idents[@(name)] != nil);
	}
}

OFString *
getalias(OFString *name)
{

	Ident *i = idents[name];
	return i != nil && i.type == ID_ALIAS ? i.action : nil;

}

bool
addcommand(OFString *name, void (*fun)(), int narg)
{
	if (idents == nil)
		idents = [[OFMutableDictionary alloc] init];

	@autoreleasepool {
		Ident *c = [[Ident alloc] init];
		c.type = ID_COMMAND;
		c.name = name;
		c.fun = fun;
		c.narg = narg;

		idents[name] = c;
	}

	return false;
}

char *
parseexp(char *&p, int right) // parse any nested set of () or []
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
		if (ID != nil) {
			switch (ID.type) {
			case ID_VAR:
				string t;
				itoa(t, *(ID.storage));
				return exchangestr(n, t);
			case ID_ALIAS:
				return exchangestr(n, ID.action);
			}
		}
	}

	conoutf(@"unknown alias lookup: %s", n + 1);
	return n;
}







|







200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
		if (ID != nil) {
			switch (ID.type) {
			case ID_VAR:
				string t;
				itoa(t, *(ID.storage));
				return exchangestr(n, t);
			case ID_ALIAS:
				return exchangestr(n, ID.action.UTF8String);
			}
		}
	}

	conoutf(@"unknown alias lookup: %s", n + 1);
	return n;
}
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
							    ATOI(w[4]));
						break;
					case ARG_NONE:
						if (isdown)
							((void(__cdecl *)())
							        ID.fun)();
						break;
					case ARG_1STR:
						if (isdown)
							((void(__cdecl *)(
							    char *))ID.fun)(
							    w[1]);
						break;
					case ARG_2STR:
						if (isdown)







|







292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
							    ATOI(w[4]));
						break;
					case ARG_NONE:
						if (isdown)
							((void(__cdecl *)())
							        ID.fun)();
						break;
					case ARG_1CSTR:
						if (isdown)
							((void(__cdecl *)(
							    char *))ID.fun)(
							    w[1]);
						break;
					case ARG_2STR:
						if (isdown)
381
382
383
384
385
386
387











388
389
390
391
392
393
394
								strcat_s(
								    r, " ");
							}
							((void(__cdecl *)(
							    char *))ID.fun)(r);
							break;
						}











					}
					break;

				// game defined variables
				case ID_VAR:
					if (isdown) {
						if (!w[1][0])







>
>
>
>
>
>
>
>
>
>
>







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
								strcat_s(
								    r, " ");
							}
							((void(__cdecl *)(
							    char *))ID.fun)(r);
							break;
						}
					case ARG_1STR:
						if (isdown) {
							@autoreleasepool {
								((void(
								    __cdecl *)(
								    OFString *))
								        ID.fun)(
								    @(w[1]));
							}
						}
						break;
					}
					break;

				// game defined variables
				case ID_VAR:
					if (isdown) {
						if (!w[1][0])
474
475
476
477
478
479
480
481

482
483
484
485
486
487
488
						// (global) arg values so
						// functions can access them
						sprintf_sd(t)("arg%d", i);
						alias(t, w[i]);
					}
					// create new string here because alias
					// could rebind itself
					char *action = newstring(ID.action);

					val = execute(action, isdown);
					gp()->deallocstr(action);
					break;
				}
			}
		}
		loopj(numargs) gp()->deallocstr(w[j]);







|
>







483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
						// (global) arg values so
						// functions can access them
						sprintf_sd(t)("arg%d", i);
						alias(t, w[i]);
					}
					// create new string here because alias
					// could rebind itself
					char *action =
					    newstring(ID.action.UTF8String);
					val = execute(action, isdown);
					gp()->deallocstr(action);
					break;
				}
			}
		}
		loopj(numargs) gp()->deallocstr(w[j]);
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
	if (!completesize) {
		completesize = (int)strlen(s) - 1;
		completeidx = 0;
	}
	__block int idx = 0;
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
		if (strncmp(ident.name, s + 1, completesize) == 0 &&
		    idx++ == completeidx) {
			strcpy_s(s, "/");
			strcat_s(s, ident.name);
		}
	}];
	completeidx++;
	if (completeidx >= idx)
		completeidx = 0;
}








|


|







525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
	if (!completesize) {
		completesize = (int)strlen(s) - 1;
		completeidx = 0;
	}
	__block int idx = 0;
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
		if (strncmp(ident.name.UTF8String, s + 1, completesize) == 0 &&
		    idx++ == completeidx) {
			strcpy_s(s, "/");
			strcat_s(s, ident.name.UTF8String);
		}
	}];
	completeidx++;
	if (completeidx >= idx)
		completeidx = 0;
}

561
562
563
564
565
566
567
568

569
570
571
572
573
574
575
576
577
578

579
580
581
582
583
584
585
586
587
588
589
590
591
	           "settings\n// modify settings in game, or put settings in "
	           "autoexec.cfg to override anything\n\n");
	writeclientinfo(f);
	fprintf(f, "\n");
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
		if (ident.type == ID_VAR && ident.persist) {
			fprintf(f, "%s %d\n", ident.name, *ident.storage);

		}
	}];
	fprintf(f, "\n");
	writebinds(f);
	fprintf(f, "\n");
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
		if (ident.type == ID_ALIAS && !strstr(ident.name, "nextmap_")) {
			fprintf(
			    f, "alias \"%s\" [%s]\n", ident.name, ident.action);

		}
	}];
	fclose(f);
}

COMMAND(writecfg, ARG_NONE);

// below the commands that implement a small imperative language. thanks to the
// semantics of
// () and [] expressions, any control construct can be defined trivially.

void
intset(char *name, int v)







|
>







|
|
|
>





|







571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
	           "settings\n// modify settings in game, or put settings in "
	           "autoexec.cfg to override anything\n\n");
	writeclientinfo(f);
	fprintf(f, "\n");
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
		if (ident.type == ID_VAR && ident.persist) {
			fprintf(f, "%s %d\n", ident.name.UTF8String,
			    *ident.storage);
		}
	}];
	fprintf(f, "\n");
	writebinds(f);
	fprintf(f, "\n");
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
		if (ident.type == ID_ALIAS &&
		    !strstr(ident.name.UTF8String, "nextmap_")) {
			fprintf(f, "alias \"%s\" [%s]\n", ident.name.UTF8String,
			    ident.action.UTF8String);
		}
	}];
	fclose(f);
}

COMMAND(writecfg, ARG_NONE)

// below the commands that implement a small imperative language. thanks to the
// semantics of
// () and [] expressions, any control construct can be defined trivially.

void
intset(char *name, int v)
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680

681
682
683
684
685
686

687
688
689
690
691
692

693
694
695
696
697
698

699
700
701
702
703
704

705
706
707
708
709
710

711
712
713
714
715
716

717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
{
	int n = atoi(pos);
	loopi(n) s += strspn(s += strcspn(s, " \0"), " ");
	s[strcspn(s, " \0")] = 0;
	concat(s);
}

COMMANDN(loop, loopa, ARG_2STR);
COMMANDN(while, whilea, ARG_2STR);
COMMANDN(if, ifthen, ARG_3STR);
COMMAND(onrelease, ARG_DWN1);
COMMAND(exec, ARG_1STR);
COMMAND(concat, ARG_VARI);
COMMAND(concatword, ARG_VARI);
COMMAND(at, ARG_2STR);
COMMAND(listlen, ARG_1EST);

int
add(int a, int b)
{
	return a + b;
}
COMMANDN(+, add, ARG_2EXP);

int
mul(int a, int b)
{
	return a * b;
}
COMMANDN(*, mul, ARG_2EXP);

int
sub(int a, int b)
{
	return a - b;
}
COMMANDN(-, sub, ARG_2EXP);

int
divi(int a, int b)
{
	return b ? a / b : 0;
}
COMMANDN(div, divi, ARG_2EXP);

int
mod(int a, int b)
{
	return b ? a % b : 0;
}
COMMAND(mod, ARG_2EXP);

int
equal(int a, int b)
{
	return (int)(a == b);
}
COMMANDN(=, equal, ARG_2EXP);

int
lt(int a, int b)
{
	return (int)(a < b);
}
COMMANDN(<, lt, ARG_2EXP);

int
gt(int a, int b)
{
	return (int)(a > b);
}
COMMANDN(>, gt, ARG_2EXP);

int
strcmpa(char *a, char *b)
{
	return strcmp(a, b) == 0;
}
COMMANDN(strcmp, strcmpa, ARG_2EST);

int
rndn(int a)
{
	return a > 0 ? rnd(a) : 0;
}
COMMANDN(rnd, rndn, ARG_1EXP);

int
explastmillis()
{
	return lastmillis;
}
COMMANDN(millis, explastmillis, ARG_1EXP);







|
|
|
|
|
|
|
|
|






|
>





|
>





|
>





|
>





|
>





|
>





|
>





|






|






|






|
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
{
	int n = atoi(pos);
	loopi(n) s += strspn(s += strcspn(s, " \0"), " ");
	s[strcspn(s, " \0")] = 0;
	concat(s);
}

COMMANDN(loop, loopa, ARG_2STR)
COMMANDN(while, whilea, ARG_2STR)
COMMANDN(if, ifthen, ARG_3STR)
COMMAND(onrelease, ARG_DWN1)
COMMAND(exec, ARG_1CSTR)
COMMAND(concat, ARG_VARI)
COMMAND(concatword, ARG_VARI)
COMMAND(at, ARG_2STR)
COMMAND(listlen, ARG_1EST)

int
add(int a, int b)
{
	return a + b;
}
COMMANDN(+, add, ARG_2EXP)

int
mul(int a, int b)
{
	return a * b;
}
COMMANDN(*, mul, ARG_2EXP)

int
sub(int a, int b)
{
	return a - b;
}
COMMANDN(-, sub, ARG_2EXP)

int
divi(int a, int b)
{
	return b ? a / b : 0;
}
COMMANDN(div, divi, ARG_2EXP)

int
mod(int a, int b)
{
	return b ? a % b : 0;
}
COMMAND(mod, ARG_2EXP)

int
equal(int a, int b)
{
	return (int)(a == b);
}
COMMANDN(=, equal, ARG_2EXP)

int
lt(int a, int b)
{
	return (int)(a < b);
}
COMMANDN(<, lt, ARG_2EXP)

int
gt(int a, int b)
{
	return (int)(a > b);
}
COMMANDN(>, gt, ARG_2EXP)

int
strcmpa(char *a, char *b)
{
	return strcmp(a, b) == 0;
}
COMMANDN(strcmp, strcmpa, ARG_2EST)

int
rndn(int a)
{
	return a > 0 ? rnd(a) : 0;
}
COMMANDN(rnd, rndn, ARG_1EXP)

int
explastmillis()
{
	return lastmillis;
}
COMMANDN(millis, explastmillis, ARG_1EXP)

Modified src/console.mm from [74e953a174] to [e55e1dd6f3].

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

void
setconskip(int n)
{
	conskip += n;
	if (conskip < 0)
		conskip = 0;
};

COMMANDN(conskip, setconskip, ARG_1INT);

void
conline(const char *sf, bool highlight) // add a line to the console buffer
{
	cline cl;
	cl.cref = conlines.length() > 100
	              ? conlines.pop().cref







<
|
|







18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33

void
setconskip(int n)
{
	conskip += n;
	if (conskip < 0)
		conskip = 0;

}
COMMANDN(conskip, setconskip, ARG_1INT)

void
conline(const char *sf, bool highlight) // add a line to the console buffer
{
	cline cl;
	cl.cref = conlines.length() > 100
	              ? conlines.pop().cref
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147

void
keymap(char *code, char *key, char *action)
{
	keyms[numkm].code = atoi(code);
	keyms[numkm].name = newstring(key);
	keyms[numkm++].action = newstringbuf(action);
};

COMMAND(keymap, ARG_3STR);

void
bindkey(char *key, char *action)
{
	for (char *x = key; *x; x++)
		*x = toupper(*x);
	loopi(numkm) if (strcmp(keyms[i].name, key) == 0)
	{
		strcpy_s(keyms[i].action, action);
		return;
	};
	conoutf(@"unknown key \"%s\"", key);
};

COMMANDN(bind, bindkey, ARG_2STR);

void
saycommand(char *init) // turns input to the command line on or off
{
	SDL_EnableUNICODE(saycommandon = (init != NULL));
	if (!editmode)
		keyrepeat(saycommandon);
	if (!init)
		init = "";
	strcpy_s(commandbuf, init);
};

void
mapmsg(char *s)
{
	strn0cpy(hdr.maptitle, s, 128);
};


COMMAND(saycommand, ARG_VARI);
COMMAND(mapmsg, ARG_1STR);

#ifndef _WIN32
# include <SDL_syswm.h>
# include <X11/Xlib.h>
#endif

void







<
|
|












<
|
|
















<
|
>
|
|







95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143
144

void
keymap(char *code, char *key, char *action)
{
	keyms[numkm].code = atoi(code);
	keyms[numkm].name = newstring(key);
	keyms[numkm++].action = newstringbuf(action);

}
COMMAND(keymap, ARG_3STR)

void
bindkey(char *key, char *action)
{
	for (char *x = key; *x; x++)
		*x = toupper(*x);
	loopi(numkm) if (strcmp(keyms[i].name, key) == 0)
	{
		strcpy_s(keyms[i].action, action);
		return;
	};
	conoutf(@"unknown key \"%s\"", key);

}
COMMANDN(bind, bindkey, ARG_2STR)

void
saycommand(char *init) // turns input to the command line on or off
{
	SDL_EnableUNICODE(saycommandon = (init != NULL));
	if (!editmode)
		keyrepeat(saycommandon);
	if (!init)
		init = "";
	strcpy_s(commandbuf, init);
};

void
mapmsg(char *s)
{
	strn0cpy(hdr.maptitle, s, 128);

}

COMMAND(saycommand, ARG_VARI)
COMMAND(mapmsg, ARG_1CSTR)

#ifndef _WIN32
# include <SDL_syswm.h>
# include <X11/Xlib.h>
#endif

void
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
{
	static bool rec = false;
	if (!rec && n >= 0 && n < vhistory.length()) {
		rec = true;
		execute(vhistory[vhistory.length() - n - 1]);
		rec = false;
	};
};

COMMAND(history, ARG_1INT);

void
keypress(int code, bool isdown, int cooked)
{
	if (saycommandon) // keystrokes go to commandline
	{
		if (isdown) {







<
|
|







191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
{
	static bool rec = false;
	if (!rec && n >= 0 && n < vhistory.length()) {
		rec = true;
		execute(vhistory[vhistory.length() - n - 1]);
		rec = false;
	};

}
COMMAND(history, ARG_1INT)

void
keypress(int code, bool isdown, int cooked)
{
	if (saycommandon) // keystrokes go to commandline
	{
		if (isdown) {

Modified src/cube.h from [d8a1a5267e] to [6a3965a96d].

375
376
377
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
404
405
406
407
408
enum // function signatures for script functions, see command.cpp
{
	ARG_1INT,
	ARG_2INT,
	ARG_3INT,
	ARG_4INT,
	ARG_NONE,
	ARG_1STR,
	ARG_2STR,
	ARG_3STR,
	ARG_5STR,
	ARG_DOWN,
	ARG_DWN1,
	ARG_1EXP,
	ARG_2EXP,
	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 COMMAND(name, nargs) COMMANDN(name, name, nargs)
#define VARP(name, min, cur, max)                                              \
	int name;                                                              \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \







|









|
>








|







375
376
377
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
404
405
406
407
408
409
enum // function signatures for script functions, see command.cpp
{
	ARG_1INT,
	ARG_2INT,
	ARG_3INT,
	ARG_4INT,
	ARG_NONE,
	ARG_1CSTR,
	ARG_2STR,
	ARG_3STR,
	ARG_5STR,
	ARG_DOWN,
	ARG_DWN1,
	ARG_1EXP,
	ARG_2EXP,
	ARG_1EST,
	ARG_2EST,
	ARG_VARI,
	ARG_1STR
};

// 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 COMMAND(name, nargs) COMMANDN(name, name, nargs)
#define VARP(name, min, cur, max)                                              \
	int name;                                                              \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \

Modified src/editing.mm from [35e47e0fb8] to [90f4cefa84].

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
			monsterclear(); // all monsters back at their spawns for
			                // editing
		projreset();
	};
	keyrepeat(editmode);
	selset = false;
	editing = editmode;
};

COMMANDN(edittoggle, toggleedit, ARG_NONE);

void
correctsel() // ensures above invariant
{
	selset = !OUTBORD(sel.x, sel.y);
	int bsize = ssize - MINBORD;
	if (sel.xs + sel.x > bsize)







<
|
|







61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
			monsterclear(); // all monsters back at their spawns for
			                // editing
		projreset();
	};
	keyrepeat(editmode);
	selset = false;
	editing = editmode;

}
COMMANDN(edittoggle, toggleedit, ARG_NONE)

void
correctsel() // ensures above invariant
{
	selset = !OUTBORD(sel.x, sel.y);
	int bsize = ssize - MINBORD;
	if (sel.xs + sel.x > bsize)
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
void
editheight(int flr, int amount)
{
	EDITSEL;
	bool isfloor = flr == 0;
	editheightxy(isfloor, amount, sel);
	addmsg(1, 7, SV_EDITH, sel.x, sel.y, sel.xs, sel.ys, isfloor, amount);
};

COMMAND(editheight, ARG_2INT);

void
edittexxy(int type, int t, block &sel)
{
	loopselxy(switch (type) {
	        case 0:
		        s->ftex = t;







<
|
|







350
351
352
353
354
355
356

357
358
359
360
361
362
363
364
365
void
editheight(int flr, int amount)
{
	EDITSEL;
	bool isfloor = flr == 0;
	editheightxy(isfloor, amount, sel);
	addmsg(1, 7, SV_EDITH, sel.x, sel.y, sel.xs, sel.ys, isfloor, amount);

}
COMMAND(editheight, ARG_2INT)

void
edittexxy(int type, int t, block &sel)
{
	loopselxy(switch (type) {
	        case 0:
		        s->ftex = t;
447
448
449
450
451
452
453


454
455
456
457
458


459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
	addmsg(1, 6, SV_EDITS, sel.x, sel.y, sel.xs, sel.ys, type);
};

void
heightfield(int t)
{
	edittype(t == 0 ? FHF : CHF);


};
void
solid(int t)
{
	edittype(t == 0 ? SPACE : SOLID);


};
void
corner()
{
	edittype(CORNER);
};

COMMAND(heightfield, ARG_1INT);
COMMAND(solid, ARG_1INT);
COMMAND(corner, ARG_NONE);

void
editequalisexy(bool isfloor, block &sel)
{
	int low = 127, hi = -128;
	loopselxy({
		if (s->floor < low)







>
>
|




>
>
|




<
|
<
<
|







445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465

466


467
468
469
470
471
472
473
474
	addmsg(1, 6, SV_EDITS, sel.x, sel.y, sel.xs, sel.ys, type);
};

void
heightfield(int t)
{
	edittype(t == 0 ? FHF : CHF);
}
COMMAND(heightfield, ARG_1INT)

void
solid(int t)
{
	edittype(t == 0 ? SPACE : SOLID);
}
COMMAND(solid, ARG_1INT)

void
corner()
{
	edittype(CORNER);

}


COMMAND(corner, ARG_NONE)

void
editequalisexy(bool isfloor, block &sel)
{
	int low = 127, hi = -128;
	loopselxy({
		if (s->floor < low)
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
void
equalize(int flr)
{
	bool isfloor = flr == 0;
	EDITSEL;
	editequalisexy(isfloor, sel);
	addmsg(1, 6, SV_EDITE, sel.x, sel.y, sel.xs, sel.ys, isfloor);
};

COMMAND(equalize, ARG_1INT);

void
setvdeltaxy(int delta, block &sel)
{
	loopselxy(s->vdelta = max(s->vdelta + delta, 0));
	remipmore(sel);
};







<
|
|







489
490
491
492
493
494
495

496
497
498
499
500
501
502
503
504
void
equalize(int flr)
{
	bool isfloor = flr == 0;
	EDITSEL;
	editequalisexy(isfloor, sel);
	addmsg(1, 6, SV_EDITE, sel.x, sel.y, sel.xs, sel.ys, isfloor);

}
COMMAND(equalize, ARG_1INT)

void
setvdeltaxy(int delta, block &sel)
{
	loopselxy(s->vdelta = max(s->vdelta + delta, 0));
	remipmore(sel);
};
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
newent(char *what, char *a1, char *a2, char *a3, char *a4)
{
	EDITSEL;
	newentity(sel.x, sel.y, (int)player1->o.z, what, ATOI(a1), ATOI(a2),
	    ATOI(a3), ATOI(a4));
};

COMMANDN(select, selectpos, ARG_4INT);
COMMAND(edittag, ARG_1INT);
COMMAND(replace, ARG_NONE);
COMMAND(archvertex, ARG_3INT);
COMMAND(arch, ARG_2INT);
COMMAND(slope, ARG_2INT);
COMMANDN(vdelta, setvdelta, ARG_1INT);
COMMANDN(undo, editundo, ARG_NONE);
COMMAND(copy, ARG_NONE);
COMMAND(paste, ARG_NONE);
COMMAND(edittex, ARG_2INT);
COMMAND(newent, ARG_5STR);
COMMAND(perlin, ARG_3INT);







|
|
|
|
|
|
|
|
|
|
|
|
|
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
newent(char *what, char *a1, char *a2, char *a3, char *a4)
{
	EDITSEL;
	newentity(sel.x, sel.y, (int)player1->o.z, what, ATOI(a1), ATOI(a2),
	    ATOI(a3), ATOI(a4));
};

COMMANDN(select, selectpos, ARG_4INT)
COMMAND(edittag, ARG_1INT)
COMMAND(replace, ARG_NONE)
COMMAND(archvertex, ARG_3INT)
COMMAND(arch, ARG_2INT)
COMMAND(slope, ARG_2INT)
COMMANDN(vdelta, setvdelta, ARG_1INT)
COMMANDN(undo, editundo, ARG_NONE)
COMMAND(copy, ARG_NONE)
COMMAND(paste, ARG_NONE)
COMMAND(edittex, ARG_2INT)
COMMAND(newent, ARG_5STR)
COMMAND(perlin, ARG_3INT)

Modified src/init.mm from [79aa5cd4bd] to [1613c5c115].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <vector>

#import "cube.h"
#import "protos.h"

static OFMutableArray<void (^)(void)> *queue;

void
enqueueInit(void (^init)(void))
{
	if (queue == nil)
		queue = [[OFMutableArray alloc] init];

	[queue addObject:init];
}

void
processInitQueue(void)
{
	for (void (^init)(void) in queue)
		init();

	[queue removeAllObjects];
}





|




|
|

|





|


|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <vector>

#import "cube.h"
#import "protos.h"

static std::vector<void (^)(void)> *queue;

void
enqueueInit(void (^init)(void))
{
	if (queue == NULL)
		queue = new std::vector<void (^)(void)>();

	queue->push_back(init);
}

void
processInitQueue(void)
{
	for (auto &init : *queue)
		init();

	queue->clear();
}

Modified src/menus.mm from [ae67c88d5e] to [f8da5ecd7e].

123
124
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141
void
menuitem(char *text, char *action)
{
	gmenu &menu = menus.last();
	mitem &mi = menu.items.add();
	mi.text = newstring(text);
	mi.action = action[0] ? newstring(action) : mi.text;
};

COMMAND(menuitem, ARG_2STR);

COMMAND(showmenu, ARG_1STR);
COMMAND(newmenu, ARG_1STR);

bool
menukey(int code, bool isdown)
{
	if (vmenu <= 0)
		return false;
	int menusel = menus[vmenu].menusel;







<
|
|
>
|
|







123
124
125
126
127
128
129

130
131
132
133
134
135
136
137
138
139
140
141
void
menuitem(char *text, char *action)
{
	gmenu &menu = menus.last();
	mitem &mi = menu.items.add();
	mi.text = newstring(text);
	mi.action = action[0] ? newstring(action) : mi.text;

}
COMMAND(menuitem, ARG_2STR)

COMMAND(showmenu, ARG_1CSTR)
COMMAND(newmenu, ARG_1CSTR)

bool
menukey(int code, bool isdown)
{
	if (vmenu <= 0)
		return false;
	int menusel = menus[vmenu].menusel;

Modified src/protos.h from [9cae557fce] to [caa998f8bf].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// protos for ALL external functions in cube...

// command
extern int variable(char *name, int min, int cur, int max, int *storage,
    void (*fun)(), bool persist);
extern void setvar(char *name, int i);
extern int getvar(char *name);
extern bool identexists(char *name);
extern bool addcommand(char *name, void (*fun)(), int narg);
extern int execute(char *p, bool down = true);
extern void exec(char *cfgfile);
extern bool execfile(char *cfgfile);
extern void resetcomplete();
extern void complete(char *s);
extern void alias(char *name, char *action);
extern char *getalias(char *name);
extern void writecfg();

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








|






|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// protos for ALL external functions in cube...

// command
extern int variable(char *name, int min, int cur, int max, int *storage,
    void (*fun)(), bool persist);
extern void setvar(char *name, int i);
extern int getvar(char *name);
extern bool identexists(char *name);
extern bool addcommand(OFString *name, void (*fun)(), int narg);
extern int execute(char *p, bool down = true);
extern void exec(char *cfgfile);
extern bool execfile(char *cfgfile);
extern void resetcomplete();
extern void complete(char *s);
extern void alias(char *name, char *action);
extern OFString *getalias(OFString *name);
extern void writecfg();

// console
extern void keypress(int code, bool isdown, int cooked);
extern void renderconsole();
extern void conoutf(OFString *s, ...);
extern char *getcurcommand();
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
extern void changemapserv(char *name, int mode);
extern void writeclientinfo(FILE *f);

// clientgame
extern void mousemove(int dx, int dy);
extern void updateworld(int millis);
extern void startmap(char *name);
extern void changemap(char *name);
extern void initclient();
extern void spawnplayer(dynent *d);
extern void selfdamage(int damage, int actor, dynent *act);
extern dynent *newdynent();
extern char *getclientmap();
extern const char *modestr(int n);
extern void zapdynent(dynent *&d);
extern dynent *getclient(int cn);
extern void timeupdate(int timeremain);
extern void resetmovement(dynent *d);
extern void fixplayer1range();








|




|







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
extern void changemapserv(char *name, int mode);
extern void writeclientinfo(FILE *f);

// clientgame
extern void mousemove(int dx, int dy);
extern void updateworld(int millis);
extern void startmap(char *name);
extern void changemap(OFString *name);
extern void initclient();
extern void spawnplayer(dynent *d);
extern void selfdamage(int damage, int actor, dynent *act);
extern dynent *newdynent();
extern OFString *getclientmap();
extern const char *modestr(int n);
extern void zapdynent(dynent *&d);
extern dynent *getclient(int cn);
extern void timeupdate(int timeremain);
extern void resetmovement(dynent *d);
extern void fixplayer1range();

178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// renderparticles
extern void setorient(vec &r, vec &u);
extern void particle_splash(int type, int num, int fade, vec &p);
extern void particle_trail(int type, int fade, vec &from, vec &to);
extern void render_particles(int time);

// worldio
extern void save_world(char *fname);
extern void load_world(char *mname);
extern void writemap(char *mname, int msize, uchar *mdata);
extern uchar *readmap(char *mname, int *msize);
extern void loadgamerest();
extern void incomingdemodata(uchar *buf, int len, bool extras = false);
extern void demoplaybackstep();
extern void stop();
extern void stopifrecording();
extern void demodamage(int damage, vec &o);
extern void demoblend(int damage);







|


|







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// renderparticles
extern void setorient(vec &r, vec &u);
extern void particle_splash(int type, int num, int fade, vec &p);
extern void particle_trail(int type, int fade, vec &from, vec &to);
extern void render_particles(int time);

// worldio
extern void save_world(const char *fname);
extern void load_world(char *mname);
extern void writemap(char *mname, int msize, uchar *mdata);
extern uchar *readmap(const char *mname, int *msize);
extern void loadgamerest();
extern void incomingdemodata(uchar *buf, int len, bool extras = false);
extern void demoplaybackstep();
extern void stop();
extern void stopifrecording();
extern void demodamage(int damage, vec &o);
extern void demoblend(int damage);

Modified src/rendercubes.mm from [93318b77b9] to [00e0652146].

62
63
64
65
66
67
68


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
int firstindex;
bool showm = false;

void
showmip()
{
	showm = !showm;


};
void
mipstats(int a, int b, int c)
{
	if (showm)
		conoutf(@"1x1/2x2/4x4: %d / %d / %d", a, b, c);
};

COMMAND(showmip, ARG_NONE);

#define stripend()                                                             \
	{                                                                      \
		if (floorstrip || deltastrip) {                                \
			addstrip(ogltex, firstindex, curvert - firstindex);    \
			floorstrip = deltastrip = false;                       \
		};                                                             \







>
>
|





<
|
<







62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

77

78
79
80
81
82
83
84
int firstindex;
bool showm = false;

void
showmip()
{
	showm = !showm;
}
COMMAND(showmip, ARG_NONE)

void
mipstats(int a, int b, int c)
{
	if (showm)
		conoutf(@"1x1/2x2/4x4: %d / %d / %d", a, b, c);

}


#define stripend()                                                             \
	{                                                                      \
		if (floorstrip || deltastrip) {                                \
			addstrip(ogltex, firstindex, curvert - firstindex);    \
			floorstrip = deltastrip = false;                       \
		};                                                             \

Modified src/renderextras.mm from [93b4bffbbf] to [92e074465e].

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
	{
		sprintf_sd(name)("packages/%s_%s.jpg", basename, side[i]);
		int xs, ys;
		if (!installtex(texnum + i, path(name), xs, ys, true))
			conoutf(@"could not load sky textures");
	};
	strcpy_s(lastsky, basename);
};

COMMAND(loadsky, ARG_1STR);

float cursordepth = 0.9f;
GLint viewport[4];
GLdouble mm[16], pm[16];
vec worldpos;

void







<
|
|







209
210
211
212
213
214
215

216
217
218
219
220
221
222
223
224
	{
		sprintf_sd(name)("packages/%s_%s.jpg", basename, side[i]);
		int xs, ys;
		if (!installtex(texnum + i, path(name), xs, ys, true))
			conoutf(@"could not load sky textures");
	};
	strcpy_s(lastsky, basename);

}
COMMAND(loadsky, ARG_1CSTR)

float cursordepth = 0.9f;
GLint viewport[4];
GLdouble mm[16], pm[16];
vec worldpos;

void

Modified src/rendergl.mm from [a9494ec649] to [d502cbc841].

142
143
144
145
146
147
148
149


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

int curtexnum = 0;

void
texturereset()
{
	curtexnum = 0;
};



void
texture(char *aframe, char *name)
{
	int num = curtexnum++, frame = atoi(aframe);
	if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES)
		return;
	mapping[num][frame] = 1;
	char *n = mapname[num][frame];
	strcpy_s(n, name);
	path(n);
};

COMMAND(texturereset, ARG_NONE);
COMMAND(texture, ARG_2STR);

int
lookuptexture(int tex, int &xs, int &ys)
{
	int frame = 0; // other frames?
	int tid = mapping[tex][frame];








<
>
>











<
|
<
|







142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
157
158
159
160
161

162

163
164
165
166
167
168
169
170

int curtexnum = 0;

void
texturereset()
{
	curtexnum = 0;

}
COMMAND(texturereset, ARG_NONE)

void
texture(char *aframe, char *name)
{
	int num = curtexnum++, frame = atoi(aframe);
	if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES)
		return;
	mapping[num][frame] = 1;
	char *n = mapname[num][frame];
	strcpy_s(n, name);
	path(n);

}

COMMAND(texture, ARG_2STR)

int
lookuptexture(int tex, int &xs, int &ys)
{
	int frame = 0; // other frames?
	int tid = mapping[tex][frame];

Modified src/rendermd2.mm from [e791a84317] to [8c996c1951].

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
mapmodel(char *rad, char *h, char *zoff, char *snap, char *name)
{
	md2 *m = loadmodel(name);
	mapmodelinfo mmi = {
	    atoi(rad), atoi(h), atoi(zoff), atoi(snap), m->loadname};
	m->mmi = mmi;
	mapmodels.add(m);
};



void
mapmodelreset()
{
	mapmodels.setsize(0);
};



mapmodelinfo *
getmminfo(int i)
{
	return i < mapmodels.length() ? &mapmodels[i]->mmi : NULL;
};

COMMAND(mapmodel, ARG_5STR);
COMMAND(mapmodelreset, ARG_NONE);

void
rendermodel(char *mdl, int frame, int range, int tex, float rad, float x,
    float y, float z, float yaw, float pitch, bool teammate, float scale,
    float speed, int snap, int basetime)
{
	md2 *m = loadmodel(mdl);







<
>
>





<
>
>





<
|
<
<







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
mapmodel(char *rad, char *h, char *zoff, char *snap, char *name)
{
	md2 *m = loadmodel(name);
	mapmodelinfo mmi = {
	    atoi(rad), atoi(h), atoi(zoff), atoi(snap), m->loadname};
	m->mmi = mmi;
	mapmodels.add(m);

}
COMMAND(mapmodel, ARG_5STR)

void
mapmodelreset()
{
	mapmodels.setsize(0);

}
COMMAND(mapmodelreset, ARG_NONE)

mapmodelinfo *
getmminfo(int i)
{
	return i < mapmodels.length() ? &mapmodels[i]->mmi : NULL;

}



void
rendermodel(char *mdl, int frame, int range, int tex, float rad, float x,
    float y, float z, float yaw, float pitch, bool teammate, float scale,
    float speed, int snap, int basetime)
{
	md2 *m = loadmodel(mdl);

Modified src/savegamedemo.mm from [7d18bd49dc] to [173411f8b2].

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
53
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
91
92
93
94
95
96
97

98

99
100
101
102
103
104
105

void startdemo();

void
gzput(int i)
{
	gzputc(f, i);

};
void
gzputi(int i)
{
	gzwrite(f, &i, sizeof(int));

};
void
gzputv(vec &v)
{
	gzwrite(f, &v, sizeof(vec));
};


void
gzcheck(int a, int b)
{
	if (a != b)
		fatal("savegame file corrupt (short)");

};
int
gzget()
{
	char c = gzgetc(f);
	return c;

};
int
gzgeti()
{
	int i;
	gzcheck(gzread(f, &i, sizeof(int)), sizeof(int));
	return i;

};
void
gzgetv(vec &v)
{
	gzcheck(gzread(f, &v, sizeof(vec)), sizeof(vec));
};


void
stop()
{
	if (f) {
		if (demorecording)
			gzputi(-1);
		gzclose(f);
	};
	f = NULL;
	demorecording = false;
	demoplayback = false;
	demoloading = false;
	loopv(playerhistory) zapdynent(playerhistory[i]);
	playerhistory.setsize(0);
};


void
stopifrecording()
{
	if (demorecording)
		stop();
};


void
savestate(char *fn)
{
	stop();
	f = gzopen(fn, "wb9");
	if (!f) {
		conoutf(@"could not write %s", fn);
		return;
	};
	gzwrite(f, (void *)"CUBESAVE", 8);
	gzputc(f, islittleendian);
	gzputi(SAVEGAMEVERSION);
	gzputi(sizeof(dynent));

	gzwrite(f, getclientmap(), _MAXDEFSTR);

	gzputi(gamemode);
	gzputi(ents.length());
	loopv(ents) gzputc(f, ents[i].spawned);
	gzwrite(f, player1, sizeof(dynent));
	dvector &monsters = getmonsters();
	gzputi(monsters.length());
	loopv(monsters) gzwrite(f, monsters[i], sizeof(dynent));







>
|




>
|




<
>






>
|





>
|






>
|




<
>















<
>






<
>














>
|
>







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
53
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

void startdemo();

void
gzput(int i)
{
	gzputc(f, i);
}

void
gzputi(int i)
{
	gzwrite(f, &i, sizeof(int));
}

void
gzputv(vec &v)
{
	gzwrite(f, &v, sizeof(vec));

}

void
gzcheck(int a, int b)
{
	if (a != b)
		fatal("savegame file corrupt (short)");
}

int
gzget()
{
	char c = gzgetc(f);
	return c;
}

int
gzgeti()
{
	int i;
	gzcheck(gzread(f, &i, sizeof(int)), sizeof(int));
	return i;
}

void
gzgetv(vec &v)
{
	gzcheck(gzread(f, &v, sizeof(vec)), sizeof(vec));

}

void
stop()
{
	if (f) {
		if (demorecording)
			gzputi(-1);
		gzclose(f);
	};
	f = NULL;
	demorecording = false;
	demoplayback = false;
	demoloading = false;
	loopv(playerhistory) zapdynent(playerhistory[i]);
	playerhistory.setsize(0);

}

void
stopifrecording()
{
	if (demorecording)
		stop();

}

void
savestate(char *fn)
{
	stop();
	f = gzopen(fn, "wb9");
	if (!f) {
		conoutf(@"could not write %s", fn);
		return;
	};
	gzwrite(f, (void *)"CUBESAVE", 8);
	gzputc(f, islittleendian);
	gzputi(SAVEGAMEVERSION);
	gzputi(sizeof(dynent));
	@autoreleasepool {
		gzwrite(f, getclientmap().UTF8String, _MAXDEFSTR);
	}
	gzputi(gamemode);
	gzputi(ents.length());
	loopv(ents) gzputc(f, ents[i].spawned);
	gzwrite(f, player1, sizeof(dynent));
	dvector &monsters = getmonsters();
	gzputi(monsters.length());
	loopv(monsters) gzwrite(f, monsters[i], sizeof(dynent));
119
120
121
122
123
124
125

126
127
128
129
130
131
132
		return;
	}
	sprintf_sd(fn)("savegames/%s.csgz", name);
	savestate(fn);
	stop();
	conoutf(@"wrote %s", fn);
}


void
loadstate(char *fn)
{
	stop();
	if (multiplayer())
		return;







>







126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
		return;
	}
	sprintf_sd(fn)("savegames/%s.csgz", name);
	savestate(fn);
	stop();
	conoutf(@"wrote %s", fn);
}
COMMAND(savegame, ARG_1CSTR)

void
loadstate(char *fn)
{
	stop();
	if (multiplayer())
		return;
144
145
146
147
148
149
150


151
152

153
154
155
156
157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
		goto out; // not supporting save->load accross incompatible
		          // architectures simpifies things a LOT
	if (gzgeti() != SAVEGAMEVERSION || gzgeti() != sizeof(dynent))
		goto out;
	string mapname;
	gzread(f, mapname, _MAXDEFSTR);
	nextmode = gzgeti();


	changemap(mapname); // continue below once map has been loaded and
	                    // client & server have updated

	return;
out:
	conoutf(@"aborting: savegame/demo from a different version of cube or "
	        @"cpu architecture");
	stop();
}

void
loadgame(char *name)
{
	sprintf_sd(fn)("savegames/%s.csgz", name);
	loadstate(fn);
}


void
loadgameout()
{
	stop();
	conoutf(@"loadgame incomplete: savegame from a different version of "
	        @"this map");







>
>
|
|
>













>







152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
		goto out; // not supporting save->load accross incompatible
		          // architectures simpifies things a LOT
	if (gzgeti() != SAVEGAMEVERSION || gzgeti() != sizeof(dynent))
		goto out;
	string mapname;
	gzread(f, mapname, _MAXDEFSTR);
	nextmode = gzgeti();
	@autoreleasepool {
		changemap(
		    @(mapname)); // continue below once map has been loaded and
		                 // client & server have updated
	}
	return;
out:
	conoutf(@"aborting: savegame/demo from a different version of cube or "
	        @"cpu architecture");
	stop();
}

void
loadgame(char *name)
{
	sprintf_sd(fn)("savegames/%s.csgz", name);
	loadstate(fn);
}
COMMAND(loadgame, ARG_1CSTR)

void
loadgameout()
{
	stop();
	conoutf(@"loadgame incomplete: savegame from a different version of "
	        @"this map");
243
244
245
246
247
248
249
250


251
252
253
254
255
256
257
	sprintf_sd(fn)("demos/%s.cdgz", name);
	savestate(fn);
	gzputi(cn);
	conoutf(@"started recording demo to %s", fn);
	demorecording = true;
	starttime = lastmillis;
	ddamage = bdamage = 0;
};



void
demodamage(int damage, vec &o)
{
	ddamage = damage;
	dorig = o;
};







<
>
>







255
256
257
258
259
260
261

262
263
264
265
266
267
268
269
270
	sprintf_sd(fn)("demos/%s.cdgz", name);
	savestate(fn);
	gzputi(cn);
	conoutf(@"started recording demo to %s", fn);
	demorecording = true;
	starttime = lastmillis;
	ddamage = bdamage = 0;

}
COMMAND(record, ARG_1CSTR)

void
demodamage(int damage, vec &o)
{
	ddamage = damage;
	dorig = o;
};
295
296
297
298
299
300
301

302
303
304
305
306
307
308
void
demo(char *name)
{
	sprintf_sd(fn)("demos/%s.cdgz", name);
	loadstate(fn);
	demoloading = true;
}


void
stopreset()
{
	conoutf(@"demo stopped (%d msec elapsed)", lastmillis - starttime);
	stop();
	loopv(players) zapdynent(players[i]);







>







308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
void
demo(char *name)
{
	sprintf_sd(fn)("demos/%s.cdgz", name);
	loadstate(fn);
	demoloading = true;
}
COMMAND(demo, ARG_1CSTR)

void
stopreset()
{
	conoutf(@"demo stopped (%d msec elapsed)", lastmillis - starttime);
	stop();
	loopv(players) zapdynent(players[i]);
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
stopn()
{
	if (demoplayback)
		stopreset();
	else
		stop();
	conoutf(@"demo stopped");
};

COMMAND(record, ARG_1STR);
COMMAND(demo, ARG_1STR);
COMMANDN(stop, stopn, ARG_NONE);

COMMAND(savegame, ARG_1STR);
COMMAND(loadgame, ARG_1STR);







<
|
<
<
|
<
<
<
498
499
500
501
502
503
504

505


506



stopn()
{
	if (demoplayback)
		stopreset();
	else
		stop();
	conoutf(@"demo stopped");

}


COMMANDN(stop, stopn, ARG_NONE)



Modified src/serverbrowser.mm from [164c8571dd] to [28e1977716].

308
309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324
325
326
	    strstr((char *)reply, "<HTML>"))
		conoutf(@"master server not replying");
	else {
		servers.setsize(0);
		execute((char *)reply);
	};
	servermenu();
};


COMMAND(addserver, ARG_1STR);
COMMAND(servermenu, ARG_NONE);
COMMAND(updatefrommaster, ARG_NONE);

void
writeservercfg()
{
	FILE *f = fopen("servers.cfg", "w");
	if (!f)
		return;







<
|
>
|
|
|







308
309
310
311
312
313
314

315
316
317
318
319
320
321
322
323
324
325
326
	    strstr((char *)reply, "<HTML>"))
		conoutf(@"master server not replying");
	else {
		servers.setsize(0);
		execute((char *)reply);
	};
	servermenu();

}

COMMAND(addserver, ARG_1CSTR)
COMMAND(servermenu, ARG_NONE)
COMMAND(updatefrommaster, ARG_NONE)

void
writeservercfg()
{
	FILE *f = fopen("servers.cfg", "w");
	if (!f)
		return;

Modified src/sound.mm from [1b753dcafe] to [45fff0426a].

106
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
				FSOUND_SetPaused(chan, false);
			};
		} else {
			conoutf(@"could not play music: %s", sn);
		};
#endif
	};
};


COMMAND(music, ARG_1STR);

#ifdef USE_MIXER
vector<Mix_Chunk *> samples;
#else
vector<FSOUND_SAMPLE *> samples;
#endif

cvector snames;

int
registersound(char *name)
{
	loopv(snames) if (strcmp(snames[i], name) == 0) return i;
	snames.add(newstring(name));
	samples.add(NULL);
	return samples.length() - 1;
};

COMMAND(registersound, ARG_1EST);

void
cleansound()
{
	if (nosound)
		return;
	stopsound();







<
|
>
|


















|







106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
				FSOUND_SetPaused(chan, false);
			};
		} else {
			conoutf(@"could not play music: %s", sn);
		};
#endif
	};

}

COMMAND(music, ARG_1CSTR)

#ifdef USE_MIXER
vector<Mix_Chunk *> samples;
#else
vector<FSOUND_SAMPLE *> samples;
#endif

cvector snames;

int
registersound(char *name)
{
	loopv(snames) if (strcmp(snames[i], name) == 0) return i;
	snames.add(newstring(name));
	samples.add(NULL);
	return samples.length() - 1;
};

COMMAND(registersound, ARG_1EST)

void
cleansound()
{
	if (nosound)
		return;
	stopsound();
263
264
265
266
267
268
269
270

271
#endif
};

void
sound(int n)
{
	playsound(n, NULL);
};

COMMAND(sound, ARG_1INT);







<
>
|
263
264
265
266
267
268
269

270
271
#endif
};

void
sound(int n)
{
	playsound(n, NULL);

}
COMMAND(sound, ARG_1INT)

Modified src/tools.h from [900cc870ab] to [2f2caef516].

162
163
164
165
166
167
168
169

170
171
172
173

174
175
176
177
178

179
180
181
182
183
184

185
186
187
188
189
190
191
	pool();
	~pool() { dealloc_block(blocks); };

	void *alloc(size_t size);
	void dealloc(void *p, size_t size);
	void *realloc(void *p, size_t oldsize, size_t newsize);

	char *string(char *s, size_t l);

	char *
	string(char *s)
	{
		return string(s, strlen(s));

	};
	void
	deallocstr(char *s)
	{
		dealloc(s, strlen(s) + 1);

	};
	char *
	stringbuf(char *s)
	{
		return string(s, _MAXDEFSTR - 1);
	};


	void dealloc_block(void *b);
	void allocnext(size_t allocsize);
};

pool *gp();








|
>

|


>
|




>
|

|


<
>







162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
	pool();
	~pool() { dealloc_block(blocks); };

	void *alloc(size_t size);
	void dealloc(void *p, size_t size);
	void *realloc(void *p, size_t oldsize, size_t newsize);

	char *string(const char *s, size_t l);

	char *
	string(const char *s)
	{
		return string(s, strlen(s));
	}

	void
	deallocstr(char *s)
	{
		dealloc(s, strlen(s) + 1);
	}

	char *
	stringbuf(const char *s)
	{
		return string(s, _MAXDEFSTR - 1);

	}

	void dealloc_block(void *b);
	void allocnext(size_t allocsize);
};

pool *gp();

375
376
377
378
379
380
381
382
383
384

385
386
387
388
389

390
391
392
393
394
395
396

397
	                     ht->enumc = ht->enumc->next)                      \
	{                                                                      \
		t e = &ht->enumc->data;                                        \
		b;                                                             \
	}

inline char *
newstring(char *s)
{
	return gp()->string(s);

};
inline char *
newstring(char *s, size_t l)
{
	return gp()->string(s, l);

};
inline char *
newstringbuf(char *s)
{
	return gp()->stringbuf(s);
};


#endif







|


>
|

|


>
|

|


<
|
>

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
	                     ht->enumc = ht->enumc->next)                      \
	{                                                                      \
		t e = &ht->enumc->data;                                        \
		b;                                                             \
	}

inline char *
newstring(const char *s)
{
	return gp()->string(s);
}

inline char *
newstring(const char *s, size_t l)
{
	return gp()->string(s, l);
}

inline char *
newstringbuf(const char *s)
{
	return gp()->stringbuf(s);

}

#endif

Modified src/tools.mm from [d4bb43600a] to [bc3e2d9f84].

78
79
80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
	*((char **)b) = blocks;
	blocks = b;
	p = b + PTRSIZE;
	left = allocsize;
};

char *
pool::string(char *s, size_t l)
{
	char *b = (char *)alloc(l + 1);
	strncpy(b, s, l);
	b[l] = 0;
	return b;
};


pool *
gp() // useful for global buffers that need to be initialisation order
     // independant
{
	static pool *p = NULL;
	return p ? p : (p = new pool());







|





<
>







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

91
92
93
94
95
96
97
98
	*((char **)b) = blocks;
	blocks = b;
	p = b + PTRSIZE;
	left = allocsize;
};

char *
pool::string(const char *s, size_t l)
{
	char *b = (char *)alloc(l + 1);
	strncpy(b, s, l);
	b[l] = 0;
	return b;

}

pool *
gp() // useful for global buffers that need to be initialisation order
     // independant
{
	static pool *p = NULL;
	return p ? p : (p = new pool());

Modified src/weapon.mm from [2770740083] to [61c62f225e].

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
};

void
weapon(char *a1, char *a2, char *a3)
{
	selectgun(a1[0] ? atoi(a1) : -1, a2[0] ? atoi(a2) : -1,
	    a3[0] ? atoi(a3) : -1);
};

COMMAND(weapon, ARG_3STR);

void
createrays(vec &from, vec &to) // create random spread of rays for the shotgun
{
	vdist(dist, dvec, from, to);
	float f = dist * SGSPREAD / 1000;
	loopi(SGRAYS)







<
|
|







60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75
};

void
weapon(char *a1, char *a2, char *a3)
{
	selectgun(a1[0] ? atoi(a1) : -1, a2[0] ? atoi(a2) : -1,
	    a3[0] ? atoi(a3) : -1);

}
COMMAND(weapon, ARG_3STR)

void
createrays(vec &from, vec &to) // create random spread of rays for the shotgun
{
	vdist(dist, dvec, from, to);
	float f = dist * SGSPREAD / 1000;
	loopi(SGRAYS)

Modified src/world.mm from [0157413baa] to [a8778ab451].

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
	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).








<
|
|







62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
	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).

356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
	{
		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;







<
|
|







355
356
357
358
359
360
361

362
363
364
365
366
367
368
369
370
	{
		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;
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
		if (intens) {
			scalecomp(e.attr2, intens);
			scalecomp(e.attr3, intens);
			scalecomp(e.attr4, intens);
		};
	};
	calclight();
};

COMMAND(scalelights, ARG_2INT);

int
findentity(int type, int index)
{
	for (int i = index; i < ents.length(); i++)
		if (ents[i].type == type)
			return i;







<
|
|







387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
		if (intens) {
			scalecomp(e.attr2, intens);
			scalecomp(e.attr3, intens);
			scalecomp(e.attr4, intens);
		};
	};
	calclight();

}
COMMAND(scalelights, ARG_2INT)

int
findentity(int type, int index)
{
	for (int i = index; i < ents.length(); i++)
		if (ents[i].type == type)
			return i;
500
501
502
503
504
505
506
507
508
509
510
511
};
void
newmap(int i)
{
	empty_world(i, false);
};

COMMAND(mapenlarge, ARG_NONE);
COMMAND(newmap, ARG_1INT);
COMMANDN(recalc, calclight, ARG_NONE);
COMMAND(delent, ARG_NONE);
COMMAND(entproperty, ARG_2INT);







|
|
|
|
|
497
498
499
500
501
502
503
504
505
506
507
508
};
void
newmap(int i)
{
	empty_world(i, false);
};

COMMAND(mapenlarge, ARG_NONE)
COMMAND(newmap, ARG_1INT)
COMMANDN(recalc, calclight, ARG_NONE)
COMMAND(delent, ARG_NONE)
COMMAND(entproperty, ARG_2INT)

Modified src/worldio.mm from [e1e98ece3c] to [6ed752d022].

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
// worldio.cpp: loading & saving of maps and savegames

#include "cube.h"

void
backup(char *name, char *backupname)
{
	remove(backupname);
	rename(name, backupname);
};

string cgzname, bakname, pcfname, mcfname;

void
setnames(char *name)
{
	string pakname, mapname;
	char *slash = strpbrk(name, "/\\");
	if (slash) {
		strn0cpy(pakname, name, slash - name + 1);
		strcpy_s(mapname, slash + 1);
	} else {
		strcpy_s(pakname, "base");
		strcpy_s(mapname, name);
	};

	sprintf_s(cgzname)("packages/%s/%s.cgz", pakname, mapname);
	sprintf_s(bakname)(
	    "packages/%s/%s_%d.BAK", pakname, mapname, lastmillis);
	sprintf_s(pcfname)("packages/%s/package.cfg", pakname);
	sprintf_s(mcfname)("packages/%s/%s.cfg", pakname, mapname);

	path(cgzname);
	path(bakname);
};


// the optimize routines below are here to reduce the detrimental effects of
// messy mapping by setting certain properties (vdeltas and textures) to
// neighbouring values wherever there is no visible difference. This allows the
// mipmapper to generate more efficient mips. the reason it is done on save is
// to reduce the amount spend in the mipmapper (as that is done in realtime).














|
|


|






<
>








<
>







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
// worldio.cpp: loading & saving of maps and savegames

#include "cube.h"

void
backup(char *name, char *backupname)
{
	remove(backupname);
	rename(name, backupname);
};

string cgzname, bakname, pcfname, mcfname;

static void
setnames(const char *name)
{
	string pakname, mapname;
	const char *slash = strpbrk(name, "/\\");
	if (slash) {
		strn0cpy(pakname, name, slash - name + 1);
		strcpy_s(mapname, slash + 1);
	} else {
		strcpy_s(pakname, "base");
		strcpy_s(mapname, name);

	}
	sprintf_s(cgzname)("packages/%s/%s.cgz", pakname, mapname);
	sprintf_s(bakname)(
	    "packages/%s/%s_%d.BAK", pakname, mapname, lastmillis);
	sprintf_s(pcfname)("packages/%s/package.cfg", pakname);
	sprintf_s(mcfname)("packages/%s/%s.cfg", pakname, mapname);

	path(cgzname);
	path(bakname);

}

// the optimize routines below are here to reduce the detrimental effects of
// messy mapping by setting certain properties (vdeltas and textures) to
// neighbouring values wherever there is no visible difference. This allows the
// mipmapper to generate more efficient mips. the reason it is done on save is
// to reduce the amount spend in the mipmapper (as that is done in realtime).

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

159

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
	};
	fwrite(mdata, 1, msize, f);
	fclose(f);
	conoutf(@"wrote map %s as file %s", mname, cgzname);
}

uchar *
readmap(char *mname, int *msize)
{
	setnames(mname);
	uchar *mdata = (uchar *)loadfile(cgzname, msize);
	if (!mdata) {
		conoutf(@"could not read map %s", cgzname);
		return NULL;
	};
	return mdata;
}

// save map as .cgz file. uses 2 layers of compression: first does simple
// run-length encoding and leaves out data for certain kinds of cubes, then zlib
// removes the last bits of redundancy. Both passes contribute greatly to the
// miniscule map sizes.

void
save_world(char *mname)
{

	resettagareas(); // wouldn't be able to reproduce tagged areas otherwise

	voptimize();
	toptimize();
	if (!*mname)
		mname = getclientmap();
	setnames(mname);
	backup(cgzname, bakname);
	gzFile f = gzopen(cgzname, "wb9");
	if (!f) {
		conoutf(@"could not write map to %s", cgzname);
		return;
	};
	hdr.version = MAPVERSION;
	hdr.numents = 0;
	loopv(ents) if (ents[i].type != NOTUSED) hdr.numents++;
	header tmp = hdr;
	endianswap(&tmp.version, sizeof(int), 4);
	endianswap(&tmp.waterlevel, sizeof(int), 16);
	gzwrite(f, &tmp, sizeof(header));
	loopv(ents)
	{
		if (ents[i].type != NOTUSED) {
			entity tmp = ents[i];
			endianswap(&tmp, sizeof(short), 4);
			gzwrite(f, &tmp, sizeof(persistent_entity));
		};
	};
	sqr *t = NULL;
	int sc = 0;
#define spurge                                                                 \
	while (sc) {                                                           \
		gzputc(f, 255);                                                \
		if (sc > 255) {                                                \
			gzputc(f, 255);                                        \
			sc -= 255;                                             \
		} else {                                                       \
			gzputc(f, sc);                                         \
			sc = 0;                                                \
		}                                                              \
	};
	loopk(cubicsize)
	{
		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)

		if (SOLID(s)) {
			if (t && c(type) && c(wtex) && c(vdelta)) {
				sc++;
			} else {
				spurge;
				gzputc(f, s->type);
				gzputc(f, s->wtex);
				gzputc(f, s->vdelta);
			};
		} else {
			if (t && c(type) && c(floor) && c(ceil) && c(ctex) &&
			    c(ftex) && c(utex) && c(wtex) && c(vdelta) &&
			    c(tag)) {
				sc++;
			} else {
				spurge;
				gzputc(f, s->type);
				gzputc(f, s->floor);
				gzputc(f, s->ceil);
				gzputc(f, s->wtex);
				gzputc(f, s->ftex);
				gzputc(f, s->ctex);
				gzputc(f, s->vdelta);
				gzputc(f, s->utex);
				gzputc(f, s->tag);
			};
		};
		t = s;
	};
	spurge;
	gzclose(f);
	conoutf(@"wrote map file %s", cgzname);
	settagareas();
};



void
load_world(char *mname) // still supports all map formats that have existed
                        // since the earliest cube betas!
{
	stopifrecording();
	cleardlights();







|
















|

>
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|











|
|
|

|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
>
>







133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
	};
	fwrite(mdata, 1, msize, f);
	fclose(f);
	conoutf(@"wrote map %s as file %s", mname, cgzname);
}

uchar *
readmap(const char *mname, int *msize)
{
	setnames(mname);
	uchar *mdata = (uchar *)loadfile(cgzname, msize);
	if (!mdata) {
		conoutf(@"could not read map %s", cgzname);
		return NULL;
	};
	return mdata;
}

// save map as .cgz file. uses 2 layers of compression: first does simple
// run-length encoding and leaves out data for certain kinds of cubes, then zlib
// removes the last bits of redundancy. Both passes contribute greatly to the
// miniscule map sizes.

void
save_world(const char *mname)
{
	@autoreleasepool {
		resettagareas(); // wouldn't be able to reproduce tagged areas
		                 // otherwise
		voptimize();
		toptimize();
		if (!*mname)
			mname = getclientmap().UTF8String;
		setnames(mname);
		backup(cgzname, bakname);
		gzFile f = gzopen(cgzname, "wb9");
		if (!f) {
			conoutf(@"could not write map to %s", cgzname);
			return;
		};
		hdr.version = MAPVERSION;
		hdr.numents = 0;
		loopv(ents) if (ents[i].type != NOTUSED) hdr.numents++;
		header tmp = hdr;
		endianswap(&tmp.version, sizeof(int), 4);
		endianswap(&tmp.waterlevel, sizeof(int), 16);
		gzwrite(f, &tmp, sizeof(header));
		loopv(ents)
		{
			if (ents[i].type != NOTUSED) {
				entity tmp = ents[i];
				endianswap(&tmp, sizeof(short), 4);
				gzwrite(f, &tmp, sizeof(persistent_entity));
			};
		};
		sqr *t = NULL;
		int sc = 0;
#define spurge                                                                 \
	while (sc) {                                                           \
		gzputc(f, 255);                                                \
		if (sc > 255) {                                                \
			gzputc(f, 255);                                        \
			sc -= 255;                                             \
		} else {                                                       \
			gzputc(f, sc);                                         \
			sc = 0;                                                \
		}                                                              \
	};
		loopk(cubicsize)
		{
			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)

			if (SOLID(s)) {
				if (t && c(type) && c(wtex) && c(vdelta)) {
					sc++;
				} else {
					spurge;
					gzputc(f, s->type);
					gzputc(f, s->wtex);
					gzputc(f, s->vdelta);
				};
			} else {
				if (t && c(type) && c(floor) && c(ceil) &&
				    c(ctex) && c(ftex) && c(utex) && c(wtex) &&
				    c(vdelta) && c(tag)) {
					sc++;
				} else {
					spurge;
					gzputc(f, s->type);
					gzputc(f, s->floor);
					gzputc(f, s->ceil);
					gzputc(f, s->wtex);
					gzputc(f, s->ftex);
					gzputc(f, s->ctex);
					gzputc(f, s->vdelta);
					gzputc(f, s->utex);
					gzputc(f, s->tag);
				};
			};
			t = s;
		};
		spurge;
		gzclose(f);
		conoutf(@"wrote map file %s", cgzname);
		settagareas();

	}
}

void
load_world(char *mname) // still supports all map formats that have existed
                        // since the earliest cube betas!
{
	stopifrecording();
	cleardlights();
367
368
369
370
371
372
373
374
375

376
		    "level_trigger_%d", l); // can this be done smarter?
		if (identexists(aliasname))
			alias(aliasname, "");
	};
	execfile("data/default_map_settings.cfg");
	execfile(pcfname);
	execfile(mcfname);
};


COMMANDN(savemap, save_world, ARG_1STR);







<
|
>
|
370
371
372
373
374
375
376

377
378
379
		    "level_trigger_%d", l); // can this be done smarter?
		if (identexists(aliasname))
			alias(aliasname, "");
	};
	execfile("data/default_map_settings.cfg");
	execfile(pcfname);
	execfile(mcfname);

}

COMMANDN(savemap, save_world, ARG_1CSTR)

Modified src/worldocull.mm from [cfc9b27041] to [70fd16d6e2].

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
bool ocull = true;
float odist = 256;

void
toggleocull()
{
	ocull = !ocull;
};

COMMAND(toggleocull, ARG_NONE);

// constructs occlusion map: cast rays in all directions on the 2d plane and
// record distance. done exactly once per frame.

void
computeraytable(float vx, float vy)
{







<
|
|







8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
bool ocull = true;
float odist = 256;

void
toggleocull()
{
	ocull = !ocull;

}
COMMAND(toggleocull, ARG_NONE)

// constructs occlusion map: cast rays in all directions on the 2d plane and
// record distance. done exactly once per frame.

void
computeraytable(float vx, float vy)
{