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

View file

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

View file

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

View file

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

View file

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

View file

@ -41,9 +41,9 @@ int kexMath::RoundPowerOfTwo(int x)
{
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;
}
@ -64,10 +64,10 @@ void kexMath::CubicCurve(const kexVec3 &start, const kexVec3 &end, const float t
int i;
float xyz[3];
for(i = 0; i < 3; i++)
for (i = 0; i < 3; i++)
{
xyz[i] = kexMath::Pow(1-time, 2) * start[i] +
(2 * (1-time)) * time * point[i] + kexMath::Pow(time, 2) * end[i];
xyz[i] = kexMath::Pow(1 - time, 2) * start[i] +
(2 * (1 - time)) * time * point[i] + kexMath::Pow(time, 2) * end[i];
}
vec->x = xyz[0];
@ -85,10 +85,10 @@ void kexMath::QuadraticCurve(const kexVec3 &start, const kexVec3 &end, const flo
int i;
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)) *
time * pt1[i] + (3 * (1-time)) * kexMath::Pow(time, 2) * pt2[i] +
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] +
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)
{
if(f < min) { f = min; }
if(f > max) { f = max; }
if (f < min) { f = min; }
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)
{
if(b < min) { b = min; }
if(b > max) { b = max; }
if (b < min) { b = min; }
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)
{
if(i < min) { i = min; }
if(i > max) { i = max; }
if (i < min) { i = min; }
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)
{
if(v.x < min) { v.x = min; }
if(v.x > max) { v.x = max; }
if(v.y < min) { v.y = min; }
if(v.y > max) { v.y = max; }
if(v.z < min) { v.z = min; }
if(v.z > max) { v.z = max; }
if (v.x < min) { v.x = min; }
if (v.x > max) { v.x = max; }
if (v.y < min) { v.y = min; }
if (v.y > max) { v.y = max; }
if (v.z < min) { v.z = min; }
if (v.z > max) { v.z = max; }
}

View file

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

View file

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

View file

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

View file

