#ifndef _RURESOURCEMANAGER_NULL_H_
#define _RURESOURCEMANAGER_NULL_H_

#include "../Engine/Base/RuResourceManagerBase.h"

#include "../NULL/RuEngine_NULL.h"

#pragma unmanaged

// ************************************************************************************************************************************************************

class cFilePackage;

class CRuResourceManager_NULL : public IRuResourceManager
{
protected:
	cFilePackage*							m_filePackage;						// File packager Entity

	CRuStringHash<CRuAnimation *>*			m_animationHash;					// Animation hash
	CRuStringHash<CRuAnimation_GR2 *>*		m_animationHash_GR2;				// Animation hash
	CRuStringHash<IRuObject *>*				m_entityHash;						// Entity hash
	CRuTernaryStringTree<IRuObject *>*		m_genericObjectTree;				//!< Generic object tree

public:
											CRuResourceManager_NULL();
	virtual									~CRuResourceManager_NULL();

	// Engine association
	virtual IRuEngine*						GetEngine();

	// Manager setup
	virtual const char*						GetRootDirectory();
	virtual void							SetRootDirectory(const char *rootDirectory);
	virtual	void							LoadPackageFile(const char *filename);
	virtual BOOL							FileExists(const char* filename);
	virtual BOOL							SetObjectDequeueRate(REAL dequeueRate);
	virtual BOOL							SetTextureDequeueRate(REAL dequeueRate);

	// Generic stream loading
	virtual IRuStream*						LoadStream(const char *resourceName);
	virtual BOOL							LoadStream(const char *resourceName, IRuStream **streamOut);

	// Texture management
	virtual BOOL							AddTexture(IRuBaseTexture *texture);
	virtual BOOL							RemoveTexture(IRuBaseTexture *texture);
	virtual BOOL							RemoveTexture(const char *textureName);
	virtual BOOL							TextureExistsInCache(const char *textureName);
	virtual BOOL							EnableTextureGarbageCollection(IRuBaseTexture *texture, BOOL enableGC);
	virtual BOOL							PinTexture(IRuBaseTexture *texture, BOOL pinTexture);

	virtual	IRuTexture*						LoadTexture(const char *textureName, RuSurfaceFormat surfaceFormat = ruSURFACEFMT_DEFAULT, UINT32 maxMipLevel = 0, BOOL async = FALSE);

	virtual BOOL							CreateRenderTargetPool(INT32 poolSize, INT32 rtSize, RuSurfaceFormat rtFormat);
	virtual BOOL							ResetRenderTargetPools();
	virtual IRuTexture*						GetPooledRenderTarget(INT32 rtSize, RuSurfaceFormat rtFormat);
	virtual BOOL							FreePooledRenderTarget(IRuTexture *renderTarget);

	virtual BOOL							CreateRenderTargetSubAtlas(INT32 subAtlasSize, INT32 pageSize, RuSurfaceFormat rtFormat);
	virtual BOOL							RestoreRenderTargetView(IRuTextureView *textureView);
	virtual BOOL							ResetRenderTargetViews();

	// Animation management
	virtual CRuAnimation*					LoadAnimation(const char *animationName);
	virtual CRuAnimation_GR2*				LoadAnimation_GR2(const char *animationName);

	// Entity management
	// TODO: Pre-load function, garbage collection of stale entities(clone count = 1), etc
	virtual BOOL							AddEntity(const char *entityName, CRuEntity *entity);

	virtual CRuEntity*						LoadEntity(const char *entityName);
	virtual BOOL							LoadEntity(const char *entityName, CRuEntity **entityOut);

	// Generic object dictionary
	virtual BOOL							AddGenericObject(const char *objectName, IRuObject *obj);
	virtual IRuObject*						GetGenericObject(const char *objectName);

	// Dictionary management
	virtual BOOL							ClearTextureDictionary();
	virtual BOOL							ClearAnimationDictionary();
	virtual BOOL							ClearAnimationDictionary_GR2();
	virtual BOOL							ClearEntityDictionary();
	virtual BOOL							ClearGenericObjectDictionary();

	// Status report
	virtual BOOL							IsObjectWorkQueueEmpty();
	virtual BOOL							IsTextureWorkQueueEmpty();

	// Debugging
	virtual BOOL							OutputResourceManifest();

protected:
	static BOOL								ClearAnimationDictionaryCallback(const void *key, const void *data, void *userData);
	static BOOL								ClearAnimationDictionaryCallback_GR2(const void *key, const void *data, void *userData);
	static BOOL								ClearEntityDictionaryCallback(const void *key, const void *data, void *userData);
	BOOL									ClearGenericObjectDictionaryCallback(const void *key, void *data);
};

// ************************************************************************************************************************************************************

#pragma managed

#endif
