- 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:
Braden Obrzut 2012-10-22 01:28:11 +00:00
parent df5d43badf
commit b52c3238eb
6 changed files with 109 additions and 117 deletions

View file

@ -50,6 +50,7 @@
#include "g_level.h"
#include "p_lnspec.h"
#include "r_state.h"
#include "w_wad.h"
// MACROS ------------------------------------------------------------------

View file

@ -230,18 +230,18 @@ bool P_CheckForGLNodes()
static int firstglvertex;
static bool format5;
static bool LoadGLVertexes(FileReader * f, wadlump_t * lump)
static bool LoadGLVertexes(FileReader * lump)
{
BYTE *gldata;
int i;
firstglvertex = numvertexes;
int gllen=lump->Size;
int gllen=lump->GetLength();
gldata = new BYTE[gllen];
f->Seek(lump->FilePos, SEEK_SET);
f->Read(gldata, gllen);
lump->Seek(0, SEEK_SET);
lump->Read(gldata, gllen);
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;
int i;
line_t *ldef=NULL;
numsegs = lump->Size;
numsegs = lump->GetLength();
data= new char[numsegs];
f->Seek(lump->FilePos, SEEK_SET);
f->Read(data, lump->Size);
lump->Seek(0, SEEK_SET);
lump->Read(data, numsegs);
segs=NULL;
#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;
int i;
numsubsectors = lump->Size;
numsubsectors = lump->GetLength();
datab = new char[numsubsectors];
f->Seek(lump->FilePos, SEEK_SET);
f->Read(datab, lump->Size);
lump->Seek(0, SEEK_SET);
lump->Read(datab, numsubsectors);
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 GL5_NF_SUBSECTOR = (1 << 31);
@ -538,15 +538,15 @@ static bool LoadNodes (FileReader * f, wadlump_t * lump)
if (!format5)
{
mapnode_t* mn, * basemn;
numnodes = lump->Size / sizeof(mapnode_t);
numnodes = lump->GetLength() / sizeof(mapnode_t);
if (numnodes == 0) return false;
nodes = new node_t[numnodes];
f->Seek(lump->FilePos, SEEK_SET);
lump->Seek(0, SEEK_SET);
basemn = mn = new mapnode_t[numnodes];
f->Read(mn, lump->Size);
lump->Read(mn, lump->GetLength());
used = (WORD *)alloca (sizeof(WORD)*numnodes);
memset (used, 0, sizeof(WORD)*numnodes);
@ -598,15 +598,15 @@ static bool LoadNodes (FileReader * f, wadlump_t * lump)
else
{
gl5_mapnode_t* mn, * basemn;
numnodes = lump->Size / sizeof(gl5_mapnode_t);
numnodes = lump->GetLength() / sizeof(gl5_mapnode_t);
if (numnodes == 0) return false;
nodes = new node_t[numnodes];
f->Seek(lump->FilePos, SEEK_SET);
lump->Seek(0, SEEK_SET);
basemn = mn = new gl5_mapnode_t[numnodes];
f->Read(mn, lump->Size);
lump->Read(mn, lump->GetLength());
used = (WORD *)alloca (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;
}
if (!LoadGLSegs(f, &lumps[1]))
if (!LoadGLSegs(lumps[1]))
{
delete [] segs;
segs = NULL;
return false;
}
if (!LoadGLSubsectors(f, &lumps[2]))
if (!LoadGLSubsectors(lumps[2]))
{
delete [] subsectors;
subsectors = NULL;
@ -684,7 +684,7 @@ static bool DoLoadGLNodes(FileReader * f, wadlump_t * lumps)
segs = NULL;
return false;
}
if (!LoadNodes(f, &lumps[3]))
if (!LoadNodes(lumps[3]))
{
delete [] nodes;
nodes = NULL;
@ -851,7 +851,7 @@ static int FindGLNodesInFile(FileReader * f, const char * label)
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 idcheck2 = MAKE_ID('Z','G','L','2');
@ -894,13 +894,13 @@ bool P_LoadGLNodes(MapData * map)
if (!CheckCachedNodes(map))
{
wadlump_t gwalumps[4];
FileReader *gwalumps[4] = { NULL, NULL, NULL, NULL };
char path[256];
int li;
int lumpfile = Wads.GetLumpFile(map->lumpnum);
bool mapinwad = map->file == Wads.GetFileReader(lumpfile);
FileReader * fr = map->file;
FILE * f_gwa = NULL;
FResourceFile * f_gwa = NULL;
const char * name = Wads.GetWadFullName(lumpfile);
@ -913,10 +913,9 @@ bool P_LoadGLNodes(MapData * map)
// GL nodes are loaded with a WAD
for(int i=0;i<4;i++)
{
gwalumps[i].FilePos=Wads.GetLumpOffset(li+i+1);
gwalumps[i].Size=Wads.LumpLength(li+i+1);
gwalumps[i]=Wads.ReopenLumpNum(li+i+1);
}
return DoLoadGLNodes(fr, gwalumps);
return DoLoadGLNodes(gwalumps);
}
else
{
@ -928,10 +927,10 @@ bool P_LoadGLNodes(MapData * map)
strcpy(ext, ".gwa");
// Todo: Compare file dates
f_gwa = fopen(path, "rb");
f_gwa = FResourceFile::OpenResourceFile(path, NULL, true);
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);
}
@ -946,23 +945,24 @@ bool P_LoadGLNodes(MapData * map)
result=true;
for(unsigned i=0; i<4;i++)
{
(*fr) >> gwalumps[i].FilePos;
(*fr) >> gwalumps[i].Size;
fr->Read(gwalumps[i].Name, 8);
if (strnicmp(gwalumps[i].Name, check[i], 8))
if (strnicmp(f_gwa->GetLump(i)->Name, check[i], 8))
{
result=false;
break;
}
else
gwalumps[i] = f_gwa->GetLump(i)->NewReader();
}
if (result) result = DoLoadGLNodes(fr, gwalumps);
if (result) result = DoLoadGLNodes(gwalumps);
}
if (f_gwa)
{
delete fr;
fclose(f_gwa);
delete f_gwa;
}
for(unsigned int i = 0;i < 4;++i)
delete gwalumps[i];
return result;
}
else return true;

View file

@ -251,6 +251,7 @@ static int GetMapIndex(const char *mapname, int lastindex, const char *lumpname,
MapData *P_OpenMapData(const char * mapname)
{
MapData * map = new MapData;
FileReader * wadReader = NULL;
bool externalfile = !strnicmp(mapname, "file:", 5);
if (externalfile)
@ -261,8 +262,8 @@ MapData *P_OpenMapData(const char * mapname)
delete map;
return NULL;
}
map->file = new FileReader(mapname);
map->CloseOnDestruct = true;
map->resource = FResourceFile::OpenResourceFile(mapname, NULL, true);
wadReader = map->resource->GetReader();
}
else
{
@ -284,18 +285,13 @@ MapData *P_OpenMapData(const char * mapname)
int lumpfile = Wads.GetLumpFile(lump_name);
int nextfile = Wads.GetLumpFile(lump_name+1);
map->file = Wads.GetFileReader(lumpfile);
map->CloseOnDestruct = false;
map->lumpnum = lump_name;
if (lumpfile != nextfile)
{
// 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].FilePos = 0;
map->MapLumps[0].Size = Wads.LumpLength(lump_name);
map->file = Wads.ReopenLumpNum(lump_name);
map->CloseOnDestruct = true;
map->MapLumps[0].Reader = map->file = Wads.ReopenLumpNum(lump_name);
if (!P_IsBuildMap(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.
// As such any special handling for other types of lumps is skipped.
map->MapLumps[0].FilePos = Wads.GetLumpOffset(lump_name);
map->MapLumps[0].Size = Wads.LumpLength(lump_name);
map->MapLumps[0].Reader = Wads.ReopenLumpNum(lump_name);
map->Encrypted = Wads.IsEncryptedFile(lump_name);
if (map->Encrypted)
{ // If it's encrypted, then it's a Blood file, presumably a map.
map->file = Wads.ReopenLumpNum(lump_name);
map->CloseOnDestruct = true;
map->MapLumps[0].FilePos = 0;
map->MapLumps[0].Reader = map->file = Wads.ReopenLumpNum(lump_name);
if (!P_IsBuildMap(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
// names and for any valid level lump this always returns the short name.
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;
// The next lump is not part of this map anymore
if (index < 0) break;
map->MapLumps[index].FilePos = Wads.GetLumpOffset(lump_name + i);
map->MapLumps[index].Size = Wads.LumpLength(lump_name + i);
map->MapLumps[index].Reader = Wads.ReopenLumpNum(lump_name + i);
strncpy(map->MapLumps[index].Name, lumpname, 8);
}
}
else
{
map->isText = true;
map->MapLumps[1].FilePos = Wads.GetLumpOffset(lump_name + 1);
map->MapLumps[1].Size = Wads.LumpLength(lump_name + 1);
map->MapLumps[1].Reader = Wads.ReopenLumpNum(lump_name + 1);
for(int i = 2;; i++)
{
const char * lumpname = Wads.GetLumpFullName(lump_name + i);
@ -383,8 +374,7 @@ MapData *P_OpenMapData(const char * mapname)
break;
}
else continue;
map->MapLumps[index].FilePos = Wads.GetLumpOffset(lump_name + i);
map->MapLumps[index].Size = Wads.LumpLength(lump_name + i);
map->MapLumps[index].Reader = Wads.ReopenLumpNum(lump_name + i);
strncpy(map->MapLumps[index].Name, lumpname, 8);
}
}
@ -402,42 +392,35 @@ MapData *P_OpenMapData(const char * mapname)
return NULL;
}
map->lumpnum = lump_wad;
map->file = Wads.ReopenLumpNum(lump_wad);
map->CloseOnDestruct = true;
map->resource = FResourceFile::OpenResourceFile(Wads.GetLumpFullName(lump_wad), Wads.ReopenLumpNum(lump_wad), true);
wadReader = map->resource->GetReader();
}
}
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)
{
char maplabel[9]="";
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);
(*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++)
for(DWORD i = 1; i < map->resource->LumpCount(); i++)
{
DWORD offset, size;
char lumpname[8];
const char* lumpname = map->resource->GetLump(i)->Name;
(*map->file) >> offset >> size;
map->file->Read(lumpname, 8);
if (i == 1 && !strnicmp(lumpname, "TEXTMAP", 8))
{
map->isText = true;
map->MapLumps[1].FilePos = offset;
map->MapLumps[1].Size = size;
for(int i = 2;; i++)
{
(*map->file) >> offset >> size;
long v = map->file->Read(lumpname, 8);
lumpname = map->resource->GetLump(i)->Name;
long v = strlen(lumpname);
if (v < 8)
{
I_Error("Invalid map definition for %s", mapname);
@ -469,8 +452,7 @@ MapData *P_OpenMapData(const char * mapname)
return map;
}
else continue;
map->MapLumps[index].FilePos = offset;
map->MapLumps[index].Size = size;
map->MapLumps[index].Reader = map->resource->GetLump(i)->NewReader();
strncpy(map->MapLumps[index].Name, lumpname, 8);
}
}
@ -489,15 +471,14 @@ MapData *P_OpenMapData(const char * mapname)
maplabel[8]=0;
}
map->MapLumps[index].FilePos = offset;
map->MapLumps[index].Size = size;
map->MapLumps[index].Reader = map->resource->GetLump(i)->NewReader();
strncpy(map->MapLumps[index].Name, lumpname, 8);
}
}
else
{
// 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))
{
delete map;
@ -532,29 +513,29 @@ void MapData::GetChecksum(BYTE cksum[16])
{
if (isText)
{
file->Seek(MapLumps[ML_TEXTMAP].FilePos, SEEK_SET);
md5.Update(file, MapLumps[ML_TEXTMAP].Size);
Seek(ML_TEXTMAP);
md5.Update(file, Size(ML_TEXTMAP));
}
else
{
if (MapLumps[ML_LABEL].Size != 0)
if (Size(ML_LABEL) != 0)
{
file->Seek(MapLumps[ML_LABEL].FilePos, SEEK_SET);
md5.Update(file, MapLumps[ML_LABEL].Size);
Seek(ML_LABEL);
md5.Update(file, Size(ML_LABEL));
}
file->Seek(MapLumps[ML_THINGS].FilePos, SEEK_SET);
md5.Update(file, MapLumps[ML_THINGS].Size);
file->Seek(MapLumps[ML_LINEDEFS].FilePos, SEEK_SET);
md5.Update(file, MapLumps[ML_LINEDEFS].Size);
file->Seek(MapLumps[ML_SIDEDEFS].FilePos, SEEK_SET);
md5.Update(file, MapLumps[ML_SIDEDEFS].Size);
file->Seek(MapLumps[ML_SECTORS].FilePos, SEEK_SET);
md5.Update(file, MapLumps[ML_SECTORS].Size);
Seek(ML_THINGS);
md5.Update(file, Size(ML_THINGS));
Seek(ML_LINEDEFS);
md5.Update(file, Size(ML_LINEDEFS));
Seek(ML_SIDEDEFS);
md5.Update(file, Size(ML_SIDEDEFS));
Seek(ML_SECTORS);
md5.Update(file, Size(ML_SECTORS));
}
if (HasBehavior)
{
file->Seek(MapLumps[ML_BEHAVIOR].FilePos, SEEK_SET);
md5.Update(file, MapLumps[ML_BEHAVIOR].Size);
Seek(ML_BEHAVIOR);
md5.Update(file, Size(ML_BEHAVIOR));
}
}
md5.Final(cksum);
@ -834,7 +815,7 @@ void P_LoadVertexes (MapData * map)
// Determine number of vertices:
// 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;
if (numvertexes == 0)
@ -1199,7 +1180,7 @@ void P_LoadSegs (MapData * map)
int dis; // phares 10/4/98
int dx,dy; // 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
@ -1382,7 +1363,7 @@ void P_LoadSubsectors (MapData * map)
int i;
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 )
{
@ -1746,7 +1727,7 @@ void P_LoadThings (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);
char *mtp;
@ -3561,13 +3542,13 @@ void P_SetupLevel (char *lumpname, int position)
// [RH] Support loading Build maps (because I felt like it. :-)
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->file->Read(mapdata, map->MapLumps[0].Size);
map->file->Read(mapdata, map->Size(0));
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();
delete[] mapdata;
}
@ -3704,14 +3685,14 @@ void P_SetupLevel (char *lumpname, int position)
FWadLump test;
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
map->Seek(ML_ZNODES);
idcheck = MAKE_ID('Z','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);
idcheck = MAKE_ID('Z','G','L','N');

View file

@ -23,42 +23,50 @@
#ifndef __P_SETUP__
#define __P_SETUP__
#include "w_wad.h"
#include "resourcefiles/resourcefile.h"
#include "doomdata.h"
struct MapData
{
wadlump_t MapLumps[ML_MAX];
struct
{
char Name[8];
FileReader *Reader;
} MapLumps[ML_MAX];
bool HasBehavior;
bool CloseOnDestruct;
bool Encrypted;
bool isText;
int lumpnum;
FileReader * file;
FResourceFile * resource;
MapData()
{
memset(MapLumps, 0, sizeof(MapLumps));
file = NULL;
resource = NULL;
lumpnum = -1;
HasBehavior = false;
CloseOnDestruct = true;
Encrypted = false;
isText = false;
}
~MapData()
{
if (CloseOnDestruct && file != NULL) delete file;
file = NULL;
for (unsigned int i = 0;i < ML_MAX;++i)
delete MapLumps[i].Reader;
delete resource;
resource = NULL;
}
void Seek(unsigned int lumpindex)
{
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 (size == -1) size = MapLumps[lumpindex].Size;
file->Seek(MapLumps[lumpindex].FilePos, SEEK_SET);
if (size == -1) size = MapLumps[lumpindex].Reader->GetLength();
Seek(lumpindex);
file->Read(buffer, size);
}
}
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;
}

View file

@ -45,6 +45,7 @@
#include "p_udmf.h"
#include "r_state.h"
#include "r_data/colormaps.h"
#include "w_wad.h"
//===========================================================================
//

View file

@ -41,6 +41,7 @@
#include "doomerrors.h"
#include "cmdlib.h"
#include "actor.h"
#include "w_wad.h"
#define Zd 1
#define St 2