diff --git a/src/lightmap/common.h b/src/lightmap/common.h index aaacc2c..27498f2 100644 --- a/src/lightmap/common.h +++ b/src/lightmap/common.h @@ -35,127 +35,19 @@ #include #include #include +#include #ifdef _MSC_VER #pragma warning(disable: 4267) // warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data #pragma warning(disable: 4244) // warning C4244: '=': conversion from '__int64' to 'int', possible loss of data #endif -// narrow down the windows preprocessor bullshit down to just one macro define -#if defined(__WIN32__) || defined(__WIN32) || defined(_WIN32_) || defined(_WIN32) || defined(WIN32) -#define KEX_WIN32 -#else -#if defined(__APPLE__) -// lets us know what version of Mac OS X we're compiling on -#include "AvailabilityMacros.h" -#include "TargetConditionals.h" -#if TARGET_OS_IPHONE -// if compiling for iPhone -#define KEX_IPHONE -#else -// if not compiling for iPhone -#define KEX_MACOSX -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050 -# error KexLIB for Mac OS X only supports deploying on 10.5 and above. -#endif // MAC_OS_X_VERSION_MIN_REQUIRED < 1050 -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 -# error KexLIB for Mac OS X must be built with a 10.6 SDK or above. -#endif // MAC_OS_X_VERSION_MAX_ALLOWED < 1060 -#endif // TARGET_OS_IPHONE -#endif // defined(__APPLE__) -#endif // WIN32 - -#ifdef KEX_WIN32 -#include -#else -#include -#endif - -#define MAX_FILEPATH 256 -#define MAX_HASH 2048 - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned long ulong; -typedef unsigned int uint; -typedef unsigned int dtexture; -typedef unsigned int rcolor; -typedef char filepath_t[MAX_FILEPATH]; - -typedef union -{ - int i; - float f; -} fint_t; - -#define ASCII_SLASH 47 -#define ASCII_BACKSLASH 92 - -#ifdef KEX_WIN32 -#define DIR_SEPARATOR '\\' -#define PATH_SEPARATOR ';' -#else -#define DIR_SEPARATOR '/' -#define PATH_SEPARATOR ':' -#endif - -#include -#define D_MININT INT_MIN -#define D_MAXINT INT_MAX - -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif - -#ifndef BETWEEN -#define BETWEEN(l,u,x) ((l)>(x)?(l):(x)>(u)?(u):(x)) -#endif - -#ifndef BIT -#define BIT(num) (1<<(num)) -#endif - -#if defined(KEX_WIN32) && !defined(__GNUC__) -#define KDECL __cdecl -#else -#define KDECL -#endif - -#ifdef ALIGNED -#undef ALIGNED -#endif - -#if defined(_MSC_VER) -#define ALIGNED(x) __declspec(align(x)) -#define PACKED -#elif defined(__GNUC__) -#define ALIGNED(x) __attribute__ ((aligned(x))) -#define PACKED __attribute__((packed)) -#else -#define ALIGNED(x) -#define PACKED -#endif - -// function inlining is available on most platforms, however, -// the GNU C __inline__ is too common and conflicts with a -// definition in other dependencies, so it needs to be factored -// out into a custom macro definition - #if defined(__GNUC__) || defined(__APPLE__) #define d_inline __inline__ -#elif defined(_MSC_VER) || defined(KEX_WIN32) +#elif defined(_MSC_VER) #define d_inline __forceinline #else #define d_inline #endif #include "kexlib/math/mathlib.h" - -void Error(const char *error, ...); -char *Va(const char *str, ...); -void Delay(int ms); -const int64_t GetSeconds(); diff --git a/src/lightmap/kexlib/binfile.cpp b/src/lightmap/kexlib/binfile.cpp index ccd0f27..9ccb65b 100644 --- a/src/lightmap/kexlib/binfile.cpp +++ b/src/lightmap/kexlib/binfile.cpp @@ -33,9 +33,15 @@ #include "lightmap/common.h" #include "lightmap/kexlib/binfile.h" -byte kexBinFile::Read8() +typedef union { - byte result; + int i; + float f; +} fint_t; + +uint8_t kexBinFile::Read8() +{ + uint8_t result; result = buffer[bufferOffset++]; return result; } @@ -94,7 +100,7 @@ std::string kexBinFile::ReadString() return str; } -void kexBinFile::Write8(const byte val) +void kexBinFile::Write8(const uint8_t val) { buffer[bufferOffset] = val; bufferOffset++; @@ -145,12 +151,12 @@ int kexBinFile::GetOffsetValue(int id) return *(int*)(buffer + (id << 2)); } -byte *kexBinFile::GetOffset(int id, byte *subdata, int *count) +uint8_t *kexBinFile::GetOffset(int id, uint8_t *subdata, int *count) { - byte *data = (subdata == nullptr) ? buffer : subdata; + uint8_t *data = (subdata == nullptr) ? buffer : subdata; bufferOffset = GetOffsetValue(id); - byte *dataOffs = &data[bufferOffset]; + uint8_t *dataOffs = &data[bufferOffset]; if (count) { diff --git a/src/lightmap/kexlib/binfile.h b/src/lightmap/kexlib/binfile.h index e273f83..35dc20b 100644 --- a/src/lightmap/kexlib/binfile.h +++ b/src/lightmap/kexlib/binfile.h @@ -33,14 +33,14 @@ class kexBinFile { public: - byte Read8(); + uint8_t Read8(); short Read16(); int Read32(); float ReadFloat(); kexVec3 ReadVector(); std::string ReadString(); - void Write8(const byte val); + void Write8(const uint8_t val); void Write16(const short val); void Write32(const int val); void WriteFloat(const float val); @@ -48,14 +48,14 @@ public: void WriteString(const std::string &val); int GetOffsetValue(int id); - byte *GetOffset(int id, byte *subdata = nullptr, int *count = nullptr); + uint8_t *GetOffset(int id, uint8_t *subdata = nullptr, int *count = nullptr); - byte *Buffer() const { return buffer; } - void SetBuffer(byte *ptr) { buffer = ptr; } - byte *BufferAt() const { return &buffer[bufferOffset]; } + uint8_t *Buffer() const { return buffer; } + void SetBuffer(uint8_t *ptr) { buffer = ptr; } + uint8_t *BufferAt() const { return &buffer[bufferOffset]; } void SetOffset(const int offset) { bufferOffset = offset; } private: - byte *buffer = nullptr; + uint8_t *buffer = nullptr; unsigned int bufferOffset = 0; }; diff --git a/src/lightmap/kexlib/math/mathlib.h b/src/lightmap/kexlib/math/mathlib.h index 6c65235..df7fa94 100644 --- a/src/lightmap/kexlib/math/mathlib.h +++ b/src/lightmap/kexlib/math/mathlib.h @@ -73,7 +73,7 @@ public: static float InvSqrt(float x); static void Clamp(float &f, const float min, const float max); static void Clamp(int &i, const int min, const int max); - static void Clamp(byte &b, const byte min, const byte max); + static void Clamp(uint8_t &b, const uint8_t min, const uint8_t max); static void Clamp(kexVec3 &f, const float min, const float max); static void CubicCurve(const kexVec3 &start, const kexVec3 &end, const float time, @@ -658,7 +658,7 @@ d_inline void kexMath::Clamp(float &f, const float min, const float max) // kexMath::Clamp // -d_inline void kexMath::Clamp(byte &b, const byte min, const byte max) +d_inline void kexMath::Clamp(uint8_t &b, const uint8_t min, const uint8_t max) { if (b < min) { b = min; } if (b > max) { b = max; } diff --git a/src/lightmap/lightmap.cpp b/src/lightmap/lightmap.cpp index 1408c75..824fd86 100644 --- a/src/lightmap/lightmap.cpp +++ b/src/lightmap/lightmap.cpp @@ -41,6 +41,7 @@ #include "halffloat.h" #include #include +#include extern int Multisample; extern thread_local kexVec3 *colorSamples; @@ -444,10 +445,10 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface) { multisamplePos.x += rand() / (float)RAND_MAX - 0.5f; multisamplePos.y += rand() / (float)RAND_MAX - 0.5f; - multisamplePos.x = max(multisamplePos.x, 0.0f); - multisamplePos.y = max(multisamplePos.y, 0.0f); - multisamplePos.x = min(multisamplePos.x, (float)sampleWidth); - multisamplePos.y = min(multisamplePos.y, (float)sampleHeight); + multisamplePos.x = std::max(multisamplePos.x, 0.0f); + multisamplePos.y = std::max(multisamplePos.y, 0.0f); + multisamplePos.x = std::min(multisamplePos.x, (float)sampleWidth); + multisamplePos.y = std::min(multisamplePos.y, (float)sampleHeight); } // convert the texel into world-space coordinates. @@ -499,8 +500,7 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface) if (!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum)) { - Error("Lightmap allocation failed\n"); - return; + throw std::runtime_error("Lightmap allocation failed"); } } diff --git a/src/lightmap/mapdata.cpp b/src/lightmap/mapdata.cpp index a839e78..e4b084b 100644 --- a/src/lightmap/mapdata.cpp +++ b/src/lightmap/mapdata.cpp @@ -33,6 +33,7 @@ #include "common.h" #include "mapdata.h" #include "lightsurface.h" +#include static const kexVec3 defaultSunColor(1, 1, 1); static const kexVec3 defaultSunDirection(0.45f, 0.3f, 0.9f); @@ -219,7 +220,7 @@ void FLevel::CreateLights() thingLight->rgb.y = ((lightcolor >> 8) & 0xff) / 255.0f; thingLight->rgb.z = (lightcolor & 0xff) / 255.0f; thingLight->intensity = lightintensity; - thingLight->innerAngleCos = max(innerAngleCos, outerAngleCos); + thingLight->innerAngleCos = std::max(innerAngleCos, outerAngleCos); thingLight->outerAngleCos = outerAngleCos; thingLight->radius = lightdistance; thingLight->height = thing->height; diff --git a/src/lightmap/surfaces.cpp b/src/lightmap/surfaces.cpp index b534146..1890454 100644 --- a/src/lightmap/surfaces.cpp +++ b/src/lightmap/surfaces.cpp @@ -194,13 +194,8 @@ static void CreateSubsectorSurfaces(FLevel &doomMap) sector = doomMap.GetSectorFromSubSector(sub); - // I will be NOT surprised if some users tries to do something stupid with - // sector hacks - if (sector == NULL) - { - Error("CreateSubsectorSurfaces: subsector %i has no sector\n", i); - return; - } + if (!sector) + continue; if (sector->controlsector) continue; diff --git a/src/main.cpp b/src/main.cpp index 5774601..6867864 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -730,36 +730,3 @@ void Warn(const char *format, ...) vprintf(format, marker); va_end(marker); } - -void Error(const char *error, ...) -{ - va_list argptr; - - va_start(argptr, error); - vprintf(error, argptr); - va_end(argptr); - printf("\n"); - exit(1); -} - -char *Va(const char *str, ...) -{ - va_list v; - static char vastr[1024]; - - va_start(v, str); - vsprintf(vastr, str, v); - va_end(v); - - return vastr; -} - -void Delay(int ms) -{ - std::this_thread::sleep_for(std::chrono::milliseconds(ms)); -} - -const int64_t GetSeconds() -{ - return time(0); -}