From 5e9e9773f748ab17c8298cd212c77bf5ea1b2051 Mon Sep 17 00:00:00 2001 From: Matthew Cline Date: Tue, 10 Nov 2009 02:06:42 -0800 Subject: tags: Store minorVersion in reader class Store the minor version of a savefile being read into the reader class, so that it doesn't need to be passed around as a method/function parameter everywhere. --- crawl-ref/source/files.cc | 14 +++++++------- crawl-ref/source/tags.cc | 9 +++++++-- crawl-ref/source/tags.h | 13 +++++++++---- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index 3bb45a6c55..cd63e9cd15 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -1818,7 +1818,7 @@ void restore_game(void) FILE *stashf = fopen(stashFile.c_str(), "rb"); if (stashf) { - reader inf(stashf); + reader inf(stashf, minorVersion); StashTrack.load(inf); fclose(stashf); } @@ -1832,7 +1832,7 @@ void restore_game(void) FILE *killf = fopen(killFile.c_str(), "rb"); if (killf) { - reader inf(killf); + reader inf(killf, minorVersion); you.kills->load(inf); fclose(killf); } @@ -1841,7 +1841,7 @@ void restore_game(void) FILE *travelf = fopen(travelCacheFile.c_str(), "rb"); if (travelf) { - reader inf(travelf); + reader inf(travelf, minorVersion); travel_cache.load(inf, minorVersion); fclose(travelf); } @@ -1850,7 +1850,7 @@ void restore_game(void) FILE *notesf = fopen(notesFile.c_str(), "rb"); if (notesf) { - reader inf(notesf); + reader inf(notesf, minorVersion); load_notes(inf); fclose(notesf); } @@ -1860,7 +1860,7 @@ void restore_game(void) FILE *tutorf = fopen(tutorFile.c_str(), "rb"); if (tutorf) { - reader inf(tutorf); + reader inf(tutorf, minorVersion); load_tutorial(inf); fclose(tutorf); } @@ -1870,7 +1870,7 @@ void restore_game(void) FILE *msgf = fopen(msgFile.c_str(), "rb"); if (msgf) { - reader inf(msgf); + reader inf(msgf, minorVersion); load_messages(inf); fclose(msgf); } @@ -2065,7 +2065,7 @@ static bool _determine_ghost_version( FILE *ghostFile, majorVersion = buf[0]; minorVersion = buf[1]; - reader inf(ghostFile); + reader inf(ghostFile, minorVersion); // Check for the DCSS ghost signature. if (unmarshallShort(inf) != GHOST_SIGNATURE) return (false); diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc index 9dbe2fced8..421593bc5c 100644 --- a/crawl-ref/source/tags.cc +++ b/crawl-ref/source/tags.cc @@ -134,6 +134,11 @@ void reader::read(void *data, size_t size) } } +char reader::getMinorVersion() +{ + return _minorVersion; +} + void writer::writeByte(unsigned char ch) { if (_file) @@ -703,7 +708,7 @@ tag_type tag_read(FILE *fp, char minorVersion) short tag_id; std::vector buf; { - reader tmp(fp); + reader tmp(fp, minorVersion); tag_id = unmarshallShort(tmp); if (tag_id < 0) return TAG_NO_TAG; @@ -720,7 +725,7 @@ tag_type tag_read(FILE *fp, char minorVersion) unwind_var tag_minor_version(_tag_minor_version, minorVersion); // Ok, we have data now. - reader th(buf); + reader th(buf, minorVersion); switch (tag_id) { case TAG_YOU: tag_read_you(th, minorVersion); break; diff --git a/crawl-ref/source/tags.h b/crawl-ref/source/tags.h index ce2ec65a68..c85796bef9 100644 --- a/crawl-ref/source/tags.h +++ b/crawl-ref/source/tags.h @@ -103,18 +103,23 @@ void marshallShowtype (writer &, const show_type &); class reader { public: - reader(FILE* input) - : _file(input), _pbuf(0), _read_offset(0) {} - reader(const std::vector& input) - : _file(0), _pbuf(&input), _read_offset(0) {} + reader(FILE* input, char minorVersion = TAG_MINOR_VERSION) + : _file(input), _pbuf(0), _read_offset(0), + _minorVersion(minorVersion) {} + reader(const std::vector& input, + char minorVersion = TAG_MINOR_VERSION) + : _file(0), _pbuf(&input), _read_offset(0), + _minorVersion(minorVersion) {} unsigned char readByte(); void read(void *data, size_t size); + char getMinorVersion(); private: FILE* _file; const std::vector* _pbuf; unsigned int _read_offset; + char _minorVersion; }; char unmarshallByte (reader &); -- cgit v1.2.3-54-g00ecf