MCPcopy Create free account
hub / github.com/assaultcube/AC / write

Method write

source/src/worldio.cpp:1369–1406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1367 }
1368
1369 void write(stream *f) // write xmap as cubescript to a file
1370 {
1371 f->printf("restorexmap version %d %d %d\n", XMAPVERSION, isbigendian() ? 1 : 0, int(sizeof(world))); // it is a non-portable binary file format, so we have to check...
1372 f->printf("restorexmap names \"%s\" \"%s\"\n", name, mcfname);
1373 f->printf("restorexmap sizes %d %d %d\n", ssize, cubicsize, numundo);
1374 hexbinwrite(f, &hdr, sizeof(header));
1375 f->printf("restorexmap header\n");
1376 uLongf worldsize = cubicsize * sizeof(sqr), gzbufsize = (worldsize * 11) / 10; // gzip the world, so the file will only be big instead of huge
1377 uchar *gzbuf = new uchar[gzbufsize];
1378 if(compress2(gzbuf, &gzbufsize, (uchar *)world, worldsize, 9) != Z_OK) gzbufsize = 0;
1379 hexbinwrite(f, gzbuf, gzbufsize, false);
1380 f->printf("restorexmap world\n");
1381 DELETEA(gzbuf);
1382 loopv(headerextras)
1383 {
1384 hexbinwrite(f, headerextras[i]->data, headerextras[i]->len);
1385 f->printf("restorexmap headerextra %d // %s\n", headerextras[i]->flags, hx_name(headerextras[i]->flags));
1386 }
1387 int el = ents.length(), all = el + delents.length();
1388 loopi(all) // entities are stored as plain text - you may edit them
1389 {
1390 persistent_entity &e = i >= el ? delents[i - el] : ents[i];
1391 f->printf("restorexmap %sent %d %d %d %d %d %d %d %d %d %d %d // %s\n", i >= el ? "del": "", e.type, e.x, e.y, e.z, e.attr1, e.attr2, e.attr3, e.attr4, e.attr5, e.attr6, e.attr7, e.type >= 0 && e.type < MAXENTTYPES ? entnames[e.type] : "unknown");
1392 }
1393 if(mapconfig.length())
1394 {
1395 char *t = newstring(mapconfig.getbuf()), *p, *l = t;
1396 while((p = strchr(l, '\n')))
1397 {
1398 *p = '\0';
1399 f->printf("restorexmap config %s\n", escapestring(l));
1400 l = p + 1;
1401 }
1402 delstring(t);
1403 }
1404 loopv(todoents) f->printf("restorexmap todoent %d %s\n", todoents[i], escapestring(todoentdescs[i]));
1405 f->printf("restorexmap position %d %d %d %d %d // EOF, don't touch this\n\n", int(position[0]), int(position[1]), int(position[2]), int(position[3]), int(position[4]));
1406 }
1407};
1408
1409static vector<xmap *> xmaps;

Callers 8

writemapFunction · 0.45
writecfggzFunction · 0.45
extractconfigfileFunction · 0.45
worldio.cppFile · 0.45
save_worldFunction · 0.45
save_world9Function · 0.45
loopvFunction · 0.45
writexmapFunction · 0.45

Calls 9

isbigendianFunction · 0.85
hexbinwriteFunction · 0.85
newstringFunction · 0.85
escapestringFunction · 0.85
delstringFunction · 0.85
loopvFunction · 0.70
printfMethod · 0.45
lengthMethod · 0.45
getbufMethod · 0.45

Tested by

no test coverage detected