- reformat files

This commit is contained in:
Magnus Norddahl 2018-11-02 23:17:46 +01:00
parent 8eee053896
commit b588b809ea
25 changed files with 3375 additions and 3705 deletions

View file

@ -61,27 +61,18 @@ protected:
unsigned int aidx; unsigned int aidx;
}; };
//
// kexArray::kexArray
//
template<class type> template<class type>
kexArray<type>::kexArray() kexArray<type>::kexArray()
{ {
Init(); Init();
} }
//
// kexArray::~kexArray
//
template<class type> template<class type>
kexArray<type>::~kexArray() kexArray<type>::~kexArray()
{ {
Empty(); Empty();
} }
//
// kexArray::Init
//
template<class type> template<class type>
void kexArray<type>::Init() void kexArray<type>::Init()
{ {
@ -90,20 +81,17 @@ void kexArray<type>::Init()
aidx = 0; aidx = 0;
} }
//
// kexArray::Resize
//
template<class type> template<class type>
void kexArray<type>::Resize(unsigned int size) void kexArray<type>::Resize(unsigned int size)
{ {
type *tmp; type *tmp;
if(size == length) if (size == length)
{ {
return; return;
} }
if(size <= 0 && length != 0) if (size <= 0 && length != 0)
{ {
delete[] data; delete[] data;
data = NULL; data = NULL;
@ -111,7 +99,7 @@ void kexArray<type>::Resize(unsigned int size)
return; return;
} }
if(length == 0) if (length == 0)
{ {
data = new type[size]; data = new type[size];
length = size; length = size;
@ -121,7 +109,7 @@ void kexArray<type>::Resize(unsigned int size)
tmp = data; tmp = data;
data = new type[size]; data = new type[size];
for(unsigned int i = 0; i < length; i++) for (unsigned int i = 0; i < length; i++)
{ {
data[i] = tmp[i]; data[i] = tmp[i];
} }
@ -130,38 +118,29 @@ void kexArray<type>::Resize(unsigned int size)
delete[] tmp; delete[] tmp;
} }
//
// kexArray::Push
//
template<class type> template<class type>
void kexArray<type>::Push(type o) void kexArray<type>::Push(type o)
{ {
Resize(length+1); Resize(length + 1);
data[aidx++] = o; data[aidx++] = o;
} }
//
// kexArray::Pop
//
template<class type> template<class type>
void kexArray<type>::Pop() void kexArray<type>::Pop()
{ {
if(length == 0) if (length == 0)
{ {
return; return;
} }
Resize(length-1); Resize(length - 1);
aidx--; aidx--;
} }
//
// kexArray::Empty
//
template<class type> template<class type>
void kexArray<type>::Empty() void kexArray<type>::Empty()
{ {
if(data && length > 0) if (data && length > 0)
{ {
delete[] data; delete[] data;
data = NULL; data = NULL;
@ -170,29 +149,23 @@ void kexArray<type>::Empty()
} }
} }
//
// kexArray::IndexOf
//
template<class type> template<class type>
type kexArray<type>::IndexOf(unsigned int index) const type kexArray<type>::IndexOf(unsigned int index) const
{ {
if(index >= length) if (index >= length)
{ {
index = length-1; index = length - 1;
} }
return data[index]; return data[index];
} }
//
// kexArray::Contains
//
template<class type> template<class type>
bool kexArray<type>::Contains(const type check) const bool kexArray<type>::Contains(const type check) const
{ {
for(unsigned int i = 0; i < length; ++i) for (unsigned int i = 0; i < length; ++i)
{ {
if(data[i] == check) if (data[i] == check)
{ {
return true; return true;
} }
@ -201,45 +174,37 @@ bool kexArray<type>::Contains(const type check) const
return false; return false;
} }
//
// kexArray::Splice
//
template<class type> template<class type>
void kexArray<type>::Splice(const unsigned int start, unsigned int len) void kexArray<type>::Splice(const unsigned int start, unsigned int len)
{ {
if(length == 0 || len == 0) if (length == 0 || len == 0)
{ {
return; return;
} }
if(len >= length) if (len >= length)
{ {
len = length; len = length;
} }
type *tmp = new type[len]; type *tmp = new type[len];
for(unsigned int i = 0; i < len; i++) for (unsigned int i = 0; i < len; i++)
{ {
tmp[i] = data[start+i]; tmp[i] = data[start + i];
} }
delete[] data; delete[] data;
data = tmp; data = tmp;
length = length - len; length = length - len;
aidx = length-1; aidx = length - 1;
} }
// // Note that data will be shuffled around, so this could invalidate any pointers that relies on the array/data
// kexArray::Sort
//
// Note that data will be shuffled around, so this could invalidate any
// pointers that relies on the array/data
//
template<class type> template<class type>
void kexArray<type>::Sort(compare_t *function) void kexArray<type>::Sort(compare_t *function)
{ {
if(data == NULL) if (data == NULL)
{ {
return; return;
} }
@ -250,16 +215,11 @@ void kexArray<type>::Sort(compare_t *function)
qsort((void*)data, length, sizeof(type), cmpFunc); qsort((void*)data, length, sizeof(type), cmpFunc);
} }
// // Note that data will be shuffled around, so this could invalidate any pointers that relies on the array/data
// kexArray::Sort
//
// Note that data will be shuffled around, so this could invalidate any
// pointers that relies on the array/data
//
template<class type> template<class type>
void kexArray<type>::Sort(compare_t *function, unsigned int count) void kexArray<type>::Sort(compare_t *function, unsigned int count)
{ {
if(data == NULL) if (data == NULL)
{ {
return; return;
} }
@ -270,9 +230,6 @@ void kexArray<type>::Sort(compare_t *function, unsigned int count)
qsort((void*)data, count, sizeof(type), cmpFunc); qsort((void*)data, count, sizeof(type), cmpFunc);
} }
//
// kexArray::operator[]
//
template <class type> template <class type>
type &kexArray<type>::operator[](unsigned int index) type &kexArray<type>::operator[](unsigned int index)
{ {
@ -280,13 +237,10 @@ type &kexArray<type>::operator[](unsigned int index)
return data[index]; return data[index];
} }
//
// kexArray::operator=
//
template <class type> template <class type>
kexArray<type> &kexArray<type>::operator=(const kexArray<type> &arr) kexArray<type> &kexArray<type>::operator=(const kexArray<type> &arr)
{ {
if(data) if (data)
{ {
delete[] data; delete[] data;
} }
@ -295,11 +249,11 @@ kexArray<type> &kexArray<type>::operator=(const kexArray<type> &arr)
length = arr.length; length = arr.length;
aidx = arr.aidx; aidx = arr.aidx;
if(arr.length > 0) if (arr.length > 0)
{ {
data = new type[arr.length]; data = new type[arr.length];
for(unsigned int i = 0; i < arr.length; i++) for (unsigned int i = 0; i < arr.length; i++)
{ {
data[i] = arr.data[i]; data[i] = arr.data[i];
} }

View file

@ -33,10 +33,6 @@
#include "lightmap/common.h" #include "lightmap/common.h"
#include "lightmap/kexlib/binfile.h" #include "lightmap/kexlib/binfile.h"
//
// kexBinFile::kexBinFile
//
kexBinFile::kexBinFile() kexBinFile::kexBinFile()
{ {
this->handle = NULL; this->handle = NULL;
@ -45,22 +41,14 @@ kexBinFile::kexBinFile()
this->bOpened = false; this->bOpened = false;
} }
//
// kexBinFile::~kexBinFile
//
kexBinFile::~kexBinFile() kexBinFile::~kexBinFile()
{ {
Close(); Close();
} }
//
// kexBinFile::Open
//
bool kexBinFile::Open(const char *file, kexHeapBlock &heapBlock) bool kexBinFile::Open(const char *file, kexHeapBlock &heapBlock)
{ {
if((handle = fopen(file, "rb"))) if ((handle = fopen(file, "rb")))
{ {
size_t length; size_t length;
@ -68,11 +56,11 @@ bool kexBinFile::Open(const char *file, kexHeapBlock &heapBlock)
length = ftell(handle); length = ftell(handle);
fseek(handle, 0, SEEK_SET); fseek(handle, 0, SEEK_SET);
buffer = (byte*)Mem_Calloc(length+1, heapBlock); buffer = (byte*)Mem_Calloc(length + 1, heapBlock);
if(fread(buffer, 1, length, handle) == length) if (fread(buffer, 1, length, handle) == length)
{ {
if(length > 0) if (length > 0)
{ {
bOpened = true; bOpened = true;
bufferOffset = 0; bufferOffset = 0;
@ -88,13 +76,9 @@ bool kexBinFile::Open(const char *file, kexHeapBlock &heapBlock)
return false; return false;
} }
//
// kexBinFile::Create
//
bool kexBinFile::Create(const char *file) bool kexBinFile::Create(const char *file)
{ {
if((handle = fopen(file, "wb"))) if ((handle = fopen(file, "wb")))
{ {
bOpened = true; bOpened = true;
bufferOffset = 0; bufferOffset = 0;
@ -104,21 +88,17 @@ bool kexBinFile::Create(const char *file)
return false; return false;
} }
//
// kexBinFile::Close
//
void kexBinFile::Close() void kexBinFile::Close()
{ {
if(bOpened == false) if (bOpened == false)
{ {
return; return;
} }
if(handle) if (handle)
{ {
fclose(handle); fclose(handle);
handle = NULL; handle = NULL;
if(buffer) if (buffer)
{ {
Mem_Free(buffer); Mem_Free(buffer);
} }
@ -127,17 +107,13 @@ void kexBinFile::Close()
bOpened = false; bOpened = false;
} }
//
// kexBinFile::Exists
//
bool kexBinFile::Exists(const char *file) bool kexBinFile::Exists(const char *file)
{ {
FILE *fstream; FILE *fstream;
fstream = fopen(file, "r"); fstream = fopen(file, "r");
if(fstream != NULL) if (fstream != NULL)
{ {
fclose(fstream); fclose(fstream);
return true; return true;
@ -147,7 +123,7 @@ bool kexBinFile::Exists(const char *file)
{ {
// If we can't open because the file is a directory, the // If we can't open because the file is a directory, the
// "file" exists at least! // "file" exists at least!
if(errno == 21) if (errno == 21)
{ {
return true; return true;
} }
@ -157,22 +133,18 @@ bool kexBinFile::Exists(const char *file)
return false; return false;
} }
//
// kexBinFile::Duplicate
//
void kexBinFile::Duplicate(const char *newFileName) void kexBinFile::Duplicate(const char *newFileName)
{ {
FILE *f; FILE *f;
if(bOpened == false) if (bOpened == false)
{ {
return; return;
} }
f = fopen(newFileName, "wb"); f = fopen(newFileName, "wb");
if(f == NULL) if (f == NULL)
{ {
return; return;
} }
@ -181,16 +153,12 @@ void kexBinFile::Duplicate(const char *newFileName)
fclose(f); fclose(f);
} }
//
// kexBinFile::Length
//
int kexBinFile::Length() int kexBinFile::Length()
{ {
long savedpos; long savedpos;
long length; long length;
if(bOpened == false) if (bOpened == false)
{ {
return 0; return 0;
} }
@ -208,10 +176,6 @@ int kexBinFile::Length()
return length; return length;
} }
//
// kexBinFile::Read8
//
byte kexBinFile::Read8() byte kexBinFile::Read8()
{ {
byte result; byte result;
@ -219,10 +183,6 @@ byte kexBinFile::Read8()
return result; return result;
} }
//
// kexBinFile::Read16
//
short kexBinFile::Read16() short kexBinFile::Read16()
{ {
int result; int result;
@ -231,10 +191,6 @@ short kexBinFile::Read16()
return result; return result;
} }
//
// kexBinFile::Read32
//
int kexBinFile::Read32() int kexBinFile::Read32()
{ {
int result; int result;
@ -245,10 +201,6 @@ int kexBinFile::Read32()
return result; return result;
} }
//
// kexBinFile::ReadFloat
//
float kexBinFile::ReadFloat() float kexBinFile::ReadFloat()
{ {
fint_t fi; fint_t fi;
@ -256,10 +208,6 @@ float kexBinFile::ReadFloat()
return fi.f; return fi.f;
} }
//
// kexBinFile::ReadVector
//
kexVec3 kexBinFile::ReadVector() kexVec3 kexBinFile::ReadVector()
{ {
kexVec3 vec; kexVec3 vec;
@ -271,18 +219,14 @@ kexVec3 kexBinFile::ReadVector()
return vec; return vec;
} }
//
// kexBinFile::ReadString
//
kexStr kexBinFile::ReadString() kexStr kexBinFile::ReadString()
{ {
kexStr str; kexStr str;
char c = 0; char c = 0;
while(1) while (1)
{ {
if(!(c = Read8())) if (!(c = Read8()))
{ {
break; break;
} }
@ -293,13 +237,9 @@ kexStr kexBinFile::ReadString()
return str; return str;
} }
//
// kexBinFile::Write8
//
void kexBinFile::Write8(const byte val) void kexBinFile::Write8(const byte val)
{ {
if(bOpened) if (bOpened)
{ {
fwrite(&val, 1, 1, handle); fwrite(&val, 1, 1, handle);
} }
@ -310,20 +250,12 @@ void kexBinFile::Write8(const byte val)
bufferOffset++; bufferOffset++;
} }
//
// kexBinFile::Write16
//
void kexBinFile::Write16(const short val) void kexBinFile::Write16(const short val)
{ {
Write8(val & 0xff); Write8(val & 0xff);
Write8((val >> 8) & 0xff); Write8((val >> 8) & 0xff);
} }
//
// kexBinFile::Write32
//
void kexBinFile::Write32(const int val) void kexBinFile::Write32(const int val)
{ {
Write8(val & 0xff); Write8(val & 0xff);
@ -332,10 +264,6 @@ void kexBinFile::Write32(const int val)
Write8((val >> 24) & 0xff); Write8((val >> 24) & 0xff);
} }
//
// kexBinFile::WriteFloat
//
void kexBinFile::WriteFloat(const float val) void kexBinFile::WriteFloat(const float val)
{ {
fint_t fi; fint_t fi;
@ -343,10 +271,6 @@ void kexBinFile::WriteFloat(const float val)
Write32(fi.i); Write32(fi.i);
} }
//
// kexBinFile::WriteVector
//
void kexBinFile::WriteVector(const kexVec3 &val) void kexBinFile::WriteVector(const kexVec3 &val)
{ {
WriteFloat(val.x); WriteFloat(val.x);
@ -354,15 +278,11 @@ void kexBinFile::WriteVector(const kexVec3 &val)
WriteFloat(val.z); WriteFloat(val.z);
} }
//
// kexBinFile::WriteString
//
void kexBinFile::WriteString(const kexStr &val) void kexBinFile::WriteString(const kexStr &val)
{ {
const char *c = val.c_str(); const char *c = val.c_str();
for(int i = 0; i < val.Length(); i++) for (int i = 0; i < val.Length(); i++)
{ {
Write8(c[i]); Write8(c[i]);
} }
@ -370,19 +290,11 @@ void kexBinFile::WriteString(const kexStr &val)
Write8(0); Write8(0);
} }
//
// kexBinFile::GetOffsetValue
//
int kexBinFile::GetOffsetValue(int id) int kexBinFile::GetOffsetValue(int id)
{ {
return *(int*)(buffer + (id << 2)); return *(int*)(buffer + (id << 2));
} }
//
// kexBinFile::GetOffset
//
byte *kexBinFile::GetOffset(int id, byte *subdata, int *count) byte *kexBinFile::GetOffset(int id, byte *subdata, int *count)
{ {
byte *data = (subdata == NULL) ? buffer : subdata; byte *data = (subdata == NULL) ? buffer : subdata;
@ -390,7 +302,7 @@ byte *kexBinFile::GetOffset(int id, byte *subdata, int *count)
bufferOffset = GetOffsetValue(id); bufferOffset = GetOffsetValue(id);
byte *dataOffs = &data[bufferOffset]; byte *dataOffs = &data[bufferOffset];
if(count) if (count)
{ {
*count = *(int*)(dataOffs); *count = *(int*)(dataOffs);
} }

View file

@ -57,9 +57,7 @@ public:
void WriteString(const kexStr &val); void WriteString(const kexStr &val);
int GetOffsetValue(int id); int GetOffsetValue(int id);
byte *GetOffset(int id, byte *GetOffset(int id, byte *subdata = NULL, int *count = NULL);
byte *subdata = NULL,
int *count = NULL);
FILE *Handle() const { return handle; } FILE *Handle() const { return handle; }
byte *Buffer() const { return buffer; } byte *Buffer() const { return buffer; }

View file

@ -33,10 +33,6 @@
#include <ctype.h> #include <ctype.h>
#include "kstring.h" #include "kstring.h"
//
// kexStr::Init
//
void kexStr::Init() void kexStr::Init()
{ {
length = 0; length = 0;
@ -45,13 +41,9 @@ void kexStr::Init()
charPtr[0] = '\0'; charPtr[0] = '\0';
} }
//
// kexStr::CheckSize
//
void kexStr::CheckSize(int size, bool bKeepString) void kexStr::CheckSize(int size, bool bKeepString)
{ {
if(size <= bufferLength) if (size <= bufferLength)
{ {
return; return;
} }
@ -59,35 +51,23 @@ void kexStr::CheckSize(int size, bool bKeepString)
Resize(size, bKeepString); Resize(size, bKeepString);
} }
//
// kexStr::CopyNew
//
void kexStr::CopyNew(const char *string, int len) void kexStr::CopyNew(const char *string, int len)
{ {
CheckSize(len+1, false); CheckSize(len + 1, false);
strcpy(charPtr, string); strcpy(charPtr, string);
length = len; length = len;
} }
//
// kexStr::kexStr
//
kexStr::kexStr() kexStr::kexStr()
{ {
Init(); Init();
} }
//
// kexStr::kexStr
//
kexStr::kexStr(const char *string) kexStr::kexStr(const char *string)
{ {
Init(); Init();
if(string == NULL) if (string == NULL)
{ {
return; return;
} }
@ -95,15 +75,11 @@ kexStr::kexStr(const char *string)
CopyNew(string, strlen(string)); CopyNew(string, strlen(string));
} }
//
// kexStr::kexStr
//
kexStr::kexStr(const char *string, const int length) kexStr::kexStr(const char *string, const int length)
{ {
Init(); Init();
if(string == NULL) if (string == NULL)
{ {
return; return;
} }
@ -111,15 +87,11 @@ kexStr::kexStr(const char *string, const int length)
CopyNew(string, length); CopyNew(string, length);
} }
//
// kexStr::kexStr
//
kexStr::kexStr(const kexStr &string) kexStr::kexStr(const kexStr &string)
{ {
Init(); Init();
if(string.charPtr == NULL) if (string.charPtr == NULL)
{ {
return; return;
} }
@ -127,13 +99,9 @@ kexStr::kexStr(const kexStr &string)
CopyNew(string.charPtr, string.Length()); CopyNew(string.charPtr, string.Length());
} }
//
// kexStr::~kexStr
//
kexStr::~kexStr() kexStr::~kexStr()
{ {
if(charPtr != defaultBuffer) if (charPtr != defaultBuffer)
{ {
delete[] charPtr; delete[] charPtr;
charPtr = defaultBuffer; charPtr = defaultBuffer;
@ -143,38 +111,26 @@ kexStr::~kexStr()
length = 0; length = 0;
} }
//
// kexStr::Concat
//
kexStr &kexStr::Concat(const char *string) kexStr &kexStr::Concat(const char *string)
{ {
return Concat(string, strlen(string)); return Concat(string, strlen(string));
} }
//
// kexStr::Concat
//
kexStr &kexStr::Concat(const char c) kexStr &kexStr::Concat(const char c)
{ {
CheckSize((length + 1)+1, true); CheckSize((length + 1) + 1, true);
charPtr[length++] = c; charPtr[length++] = c;
charPtr[length] = '\0'; charPtr[length] = '\0';
return *this; return *this;
} }
//
// kexStr::Concat
//
kexStr &kexStr::Concat(const char *string, int len) kexStr &kexStr::Concat(const char *string, int len)
{ {
CheckSize((length + len)+1, true); CheckSize((length + len) + 1, true);
for(int i = 0; i < len; i++) for (int i = 0; i < len; i++)
{ {
charPtr[length+i] = string[i]; charPtr[length + i] = string[i];
} }
length += len; length += len;
@ -183,17 +139,13 @@ kexStr &kexStr::Concat(const char *string, int len)
return *this; return *this;
} }
//
// kexStr::Copy
//
kexStr &kexStr::Copy(const kexStr &src, int len) kexStr &kexStr::Copy(const kexStr &src, int len)
{ {
int i = 0; int i = 0;
const char *p = src; const char *p = src;
CheckSize((length + len)+1, true); CheckSize((length + len) + 1, true);
while((len--) >= 0) while ((len--) >= 0)
{ {
charPtr[i] = p[i]; charPtr[i] = p[i];
i++; i++;
@ -202,24 +154,16 @@ kexStr &kexStr::Copy(const kexStr &src, int len)
return *this; return *this;
} }
//
// kexStr::Copy
//
kexStr &kexStr::Copy(const kexStr &src) kexStr &kexStr::Copy(const kexStr &src)
{ {
return Copy(src, src.Length()); return Copy(src, src.Length());
} }
//
// kexStr::operator=
//
kexStr &kexStr::operator=(const kexStr &str) kexStr &kexStr::operator=(const kexStr &str)
{ {
int len = str.Length(); int len = str.Length();
CheckSize(len+1, false); CheckSize(len + 1, false);
strncpy(charPtr, str.charPtr, len); strncpy(charPtr, str.charPtr, len);
length = len; length = len;
charPtr[length] = '\0'; charPtr[length] = '\0';
@ -227,15 +171,11 @@ kexStr &kexStr::operator=(const kexStr &str)
return *this; return *this;
} }
//
// kexStr::operator=
//
kexStr &kexStr::operator=(const char *str) kexStr &kexStr::operator=(const char *str)
{ {
int len = strlen(str); int len = strlen(str);
CheckSize(len+1, false); CheckSize(len + 1, false);
strncpy(charPtr, str, len); strncpy(charPtr, str, len);
length = len; length = len;
charPtr[length] = '\0'; charPtr[length] = '\0';
@ -243,16 +183,12 @@ kexStr &kexStr::operator=(const char *str)
return *this; return *this;
} }
//
// kexStr::operator=
//
kexStr &kexStr::operator=(const bool b) kexStr &kexStr::operator=(const bool b)
{ {
const char *str = b ? "true" : "false"; const char *str = b ? "true" : "false";
int len = strlen(str); int len = strlen(str);
CheckSize(len+1, false); CheckSize(len + 1, false);
strncpy(charPtr, str, len); strncpy(charPtr, str, len);
length = len; length = len;
charPtr[length] = '\0'; charPtr[length] = '\0';
@ -260,10 +196,6 @@ kexStr &kexStr::operator=(const bool b)
return *this; return *this;
} }
//
// kexStr::operator+
//
kexStr kexStr::operator+(const kexStr &str) kexStr kexStr::operator+(const kexStr &str)
{ {
kexStr out(*this); kexStr out(*this);
@ -271,10 +203,6 @@ kexStr kexStr::operator+(const kexStr &str)
return out.Concat(str.c_str()); return out.Concat(str.c_str());
} }
//
// kexStr::operator+
//
kexStr kexStr::operator+(const char *str) kexStr kexStr::operator+(const char *str)
{ {
kexStr out(*this); kexStr out(*this);
@ -282,10 +210,6 @@ kexStr kexStr::operator+(const char *str)
return out.Concat(str); return out.Concat(str);
} }
//
// kexStr::operator+
//
kexStr kexStr::operator+(const bool b) kexStr kexStr::operator+(const bool b)
{ {
kexStr out(*this); kexStr out(*this);
@ -293,10 +217,6 @@ kexStr kexStr::operator+(const bool b)
return out.Concat(b ? "true" : "false"); return out.Concat(b ? "true" : "false");
} }
//
// kexStr::operator+
//
kexStr kexStr::operator+(const int i) kexStr kexStr::operator+(const int i)
{ {
kexStr out(*this); kexStr out(*this);
@ -307,10 +227,6 @@ kexStr kexStr::operator+(const int i)
return out.Concat(tmp); return out.Concat(tmp);
} }
//
// kexStr::operator+
//
kexStr kexStr::operator+(const float f) kexStr kexStr::operator+(const float f)
{ {
kexStr out(*this); kexStr out(*this);
@ -321,60 +237,36 @@ kexStr kexStr::operator+(const float f)
return out.Concat(tmp); return out.Concat(tmp);
} }
//
// kexStr::operator+=
//
kexStr &kexStr::operator+=(const kexStr &str) kexStr &kexStr::operator+=(const kexStr &str)
{ {
return Concat(str.c_str()); return Concat(str.c_str());
} }
//
// kexStr::operator+=
//
kexStr &kexStr::operator+=(const char *str) kexStr &kexStr::operator+=(const char *str)
{ {
return Concat(str); return Concat(str);
} }
//
// kexStr::operator+=
//
kexStr &kexStr::operator+=(const char c) kexStr &kexStr::operator+=(const char c)
{ {
return Concat(c); return Concat(c);
} }
//
// kexStr::operator+=
//
kexStr &kexStr::operator+=(const bool b) kexStr &kexStr::operator+=(const bool b)
{ {
return Concat(b ? "true" : "false"); return Concat(b ? "true" : "false");
} }
//
// kexStr::operator[]
//
const char kexStr::operator[](int index) const const char kexStr::operator[](int index) const
{ {
assert(index >= 0 && index < length); assert(index >= 0 && index < length);
return charPtr[index]; return charPtr[index];
} }
//
// kexStr::Resize
//
void kexStr::Resize(int size, bool bKeepString) void kexStr::Resize(int size, bool bKeepString)
{ {
if(size <= 0) if (size <= 0)
{ {
return; return;
} }
@ -382,12 +274,12 @@ void kexStr::Resize(int size, bool bKeepString)
int newsize = size + ((32 - (size & 31)) & 31); int newsize = size + ((32 - (size & 31)) & 31);
char *newbuffer = new char[newsize]; char *newbuffer = new char[newsize];
if(bKeepString) if (bKeepString)
{ {
strncpy(newbuffer, charPtr, length); strncpy(newbuffer, charPtr, length);
} }
if(charPtr != defaultBuffer) if (charPtr != defaultBuffer)
{ {
delete[] charPtr; delete[] charPtr;
} }
@ -396,21 +288,17 @@ void kexStr::Resize(int size, bool bKeepString)
bufferLength = newsize; bufferLength = newsize;
} }
//
// kexStr::IndexOf
//
int kexStr::IndexOf(const char *pattern) const int kexStr::IndexOf(const char *pattern) const
{ {
int patlen = strlen(pattern); int patlen = strlen(pattern);
int i = 0; int i = 0;
int j = 0; int j = 0;
while(i + j < Length()) while (i + j < Length())
{ {
if(charPtr[i + j] == pattern[j]) if (charPtr[i + j] == pattern[j])
{ {
if(++j == patlen) if (++j == patlen)
{ {
return i; return i;
} }
@ -425,21 +313,17 @@ int kexStr::IndexOf(const char *pattern) const
return -1; return -1;
} }
//
// kexStr::IndexOf
//
int kexStr::IndexOf(const char *string, const char *pattern) int kexStr::IndexOf(const char *string, const char *pattern)
{ {
int patlen = strlen(pattern); int patlen = strlen(pattern);
int i = 0; int i = 0;
int j = 0; int j = 0;
while(i + j < (int)strlen(string)) while (i + j < (int)strlen(string))
{ {
if(string[i + j] == pattern[j]) if (string[i + j] == pattern[j])
{ {
if(++j == patlen) if (++j == patlen)
{ {
return i; return i;
} }
@ -454,24 +338,16 @@ int kexStr::IndexOf(const char *string, const char *pattern)
return -1; return -1;
} }
//
// kexStr::IndexOf
//
int kexStr::IndexOf(const kexStr &pattern) const int kexStr::IndexOf(const kexStr &pattern) const
{ {
return IndexOf(pattern.c_str()); return IndexOf(pattern.c_str());
} }
//
// kexStr::NormalizeSlashes
//
kexStr &kexStr::NormalizeSlashes() kexStr &kexStr::NormalizeSlashes()
{ {
for(int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
if((charPtr[i] == '/' || charPtr[i] == '\\') && charPtr[i] != DIR_SEPARATOR) if ((charPtr[i] == '/' || charPtr[i] == '\\') && charPtr[i] != DIR_SEPARATOR)
{ {
charPtr[i] = DIR_SEPARATOR; charPtr[i] = DIR_SEPARATOR;
} }
@ -480,10 +356,6 @@ kexStr &kexStr::NormalizeSlashes()
return *this; return *this;
} }
//
// kexStr::StripPath
//
kexStr &kexStr::StripPath() kexStr &kexStr::StripPath()
{ {
int pos = 0; int pos = 0;
@ -491,17 +363,17 @@ kexStr &kexStr::StripPath()
pos = length; pos = length;
for(i = length - 1; charPtr[i] != '\\' && charPtr[i] != '/'; i--, pos--) for (i = length - 1; charPtr[i] != '\\' && charPtr[i] != '/'; i--, pos--)
{ {
if(pos <= 0) if (pos <= 0)
{ {
return *this; return *this;
} }
} }
length = length - pos; length = length - pos;
for(i = 0; i < length; i++) for (i = 0; i < length; i++)
{ {
charPtr[i] = charPtr[pos+i]; charPtr[i] = charPtr[pos + i];
} }
CheckSize(length, true); CheckSize(length, true);
@ -509,15 +381,11 @@ kexStr &kexStr::StripPath()
return *this; return *this;
} }
//
// kexStr::StripExtension
//
kexStr &kexStr::StripExtension() kexStr &kexStr::StripExtension()
{ {
int pos = IndexOf("."); int pos = IndexOf(".");
if(pos == -1) if (pos == -1)
{ {
return *this; return *this;
} }
@ -529,25 +397,21 @@ kexStr &kexStr::StripExtension()
return *this; return *this;
} }
//
// kexStr::StripFile
//
kexStr &kexStr::StripFile() kexStr &kexStr::StripFile()
{ {
int pos = 0; int pos = 0;
int i = 0; int i = 0;
if(IndexOf(".") == -1) if (IndexOf(".") == -1)
{ {
return *this; return *this;
} }
pos = length; pos = length;
for(i = length - 1; charPtr[i] != '\\' && charPtr[i] != '/'; i--, pos--) for (i = length - 1; charPtr[i] != '\\' && charPtr[i] != '/'; i--, pos--)
{ {
if(pos <= 0) if (pos <= 0)
{ {
return *this; return *this;
} }
@ -560,73 +424,57 @@ kexStr &kexStr::StripFile()
return *this; return *this;
} }
//
// kexStr::Hash
//
int kexStr::Hash() int kexStr::Hash()
{ {
unsigned int hash = 0; unsigned int hash = 0;
char *str = (char*)charPtr; char *str = (char*)charPtr;
char c; char c;
while((c = *str++)) while ((c = *str++))
{ {
hash = c + (hash << 6) + (hash << 16) - hash; hash = c + (hash << 6) + (hash << 16) - hash;
} }
return hash & (MAX_HASH-1); return hash & (MAX_HASH - 1);
} }
//
// kexStr::Hash
//
int kexStr::Hash(const char *s) int kexStr::Hash(const char *s)
{ {
unsigned int hash = 0; unsigned int hash = 0;
char *str = (char*)s; char *str = (char*)s;
char c; char c;
while((c = *str++)) while ((c = *str++))
{ {
hash = c + (hash << 6) + (hash << 16) - hash; hash = c + (hash << 6) + (hash << 16) - hash;
} }
return hash & (MAX_HASH-1); return hash & (MAX_HASH - 1);
} }
//
// kexStr::Format
//
char *kexStr::Format(const char *str, ...) char *kexStr::Format(const char *str, ...)
{ {
va_list v; va_list v;
static char vastr[1024]; static char vastr[1024];
va_start(v, str); va_start(v, str);
vsprintf(vastr, str,v); vsprintf(vastr, str, v);
va_end(v); va_end(v);
return vastr; return vastr;
} }
//
// kexStr::Substr
//
kexStr kexStr::Substr(int start, int len) const kexStr kexStr::Substr(int start, int len) const
{ {
kexStr str; kexStr str;
int l = Length(); int l = Length();
if(l <= 0 || start >= l) if (l <= 0 || start >= l)
{ {
return str; return str;
} }
if(start + len >= l) if (start + len >= l)
{ {
len = l - start; len = l - start;
} }
@ -634,25 +482,21 @@ kexStr kexStr::Substr(int start, int len) const
return str.Concat((const char*)&charPtr[start], len); return str.Concat((const char*)&charPtr[start], len);
} }
//
// kexStr::Split
//
void kexStr::Split(kexStrList &list, const char seperator) void kexStr::Split(kexStrList &list, const char seperator)
{ {
int splitLen = 0; int splitLen = 0;
int startOffs = 0; int startOffs = 0;
for(int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
if(charPtr[i] == seperator) if (charPtr[i] == seperator)
{ {
if(splitLen == 0) if (splitLen == 0)
{ {
continue; continue;
} }
list.Push(kexStr(&charPtr[startOffs], splitLen)); list.Push(kexStr(&charPtr[startOffs], splitLen));
startOffs += (splitLen+1); startOffs += (splitLen + 1);
splitLen = 0; splitLen = 0;
continue; continue;
} }
@ -660,37 +504,25 @@ void kexStr::Split(kexStrList &list, const char seperator)
splitLen++; splitLen++;
} }
if(splitLen != 0 && startOffs != 0) if (splitLen != 0 && startOffs != 0)
{ {
list.Push(kexStr(&charPtr[startOffs], splitLen)); list.Push(kexStr(&charPtr[startOffs], splitLen));
} }
} }
//
// kexStr::Atoi
//
int kexStr::Atoi() int kexStr::Atoi()
{ {
return atoi(charPtr); return atoi(charPtr);
} }
//
// kexStr::Atof
//
float kexStr::Atof() float kexStr::Atof()
{ {
return (float)atof(charPtr); return (float)atof(charPtr);
} }
//
// kexStr::WriteToFile
//
void kexStr::WriteToFile(const char *file) void kexStr::WriteToFile(const char *file)
{ {
if(length <= 0) if (length <= 0)
{ {
return; return;
} }
@ -700,19 +532,15 @@ void kexStr::WriteToFile(const char *file)
fclose(f); fclose(f);
} }
//
// kexStr::ToUpper
//
kexStr &kexStr::ToUpper() kexStr &kexStr::ToUpper()
{ {
char c; char c;
for(int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
c = charPtr[i]; c = charPtr[i];
if(c >= 'a' && c <= 'z') if (c >= 'a' && c <= 'z')
{ {
c -= 'a'-'A'; c -= 'a' - 'A';
} }
charPtr[i] = c; charPtr[i] = c;
} }
@ -720,17 +548,13 @@ kexStr &kexStr::ToUpper()
return *this; return *this;
} }
//
// kexStr::ToLower
//
kexStr &kexStr::ToLower() kexStr &kexStr::ToLower()
{ {
char c; char c;
for(int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
c = charPtr[i]; c = charPtr[i];
if(c >= 'A' && c <= 'Z') if (c >= 'A' && c <= 'Z')
{ {
c += 32; c += 32;
} }
@ -740,22 +564,18 @@ kexStr &kexStr::ToLower()
return *this; return *this;
} }
//
// kexStr::CompareCase
//
bool kexStr::CompareCase(const char *s1, const char *s2) bool kexStr::CompareCase(const char *s1, const char *s2)
{ {
while(*s1 && *s2) while (*s1 && *s2)
{ {
if(*s1 != *s2) if (*s1 != *s2)
{ {
return (*s2 - *s1) != 0; return (*s2 - *s1) != 0;
} }
s1++; s1++;
s2++; s2++;
} }
if(*s1 != *s2) if (*s1 != *s2)
{ {
return (*s2 - *s1) != 0; return (*s2 - *s1) != 0;
} }
@ -763,27 +583,19 @@ bool kexStr::CompareCase(const char *s1, const char *s2)
return false; return false;
} }
//
// kexStr::CompareCase
//
bool kexStr::CompareCase(const kexStr &a, const kexStr &b) bool kexStr::CompareCase(const kexStr &a, const kexStr &b)
{ {
return CompareCase(a.c_str(), b.c_str()); return CompareCase(a.c_str(), b.c_str());
} }
//
// kexStr::Compare
//
bool kexStr::Compare(const char *s1, const char *s2) bool kexStr::Compare(const char *s1, const char *s2)
{ {
const byte *us1 = (const byte*)s1; const byte *us1 = (const byte*)s1;
const byte *us2 = (const byte*)s2; const byte *us2 = (const byte*)s2;
while(tolower(*us1) == tolower(*us2)) while (tolower(*us1) == tolower(*us2))
{ {
if(*us1++ == '\0') if (*us1++ == '\0')
{ {
return false; return false;
} }
@ -794,10 +606,6 @@ bool kexStr::Compare(const char *s1, const char *s2)
return (tolower(*us1) - tolower(*us2)) != 0; return (tolower(*us1) - tolower(*us2)) != 0;
} }
//
// kexStr::Compare
//
bool kexStr::Compare(const kexStr &a, const kexStr &b) bool kexStr::Compare(const kexStr &a, const kexStr &b)
{ {
return Compare(a.c_str(), b.c_str()); return Compare(a.c_str(), b.c_str());

View file

@ -211,19 +211,19 @@ void kexAngle::ToAxis(kexVec3 *forward, kexVec3 *up, kexVec3 *right)
float sr = kexMath::Sin(roll); float sr = kexMath::Sin(roll);
float cr = kexMath::Cos(roll); float cr = kexMath::Cos(roll);
if(forward) if (forward)
{ {
forward->x = sy * cp; forward->x = sy * cp;
forward->y = sp; forward->y = sp;
forward->z = cy * cp; forward->z = cy * cp;
} }
if(right) if (right)
{ {
right->x = sr * sp * sy + cr * cy; right->x = sr * sp * sy + cr * cy;
right->y = sr * cp; right->y = sr * cp;
right->z = sr * sp * cy + cr * -sy; right->z = sr * sp * cy + cr * -sy;
} }
if(up) if (up)
{ {
up->x = cr * sp * sy + -sr * cy; up->x = cr * sp * sy + -sr * cy;
up->y = cr * cp; up->y = cr * cp;

View file

@ -75,12 +75,12 @@ void kexBBox::AddPoint(const kexVec3 &vec)
float hiy = max.y; float hiy = max.y;
float hiz = max.z; float hiz = max.z;
if(vec.x < lowx) { lowx = vec.x; } if (vec.x < lowx) { lowx = vec.x; }
if(vec.y < lowy) { lowy = vec.y; } if (vec.y < lowy) { lowy = vec.y; }
if(vec.z < lowz) { lowz = vec.z; } if (vec.z < lowz) { lowz = vec.z; }
if(vec.x > hix) { hix = vec.x; } if (vec.x > hix) { hix = vec.x; }
if(vec.y > hiy) { hiy = vec.y; } if (vec.y > hiy) { hiy = vec.y; }
if(vec.z > hiz) { hiz = vec.z; } if (vec.z > hiz) { hiz = vec.z; }
min.Set(lowx, lowy, lowz); min.Set(lowx, lowy, lowz);
max.Set(hix, hiy, hiz); max.Set(hix, hiy, hiz);
@ -117,12 +117,12 @@ float kexBBox::Radius() const
float r1; float r1;
float r2; float r2;
for(i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
r1 = kexMath::Fabs(min[i]); r1 = kexMath::Fabs(min[i]);
r2 = kexMath::Fabs(max[i]); r2 = kexMath::Fabs(max[i]);
if(r1 > r2) if (r1 > r2)
{ {
r += r1 * r1; r += r1 * r1;
} }
@ -185,7 +185,7 @@ float kexBBox::DistanceToPlane(kexPlane &plane)
dist = distStart - distEnd; dist = distStart - distEnd;
if(dist > 0) if (dist > 0)
{ {
// in front // in front
return dist; return dist;
@ -193,7 +193,7 @@ float kexBBox::DistanceToPlane(kexPlane &plane)
dist = distStart + distEnd; dist = distStart + distEnd;
if(dist < 0) if (dist < 0)
{ {
// behind // behind
return dist; return dist;
@ -324,7 +324,7 @@ kexBBox kexBBox::operator*(const kexMatrix &matrix) const
kexMatrix mtx(matrix); kexMatrix mtx(matrix);
for(int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
mtx.vectors[i].x = kexMath::Fabs(mtx.vectors[i].x); mtx.vectors[i].x = kexMath::Fabs(mtx.vectors[i].x);
mtx.vectors[i].y = kexMath::Fabs(mtx.vectors[i].y); mtx.vectors[i].y = kexMath::Fabs(mtx.vectors[i].y);
@ -349,7 +349,7 @@ kexBBox &kexBBox::operator*=(const kexMatrix &matrix)
kexMatrix mtx(matrix); kexMatrix mtx(matrix);
for(int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
mtx.vectors[i].x = kexMath::Fabs(mtx.vectors[i].x); mtx.vectors[i].x = kexMath::Fabs(mtx.vectors[i].x);
mtx.vectors[i].y = kexMath::Fabs(mtx.vectors[i].y); mtx.vectors[i].y = kexMath::Fabs(mtx.vectors[i].y);
@ -372,12 +372,12 @@ kexBBox kexBBox::operator*(const kexVec3 &vec) const
{ {
kexBBox box = *this; kexBBox box = *this;
if(vec.x < 0) { box.min.x += (vec.x-1); } if (vec.x < 0) { box.min.x += (vec.x - 1); }
else { box.max.x += (vec.x+1); } else { box.max.x += (vec.x + 1); }
if(vec.y < 0) { box.min.y += (vec.y-1); } if (vec.y < 0) { box.min.y += (vec.y - 1); }
else { box.max.y += (vec.y+1); } else { box.max.y += (vec.y + 1); }
if(vec.z < 0) { box.min.z += (vec.z-1); } if (vec.z < 0) { box.min.z += (vec.z - 1); }
else { box.max.z += (vec.z+1); } else { box.max.z += (vec.z + 1); }
return box; return box;
} }
@ -388,12 +388,12 @@ kexBBox kexBBox::operator*(const kexVec3 &vec) const
kexBBox &kexBBox::operator*=(const kexVec3 &vec) kexBBox &kexBBox::operator*=(const kexVec3 &vec)
{ {
if(vec.x < 0) { min.x += (vec.x-1); } if (vec.x < 0) { min.x += (vec.x - 1); }
else { max.x += (vec.x+1); } else { max.x += (vec.x + 1); }
if(vec.y < 0) { min.y += (vec.y-1); } if (vec.y < 0) { min.y += (vec.y - 1); }
else { max.y += (vec.y+1); } else { max.y += (vec.y + 1); }
if(vec.z < 0) { min.z += (vec.z-1); } if (vec.z < 0) { min.z += (vec.z - 1); }
else { max.z += (vec.z+1); } else { max.z += (vec.z + 1); }
return *this; return *this;
} }
@ -444,17 +444,17 @@ bool kexBBox::LineIntersect(const kexVec3 &start, const kexVec3 &end)
kexVec3 dir = lineCenter - center; kexVec3 dir = lineCenter - center;
ld[0] = kexMath::Fabs(lineDir.x); ld[0] = kexMath::Fabs(lineDir.x);
if(kexMath::Fabs(dir.x) > extents.x + ld[0]) { return false; } if (kexMath::Fabs(dir.x) > extents.x + ld[0]) { return false; }
ld[1] = kexMath::Fabs(lineDir.y); ld[1] = kexMath::Fabs(lineDir.y);
if(kexMath::Fabs(dir.y) > extents.y + ld[1]) { return false; } if (kexMath::Fabs(dir.y) > extents.y + ld[1]) { return false; }
ld[2] = kexMath::Fabs(lineDir.z); ld[2] = kexMath::Fabs(lineDir.z);
if(kexMath::Fabs(dir.z) > extents.z + ld[2]) { return false; } if (kexMath::Fabs(dir.z) > extents.z + ld[2]) { return false; }
kexVec3 cross = lineDir.Cross(dir); kexVec3 cross = lineDir.Cross(dir);
if(kexMath::Fabs(cross.x) > extents.y * ld[2] + extents.z * ld[1]) { return false; } if (kexMath::Fabs(cross.x) > extents.y * ld[2] + extents.z * ld[1]) { return false; }
if(kexMath::Fabs(cross.y) > extents.x * ld[2] + extents.z * ld[0]) { return false; } if (kexMath::Fabs(cross.y) > extents.x * ld[2] + extents.z * ld[0]) { return false; }
if(kexMath::Fabs(cross.z) > extents.x * ld[1] + extents.y * ld[0]) { return false; } if (kexMath::Fabs(cross.z) > extents.x * ld[1] + extents.y * ld[0]) { return false; }
return true; return true;
} }

View file

@ -41,9 +41,9 @@ int kexMath::RoundPowerOfTwo(int x)
{ {
int mask = 1; int mask = 1;
while(mask < 0x40000000) while (mask < 0x40000000)
{ {
if(x == mask || (x & (mask-1)) == x) if (x == mask || (x & (mask - 1)) == x)
{ {
return mask; return mask;
} }
@ -64,10 +64,10 @@ void kexMath::CubicCurve(const kexVec3 &start, const kexVec3 &end, const float t
int i; int i;
float xyz[3]; float xyz[3];
for(i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
xyz[i] = kexMath::Pow(1-time, 2) * start[i] + xyz[i] = kexMath::Pow(1 - time, 2) * start[i] +
(2 * (1-time)) * time * point[i] + kexMath::Pow(time, 2) * end[i]; (2 * (1 - time)) * time * point[i] + kexMath::Pow(time, 2) * end[i];
} }
vec->x = xyz[0]; vec->x = xyz[0];
@ -85,10 +85,10 @@ void kexMath::QuadraticCurve(const kexVec3 &start, const kexVec3 &end, const flo
int i; int i;
float xyz[3]; float xyz[3];
for(i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
xyz[i] = kexMath::Pow(1-time, 3) * start[i] + (3 * kexMath::Pow(1-time, 2)) * xyz[i] = kexMath::Pow(1 - time, 3) * start[i] + (3 * kexMath::Pow(1 - time, 2)) *
time * pt1[i] + (3 * (1-time)) * kexMath::Pow(time, 2) * pt2[i] + time * pt1[i] + (3 * (1 - time)) * kexMath::Pow(time, 2) * pt2[i] +
kexMath::Pow(time, 3) * end[i]; kexMath::Pow(time, 3) * end[i];
} }

View file

@ -650,8 +650,8 @@ d_inline float kexMath::InvSqrt(float x)
d_inline void kexMath::Clamp(float &f, const float min, const float max) d_inline void kexMath::Clamp(float &f, const float min, const float max)
{ {
if(f < min) { f = min; } if (f < min) { f = min; }
if(f > max) { f = max; } if (f > max) { f = max; }
} }
// //
@ -660,8 +660,8 @@ d_inline void kexMath::Clamp(float &f, const float min, const float max)
d_inline void kexMath::Clamp(byte &b, const byte min, const byte max) d_inline void kexMath::Clamp(byte &b, const byte min, const byte max)
{ {
if(b < min) { b = min; } if (b < min) { b = min; }
if(b > max) { b = max; } if (b > max) { b = max; }
} }
// //
@ -670,8 +670,8 @@ d_inline void kexMath::Clamp(byte &b, const byte min, const byte max)
d_inline void kexMath::Clamp(int &i, const int min, const int max) d_inline void kexMath::Clamp(int &i, const int min, const int max)
{ {
if(i < min) { i = min; } if (i < min) { i = min; }
if(i > max) { i = max; } if (i > max) { i = max; }
} }
// //
@ -680,10 +680,10 @@ d_inline void kexMath::Clamp(int &i, const int min, const int max)
d_inline void kexMath::Clamp(kexVec3 &v, const float min, const float max) d_inline void kexMath::Clamp(kexVec3 &v, const float min, const float max)
{ {
if(v.x < min) { v.x = min; } if (v.x < min) { v.x = min; }
if(v.x > max) { v.x = max; } if (v.x > max) { v.x = max; }
if(v.y < min) { v.y = min; } if (v.y < min) { v.y = min; }
if(v.y > max) { v.y = max; } if (v.y > max) { v.y = max; }
if(v.z < min) { v.z = min; } if (v.z < min) { v.z = min; }
if(v.z > max) { v.z = max; } if (v.z > max) { v.z = max; }
} }

View file

@ -88,7 +88,7 @@ kexMatrix::kexMatrix()
kexMatrix::kexMatrix(const kexMatrix &mtx) kexMatrix::kexMatrix(const kexMatrix &mtx)
{ {
for(int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
vectors[i].x = mtx.vectors[i].x; vectors[i].x = mtx.vectors[i].x;
vectors[i].y = mtx.vectors[i].y; vectors[i].y = mtx.vectors[i].y;
@ -155,7 +155,7 @@ kexMatrix::kexMatrix(const float angle, const int axis)
Identity(); Identity();
switch(axis) switch (axis)
{ {
case 0: case 0:
this->vectors[0].x = c; this->vectors[0].x = c;
@ -330,51 +330,51 @@ kexMatrix kexMatrix::Invert(kexMatrix &mtx)
m = mtx.ToFloatPtr(); m = mtx.ToFloatPtr();
d = m[ 0] * m[10] * m[ 5] - d = m[0] * m[10] * m[5] -
m[ 0] * m[ 9] * m[ 6] - m[0] * m[9] * m[6] -
m[ 1] * m[ 4] * m[10] + m[1] * m[4] * m[10] +
m[ 2] * m[ 4] * m[ 9] + m[2] * m[4] * m[9] +
m[ 1] * m[ 6] * m[ 8] - m[1] * m[6] * m[8] -
m[ 2] * m[ 5] * m[ 8]; m[2] * m[5] * m[8];
if(d != 0.0f) if (d != 0.0f)
{ {
kexMatrix inv; kexMatrix inv;
d = (1.0f / d); d = (1.0f / d);
inv.vectors[0].x = ( m[10] * m[ 5] - m[ 9] * m[ 6]) * d; inv.vectors[0].x = (m[10] * m[5] - m[9] * m[6]) * d;
inv.vectors[0].y = -((m[ 1] * m[10] - m[ 2] * m[ 9]) * d); inv.vectors[0].y = -((m[1] * m[10] - m[2] * m[9]) * d);
inv.vectors[0].z = ( m[ 1] * m[ 6] - m[ 2] * m[ 5]) * d; inv.vectors[0].z = (m[1] * m[6] - m[2] * m[5]) * d;
inv.vectors[0].w = 0; inv.vectors[0].w = 0;
inv.vectors[1].x = ( m[ 6] * m[ 8] - m[ 4] * m[10]) * d; inv.vectors[1].x = (m[6] * m[8] - m[4] * m[10]) * d;
inv.vectors[1].y = ( m[ 0] * m[10] - m[ 2] * m[ 8]) * d; inv.vectors[1].y = (m[0] * m[10] - m[2] * m[8]) * d;
inv.vectors[1].z = -((m[ 0] * m[ 6] - m[ 2] * m[ 4]) * d); inv.vectors[1].z = -((m[0] * m[6] - m[2] * m[4]) * d);
inv.vectors[1].w = 0; inv.vectors[1].w = 0;
inv.vectors[2].x = -((m[ 5] * m[ 8] - m[ 4] * m[ 9]) * d); inv.vectors[2].x = -((m[5] * m[8] - m[4] * m[9]) * d);
inv.vectors[2].y = ( m[ 1] * m[ 8] - m[ 0] * m[ 9]) * d; inv.vectors[2].y = (m[1] * m[8] - m[0] * m[9]) * d;
inv.vectors[2].z = -((m[ 1] * m[ 4] - m[ 0] * m[ 5]) * d); inv.vectors[2].z = -((m[1] * m[4] - m[0] * m[5]) * d);
inv.vectors[2].w = 0; inv.vectors[2].w = 0;
inv.vectors[3].x = ( inv.vectors[3].x = (
( m[13] * m[10] - m[14] * m[ 9]) * m[ 4] (m[13] * m[10] - m[14] * m[9]) * m[4]
+ m[14] * m[ 5] * m[ 8] + m[14] * m[5] * m[8]
- m[13] * m[ 6] * m[ 8] - m[13] * m[6] * m[8]
- m[12] * m[10] * m[ 5] - m[12] * m[10] * m[5]
+ m[12] * m[ 9] * m[ 6]) * d; + m[12] * m[9] * m[6]) * d;
inv.vectors[3].y = ( inv.vectors[3].y = (
m[ 0] * m[14] * m[ 9] m[0] * m[14] * m[9]
- m[ 0] * m[13] * m[10] - m[0] * m[13] * m[10]
- m[14] * m[ 1] * m[ 8] - m[14] * m[1] * m[8]
+ m[13] * m[ 2] * m[ 8] + m[13] * m[2] * m[8]
+ m[12] * m[ 1] * m[10] + m[12] * m[1] * m[10]
- m[12] * m[ 2] * m[ 9]) * d; - m[12] * m[2] * m[9]) * d;
inv.vectors[3].z = -( inv.vectors[3].z = -(
( m[ 0] * m[14] * m[ 5] (m[0] * m[14] * m[5]
- m[ 0] * m[13] * m[ 6] - m[0] * m[13] * m[6]
- m[14] * m[ 1] * m[ 4] - m[14] * m[1] * m[4]
+ m[13] * m[ 2] * m[ 4] + m[13] * m[2] * m[4]
+ m[12] * m[ 1] * m[ 6] + m[12] * m[1] * m[6]
- m[12] * m[ 2] * m[ 5]) * d); - m[12] * m[2] * m[5]) * d);
inv.vectors[3].w = 1.0f; inv.vectors[3].w = 1.0f;
return inv; return inv;
@ -468,7 +468,7 @@ kexQuat kexMatrix::ToQuat()
t = 1.0f + mx + my + mz; t = 1.0f + mx + my + mz;
if(t > 0) if (t > 0)
{ {
d = 0.5f / kexMath::Sqrt(t); d = 0.5f / kexMath::Sqrt(t);
q.x = m21 * d; q.x = m21 * d;
@ -476,7 +476,7 @@ kexQuat kexMatrix::ToQuat()
q.z = m10 * d; q.z = m10 * d;
q.w = 0.25f / d; q.w = 0.25f / d;
} }
else if(mx > my && mx > mz) else if (mx > my && mx > mz)
{ {
d = kexMath::Sqrt(1.0f + mx - my - mz) * 2; d = kexMath::Sqrt(1.0f + mx - my - mz) * 2;
q.x = 0.5f / d; q.x = 0.5f / d;
@ -484,7 +484,7 @@ kexQuat kexMatrix::ToQuat()
q.z = m20 / d; q.z = m20 / d;
q.w = m21 / d; q.w = m21 / d;
} }
else if(my > mz) else if (my > mz)
{ {
d = kexMath::Sqrt(1.0f + my - mx - mz) * 2; d = kexMath::Sqrt(1.0f + my - mx - mz) * 2;
q.x = m10 / d; q.x = m10 / d;
@ -550,7 +550,7 @@ kexMatrix kexMatrix::operator*(const kexMatrix &matrix)
{ {
kexMatrix out; kexMatrix out;
for(int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
out.vectors[i].x = out.vectors[i].x =
vectors[i].x * matrix.vectors[0].x + vectors[i].x * matrix.vectors[0].x +
@ -583,7 +583,7 @@ kexMatrix kexMatrix::operator*(const kexMatrix &matrix)
kexMatrix &kexMatrix::operator*=(const kexMatrix &matrix) kexMatrix &kexMatrix::operator*=(const kexMatrix &matrix)
{ {
for(int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
vectors[i].x = vectors[i].x =
vectors[i].x * matrix.vectors[0].x + vectors[i].x * matrix.vectors[0].x +
@ -618,7 +618,7 @@ kexMatrix operator*(const kexMatrix &m1, const kexMatrix &m2)
{ {
kexMatrix out; kexMatrix out;
for(int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
out.vectors[i].x = out.vectors[i].x =
m1.vectors[i].x * m2.vectors[0].x + m1.vectors[i].x * m2.vectors[0].x +
@ -653,7 +653,7 @@ kexMatrix kexMatrix::operator|(const kexMatrix &matrix)
{ {
kexMatrix out; kexMatrix out;
for(int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
out.vectors[i].x = out.vectors[i].x =
vectors[i].x * matrix.vectors[0].x + vectors[i].x * matrix.vectors[0].x +
@ -705,9 +705,9 @@ kexMatrix &kexMatrix::operator=(const kexMatrix &matrix)
kexMatrix &kexMatrix::operator=(const float *m) kexMatrix &kexMatrix::operator=(const float *m)
{ {
for(int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
for(int j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
{ {
vectors[i][j] = m[i * 4 + j]; vectors[i][j] = m[i * 4 + j];
} }

View file

@ -165,11 +165,11 @@ float kexPlane::ToYaw()
{ {
float d = Normal().Unit(); float d = Normal().Unit();
if(d != 0) if (d != 0)
{ {
float phi; float phi;
phi = kexMath::ACos(b / d); phi = kexMath::ACos(b / d);
if(a <= 0) if (a <= 0)
{ {
phi = -phi; phi = -phi;
} }
@ -228,11 +228,11 @@ const kexPlane::planeAxis_t kexPlane::BestAxis() const
float nc = kexMath::Fabs(c); float nc = kexMath::Fabs(c);
// figure out what axis the plane lies on // figure out what axis the plane lies on
if(na >= nb && na >= nc) if (na >= nb && na >= nc)
{ {
return AXIS_YZ; return AXIS_YZ;
} }
else if(nb >= na && nb >= nc) else if (nb >= na && nb >= nc)
{ {
return AXIS_XZ; return AXIS_XZ;
} }

View file

@ -134,7 +134,7 @@ float kexQuat::Unit() const
kexQuat &kexQuat::Normalize() kexQuat &kexQuat::Normalize()
{ {
float d = Unit(); float d = Unit();
if(d != 0.0f) if (d != 0.0f)
{ {
d = 1.0f / d; d = 1.0f / d;
*this *= d; *this *= d;
@ -319,18 +319,18 @@ kexQuat kexQuat::Slerp(const kexQuat &quat, float movement) const
float d1 = Dot(quat); float d1 = Dot(quat);
float d2 = Dot(quat.Inverse()); float d2 = Dot(quat.Inverse());
if(d1 < d2) if (d1 < d2)
{ {
rdest = quat.Inverse(); rdest = quat.Inverse();
d1 = d2; d1 = d2;
} }
if(d1 <= 0.7071067811865001f) if (d1 <= 0.7071067811865001f)
{ {
float halfcos = kexMath::ACos(d1); float halfcos = kexMath::ACos(d1);
float halfsin = kexMath::Sin(halfcos); float halfsin = kexMath::Sin(halfcos);
if(halfsin == 0) if (halfsin == 0)
{ {
kexQuat out; kexQuat out;
out.Set(x, y, z, w); out.Set(x, y, z, w);
@ -346,7 +346,7 @@ kexQuat kexQuat::Slerp(const kexQuat &quat, float movement) const
ms1 = kexMath::Sin((1.0f - movement) * halfcos) * d; ms1 = kexMath::Sin((1.0f - movement) * halfcos) * d;
ms2 = kexMath::Sin(halfcos * movement) * d; ms2 = kexMath::Sin(halfcos * movement) * d;
if(ms2 < 0) if (ms2 < 0)
{ {
rdest = quat.Inverse(); rdest = quat.Inverse();
} }
@ -380,7 +380,7 @@ kexQuat kexQuat::RotateFrom(const kexVec3 &location, const kexVec3 &target, floa
an = kexMath::ACos(axis.Dot(dir)); an = kexMath::ACos(axis.Dot(dir));
if(maxAngle != 0 && an >= maxAngle) if (maxAngle != 0 && an >= maxAngle)
{ {
an = maxAngle; an = maxAngle;
} }

View file

@ -71,7 +71,7 @@ int kexRand::Int()
int kexRand::Max(const int max) int kexRand::Max(const int max)
{ {
if(max == 0) if (max == 0)
{ {
return 0; return 0;
} }
@ -85,7 +85,7 @@ int kexRand::Max(const int max)
float kexRand::Float() float kexRand::Float()
{ {
return (float)Max(RANDOM_MAX+1) / ((float)RANDOM_MAX+1); return (float)Max(RANDOM_MAX + 1) / ((float)RANDOM_MAX + 1);
} }
// //

View file

@ -257,7 +257,7 @@ float kexVec2::ToYaw() const
{ {
float d = x * x + y * y; float d = x * x + y * y;
if(d == 0.0f) if (d == 0.0f)
{ {
return 0.0f; return 0.0f;
} }
@ -740,7 +740,7 @@ float kexVec3::ToYaw() const
{ {
float d = x * x + z * z; float d = x * x + z * z;
if(d == 0.0f) if (d == 0.0f)
{ {
return 0.0f; return 0.0f;
} }
@ -756,9 +756,9 @@ float kexVec3::ToPitch() const
{ {
float d = x * x + z * z; float d = x * x + z * z;
if(d == 0.0f) if (d == 0.0f)
{ {
if(y > 0.0f) if (y > 0.0f)
{ {
return DEG2RAD(90); return DEG2RAD(90);
} }
@ -828,7 +828,7 @@ kexVec3 kexVec3::ScreenProject(kexMatrix &proj, kexMatrix &model,
projVec.y *= modelVec.w; projVec.y *= modelVec.w;
projVec.z *= modelVec.w; projVec.z *= modelVec.w;
if(projVec.w != 0) if (projVec.w != 0)
{ {
projVec.w = 1.0f / projVec.w; projVec.w = 1.0f / projVec.w;
projVec.x *= projVec.w; projVec.x *= projVec.w;

View file

@ -61,9 +61,9 @@ kexHeapBlock::kexHeapBlock(const char *name, bool bGarbageCollect,
this->purgeID = kexHeap::numHeapBlocks++; this->purgeID = kexHeap::numHeapBlocks++;
// add heap block to main block list // add heap block to main block list
if(kexHeap::blockList) if (kexHeap::blockList)
{ {
if(kexHeap::blockList->prev) if (kexHeap::blockList->prev)
{ {
kexHeap::blockList->prev->next = this; kexHeap::blockList->prev->next = this;
this->prev = kexHeap::blockList->prev; this->prev = kexHeap::blockList->prev;
@ -103,17 +103,17 @@ kexHeapBlock::~kexHeapBlock()
kexHeapBlock *kexHeapBlock::operator[](int index) kexHeapBlock *kexHeapBlock::operator[](int index)
{ {
if(kexHeap::currentHeapBlockID == index) if (kexHeap::currentHeapBlockID == index)
{ {
return kexHeap::currentHeapBlock; return kexHeap::currentHeapBlock;
} }
kexHeapBlock *heapBlock = this; kexHeapBlock *heapBlock = this;
for(int i = 0; i < index; i++) for (int i = 0; i < index; i++)
{ {
heapBlock = heapBlock->next; heapBlock = heapBlock->next;
if(heapBlock == NULL) if (heapBlock == NULL)
{ {
return NULL; return NULL;
} }
@ -137,7 +137,7 @@ void kexHeap::AddBlock(memBlock *block, kexHeapBlock *heapBlock)
block->heapBlock = heapBlock; block->heapBlock = heapBlock;
if(block->next != NULL) if (block->next != NULL)
{ {
block->next->prev = block; block->next->prev = block;
} }
@ -149,7 +149,7 @@ void kexHeap::AddBlock(memBlock *block, kexHeapBlock *heapBlock)
void kexHeap::RemoveBlock(memBlock *block) void kexHeap::RemoveBlock(memBlock *block)
{ {
if(block->prev == NULL) if (block->prev == NULL)
{ {
block->heapBlock->blocks = block->next; block->heapBlock->blocks = block->next;
} }
@ -158,7 +158,7 @@ void kexHeap::RemoveBlock(memBlock *block)
block->prev->next = block->next; block->prev->next = block->next;
} }
if(block->next != NULL) if (block->next != NULL)
{ {
block->next->prev = block->prev; block->next->prev = block->prev;
} }
@ -176,7 +176,7 @@ memBlock *kexHeap::GetBlock(void *ptr, const char *file, int line)
block = (memBlock*)((byte*)ptr - sizeof(memBlock)); block = (memBlock*)((byte*)ptr - sizeof(memBlock));
if(block->heapTag != kexHeap::HeapTag) if (block->heapTag != kexHeap::HeapTag)
{ {
Error("kexHeap::GetBlock: found a pointer without heap tag (%s:%d)", file, line); Error("kexHeap::GetBlock: found a pointer without heap tag (%s:%d)", file, line);
} }
@ -196,7 +196,7 @@ void *kexHeap::Malloc(int size, kexHeapBlock &heapBlock, const char *file, int l
newblock = NULL; newblock = NULL;
if(!(newblock = (memBlock*)malloc(sizeof(memBlock) + size))) if (!(newblock = (memBlock*)malloc(sizeof(memBlock) + size)))
{ {
Error("kexHeap::Malloc: failed on allocation of %u bytes (%s:%d)", size, file, line); Error("kexHeap::Malloc: failed on allocation of %u bytes (%s:%d)", size, file, line);
} }
@ -229,14 +229,14 @@ void *kexHeap::Realloc(void *ptr, int size, kexHeapBlock &heapBlock, const char
memBlock *block; memBlock *block;
memBlock *newblock; memBlock *newblock;
if(!ptr) if (!ptr)
{ {
return kexHeap::Malloc(size, heapBlock, file, line); return kexHeap::Malloc(size, heapBlock, file, line);
} }
assert(size >= 0); assert(size >= 0);
if(size == 0) if (size == 0)
{ {
kexHeap::Free(ptr, file, line); kexHeap::Free(ptr, file, line);
return NULL; return NULL;
@ -250,12 +250,12 @@ void *kexHeap::Realloc(void *ptr, int size, kexHeapBlock &heapBlock, const char
block->next = NULL; block->next = NULL;
block->prev = NULL; block->prev = NULL;
if(block->ptrRef) if (block->ptrRef)
{ {
*block->ptrRef = NULL; *block->ptrRef = NULL;
} }
if(!(newblock = (memBlock*)realloc(block, sizeof(memBlock) + size))) if (!(newblock = (memBlock*)realloc(block, sizeof(memBlock) + size)))
{ {
Error("kexHeap::Realloc: failed on allocation of %u bytes (%s:%d)", size, file, line); Error("kexHeap::Realloc: failed on allocation of %u bytes (%s:%d)", size, file, line);
} }
@ -288,7 +288,7 @@ void kexHeap::Free(void *ptr, const char *file, int line)
memBlock* block; memBlock* block;
block = kexHeap::GetBlock(ptr, file, line); block = kexHeap::GetBlock(ptr, file, line);
if(block->ptrRef) if (block->ptrRef)
{ {
*block->ptrRef = NULL; *block->ptrRef = NULL;
} }
@ -308,16 +308,16 @@ void kexHeap::Purge(kexHeapBlock &heapBlock, const char *file, int line)
memBlock *block; memBlock *block;
memBlock *next; memBlock *next;
for(block = heapBlock.blocks; block != NULL;) for (block = heapBlock.blocks; block != NULL;)
{ {
next = block->next; next = block->next;
if(block->heapTag != kexHeap::HeapTag) if (block->heapTag != kexHeap::HeapTag)
{ {
Error("kexHeap::Purge: Purging without heap tag (%s:%d)", file, line); Error("kexHeap::Purge: Purging without heap tag (%s:%d)", file, line);
} }
if(block->ptrRef) if (block->ptrRef)
{ {
*block->ptrRef = NULL; *block->ptrRef = NULL;
} }
@ -357,17 +357,17 @@ void kexHeap::CheckBlocks(const char *file, int line)
memBlock *prev; memBlock *prev;
kexHeapBlock *heapBlock; kexHeapBlock *heapBlock;
for(heapBlock = kexHeap::blockList; heapBlock; heapBlock = heapBlock->next) for (heapBlock = kexHeap::blockList; heapBlock; heapBlock = heapBlock->next)
{ {
prev = NULL; prev = NULL;
for(block = heapBlock->blocks; block != NULL; block = block->next) for (block = heapBlock->blocks; block != NULL; block = block->next)
{ {
if(block->heapTag != kexHeap::HeapTag) if (block->heapTag != kexHeap::HeapTag)
{ {
Error("kexHeap::CheckBlocks: found block without heap tag (%s:%d)", file, line); Error("kexHeap::CheckBlocks: found block without heap tag (%s:%d)", file, line);
} }
if(block->prev != prev) if (block->prev != prev)
{ {
Error("kexHeap::CheckBlocks: bad link list found (%s:%d)", file, line); Error("kexHeap::CheckBlocks: bad link list found (%s:%d)", file, line);
} }
@ -394,7 +394,7 @@ int kexHeap::Usage(const kexHeapBlock &heapBlock)
int bytes = 0; int bytes = 0;
memBlock *block; memBlock *block;
for(block = heapBlock.blocks; block != NULL; block = block->next) for (block = heapBlock.blocks; block != NULL; block = block->next)
{ {
bytes += block->size; bytes += block->size;
} }

View file

@ -27,7 +27,7 @@
#pragma once #pragma once
typedef void (*blockFunc_t)(void*); typedef void(*blockFunc_t)(void*);
class kexHeapBlock; class kexHeapBlock;

View file

@ -67,9 +67,9 @@ void kexLightmapBuilder::NewTexture()
numTextures++; numTextures++;
allocBlocks = (int**)Mem_Realloc(allocBlocks, sizeof(int*) * numTextures, hb_static); allocBlocks = (int**)Mem_Realloc(allocBlocks, sizeof(int*) * numTextures, hb_static);
allocBlocks[numTextures-1] = (int*)Mem_Calloc(sizeof(int) * textureWidth, hb_static); allocBlocks[numTextures - 1] = (int*)Mem_Calloc(sizeof(int) * textureWidth, hb_static);
memset(allocBlocks[numTextures-1], 0, sizeof(int) * textureWidth); memset(allocBlocks[numTextures - 1], 0, sizeof(int) * textureWidth);
uint16_t *texture = (uint16_t*)Mem_Calloc((textureWidth * textureHeight) * 3 * 2, hb_static); uint16_t *texture = (uint16_t*)Mem_Calloc((textureWidth * textureHeight) * 3 * 2, hb_static);
textures.Push(texture); textures.Push(texture);
@ -86,47 +86,47 @@ bool kexLightmapBuilder::MakeRoomForBlock(const int width, const int height, int
*num = -1; *num = -1;
if(allocBlocks == NULL) if (allocBlocks == NULL)
{ {
return false; return false;
} }
for(k = 0; k < numTextures; ++k) for (k = 0; k < numTextures; ++k)
{ {
bestRow1 = textureHeight; bestRow1 = textureHeight;
for(i = 0; i <= textureWidth - width; i++) for (i = 0; i <= textureWidth - width; i++)
{ {
bestRow2 = 0; bestRow2 = 0;
for(j = 0; j < width; j++) for (j = 0; j < width; j++)
{ {
if(allocBlocks[k][i + j] >= bestRow1) if (allocBlocks[k][i + j] >= bestRow1)
{ {
break; break;
} }
if(allocBlocks[k][i + j] > bestRow2) if (allocBlocks[k][i + j] > bestRow2)
{ {
bestRow2 = allocBlocks[k][i + j]; bestRow2 = allocBlocks[k][i + j];
} }
} }
// found a free block // found a free block
if(j == width) if (j == width)
{ {
*x = i; *x = i;
*y = bestRow1 = bestRow2; *y = bestRow1 = bestRow2;
} }
} }
if(bestRow1 + height > textureHeight) if (bestRow1 + height > textureHeight)
{ {
// no room // no room
continue; continue;
} }
for(i = 0; i < width; i++) for (i = 0; i < width; i++)
{ {
// store row offset // store row offset
allocBlocks[k][*x + i] = bestRow1 + height; allocBlocks[k][*x + i] = bestRow1 + height;
@ -147,15 +147,15 @@ kexBBox kexLightmapBuilder::GetBoundsFromSurface(const surface_t *surface)
kexBBox bounds; kexBBox bounds;
bounds.Clear(); bounds.Clear();
for(int i = 0; i < surface->numVerts; i++) for (int i = 0; i < surface->numVerts; i++)
{ {
for(int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
{ {
if(surface->verts[i][j] < low[j]) if (surface->verts[i][j] < low[j])
{ {
low[j] = surface->verts[i][j]; low[j] = surface->verts[i][j];
} }
if(surface->verts[i][j] > hi[j]) if (surface->verts[i][j] > hi[j])
{ {
hi[j] = surface->verts[i][j]; hi[j] = surface->verts[i][j];
} }
@ -173,7 +173,7 @@ bool kexLightmapBuilder::EmitFromCeiling(kexTrace &trace, const surface_t *surfa
{ {
float attenuation = normal.Dot(map->GetSunDirection()); float attenuation = normal.Dot(map->GetSunDirection());
if(attenuation <= 0) if (attenuation <= 0)
{ {
// plane is not even facing the sunlight // plane is not even facing the sunlight
return false; return false;
@ -181,14 +181,14 @@ bool kexLightmapBuilder::EmitFromCeiling(kexTrace &trace, const surface_t *surfa
trace.Trace(origin, origin + (map->GetSunDirection() * 32768.0f)); trace.Trace(origin, origin + (map->GetSunDirection() * 32768.0f));
if(trace.fraction == 1.0f) if (trace.fraction == 1.0f)
{ {
// nothing was hit // nothing was hit
//color.x += 1.0f; //color.x += 1.0f;
return false; return false;
} }
if(trace.hitSurface->bSky == false) if (trace.hitSurface->bSky == false)
{ {
if (trace.hitSurface->type == ST_CEILING) if (trace.hitSurface->type == ST_CEILING)
return false; return false;
@ -221,7 +221,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
kexVec3 color(0.0f, 0.0f, 0.0f); kexVec3 color(0.0f, 0.0f, 0.0f);
// check all thing lights // check all thing lights
for(unsigned int i = 0; i < map->thingLights.Size(); i++) for (unsigned int i = 0; i < map->thingLights.Size(); i++)
{ {
thingLight_t *tl = map->thingLights[i]; thingLight_t *tl = map->thingLights[i];
@ -233,7 +233,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
kexVec3 lightOrigin(tl->origin.x, tl->origin.y, originZ); kexVec3 lightOrigin(tl->origin.x, tl->origin.y, originZ);
if(plane.Distance(lightOrigin) - plane.d < 0) if (plane.Distance(lightOrigin) - plane.d < 0)
{ {
// completely behind the plane // completely behind the plane
continue; continue;
@ -242,7 +242,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
float radius = tl->radius * 2.0f; // 2.0 because gzdoom's dynlights do this and we want them to match float radius = tl->radius * 2.0f; // 2.0 because gzdoom's dynlights do this and we want them to match
float intensity = tl->intensity; float intensity = tl->intensity;
if(origin.DistanceSq(lightOrigin) > (radius*radius)) if (origin.DistanceSq(lightOrigin) > (radius*radius))
{ {
// not within range // not within range
continue; continue;
@ -272,7 +272,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
trace.Trace(lightOrigin, origin); trace.Trace(lightOrigin, origin);
if(trace.fraction != 1) if (trace.fraction != 1)
{ {
// this light is occluded by something // this light is occluded by something
continue; continue;
@ -289,20 +289,20 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
tracedTexels++; tracedTexels++;
} }
if(surface->type != ST_CEILING) if (surface->type != ST_CEILING)
{ {
// see if it's exposed to sunlight // see if it's exposed to sunlight
if(EmitFromCeiling(trace, surface, origin, plane.Normal(), color)) if (EmitFromCeiling(trace, surface, origin, plane.Normal(), color))
tracedTexels++; tracedTexels++;
} }
// trace against surface lights // trace against surface lights
for(unsigned int i = 0; i < map->lightSurfaces.Size(); ++i) for (unsigned int i = 0; i < map->lightSurfaces.Size(); ++i)
{ {
kexLightSurface *surfaceLight = map->lightSurfaces[i]; kexLightSurface *surfaceLight = map->lightSurfaces[i];
float attenuation; float attenuation;
if(surfaceLight->TraceSurface(map, trace, surface, origin, &attenuation)) if (surfaceLight->TraceSurface(map, trace, surface, origin, &attenuation))
{ {
color += surfaceLight->GetRGB() * attenuation; color += surfaceLight->GetRGB() * attenuation;
@ -332,7 +332,7 @@ void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
bounds = GetBoundsFromSurface(surface); bounds = GetBoundsFromSurface(surface);
// round off dimentions // round off dimentions
for(i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
bounds.min[i] = samples * kexMath::Floor(bounds.min[i] / samples); bounds.min[i] = samples * kexMath::Floor(bounds.min[i] / samples);
bounds.max[i] = samples * kexMath::Ceil(bounds.max[i] / samples); bounds.max[i] = samples * kexMath::Ceil(bounds.max[i] / samples);
@ -345,7 +345,7 @@ void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
axis = plane->BestAxis(); axis = plane->BestAxis();
switch(axis) switch (axis)
{ {
case kexPlane::AXIS_YZ: case kexPlane::AXIS_YZ:
width = (int)roundedSize.y; width = (int)roundedSize.y;
@ -370,14 +370,14 @@ void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
} }
// clamp width // clamp width
if(width > textureWidth) if (width > textureWidth)
{ {
tCoords[0] *= ((float)textureWidth / (float)width); tCoords[0] *= ((float)textureWidth / (float)width);
width = textureWidth; width = textureWidth;
} }
// clamp height // clamp height
if(height > textureHeight) if (height > textureHeight)
{ {
tCoords[1] *= ((float)textureHeight / (float)height); tCoords[1] *= ((float)textureHeight / (float)height);
height = textureHeight; height = textureHeight;
@ -395,7 +395,7 @@ void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
d = (plane->Distance(bounds.min) - plane->d) / plane->Normal()[axis]; d = (plane->Distance(bounds.min) - plane->d) / plane->Normal()[axis];
tOrigin[axis] -= d; tOrigin[axis] -= d;
for(i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
tCoords[i].Normalize(); tCoords[i].Normalize();
d = plane->Distance(tCoords[i]) / plane->Normal()[axis]; d = plane->Distance(tCoords[i]) / plane->Normal()[axis];
@ -437,9 +437,9 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
int multisampleCount = Multisample; int multisampleCount = Multisample;
// start walking through each texel // start walking through each texel
for(i = 0; i < sampleHeight; i++) for (i = 0; i < sampleHeight; i++)
{ {
for(j = 0; j < sampleWidth; j++) for (j = 0; j < sampleWidth; j++)
{ {
kexVec3 c(0.0f, 0.0f, 0.0f); kexVec3 c(0.0f, 0.0f, 0.0f);
@ -482,7 +482,7 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
// SVE redraws the scene for lightmaps, so for optimizations, // SVE redraws the scene for lightmaps, so for optimizations,
// tell the engine to ignore this surface if completely black // tell the engine to ignore this surface if completely black
if(bShouldLookupTexture == false) if (bShouldLookupTexture == false)
{ {
surface->lightmapNum = -1; surface->lightmapNum = -1;
return; return;
@ -498,12 +498,12 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
// now that we know the width and height of this block, see if we got // now that we know the width and height of this block, see if we got
// room for it in the light map texture. if not, then we must allocate // room for it in the light map texture. if not, then we must allocate
// a new texture // a new texture
if(!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum)) if (!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum))
{ {
// allocate a new texture for this block // allocate a new texture for this block
NewTexture(); NewTexture();
if(!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum)) if (!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum))
{ {
Error("Lightmap allocation failed\n"); Error("Lightmap allocation failed\n");
return; return;
@ -513,7 +513,7 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
lock.unlock(); lock.unlock();
// calculate texture coordinates // calculate texture coordinates
for(i = 0; i < surface->numVerts; i++) for (i = 0; i < surface->numVerts; i++)
{ {
tDelta = surface->verts[i] - surface->bounds.min; tDelta = surface->verts[i] - surface->bounds.min;
surface->lightmapCoords[i * 2 + 0] = surface->lightmapCoords[i * 2 + 0] =
@ -531,9 +531,9 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
lock.unlock(); lock.unlock();
// store results to lightmap texture // store results to lightmap texture
for(i = 0; i < sampleHeight; i++) for (i = 0; i < sampleHeight; i++)
{ {
for(j = 0; j < sampleWidth; j++) for (j = 0; j < sampleWidth; j++)
{ {
// get texture offset // get texture offset
int offs = (((textureWidth * (i + surface->lightmapOffs[1])) + surface->lightmapOffs[0]) * 3); int offs = (((textureWidth * (i + surface->lightmapOffs[1])) + surface->lightmapOffs[0]) * 3);
@ -552,7 +552,7 @@ void kexLightmapBuilder::LightSurface(const int surfid)
int numsurfs = surfaces.Length(); int numsurfs = surfaces.Length();
// TODO: this should NOT happen, but apparently, it can randomly occur // TODO: this should NOT happen, but apparently, it can randomly occur
if(surfaces.Length() == 0) if (surfaces.Length() == 0)
{ {
return; return;
} }
@ -703,7 +703,7 @@ void kexLightmapBuilder::WriteTexturesToTGA()
{ {
kexBinFile file; kexBinFile file;
for(unsigned int i = 0; i < textures.Length(); i++) for (unsigned int i = 0; i < textures.Length(); i++)
{ {
file.Create(Va("lightmap_%02d.tga", i)); file.Create(Va("lightmap_%02d.tga", i));
file.Write16(0); file.Write16(0);
@ -716,11 +716,11 @@ void kexLightmapBuilder::WriteTexturesToTGA()
file.Write16(textureHeight); file.Write16(textureHeight);
file.Write16(24); file.Write16(24);
for(int j = 0; j < (textureWidth * textureHeight) * 3; j += 3) for (int j = 0; j < (textureWidth * textureHeight) * 3; j += 3)
{ {
file.Write8(textures[i][j+2]); file.Write8(textures[i][j + 2]);
file.Write8(textures[i][j+1]); file.Write8(textures[i][j + 1]);
file.Write8(textures[i][j+0]); file.Write8(textures[i][j + 0]);
} }
file.Close(); file.Close();
} }

View file

@ -62,8 +62,6 @@ private:
kexBBox GetBoundsFromSurface(const surface_t *surface); kexBBox GetBoundsFromSurface(const surface_t *surface);
kexVec3 LightTexelSample(kexTrace &trace, const kexVec3 &origin, surface_t *surface); kexVec3 LightTexelSample(kexTrace &trace, const kexVec3 &origin, surface_t *surface);
bool EmitFromCeiling(kexTrace &trace, const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, kexVec3 &color); bool EmitFromCeiling(kexTrace &trace, const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, kexVec3 &color);
void ExportTexelsToObjFile(FILE *f, const kexVec3 &org, int indices);
void WriteBlock(FILE *f, const int i, const kexVec3 &org, int indices, kexBBox &box);
FLevel *map; FLevel *map;
kexArray<uint16_t*> textures; kexArray<uint16_t*> textures;

View file

@ -58,11 +58,11 @@ void kexLightSurface::Init(const surfaceLightDef &lightSurfaceDef, surface_t *su
// Creates a single origin point if we're not intending on subdividing this light surface // Creates a single origin point if we're not intending on subdividing this light surface
void kexLightSurface::CreateCenterOrigin() void kexLightSurface::CreateCenterOrigin()
{ {
if(!bWall) if (!bWall)
{ {
kexVec3 center; kexVec3 center;
for(int i = 0; i < surface->numVerts; ++i) for (int i = 0; i < surface->numVerts; ++i)
{ {
center += surface->verts[i]; center += surface->verts[i];
} }
@ -84,17 +84,17 @@ void kexLightSurface::Clip(vertexBatch_t &points, const kexVec3 &normal, float d
kexArray<char> sides; kexArray<char> sides;
// determines what sides the vertices lies on // determines what sides the vertices lies on
for(unsigned int i = 0; i < points.Length(); ++i) for (unsigned int i = 0; i < points.Length(); ++i)
{ {
float d = points[i].Dot(normal) - dist; float d = points[i].Dot(normal) - dist;
dists.Push(d); dists.Push(d);
if(d > 0.1f) if (d > 0.1f)
{ {
sides.Push(1); // front sides.Push(1); // front
} }
else if(d < -0.1f) else if (d < -0.1f)
{ {
sides.Push(-1); // directly on the split plane sides.Push(-1); // directly on the split plane
} }
@ -105,13 +105,13 @@ void kexLightSurface::Clip(vertexBatch_t &points, const kexVec3 &normal, float d
} }
// add points // add points
for(unsigned int i = 0; i < points.Length(); ++i) for (unsigned int i = 0; i < points.Length(); ++i)
{ {
int next; int next;
float frac; float frac;
kexVec3 pt1, pt2, pt3; kexVec3 pt1, pt2, pt3;
switch(sides[i]) switch (sides[i])
{ {
case -1: case -1:
backPoints->Push(points[i]); backPoints->Push(points[i]);
@ -133,7 +133,7 @@ void kexLightSurface::Clip(vertexBatch_t &points, const kexVec3 &normal, float d
// check if the edge crosses the split plane // check if the edge crosses the split plane
next = (i + 1) % points.Length(); next = (i + 1) % points.Length();
if(sides[next] == 0 || sides[next] == sides[i]) if (sides[next] == 0 || sides[next] == sides[i])
{ {
// didn't cross // didn't cross
continue; continue;
@ -161,15 +161,15 @@ bool kexLightSurface::SubdivideRecursion(vertexBatch_t &surfPoints, float divide
vertexBatch_t *backPoints; vertexBatch_t *backPoints;
// get bounds from current set of points // get bounds from current set of points
for(unsigned int i = 0; i < surfPoints.Length(); ++i) for (unsigned int i = 0; i < surfPoints.Length(); ++i)
{ {
bounds.AddPoint(surfPoints[i]); bounds.AddPoint(surfPoints[i]);
} }
for(int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
{ {
// check if its large enough to be divided // check if its large enough to be divided
if((bounds.max[i] - bounds.min[i]) > divide) if ((bounds.max[i] - bounds.min[i]) > divide)
{ {
splitNormal.Clear(); splitNormal.Clear();
splitNormal[i] = 1; splitNormal[i] = 1;
@ -182,7 +182,7 @@ bool kexLightSurface::SubdivideRecursion(vertexBatch_t &surfPoints, float divide
// start clipping // start clipping
Clip(surfPoints, splitNormal, dist, frontPoints, backPoints); Clip(surfPoints, splitNormal, dist, frontPoints, backPoints);
if(!SubdivideRecursion(*frontPoints, divide, points)) if (!SubdivideRecursion(*frontPoints, divide, points))
{ {
points.Push(frontPoints); points.Push(frontPoints);
} }
@ -191,7 +191,7 @@ bool kexLightSurface::SubdivideRecursion(vertexBatch_t &surfPoints, float divide
delete frontPoints; delete frontPoints;
} }
if(!SubdivideRecursion(*backPoints, divide, points)) if (!SubdivideRecursion(*backPoints, divide, points))
{ {
points.Push(backPoints); points.Push(backPoints);
} }
@ -212,7 +212,7 @@ void kexLightSurface::Subdivide(const float divide)
kexArray<vertexBatch_t*> points; kexArray<vertexBatch_t*> points;
vertexBatch_t surfPoints; vertexBatch_t surfPoints;
for(int i = 0; i < surface->numVerts; ++i) for (int i = 0; i < surface->numVerts; ++i)
{ {
surfPoints.Push(surface->verts[i]); surfPoints.Push(surface->verts[i]);
} }
@ -221,12 +221,12 @@ void kexLightSurface::Subdivide(const float divide)
// from each group of vertices caused by the split, begin // from each group of vertices caused by the split, begin
// creating a origin point based on the center of that group // creating a origin point based on the center of that group
for(unsigned int i = 0; i < points.Length(); ++i) for (unsigned int i = 0; i < points.Length(); ++i)
{ {
vertexBatch_t *vb = points[i]; vertexBatch_t *vb = points[i];
kexVec3 center; kexVec3 center;
for(unsigned int j = 0; j < vb->Length(); ++j) for (unsigned int j = 0; j < vb->Length(); ++j)
{ {
center += (*vb)[j]; center += (*vb)[j];
} }
@ -234,7 +234,7 @@ void kexLightSurface::Subdivide(const float divide)
origins.Push(center / (float)vb->Length()); origins.Push(center / (float)vb->Length());
} }
for(unsigned int i = 0; i < points.Length(); ++i) for (unsigned int i = 0; i < points.Length(); ++i)
{ {
vertexBatch_t *vb = points[i]; vertexBatch_t *vb = points[i];
@ -252,7 +252,7 @@ bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surfa
*dist = -M_INFINITY; *dist = -M_INFINITY;
// light surface will always be fullbright // light surface will always be fullbright
if(surf == surface) if (surf == surface)
{ {
*dist = Intensity(); *dist = Intensity();
return true; return true;
@ -260,11 +260,11 @@ bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surfa
lnormal = surface->plane.Normal(); lnormal = surface->plane.Normal();
if(surf) if (surf)
{ {
normal = surf->plane.Normal(); normal = surf->plane.Normal();
if(normal.Dot(lnormal) > 0) if (normal.Dot(lnormal) > 0)
{ {
// not facing the light surface // not facing the light surface
return false; return false;
@ -277,11 +277,11 @@ bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surfa
// we need to pick the closest sample point on the light surface. what really sucks is // we need to pick the closest sample point on the light surface. what really sucks is
// that we have to trace each one... which could really blow up the compile time // that we have to trace each one... which could really blow up the compile time
for(unsigned int i = 0; i < origins.Length(); ++i) for (unsigned int i = 0; i < origins.Length(); ++i)
{ {
kexVec3 center = origins[i]; kexVec3 center = origins[i];
if(!bWall && origin.z > center.z) if (!bWall && origin.z > center.z)
{ {
// origin is not going to seen or traced by the light surface // origin is not going to seen or traced by the light surface
// so don't even bother. this also fixes some bizzare light // so don't even bother. this also fixes some bizzare light
@ -309,9 +309,9 @@ bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surfa
angle = dir.Dot(lnormal); angle = dir.Dot(lnormal);
}*/ }*/
if(bWall) if (bWall)
{ {
if(origin.z >= surface->verts[0].z && origin.z <= surface->verts[2].z) if (origin.z >= surface->verts[0].z && origin.z <= surface->verts[2].z)
{ {
// since walls are always vertically straight, we can cheat a little by adjusting // since walls are always vertically straight, we can cheat a little by adjusting
// the sampling point height. this also allows us to do accurate light emitting // the sampling point height. this also allows us to do accurate light emitting
@ -324,7 +324,7 @@ bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surfa
// case the start/end points are directly on or inside the surface // case the start/end points are directly on or inside the surface
trace.Trace(center + lnormal, origin + normal); trace.Trace(center + lnormal, origin + normal);
if(trace.fraction != 1) if (trace.fraction != 1)
{ {
// something is obstructing it // something is obstructing it
continue; continue;
@ -335,20 +335,20 @@ bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surfa
curDist = 1.0f - d / (distance * 2.0f); // 2.0 because gzdoom's dynlights do this and we want them to match curDist = 1.0f - d / (distance * 2.0f); // 2.0 because gzdoom's dynlights do this and we want them to match
if (curDist < 0.0f) curDist = 0.0f; if (curDist < 0.0f) curDist = 0.0f;
if(curDist >= 1) if (curDist >= 1)
{ {
curDist = 1; curDist = 1;
// might get large unlit gaps near the surface. this looks a lot worse for // might get large unlit gaps near the surface. this looks a lot worse for
// non-wall light surfaces so just clamp to full bright and exit out. // non-wall light surfaces so just clamp to full bright and exit out.
if(!bWall) if (!bWall)
{ {
*dist = 1; *dist = 1;
break; break;
} }
} }
if(curDist > *dist) if (curDist > *dist)
{ {
*dist = curDist; *dist = curDist;
} }

View file

@ -61,7 +61,7 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
float v2Top = front->ceilingplane.zAt(v2.x, v2.y); float v2Top = front->ceilingplane.zAt(v2.x, v2.y);
float v2Bottom = front->floorplane.zAt(v2.x, v2.y); float v2Bottom = front->floorplane.zAt(v2.x, v2.y);
if(back) if (back)
{ {
float v1TopBack = back->ceilingplane.zAt(v1.x, v1.y); float v1TopBack = back->ceilingplane.zAt(v1.x, v1.y);
float v1BottomBack = back->floorplane.zAt(v1.x, v1.y); float v1BottomBack = back->floorplane.zAt(v1.x, v1.y);
@ -74,9 +74,9 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
} }
// bottom seg // bottom seg
if(v1Bottom < v1BottomBack || v2Bottom < v2BottomBack) if (v1Bottom < v1BottomBack || v2Bottom < v2BottomBack)
{ {
if(side->bottomtexture[0] != '-') if (side->bottomtexture[0] != '-')
{ {
surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static);
surf->numVerts = 4; surf->numVerts = 4;
@ -104,21 +104,21 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
} }
// top seg // top seg
if(v1Top > v1TopBack || v2Top > v2TopBack) if (v1Top > v1TopBack || v2Top > v2TopBack)
{ {
bool bSky = false; bool bSky = false;
int frontidx = front - &doomMap.Sectors[0]; int frontidx = front - &doomMap.Sectors[0];
int backidx = back - &doomMap.Sectors[0]; int backidx = back - &doomMap.Sectors[0];
if(doomMap.bSkySectors[frontidx] && doomMap.bSkySectors[backidx]) if (doomMap.bSkySectors[frontidx] && doomMap.bSkySectors[backidx])
{ {
if(front->data.ceilingheight != back->data.ceilingheight && side->toptexture[0] == '-') if (front->data.ceilingheight != back->data.ceilingheight && side->toptexture[0] == '-')
{ {
bSky = true; bSky = true;
} }
} }
if(side->toptexture[0] != '-' || bSky) if (side->toptexture[0] != '-' || bSky)
{ {
surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static);
surf->numVerts = 4; surf->numVerts = 4;
@ -148,7 +148,7 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
} }
// middle seg // middle seg
if(back == NULL) if (back == NULL)
{ {
surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static);
surf->numVerts = 4; surf->numVerts = 4;
@ -181,13 +181,13 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
printf("------------- Building subsector surfaces -------------\n"); printf("------------- Building subsector surfaces -------------\n");
for(i = 0; i < doomMap.NumGLSubsectors; i++) for (i = 0; i < doomMap.NumGLSubsectors; i++)
{ {
printf("subsectors: %i / %i\r", i+1, doomMap.NumGLSubsectors); printf("subsectors: %i / %i\r", i + 1, doomMap.NumGLSubsectors);
MapSubsectorEx *sub = &doomMap.GLSubsectors[i]; MapSubsectorEx *sub = &doomMap.GLSubsectors[i];
if(sub->numlines < 3) if (sub->numlines < 3)
{ {
continue; continue;
} }
@ -196,7 +196,7 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
// I will be NOT surprised if some users tries to do something stupid with // I will be NOT surprised if some users tries to do something stupid with
// sector hacks // sector hacks
if(sector == NULL) if (sector == NULL)
{ {
Error("CreateSubsectorSurfaces: subsector %i has no sector\n", i); Error("CreateSubsectorSurfaces: subsector %i has no sector\n", i);
return; return;
@ -210,7 +210,7 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * surf->numVerts, hb_static); surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * surf->numVerts, hb_static);
// floor verts // floor verts
for(j = 0; j < surf->numVerts; j++) for (j = 0; j < surf->numVerts; j++)
{ {
MapSegGLEx *seg = &doomMap.GLSegs[sub->firstline + (surf->numVerts - 1) - j]; MapSegGLEx *seg = &doomMap.GLSegs[sub->firstline + (surf->numVerts - 1) - j];
FloatVertex v1 = doomMap.GetSegVertex(seg->v1); FloatVertex v1 = doomMap.GetSegVertex(seg->v1);
@ -230,13 +230,13 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
surf->numVerts = sub->numlines; surf->numVerts = sub->numlines;
surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * surf->numVerts, hb_static); surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * surf->numVerts, hb_static);
if(doomMap.bSkySectors[sector-&doomMap.Sectors[0]]) if (doomMap.bSkySectors[sector - &doomMap.Sectors[0]])
{ {
surf->bSky = true; surf->bSky = true;
} }
// ceiling verts // ceiling verts
for(j = 0; j < surf->numVerts; j++) for (j = 0; j < surf->numVerts; j++)
{ {
MapSegGLEx *seg = &doomMap.GLSegs[sub->firstline + j]; MapSegGLEx *seg = &doomMap.GLSegs[sub->firstline + j];
FloatVertex v1 = doomMap.GetSegVertex(seg->v1); FloatVertex v1 = doomMap.GetSegVertex(seg->v1);
@ -315,10 +315,10 @@ void CreateSurfaces(FLevel &doomMap)
printf("------------- Building side surfaces -------------\n"); printf("------------- Building side surfaces -------------\n");
for(unsigned int i = 0; i < doomMap.Sides.Size(); i++) for (unsigned int i = 0; i < doomMap.Sides.Size(); i++)
{ {
CreateSideSurfaces(doomMap, &doomMap.Sides[i]); CreateSideSurfaces(doomMap, &doomMap.Sides[i]);
printf("sides: %i / %i\r", i+1, doomMap.Sides.Size()); printf("sides: %i / %i\r", i + 1, doomMap.Sides.Size());
} }
printf("\nSide surfaces: %i\n", surfaces.Length()); printf("\nSide surfaces: %i\n", surfaces.Length());

View file

@ -31,7 +31,7 @@ struct MapSubsectorEx;
enum surfaceType_t enum surfaceType_t
{ {
ST_UNKNOWN = 0, ST_UNKNOWN,
ST_MIDDLESIDE, ST_MIDDLESIDE,
ST_UPPERSIDE, ST_UPPERSIDE,
ST_LOWERSIDE, ST_LOWERSIDE,