Skip to content

Commit

Permalink
Part 1 of the experiment to remove doug_lea_allocator.
Browse files Browse the repository at this point in the history
  • Loading branch information
intorr authored and Xottab-DUTY committed Dec 23, 2017
1 parent 2ba0a72 commit a9eb04f
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 247 deletions.
6 changes: 3 additions & 3 deletions Externals/OPCODE/OPC_AABBTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ AABBTree::AABBTree() : mIndices(nullptr), mTotalNbNodes(0) {}
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
AABBTree::~AABBTree() { CFREE(mIndices); }
AABBTree::~AABBTree() { xr_free(mIndices); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Builds a generic AABB tree from a tree builder.
Expand All @@ -366,8 +366,8 @@ bool AABBTree::Build(AABBTreeBuilder* builder)
builder->SetNbInvalidSplits(0);

// Initialize indices. This list will be modified during build.
CFREE(mIndices);
mIndices = CALLOC(udword, builder->mNbPrimitives);
xr_free(mIndices);
mIndices = xr_alloc<udword>(builder->mNbPrimitives);
CHECKALLOC(mIndices);
for (udword i = 0; i < builder->mNbPrimitives; i++)
mIndices[i] = i;
Expand Down
10 changes: 5 additions & 5 deletions Externals/OPCODE/OPC_Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool Container::Resize(udword needed)
mMaxNbEntries = mCurNbEntries + needed;

// Get some bytes for _new_ entries
udword* NewEntries = CALLOC(udword, mMaxNbEntries);
udword* NewEntries = xr_alloc<udword>(mMaxNbEntries);
CHECKALLOC(NewEntries);

#ifdef CONTAINER_STATS
Expand All @@ -107,7 +107,7 @@ bool Container::Resize(udword needed)
CopyMemory(NewEntries, mEntries, mCurNbEntries * sizeof(udword));

// Delete old data
CFREE(mEntries);
xr_free(mEntries);

// Assign _new_ pointer
mEntries = NewEntries;
Expand Down Expand Up @@ -135,7 +135,7 @@ bool Container::SetSize(udword nb)
mMaxNbEntries = nb;

// Get some bytes for _new_ entries
mEntries = CALLOC(udword, mMaxNbEntries);
mEntries = xr_alloc<udword>(mMaxNbEntries);
CHECKALLOC(mEntries);

#ifdef CONTAINER_STATS
Expand Down Expand Up @@ -164,7 +164,7 @@ bool Container::Refit()
return false;

// Get just enough bytes
udword* NewEntries = CALLOC(udword, mMaxNbEntries);
udword* NewEntries = xr_alloc<udword>(mMaxNbEntries);
CHECKALLOC(NewEntries);

#ifdef CONTAINER_STATS
Expand All @@ -176,7 +176,7 @@ bool Container::Refit()
CopyMemory(NewEntries, mEntries, mCurNbEntries * sizeof(udword));

// Delete old data
CFREE(mEntries);
xr_free(mEntries);

// Assign _new_ pointer
mEntries = NewEntries;
Expand Down
2 changes: 1 addition & 1 deletion Externals/OPCODE/OPC_Container.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ICECORE_API Container
#ifdef CONTAINER_STATS
mUsedRam -= mMaxNbEntries * sizeof(udword);
#endif
CFREE(mEntries);
xr_free(mEntries);
mCurNbEntries = mMaxNbEntries = 0;
return *this;
}
Expand Down
20 changes: 10 additions & 10 deletions Externals/OPCODE/OPC_Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ OPCODE_Model::OPCODE_Model() : mSource(nullptr), mTree(nullptr), mNoLeaf(false),
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
OPCODE_Model::~OPCODE_Model()
{
CDELETE(mSource);
CDELETE(mTree);
xr_delete(mSource);
xr_delete(mTree);
#ifdef __MESHMERIZER_H__ // Collision hulls only supported within ICE !
CDELETE(mHull);
xr_delete(mHull);
#endif // __MESHMERIZER_H__
}

Expand Down Expand Up @@ -212,7 +212,7 @@ bool OPCODE_Model::Build(const OPCODECREATE& create)
// We continue nonetheless....

