mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-30 07:41:22 +00:00
- allow loading uncompressed version of compressed nodes.
- extended FileReader hierarchy so that FileReader, FileReaderZ etc. all inherit from one base class so that the same code can be used to read from both uncompressed and compressed streams. SVN r2287 (trunk)
This commit is contained in:
parent
da99577cbf
commit
c85a602546
2 changed files with 120 additions and 16 deletions
59
src/files.h
59
src/files.h
|
@ -8,7 +8,56 @@
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
#include "m_swap.h"
|
#include "m_swap.h"
|
||||||
|
|
||||||
class FileReader
|
class FileReaderBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~FileReaderBase() {}
|
||||||
|
virtual long Read (void *buffer, long len) = 0;
|
||||||
|
|
||||||
|
FileReaderBase &operator>> (BYTE &v)
|
||||||
|
{
|
||||||
|
Read (&v, 1);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileReaderBase &operator>> (SBYTE &v)
|
||||||
|
{
|
||||||
|
Read (&v, 1);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileReaderBase &operator>> (WORD &v)
|
||||||
|
{
|
||||||
|
Read (&v, 2);
|
||||||
|
v = LittleShort(v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileReaderBase &operator>> (SWORD &v)
|
||||||
|
{
|
||||||
|
Read (&v, 2);
|
||||||
|
v = LittleShort(v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileReaderBase &operator>> (DWORD &v)
|
||||||
|
{
|
||||||
|
Read (&v, 4);
|
||||||
|
v = LittleLong(v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileReaderBase &operator>> (fixed_t &v)
|
||||||
|
{
|
||||||
|
Read (&v, 4);
|
||||||
|
v = LittleLong(v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class FileReader : public FileReaderBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileReader ();
|
FileReader ();
|
||||||
|
@ -82,13 +131,13 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
// Wraps around a FileReader to decompress a zlib stream
|
// Wraps around a FileReader to decompress a zlib stream
|
||||||
class FileReaderZ
|
class FileReaderZ : public FileReaderBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileReaderZ (FileReader &file, bool zip=false);
|
FileReaderZ (FileReader &file, bool zip=false);
|
||||||
~FileReaderZ ();
|
~FileReaderZ ();
|
||||||
|
|
||||||
long Read (void *buffer, long len);
|
virtual long Read (void *buffer, long len);
|
||||||
|
|
||||||
FileReaderZ &operator>> (BYTE &v)
|
FileReaderZ &operator>> (BYTE &v)
|
||||||
{
|
{
|
||||||
|
@ -144,7 +193,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
// Wraps around a FileReader to decompress a bzip2 stream
|
// Wraps around a FileReader to decompress a bzip2 stream
|
||||||
class FileReaderBZ2
|
class FileReaderBZ2 : public FileReaderBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileReaderBZ2 (FileReader &file);
|
FileReaderBZ2 (FileReader &file);
|
||||||
|
@ -206,7 +255,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
// Wraps around a FileReader to decompress a lzma stream
|
// Wraps around a FileReader to decompress a lzma stream
|
||||||
class FileReaderLZMA
|
class FileReaderLZMA : public FileReaderBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileReaderLZMA (FileReader &file, size_t uncompressed_size, bool zip);
|
FileReaderLZMA (FileReader &file, size_t uncompressed_size, bool zip);
|
||||||
|
|
|
@ -793,7 +793,7 @@ void P_LoadVertexes (MapData * map)
|
||||||
//
|
//
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
void P_LoadZSegs (FileReaderZ &data)
|
void P_LoadZSegs (FileReaderBase &data)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numsegs; ++i)
|
for (int i = 0; i < numsegs; ++i)
|
||||||
{
|
{
|
||||||
|
@ -830,7 +830,7 @@ void P_LoadZSegs (FileReaderZ &data)
|
||||||
//
|
//
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
void P_LoadGLZSegs (FileReaderZ &data, DWORD id)
|
void P_LoadGLZSegs (FileReaderBase &data, int type)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numsubsectors; ++i)
|
for (int i = 0; i < numsubsectors; ++i)
|
||||||
{
|
{
|
||||||
|
@ -843,7 +843,7 @@ void P_LoadGLZSegs (FileReaderZ &data, DWORD id)
|
||||||
BYTE side;
|
BYTE side;
|
||||||
|
|
||||||
data >> v1 >> partner;
|
data >> v1 >> partner;
|
||||||
if (id == MAKE_ID('Z','G','L','2'))
|
if (type == 2)
|
||||||
{
|
{
|
||||||
data >> line;
|
data >> line;
|
||||||
}
|
}
|
||||||
|
@ -905,14 +905,12 @@ void P_LoadGLZSegs (FileReaderZ &data, DWORD id)
|
||||||
//
|
//
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
static void P_LoadZNodes (FileReader &dalump, DWORD id)
|
static void LoadZNodes(FileReaderBase &data, int glnodes)
|
||||||
{
|
{
|
||||||
FileReaderZ data (dalump);
|
|
||||||
DWORD i;
|
|
||||||
|
|
||||||
// Read extra vertices added during node building
|
// Read extra vertices added during node building
|
||||||
DWORD orgVerts, newVerts;
|
DWORD orgVerts, newVerts;
|
||||||
vertex_t *newvertarray;
|
vertex_t *newvertarray;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
data >> orgVerts >> newVerts;
|
data >> orgVerts >> newVerts;
|
||||||
if (orgVerts + newVerts == (DWORD)numvertexes)
|
if (orgVerts + newVerts == (DWORD)numvertexes)
|
||||||
|
@ -977,13 +975,13 @@ static void P_LoadZNodes (FileReader &dalump, DWORD id)
|
||||||
segs = new seg_t[numsegs];
|
segs = new seg_t[numsegs];
|
||||||
memset (segs, 0, numsegs*sizeof(seg_t));
|
memset (segs, 0, numsegs*sizeof(seg_t));
|
||||||
|
|
||||||
if (id == MAKE_ID('Z','N','O','D'))
|
if (glnodes == 0)
|
||||||
{
|
{
|
||||||
P_LoadZSegs (data);
|
P_LoadZSegs (data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
P_LoadGLZSegs (data, id);
|
P_LoadGLZSegs (data, glnodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read nodes
|
// Read nodes
|
||||||
|
@ -1029,6 +1027,60 @@ static void P_LoadZNodes (FileReader &dalump, DWORD id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void P_LoadZNodes (FileReader &dalump, DWORD id)
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
bool compressed;
|
||||||
|
|
||||||
|
switch (id)
|
||||||
|
{
|
||||||
|
case MAKE_ID('Z','N','O','D'):
|
||||||
|
type = 0;
|
||||||
|
compressed = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MAKE_ID('Z','G','L','N'):
|
||||||
|
type = 1;
|
||||||
|
compressed = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MAKE_ID('Z','G','L','2'):
|
||||||
|
type = 2;
|
||||||
|
compressed = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MAKE_ID('X','N','O','D'):
|
||||||
|
type = 0;
|
||||||
|
compressed = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MAKE_ID('X','G','L','N'):
|
||||||
|
type = 1;
|
||||||
|
compressed = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MAKE_ID('X','G','L','2'):
|
||||||
|
type = 2;
|
||||||
|
compressed = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compressed)
|
||||||
|
{
|
||||||
|
FileReaderZ data (dalump);
|
||||||
|
LoadZNodes(data, type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadZNodes(dalump, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
// P_CheckV4Nodes
|
// P_CheckV4Nodes
|
||||||
|
@ -3559,12 +3611,13 @@ void P_SetupLevel (char *lumpname, int position)
|
||||||
{
|
{
|
||||||
// Check for compressed nodes first, then uncompressed nodes
|
// Check for compressed nodes first, then uncompressed nodes
|
||||||
FWadLump test;
|
FWadLump test;
|
||||||
DWORD id = MAKE_ID('X','x','X','x'), idcheck = 0, idcheck2 = 0;
|
DWORD id = MAKE_ID('X','x','X','x'), idcheck = 0, idcheck2 = 0, idcheck3 = 0, idcheck4 = 0;
|
||||||
|
|
||||||
if (map->MapLumps[ML_ZNODES].Size != 0 && !UsingGLNodes)
|
if (map->MapLumps[ML_ZNODES].Size != 0 && !UsingGLNodes)
|
||||||
{
|
{
|
||||||
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');
|
||||||
}
|
}
|
||||||
else if (map->MapLumps[ML_GLZNODES].Size != 0)
|
else if (map->MapLumps[ML_GLZNODES].Size != 0)
|
||||||
{
|
{
|
||||||
|
@ -3572,10 +3625,12 @@ void P_SetupLevel (char *lumpname, int position)
|
||||||
map->Seek(ML_GLZNODES);
|
map->Seek(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('X','G','L','N');
|
||||||
|
idcheck4 = MAKE_ID('X','G','L','2');
|
||||||
}
|
}
|
||||||
|
|
||||||
map->file->Read (&id, 4);
|
map->file->Read (&id, 4);
|
||||||
if (id == idcheck || id == idcheck2)
|
if (id == idcheck || id == idcheck2 || id == idcheck3 || id == idcheck4)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue