summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/maps.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2013-02-24 06:00:44 +0100
committerAdam Borowski <kilobyte@angband.pl>2013-02-24 06:01:51 +0100
commit78bee588c59502f03ad122a52a5be3958e35db5c (patch)
tree29d2bef3568078ba368bbc37535cba1204709d25 /crawl-ref/source/maps.cc
parente5b0a8015cd648100a4bba001816c07181e4944b (diff)
downloadcrawl-ref-78bee588c59502f03ad122a52a5be3958e35db5c.tar.gz
crawl-ref-78bee588c59502f03ad122a52a5be3958e35db5c.zip
Tag the des cache with endianness and word width.
Lua stored inside is not portable between architectures. One could allow separate caches in case someone shares $HOME between systems of different architecture and switches them often, but I don't think I care that much. In the worst case, you'll get cache rebuilds. A wee bit better than crash on start until you "rm -rf ~/.crawl/saves/des".
Diffstat (limited to 'crawl-ref/source/maps.cc')
-rw-r--r--crawl-ref/source/maps.cc36
1 files changed, 23 insertions, 13 deletions
diff --git a/crawl-ref/source/maps.cc b/crawl-ref/source/maps.cc
index a2f6df14cf..d1741f0872 100644
--- a/crawl-ref/source/maps.cc
+++ b/crawl-ref/source/maps.cc
@@ -36,6 +36,12 @@
#include "tags.h"
#include "terrain.h"
+#if BYTE_ORDER == LITTLE_ENDIAN
+# define WORD_LEN sizeof(long)
+#else
+# define WORD_LEN -sizeof(long)
+#endif
+
static map_section_type _write_vault(map_def &mdef,
vault_placement &,
bool check_place);
@@ -1180,13 +1186,12 @@ static bool verify_file_version(const string &file, time_t mtime)
reader inf(fp);
const uint8_t major = unmarshallUByte(inf);
const uint8_t minor = unmarshallUByte(inf);
+ const int8_t word = unmarshallByte(inf);
const int64_t t = unmarshallSigned(inf);
fclose(fp);
return (major == TAG_MAJOR_VERSION
&& minor <= TAG_MINOR_VERSION
-#if TAG_MAJOR_VERSION == 34
- && minor >= TAG_MINOR_0_12
-#endif
+ && word == WORD_LEN
&& t == mtime);
}
catch (short_read_exception &E)
@@ -1217,13 +1222,14 @@ static bool _load_map_index(const string& cache, const string &base,
reader inf(fp, TAG_MINOR_VERSION);
uint8_t major = unmarshallUByte(inf);
uint8_t minor = unmarshallUByte(inf);
+ int8_t word = unmarshallByte(inf);
int64_t t = unmarshallSigned(inf);
- if (major != TAG_MAJOR_VERSION || minor > TAG_MINOR_VERSION || t != mtime)
- return false;
-#if TAG_MAJOR_VERSION == 34
- if (minor < TAG_MINOR_0_12)
+ if (major != TAG_MAJOR_VERSION || minor > TAG_MINOR_VERSION
+ || word != WORD_LEN || t != mtime)
+ {
return false;
-#endif
+ }
+
lc_global_prelude.read(inf);
fclose(fp);
@@ -1239,13 +1245,14 @@ static bool _load_map_index(const string& cache, const string &base,
// Re-check version, might have been modified in the meantime.
uint8_t major = unmarshallUByte(inf);
uint8_t minor = unmarshallUByte(inf);
+ int8_t word = unmarshallByte(inf);
int64_t t = unmarshallSigned(inf);
- if (major != TAG_MAJOR_VERSION || minor > TAG_MINOR_VERSION || t != mtime)
- return false;
-#if TAG_MAJOR_VERSION == 34
- if (minor < TAG_MINOR_0_12)
+ if (major != TAG_MAJOR_VERSION || minor > TAG_MINOR_VERSION
+ || word != WORD_LEN || t != mtime)
+ {
return false;
-#endif
+ }
+
const int nmaps = unmarshallShort(inf);
const int nexist = vdefs.size();
vdefs.resize(nexist + nmaps, map_def());
@@ -1298,6 +1305,7 @@ static void _write_map_prelude(const string &filebase, time_t mtime)
writer outf(luafile, fp);
marshallUByte(outf, TAG_MAJOR_VERSION);
marshallUByte(outf, TAG_MINOR_VERSION);
+ marshallByte(outf, WORD_LEN);
marshallSigned(outf, mtime);
lc_global_prelude.write(outf);
fclose(fp);
@@ -1314,6 +1322,7 @@ static void _write_map_full(const string &filebase, size_t vs, size_t ve,
writer outf(cfile, fp);
marshallUByte(outf, TAG_MAJOR_VERSION);
marshallUByte(outf, TAG_MINOR_VERSION);
+ marshallByte(outf, WORD_LEN);
marshallSigned(outf, mtime);
for (size_t i = vs; i < ve; ++i)
vdefs[i].write_full(outf);
@@ -1331,6 +1340,7 @@ static void _write_map_index(const string &filebase, size_t vs, size_t ve,
writer outf(cfile, fp);
marshallUByte(outf, TAG_MAJOR_VERSION);
marshallUByte(outf, TAG_MINOR_VERSION);
+ marshallByte(outf, WORD_LEN);
marshallSigned(outf, mtime);
marshallShort(outf, ve > vs? ve - vs : 0);
for (size_t i = vs; i < ve; ++i)