// 2) Build a generic AABB Tree.
mSource = CNEW(AABBTree)();
mSource = new AABBTree();
CHECKALLOC(mSource);

// 2-1) Setup a builder. Our primitives here are triangles from input mesh,
Expand All @@ -233,16 +233,16 @@ bool OPCODE_Model::Build(const OPCODECREATE& create)
if (mNoLeaf)
{
if (mQuantized)
mTree = CNEW(AABBQuantizedNoLeafTree)();
mTree = new AABBQuantizedNoLeafTree();
else
mTree = CNEW(AABBNoLeafTree)();
mTree = new AABBNoLeafTree();
}
else
{
if (mQuantized)
mTree = CNEW(AABBQuantizedTree)();
mTree = new AABBQuantizedTree();
else
mTree = CNEW(AABBCollisionTree)();
mTree = new AABBCollisionTree();
}

// 3-2) Create optimized tree
Expand All @@ -253,15 +253,15 @@ bool OPCODE_Model::Build(const OPCODECREATE& create)
if (!create.KeepOriginal)
{
mSource->destroy(&TB);
CDELETE(mSource);
xr_delete(mSource);
}

#ifdef __MESHMERIZER_H__
// 4) Convex hull
if (create.CollisionHull)
{
// Create hull
mHull = CNEW(CollisionHull)();
mHull = new CollisionHull();
CHECKALLOC(mHull);

CONVEXHULLCREATE CHC;
Expand Down
24 changes: 12 additions & 12 deletions Externals/OPCODE/OPC_OptimizedTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ AABBCollisionTree::AABBCollisionTree() : mNodes(nullptr) {}
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
AABBCollisionTree::~AABBCollisionTree() { CFREE(mNodes); }
AABBCollisionTree::~AABBCollisionTree() { xr_free(mNodes); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Builds the collision tree from a generic AABB tree.
Expand All @@ -230,7 +230,7 @@ bool AABBCollisionTree::Build(AABBTree* tree)

// Get nodes
mNbNodes = NbNodes;
mNodes = CALLOC(AABBCollisionNode, mNbNodes);
mNodes = xr_alloc<AABBCollisionNode>(mNbNodes);
CHECKALLOC(mNodes);
ZeroMemory(mNodes, mNbNodes * sizeof(AABBCollisionNode));

Expand Down Expand Up @@ -259,7 +259,7 @@ AABBNoLeafTree::AABBNoLeafTree() : mNodes(nullptr) {}
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
AABBNoLeafTree::~AABBNoLeafTree() { CFREE(mNodes); }
AABBNoLeafTree::~AABBNoLeafTree() { xr_free(mNodes); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Builds the collision tree from a generic AABB tree.
Expand All @@ -280,7 +280,7 @@ bool AABBNoLeafTree::Build(AABBTree* tree)

// Get nodes
mNbNodes = NbTriangles - 1;
mNodes = CALLOC(AABBNoLeafNode, mNbNodes);
mNodes = xr_alloc<AABBNoLeafNode>(mNbNodes);
CHECKALLOC(mNodes);
ZeroMemory(mNodes, mNbNodes * sizeof(AABBNoLeafNode));

Expand Down Expand Up @@ -414,7 +414,7 @@ AABBQuantizedTree::AABBQuantizedTree() : mNodes(nullptr) {}
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
AABBQuantizedTree::~AABBQuantizedTree() { CFREE(mNodes); }
AABBQuantizedTree::~AABBQuantizedTree() { xr_free(mNodes); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Builds the collision tree from a generic AABB tree.
Expand All @@ -435,7 +435,7 @@ bool AABBQuantizedTree::Build(AABBTree* tree)

// Get nodes
mNbNodes = NbNodes;
AABBCollisionNode* Nodes = CALLOC(AABBCollisionNode, mNbNodes);
AABBCollisionNode* Nodes = xr_alloc<AABBCollisionNode>(mNbNodes);
CHECKALLOC(Nodes);
ZeroMemory(Nodes, mNbNodes * sizeof(AABBCollisionNode));

Expand All @@ -445,7 +445,7 @@ bool AABBQuantizedTree::Build(AABBTree* tree)

// Quantize
{
mNodes = CALLOC(AABBQuantizedNode, mNbNodes);
mNodes = xr_alloc<AABBQuantizedNode>(mNbNodes);
CHECKALLOC(mNodes);
ZeroMemory(mNodes, mNbNodes * sizeof(AABBQuantizedNode));

Expand All @@ -463,7 +463,7 @@ bool AABBQuantizedTree::Build(AABBTree* tree)
REMAP_DATA(mData)
}

CFREE(Nodes);
xr_free(Nodes);
}

#ifdef __ICECORE_H__
Expand All @@ -485,7 +485,7 @@ AABBQuantizedNoLeafTree::AABBQuantizedNoLeafTree() : mNodes(nullptr) {}
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
AABBQuantizedNoLeafTree::~AABBQuantizedNoLeafTree() { CFREE(mNodes); }
AABBQuantizedNoLeafTree::~AABBQuantizedNoLeafTree() { xr_free(mNodes); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Builds the collision tree from a generic AABB tree.
Expand All @@ -506,7 +506,7 @@ bool AABBQuantizedNoLeafTree::Build(AABBTree* tree)

// Get nodes
mNbNodes = NbTriangles - 1;
AABBNoLeafNode* Nodes = CALLOC(AABBNoLeafNode, mNbNodes);
AABBNoLeafNode* Nodes = xr_alloc<AABBNoLeafNode>(mNbNodes);
CHECKALLOC(Nodes);
ZeroMemory(Nodes, mNbNodes * sizeof(AABBNoLeafNode));

Expand All @@ -517,7 +517,7 @@ bool AABBQuantizedNoLeafTree::Build(AABBTree* tree)

// Quantize
{
mNodes = CALLOC(AABBQuantizedNoLeafNode, mNbNodes);
mNodes = xr_alloc<AABBQuantizedNoLeafNode>(mNbNodes);
CHECKALLOC(mNodes);
ZeroMemory(mNodes, mNbNodes * sizeof(AABBQuantizedNoLeafNode));

Expand All @@ -536,7 +536,7 @@ bool AABBQuantizedNoLeafTree::Build(AABBTree* tree)
REMAP_DATA(mData2)
}

CFREE(Nodes);
xr_free(Nodes);
}

#ifdef __ICECORE_H__
Expand Down
6 changes: 3 additions & 3 deletions Externals/OPCODE/OPC_PlanesCollider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ PlanesCollider::PlanesCollider() : mPlanes(nullptr), mNbPlanes(0) {}
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PlanesCollider::~PlanesCollider() { CFREE(mPlanes); }
PlanesCollider::~PlanesCollider() { xr_free(mPlanes); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Validates current settings. You should call this method after all the settings and callbacks have been defined.
Expand Down Expand Up @@ -140,8 +140,8 @@ BOOL PlanesCollider::InitQuery(PlanesCache& cache, const Plane* planes, udword n
// 2) Compute planes in model space
if (nb_planes > mNbPlanes)
{
CFREE(mPlanes);
mPlanes = CALLOC(Plane, nb_planes);
xr_free(mPlanes);
mPlanes = xr_alloc<Plane>(nb_planes);
}
mNbPlanes = nb_planes;

Expand Down
6 changes: 0 additions & 6 deletions Externals/OPCODE/pch.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
#include "pch.hpp"

#ifdef USE_ARENA_ALLOCATOR
static const u32 s_arena_size = (128 + 16) * 1024 * 1024;
static char s_fake_array[s_arena_size];
doug_lea_allocator g_collision_allocator(s_fake_array, s_arena_size, "opcode");
#endif // #ifdef USE_ARENA_ALLOCATOR
50 changes: 0 additions & 50 deletions Externals/OPCODE/pch.hpp
Original file line number Diff line number Diff line change
@@ -1,56 +1,6 @@
#pragma once

#include <algorithm>

#include "Common/Common.hpp"
#include "xrCore/xrCore.h"
#include "xrCore/Memory/doug_lea_allocator.h"

#ifdef USE_ARENA_ALLOCATOR
extern doug_lea_allocator g_collision_allocator;

#define CNEW(type) new (g_collision_allocator.alloc_impl<type>(1)) type
#define CDELETE(ptr) cdelete(ptr)
#define CFREE(ptr) g_collision_allocator.free_impl(ptr)
#define CMALLOC(size) g_collision_allocator.malloc_impl(size)
#define CALLOC(type, count) g_collision_allocator.alloc_impl<type>(count)
#else // #ifdef USE_ARENA_ALLOCATOR
#define CNEW(type) new (xr_alloc<type>(1)) type
#define CDELETE(ptr) xr_delete(ptr)
#define CFREE(ptr) xr_free(ptr)
#define CMALLOC(size) xr_malloc(size)
#define CALLOC(type, count) xr_alloc<type>(count)
#endif // #ifdef USE_ARENA_ALLOCATOR

template <bool _is_pm, typename T>
struct cspecial_free
{
IC void operator()(T*& ptr)
{
void* _real_ptr = dynamic_cast<void*>(ptr);
ptr->~T();
CFREE(_real_ptr);
}
};

template <typename T>
struct cspecial_free<false, T>
{
IC void operator()(T*& ptr)
{
ptr->~T();
CFREE(ptr);
}
};

template <class T>
IC void cdelete(T*& ptr)
{
if (ptr)
{
cspecial_free<std::is_polymorphic<T>::value, T>()(ptr);
ptr = NULL;
}
}

#include "Opcode.h"
1 change: 0 additions & 1 deletion src/Layers/xrRender/D3DXRenderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class D3DXRenderBase : public IRender, public pureFrame
void r_dsgraph_render_subspace(
IRender_Sector* _sector, Fmatrix& mCombined, Fvector& _cop, BOOL _dynamic, BOOL _precise_portals = FALSE);
void r_dsgraph_render_R1_box(IRender_Sector* _sector, Fbox& _bb, int _element);
virtual u32 memory_usage() override { return g_render_allocator.get_allocated_size(); }
virtual void Copy(IRender& _in) override;
// Gamma correction functions
virtual void setGamma(float fGamma) override;
Expand Down
52 changes: 0 additions & 52 deletions src/xrCDB/StdAfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,4 @@

#include "Common/Common.hpp"
#include "xrCore/xrCore.h"
#include "xrCore/Memory/doug_lea_allocator.h"

#ifdef USE_ARENA_ALLOCATOR
extern doug_lea_allocator g_collision_allocator;

#define CNEW(type) new (g_collision_allocator.alloc_impl<type>(1)) type
#define CDELETE(ptr) cdelete(ptr)
#define CFREE(ptr) g_collision_allocator.free_impl(ptr)
#define CMALLOC(size) g_collision_allocator.malloc_impl(size)
#define CALLOC(type, count) g_collision_allocator.alloc_impl<type>(count)
#else // #ifdef USE_ARENA_ALLOCATOR
#define CNEW(type) new (xr_alloc<type>(1)) type
#define CDELETE(ptr) xr_delete(ptr)
#define CFREE(ptr) xr_free(ptr)
#define CMALLOC(size) xr_malloc(size)
#define CALLOC(type, count) xr_alloc<type>(count)
#endif // #ifdef USE_ARENA_ALLOCATOR

template <bool _is_pm, typename T>
struct cspecial_free
{
IC void operator()(T*& ptr)
{
void* _real_ptr = dynamic_cast<void*>(ptr);
ptr->~T();
CFREE(_real_ptr);
}
};

template <typename T>
struct cspecial_free<false, T>
{
IC void operator()(T*& ptr)
{
ptr->~T();
CFREE(ptr);
}
};

template <class T>
IC void cdelete(T*& ptr)
{
if (ptr)
{
cspecial_free<std::is_polymorphic<T>::value, T>()(ptr);
ptr = NULL;
}
}

#include "OPCODE/Opcode.h"

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
Loading

0 comments on commit a9eb04f

Please sign in to comment.