Skip to content

Commit

Permalink
xenocollide: Put everything inside a XenoCollide namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcel303 committed Jun 8, 2022
1 parent 85e6d4a commit bb19447
Show file tree
Hide file tree
Showing 39 changed files with 5,467 additions and 5,360 deletions.
40 changes: 21 additions & 19 deletions users/marcel/xenocollide-testbed/DrawUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ not be misrepresented as being the original software.

#include "framework.h"

void SetTransform(const Vector& pos, const Quat& q)
namespace XenoCollide
{
Matrix transform(q);
transform.SetTrans(pos);

gxMultMatrixf((float*)&transform);
void SetTransform(const Vector& pos, const Quat& q)
{
Matrix transform(q);
transform.SetTrans(pos);

gxMultMatrixf((float*)&transform);
}

void DrawSphere(const Vector& pos, const Quat& q, float radius, const Vector& c)
{
gxColor3f(c.X(), c.Y(), c.Z());
gxPushMatrix();
SetTransform(pos, q);
// todo : xeno : draw sphere
fillCube(Vec3(), Vec3(radius));
//GLUquadricObj* quadric = gluNewQuadric();
//gluSphere(quadric, radius, 10, 10);
//gluDeleteQuadric(quadric);
gxPopMatrix();
}
}

void DrawSphere(const Vector& pos, const Quat& q, float radius, const Vector& c)
{
gxColor3f(c.X(), c.Y(), c.Z());
gxPushMatrix();
SetTransform(pos, q);
// todo : xeno : draw sphere
fillCube(Vec3(), Vec3(radius));
//GLUquadricObj* quadric = gluNewQuadric();
//gluSphere(quadric, radius, 10, 10);
//gluDeleteQuadric(quadric);
gxPopMatrix();
}

12 changes: 7 additions & 5 deletions users/marcel/xenocollide-testbed/DrawUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ not be misrepresented as being the original software.

#include "Math/Math.h"

// Set OpenGL's model-view transform
void SetTransform(const Vector& pos, const Quat& q);

// Draw a sphere using OpenGL
void DrawSphere(const Vector& pos, const Quat& q, float radius, const Vector& c);
namespace XenoCollide
{
// Set OpenGL's model-view transform
void SetTransform(const Vector& pos, const Quat& q);

// Draw a sphere using OpenGL
void DrawSphere(const Vector& pos, const Quat& q, float radius, const Vector& c);
}
7 changes: 5 additions & 2 deletions users/marcel/xenocollide-testbed/MapPtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ not be misrepresented as being the original software.

#include "MapPtr.h"

//map<void*, int> MapPtrBase::s_refCount;
std::unordered_map<void*, int> MapPtrBase::s_refCount;
namespace XenoCollide
{
//map<void*, int> MapPtrBase::s_refCount;
std::unordered_map<void*, int> MapPtrBase::s_refCount;
}
125 changes: 64 additions & 61 deletions users/marcel/xenocollide-testbed/MapPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,93 +30,96 @@ not be misrepresented as being the original software.
#include <map>
#include <unordered_map>

class MapPtrBase
namespace XenoCollide
{
protected:
static std::unordered_map<void*, int> s_refCount;
};

template <class T>
class MapPtr : MapPtrBase
{
public:

MapPtr()
class MapPtrBase
{
m_pointer = NULL;
}
protected:
static std::unordered_map<void*, int> s_refCount;
};

MapPtr(T* pointer)
template <class T>
class MapPtr : MapPtrBase
{
m_pointer = pointer;
if (pointer)
public:

MapPtr()
{
s_refCount[pointer]++;
m_pointer = NULL;
}
}

MapPtr(const MapPtr& other)
{
m_pointer = NULL;
*this = other;
}
MapPtr(T* pointer)
{
m_pointer = pointer;
if (pointer)
{
s_refCount[pointer]++;
}
}

~MapPtr()
{
if ( m_pointer && --s_refCount[m_pointer] == 0 )
MapPtr(const MapPtr& other)
{
s_refCount.erase(m_pointer);
delete m_pointer;
m_pointer = NULL;
*this = other;
}
}

void Release()
{
if (m_pointer)
~MapPtr()
{
if (--s_refCount[m_pointer] == 0)
if (m_pointer && --s_refCount[m_pointer] == 0)
{
s_refCount.erase(m_pointer);
delete m_pointer;
m_pointer = NULL;
}
}
}

void AddRef()
{
if (m_pointer)
void Release()
{
s_refCount[m_pointer]++;
if (m_pointer)
{
if (--s_refCount[m_pointer] == 0)
{
s_refCount.erase(m_pointer);
delete m_pointer;
m_pointer = NULL;
}
}
}
}

MapPtr& operator= (const MapPtr& other)
{
Release();
m_pointer = other.m_pointer;
AddRef();
return *this;
}
void AddRef()
{
if (m_pointer)
{
s_refCount[m_pointer]++;
}
}

T* Pointer()
{
return m_pointer;
}
MapPtr& operator= (const MapPtr& other)
{
Release();
m_pointer = other.m_pointer;
AddRef();
return *this;
}

operator T*()
{
return m_pointer;
}
T* Pointer()
{
return m_pointer;
}

T* operator -> ()
{
return m_pointer;
}
operator T* ()
{
return m_pointer;
}

T* operator -> ()
{
return m_pointer;
}

private:
private:

T* m_pointer;
T* m_pointer;

};
};
}
Loading

0 comments on commit bb19447

Please sign in to comment.