#pragma once

#include "dllinterface.h"
#include "NxPhysics.h"
#include "..\Utilities\list.h"
#include "UserAllocator.h"
#include "PhysicsRenderer.h"

class DeviceStateManager;
class PhysicsCore;
class UserOutputStream;

class DXFUNCTIONS_API PhysicsScene
{
	NxScene* m_Scene;
	PhysicsCore* m_PhysicsCore;

protected:
	friend ListElement<PhysicsScene>;
	friend LList<PhysicsScene>;
	friend PhysicsCore;

	PhysicsScene(PhysicsCore* Core, const NxSceneDesc& Desc);
	~PhysicsScene(void);

public:
	NxScene* GetScene(void) const {return m_Scene;}
	PhysicsCore* GetCore(void) const {return m_PhysicsCore;}

	void StartSimulation(const float dTime);
	void GetSimulationResults(void);

	void Release(void);

	void DrawDebug(const Camera& cam);
};

class DXFUNCTIONS_API PhysicsCore
{
	NxPhysicsSDK*		m_PhysicsSDK;
	LList<PhysicsScene>  m_Scenes;
	NxUserAllocator*	m_Allocator;
	UserOutputStream*	m_OutputStream;
	PhysicsRenderer*	m_DebugRenderer;

protected:

	friend PhysicsScene;

	void Release(PhysicsScene* const Scene);

public:
	PhysicsCore(DeviceStateManager* const device);
	~PhysicsCore(void);

	NxPhysicsSDK* GetSDK(void) const {return m_PhysicsSDK;}

	PhysicsScene* CreateScene(const NxSceneDesc& SceneDesc);

	PhysicsRenderer* GetDebugRenderer(void) const {return m_DebugRenderer;}
};
