mirror of
https://github.com/ZDoom/zdbsp.git
synced 2024-11-28 22:52:08 +00:00
- UDMF implementation for ZDBSP.
SVN r1482 (trunk)
This commit is contained in:
parent
9f300f1b06
commit
bf47221046
14 changed files with 768 additions and 167 deletions
13
doomdata.h
13
doomdata.h
|
@ -14,8 +14,8 @@ enum
|
|||
|
||||
struct UDMFKey
|
||||
{
|
||||
int key;
|
||||
int value;
|
||||
const char *key;
|
||||
const char *value;
|
||||
};
|
||||
|
||||
struct MapVertex
|
||||
|
@ -26,6 +26,7 @@ struct MapVertex
|
|||
struct WideVertex
|
||||
{
|
||||
fixed_t x, y;
|
||||
int index;
|
||||
};
|
||||
|
||||
struct MapSideDef
|
||||
|
@ -201,12 +202,18 @@ struct IntThing
|
|||
TArray<UDMFKey> props;
|
||||
};
|
||||
|
||||
struct IntVertex
|
||||
{
|
||||
TArray<UDMFKey> props;
|
||||
};
|
||||
|
||||
struct FLevel
|
||||
{
|
||||
FLevel ();
|
||||
~FLevel ();
|
||||
|
||||
WideVertex *Vertices; int NumVertices;
|
||||
TArray<IntVertex> VertexProps;
|
||||
TArray<IntSideDef> Sides;
|
||||
TArray<IntLineDef> Lines;
|
||||
TArray<IntSector> Sectors;
|
||||
|
@ -229,6 +236,8 @@ struct FLevel
|
|||
|
||||
fixed_t MinX, MinY, MaxX, MaxY;
|
||||
|
||||
TArray<UDMFKey> props;
|
||||
|
||||
void FindMapBounds ();
|
||||
void RemoveExtraLines ();
|
||||
void RemoveExtraSides ();
|
||||
|
|
|
@ -778,6 +778,7 @@ void FNodeBuilder::SplitSegs (DWORD set, node_t &node, DWORD splitseg, DWORD &ou
|
|||
newvert.y = Vertices[seg->v1].y;
|
||||
newvert.x += fixed_t(frac * double(Vertices[seg->v2].x - newvert.x));
|
||||
newvert.y += fixed_t(frac * double(Vertices[seg->v2].y - newvert.y));
|
||||
newvert.index = 0;
|
||||
vertnum = VertexMap->SelectVertexClose (newvert);
|
||||
|
||||
seg2 = SplitSeg (set, vertnum, sidev1);
|
||||
|
|
|
@ -50,7 +50,7 @@ class FNodeBuilder
|
|||
struct FPrivSeg
|
||||
{
|
||||
int v1, v2;
|
||||
int sidedef;
|
||||
DWORD sidedef;
|
||||
int linedef;
|
||||
int frontsector;
|
||||
int backsector;
|
||||
|
@ -72,6 +72,7 @@ class FNodeBuilder
|
|||
fixed_t x, y;
|
||||
DWORD segs; // segs that use this vertex as v1
|
||||
DWORD segs2; // segs that use this vertex as v2
|
||||
int index;
|
||||
|
||||
bool operator== (const FPrivVert &other)
|
||||
{
|
||||
|
|
|
@ -358,7 +358,7 @@ void FNodeBuilder::PushConnectingGLSeg (int subsector, TArray<MapSegGLEx> &segs,
|
|||
|
||||
newseg.v1 = v1;
|
||||
newseg.v2 = v2;
|
||||
newseg.linedef = NO_INDEX;
|
||||
newseg.linedef = NO_MAP_INDEX;
|
||||
newseg.side = 0;
|
||||
newseg.partner = DWORD_MAX;
|
||||
segs.Push (newseg);
|
||||
|
@ -373,6 +373,7 @@ void FNodeBuilder::GetVertices (WideVertex *&verts, int &count)
|
|||
{
|
||||
verts[i].x = Vertices[i].x;
|
||||
verts[i].y = Vertices[i].y;
|
||||
verts[i].index = Vertices[i].index;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,12 +62,14 @@ void FNodeBuilder::FindUsedVertices (WideVertex *oldverts, int max)
|
|||
{
|
||||
newvert.x = oldverts[v1].x;
|
||||
newvert.y = oldverts[v1].y;
|
||||
newvert.index = oldverts[v1].index;
|
||||
map[v1] = VertexMap->SelectVertexExact (newvert);
|
||||
}
|
||||
if (map[v2] == -1)
|
||||
{
|
||||
newvert.x = oldverts[v2].x;
|
||||
newvert.y = oldverts[v2].y;
|
||||
newvert.index = oldverts[v2].index;
|
||||
map[v2] = VertexMap->SelectVertexExact (newvert);
|
||||
}
|
||||
|
||||
|
|
|
@ -179,8 +179,8 @@ void FProcessor::LoadLines ()
|
|||
Level.Lines[i].flags = LittleShort(Lines[i].flags);
|
||||
Level.Lines[i].sidenum[0] = LittleShort(Lines[i].sidenum[0]);
|
||||
Level.Lines[i].sidenum[1] = LittleShort(Lines[i].sidenum[1]);
|
||||
if (Level.Lines[i].sidenum[0] == 0xffff) Level.Lines[i].sidenum[0] = NO_INDEX;
|
||||
if (Level.Lines[i].sidenum[1] == 0xffff) Level.Lines[i].sidenum[1] = NO_INDEX;
|
||||
if (Level.Lines[i].sidenum[0] == NO_MAP_INDEX) Level.Lines[i].sidenum[0] = NO_INDEX;
|
||||
if (Level.Lines[i].sidenum[1] == NO_MAP_INDEX) Level.Lines[i].sidenum[1] = NO_INDEX;
|
||||
}
|
||||
delete[] Lines;
|
||||
}
|
||||
|
@ -197,8 +197,8 @@ void FProcessor::LoadLines ()
|
|||
Level.Lines[i].flags = LittleShort(ml[i].flags);
|
||||
Level.Lines[i].sidenum[0] = LittleShort(ml[i].sidenum[0]);
|
||||
Level.Lines[i].sidenum[1] = LittleShort(ml[i].sidenum[1]);
|
||||
if (Level.Lines[i].sidenum[0] == 0xffff) Level.Lines[i].sidenum[0] = NO_INDEX;
|
||||
if (Level.Lines[i].sidenum[1] == 0xffff) Level.Lines[i].sidenum[1] = NO_INDEX;
|
||||
if (Level.Lines[i].sidenum[0] == NO_MAP_INDEX) Level.Lines[i].sidenum[0] = NO_INDEX;
|
||||
if (Level.Lines[i].sidenum[1] == NO_MAP_INDEX) Level.Lines[i].sidenum[1] = NO_INDEX;
|
||||
|
||||
// Store the special and tag in the args array so we don't lose them
|
||||
Level.Lines[i].special = 0;
|
||||
|
@ -220,6 +220,7 @@ void FProcessor::LoadVertices ()
|
|||
{
|
||||
Level.Vertices[i].x = LittleShort(verts[i].x) << FRACBITS;
|
||||
Level.Vertices[i].y = LittleShort(verts[i].y) << FRACBITS;
|
||||
Level.Vertices[i].index = 0; // we don't need this value for non-UDMF maps
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,7 +240,7 @@ void FProcessor::LoadSides ()
|
|||
memcpy(Level.Sides[i].midtexture, Sides[i].midtexture, 8);
|
||||
|
||||
Level.Sides[i].sector = LittleShort(Sides[i].sector);
|
||||
if (Level.Sides[i].sector == 0xffff) Level.Sides[i].sector = NO_INDEX;
|
||||
if (Level.Sides[i].sector == NO_MAP_INDEX) Level.Sides[i].sector = NO_INDEX;
|
||||
}
|
||||
delete [] Sides;
|
||||
}
|
||||
|
@ -531,6 +532,11 @@ void FProcessor::Write (FWadWriter &out)
|
|||
}
|
||||
else
|
||||
{
|
||||
for(int i=Lump; stricmp(Wad.LumpName(i), "ENDMAP") && i < Wad.NumLumps(); i++)
|
||||
{
|
||||
out.CopyLump(Wad, i);
|
||||
}
|
||||
out.CreateLabel("ENDMAP");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -557,8 +563,15 @@ void FProcessor::Write (FWadWriter &out)
|
|||
{
|
||||
FNodeBuilder *builder = NULL;
|
||||
|
||||
// UDMF spec requires GL nodes.
|
||||
if (isUDMF) BuildGLNodes = true;
|
||||
// ZDoom's UDMF spec requires compressed GL nodes.
|
||||
// No other UDMF spec has defined anything regarding nodes yet.
|
||||
if (isUDMF)
|
||||
{
|
||||
BuildGLNodes = true;
|
||||
ConformNodes = false;
|
||||
GLOnly = true;
|
||||
CompressGLNodes = true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -641,6 +654,8 @@ void FProcessor::Write (FWadWriter &out)
|
|||
}
|
||||
}
|
||||
|
||||
if (!isUDMF)
|
||||
{
|
||||
FBlockmapBuilder bbuilder (Level);
|
||||
WORD *blocks = bbuilder.GetBlockmap (Level.BlockmapSize);
|
||||
Level.Blockmap = new WORD[Level.BlockmapSize];
|
||||
|
@ -695,6 +710,7 @@ void FProcessor::Write (FWadWriter &out)
|
|||
memset (Level.Reject, 0, Level.RejectSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ShowMap)
|
||||
{
|
||||
|
@ -712,6 +728,9 @@ void FProcessor::Write (FWadWriter &out)
|
|||
#endif
|
||||
}
|
||||
|
||||
if (!isUDMF)
|
||||
{
|
||||
|
||||
if (Level.GLNodes != NULL )
|
||||
{
|
||||
gl5 = V5GLNodes ||
|
||||
|
@ -804,6 +823,11 @@ void FProcessor::Write (FWadWriter &out)
|
|||
WriteGLSSect (out, gl5);
|
||||
WriteGLNodes (out, gl5);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteUDMF(out);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
|
20
processor.h
20
processor.h
|
@ -87,6 +87,26 @@ private:
|
|||
void WriteNodes5 (FWadWriter &out, const char *name, const MapNodeEx *zaNodes, int count) const;
|
||||
void WriteSSectors5 (FWadWriter &out, const char *name, const MapSubsectorEx *zaSubs, int count) const;
|
||||
|
||||
const char *ParseKey(const char *&value);
|
||||
bool CheckKey(const char *&key, const char *&value);
|
||||
void ParseThing(IntThing *th);
|
||||
void ParseLinedef(IntLineDef *ld);
|
||||
void ParseSidedef(IntSideDef *sd);
|
||||
void ParseSector(IntSector *sec);
|
||||
void ParseVertex(WideVertex *vt, IntVertex *vtp);
|
||||
void ParseMapProperties();
|
||||
void ParseTextMap(int lump);
|
||||
|
||||
void WriteProps(FWadWriter &out, TArray<UDMFKey> &props);
|
||||
void WriteIntProp(FWadWriter &out, const char *key, int value);
|
||||
void WriteThingUDMF(FWadWriter &out, IntThing *th);
|
||||
void WriteLinedefUDMF(FWadWriter &out, IntLineDef *ld);
|
||||
void WriteSidedefUDMF(FWadWriter &out, IntSideDef *sd);
|
||||
void WriteSectorUDMF(FWadWriter &out, IntSector *sec);
|
||||
void WriteVertexUDMF(FWadWriter &out, IntVertex *vt);
|
||||
void WriteTextMap(FWadWriter &out);
|
||||
void WriteUDMF(FWadWriter &out);
|
||||
|
||||
FLevel Level;
|
||||
|
||||
TArray<FNodeBuilder::FPolyStart> PolyStarts;
|
||||
|
|
|
@ -1,7 +1,559 @@
|
|||
/*
|
||||
Reads and writes UDMF maps
|
||||
Copyright (C) 2009 Christoph Oelckers
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <float.h>
|
||||
#include "processor.h"
|
||||
#include "sc_man.h"
|
||||
|
||||
|
||||
class StringBuffer
|
||||
{
|
||||
const static int BLOCK_SIZE = 100000;
|
||||
const static int BLOCK_ALIGN = sizeof(size_t);
|
||||
|
||||
TDeletingArray<char *> blocks;
|
||||
size_t currentindex;
|
||||
|
||||
char *Alloc(size_t size)
|
||||
{
|
||||
if (currentindex + size >= BLOCK_SIZE)
|
||||
{
|
||||
// Block is full - get a new one!
|
||||
char *newblock = new char[BLOCK_SIZE];
|
||||
blocks.Push(newblock);
|
||||
currentindex = 0;
|
||||
}
|
||||
size = (size + BLOCK_ALIGN-1) &~ (BLOCK_ALIGN-1);
|
||||
char *p = blocks[blocks.Size()-1] + currentindex;
|
||||
currentindex += size;
|
||||
return p;
|
||||
}
|
||||
public:
|
||||
|
||||
StringBuffer()
|
||||
{
|
||||
currentindex = BLOCK_SIZE;
|
||||
}
|
||||
|
||||
char * Copy(const char * p)
|
||||
{
|
||||
return p != NULL? strcpy(Alloc(strlen(p)+1) , p) : NULL;
|
||||
}
|
||||
};
|
||||
|
||||
StringBuffer stbuf;
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Parses a 'key = value;' line of the map
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
const char *FProcessor::ParseKey(const char *&value)
|
||||
{
|
||||
SC_MustGetString();
|
||||
const char *key = stbuf.Copy(sc_String);
|
||||
SC_MustGetStringName("=");
|
||||
|
||||
sc_Number = INT_MIN;
|
||||
sc_Float = DBL_MIN;
|
||||
if (!SC_CheckFloat())
|
||||
{
|
||||
SC_MustGetString();
|
||||
}
|
||||
value = stbuf.Copy(sc_String);
|
||||
SC_MustGetStringName(";");
|
||||
return key;
|
||||
}
|
||||
|
||||
bool FProcessor::CheckKey(const char *&key, const char *&value)
|
||||
{
|
||||
SC_SavePos();
|
||||
SC_MustGetString();
|
||||
if (SC_CheckString("="))
|
||||
{
|
||||
SC_RestorePos();
|
||||
key = ParseKey(value);
|
||||
return true;
|
||||
}
|
||||
SC_RestorePos();
|
||||
return false;
|
||||
}
|
||||
|
||||
int CheckInt(const char *key)
|
||||
{
|
||||
if (sc_Number == INT_MIN)
|
||||
{
|
||||
SC_ScriptError("Integer value expected for key '%s'", key);
|
||||
}
|
||||
return sc_Number;
|
||||
}
|
||||
|
||||
double CheckFloat(const char *key)
|
||||
{
|
||||
if (sc_Float == DBL_MIN)
|
||||
{
|
||||
SC_ScriptError("Floating point value expected for key '%s'", key);
|
||||
}
|
||||
return sc_Float;
|
||||
}
|
||||
|
||||
fixed_t CheckFixed(const char *key)
|
||||
{
|
||||
return (fixed_t)(CheckFloat(key)*65536.);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Parse a thing block
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::ParseThing(IntThing *th)
|
||||
{
|
||||
SC_MustGetStringName("{");
|
||||
while (!SC_CheckString("}"))
|
||||
{
|
||||
const char *value;
|
||||
const char *key = ParseKey(value);
|
||||
|
||||
// The only properties we need from a thing are
|
||||
// x, y, angle and type.
|
||||
|
||||
if (!stricmp(key, "x"))
|
||||
{
|
||||
th->x = CheckFixed(key);
|
||||
}
|
||||
else if (!stricmp(key, "y"))
|
||||
{
|
||||
th->y = CheckFixed(key);
|
||||
}
|
||||
if (!stricmp(key, "angle"))
|
||||
{
|
||||
th->angle = (short)CheckInt(key);
|
||||
}
|
||||
if (!stricmp(key, "type"))
|
||||
{
|
||||
th->type = (short)CheckInt(key);
|
||||
}
|
||||
|
||||
// now store the key in its unprocessed form
|
||||
UDMFKey k = {key, value};
|
||||
th->props.Push(k);
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Parse a linedef block
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::ParseLinedef(IntLineDef *ld)
|
||||
{
|
||||
SC_MustGetStringName("{");
|
||||
ld->v1 = ld->v2 = ld->sidenum[0] = ld->sidenum[1] = NO_INDEX;
|
||||
ld->special = 0;
|
||||
while (!SC_CheckString("}"))
|
||||
{
|
||||
const char *value;
|
||||
const char *key = ParseKey(value);
|
||||
|
||||
if (!stricmp(key, "v1"))
|
||||
{
|
||||
ld->v1 = CheckInt(key);
|
||||
continue; // do not store in props
|
||||
}
|
||||
else if (!stricmp(key, "v2"))
|
||||
{
|
||||
ld->v2 = CheckInt(key);
|
||||
continue; // do not store in props
|
||||
}
|
||||
else if (Extended && !stricmp(key, "special"))
|
||||
{
|
||||
ld->special = CheckInt(key);
|
||||
}
|
||||
else if (Extended && !stricmp(key, "arg0"))
|
||||
{
|
||||
ld->args[0] = CheckInt(key);
|
||||
}
|
||||
if (!stricmp(key, "sidefront"))
|
||||
{
|
||||
ld->sidenum[0] = CheckInt(key);
|
||||
continue; // do not store in props
|
||||
}
|
||||
else if (!stricmp(key, "sideback"))
|
||||
{
|
||||
ld->sidenum[1] = CheckInt(key);
|
||||
continue; // do not store in props
|
||||
}
|
||||
|
||||
// now store the key in its unprocessed form
|
||||
UDMFKey k = {key, value};
|
||||
ld->props.Push(k);
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Parse a sidedef block
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::ParseSidedef(IntSideDef *sd)
|
||||
{
|
||||
SC_MustGetStringName("{");
|
||||
sd->sector = NO_INDEX;
|
||||
while (!SC_CheckString("}"))
|
||||
{
|
||||
const char *value;
|
||||
const char *key = ParseKey(value);
|
||||
|
||||
if (!stricmp(key, "sector"))
|
||||
{
|
||||
sd->sector = CheckInt(key);
|
||||
continue; // do not store in props
|
||||
}
|
||||
|
||||
// now store the key in its unprocessed form
|
||||
UDMFKey k = {key, value};
|
||||
sd->props.Push(k);
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Parse a sidedef block
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::ParseSector(IntSector *sec)
|
||||
{
|
||||
SC_MustGetStringName("{");
|
||||
while (!SC_CheckString("}"))
|
||||
{
|
||||
const char *value;
|
||||
const char *key = ParseKey(value);
|
||||
|
||||
// No specific sector properties are ever used by the node builder
|
||||
// so everything can go directly to the props array.
|
||||
|
||||
// now store the key in its unprocessed form
|
||||
UDMFKey k = {key, value};
|
||||
sec->props.Push(k);
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// parse a vertex block
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::ParseVertex(WideVertex *vt, IntVertex *vtp)
|
||||
{
|
||||
vt->x = vt->y = 0;
|
||||
SC_MustGetStringName("{");
|
||||
while (!SC_CheckString("}"))
|
||||
{
|
||||
const char *value;
|
||||
const char *key = ParseKey(value);
|
||||
|
||||
if (!stricmp(key, "x"))
|
||||
{
|
||||
vt->x = CheckFixed(key);
|
||||
}
|
||||
else if (!stricmp(key, "y"))
|
||||
{
|
||||
vt->y = CheckFixed(key);
|
||||
}
|
||||
|
||||
// now store the key in its unprocessed form
|
||||
UDMFKey k = {key, value};
|
||||
vtp->props.Push(k);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// parses global map properties
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::ParseMapProperties()
|
||||
{
|
||||
const char *key, *value;
|
||||
|
||||
// all global keys must come before the first map element.
|
||||
|
||||
while (CheckKey(key, value))
|
||||
{
|
||||
if (!stricmp(key, "namespace"))
|
||||
{
|
||||
// all unknown namespaces are assumed to be standard.
|
||||
Extended = !stricmp(value, "ZDoom") || !stricmp(value, "Hexen") || !stricmp(value, "Vavoom");
|
||||
}
|
||||
|
||||
// now store the key in its unprocessed form
|
||||
UDMFKey k = {key, value};
|
||||
Level.props.Push(k);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Main parsing function
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::ParseTextMap(int lump)
|
||||
{
|
||||
char *buffer;
|
||||
int buffersize;
|
||||
TArray<WideVertex> Vertices;
|
||||
|
||||
ReadLump<char> (Wad, lump, buffer, buffersize);
|
||||
SC_OpenMem("TEXTMAP", buffer, buffersize);
|
||||
|
||||
SC_SetCMode(true);
|
||||
ParseMapProperties();
|
||||
|
||||
while (SC_GetString())
|
||||
{
|
||||
if (SC_Compare("thing"))
|
||||
{
|
||||
IntThing *th = &Level.Things[Level.Things.Reserve(1)];
|
||||
ParseThing(th);
|
||||
}
|
||||
else if (SC_Compare("linedef"))
|
||||
{
|
||||
IntLineDef *ld = &Level.Lines[Level.Lines.Reserve(1)];
|
||||
ParseLinedef(ld);
|
||||
}
|
||||
else if (SC_Compare("sidedef"))
|
||||
{
|
||||
IntSideDef *sd = &Level.Sides[Level.Sides.Reserve(1)];
|
||||
ParseSidedef(sd);
|
||||
}
|
||||
else if (SC_Compare("sector"))
|
||||
{
|
||||
IntSector *sec = &Level.Sectors[Level.Sectors.Reserve(1)];
|
||||
ParseSector(sec);
|
||||
}
|
||||
else if (SC_Compare("vertex"))
|
||||
{
|
||||
WideVertex *vt = &Vertices[Vertices.Reserve(1)];
|
||||
IntVertex *vtp = &Level.VertexProps[Level.VertexProps.Reserve(1)];
|
||||
vt->index = Vertices.Size();
|
||||
ParseVertex(vt, vtp);
|
||||
}
|
||||
}
|
||||
Level.Vertices = new WideVertex[Vertices.Size()];
|
||||
Level.NumVertices = Vertices.Size();
|
||||
memcpy(Level.Vertices, &Vertices[0], Vertices.Size() * sizeof(WideVertex));
|
||||
SC_Close();
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// parse an UDMF map
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::LoadUDMF()
|
||||
{
|
||||
ParseTextMap(Lump+1);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// writes a property list
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::WriteProps(FWadWriter &out, TArray<UDMFKey> &props)
|
||||
{
|
||||
for(unsigned i=0; i< props.Size(); i++)
|
||||
{
|
||||
out.AddToLump(props[i].key, (int)strlen(props[i].key));
|
||||
out.AddToLump(" = ", 3);
|
||||
out.AddToLump(props[i].value, (int)strlen(props[i].value));
|
||||
out.AddToLump(";\n", 2);
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// writes an integer property
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::WriteIntProp(FWadWriter &out, const char *key, int value)
|
||||
{
|
||||
char buffer[20];
|
||||
|
||||
out.AddToLump(key, (int)strlen(key));
|
||||
out.AddToLump(" = ", 3);
|
||||
sprintf(buffer, "%d;\n", value);
|
||||
out.AddToLump(buffer, (int)strlen(buffer));
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// writes an UDMF thing
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::WriteThingUDMF(FWadWriter &out, IntThing *th)
|
||||
{
|
||||
out.AddToLump("thing\n{\n", 8);
|
||||
WriteProps(out, th->props);
|
||||
out.AddToLump("}\n\n", 3);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// writes an UDMF linedef
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::WriteLinedefUDMF(FWadWriter &out, IntLineDef *ld)
|
||||
{
|
||||
out.AddToLump("linedef\n{\n", 10);
|
||||
WriteIntProp(out, "v1", ld->v1);
|
||||
WriteIntProp(out, "v2", ld->v2);
|
||||
if (ld->sidenum[0] != NO_INDEX) WriteIntProp(out, "sidefront", ld->sidenum[0]);
|
||||
if (ld->sidenum[1] != NO_INDEX) WriteIntProp(out, "sideback", ld->sidenum[1]);
|
||||
WriteProps(out, ld->props);
|
||||
out.AddToLump("}\n\n", 3);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// writes an UDMF sidedef
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::WriteSidedefUDMF(FWadWriter &out, IntSideDef *sd)
|
||||
{
|
||||
out.AddToLump("sidedef\n{\n", 10);
|
||||
WriteIntProp(out, "sector", sd->sector);
|
||||
WriteProps(out, sd->props);
|
||||
out.AddToLump("}\n\n", 3);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// writes an UDMF sector
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::WriteSectorUDMF(FWadWriter &out, IntSector *sec)
|
||||
{
|
||||
out.AddToLump("sector\n{\n", 9);
|
||||
WriteProps(out, sec->props);
|
||||
out.AddToLump("}\n\n", 3);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// writes an UDMF vertex
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::WriteVertexUDMF(FWadWriter &out, IntVertex *vt)
|
||||
{
|
||||
out.AddToLump("vertex\n{\n", 9);
|
||||
WriteProps(out, vt->props);
|
||||
out.AddToLump("}\n\n", 3);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// writes an UDMF vertex
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::WriteTextMap(FWadWriter &out)
|
||||
{
|
||||
out.StartWritingLump("TEXTMAP");
|
||||
WriteProps(out, Level.props);
|
||||
for(int i = 0; i < Level.NumThings(); i++)
|
||||
{
|
||||
WriteThingUDMF(out, &Level.Things[i]);
|
||||
}
|
||||
|
||||
for(int i = 0; i < Level.NumOrgVerts; i++)
|
||||
{
|
||||
WideVertex *vt = &Level.Vertices[i];
|
||||
if (vt->index <= 0)
|
||||
{
|
||||
// not valid!
|
||||
throw std::runtime_error("Invalid vertex data.");
|
||||
}
|
||||
WriteVertexUDMF(out, &Level.VertexProps[vt->index-1]);
|
||||
}
|
||||
|
||||
for(int i = 0; i < Level.NumLines(); i++)
|
||||
{
|
||||
WriteLinedefUDMF(out, &Level.Lines[i]);
|
||||
}
|
||||
|
||||
for(int i = 0; i < Level.NumSides(); i++)
|
||||
{
|
||||
WriteSidedefUDMF(out, &Level.Sides[i]);
|
||||
}
|
||||
|
||||
for(int i = 0; i < Level.NumSectors(); i++)
|
||||
{
|
||||
WriteSectorUDMF(out, &Level.Sectors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// writes an UDMF vertex
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FProcessor::WriteUDMF(FWadWriter &out)
|
||||
{
|
||||
out.CopyLump (Wad, Lump);
|
||||
WriteTextMap(out);
|
||||
WriteGLBSPZ (out, "ZNODES");
|
||||
// copy everything except existing nodes, blockmap and reject
|
||||
for(int i=Lump+2; stricmp(Wad.LumpName(i), "ENDMAP") && i < Wad.NumLumps(); i++)
|
||||
{
|
||||
const char *lumpname = Wad.LumpName(i);
|
||||
if (stricmp(lumpname, "ZNODES") &&
|
||||
stricmp(lumpname, "BLOCKMAP") &&
|
||||
stricmp(lumpname, "REJECT"))
|
||||
{
|
||||
out.CopyLump(Wad, i);
|
||||
}
|
||||
}
|
||||
out.CreateLabel("ENDMAP");
|
||||
}
|
||||
|
|
39
sc_man.cpp
39
sc_man.cpp
|
@ -60,7 +60,7 @@ static void CheckOpen (void);
|
|||
char *sc_String;
|
||||
int sc_StringLen;
|
||||
int sc_Number;
|
||||
float sc_Float;
|
||||
double sc_Float;
|
||||
int sc_Line;
|
||||
bool sc_End;
|
||||
bool sc_Crossed;
|
||||
|
@ -87,31 +87,15 @@ static bool CMode;
|
|||
//
|
||||
// SC_OpenFile
|
||||
//
|
||||
// Loads a script (from a file). Uses the new/delete memory allocator for
|
||||
// memory allocation and de-allocation.
|
||||
// Loads a script
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void SC_OpenFile (const char *name)
|
||||
void SC_OpenMem (const char *name, char *buffer, int len)
|
||||
{
|
||||
SC_Close ();
|
||||
FILE * f = fopen(name, "rb");
|
||||
if (f == NULL)
|
||||
{
|
||||
printf("%s: file not found\n", name);
|
||||
exit(1);
|
||||
}
|
||||
fseek(f, 0, SEEK_END);
|
||||
ScriptSize = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
ScriptBuffer = (char*)malloc(ScriptSize);
|
||||
if (ScriptSize != int(fread(ScriptBuffer, 1, ScriptSize, f)))
|
||||
{
|
||||
fclose(f);
|
||||
printf("%s: unable to read file\n", name);
|
||||
exit(1);
|
||||
}
|
||||
fclose(f);
|
||||
ScriptSize = len;
|
||||
ScriptBuffer = buffer;
|
||||
SC_PrepareScript ();
|
||||
}
|
||||
|
||||
|
@ -146,10 +130,6 @@ void SC_Close (void)
|
|||
{
|
||||
if (ScriptOpen)
|
||||
{
|
||||
if (ScriptBuffer)
|
||||
{
|
||||
free(ScriptBuffer);
|
||||
}
|
||||
ScriptBuffer = NULL;
|
||||
ScriptOpen = false;
|
||||
}
|
||||
|
@ -456,7 +436,7 @@ bool SC_GetNumber (void)
|
|||
SC_ScriptError ("SC_GetNumber: Bad numeric constant \"%s\".", sc_String);
|
||||
}
|
||||
}
|
||||
sc_Float = (float)sc_Number;
|
||||
sc_Float = sc_Number;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -507,7 +487,7 @@ bool SC_CheckNumber (void)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
sc_Float = (float)sc_Number;
|
||||
sc_Float = sc_Number;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -530,7 +510,8 @@ bool SC_CheckFloat (void)
|
|||
//CheckOpen ();
|
||||
if (SC_GetString())
|
||||
{
|
||||
sc_Float = (float)strtod (sc_String, &stopper);
|
||||
sc_Float = strtod (sc_String, &stopper);
|
||||
sc_Number = (int)sc_Float;
|
||||
if (*stopper != 0)
|
||||
{
|
||||
SC_UnGet();
|
||||
|
@ -558,7 +539,7 @@ bool SC_GetFloat (void)
|
|||
CheckOpen ();
|
||||
if (SC_GetString())
|
||||
{
|
||||
sc_Float = (float)strtod (sc_String, &stopper);
|
||||
sc_Float = strtod (sc_String, &stopper);
|
||||
if (*stopper != 0)
|
||||
{
|
||||
SC_ScriptError("SC_GetFloat: Bad numeric constant \"%s\".\n",sc_String);
|
||||
|
|
2
sc_man.h
2
sc_man.h
|
@ -32,7 +32,7 @@ void SC_RestoreScriptState();
|
|||
extern char *sc_String;
|
||||
extern int sc_StringLen;
|
||||
extern int sc_Number;
|
||||
extern float sc_Float;
|
||||
extern double sc_Float;
|
||||
extern int sc_Line;
|
||||
extern bool sc_End;
|
||||
extern bool sc_Crossed;
|
||||
|
|
10
view.cpp
10
view.cpp
|
@ -1010,10 +1010,20 @@ void ShowView (FLevel *level)
|
|||
{
|
||||
Level = level;
|
||||
|
||||
if (level->Blockmap != NULL)
|
||||
{
|
||||
MapBounds.left = short(level->Blockmap[0]) - 8;
|
||||
MapBounds.right = short(level->Blockmap[0]) + (level->Blockmap[2] << BLOCKBITS) + 8;
|
||||
MapBounds.top = short(level->Blockmap[1]) - 8;
|
||||
MapBounds.bottom = short(level->Blockmap[1]) + (level->Blockmap[3] << BLOCKBITS) + 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
MapBounds.left = level->MinX >> FRACBITS;
|
||||
MapBounds.right = level->MaxX >> FRACBITS;
|
||||
MapBounds.top = level->MinY >> FRACBITS;
|
||||
MapBounds.bottom = level->MaxY >> FRACBITS;
|
||||
}
|
||||
MapSize.x = MapBounds.right - MapBounds.left;
|
||||
MapSize.y = MapBounds.bottom - MapBounds.top;
|
||||
Divisor = 1;
|
||||
|
|
2
wad.cpp
2
wad.cpp
|
@ -303,7 +303,7 @@ int FWadReader::LumpAfterMap (int i) const
|
|||
{
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
return i+1; // one lump after ENDMAP
|
||||
}
|
||||
|
||||
i++;
|
||||
|
|
4
zdbsp.h
4
zdbsp.h
|
@ -66,8 +66,8 @@ typedef uint32_t angle_t;
|
|||
|
||||
angle_t PointToAngle (fixed_t x, fixed_t y);
|
||||
|
||||
static const DWORD NO_MAP_INDEX = 0xffffffff;
|
||||
static const WORD NO_INDEX = 0xffff;
|
||||
static const WORD NO_MAP_INDEX = 0xffff;
|
||||
static const DWORD NO_INDEX = 0xffffffff;
|
||||
static const angle_t ANGLE_MAX = 0xffffffff;
|
||||
static const DWORD DWORD_MAX = 0xffffffff;
|
||||
static const angle_t ANGLE_180 = (1u<<31);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
# Visual C++ Express 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zdbsp_vs2005", "zdbsp_vs2005.vcproj", "{E628034A-AE64-43B5-8CF4-668D07041C35}"
|
||||
EndProject
|
||||
Global
|
||||
|
|
Loading…
Reference in a new issue