clean up map header handling

Older versions of ac did not obey the map header field "headersize".
When a map was written, only the "version" field was updated, even if
the new written header had a different size. Thanks to bigger headers
in map versions 7 & 8 (and now smaller headers again in 9), the headersize
of basically all official maps is bogus. This fix makes sure, only proper
headersizes are written. It also makes the game tolerate different (bigger)
headers - and keeps their content untouched. Future map format extensions
can use this to add header information without breaking existing map parsers.

This patch establishes a new map format 10, which is identical to format 9,
with the exception that the headersize field is guaranteed to be correct.
Format 10 also allows any amount of additional header data.

This patch also cleans up the transformation routines for old map entities.
This commit is contained in:
ac-stef
2014-01-27 23:01:23 +01:00
parent 6e4b23734f
commit c3d4713904
6 changed files with 94 additions and 70 deletions
+10 -8
View File
@@ -8,6 +8,8 @@ sqr *world = NULL;
int sfactor, ssize, cubicsize, mipsize;
header hdr;
uchar *headerextra = NULL;
int headerextrasize;
// main geometric mipmapping routine, recursively rebuild mipmaps within block b.
// tries to produce cube out of 4 lower level mips as well as possible,
@@ -481,10 +483,6 @@ bool empty_world(int factor, bool force) // main empty world creation routine
checkselections(); // assert no selection became invalid
strncpy(hdr.head, "ACMP", 4);
hdr.version = MAPVERSION;
hdr.headersize = sizeof(header);
hdr.sfactor = sfactor;
if(copy)
{
ow->x = ow->y = shrink ? 0 : ssize/4;
@@ -501,17 +499,21 @@ bool empty_world(int factor, bool force) // main empty world creation routine
entinmap(player1);
}
else
{
copystring(hdr.maptitle, "Untitled Map by Unknown", 128);
{ // all-new map
memset(&hdr, 0, sizeof(header));
formatstring(hdr.maptitle)("Untitled Map by %s", player1->name);
hdr.waterlevel = -100000;
hdr.ambient = 0;
setwatercolor();
loopi(sizeof(hdr.reserved)/sizeof(hdr.reserved[0])) hdr.reserved[i] = 0;
loopk(3) loopi(256) hdr.texlists[k][i] = i;
ents.shrink(0);
block b = { 8, 8, ssize-16, ssize - 16};
edittypexy(SPACE, b);
DELETEA(headerextra);
}
strncpy(hdr.head, "ACMP", 4);
hdr.version = MAPVERSION;
hdr.headersize = sizeof(header);
hdr.sfactor = sfactor;
calclight();
resetmap(!copy);