Cube  Diff

Differences From Artifact [804d0f5ee3]:

To Artifact [abb1a9a463]:


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
writemap(OFString *mname, int msize, uchar *mdata)
{
	setnames(mname);
	backup(cgzname, bakname);

	FILE *f = fopen([cgzname cStringWithEncoding:OFLocale.encoding], "wb");
	if (!f) {
		conoutf(@"could not write map to %s", cgzname);
		return;
	}
	fwrite(mdata, 1, msize, f);
	fclose(f);
	conoutf(@"wrote map %@ as file %s", mname, cgzname);
}

OFData *
readmap(OFString *mname)
{
	setnames(mname);
	return [OFData dataWithContentsOfFile:mname];







|




|







131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
writemap(OFString *mname, int msize, uchar *mdata)
{
	setnames(mname);
	backup(cgzname, bakname);

	FILE *f = fopen([cgzname cStringWithEncoding:OFLocale.encoding], "wb");
	if (!f) {
		conoutf(@"could not write map to %@", cgzname);
		return;
	}
	fwrite(mdata, 1, msize, f);
	fclose(f);
	conoutf(@"wrote map %@ as file %@", mname, cgzname);
}

OFData *
readmap(OFString *mname)
{
	setnames(mname);
	return [OFData dataWithContentsOfFile:mname];
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
		if (mname.length == 0)
			mname = getclientmap();
		setnames(mname);
		backup(cgzname, bakname);
		gzFile f = gzopen(
		    [cgzname cStringWithEncoding:OFLocale.encoding], "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);







|







166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
		if (mname.length == 0)
			mname = getclientmap();
		setnames(mname);
		backup(cgzname, bakname);
		gzFile f = gzopen(
		    [cgzname cStringWithEncoding:OFLocale.encoding], "wb9");
		if (!f) {
			conoutf(@"could not write map to %@", 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);
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
					gzputc(f, s->tag);
				}
			}
			t = s;
		}
		spurge;
		gzclose(f);
		conoutf(@"wrote map file %s", cgzname);
		settagareas();
	}
}
COMMANDN(savemap, save_world, ARG_1STR)

void
load_world(OFString *mname) // still supports all map formats that have existed
                            // since the earliest cube betas!
{
	@autoreleasepool {
		stopifrecording();
		cleardlights();
		pruneundos();
		setnames(mname);
		gzFile f = gzopen(
		    [cgzname cStringWithEncoding:OFLocale.encoding], "rb9");
		if (!f) {
			conoutf(@"could not read map %s", cgzname);
			return;
		}
		gzread(f, &hdr, sizeof(header) - sizeof(int) * 16);
		endianswap(&hdr.version, sizeof(int), 4);
		if (strncmp(hdr.head, "CUBE", 4) != 0)
			fatal(@"while reading map: header malformatted");
		if (hdr.version > MAPVERSION)







|

















|







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
					gzputc(f, s->tag);
				}
			}
			t = s;
		}
		spurge;
		gzclose(f);
		conoutf(@"wrote map file %@", cgzname);
		settagareas();
	}
}
COMMANDN(savemap, save_world, ARG_1STR)

void
load_world(OFString *mname) // still supports all map formats that have existed
                            // since the earliest cube betas!
{
	@autoreleasepool {
		stopifrecording();
		cleardlights();
		pruneundos();
		setnames(mname);
		gzFile f = gzopen(
		    [cgzname cStringWithEncoding:OFLocale.encoding], "rb9");
		if (!f) {
			conoutf(@"could not read map %@", cgzname);
			return;
		}
		gzread(f, &hdr, sizeof(header) - sizeof(int) * 16);
		endianswap(&hdr.version, sizeof(int), 4);
		if (strncmp(hdr.head, "CUBE", 4) != 0)
			fatal(@"while reading map: header malformatted");
		if (hdr.version > MAPVERSION)
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
				    texuse[s->ctex] = 1;
		}
		gzclose(f);
		calclight();
		settagareas();
		int xs, ys;
		loopi(256) if (texuse) lookuptexture(i, &xs, &ys);
		conoutf(@"read map %s (%d milliseconds)", cgzname,
		    SDL_GetTicks() - lastmillis);
		conoutf(@"%s", hdr.maptitle);
		startmap(mname);
		loopl(256)
		{
			// can this be done smarter?
			OFString *aliasname =







|







368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
				    texuse[s->ctex] = 1;
		}
		gzclose(f);
		calclight();
		settagareas();
		int xs, ys;
		loopi(256) if (texuse) lookuptexture(i, &xs, &ys);
		conoutf(@"read map %@ (%d milliseconds)", cgzname,
		    SDL_GetTicks() - lastmillis);
		conoutf(@"%s", hdr.maptitle);
		startmap(mname);
		loopl(256)
		{
			// can this be done smarter?
			OFString *aliasname =