@ -71,7 +71,7 @@ int kexRand::Int()
int kexRand::Max(const int max)
{
if(max == 0)
if (max == 0)
{
return 0;
}
@ -85,7 +85,7 @@ int kexRand::Max(const int max)
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;
if(d == 0.0f)
if (d == 0.0f)
{
return 0.0f;
}
@ -740,7 +740,7 @@ float kexVec3::ToYaw() const
{
float d = x * x + z * z;
if(d == 0.0f)
if (d == 0.0f)
{
return 0.0f;
}
@ -756,9 +756,9 @@ float kexVec3::ToPitch() const
{
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);
}
@ -828,7 +828,7 @@ kexVec3 kexVec3::ScreenProject(kexMatrix &proj, kexMatrix &model,
projVec.y *= modelVec.w;
projVec.z *= modelVec.w;
if(projVec.w != 0)
if (projVec.w != 0)
{
projVec.w = 1.0f / projVec.w;
projVec.x *= projVec.w;

View file

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

View file

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

View file

@ -67,9 +67,9 @@ void kexLightmapBuilder::NewTexture()
numTextures++;
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);
textures.Push(texture);
@ -86,47 +86,47 @@ bool kexLightmapBuilder::MakeRoomForBlock(const int width, const int height, int
*num = -1;
if(allocBlocks == NULL)
if (allocBlocks == NULL)
{
return false;
}
for(k = 0; k < numTextures; ++k)
for (k = 0; k < numTextures; ++k)
{
bestRow1 = textureHeight;
for(i = 0; i <= textureWidth - width; i++)
for (i = 0; i <= textureWidth - width; i++)
{
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;
}
if(allocBlocks[k][i + j] > bestRow2)
if (allocBlocks[k][i + j] > bestRow2)
{
bestRow2 = allocBlocks[k][i + j];
}
}
// found a free block
if(j == width)
if (j == width)
{
*x = i;
*y = bestRow1 = bestRow2;
}
}
if(bestRow1 + height > textureHeight)
if (bestRow1 + height > textureHeight)
{
// no room
continue;
}
for(i = 0; i < width; i++)
for (i = 0; i < width; i++)
{
// store row offset
allocBlocks[k][*x + i] = bestRow1 + height;
@ -147,15 +147,15 @@ kexBBox kexLightmapBuilder::GetBoundsFromSurface(const surface_t *surface)
kexBBox bounds;
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];
}
if(surface->verts[i][j] > hi[j])
if (surface->verts[i][j] > hi[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());
if(attenuation <= 0)
if (attenuation <= 0)
{
// plane is not even facing the sunlight
return false;
@ -181,14 +181,14 @@ bool kexLightmapBuilder::EmitFromCeiling(kexTrace &trace, const surface_t *surfa
trace.Trace(origin, origin + (map->GetSunDirection() * 32768.0f));
if(trace.fraction == 1.0f)
if (trace.fraction == 1.0f)
{
// nothing was hit
//color.x += 1.0f;
return false;
}
if(trace.hitSurface->bSky == false)
if (trace.hitSurface->bSky == false)
{
if (trace.hitSurface->type == ST_CEILING)
return false;
@ -221,7 +221,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
kexVec3 color(0.0f, 0.0f, 0.0f);
// 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];
@ -233,7 +233,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
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
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 intensity = tl->intensity;
if(origin.DistanceSq(lightOrigin) > (radius*radius))
if (origin.DistanceSq(lightOrigin) > (radius*radius))
{
// not within range
continue;
@ -272,7 +272,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
trace.Trace(lightOrigin, origin);
if(trace.fraction != 1)
if (trace.fraction != 1)
{
// this light is occluded by something
continue;
@ -289,20 +289,20 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
tracedTexels++;
}
if(surface->type != ST_CEILING)
if (surface->type != ST_CEILING)
{
// see if it's exposed to sunlight
if(EmitFromCeiling(trace, surface, origin, plane.Normal(), color))
if (EmitFromCeiling(trace, surface, origin, plane.Normal(), color))
tracedTexels++;
}
// 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];
float attenuation;
if(surfaceLight->TraceSurface(map, trace, surface, origin, &attenuation))
if (surfaceLight->TraceSurface(map, trace, surface, origin, &attenuation))
{
color += surfaceLight->GetRGB() * attenuation;
@ -332,7 +332,7 @@ void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
bounds = GetBoundsFromSurface(surface);
// 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.max[i] = samples * kexMath::Ceil(bounds.max[i] / samples);
@ -345,7 +345,7 @@ void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
axis = plane->BestAxis();
switch(axis)
switch (axis)
{
case kexPlane::AXIS_YZ:
width = (int)roundedSize.y;
@ -370,14 +370,14 @@ void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
}
// clamp width
if(width > textureWidth)
if (width > textureWidth)
{
tCoords[0] *= ((float)textureWidth / (float)width);
width = textureWidth;
}
// clamp height
if(height > textureHeight)
if (height > textureHeight)
{
tCoords[1] *= ((float)textureHeight / (float)height);
height = textureHeight;
@ -395,7 +395,7 @@ void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
d = (plane->Distance(bounds.min) - plane->d) / plane->Normal()[axis];
tOrigin[axis] -= d;
for(i = 0; i < 2; i++)
for (i = 0; i < 2; i++)
{
tCoords[i].Normalize();
d = plane->Distance(tCoords[i]) / plane->Normal()[axis];
@ -437,9 +437,9 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
int multisampleCount = Multisample;
// 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);
@ -482,7 +482,7 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
// SVE redraws the scene for lightmaps, so for optimizations,
// tell the engine to ignore this surface if completely black
if(bShouldLookupTexture == false)
if (bShouldLookupTexture == false)
{
surface->lightmapNum = -1;
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
// room for it in the light map texture. if not, then we must allocate
// 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
NewTexture();
if(!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum))
if (!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum))
{
Error("Lightmap allocation failed\n");
return;
@ -513,7 +513,7 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
lock.unlock();
// calculate texture coordinates
for(i = 0; i < surface->numVerts; i++)
for (i = 0; i < surface->numVerts; i++)
{
tDelta = surface->verts[i] - surface->bounds.min;
surface->lightmapCoords[i * 2 + 0] =
@ -531,9 +531,9 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
lock.unlock();
// 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
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();
// TODO: this should NOT happen, but apparently, it can randomly occur
if(surfaces.Length() == 0)
if (surfaces.Length() == 0)
{
return;
}
@ -703,7 +703,7 @@ void kexLightmapBuilder::WriteTexturesToTGA()
{
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.Write16(0);
@ -716,11 +716,11 @@ void kexLightmapBuilder::WriteTexturesToTGA()
file.Write16(textureHeight);
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+1]);
file.Write8(textures[i][j+0]);
file.Write8(textures[i][j + 2]);
file.Write8(textures[i][j + 1]);
file.Write8(textures[i][j + 0]);
}
file.Close();
}

View file

@ -62,8 +62,6 @@ private:
kexBBox GetBoundsFromSurface(const 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);
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;
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
void kexLightSurface::CreateCenterOrigin()
{
if(!bWall)
if (!bWall)
{
kexVec3 center;
for(int i = 0; i < surface->numVerts; ++i)
for (int i = 0; i < surface->numVerts; ++i)
{
center += surface->verts[i];
}
@ -84,17 +84,17 @@ void kexLightSurface::Clip(vertexBatch_t &points, const kexVec3 &normal, float d
kexArray<char> sides;
// 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;
dists.Push(d);
if(d > 0.1f)
if (d > 0.1f)
{
sides.Push(1); // front
}
else if(d < -0.1f)
else if (d < -0.1f)
{
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
for(unsigned int i = 0; i < points.Length(); ++i)
for (unsigned int i = 0; i < points.Length(); ++i)
{
int next;
float frac;
kexVec3 pt1, pt2, pt3;
switch(sides[i])
switch (sides[i])
{
case -1:
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
next = (i + 1) % points.Length();
if(sides[next] == 0 || sides[next] == sides[i])
if (sides[next] == 0 || sides[next] == sides[i])
{
// didn't cross
continue;
@ -161,15 +161,15 @@ bool kexLightSurface::SubdivideRecursion(vertexBatch_t &surfPoints, float divide
vertexBatch_t *backPoints;
// 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]);
}
for(int i = 0; i < 3; ++i)
for (int i = 0; i < 3; ++i)
{
// 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[i] = 1;
@ -182,7 +182,7 @@ bool kexLightSurface::SubdivideRecursion(vertexBatch_t &surfPoints, float divide
// start clipping
Clip(surfPoints, splitNormal, dist, frontPoints, backPoints);
if(!SubdivideRecursion(*frontPoints, divide, points))
if (!SubdivideRecursion(*frontPoints, divide, points))
{
points.Push(frontPoints);
}
@ -191,7 +191,7 @@ bool kexLightSurface::SubdivideRecursion(vertexBatch_t &surfPoints, float divide
delete frontPoints;
}
if(!SubdivideRecursion(*backPoints, divide, points))
if (!SubdivideRecursion(*backPoints, divide, points))
{
points.Push(backPoints);
}
@ -212,7 +212,7 @@ void kexLightSurface::Subdivide(const float divide)
kexArray<vertexBatch_t*> points;
vertexBatch_t surfPoints;
for(int i = 0; i < surface->numVerts; ++i)
for (int i = 0; i < surface->numVerts; ++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
// 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];
kexVec3 center;
for(unsigned int j = 0; j < vb->Length(); ++j)
for (unsigned int j = 0; j < vb->Length(); ++j)
{
center += (*vb)[j];
}
@ -234,7 +234,7 @@ void kexLightSurface::Subdivide(const float divide)
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];
@ -252,7 +252,7 @@ bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surfa
*dist = -M_INFINITY;
// light surface will always be fullbright
if(surf == surface)
if (surf == surface)
{
*dist = Intensity();
return true;
@ -260,11 +260,11 @@ bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surfa
lnormal = surface->plane.Normal();
if(surf)
if (surf)
{
normal = surf->plane.Normal();
if(normal.Dot(lnormal) > 0)
if (normal.Dot(lnormal) > 0)
{
// not facing the light surface
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
// 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];
if(!bWall && origin.z > center.z)
if (!bWall && origin.z > center.z)
{
// origin is not going to seen or traced by the light surface
// 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);
}*/
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
// 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
trace.Trace(center + lnormal, origin + normal);
if(trace.fraction != 1)
if (trace.fraction != 1)
{
// something is obstructing it
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
if (curDist < 0.0f) curDist = 0.0f;
if(curDist >= 1)
if (curDist >= 1)
{
curDist = 1;
// 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.
if(!bWall)
if (!bWall)
{
*dist = 1;
break;
}
}
if(curDist > *dist)
if (curDist > *dist)
{
*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 v2Bottom = front->floorplane.zAt(v2.x, v2.y);
if(back)
if (back)
{
float v1TopBack = back->ceilingplane.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
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->numVerts = 4;
@ -104,21 +104,21 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
}
// top seg
if(v1Top > v1TopBack || v2Top > v2TopBack)
if (v1Top > v1TopBack || v2Top > v2TopBack)
{
bool bSky = false;
int frontidx = front - &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;
}
}
if(side->toptexture[0] != '-' || bSky)
if (side->toptexture[0] != '-' || bSky)
{
surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static);
surf->numVerts = 4;
@ -148,7 +148,7 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
}
// middle seg
if(back == NULL)
if (back == NULL)
{
surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static);
surf->numVerts = 4;
@ -181,13 +181,13 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
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];
if(sub->numlines < 3)
if (sub->numlines < 3)
{
continue;
}
@ -196,7 +196,7 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
// I will be NOT surprised if some users tries to do something stupid with
// sector hacks
if(sector == NULL)
if (sector == NULL)
{
Error("CreateSubsectorSurfaces: subsector %i has no sector\n", i);
return;
@ -210,7 +210,7 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * surf->numVerts, hb_static);
// 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];
FloatVertex v1 = doomMap.GetSegVertex(seg->v1);
@ -230,13 +230,13 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
surf->numVerts = sub->numlines;
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;
}
// ceiling verts
for(j = 0; j < surf->numVerts; j++)
for (j = 0; j < surf->numVerts; j++)
{
MapSegGLEx *seg = &doomMap.GLSegs[sub->firstline + j];
FloatVertex v1 = doomMap.GetSegVertex(seg->v1);
@ -315,10 +315,10 @@ void CreateSurfaces(FLevel &doomMap)
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]);
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());

View file

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