Commit b2578fec authored by D-AIRY's avatar D-AIRY

Some refactor

parent b3951c6f
......@@ -18,6 +18,7 @@ See the license in LICENSE
#include "types.h"
#include <malloc.h>
#if defined(_WINDOWS)
# pragma warning(push)
# pragma warning(disable:4018)
#endif
......@@ -103,51 +104,54 @@ public:
MemAlloc & operator=(const MemAlloc & al)
{//clear mem
for(int i = 0; i < this->NumCurBlockCount; i++)
if(&al != this)
{
if(this->memblocks[i].mem)
for(int i = 0; i < this->NumCurBlockCount; i++)
{
for(int j = 0; j < this->memblocks[i].size; j++)
if(this->memblocks[i].mem)
{
if(!(this->memblocks[i].mem[j].IsFree & 0x80000000))
for(int j = 0; j < this->memblocks[i].size; j++)
{
this->memblocks[i].mem[j].data.~T();
}
if(!(this->memblocks[i].mem[j].IsFree & 0x80000000))
{
this->memblocks[i].mem[j].data.~T();
}
}
_aligned_free(this->memblocks[i].mem);
}
_aligned_free(this->memblocks[i].mem);
//SX_SAFE_DELETE_A(this->memblocks[i].mem);
}
//SX_SAFE_DELETE_A(this->memblocks[i].mem);
}
mem_delete_a(this->memblocks);
this->NumCurBlock = al.NumCurBlock;
this->NumCurBlockCount = al.NumCurBlockCount;
this->memblocks = new MemBlock[this->NumCurBlockCount];
//SX_DBG_NEW(this->NumCurBlockCount * sizeof(MemBlock), this->memblocks);
for(int i = 0; i < this->NumCurBlockCount; i++)
{
this->memblocks[i].size = al.memblocks[i].size;
this->memblocks[i].pos = al.memblocks[i].pos;
mem_delete_a(this->memblocks);
if(!this->memblocks[i].size)
{
this->memblocks[i].mem = NULL;
}
else
this->NumCurBlock = al.NumCurBlock;
this->NumCurBlockCount = al.NumCurBlockCount;
this->memblocks = new MemBlock[this->NumCurBlockCount];
//SX_DBG_NEW(this->NumCurBlockCount * sizeof(MemBlock), this->memblocks);
for(int i = 0; i < this->NumCurBlockCount; i++)
{
this->memblocks[i].mem = (MemCell*)_aligned_malloc(al.memblocks[i].size * sizeof(MemCell), alignBy);
//SX_DBG_NEW(al.memblocks[i].size, this->memblocks[i].mem);
for(int j = 0; (unsigned int)j < al.memblocks[i].size; j++)
this->memblocks[i].size = al.memblocks[i].size;
this->memblocks[i].pos = al.memblocks[i].pos;
if(!this->memblocks[i].size)
{
this->memblocks[i].mem = NULL;
}
else
{
this->memblocks[i].mem[j].IsFree = al.memblocks[i].mem[j].IsFree;
if(!(al.memblocks[i].mem[j].IsFree & 0x80000000))
this->memblocks[i].mem = (MemCell*)_aligned_malloc(al.memblocks[i].size * sizeof(MemCell), alignBy);
//SX_DBG_NEW(al.memblocks[i].size, this->memblocks[i].mem);
for(int j = 0; (unsigned int)j < al.memblocks[i].size; j++)
{
this->memblocks[i].mem[j].data = al.memblocks[i].mem[j].data;
this->memblocks[i].mem[j].IsFree = al.memblocks[i].mem[j].IsFree;
if(!(al.memblocks[i].mem[j].IsFree & 0x80000000))
{
this->memblocks[i].mem[j].data = al.memblocks[i].mem[j].data;
}
}
}
//SX_SAFE_DELETE_A(memblocks[i].mem);
}
//SX_SAFE_DELETE_A(memblocks[i].mem);
}
return(*this);
}
......@@ -413,7 +417,7 @@ public:
};
#if defined(_WINDOWS)
# pragma warning(default:4018)
# pragma warning(pop)
#endif
#if defined(_LINUX) || defined(_MAC)
# pragma GCC diagnostic pop
......
......@@ -251,7 +251,12 @@ protected:
{
return;
}
T * tmpData = (T*)malloc(sizeof(T) * NewSize);
T *tmpData = (T*)malloc(sizeof(T) * NewSize);
assert(tmpData);
if(!tmpData)
{
return;
}
memcpy(tmpData, this->Data, min(NewSize, this->Size) * sizeof(T));
if(this->Size > NewSize)
{
......
......@@ -119,10 +119,8 @@ private:
tmpNode->Right->Parent = node;
}
if(tmpNode)
{
tmpNode->Parent = node->Parent;
}
tmpNode->Parent = node->Parent;
if(node->Parent)
{
if(node == node->Parent->Right)
......@@ -140,10 +138,8 @@ private:
}
tmpNode->Right = node;
if(node)
{
node->Parent = tmpNode;
}
node->Parent = tmpNode;
}
void TreeFixIns(Node * node)
......@@ -267,7 +263,7 @@ private:
node->IsBlack = true;
}
Node * TreeInsert(const SX_KEYTYPE & key, bool * found = NULL)
Node* TreeInsert(const SX_KEYTYPE & key, bool * found = NULL)
{
Node * tmpCur;
Node * tmpParent;
......@@ -294,19 +290,10 @@ private:
this->Size_++;
// tmpNode = new Node;
tmpNode = this->MemNodes.Alloc();
assert(tmpNode);
if(!tmpNode)
{
//printf("Unable to allocate memory\n");
#if 0
#if defined(WIN32)
_asm
{
int 3;
};
#else
asm("int $3");
#endif
#endif
return(NULL);
}
tmpNode->Key = key;
//tmpNode->Val = new SX_VALTYPE;
......
......@@ -1752,7 +1752,7 @@ public:
x = f.x;
y = f.y;
z = f.z;
Renormalize();
w = Renormalize().w;
}
SMQuaternion::SMQuaternion(const float4 & f)
......@@ -1803,10 +1803,10 @@ public:
float3 vec;
if(u == -v)
{
float x = abs(v.x);
float y = abs(v.y);
float z = abs(v.z);
float3 vOther = x < y ? (x < z ? float3(1.0f, 0.0f, 0.0f) : float3(0.0f, 0.0f, 1.0f)) : (y < z ? float3(0.0f, 1.0f, 0.0f) : float3(0.0f, 0.0f, 1.0f));
float _x = abs(v.x);
float _y = abs(v.y);
float _z = abs(v.z);
float3 vOther = _x < _y ? (_x < _z ? float3(1.0f, 0.0f, 0.0f) : float3(0.0f, 0.0f, 1.0f)) : (_y < _z ? float3(0.0f, 1.0f, 0.0f) : float3(0.0f, 0.0f, 1.0f));
vec = SMVector3Cross(v, vOther);
w = 0.0f;
......@@ -1884,8 +1884,8 @@ public:
s = sqrt((m[i][i] - (m[j][j] + m[k][k])) + 1.0f);
q[i] = s * 0.5f;
if(s != 0.0) s = 0.5f / s;
if(fabs(s) < FLT_EPSILON) s = 0.5f / s;
q[3] = (m[j][k] - m[k][j]) * s;
q[j] = (m[i][j] + m[j][i]) * s;
......@@ -1901,7 +1901,7 @@ public:
};
__forceinline bool operator==(const SMQuaternion & q1, const SMQuaternion & q2)
{
return(q1.x == q2.x && q1.y == q2.y && q1.z == q2.z && q1.w == q2.w);
return(fabs(q1.x - q2.x) < FLT_EPSILON && fabs(q1.y - q2.y) < FLT_EPSILON && fabs(q1.z - q2.z) < FLT_EPSILON && fabs(q1.w - q2.w) < FLT_EPSILON);
}
__forceinline SMQuaternion operator*(const SMQuaternion & q1, const SMQuaternion & q2)
......
......@@ -85,7 +85,7 @@ const char* StrCutStr(const char *szStr, const char *szFinder);
String StrCutStrI(const char *szStr, const char *szFinder);
#define STR_VALIDATE(str) (str && str[0]!=0 && str[0]!='0')
#define STR_VALIDATE(str) ((str) && (str)[0]!=0 && (str)[0]!='0')
void StrCutName(const char* path, char* name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment