summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/maps.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/maps.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/maps.cc')
-rw-r--r--crawl-ref/source/maps.cc61
1 files changed, 35 insertions, 26 deletions
diff --git a/crawl-ref/source/maps.cc b/crawl-ref/source/maps.cc
index 05558cecae..7e4b2a95ea 100644
--- a/crawl-ref/source/maps.cc
+++ b/crawl-ref/source/maps.cc
@@ -14,6 +14,7 @@
#include "AppHdr.h"
#include "maps.h"
+#include "tags.h"
#include <cstring>
#include <cstdlib>
@@ -511,12 +512,12 @@ std::string get_descache_path(const std::string &file,
static bool verify_file_version(const std::string &file)
{
- FILE *inf = fopen(file.c_str(), "rb");
- if (!inf)
+ FILE *fp = fopen(file.c_str(), "rb");
+ if (!fp)
return (false);
-
- const long ver = readLong(inf);
- fclose(inf);
+ reader inf(fp);
+ const long ver = unmarshallLong(inf);
+ fclose(fp);
return (ver == MAP_CACHE_VERSION);
}
@@ -534,21 +535,26 @@ static bool verify_map_full(const std::string &base)
static bool load_map_index(const std::string &base)
{
// If there's a global prelude, load that first.
- FILE *inf = fopen((base + ".lux").c_str(), "rb");
- if (inf)
{
- lc_global_prelude.read(inf);
- fclose(inf);
+ FILE *fp = fopen((base + ".lux").c_str(), "rb");
+ if (fp)
+ {
+ reader inf(fp);
+ lc_global_prelude.read(inf);
+ fclose(fp);
- global_preludes.push_back( lc_global_prelude );
+ global_preludes.push_back( lc_global_prelude );
+ }
}
- inf = fopen((base + ".idx").c_str(), "rb");
- if (!inf)
+ FILE* fp = fopen((base + ".idx").c_str(), "rb");
+ if (!fp)
end(1, true, "Unable to read %s", (base + ".idx").c_str());
+ reader inf(fp);
+
// Discard version (it's been checked by verify_map_index).
- readLong(inf);
- const int nmaps = readShort(inf);
+ (void) unmarshallLong(inf);
+ const int nmaps = unmarshallShort(inf);
const int nexist = vdefs.size();
vdefs.resize( nexist + nmaps, map_def() );
for (int i = 0; i < nmaps; ++i)
@@ -559,7 +565,7 @@ static bool load_map_index(const std::string &base)
lc_loaded_maps[vdef.name] = vdef.place_loaded_from;
vdef.place_loaded_from.clear();
}
- fclose(inf);
+ fclose(fp);
return (true);
}
@@ -590,36 +596,39 @@ static void write_map_prelude(const std::string &filebase)
return;
}
- FILE *outf = fopen(luafile.c_str(), "wb");
+ FILE *fp = fopen(luafile.c_str(), "wb");
+ writer outf(fp);
lc_global_prelude.write(outf);
- fclose(outf);
+ fclose(fp);
}
static void write_map_full(const std::string &filebase, size_t vs, size_t ve)
{
const std::string cfile = filebase + ".dsc";
- FILE *outf = fopen(cfile.c_str(), "wb");
- if (!outf)
+ FILE *fp = fopen(cfile.c_str(), "wb");
+ if (!fp)
end(1, true, "Unable to open %s for writing", cfile.c_str());
- writeLong(outf, MAP_CACHE_VERSION);
+ writer outf(fp);
+ marshallLong(outf, MAP_CACHE_VERSION);
for (size_t i = vs; i < ve; ++i)
vdefs[i].write_full(outf);
- fclose(outf);
+ fclose(fp);
}
static void write_map_index(const std::string &filebase, size_t vs, size_t ve)
{
const std::string cfile = filebase + ".idx";
- FILE *outf = fopen(cfile.c_str(), "wb");
- if (!outf)
+ FILE *fp = fopen(cfile.c_str(), "wb");
+ if (!fp)
end(1, true, "Unable to open %s for writing", cfile.c_str());
- writeLong(outf, MAP_CACHE_VERSION);
- writeShort(outf, ve > vs? ve - vs : 0);
+ writer outf(fp);
+ marshallLong(outf, MAP_CACHE_VERSION);
+ marshallShort(outf, ve > vs? ve - vs : 0);
for (size_t i = vs; i < ve; ++i)
vdefs[i].write_index(outf);
- fclose(outf);
+ fclose(fp);
}
static void write_map_cache(const std::string &filename, size_t vs, size_t ve)