mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 23:02:08 +00:00
- converted map loader to FileRdr and took the opportunity to clean up its interface.
This commit is contained in:
parent
6f8ca2eace
commit
247785bca2
11 changed files with 131 additions and 122 deletions
|
@ -95,16 +95,16 @@ void MD5Context::Update(const uint8_t *buf, unsigned len)
|
||||||
memcpy(in, buf, len);
|
memcpy(in, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MD5Context::Update(FileReader *file, unsigned len)
|
void MD5Context::Update(FileRdr &file, unsigned len)
|
||||||
{
|
{
|
||||||
uint8_t readbuf[8192];
|
uint8_t readbuf[8192];
|
||||||
long t;
|
long t;
|
||||||
|
|
||||||
while (len != 0)
|
while (len > 0)
|
||||||
{
|
{
|
||||||
t = MIN<long>(len, sizeof(readbuf));
|
t = MIN<long>(len, sizeof(readbuf));
|
||||||
len -= t;
|
len -= t;
|
||||||
t = file->Read(readbuf, t);
|
t = (long)file.Read(readbuf, t);
|
||||||
Update(readbuf, t);
|
Update(readbuf, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#ifndef MD5_H
|
#ifndef MD5_H
|
||||||
#define MD5_H
|
#define MD5_H
|
||||||
|
|
||||||
class FileReader;
|
class FileRdr;
|
||||||
|
|
||||||
struct MD5Context
|
struct MD5Context
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,7 @@ struct MD5Context
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void Update(const uint8_t *buf, unsigned len);
|
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]);
|
void Final(uint8_t digest[16]);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -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;
|
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;
|
uint8_t *object;
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#define NUM_MAPVARS 128
|
#define NUM_MAPVARS 128
|
||||||
|
|
||||||
class FFont;
|
class FFont;
|
||||||
class FileReader;
|
class FileRdr;
|
||||||
struct line_t;
|
struct line_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ class FBehavior
|
||||||
public:
|
public:
|
||||||
FBehavior ();
|
FBehavior ();
|
||||||
~FBehavior ();
|
~FBehavior ();
|
||||||
bool Init(int lumpnum, FileReader * fr = NULL, int len = 0);
|
bool Init(int lumpnum, FileRdr * fr = NULL, int len = 0);
|
||||||
|
|
||||||
bool IsGood ();
|
bool IsGood ();
|
||||||
uint8_t *FindChunk (uint32_t id) const;
|
uint8_t *FindChunk (uint32_t id) const;
|
||||||
|
@ -380,7 +380,7 @@ public:
|
||||||
|
|
||||||
BoundsCheckingArray<int32_t *, NUM_MAPVARS> MapVars;
|
BoundsCheckingArray<int32_t *, NUM_MAPVARS> 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 StaticLoadDefaultModules ();
|
||||||
static void StaticUnloadModules ();
|
static void StaticUnloadModules ();
|
||||||
static bool StaticCheckAllGood ();
|
static bool StaticCheckAllGood ();
|
||||||
|
|
|
@ -116,9 +116,9 @@ static int ConversationMenuY;
|
||||||
static int ConversationPauseTic;
|
static int ConversationPauseTic;
|
||||||
static int StaticLastReply;
|
static int StaticLastReply;
|
||||||
|
|
||||||
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);
|
||||||
static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpeakerType);
|
static FStrifeDialogueNode *ReadRetailNode (FileRdr &lump, uint32_t &prevSpeakerType);
|
||||||
static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, uint32_t &prevSpeakerType);
|
static FStrifeDialogueNode *ReadTeaserNode (FileRdr &lump, uint32_t &prevSpeakerType);
|
||||||
static void ParseReplies (FStrifeDialogueReply **replyptr, Response *responses);
|
static void ParseReplies (FStrifeDialogueReply **replyptr, Response *responses);
|
||||||
static bool DrawConversationMenu ();
|
static bool DrawConversationMenu ();
|
||||||
static void PickConversationReply (int replyindex);
|
static void PickConversationReply (int replyindex);
|
||||||
|
@ -190,8 +190,7 @@ void P_LoadStrifeConversations (MapData *map, const char *mapname)
|
||||||
P_FreeStrifeConversations ();
|
P_FreeStrifeConversations ();
|
||||||
if (map->Size(ML_CONVERSATION) > 0)
|
if (map->Size(ML_CONVERSATION) > 0)
|
||||||
{
|
{
|
||||||
map->Seek(ML_CONVERSATION);
|
LoadScriptFile (map->lumpnum, map->Reader(ML_CONVERSATION), map->Size(ML_CONVERSATION), false, 0);
|
||||||
LoadScriptFile (map->lumpnum, map->file, map->Size(ML_CONVERSATION), false, 0);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -228,28 +227,26 @@ void P_LoadStrifeConversations (MapData *map, const char *mapname)
|
||||||
bool LoadScriptFile (const char *name, bool include, int type)
|
bool LoadScriptFile (const char *name, bool include, int type)
|
||||||
{
|
{
|
||||||
int lumpnum = Wads.CheckNumForName (name);
|
int lumpnum = Wads.CheckNumForName (name);
|
||||||
FileReader *lump;
|
|
||||||
|
|
||||||
if (lumpnum < 0)
|
if (lumpnum < 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
lump = Wads.ReopenLumpNum (lumpnum);
|
FileRdr lump = Wads.ReopenLumpReader (lumpnum);
|
||||||
|
|
||||||
bool res = LoadScriptFile(lumpnum, lump, Wads.LumpLength(lumpnum), include, type);
|
bool res = LoadScriptFile(lumpnum, lump, Wads.LumpLength(lumpnum), include, type);
|
||||||
delete lump;
|
|
||||||
return res;
|
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;
|
int i;
|
||||||
uint32_t prevSpeakerType;
|
uint32_t prevSpeakerType;
|
||||||
FStrifeDialogueNode *node;
|
FStrifeDialogueNode *node;
|
||||||
char buffer[4];
|
char buffer[4];
|
||||||
|
|
||||||
lump->Read(buffer, 4);
|
lump.Read(buffer, 4);
|
||||||
lump->Seek(-4, SEEK_CUR);
|
lump.Seek(-4, FileRdr::SeekCur);
|
||||||
|
|
||||||
// The binary format is so primitive that this check is enough to detect it.
|
// 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);
|
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;
|
FStrifeDialogueNode *node;
|
||||||
Speech speech;
|
Speech speech;
|
||||||
|
@ -328,7 +325,7 @@ static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpea
|
||||||
|
|
||||||
node = new FStrifeDialogueNode;
|
node = new FStrifeDialogueNode;
|
||||||
|
|
||||||
lump->Read (&speech, sizeof(speech));
|
lump.Read (&speech, sizeof(speech));
|
||||||
|
|
||||||
// Byte swap all the ints in the original data
|
// Byte swap all the ints in the original data
|
||||||
speech.SpeakerType = LittleLong(speech.SpeakerType);
|
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;
|
FStrifeDialogueNode *node;
|
||||||
TeaserSpeech speech;
|
TeaserSpeech speech;
|
||||||
|
@ -404,7 +401,7 @@ static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, uint32_t &prevSpea
|
||||||
|
|
||||||
node = new FStrifeDialogueNode;
|
node = new FStrifeDialogueNode;
|
||||||
|
|
||||||
lump->Read (&speech, sizeof(speech));
|
lump.Read (&speech, sizeof(speech));
|
||||||
|
|
||||||
// Byte swap all the ints in the original data
|
// Byte swap all the ints in the original data
|
||||||
speech.SpeakerType = LittleLong(speech.SpeakerType);
|
speech.SpeakerType = LittleLong(speech.SpeakerType);
|
||||||
|
|
|
@ -78,7 +78,7 @@ void P_ResumeConversation ();
|
||||||
void P_ConversationCommand (int netcode, int player, uint8_t **stream);
|
void P_ConversationCommand (int netcode, int player, uint8_t **stream);
|
||||||
|
|
||||||
class FileReader;
|
class FileReader;
|
||||||
bool P_ParseUSDF(int lumpnum, FileReader *lump, int lumplen);
|
bool P_ParseUSDF(int lumpnum, FileRdr &lump, int lumplen);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -75,7 +75,7 @@ void P_GetPolySpots (MapData * lump, TArray<FNodeBuilder::FPolyStart> &spots, TA
|
||||||
CVAR(Bool, gl_cachenodes, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
CVAR(Bool, gl_cachenodes, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||||
CVAR(Float, gl_cachetime, 0.6f, 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 bool CheckCachedNodes(MapData *map);
|
||||||
static void CreateCachedNodes(MapData *map);
|
static void CreateCachedNodes(MapData *map);
|
||||||
|
|
||||||
|
@ -823,7 +823,7 @@ static int FindGLNodesInFile(FResourceFile * f, const char * label)
|
||||||
|
|
||||||
bool P_LoadGLNodes(MapData * map)
|
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 idcheck1a = MAKE_ID('Z','G','L','N');
|
||||||
const int idcheck2a = MAKE_ID('Z','G','L','2');
|
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');
|
const int idcheck3b = MAKE_ID('X','G','L','3');
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
map->Seek(ML_GLZNODES);
|
auto &file = map->Reader(ML_GLZNODES);
|
||||||
map->file->Read (&id, 4);
|
file.Read (&id, 4);
|
||||||
if (id == idcheck1a || id == idcheck2a || id == idcheck3a ||
|
if (id == idcheck1a || id == idcheck2a || id == idcheck3a ||
|
||||||
id == idcheck1b || id == idcheck2b || id == idcheck3b)
|
id == idcheck1b || id == idcheck2b || id == idcheck3b)
|
||||||
{
|
{
|
||||||
|
@ -843,7 +843,7 @@ bool P_LoadGLNodes(MapData * map)
|
||||||
level.subsectors.Clear();
|
level.subsectors.Clear();
|
||||||
level.segs.Clear();
|
level.segs.Clear();
|
||||||
level.nodes.Clear();
|
level.nodes.Clear();
|
||||||
P_LoadZNodes (*map->file, id);
|
P_LoadZNodes (file, id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (CRecoverableError &)
|
catch (CRecoverableError &)
|
||||||
|
@ -1162,9 +1162,9 @@ static bool CheckCachedNodes(MapData *map)
|
||||||
uint32_t *verts = NULL;
|
uint32_t *verts = NULL;
|
||||||
|
|
||||||
FString path = CreateCacheName(map, false);
|
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 (fr.Read(magic, 4) != 4) goto errorout;
|
||||||
if (memcmp(magic, "CACH", 4)) goto errorout;
|
if (memcmp(magic, "CACH", 4)) goto errorout;
|
||||||
|
|
|
@ -281,7 +281,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck)
|
||||||
{
|
{
|
||||||
// The following lump is from a different file so whatever this is,
|
// 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.
|
// 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))
|
if (!P_IsBuildMap(map))
|
||||||
{
|
{
|
||||||
delete 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.
|
// 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.
|
// 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);
|
strncpy(map->MapLumps[0].Name, Wads.GetLumpFullName(lump_name), 8);
|
||||||
map->Encrypted = Wads.IsEncryptedFile(lump_name);
|
map->Encrypted = Wads.IsEncryptedFile(lump_name);
|
||||||
map->InWad = true;
|
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
|
// The next lump is not part of this map anymore
|
||||||
if (index < 0) break;
|
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);
|
strncpy(map->MapLumps[index].Name, lumpname, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
map->isText = true;
|
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++)
|
for(int i = 2;; i++)
|
||||||
{
|
{
|
||||||
const char * lumpname = Wads.GetLumpFullName(lump_name + i);
|
const char * lumpname = Wads.GetLumpFullName(lump_name + i);
|
||||||
|
@ -378,7 +378,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else continue;
|
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);
|
strncpy(map->MapLumps[index].Name, lumpname, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,7 +412,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck)
|
||||||
char maplabel[9]="";
|
char maplabel[9]="";
|
||||||
int index=0;
|
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);
|
strncpy(map->MapLumps[0].Name, map->resource->GetLump(0)->Name, 8);
|
||||||
|
|
||||||
for(uint32_t i = 1; i < map->resource->LumpCount(); i++)
|
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))
|
if (i == 1 && !strnicmp(lumpname, "TEXTMAP", 8))
|
||||||
{
|
{
|
||||||
map->isText = true;
|
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);
|
strncpy(map->MapLumps[ML_TEXTMAP].Name, lumpname, 8);
|
||||||
for(int i = 2;; i++)
|
for(int i = 2;; i++)
|
||||||
{
|
{
|
||||||
|
@ -454,7 +454,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck)
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
else continue;
|
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);
|
strncpy(map->MapLumps[index].Name, lumpname, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -486,7 +486,7 @@ MapData *P_OpenMapData(const char * mapname, bool justcheck)
|
||||||
maplabel[8]=0;
|
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);
|
strncpy(map->MapLumps[index].Name, lumpname, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -526,29 +526,19 @@ void MapData::GetChecksum(uint8_t cksum[16])
|
||||||
|
|
||||||
if (isText)
|
if (isText)
|
||||||
{
|
{
|
||||||
Seek(ML_TEXTMAP);
|
md5.Update(Reader(ML_TEXTMAP), Size(ML_TEXTMAP));
|
||||||
if (file != NULL) md5.Update(file, Size(ML_TEXTMAP));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Size(ML_LABEL) != 0)
|
md5.Update(Reader(ML_LABEL), Size(ML_LABEL));
|
||||||
{
|
md5.Update(Reader(ML_THINGS), Size(ML_THINGS));
|
||||||
Seek(ML_LABEL);
|
md5.Update(Reader(ML_LINEDEFS), Size(ML_LINEDEFS));
|
||||||
if (file != NULL) md5.Update(file, Size(ML_LABEL));
|
md5.Update(Reader(ML_SIDEDEFS), Size(ML_SIDEDEFS));
|
||||||
}
|
md5.Update(Reader(ML_SECTORS), Size(ML_SECTORS));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
if (HasBehavior)
|
if (HasBehavior)
|
||||||
{
|
{
|
||||||
Seek(ML_BEHAVIOR);
|
md5.Update(Reader(ML_BEHAVIOR), Size(ML_BEHAVIOR));
|
||||||
if (file != NULL) md5.Update(file, Size(ML_BEHAVIOR));
|
|
||||||
}
|
}
|
||||||
md5.Final(cksum);
|
md5.Final(cksum);
|
||||||
}
|
}
|
||||||
|
@ -847,14 +837,14 @@ void P_LoadVertexes (MapData * map)
|
||||||
level.vertexes.Alloc(numvertexes);
|
level.vertexes.Alloc(numvertexes);
|
||||||
vertexdatas.Clear();
|
vertexdatas.Clear();
|
||||||
|
|
||||||
map->Seek(ML_VERTEXES);
|
auto &fr = map->Reader(ML_VERTEXES);
|
||||||
|
|
||||||
// Copy and convert vertex coordinates, internal representation as fixed.
|
// Copy and convert vertex coordinates, internal representation as fixed.
|
||||||
for (auto &v : level.vertexes)
|
for (auto &v : level.vertexes)
|
||||||
{
|
{
|
||||||
int16_t x, y;
|
int16_t x, y;
|
||||||
|
|
||||||
(*map->file) >> x >> y;
|
fr >> x >> y;
|
||||||
v.set(double(x), double(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;
|
int type;
|
||||||
bool compressed;
|
bool compressed;
|
||||||
|
@ -1155,14 +1145,15 @@ void P_LoadZNodes (FileReader &dalump, uint32_t id)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto daptr = dalump.Reader();
|
||||||
if (compressed)
|
if (compressed)
|
||||||
{
|
{
|
||||||
FileReaderZ data (dalump);
|
FileReaderZ data (*daptr);
|
||||||
LoadZNodes(data, type);
|
LoadZNodes(data, type);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LoadZNodes(dalump, type);
|
LoadZNodes(*daptr, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1398,7 +1389,7 @@ void P_LoadSubsectors (MapData * map)
|
||||||
|
|
||||||
auto &subsectors = level.subsectors;
|
auto &subsectors = level.subsectors;
|
||||||
subsectors.Alloc(numsubsectors);
|
subsectors.Alloc(numsubsectors);
|
||||||
map->Seek(ML_SSECTORS);
|
auto &fr = map->Reader(ML_SSECTORS);
|
||||||
|
|
||||||
memset (&subsectors[0], 0, numsubsectors*sizeof(subsector_t));
|
memset (&subsectors[0], 0, numsubsectors*sizeof(subsector_t));
|
||||||
|
|
||||||
|
@ -1406,7 +1397,7 @@ void P_LoadSubsectors (MapData * map)
|
||||||
{
|
{
|
||||||
subsectortype subd;
|
subsectortype subd;
|
||||||
|
|
||||||
(*map->file) >> subd.numsegs >> subd.firstseg;
|
fr >> subd.numsegs >> subd.firstseg;
|
||||||
|
|
||||||
if (subd.numsegs == 0)
|
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;
|
const int neededsize = (level.sectors.Size() * level.sectors.Size() + 7) >> 3;
|
||||||
int rejectsize;
|
int rejectsize;
|
||||||
|
|
||||||
if (strnicmp (map->MapLumps[ML_REJECT].Name, "REJECT", 8) != 0)
|
if (!map->CheckName(ML_REJECT, "REJECT"))
|
||||||
{
|
{
|
||||||
rejectsize = 0;
|
rejectsize = 0;
|
||||||
}
|
}
|
||||||
|
@ -3335,8 +3326,7 @@ void P_LoadReject (MapData * map, bool junk)
|
||||||
rejectsize = MIN (rejectsize, neededsize);
|
rejectsize = MIN (rejectsize, neededsize);
|
||||||
level.rejectmatrix.Alloc(rejectsize);
|
level.rejectmatrix.Alloc(rejectsize);
|
||||||
|
|
||||||
map->Seek(ML_REJECT);
|
map->Read (ML_REJECT, &level.rejectmatrix[0], rejectsize);
|
||||||
map->file->Read (&level.rejectmatrix[0], rejectsize);
|
|
||||||
|
|
||||||
int qwords = rejectsize / 8;
|
int qwords = rejectsize / 8;
|
||||||
int i;
|
int i;
|
||||||
|
@ -3375,8 +3365,7 @@ void P_LoadBehavior(MapData * map)
|
||||||
{
|
{
|
||||||
if (map->Size(ML_BEHAVIOR) > 0)
|
if (map->Size(ML_BEHAVIOR) > 0)
|
||||||
{
|
{
|
||||||
map->Seek(ML_BEHAVIOR);
|
FBehavior::StaticLoadModule(-1, &map->Reader(ML_BEHAVIOR), map->Size(ML_BEHAVIOR));
|
||||||
FBehavior::StaticLoadModule(-1, map->file, map->Size(ML_BEHAVIOR));
|
|
||||||
}
|
}
|
||||||
if (!FBehavior::StaticCheckAllGood())
|
if (!FBehavior::StaticCheckAllGood())
|
||||||
{
|
{
|
||||||
|
@ -3635,8 +3624,10 @@ void P_FreeExtraLevelData()
|
||||||
void P_SetupLevel (const char *lumpname, int position)
|
void P_SetupLevel (const char *lumpname, int position)
|
||||||
{
|
{
|
||||||
cycle_t times[20];
|
cycle_t times[20];
|
||||||
|
#if 0
|
||||||
FMapThing *buildthings;
|
FMapThing *buildthings;
|
||||||
int numbuildthings;
|
int numbuildthings;
|
||||||
|
#endif
|
||||||
int i;
|
int i;
|
||||||
bool buildmap;
|
bool buildmap;
|
||||||
const int *oldvertextable = NULL;
|
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. :-)
|
// [RH] Support loading Build maps (because I felt like it. :-)
|
||||||
buildmap = false;
|
buildmap = false;
|
||||||
|
#if 0
|
||||||
|
// deactivated because broken.
|
||||||
if (map->Size(0) > 0)
|
if (map->Size(0) > 0)
|
||||||
{
|
{
|
||||||
uint8_t *mapdata = new uint8_t[map->Size(0)];
|
uint8_t *mapdata = new uint8_t[map->Size(0)];
|
||||||
map->Seek(0);
|
map->Read(0, mapdata);
|
||||||
map->file->Read(mapdata, map->Size(0));
|
|
||||||
times[0].Clock();
|
times[0].Clock();
|
||||||
buildmap = P_LoadBuildMap (mapdata, map->Size(0), &buildthings, &numbuildthings);
|
buildmap = P_LoadBuildMap (mapdata, map->Size(0), &buildthings, &numbuildthings);
|
||||||
times[0].Unclock();
|
times[0].Unclock();
|
||||||
delete[] mapdata;
|
delete[] mapdata;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!buildmap)
|
if (!buildmap)
|
||||||
{
|
{
|
||||||
|
@ -3858,19 +3851,19 @@ void P_SetupLevel (const char *lumpname, int position)
|
||||||
if (!ForceNodeBuild)
|
if (!ForceNodeBuild)
|
||||||
{
|
{
|
||||||
// Check for compressed nodes first, then uncompressed nodes
|
// 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;
|
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)
|
if (map->Size(ML_ZNODES) != 0)
|
||||||
{
|
{
|
||||||
// Test normal nodes first
|
// Test normal nodes first
|
||||||
map->Seek(ML_ZNODES);
|
fr = &map->Reader(ML_ZNODES);
|
||||||
idcheck = MAKE_ID('Z','N','O','D');
|
idcheck = MAKE_ID('Z','N','O','D');
|
||||||
idcheck2 = MAKE_ID('X','N','O','D');
|
idcheck2 = MAKE_ID('X','N','O','D');
|
||||||
}
|
}
|
||||||
else if (map->Size(ML_GLZNODES) != 0)
|
else if (map->Size(ML_GLZNODES) != 0)
|
||||||
{
|
{
|
||||||
map->Seek(ML_GLZNODES);
|
fr = &map->Reader(ML_GLZNODES);
|
||||||
idcheck = MAKE_ID('Z','G','L','N');
|
idcheck = MAKE_ID('Z','G','L','N');
|
||||||
idcheck2 = MAKE_ID('Z','G','L','2');
|
idcheck2 = MAKE_ID('Z','G','L','2');
|
||||||
idcheck3 = MAKE_ID('Z','G','L','3');
|
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');
|
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))
|
if (id != 0 && (id == idcheck || id == idcheck2 || id == idcheck3 || id == idcheck4 || id == idcheck5 || id == idcheck6))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
P_LoadZNodes (*map->file, id);
|
P_LoadZNodes (*fr, id);
|
||||||
}
|
}
|
||||||
catch (CRecoverableError &error)
|
catch (CRecoverableError &error)
|
||||||
{
|
{
|
||||||
|
@ -4067,6 +4060,7 @@ void P_SetupLevel (const char *lumpname, int position)
|
||||||
P_TranslateTeleportThings (); // [RH] Assign teleport destination TIDs
|
P_TranslateTeleportThings (); // [RH] Assign teleport destination TIDs
|
||||||
times[15].Unclock();
|
times[15].Unclock();
|
||||||
}
|
}
|
||||||
|
#if 0 // There is no such thing as a build map.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = 0; i < numbuildthings; ++i)
|
for (i = 0; i < numbuildthings; ++i)
|
||||||
|
@ -4075,6 +4069,7 @@ void P_SetupLevel (const char *lumpname, int position)
|
||||||
}
|
}
|
||||||
delete[] buildthings;
|
delete[] buildthings;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
delete map;
|
delete map;
|
||||||
if (oldvertextable != NULL)
|
if (oldvertextable != NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,69 +34,86 @@
|
||||||
|
|
||||||
struct MapData
|
struct MapData
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
struct MapLump
|
struct MapLump
|
||||||
{
|
{
|
||||||
char Name[8];
|
char Name[8] = { 0 };
|
||||||
FileReader *Reader;
|
FileRdr Reader;
|
||||||
} MapLumps[ML_MAX];
|
} MapLumps[ML_MAX];
|
||||||
bool HasBehavior;
|
FileRdr nofile;
|
||||||
bool Encrypted;
|
public:
|
||||||
bool isText;
|
bool HasBehavior = false;
|
||||||
bool InWad;
|
bool Encrypted = false;
|
||||||
int lumpnum;
|
bool isText = false;
|
||||||
FileReader * file;
|
bool InWad = false;
|
||||||
FResourceFile * resource;
|
int lumpnum = -1;
|
||||||
|
FResourceFile * resource = nullptr;
|
||||||
MapData()
|
|
||||||
{
|
|
||||||
memset(MapLumps, 0, sizeof(MapLumps));
|
|
||||||
file = NULL;
|
|
||||||
resource = NULL;
|
|
||||||
lumpnum = -1;
|
|
||||||
HasBehavior = false;
|
|
||||||
Encrypted = false;
|
|
||||||
isText = false;
|
|
||||||
InWad = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
~MapData()
|
~MapData()
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0;i < ML_MAX;++i)
|
if (resource != nullptr) delete resource;
|
||||||
delete MapLumps[i].Reader;
|
resource = nullptr;
|
||||||
|
|
||||||
delete resource;
|
|
||||||
resource = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void Seek(unsigned int lumpindex)
|
void Seek(unsigned int lumpindex)
|
||||||
{
|
{
|
||||||
if (lumpindex<countof(MapLumps))
|
if (lumpindex<countof(MapLumps))
|
||||||
{
|
{
|
||||||
file = MapLumps[lumpindex].Reader;
|
file = &MapLumps[lumpindex].Reader;
|
||||||
file->Seek(0, SEEK_SET);
|
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)
|
void Read(unsigned int lumpindex, void * buffer, int size = -1)
|
||||||
{
|
{
|
||||||
if (lumpindex<countof(MapLumps))
|
if (lumpindex<countof(MapLumps))
|
||||||
{
|
{
|
||||||
if (size == -1) size = MapLumps[lumpindex].Reader->GetLength();
|
if (size == -1) size = Size(lumpindex);
|
||||||
Seek(lumpindex);
|
if (size > 0)
|
||||||
file->Read(buffer, size);
|
{
|
||||||
|
auto &file = MapLumps[lumpindex].Reader;
|
||||||
|
file.Seek(0, FileRdr::SeekSet);
|
||||||
|
file.Read(buffer, size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Size(unsigned int lumpindex)
|
uint32_t Size(unsigned int lumpindex)
|
||||||
{
|
{
|
||||||
if (lumpindex<countof(MapLumps) && MapLumps[lumpindex].Reader)
|
if (lumpindex<countof(MapLumps) && MapLumps[lumpindex].Reader.isOpen())
|
||||||
{
|
{
|
||||||
return MapLumps[lumpindex].Reader->GetLength();
|
return (uint32_t)MapLumps[lumpindex].Reader.GetLength();
|
||||||
}
|
}
|
||||||
return 0;
|
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]);
|
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);
|
MapData * P_OpenMapData(const char * mapname, bool justcheck);
|
||||||
|
|
|
@ -474,10 +474,10 @@ class USDFParser : public UDMFParserBase
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool Parse(int lumpnum, FileReader *lump, int lumplen)
|
bool Parse(int lumpnum, FileRdr &lump, int lumplen)
|
||||||
{
|
{
|
||||||
char *buffer = new char[lumplen];
|
char *buffer = new char[lumplen];
|
||||||
lump->Read(buffer, lumplen);
|
lump.Read(buffer, lumplen);
|
||||||
sc.OpenMem(Wads.GetLumpFullName(lumpnum), buffer, lumplen);
|
sc.OpenMem(Wads.GetLumpFullName(lumpnum), buffer, lumplen);
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
sc.SetCMode(true);
|
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;
|
USDFParser parse;
|
||||||
|
|
||||||
|
|
|
@ -309,7 +309,8 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo)
|
||||||
{
|
{
|
||||||
MD5Context md5;
|
MD5Context md5;
|
||||||
reader->Seek(0, SEEK_SET);
|
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);
|
md5.Final(cksum);
|
||||||
|
|
||||||
for (size_t j = 0; j < sizeof(cksum); ++j)
|
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))
|
if (!(lump->Flags & LUMPF_EMBEDDED))
|
||||||
{
|
{
|
||||||
reader = lump->NewReader();
|
|
||||||
|
|
||||||
MD5Context md5;
|
MD5Context md5;
|
||||||
md5.Update(reader, lump->LumpSize);
|
md5.Update(FileRdr(lump->NewReader()), lump->LumpSize);
|
||||||
md5.Final(cksum);
|
md5.Final(cksum);
|
||||||
|
|
||||||
for (size_t j = 0; j < sizeof(cksum); ++j)
|
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,
|
fprintf(hashfile, "file: %s, lump: %s, hash: %s, size: %d\n", filename,
|
||||||
lump->FullName.IsNotEmpty() ? lump->FullName.GetChars() : lump->Name,
|
lump->FullName.IsNotEmpty() ? lump->FullName.GetChars() : lump->Name,
|
||||||
cksumout, lump->LumpSize);
|
cksumout, lump->LumpSize);
|
||||||
|
|
||||||
delete reader;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -942,7 +939,8 @@ void FWadCollection::RenameNerve ()
|
||||||
}
|
}
|
||||||
fr->Seek(0, SEEK_SET);
|
fr->Seek(0, SEEK_SET);
|
||||||
MD5Context md5;
|
MD5Context md5;
|
||||||
md5.Update(fr, fr->GetLength());
|
#pragma message("This does not work yet!");
|
||||||
|
//md5.Update(fr, fr->GetLength());
|
||||||
md5.Final(cksum);
|
md5.Final(cksum);
|
||||||
if (memcmp(nerve, cksum, 16) == 0)
|
if (memcmp(nerve, cksum, 16) == 0)
|
||||||
{
|
{
|
||||||
|
@ -1008,7 +1006,9 @@ void FWadCollection::FixMacHexen()
|
||||||
|
|
||||||
uint8_t checksum[16];
|
uint8_t checksum[16];
|
||||||
MD5Context md5;
|
MD5Context md5;
|
||||||
md5.Update(reader, iwadSize);
|
|
||||||
|
#pragma message("This does not work yet!");
|
||||||
|
//md5.Update(reader, iwadSize);
|
||||||
md5.Final(checksum);
|
md5.Final(checksum);
|
||||||
|
|
||||||
static const uint8_t HEXEN_DEMO_MD5[16] =
|
static const uint8_t HEXEN_DEMO_MD5[16] =
|
||||||
|
|
Loading…
Reference in a new issue