From 7a5387cbd6aa4682c7f2845bde065a9e0b828e23 Mon Sep 17 00:00:00 2001 From: pauldubois Date: Sun, 23 Mar 2008 09:42:58 +0000 Subject: 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 --- crawl-ref/source/tags.cc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'crawl-ref/source/tags.cc') 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) { -- cgit v1.2.3-54-g00ecf