mirror of
https://github.com/ZDoom/ZDRay.git
synced 2024-11-22 20:11:11 +00:00
- clean up common.h
This commit is contained in:
parent
e37ea126ce
commit
6400fd1597
8 changed files with 33 additions and 172 deletions
|
@ -35,127 +35,19 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(disable: 4267) // warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
|
#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
|
#pragma warning(disable: 4244) // warning C4244: '=': conversion from '__int64' to 'int', possible loss of data
|
||||||
#endif
|
#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 <windows.h>
|
|
||||||
#else
|
|
||||||
#include <time.h>
|
|
||||||
#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 <limits.h>
|
|
||||||
#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__)
|
#if defined(__GNUC__) || defined(__APPLE__)
|
||||||
#define d_inline __inline__
|
#define d_inline __inline__
|
||||||
#elif defined(_MSC_VER) || defined(KEX_WIN32)
|
#elif defined(_MSC_VER)
|
||||||
#define d_inline __forceinline
|
#define d_inline __forceinline
|
||||||
#else
|
#else
|
||||||
#define d_inline
|
#define d_inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "kexlib/math/mathlib.h"
|
#include "kexlib/math/mathlib.h"
|
||||||
|
|
||||||
void Error(const char *error, ...);
|
|
||||||
char *Va(const char *str, ...);
|
|
||||||
void Delay(int ms);
|
|
||||||
const int64_t GetSeconds();
|
|
||||||
|
|
|
@ -33,9 +33,15 @@
|
||||||
#include "lightmap/common.h"
|
#include "lightmap/common.h"
|
||||||
#include "lightmap/kexlib/binfile.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++];
|
result = buffer[bufferOffset++];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +100,7 @@ std::string kexBinFile::ReadString()
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kexBinFile::Write8(const byte val)
|
void kexBinFile::Write8(const uint8_t val)
|
||||||
{
|
{
|
||||||
buffer[bufferOffset] = val;
|
buffer[bufferOffset] = val;
|
||||||
bufferOffset++;
|
bufferOffset++;
|
||||||
|
@ -145,12 +151,12 @@ int kexBinFile::GetOffsetValue(int id)
|
||||||
return *(int*)(buffer + (id << 2));
|
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);
|
bufferOffset = GetOffsetValue(id);
|
||||||
byte *dataOffs = &data[bufferOffset];
|
uint8_t *dataOffs = &data[bufferOffset];
|
||||||
|
|
||||||
if (count)
|
if (count)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,14 +33,14 @@
|
||||||
class kexBinFile
|
class kexBinFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
byte Read8();
|
uint8_t Read8();
|
||||||
short Read16();
|
short Read16();
|
||||||
int Read32();
|
int Read32();
|
||||||
float ReadFloat();
|
float ReadFloat();
|
||||||
kexVec3 ReadVector();
|
kexVec3 ReadVector();
|
||||||
std::string ReadString();
|
std::string ReadString();
|
||||||
|
|
||||||
void Write8(const byte val);
|
void Write8(const uint8_t val);
|
||||||
void Write16(const short val);
|
void Write16(const short val);
|
||||||
void Write32(const int val);
|
void Write32(const int val);
|
||||||
void WriteFloat(const float val);
|
void WriteFloat(const float val);
|
||||||
|
@ -48,14 +48,14 @@ public:
|
||||||
void WriteString(const std::string &val);
|
void WriteString(const std::string &val);
|
||||||
|
|
||||||
int GetOffsetValue(int id);
|
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; }
|
uint8_t *Buffer() const { return buffer; }
|
||||||
void SetBuffer(byte *ptr) { buffer = ptr; }
|
void SetBuffer(uint8_t *ptr) { buffer = ptr; }
|
||||||
byte *BufferAt() const { return &buffer[bufferOffset]; }
|
uint8_t *BufferAt() const { return &buffer[bufferOffset]; }
|
||||||
void SetOffset(const int offset) { bufferOffset = offset; }
|
void SetOffset(const int offset) { bufferOffset = offset; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
byte *buffer = nullptr;
|
uint8_t *buffer = nullptr;
|
||||||
unsigned int bufferOffset = 0;
|
unsigned int bufferOffset = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
static float InvSqrt(float x);
|
static float InvSqrt(float x);
|
||||||
static void Clamp(float &f, const float min, const float max);
|
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(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 Clamp(kexVec3 &f, const float min, const float max);
|
||||||
|
|
||||||
static void CubicCurve(const kexVec3 &start, const kexVec3 &end, const float time,
|
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
|
// 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 < min) { b = min; }
|
||||||
if (b > max) { b = max; }
|
if (b > max) { b = max; }
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "halffloat.h"
|
#include "halffloat.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
extern int Multisample;
|
extern int Multisample;
|
||||||
extern thread_local kexVec3 *colorSamples;
|
extern thread_local kexVec3 *colorSamples;
|
||||||
|
@ -444,10 +445,10 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
|
||||||
{
|
{
|
||||||
multisamplePos.x += rand() / (float)RAND_MAX - 0.5f;
|
multisamplePos.x += rand() / (float)RAND_MAX - 0.5f;
|
||||||
multisamplePos.y += rand() / (float)RAND_MAX - 0.5f;
|
multisamplePos.y += rand() / (float)RAND_MAX - 0.5f;
|
||||||
multisamplePos.x = max(multisamplePos.x, 0.0f);
|
multisamplePos.x = std::max(multisamplePos.x, 0.0f);
|
||||||
multisamplePos.y = max(multisamplePos.y, 0.0f);
|
multisamplePos.y = std::max(multisamplePos.y, 0.0f);
|
||||||
multisamplePos.x = min(multisamplePos.x, (float)sampleWidth);
|
multisamplePos.x = std::min(multisamplePos.x, (float)sampleWidth);
|
||||||
multisamplePos.y = min(multisamplePos.y, (float)sampleHeight);
|
multisamplePos.y = std::min(multisamplePos.y, (float)sampleHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert the texel into world-space coordinates.
|
// 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))
|
if (!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum))
|
||||||
{
|
{
|
||||||
Error("Lightmap allocation failed\n");
|
throw std::runtime_error("Lightmap allocation failed");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "mapdata.h"
|
#include "mapdata.h"
|
||||||
#include "lightsurface.h"
|
#include "lightsurface.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
static const kexVec3 defaultSunColor(1, 1, 1);
|
static const kexVec3 defaultSunColor(1, 1, 1);
|
||||||
static const kexVec3 defaultSunDirection(0.45f, 0.3f, 0.9f);
|
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.y = ((lightcolor >> 8) & 0xff) / 255.0f;
|
||||||
thingLight->rgb.z = (lightcolor & 0xff) / 255.0f;
|
thingLight->rgb.z = (lightcolor & 0xff) / 255.0f;
|
||||||
thingLight->intensity = lightintensity;
|
thingLight->intensity = lightintensity;
|
||||||
thingLight->innerAngleCos = max(innerAngleCos, outerAngleCos);
|
thingLight->innerAngleCos = std::max(innerAngleCos, outerAngleCos);
|
||||||
thingLight->outerAngleCos = outerAngleCos;
|
thingLight->outerAngleCos = outerAngleCos;
|
||||||
thingLight->radius = lightdistance;
|
thingLight->radius = lightdistance;
|
||||||
thingLight->height = thing->height;
|
thingLight->height = thing->height;
|
||||||
|
|
|
@ -194,13 +194,8 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
|
||||||
|
|
||||||
sector = doomMap.GetSectorFromSubSector(sub);
|
sector = doomMap.GetSectorFromSubSector(sub);
|
||||||
|
|
||||||
// I will be NOT surprised if some users tries to do something stupid with
|
if (!sector)
|
||||||
// sector hacks
|
continue;
|
||||||
if (sector == NULL)
|
|
||||||
{
|
|
||||||
Error("CreateSubsectorSurfaces: subsector %i has no sector\n", i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sector->controlsector)
|
if (sector->controlsector)
|
||||||
continue;
|
continue;
|
||||||
|
|
33
src/main.cpp
33
src/main.cpp
|
@ -730,36 +730,3 @@ void Warn(const char *format, ...)
|
||||||
vprintf(format, marker);
|
vprintf(format, marker);
|
||||||
va_end(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);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue