diff --git a/Makefile b/Makefile index f5a4b74..1304431 100644 --- a/Makefile +++ b/Makefile @@ -27,18 +27,18 @@ else endif # To generate profiling information for gprof, pass gprof=1 to make. -ifneq ($(gprof),) +ifeq ($(gprof),1) CFLAGS += -g -fno-omit-frame-pointer -pg LDFLAGS += -g -pg endif # To strip debugging symbols, pass strip=1 to make. -ifneq ($(strip),) +ifeq ($(strip),1) LDFLAGS += -s endif # To use SSE2 math for everything, pass sse=1 to make. -ifneq ($(sse),) +ifeq ($(sse),1) CFLAGS += -msse -msse2 -mfpmath=sse endif @@ -52,6 +52,10 @@ OBJS = main.o getopt.o getopt1.o blockmapbuilder.o processor.o view.o wad.o \ nodebuild_utility.o nodebuild_classify_sse2.o nodebuild_classify_nosse2.o \ zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/deflate.o zlib/trees.o \ zlib/zutil.o + +ifeq (Windows_NT,$(OS)) + OBJS += resource.o +endif all: $(EXE) @@ -70,6 +74,9 @@ $(EXE): $(OBJS) nodebuild_classify_sse2.o: nodebuild_classify_sse2.cpp nodebuild.h $(CXX) $(CXXFLAGS) -msse2 -mfpmath=sse -c -o $@ $< +resource.o: resource.rc + windres -o $@ -i $< + .PHONY: clean clean: diff --git a/doomdata.h b/doomdata.h index 4d32a59..6483823 100644 --- a/doomdata.h +++ b/doomdata.h @@ -164,6 +164,8 @@ struct FLevel int NumOrgVerts; + WORD *OrgSectorMap; int NumOrgSectors; + fixed_t MinX, MinY, MaxX, MaxY; void FindMapBounds (); diff --git a/main.cpp b/main.cpp index d00098e..11dfc3c 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,6 @@ /* The main glue for ZDBSP. - Copyright (C) 2002,2003 Randy Heit + Copyright (C) 2002-2006 Randy Heit 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 @@ -49,6 +49,7 @@ #endif +#include #include #include #include @@ -258,11 +259,26 @@ int main (int argc, char **argv) END_COUNTER(t1a, t1b, t1c, "\nTotal time: %g seconds.\n") } + catch (std::runtime_error msg) + { + printf ("%s\n", msg.what()); + return 20; + } + catch (std::bad_alloc) + { + printf ("Out of memory\n"); + return 20; + } catch (std::exception msg) { printf ("%s\n", msg.what()); return 20; } + catch (...) + { + printf ("Unhandled exception. ZDBSP cannot continue.\n"); + return 20; + } return 0; } diff --git a/nodebuild.cpp b/nodebuild.cpp index a120c80..562c9a9 100644 --- a/nodebuild.cpp +++ b/nodebuild.cpp @@ -1,6 +1,6 @@ /* Most of the logic for the node builder. - Copyright (C) 2002,2003 Randy Heit + Copyright (C) 2002-2006 Randy Heit 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 diff --git a/nodebuild_events.cpp b/nodebuild_events.cpp index ecf7868..7427974 100644 --- a/nodebuild_events.cpp +++ b/nodebuild_events.cpp @@ -1,6 +1,6 @@ /* A red-black tree implementation for building minisegs. - Copyright (C) 2002,2003 Randy Heit + Copyright (C) 2002-2006 Randy Heit 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 diff --git a/nodebuild_extract.cpp b/nodebuild_extract.cpp index e62ff61..7c4262f 100644 --- a/nodebuild_extract.cpp +++ b/nodebuild_extract.cpp @@ -1,6 +1,6 @@ /* Routines for extracting usable data from the new BSP tree. - Copyright (C) 2002,2003 Randy Heit + Copyright (C) 2002-2006 Randy Heit 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 diff --git a/nodebuild_gl.cpp b/nodebuild_gl.cpp index c20f9d5..668c4cc 100644 --- a/nodebuild_gl.cpp +++ b/nodebuild_gl.cpp @@ -1,6 +1,6 @@ /* Routines only necessary for building GL-friendly nodes. - Copyright (C) 2002,2003 Randy Heit + Copyright (C) 2002-2006 Randy Heit 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 diff --git a/nodebuild_utility.cpp b/nodebuild_utility.cpp index d1e777a..6520202 100644 --- a/nodebuild_utility.cpp +++ b/nodebuild_utility.cpp @@ -1,6 +1,6 @@ /* Various utility functions. - Copyright (C) 2002,2003 Randy Heit + Copyright (C) 2002-2006 Randy Heit 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 diff --git a/processor.cpp b/processor.cpp index 27af9b7..0c56f6d 100644 --- a/processor.cpp +++ b/processor.cpp @@ -1,6 +1,6 @@ /* Reads wad files, builds nodes, and saves new wad files. - Copyright (C) 2002,2003 Randy Heit + Copyright (C) 2002-2006 Randy Heit 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 @@ -57,6 +57,7 @@ FLevel::~FLevel () if (GLSegs) delete[] GLSegs; if (GLNodes) delete[] GLNodes; if (GLPVS) delete[] GLPVS; + if (OrgSectorMap) delete[] OrgSectorMap; } FProcessor::FProcessor (FWadReader &inwad, int lump) @@ -330,6 +331,7 @@ void FLevel::RemoveExtraSectors () // Extra sectors are those that aren't referenced by any sides. // They just waste space, so get rid of them. + NumOrgSectors = NumSectors; used = new BYTE[NumSectors]; memset (used, 0, NumSectors*sizeof(*used)); remap = new WORD[NumSectors]; @@ -368,7 +370,6 @@ void FLevel::RemoveExtraSectors () { int diff = NumSectors - newNumSectors; printf (" Removed %d unused sector%s.\n", diff, diff > 1 ? "s" : ""); - NumSectors = newNumSectors; // Renumber sector references in sides for (i = 0; i < NumSides; ++i) @@ -378,6 +379,14 @@ void FLevel::RemoveExtraSectors () Sides[i].sector = remap[Sides[i].sector]; } } + // Make a reverse map for fixing reject lumps + OrgSectorMap = new WORD[newNumSectors]; + for (i = 0; i < NumSectors; ++i) + { + OrgSectorMap[remap[i]] = i; + } + + NumSectors = newNumSectors; } delete[] used; @@ -572,7 +581,7 @@ void FProcessor::Write (FWadWriter &out) if (lump >= 0) { ReadLump (Wad, lump, Level.Reject, Level.RejectSize); - if (Level.RejectSize != (Level.NumSectors*Level.NumSectors + 7) / 8) + if (Level.RejectSize != (Level.NumOrgSectors*Level.NumOrgSectors + 7) / 8) { // If the reject is the wrong size, don't use it. delete[] Level.Reject; @@ -583,6 +592,14 @@ void FProcessor::Write (FWadWriter &out) } Level.RejectSize = 0; } + else if (Level.NumOrgSectors != Level.NumSectors) + { + // Some sectors have been removed, so fix the reject. + BYTE *newreject = FixReject (Level.Reject); + delete[] Level.Reject; + Level.Reject = newreject; + Level.RejectSize = (Level.NumSectors * Level.NumSectors + 7) / 8; + } } } break; @@ -706,6 +723,33 @@ void FProcessor::Write (FWadWriter &out) } } +// +BYTE *FProcessor::FixReject (const BYTE *oldreject) +{ + int x, y, ox, oy, pnum, opnum; + int rejectSize = (Level.NumSectors*Level.NumSectors + 7) / 8; + BYTE *newreject = new BYTE[rejectSize]; + + memset (newreject, 0, rejectSize); + + for (y = 0; y < Level.NumSectors; ++y) + { + oy = Level.OrgSectorMap[y]; + for (x = 0; x < Level.NumSectors; ++x) + { + ox = Level.OrgSectorMap[x]; + pnum = y*Level.NumSectors + x; + opnum = oy*Level.NumSectors + ox; + + if (oldreject[opnum >> 3] & (1 << (opnum & 7))) + { + newreject[pnum >> 3] |= 1 << (pnum & 7); + } + } + } + return newreject; +} + MapNodeEx *FProcessor::NodesToEx (const MapNode *nodes, int count) { if (count == 0) diff --git a/processor.h b/processor.h index 2cc31d3..07b7dd4 100644 --- a/processor.h +++ b/processor.h @@ -54,6 +54,8 @@ private: MapSubsectorEx *SubsectorsToEx (const MapSubsector *ssec, int count); MapSegGLEx *SegGLsToEx (const MapSegGL *segs, int count); + BYTE *FixReject (const BYTE *oldreject); + void WriteLines (FWadWriter &out); void WriteVertices (FWadWriter &out, int count); void WriteSectors (FWadWriter &out); diff --git a/resource.rc b/resource.rc index a6eb7b4..5d2589e 100644 --- a/resource.rc +++ b/resource.rc @@ -93,8 +93,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,7,0,0 - PRODUCTVERSION 1,7,0,0 + FILEVERSION 1,8,0,0 + PRODUCTVERSION 1,8,0,0 FILEFLAGSMASK 0x17L #ifdef _DEBUG FILEFLAGS 0x1L @@ -110,12 +110,12 @@ BEGIN BLOCK "040904b0" BEGIN VALUE "FileDescription", "ZDBSP Node Builder" - VALUE "FileVersion", "1.7" + VALUE "FileVersion", "1.8" VALUE "InternalName", "zdbsp" - VALUE "LegalCopyright", "Copyright (C) 2002,2003" + VALUE "LegalCopyright", "Copyright (C) 2002-2006" VALUE "OriginalFilename", "zdbsp.exe" VALUE "ProductName", "ZDBSP" - VALUE "ProductVersion", "1.7" + VALUE "ProductVersion", "1.8" END END BLOCK "VarFileInfo" diff --git a/tarray.h b/tarray.h index e73f48e..edd3414 100644 --- a/tarray.h +++ b/tarray.h @@ -3,7 +3,7 @@ ** Templated, automatically resizing array ** **--------------------------------------------------------------------------- -** Copyright 1998-2005 Randy Heit +** Copyright 1998-2006 Randy Heit ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without diff --git a/templates.h b/templates.h index b8a1197..46bb83f 100644 --- a/templates.h +++ b/templates.h @@ -3,7 +3,7 @@ ** Some useful template functions ** **--------------------------------------------------------------------------- -** Copyright 1998-2001 Randy Heit +** Copyright 1998-2006 Randy Heit ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without diff --git a/view.cpp b/view.cpp index 5dc021e..f6eb22d 100644 --- a/view.cpp +++ b/view.cpp @@ -1,6 +1,6 @@ /* A really crappy viewer module. - Copyright (C) 2002,2003 Randy Heit + Copyright (C) 2002-2006 Randy Heit 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 diff --git a/wad.cpp b/wad.cpp index db81b91..8aae8b9 100644 --- a/wad.cpp +++ b/wad.cpp @@ -1,6 +1,6 @@ /* WAD-handling routines. - Copyright (C) 2002,2003 Randy Heit + Copyright (C) 2002-2006 Randy Heit 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 diff --git a/zdbsp.h b/zdbsp.h index d15deba..e03bd63 100644 --- a/zdbsp.h +++ b/zdbsp.h @@ -16,7 +16,7 @@ typedef __int32 int32_t; #include #endif -#define ZDBSP_VERSION "1.7" +#define ZDBSP_VERSION "1.8" enum EBlockmapMode {