summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/files.cc
diff options
context:
space:
mode:
authorpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-17 05:54:42 +0000
committerpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-17 05:54:42 +0000
commit8ba172496400cc74a2fa7d343d9859339f1a0f5d (patch)
tree09715fca1c835aca87d0da9d629ad5f9e0157e54 /crawl-ref/source/files.cc
parent314a2c0efb7083bc9703b6e2f6ee4e054d000cc1 (diff)
downloadcrawl-ref-8ba172496400cc74a2fa7d343d9859339f1a0f5d.tar.gz
crawl-ref-8ba172496400cc74a2fa7d343d9859339f1a0f5d.zip
Cleanup/refactoring of tags.cc. No functional changes. I've been
running with and without this patch applied for about a week, and none of my saves have broken, so I'm ready to commit it. - Tag system no longer uses one big (shared!) global buffer. This was the original impetus behind the change... - Change every use of tagHeader into reader or writer (touches a lot). - Split tagHeader into two classes: reader and writer. Turns out every place that used tagHeader only cared about reading or writing and not about tags at all. There was nothing left in tagHeader, so it disappeared along with a bunch of grotty special-case code. - Not done: merge the files.cc read/writeThing code with the tags.cc marshall/unmarshallThing code. This patch is big enough already. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3685 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/files.cc')
-rw-r--r--crawl-ref/source/files.cc29
1 files changed, 10 insertions, 19 deletions
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index a1572e51cd..ec3ec235aa 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -619,12 +619,10 @@ static void write_version( FILE *dataFile, int majorVersion, int minorVersion,
bool extended_version )
{
// write version
- tagHeader versionTag;
- versionTag.offset = 0;
- versionTag.tagID = TAG_VERSION;
+ writer outf(dataFile);
- marshallByte(versionTag, majorVersion);
- marshallByte(versionTag, minorVersion);
+ marshallByte(outf, majorVersion);
+ marshallByte(outf, minorVersion);
// extended_version just pads the version out to four 32-bit words.
// This makes the bones file compatible with Hearse with no extra
@@ -637,22 +635,18 @@ static void write_version( FILE *dataFile, int majorVersion, int minorVersion,
// hearse.pl. Crawl-aware hearse.pl will prefix the bones file
// with the first 16-bits of the Crawl version, and the following
// 7 16-bit words set to 0.
- marshallShort(versionTag, GHOST_SIGNATURE);
+ marshallShort(outf, GHOST_SIGNATURE);
// Write the three remaining 32-bit words of padding.
for (int i = 0; i < 3; ++i)
- marshallLong(versionTag, 0);
+ marshallLong(outf, 0);
}
-
- tag_write(versionTag, dataFile);
}
static void write_tagged_file( FILE *dataFile, char majorVersion,
char minorVersion, int fileType,
bool extended_version = false )
{
- struct tagHeader th;
-
// find all relevant tags
char tags[NUM_TAGS];
tag_set_expected(tags, fileType);
@@ -664,8 +658,7 @@ static void write_tagged_file( FILE *dataFile, char majorVersion,
{
if (tags[i] == 1)
{
- tag_construct(th, i);
- tag_write(th, dataFile);
+ tag_write((tag_type)i, dataFile);
}
}
}
@@ -1575,23 +1568,21 @@ static void restore_version( FILE *restoreFile,
static void restore_tagged_file( FILE *restoreFile, int fileType,
char minorVersion )
{
- int i;
-
char tags[NUM_TAGS];
tag_set_expected(tags, fileType);
while(1)
{
- i = tag_read(restoreFile, minorVersion);
- if (i == 0) // no tag!
+ tag_type tt = tag_read(restoreFile, minorVersion);
+ if (tt == TAG_NO_TAG)
break;
- tags[i] = 0; // tag read
+ tags[tt] = 0; // tag read
if (fileType == TAGTYPE_PLAYER_NAME)
break;
}
// go through and init missing tags
- for(i=0; i<NUM_TAGS; i++)
+ for (int i=0; i<NUM_TAGS; i++)
{
if (tags[i] == 1) // expected but never read
tag_missing(i, minorVersion);