From 247785bca27572eff381e9471997065167675116 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Mar 2018 21:48:33 +0100 Subject: [PATCH] - converted map loader to FileRdr and took the opportunity to clean up its interface. --- src/md5.cpp | 6 +-- src/md5.h | 4 +- src/p_acs.cpp | 4 +- src/p_acs.h | 6 +-- src/p_conversation.cpp | 27 ++++++-------- src/p_conversation.h | 2 +- src/p_glnodes.cpp | 14 +++---- src/p_setup.cpp | 85 ++++++++++++++++++++---------------------- src/p_setup.h | 83 +++++++++++++++++++++++++---------------- src/p_usdf.cpp | 6 +-- src/w_wad.cpp | 16 ++++---- 11 files changed, 131 insertions(+), 122 deletions(-) diff --git a/src/md5.cpp b/src/md5.cpp index d345e00d6..e8257b597 100644 --- a/src/md5.cpp +++ b/src/md5.cpp @@ -95,16 +95,16 @@ void MD5Context::Update(const uint8_t *buf, unsigned len) memcpy(in, buf, len); } -void MD5Context::Update(FileReader *file, unsigned len) +void MD5Context::Update(FileRdr &file, unsigned len) { uint8_t readbuf[8192]; long t; - while (len != 0) + while (len > 0) { t = MIN(len, sizeof(readbuf)); len -= t; - t = file->Read(readbuf, t); + t = (long)file.Read(readbuf, t); Update(readbuf, t); } } diff --git a/src/md5.h b/src/md5.h index a645919db..61714cd34 100644 --- a/src/md5.h +++ b/src/md5.h @@ -18,7 +18,7 @@ #ifndef MD5_H #define MD5_H -class FileReader; +class FileRdr; struct MD5Context { @@ -26,7 +26,7 @@ struct MD5Context void Init(); void Update(const uint8_t *buf, unsigned len); - void Update(FileReader *file, unsigned len); + void Update(FileRdr &file, unsigned len); void Final(uint8_t digest[16]); private: diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 1b6c472d8..8d1f039c3 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -2116,7 +2116,7 @@ void FBehavior::StaticLoadDefaultModules () } } -FBehavior *FBehavior::StaticLoadModule (int lumpnum, FileReader *fr, int len) +FBehavior *FBehavior::StaticLoadModule (int lumpnum, FileRdr *fr, int len) { if (lumpnum == -1 && fr == NULL) return NULL; @@ -2392,7 +2392,7 @@ FBehavior::FBehavior() } -bool FBehavior::Init(int lumpnum, FileReader * fr, int len) +bool FBehavior::Init(int lumpnum, FileRdr * fr, int len) { uint8_t *object; int i; diff --git a/src/p_acs.h b/src/p_acs.h index 7b0d18bd8..80853a523 100644 --- a/src/p_acs.h +++ b/src/p_acs.h @@ -41,7 +41,7 @@ #define NUM_MAPVARS 128 class FFont; -class FileReader; +class FileRdr; struct line_t; @@ -348,7 +348,7 @@ class FBehavior public: FBehavior (); ~FBehavior (); - bool Init(int lumpnum, FileReader * fr = NULL, int len = 0); + bool Init(int lumpnum, FileRdr * fr = NULL, int len = 0); bool IsGood (); uint8_t *FindChunk (uint32_t id) const; @@ -380,7 +380,7 @@ public: BoundsCheckingArray MapVars; - static FBehavior *StaticLoadModule (int lumpnum, FileReader * fr=NULL, int len=0); + static FBehavior *StaticLoadModule (int lumpnum, FileRdr *fr = nullptr, int len=0); static void StaticLoadDefaultModules (); static void StaticUnloadModules (); static bool StaticCheckAllGood (); diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index 5d3a872a4..e177c600b 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -116,9 +116,9 @@ static int ConversationMenuY; static int ConversationPauseTic; static int StaticLastReply; -static bool LoadScriptFile(int lumpnum, FileReader *lump, int numnodes, bool include, int type); -static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpeakerType); -static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, uint32_t &prevSpeakerType); +static bool LoadScriptFile(int lumpnum, FileRdr &lump, int numnodes, bool include, int type); +static FStrifeDialogueNode *ReadRetailNode (FileRdr &lump, uint32_t &prevSpeakerType); +static FStrifeDialogueNode *ReadTeaserNode (FileRdr &lump, uint32_t &prevSpeakerType); static void ParseReplies (FStrifeDialogueReply **replyptr, Response *responses); static bool DrawConversationMenu (); static void PickConversationReply (int replyindex); @@ -190,8 +190,7 @@ void P_LoadStrifeConversations (MapData *map, const char *mapname) P_FreeStrifeConversations (); if (map->Size(ML_CONVERSATION) > 0) { - map->Seek(ML_CONVERSATION); - LoadScriptFile (map->lumpnum, map->file, map->Size(ML_CONVERSATION), false, 0); + LoadScriptFile (map->lumpnum, map->Reader(ML_CONVERSATION), map->Size(ML_CONVERSATION), false, 0); } else { @@ -228,28 +227,26 @@ void P_LoadStrifeConversations (MapData *map, const char *mapname) bool LoadScriptFile (const char *name, bool include, int type) { int lumpnum = Wads.CheckNumForName (name); - FileReader *lump; if (lumpnum < 0) { return false; } - lump = Wads.ReopenLumpNum (lumpnum); + FileRdr lump = Wads.ReopenLumpReader (lumpnum); bool res = LoadScriptFile(lumpnum, lump, Wads.LumpLength(lumpnum), include, type); - delete lump; return res; } -static bool LoadScriptFile(int lumpnum, FileReader *lump, int numnodes, bool include, int type) +static bool LoadScriptFile(int lumpnum, FileRdr &lump, int numnodes, bool include, int type) { int i; uint32_t prevSpeakerType; FStrifeDialogueNode *node; char buffer[4]; - lump->Read(buffer, 4); - lump->Seek(-4, SEEK_CUR); + lump.Read(buffer, 4); + lump.Seek(-4, FileRdr::SeekCur); // The binary format is so primitive that this check is enough to detect it. bool isbinary = (buffer[0] == 0 || buffer[1] == 0 || buffer[2] == 0 || buffer[3] == 0); @@ -318,7 +315,7 @@ static bool LoadScriptFile(int lumpnum, FileReader *lump, int numnodes, bool inc // //============================================================================ -static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpeakerType) +static FStrifeDialogueNode *ReadRetailNode (FileRdr &lump, uint32_t &prevSpeakerType) { FStrifeDialogueNode *node; Speech speech; @@ -328,7 +325,7 @@ static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpea node = new FStrifeDialogueNode; - lump->Read (&speech, sizeof(speech)); + lump.Read (&speech, sizeof(speech)); // Byte swap all the ints in the original data speech.SpeakerType = LittleLong(speech.SpeakerType); @@ -394,7 +391,7 @@ static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpea // //============================================================================ -static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, uint32_t &prevSpeakerType) +static FStrifeDialogueNode *ReadTeaserNode (FileRdr &lump, uint32_t &prevSpeakerType) { FStrifeDialogueNode *node; TeaserSpeech speech; @@ -404,7 +401,7 @@ static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, uint32_t &prevSpea node = new FStrifeDialogueNode; - lump->Read (&speech, sizeof(speech)); + lump.Read (&speech, sizeof(speech)); // Byte swap all the ints in the original data speech.SpeakerType = LittleLong(speech.SpeakerType); diff --git a/src/p_conversation.h b/src/p_conversation.h index 7cabc746c..620b6f4e8 100644 --- a/src/p_conversation.h +++ b/src/p_conversation.h @@ -78,7 +78,7 @@ void P_ResumeConversation (); void P_ConversationCommand (int netcode, int player, uint8_t **stream); class FileReader; -bool P_ParseUSDF(int lumpnum, FileReader *lump, int lumplen); +bool P_ParseUSDF(int lumpnum, FileRdr &lump, int lumplen); #endif diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index 60c666e82..096eaf904 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -75,7 +75,7 @@ void P_GetPolySpots (MapData * lump, TArray &spots, TA CVAR(Bool, gl_cachenodes, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Float, gl_cachetime, 0.6f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -void P_LoadZNodes (FileReader &dalump, uint32_t id); +void P_LoadZNodes (FileRdr &dalump, uint32_t id); static bool CheckCachedNodes(MapData *map); static void CreateCachedNodes(MapData *map); @@ -823,7 +823,7 @@ static int FindGLNodesInFile(FResourceFile * f, const char * label) bool P_LoadGLNodes(MapData * map) { - if (map->MapLumps[ML_GLZNODES].Reader && map->MapLumps[ML_GLZNODES].Reader->GetLength() != 0) + if (map->Size(ML_GLZNODES) != 0) { const int idcheck1a = MAKE_ID('Z','G','L','N'); const int idcheck2a = MAKE_ID('Z','G','L','2'); @@ -833,8 +833,8 @@ bool P_LoadGLNodes(MapData * map) const int idcheck3b = MAKE_ID('X','G','L','3'); int id; - map->Seek(ML_GLZNODES); - map->file->Read (&id, 4); + auto &file = map->Reader(ML_GLZNODES); + file.Read (&id, 4); if (id == idcheck1a || id == idcheck2a || id == idcheck3a || id == idcheck1b || id == idcheck2b || id == idcheck3b) { @@ -843,7 +843,7 @@ bool P_LoadGLNodes(MapData * map) level.subsectors.Clear(); level.segs.Clear(); level.nodes.Clear(); - P_LoadZNodes (*map->file, id); + P_LoadZNodes (file, id); return true; } catch (CRecoverableError &) @@ -1162,9 +1162,9 @@ static bool CheckCachedNodes(MapData *map) uint32_t *verts = NULL; FString path = CreateCacheName(map, false); - FileReader fr; + FileRdr fr; - if (!fr.Open(path)) return false; + if (!fr.OpenFile(path)) return false; if (fr.Read(magic, 4) != 4) goto errorout; if (memcmp(magic, "CACH", 4)) goto errorout; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 1ca249607..ece2e301a 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -281,7 +281,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) { // The following lump is from a different file so whatever this is, // it is not a multi-lump Doom level so let's assume it is a Build map. - map->MapLumps[0].Reader = map->file = Wads.ReopenLumpNum(lump_name); + map->MapLumps[0].Reader = Wads.ReopenLumpReader(lump_name); if (!P_IsBuildMap(map)) { delete map; @@ -292,7 +292,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) // This case can only happen if the lump is inside a real WAD file. // As such any special handling for other types of lumps is skipped. - map->MapLumps[0].Reader = map->file = Wads.ReopenLumpNum(lump_name); + map->MapLumps[0].Reader = Wads.ReopenLumpReader(lump_name); strncpy(map->MapLumps[0].Name, Wads.GetLumpFullName(lump_name), 8); map->Encrypted = Wads.IsEncryptedFile(lump_name); map->InWad = true; @@ -335,14 +335,14 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) // The next lump is not part of this map anymore if (index < 0) break; - map->MapLumps[index].Reader = Wads.ReopenLumpNum(lump_name + i); + map->MapLumps[index].Reader = Wads.ReopenLumpReader(lump_name + i); strncpy(map->MapLumps[index].Name, lumpname, 8); } } else { map->isText = true; - map->MapLumps[1].Reader = Wads.ReopenLumpNum(lump_name + 1); + map->MapLumps[1].Reader = Wads.ReopenLumpReader(lump_name + 1); for(int i = 2;; i++) { const char * lumpname = Wads.GetLumpFullName(lump_name + i); @@ -378,7 +378,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) break; } else continue; - map->MapLumps[index].Reader = Wads.ReopenLumpNum(lump_name + i); + map->MapLumps[index].Reader = Wads.ReopenLumpReader(lump_name + i); strncpy(map->MapLumps[index].Name, lumpname, 8); } } @@ -412,7 +412,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) char maplabel[9]=""; int index=0; - map->MapLumps[0].Reader = map->resource->GetLump(0)->NewReader(); + map->MapLumps[0].Reader = FileRdr(map->resource->GetLump(0)->NewReader()); strncpy(map->MapLumps[0].Name, map->resource->GetLump(0)->Name, 8); for(uint32_t i = 1; i < map->resource->LumpCount(); i++) @@ -422,7 +422,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) if (i == 1 && !strnicmp(lumpname, "TEXTMAP", 8)) { map->isText = true; - map->MapLumps[ML_TEXTMAP].Reader = map->resource->GetLump(i)->NewReader(); + map->MapLumps[ML_TEXTMAP].Reader = FileRdr(map->resource->GetLump(i)->NewReader()); strncpy(map->MapLumps[ML_TEXTMAP].Name, lumpname, 8); for(int i = 2;; i++) { @@ -454,7 +454,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) return map; } else continue; - map->MapLumps[index].Reader = map->resource->GetLump(i)->NewReader(); + map->MapLumps[index].Reader = FileRdr(map->resource->GetLump(i)->NewReader()); strncpy(map->MapLumps[index].Name, lumpname, 8); } } @@ -486,7 +486,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck) maplabel[8]=0; } - map->MapLumps[index].Reader = map->resource->GetLump(i)->NewReader(); + map->MapLumps[index].Reader = FileRdr(map->resource->GetLump(i)->NewReader()); strncpy(map->MapLumps[index].Name, lumpname, 8); } } @@ -526,29 +526,19 @@ void MapData::GetChecksum(uint8_t cksum[16]) if (isText) { - Seek(ML_TEXTMAP); - if (file != NULL) md5.Update(file, Size(ML_TEXTMAP)); + md5.Update(Reader(ML_TEXTMAP), Size(ML_TEXTMAP)); } else { - if (Size(ML_LABEL) != 0) - { - Seek(ML_LABEL); - if (file != NULL) md5.Update(file, Size(ML_LABEL)); - } - Seek(ML_THINGS); - if (file != NULL) md5.Update(file, Size(ML_THINGS)); - Seek(ML_LINEDEFS); - if (file != NULL) md5.Update(file, Size(ML_LINEDEFS)); - Seek(ML_SIDEDEFS); - if (file != NULL) md5.Update(file, Size(ML_SIDEDEFS)); - Seek(ML_SECTORS); - if (file != NULL) md5.Update(file, Size(ML_SECTORS)); + md5.Update(Reader(ML_LABEL), Size(ML_LABEL)); + md5.Update(Reader(ML_THINGS), Size(ML_THINGS)); + md5.Update(Reader(ML_LINEDEFS), Size(ML_LINEDEFS)); + md5.Update(Reader(ML_SIDEDEFS), Size(ML_SIDEDEFS)); + md5.Update(Reader(ML_SECTORS), Size(ML_SECTORS)); } if (HasBehavior) { - Seek(ML_BEHAVIOR); - if (file != NULL) md5.Update(file, Size(ML_BEHAVIOR)); + md5.Update(Reader(ML_BEHAVIOR), Size(ML_BEHAVIOR)); } md5.Final(cksum); } @@ -847,14 +837,14 @@ void P_LoadVertexes (MapData * map) level.vertexes.Alloc(numvertexes); vertexdatas.Clear(); - map->Seek(ML_VERTEXES); + auto &fr = map->Reader(ML_VERTEXES); // Copy and convert vertex coordinates, internal representation as fixed. for (auto &v : level.vertexes) { int16_t x, y; - (*map->file) >> x >> y; + fr >> x >> y; v.set(double(x), double(y)); } } @@ -1104,7 +1094,7 @@ void LoadZNodes(FileReaderBase &data, int glnodes) // //=========================================================================== -void P_LoadZNodes (FileReader &dalump, uint32_t id) +void P_LoadZNodes (FileRdr &dalump, uint32_t id) { int type; bool compressed; @@ -1155,14 +1145,15 @@ void P_LoadZNodes (FileReader &dalump, uint32_t id) return; } + auto daptr = dalump.Reader(); if (compressed) { - FileReaderZ data (dalump); + FileReaderZ data (*daptr); LoadZNodes(data, type); } else { - LoadZNodes(dalump, type); + LoadZNodes(*daptr, type); } } @@ -1398,7 +1389,7 @@ void P_LoadSubsectors (MapData * map) auto &subsectors = level.subsectors; subsectors.Alloc(numsubsectors); - map->Seek(ML_SSECTORS); + auto &fr = map->Reader(ML_SSECTORS); memset (&subsectors[0], 0, numsubsectors*sizeof(subsector_t)); @@ -1406,7 +1397,7 @@ void P_LoadSubsectors (MapData * map) { subsectortype subd; - (*map->file) >> subd.numsegs >> subd.firstseg; + fr >> subd.numsegs >> subd.firstseg; if (subd.numsegs == 0) { @@ -3311,7 +3302,7 @@ void P_LoadReject (MapData * map, bool junk) const int neededsize = (level.sectors.Size() * level.sectors.Size() + 7) >> 3; int rejectsize; - if (strnicmp (map->MapLumps[ML_REJECT].Name, "REJECT", 8) != 0) + if (!map->CheckName(ML_REJECT, "REJECT")) { rejectsize = 0; } @@ -3335,8 +3326,7 @@ void P_LoadReject (MapData * map, bool junk) rejectsize = MIN (rejectsize, neededsize); level.rejectmatrix.Alloc(rejectsize); - map->Seek(ML_REJECT); - map->file->Read (&level.rejectmatrix[0], rejectsize); + map->Read (ML_REJECT, &level.rejectmatrix[0], rejectsize); int qwords = rejectsize / 8; int i; @@ -3375,8 +3365,7 @@ void P_LoadBehavior(MapData * map) { if (map->Size(ML_BEHAVIOR) > 0) { - map->Seek(ML_BEHAVIOR); - FBehavior::StaticLoadModule(-1, map->file, map->Size(ML_BEHAVIOR)); + FBehavior::StaticLoadModule(-1, &map->Reader(ML_BEHAVIOR), map->Size(ML_BEHAVIOR)); } if (!FBehavior::StaticCheckAllGood()) { @@ -3635,8 +3624,10 @@ void P_FreeExtraLevelData() void P_SetupLevel (const char *lumpname, int position) { cycle_t times[20]; +#if 0 FMapThing *buildthings; int numbuildthings; +#endif int i; bool buildmap; const int *oldvertextable = NULL; @@ -3709,16 +3700,18 @@ void P_SetupLevel (const char *lumpname, int position) // [RH] Support loading Build maps (because I felt like it. :-) buildmap = false; +#if 0 + // deactivated because broken. if (map->Size(0) > 0) { uint8_t *mapdata = new uint8_t[map->Size(0)]; - map->Seek(0); - map->file->Read(mapdata, map->Size(0)); + map->Read(0, mapdata); times[0].Clock(); buildmap = P_LoadBuildMap (mapdata, map->Size(0), &buildthings, &numbuildthings); times[0].Unclock(); delete[] mapdata; } +#endif if (!buildmap) { @@ -3858,19 +3851,19 @@ void P_SetupLevel (const char *lumpname, int position) if (!ForceNodeBuild) { // Check for compressed nodes first, then uncompressed nodes - FWadLump test; + FileRdr *fr; uint32_t id = MAKE_ID('X','x','X','x'), idcheck = 0, idcheck2 = 0, idcheck3 = 0, idcheck4 = 0, idcheck5 = 0, idcheck6 = 0; if (map->Size(ML_ZNODES) != 0) { // Test normal nodes first - map->Seek(ML_ZNODES); + fr = &map->Reader(ML_ZNODES); idcheck = MAKE_ID('Z','N','O','D'); idcheck2 = MAKE_ID('X','N','O','D'); } else if (map->Size(ML_GLZNODES) != 0) { - map->Seek(ML_GLZNODES); + fr = &map->Reader(ML_GLZNODES); idcheck = MAKE_ID('Z','G','L','N'); idcheck2 = MAKE_ID('Z','G','L','2'); idcheck3 = MAKE_ID('Z','G','L','3'); @@ -3879,12 +3872,12 @@ void P_SetupLevel (const char *lumpname, int position) idcheck6 = MAKE_ID('X','G','L','3'); } - map->file->Read (&id, 4); + fr->Read (&id, 4); if (id != 0 && (id == idcheck || id == idcheck2 || id == idcheck3 || id == idcheck4 || id == idcheck5 || id == idcheck6)) { try { - P_LoadZNodes (*map->file, id); + P_LoadZNodes (*fr, id); } catch (CRecoverableError &error) { @@ -4067,6 +4060,7 @@ void P_SetupLevel (const char *lumpname, int position) P_TranslateTeleportThings (); // [RH] Assign teleport destination TIDs times[15].Unclock(); } +#if 0 // There is no such thing as a build map. else { for (i = 0; i < numbuildthings; ++i) @@ -4075,6 +4069,7 @@ void P_SetupLevel (const char *lumpname, int position) } delete[] buildthings; } +#endif delete map; if (oldvertextable != NULL) { diff --git a/src/p_setup.h b/src/p_setup.h index dae64160b..0607442e4 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -34,69 +34,86 @@ struct MapData { +private: struct MapLump { - char Name[8]; - FileReader *Reader; + char Name[8] = { 0 }; + FileRdr Reader; } MapLumps[ML_MAX]; - bool HasBehavior; - bool Encrypted; - bool isText; - bool InWad; - int lumpnum; - FileReader * file; - FResourceFile * resource; - - MapData() - { - memset(MapLumps, 0, sizeof(MapLumps)); - file = NULL; - resource = NULL; - lumpnum = -1; - HasBehavior = false; - Encrypted = false; - isText = false; - InWad = false; - } + FileRdr nofile; +public: + bool HasBehavior = false; + bool Encrypted = false; + bool isText = false; + bool InWad = false; + int lumpnum = -1; + FResourceFile * resource = nullptr; ~MapData() { - for (unsigned int i = 0;i < ML_MAX;++i) - delete MapLumps[i].Reader; - - delete resource; - resource = NULL; + if (resource != nullptr) delete resource; + resource = nullptr; } + /* void Seek(unsigned int lumpindex) { if (lumpindexSeek(0, SEEK_SET); + file = &MapLumps[lumpindex].Reader; + file->Seek(0, FileRdr::SeekSet); } } + */ + + FileRdr &Reader(unsigned int lumpindex) + { + if (lumpindex < countof(MapLumps)) + { + auto &file = MapLumps[lumpindex].Reader; + file.Seek(0, FileRdr::SeekSet); + return file; + } + return nofile; + } void Read(unsigned int lumpindex, void * buffer, int size = -1) { if (lumpindexGetLength(); - Seek(lumpindex); - file->Read(buffer, size); + if (size == -1) size = Size(lumpindex); + if (size > 0) + { + auto &file = MapLumps[lumpindex].Reader; + file.Seek(0, FileRdr::SeekSet); + file.Read(buffer, size); + } } } uint32_t Size(unsigned int lumpindex) { - if (lumpindexGetLength(); + return (uint32_t)MapLumps[lumpindex].Reader.GetLength(); } return 0; } + bool CheckName(unsigned int lumpindex, const char *name) + { + if (lumpindex < countof(MapLumps)) + { + return !strnicmp(MapLumps[lumpindex].Name, name, 8); + } + return false; + } + void GetChecksum(uint8_t cksum[16]); + + friend bool P_LoadGLNodes(MapData * map); + friend MapData *P_OpenMapData(const char * mapname, bool justcheck); + }; MapData * P_OpenMapData(const char * mapname, bool justcheck); diff --git a/src/p_usdf.cpp b/src/p_usdf.cpp index 015dd9793..fe0143e94 100644 --- a/src/p_usdf.cpp +++ b/src/p_usdf.cpp @@ -474,10 +474,10 @@ class USDFParser : public UDMFParserBase //=========================================================================== public: - bool Parse(int lumpnum, FileReader *lump, int lumplen) + bool Parse(int lumpnum, FileRdr &lump, int lumplen) { char *buffer = new char[lumplen]; - lump->Read(buffer, lumplen); + lump.Read(buffer, lumplen); sc.OpenMem(Wads.GetLumpFullName(lumpnum), buffer, lumplen); delete [] buffer; sc.SetCMode(true); @@ -532,7 +532,7 @@ public: -bool P_ParseUSDF(int lumpnum, FileReader *lump, int lumplen) +bool P_ParseUSDF(int lumpnum, FileRdr &lump, int lumplen) { USDFParser parse; diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 30b9fdecc..716b7f322 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -309,7 +309,8 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) { MD5Context md5; reader->Seek(0, SEEK_SET); - md5.Update(reader, reader->GetLength()); +#pragma message("This does not work!"); + //md5.Update(FileRdr(reader), reader->GetLength()); md5.Final(cksum); for (size_t j = 0; j < sizeof(cksum); ++j) @@ -329,10 +330,8 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) if (!(lump->Flags & LUMPF_EMBEDDED)) { - reader = lump->NewReader(); - MD5Context md5; - md5.Update(reader, lump->LumpSize); + md5.Update(FileRdr(lump->NewReader()), lump->LumpSize); md5.Final(cksum); for (size_t j = 0; j < sizeof(cksum); ++j) @@ -343,8 +342,6 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) fprintf(hashfile, "file: %s, lump: %s, hash: %s, size: %d\n", filename, lump->FullName.IsNotEmpty() ? lump->FullName.GetChars() : lump->Name, cksumout, lump->LumpSize); - - delete reader; } } } @@ -942,7 +939,8 @@ void FWadCollection::RenameNerve () } fr->Seek(0, SEEK_SET); MD5Context md5; - md5.Update(fr, fr->GetLength()); +#pragma message("This does not work yet!"); + //md5.Update(fr, fr->GetLength()); md5.Final(cksum); if (memcmp(nerve, cksum, 16) == 0) { @@ -1008,7 +1006,9 @@ void FWadCollection::FixMacHexen() uint8_t checksum[16]; MD5Context md5; - md5.Update(reader, iwadSize); + +#pragma message("This does not work yet!"); + //md5.Update(reader, iwadSize); md5.Final(checksum); static const uint8_t HEXEN_DEMO_MD5[16] =