mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-28 06:53:58 +00:00
- Instead of implementing the wad code in three places, use the normal resource code for map loading and GL node loading.
SVN r3897 (trunk)
This commit is contained in:
parent
df5d43badf
commit
b52c3238eb
6 changed files with 109 additions and 117 deletions
|
@ -50,6 +50,7 @@
|
||||||
#include "g_level.h"
|
#include "g_level.h"
|
||||||
#include "p_lnspec.h"
|
#include "p_lnspec.h"
|
||||||
#include "r_state.h"
|
#include "r_state.h"
|
||||||
|
#include "w_wad.h"
|
||||||
|
|
||||||
// MACROS ------------------------------------------------------------------
|
// MACROS ------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -230,18 +230,18 @@ bool P_CheckForGLNodes()
|
||||||
static int firstglvertex;
|
static int firstglvertex;
|
||||||
static bool format5;
|
static bool format5;
|
||||||
|
|
||||||
static bool LoadGLVertexes(FileReader * f, wadlump_t * lump)
|
static bool LoadGLVertexes(FileReader * lump)
|
||||||
{
|
{
|
||||||
BYTE *gldata;
|
BYTE *gldata;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
firstglvertex = numvertexes;
|
firstglvertex = numvertexes;
|
||||||
|
|
||||||
int gllen=lump->Size;
|
int gllen=lump->GetLength();
|
||||||
|
|
||||||
gldata = new BYTE[gllen];
|
gldata = new BYTE[gllen];
|
||||||
f->Seek(lump->FilePos, SEEK_SET);
|
lump->Seek(0, SEEK_SET);
|
||||||
f->Read(gldata, gllen);
|
lump->Read(gldata, gllen);
|
||||||
|
|
||||||
if (*(int *)gldata == gNd5)
|
if (*(int *)gldata == gNd5)
|
||||||
{
|
{
|
||||||
|
@ -310,16 +310,16 @@ static inline int checkGLVertex3(int num)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static bool LoadGLSegs(FileReader * f, wadlump_t * lump)
|
static bool LoadGLSegs(FileReader * lump)
|
||||||
{
|
{
|
||||||
char *data;
|
char *data;
|
||||||
int i;
|
int i;
|
||||||
line_t *ldef=NULL;
|
line_t *ldef=NULL;
|
||||||
|
|
||||||
numsegs = lump->Size;
|
numsegs = lump->GetLength();
|
||||||
data= new char[numsegs];
|
data= new char[numsegs];
|
||||||
f->Seek(lump->FilePos, SEEK_SET);
|
lump->Seek(0, SEEK_SET);
|
||||||
f->Read(data, lump->Size);
|
lump->Read(data, numsegs);
|
||||||
segs=NULL;
|
segs=NULL;
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
@ -442,15 +442,15 @@ static bool LoadGLSegs(FileReader * f, wadlump_t * lump)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static bool LoadGLSubsectors(FileReader * f, wadlump_t * lump)
|
static bool LoadGLSubsectors(FileReader * lump)
|
||||||
{
|
{
|
||||||
char * datab;
|
char * datab;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
numsubsectors = lump->Size;
|
numsubsectors = lump->GetLength();
|
||||||
datab = new char[numsubsectors];
|
datab = new char[numsubsectors];
|
||||||
f->Seek(lump->FilePos, SEEK_SET);
|
lump->Seek(0, SEEK_SET);
|
||||||
f->Read(datab, lump->Size);
|
lump->Read(datab, numsubsectors);
|
||||||
|
|
||||||
if (numsubsectors == 0)
|
if (numsubsectors == 0)
|
||||||
{
|
{
|
||||||
|
@ -524,7 +524,7 @@ static bool LoadGLSubsectors(FileReader * f, wadlump_t * lump)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static bool LoadNodes (FileReader * f, wadlump_t * lump)
|
static bool LoadNodes (FileReader * lump)
|
||||||
{
|
{
|
||||||
const int NF_SUBSECTOR = 0x8000;
|
const int NF_SUBSECTOR = 0x8000;
|
||||||
const int GL5_NF_SUBSECTOR = (1 << 31);
|
const int GL5_NF_SUBSECTOR = (1 << 31);
|
||||||
|
@ -538,15 +538,15 @@ static bool LoadNodes (FileReader * f, wadlump_t * lump)
|
||||||
if (!format5)
|
if (!format5)
|
||||||
{
|
{
|
||||||
mapnode_t* mn, * basemn;
|
mapnode_t* mn, * basemn;
|
||||||
numnodes = lump->Size / sizeof(mapnode_t);
|
numnodes = lump->GetLength() / sizeof(mapnode_t);
|
||||||
|
|
||||||
if (numnodes == 0) return false;
|
if (numnodes == 0) return false;
|
||||||
|
|
||||||
nodes = new node_t[numnodes];
|
nodes = new node_t[numnodes];
|
||||||
f->Seek(lump->FilePos, SEEK_SET);
|
lump->Seek(0, SEEK_SET);
|
||||||
|
|
||||||
basemn = mn = new mapnode_t[numnodes];
|
basemn = mn = new mapnode_t[numnodes];
|
||||||
f->Read(mn, lump->Size);
|
lump->Read(mn, lump->GetLength());
|
||||||
|
|
||||||
used = (WORD *)alloca (sizeof(WORD)*numnodes);
|
used = (WORD *)alloca (sizeof(WORD)*numnodes);
|
||||||
memset (used, 0, sizeof(WORD)*numnodes);
|
memset (used, 0, sizeof(WORD)*numnodes);
|
||||||
|
@ -598,15 +598,15 @@ static bool LoadNodes (FileReader * f, wadlump_t * lump)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gl5_mapnode_t* mn, * basemn;
|
gl5_mapnode_t* mn, * basemn;
|
||||||
numnodes = lump->Size / sizeof(gl5_mapnode_t);
|
numnodes = lump->GetLength() / sizeof(gl5_mapnode_t);
|
||||||
|
|
||||||
if (numnodes == 0) return false;
|
if (numnodes == 0) return false;
|
||||||
|
|
||||||
nodes = new node_t[numnodes];
|
nodes = new node_t[numnodes];
|
||||||
f->Seek(lump->FilePos, SEEK_SET);
|
lump->Seek(0, SEEK_SET);
|
||||||
|
|
||||||
basemn = mn = new gl5_mapnode_t[numnodes];
|
basemn = mn = new gl5_mapnode_t[numnodes];
|
||||||
f->Read(mn, lump->Size);
|
lump->Read(mn, lump->GetLength());
|
||||||
|
|
||||||
used = (WORD *)alloca (sizeof(WORD)*numnodes);
|
used = (WORD *)alloca (sizeof(WORD)*numnodes);
|
||||||
memset (used, 0, sizeof(WORD)*numnodes);
|
memset (used, 0, sizeof(WORD)*numnodes);
|
||||||
|
@ -664,19 +664,19 @@ static bool LoadNodes (FileReader * f, wadlump_t * lump)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static bool DoLoadGLNodes(FileReader * f, wadlump_t * lumps)
|
static bool DoLoadGLNodes(FileReader ** lumps)
|
||||||
{
|
{
|
||||||
if (!LoadGLVertexes(f, &lumps[0]))
|
if (!LoadGLVertexes(lumps[0]))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!LoadGLSegs(f, &lumps[1]))
|
if (!LoadGLSegs(lumps[1]))
|
||||||
{
|
{
|
||||||
delete [] segs;
|
delete [] segs;
|
||||||
segs = NULL;
|
segs = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!LoadGLSubsectors(f, &lumps[2]))
|
if (!LoadGLSubsectors(lumps[2]))
|
||||||
{
|
{
|
||||||
delete [] subsectors;
|
delete [] subsectors;
|
||||||
subsectors = NULL;
|
subsectors = NULL;
|
||||||
|
@ -684,7 +684,7 @@ static bool DoLoadGLNodes(FileReader * f, wadlump_t * lumps)
|
||||||
segs = NULL;
|
segs = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!LoadNodes(f, &lumps[3]))
|
if (!LoadNodes(lumps[3]))
|
||||||
{
|
{
|
||||||
delete [] nodes;
|
delete [] nodes;
|
||||||
nodes = NULL;
|
nodes = NULL;
|
||||||
|
@ -851,7 +851,7 @@ static int FindGLNodesInFile(FileReader * f, const char * label)
|
||||||
|
|
||||||
bool P_LoadGLNodes(MapData * map)
|
bool P_LoadGLNodes(MapData * map)
|
||||||
{
|
{
|
||||||
if (map->MapLumps[ML_GLZNODES].Size != 0)
|
if (map->MapLumps[ML_GLZNODES].Reader && map->MapLumps[ML_GLZNODES].Reader->GetLength() != 0)
|
||||||
{
|
{
|
||||||
const int idcheck = MAKE_ID('Z','G','L','N');
|
const int idcheck = MAKE_ID('Z','G','L','N');
|
||||||
const int idcheck2 = MAKE_ID('Z','G','L','2');
|
const int idcheck2 = MAKE_ID('Z','G','L','2');
|
||||||
|
@ -894,13 +894,13 @@ bool P_LoadGLNodes(MapData * map)
|
||||||
|
|
||||||
if (!CheckCachedNodes(map))
|
if (!CheckCachedNodes(map))
|
||||||
{
|
{
|
||||||
wadlump_t gwalumps[4];
|
FileReader *gwalumps[4] = { NULL, NULL, NULL, NULL };
|
||||||
char path[256];
|
char path[256];
|
||||||
int li;
|
int li;
|
||||||
int lumpfile = Wads.GetLumpFile(map->lumpnum);
|
int lumpfile = Wads.GetLumpFile(map->lumpnum);
|
||||||
bool mapinwad = map->file == Wads.GetFileReader(lumpfile);
|
bool mapinwad = map->file == Wads.GetFileReader(lumpfile);
|
||||||
FileReader * fr = map->file;
|
FileReader * fr = map->file;
|
||||||
FILE * f_gwa = NULL;
|
FResourceFile * f_gwa = NULL;
|
||||||
|
|
||||||
const char * name = Wads.GetWadFullName(lumpfile);
|
const char * name = Wads.GetWadFullName(lumpfile);
|
||||||
|
|
||||||
|
@ -913,10 +913,9 @@ bool P_LoadGLNodes(MapData * map)
|
||||||
// GL nodes are loaded with a WAD
|
// GL nodes are loaded with a WAD
|
||||||
for(int i=0;i<4;i++)
|
for(int i=0;i<4;i++)
|
||||||
{
|
{
|
||||||
gwalumps[i].FilePos=Wads.GetLumpOffset(li+i+1);
|
gwalumps[i]=Wads.ReopenLumpNum(li+i+1);
|
||||||
gwalumps[i].Size=Wads.LumpLength(li+i+1);
|
|
||||||
}
|
}
|
||||||
return DoLoadGLNodes(fr, gwalumps);
|
return DoLoadGLNodes(gwalumps);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -928,10 +927,10 @@ bool P_LoadGLNodes(MapData * map)
|
||||||
strcpy(ext, ".gwa");
|
strcpy(ext, ".gwa");
|
||||||
// Todo: Compare file dates
|
// Todo: Compare file dates
|
||||||
|
|
||||||
f_gwa = fopen(path, "rb");
|
f_gwa = FResourceFile::OpenResourceFile(path, NULL, true);
|
||||||
if (f_gwa==NULL) return false;
|
if (f_gwa==NULL) return false;
|
||||||
|
|
||||||
fr = new FileReader(f_gwa);
|
fr = f_gwa->GetReader();
|
||||||
|
|
||||||
strncpy(map->MapLumps[0].Name, Wads.GetLumpFullName(map->lumpnum), 8);
|
strncpy(map->MapLumps[0].Name, Wads.GetLumpFullName(map->lumpnum), 8);
|
||||||
}
|
}
|
||||||
|
@ -946,23 +945,24 @@ bool P_LoadGLNodes(MapData * map)
|
||||||
result=true;
|
result=true;
|
||||||
for(unsigned i=0; i<4;i++)
|
for(unsigned i=0; i<4;i++)
|
||||||
{
|
{
|
||||||
(*fr) >> gwalumps[i].FilePos;
|
if (strnicmp(f_gwa->GetLump(i)->Name, check[i], 8))
|
||||||
(*fr) >> gwalumps[i].Size;
|
|
||||||
fr->Read(gwalumps[i].Name, 8);
|
|
||||||
if (strnicmp(gwalumps[i].Name, check[i], 8))
|
|
||||||
{
|
{
|
||||||
result=false;
|
result=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
gwalumps[i] = f_gwa->GetLump(i)->NewReader();
|
||||||
}
|
}
|
||||||
if (result) result = DoLoadGLNodes(fr, gwalumps);
|
if (result) result = DoLoadGLNodes(gwalumps);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f_gwa)
|
if (f_gwa)
|
||||||
{
|
{
|
||||||
delete fr;
|
delete fr;
|
||||||
fclose(f_gwa);
|
delete f_gwa;
|
||||||
}
|
}
|
||||||
|
for(unsigned int i = 0;i < 4;++i)
|
||||||
|
delete gwalumps[i];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else return true;
|
else return true;
|
||||||
|
|
117
src/p_setup.cpp
117
src/p_setup.cpp
|
@ -251,6 +251,7 @@ static int GetMapIndex(const char *mapname, int lastindex, const char *lumpname,
|
||||||
MapData *P_OpenMapData(const char * mapname)
|
MapData *P_OpenMapData(const char * mapname)
|
||||||
{
|
{
|
||||||
MapData * map = new MapData;
|
MapData * map = new MapData;
|
||||||
|
FileReader * wadReader = NULL;
|
||||||
bool externalfile = !strnicmp(mapname, "file:", 5);
|
bool externalfile = !strnicmp(mapname, "file:", 5);
|
||||||
|
|
||||||
if (externalfile)
|
if (externalfile)
|
||||||
|
@ -261,8 +262,8 @@ MapData *P_OpenMapData(const char * mapname)
|
||||||
delete map;
|
delete map;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
map->file = new FileReader(mapname);
|
map->resource = FResourceFile::OpenResourceFile(mapname, NULL, true);
|
||||||
map->CloseOnDestruct = true;
|
wadReader = map->resource->GetReader();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -284,18 +285,13 @@ MapData *P_OpenMapData(const char * mapname)
|
||||||
int lumpfile = Wads.GetLumpFile(lump_name);
|
int lumpfile = Wads.GetLumpFile(lump_name);
|
||||||
int nextfile = Wads.GetLumpFile(lump_name+1);
|
int nextfile = Wads.GetLumpFile(lump_name+1);
|
||||||
|
|
||||||
map->file = Wads.GetFileReader(lumpfile);
|
|
||||||
map->CloseOnDestruct = false;
|
|
||||||
map->lumpnum = lump_name;
|
map->lumpnum = lump_name;
|
||||||
|
|
||||||
if (lumpfile != nextfile)
|
if (lumpfile != nextfile)
|
||||||
{
|
{
|
||||||
// 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].FilePos = 0;
|
map->MapLumps[0].Reader = map->file = Wads.ReopenLumpNum(lump_name);
|
||||||
map->MapLumps[0].Size = Wads.LumpLength(lump_name);
|
|
||||||
map->file = Wads.ReopenLumpNum(lump_name);
|
|
||||||
map->CloseOnDestruct = true;
|
|
||||||
if (!P_IsBuildMap(map))
|
if (!P_IsBuildMap(map))
|
||||||
{
|
{
|
||||||
delete map;
|
delete map;
|
||||||
|
@ -306,15 +302,12 @@ MapData *P_OpenMapData(const char * mapname)
|
||||||
|
|
||||||
// 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].FilePos = Wads.GetLumpOffset(lump_name);
|
map->MapLumps[0].Reader = Wads.ReopenLumpNum(lump_name);
|
||||||
map->MapLumps[0].Size = Wads.LumpLength(lump_name);
|
|
||||||
map->Encrypted = Wads.IsEncryptedFile(lump_name);
|
map->Encrypted = Wads.IsEncryptedFile(lump_name);
|
||||||
|
|
||||||
if (map->Encrypted)
|
if (map->Encrypted)
|
||||||
{ // If it's encrypted, then it's a Blood file, presumably a map.
|
{ // If it's encrypted, then it's a Blood file, presumably a map.
|
||||||
map->file = Wads.ReopenLumpNum(lump_name);
|
map->MapLumps[0].Reader = map->file = Wads.ReopenLumpNum(lump_name);
|
||||||
map->CloseOnDestruct = true;
|
|
||||||
map->MapLumps[0].FilePos = 0;
|
|
||||||
if (!P_IsBuildMap(map))
|
if (!P_IsBuildMap(map))
|
||||||
{
|
{
|
||||||
delete map;
|
delete map;
|
||||||
|
@ -332,22 +325,20 @@ MapData *P_OpenMapData(const char * mapname)
|
||||||
// Since levels must be stored in WADs they can't really have full
|
// Since levels must be stored in WADs they can't really have full
|
||||||
// names and for any valid level lump this always returns the short name.
|
// names and for any valid level lump this always returns the short name.
|
||||||
const char * lumpname = Wads.GetLumpFullName(lump_name + i);
|
const char * lumpname = Wads.GetLumpFullName(lump_name + i);
|
||||||
index = GetMapIndex(mapname, index, lumpname, i != 1 || map->MapLumps[0].Size == 0);
|
index = GetMapIndex(mapname, index, lumpname, i != 1 || Wads.LumpLength(lump_name + i) == 0);
|
||||||
if (index == ML_BEHAVIOR) map->HasBehavior = true;
|
if (index == ML_BEHAVIOR) map->HasBehavior = true;
|
||||||
|
|
||||||
// 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].FilePos = Wads.GetLumpOffset(lump_name + i);
|
map->MapLumps[index].Reader = Wads.ReopenLumpNum(lump_name + i);
|
||||||
map->MapLumps[index].Size = Wads.LumpLength(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].FilePos = Wads.GetLumpOffset(lump_name + 1);
|
map->MapLumps[1].Reader = Wads.ReopenLumpNum(lump_name + 1);
|
||||||
map->MapLumps[1].Size = Wads.LumpLength(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);
|
||||||
|
@ -383,8 +374,7 @@ MapData *P_OpenMapData(const char * mapname)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else continue;
|
else continue;
|
||||||
map->MapLumps[index].FilePos = Wads.GetLumpOffset(lump_name + i);
|
map->MapLumps[index].Reader = Wads.ReopenLumpNum(lump_name + i);
|
||||||
map->MapLumps[index].Size = Wads.LumpLength(lump_name + i);
|
|
||||||
strncpy(map->MapLumps[index].Name, lumpname, 8);
|
strncpy(map->MapLumps[index].Name, lumpname, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,42 +392,35 @@ MapData *P_OpenMapData(const char * mapname)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
map->lumpnum = lump_wad;
|
map->lumpnum = lump_wad;
|
||||||
map->file = Wads.ReopenLumpNum(lump_wad);
|
map->resource = FResourceFile::OpenResourceFile(Wads.GetLumpFullName(lump_wad), Wads.ReopenLumpNum(lump_wad), true);
|
||||||
map->CloseOnDestruct = true;
|
wadReader = map->resource->GetReader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DWORD id;
|
DWORD id;
|
||||||
|
|
||||||
map->file->Read(&id, sizeof(id));
|
// Although we're using the resource system, we still want to be sure we're
|
||||||
|
// reading from a wad file.
|
||||||
|
wadReader->Seek(0, SEEK_SET);
|
||||||
|
wadReader->Read(&id, sizeof(id));
|
||||||
|
|
||||||
if (id == IWAD_ID || id == PWAD_ID)
|
if (id == IWAD_ID || id == PWAD_ID)
|
||||||
{
|
{
|
||||||
char maplabel[9]="";
|
char maplabel[9]="";
|
||||||
int index=0;
|
int index=0;
|
||||||
DWORD dirofs, numentries;
|
|
||||||
|
|
||||||
(*map->file) >> numentries >> dirofs;
|
map->MapLumps[0].Reader = map->resource->GetLump(0)->NewReader();
|
||||||
|
|
||||||
map->file->Seek(dirofs, SEEK_SET);
|
for(DWORD i = 1; i < map->resource->LumpCount(); i++)
|
||||||
(*map->file) >> map->MapLumps[0].FilePos >> map->MapLumps[0].Size;
|
|
||||||
map->file->Read(map->MapLumps[0].Name, 8);
|
|
||||||
|
|
||||||
for(DWORD i = 1; i < numentries; i++)
|
|
||||||
{
|
{
|
||||||
DWORD offset, size;
|
const char* lumpname = map->resource->GetLump(i)->Name;
|
||||||
char lumpname[8];
|
|
||||||
|
|
||||||
(*map->file) >> offset >> size;
|
|
||||||
map->file->Read(lumpname, 8);
|
|
||||||
if (i == 1 && !strnicmp(lumpname, "TEXTMAP", 8))
|
if (i == 1 && !strnicmp(lumpname, "TEXTMAP", 8))
|
||||||
{
|
{
|
||||||
map->isText = true;
|
map->isText = true;
|
||||||
map->MapLumps[1].FilePos = offset;
|
|
||||||
map->MapLumps[1].Size = size;
|
|
||||||
for(int i = 2;; i++)
|
for(int i = 2;; i++)
|
||||||
{
|
{
|
||||||
(*map->file) >> offset >> size;
|
lumpname = map->resource->GetLump(i)->Name;
|
||||||
long v = map->file->Read(lumpname, 8);
|
long v = strlen(lumpname);
|
||||||
if (v < 8)
|
if (v < 8)
|
||||||
{
|
{
|
||||||
I_Error("Invalid map definition for %s", mapname);
|
I_Error("Invalid map definition for %s", mapname);
|
||||||
|
@ -469,8 +452,7 @@ MapData *P_OpenMapData(const char * mapname)
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
else continue;
|
else continue;
|
||||||
map->MapLumps[index].FilePos = offset;
|
map->MapLumps[index].Reader = map->resource->GetLump(i)->NewReader();
|
||||||
map->MapLumps[index].Size = size;
|
|
||||||
strncpy(map->MapLumps[index].Name, lumpname, 8);
|
strncpy(map->MapLumps[index].Name, lumpname, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -489,15 +471,14 @@ MapData *P_OpenMapData(const char * mapname)
|
||||||
maplabel[8]=0;
|
maplabel[8]=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
map->MapLumps[index].FilePos = offset;
|
map->MapLumps[index].Reader = map->resource->GetLump(i)->NewReader();
|
||||||
map->MapLumps[index].Size = size;
|
|
||||||
strncpy(map->MapLumps[index].Name, lumpname, 8);
|
strncpy(map->MapLumps[index].Name, lumpname, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// This is a Build map and not subject to WAD consistency checks.
|
// This is a Build map and not subject to WAD consistency checks.
|
||||||
map->MapLumps[0].Size = map->file->GetLength();
|
//map->MapLumps[0].Size = wadReader->GetLength();
|
||||||
if (!P_IsBuildMap(map))
|
if (!P_IsBuildMap(map))
|
||||||
{
|
{
|
||||||
delete map;
|
delete map;
|
||||||
|
@ -532,29 +513,29 @@ void MapData::GetChecksum(BYTE cksum[16])
|
||||||
{
|
{
|
||||||
if (isText)
|
if (isText)
|
||||||
{
|
{
|
||||||
file->Seek(MapLumps[ML_TEXTMAP].FilePos, SEEK_SET);
|
Seek(ML_TEXTMAP);
|
||||||
md5.Update(file, MapLumps[ML_TEXTMAP].Size);
|
md5.Update(file, Size(ML_TEXTMAP));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (MapLumps[ML_LABEL].Size != 0)
|
if (Size(ML_LABEL) != 0)
|
||||||
{
|
{
|
||||||
file->Seek(MapLumps[ML_LABEL].FilePos, SEEK_SET);
|
Seek(ML_LABEL);
|
||||||
md5.Update(file, MapLumps[ML_LABEL].Size);
|
md5.Update(file, Size(ML_LABEL));
|
||||||
}
|
}
|
||||||
file->Seek(MapLumps[ML_THINGS].FilePos, SEEK_SET);
|
Seek(ML_THINGS);
|
||||||
md5.Update(file, MapLumps[ML_THINGS].Size);
|
md5.Update(file, Size(ML_THINGS));
|
||||||
file->Seek(MapLumps[ML_LINEDEFS].FilePos, SEEK_SET);
|
Seek(ML_LINEDEFS);
|
||||||
md5.Update(file, MapLumps[ML_LINEDEFS].Size);
|
md5.Update(file, Size(ML_LINEDEFS));
|
||||||
file->Seek(MapLumps[ML_SIDEDEFS].FilePos, SEEK_SET);
|
Seek(ML_SIDEDEFS);
|
||||||
md5.Update(file, MapLumps[ML_SIDEDEFS].Size);
|
md5.Update(file, Size(ML_SIDEDEFS));
|
||||||
file->Seek(MapLumps[ML_SECTORS].FilePos, SEEK_SET);
|
Seek(ML_SECTORS);
|
||||||
md5.Update(file, MapLumps[ML_SECTORS].Size);
|
md5.Update(file, Size(ML_SECTORS));
|
||||||
}
|
}
|
||||||
if (HasBehavior)
|
if (HasBehavior)
|
||||||
{
|
{
|
||||||
file->Seek(MapLumps[ML_BEHAVIOR].FilePos, SEEK_SET);
|
Seek(ML_BEHAVIOR);
|
||||||
md5.Update(file, MapLumps[ML_BEHAVIOR].Size);
|
md5.Update(file, Size(ML_BEHAVIOR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
md5.Final(cksum);
|
md5.Final(cksum);
|
||||||
|
@ -834,7 +815,7 @@ void P_LoadVertexes (MapData * map)
|
||||||
|
|
||||||
// Determine number of vertices:
|
// Determine number of vertices:
|
||||||
// total lump length / vertex record length.
|
// total lump length / vertex record length.
|
||||||
numvertexes = map->MapLumps[ML_VERTEXES].Size / sizeof(mapvertex_t);
|
numvertexes = map->Size(ML_VERTEXES) / sizeof(mapvertex_t);
|
||||||
numvertexdatas = 0;
|
numvertexdatas = 0;
|
||||||
|
|
||||||
if (numvertexes == 0)
|
if (numvertexes == 0)
|
||||||
|
@ -1199,7 +1180,7 @@ void P_LoadSegs (MapData * map)
|
||||||
int dis; // phares 10/4/98
|
int dis; // phares 10/4/98
|
||||||
int dx,dy; // phares 10/4/98
|
int dx,dy; // phares 10/4/98
|
||||||
int vnum1,vnum2; // phares 10/4/98
|
int vnum1,vnum2; // phares 10/4/98
|
||||||
int lumplen = map->MapLumps[ML_SEGS].Size;
|
int lumplen = map->Size(ML_SEGS);
|
||||||
|
|
||||||
memset (vertchanged,0,numvertexes); // phares 10/4/98
|
memset (vertchanged,0,numvertexes); // phares 10/4/98
|
||||||
|
|
||||||
|
@ -1382,7 +1363,7 @@ void P_LoadSubsectors (MapData * map)
|
||||||
int i;
|
int i;
|
||||||
DWORD maxseg = map->Size(ML_SEGS) / sizeof(segtype);
|
DWORD maxseg = map->Size(ML_SEGS) / sizeof(segtype);
|
||||||
|
|
||||||
numsubsectors = map->MapLumps[ML_SSECTORS].Size / sizeof(subsectortype);
|
numsubsectors = map->Size(ML_SSECTORS) / sizeof(subsectortype);
|
||||||
|
|
||||||
if (numsubsectors == 0 || maxseg == 0 )
|
if (numsubsectors == 0 || maxseg == 0 )
|
||||||
{
|
{
|
||||||
|
@ -1746,7 +1727,7 @@ void P_LoadThings (MapData * map)
|
||||||
|
|
||||||
void P_LoadThings2 (MapData * map)
|
void P_LoadThings2 (MapData * map)
|
||||||
{
|
{
|
||||||
int lumplen = map->MapLumps[ML_THINGS].Size;
|
int lumplen = map->Size(ML_THINGS);
|
||||||
int numthings = lumplen / sizeof(mapthinghexen_t);
|
int numthings = lumplen / sizeof(mapthinghexen_t);
|
||||||
|
|
||||||
char *mtp;
|
char *mtp;
|
||||||
|
@ -3561,13 +3542,13 @@ void P_SetupLevel (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 (map->MapLumps[0].Size > 0)
|
if (map->Size(0) > 0)
|
||||||
{
|
{
|
||||||
BYTE *mapdata = new BYTE[map->MapLumps[0].Size];
|
BYTE *mapdata = new BYTE[map->Size(0)];
|
||||||
map->Seek(0);
|
map->Seek(0);
|
||||||
map->file->Read(mapdata, map->MapLumps[0].Size);
|
map->file->Read(mapdata, map->Size(0));
|
||||||
times[0].Clock();
|
times[0].Clock();
|
||||||
buildmap = P_LoadBuildMap (mapdata, map->MapLumps[0].Size, &buildthings, &numbuildthings);
|
buildmap = P_LoadBuildMap (mapdata, map->Size(0), &buildthings, &numbuildthings);
|
||||||
times[0].Unclock();
|
times[0].Unclock();
|
||||||
delete[] mapdata;
|
delete[] mapdata;
|
||||||
}
|
}
|
||||||
|
@ -3704,14 +3685,14 @@ void P_SetupLevel (char *lumpname, int position)
|
||||||
FWadLump test;
|
FWadLump test;
|
||||||
DWORD id = MAKE_ID('X','x','X','x'), idcheck = 0, idcheck2 = 0, idcheck3 = 0, idcheck4 = 0;
|
DWORD id = MAKE_ID('X','x','X','x'), idcheck = 0, idcheck2 = 0, idcheck3 = 0, idcheck4 = 0;
|
||||||
|
|
||||||
if (map->MapLumps[ML_ZNODES].Size != 0)
|
if (map->Size(ML_ZNODES) != 0)
|
||||||
{
|
{
|
||||||
// Test normal nodes first
|
// Test normal nodes first
|
||||||
map->Seek(ML_ZNODES);
|
map->Seek(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->MapLumps[ML_GLZNODES].Size != 0)
|
else if (map->Size(ML_GLZNODES) != 0)
|
||||||
{
|
{
|
||||||
map->Seek(ML_GLZNODES);
|
map->Seek(ML_GLZNODES);
|
||||||
idcheck = MAKE_ID('Z','G','L','N');
|
idcheck = MAKE_ID('Z','G','L','N');
|
||||||
|
|
|
@ -23,42 +23,50 @@
|
||||||
#ifndef __P_SETUP__
|
#ifndef __P_SETUP__
|
||||||
#define __P_SETUP__
|
#define __P_SETUP__
|
||||||
|
|
||||||
#include "w_wad.h"
|
#include "resourcefiles/resourcefile.h"
|
||||||
#include "doomdata.h"
|
#include "doomdata.h"
|
||||||
|
|
||||||
|
|
||||||
struct MapData
|
struct MapData
|
||||||
{
|
{
|
||||||
wadlump_t MapLumps[ML_MAX];
|
struct
|
||||||
|
{
|
||||||
|
char Name[8];
|
||||||
|
FileReader *Reader;
|
||||||
|
} MapLumps[ML_MAX];
|
||||||
bool HasBehavior;
|
bool HasBehavior;
|
||||||
bool CloseOnDestruct;
|
|
||||||
bool Encrypted;
|
bool Encrypted;
|
||||||
bool isText;
|
bool isText;
|
||||||
int lumpnum;
|
int lumpnum;
|
||||||
FileReader * file;
|
FileReader * file;
|
||||||
|
FResourceFile * resource;
|
||||||
|
|
||||||
MapData()
|
MapData()
|
||||||
{
|
{
|
||||||
memset(MapLumps, 0, sizeof(MapLumps));
|
memset(MapLumps, 0, sizeof(MapLumps));
|
||||||
file = NULL;
|
file = NULL;
|
||||||
|
resource = NULL;
|
||||||
lumpnum = -1;
|
lumpnum = -1;
|
||||||
HasBehavior = false;
|
HasBehavior = false;
|
||||||
CloseOnDestruct = true;
|
|
||||||
Encrypted = false;
|
Encrypted = false;
|
||||||
isText = false;
|
isText = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
~MapData()
|
~MapData()
|
||||||
{
|
{
|
||||||
if (CloseOnDestruct && file != NULL) delete file;
|
for (unsigned int i = 0;i < ML_MAX;++i)
|
||||||
file = NULL;
|
delete MapLumps[i].Reader;
|
||||||
|
|
||||||
|
delete resource;
|
||||||
|
resource = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Seek(unsigned int lumpindex)
|
void Seek(unsigned int lumpindex)
|
||||||
{
|
{
|
||||||
if (lumpindex<countof(MapLumps))
|
if (lumpindex<countof(MapLumps))
|
||||||
{
|
{
|
||||||
file->Seek(MapLumps[lumpindex].FilePos, SEEK_SET);
|
file = MapLumps[lumpindex].Reader;
|
||||||
|
file->Seek(0, SEEK_SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,17 +74,17 @@ struct MapData
|
||||||
{
|
{
|
||||||
if (lumpindex<countof(MapLumps))
|
if (lumpindex<countof(MapLumps))
|
||||||
{
|
{
|
||||||
if (size == -1) size = MapLumps[lumpindex].Size;
|
if (size == -1) size = MapLumps[lumpindex].Reader->GetLength();
|
||||||
file->Seek(MapLumps[lumpindex].FilePos, SEEK_SET);
|
Seek(lumpindex);
|
||||||
file->Read(buffer, size);
|
file->Read(buffer, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD Size(unsigned int lumpindex)
|
DWORD Size(unsigned int lumpindex)
|
||||||
{
|
{
|
||||||
if (lumpindex<countof(MapLumps))
|
if (lumpindex<countof(MapLumps) && MapLumps[lumpindex].Reader)
|
||||||
{
|
{
|
||||||
return MapLumps[lumpindex].Size;
|
return MapLumps[lumpindex].Reader->GetLength();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include "p_udmf.h"
|
#include "p_udmf.h"
|
||||||
#include "r_state.h"
|
#include "r_state.h"
|
||||||
#include "r_data/colormaps.h"
|
#include "r_data/colormaps.h"
|
||||||
|
#include "w_wad.h"
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "doomerrors.h"
|
#include "doomerrors.h"
|
||||||
#include "cmdlib.h"
|
#include "cmdlib.h"
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
|
#include "w_wad.h"
|
||||||
|
|
||||||
#define Zd 1
|
#define Zd 1
|
||||||
#define St 2
|
#define St 2
|
||||||
|
|
Loading…
Reference in a new issue