summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/tags.cc
diff options
context:
space:
mode:
authorpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-23 09:42:58 +0000
committerpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-23 09:42:58 +0000
commit7a5387cbd6aa4682c7f2845bde065a9e0b828e23 (patch)
tree995b883e6d67e8c9011bb02133b83ce65dcfa47a /crawl-ref/source/tags.cc
parent922cba628d3d6377574a90c7a817c10d84ed7f85 (diff)
downloadcrawl-ref-7a5387cbd6aa4682c7f2845bde065a9e0b828e23.tar.gz
crawl-ref-7a5387cbd6aa4682c7f2845bde065a9e0b828e23.zip
This was originally going to be a small refactor of stash.cc before
getting into stash/item finding, but it ended up big. Removed the read/writeThing API in favor of the marshall/unmarshallThing API. It was slightly awkward in a couple spots where the format of writeThing and marshallThing differed slightly (strings, level_id, level_pos). Doesn't affect savegames. When it's is okay to break savegames (maybe just before releasing 0.4?) it would be nice to remove the few remaining redundancies listed above. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3828 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/tags.cc')
-rw-r--r--crawl-ref/source/tags.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc
index 35736247de..846b49476e 100644
--- a/crawl-ref/source/tags.cc
+++ b/crawl-ref/source/tags.cc
@@ -145,6 +145,12 @@ void writer::write(const void *data, size_t size)
}
}
+long writer::tell()
+{
+ ASSERT(_file);
+ return ftell(_file);
+}
+
// static helpers
static void tag_construct_you(writer &th);
@@ -329,6 +335,7 @@ static void unmarshall_container(reader &th, T_container &container,
(container.*inserter)(unmarshal(th));
}
+// XXX: redundant with level_id.save()/load()
void marshall_level_id( writer& th, const level_id& id )
{
marshallByte(th, id.branch );
@@ -336,6 +343,7 @@ void marshall_level_id( writer& th, const level_id& id )
marshallByte(th, id.level_type);
}
+// XXX: redundant with level_pos.save()/load()
void marshall_level_pos( writer& th, const level_pos& lpos )
{
marshallLong(th, lpos.pos.x);
@@ -468,7 +476,7 @@ float unmarshallFloat(reader &th)
return k.f_num;
}
-// string -- marshall length & string data
+// string -- 2 byte length, string data
void marshallString(writer &th, const std::string &data, int maxSize)
{
// allow for very long strings (well, up to 32K).
@@ -526,6 +534,19 @@ static std::string unmarshallStringNoMax(reader &th)
return unmarshallString(th);
}
+// string -- 4 byte length, non-terminated string data
+void marshallString4(writer &th, const std::string &data)
+{
+ marshallLong(th, data.length());
+ th.write(data.c_str(), data.length());
+}
+void unmarshallString4(reader &th, std::string& s)
+{
+ const int len = unmarshallLong(th);
+ s.resize(len);
+ if (len) th.read(&s.at(0), len);
+}
+
// boolean (to avoid system-dependant bool implementations)
void marshallBoolean(writer &th, bool data)
{