︙ | | | ︙ | |
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
void
writemap(char *mname, int msize, uchar *mdata)
{
setnames(mname);
backup(cgzname, bakname);
FILE *f = fopen(cgzname, "wb");
if (!f) {
conoutf("could not write map to %s", cgzname);
return;
};
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
|
|
|
|
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
void
writemap(char *mname, int msize, uchar *mdata)
{
setnames(mname);
backup(cgzname, bakname);
FILE *f = fopen(cgzname, "wb");
if (!f) {
conoutf(@"could not write map to %s", cgzname);
return;
};
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
|
︙ | | | ︙ | |
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
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);
|
|
|
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
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);
|
︙ | | | ︙ | |
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
|
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();
pruneundos();
setnames(mname);
gzFile f = gzopen(cgzname, "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)
|
|
|
|
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
|
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();
pruneundos();
setnames(mname);
gzFile f = gzopen(cgzname, "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)
|
︙ | | | ︙ | |
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
texuse[s->utex] = texuse[s->ftex] = 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)
{
sprintf_sd(aliasname)(
"level_trigger_%d", l); // can this be done smarter?
if (identexists(aliasname))
alias(aliasname, "");
|
|
|
|
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
texuse[s->utex] = texuse[s->ftex] = 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)
{
sprintf_sd(aliasname)(
"level_trigger_%d", l); // can this be done smarter?
if (identexists(aliasname))
alias(aliasname, "");
|
︙ | | | ︙ | |