//
// Asura_Physics_ContactCluster.cpp
//
// Created by KJFL - 05 February 2007
//
// Copyright (C) 2007 Rebellion, All Rights Reserved.
//

#include "Core/Asura.h"

// This file's header.
#include "Physics/Asura_Physics_ContactCluster.h"

#include "Core/Asura_Mempool.h"

#if 0
#include "Core/Asura_Multithread.h"
#include "Physics/Asura_Physics.h"
static Asura_Mutex g_xMutex;
#endif

static const u_int uCONTACT_CLUSTERS_PER_POOL = 16;
static Asura_ResizingMempool g_xContactClusterPool( uCONTACT_CLUSTERS_PER_POOL, sizeof(Asura_Physics_ContactCluster), __FILE__, __LINE__ );



Asura_Physics_ContactCluster* Asura_Physics_ContactCluster::Create( void )
{
	Asura_Physics_ContactCluster* pxCluster;

#if 0
	if ( Asura_Physics_System::IsMultithreaded() )
	{
		g_xMutex.Lock();
		pxCluster = static_cast<Asura_Physics_ContactCluster*>( g_xContactClusterPool.Allocate() );
		g_xMutex.Unlock();
	}
	else
#endif
	{
		pxCluster = static_cast<Asura_Physics_ContactCluster*>( g_xContactClusterPool.Allocate() );
	}

	if (pxCluster)
	{
		pxCluster->m_uNumberOfContacts = 0;
		pxCluster->m_pxNextCluster = 0;
		pxCluster->m_fPlanePenetrationConstant = -Asura_Maths::LargeFloat;
	}

	return pxCluster;
}

void Asura_Physics_ContactCluster::Destroy( Asura_Physics_ContactCluster* pxCluster )
{
#if 0
	if ( Asura_Physics_System::IsMultithreaded() )
	{
		g_xMutex.Lock();
		g_xContactClusterPool.Deallocate( pxCluster );
		g_xMutex.Unlock();
	}
	else
#endif
	{
		g_xContactClusterPool.Deallocate( pxCluster );
	}

}
