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

		InstanceRenderingCache.h
		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	charles
		Date:	6/21/2005

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

#ifndef __InstanceRenderingCache__
#define __InstanceRenderingCache__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "MCSmartPtr.h"
#include "ISMPJob.h"

/// Derive your cache from this struct
///
struct TInstanceRenderingCache : public TMCObject
{
	TInstanceRenderingCache(uint32	instanceIndex);

	// destroying this element will destroy the list.
	virtual ~TInstanceRenderingCache();

	const uint32						fInstanceIndex;
	TSMPSingleSection					fSingleSectionContext;
	TMCPtr<TInstanceRenderingCache>		fNext;
};


struct TInstanceRenderingCacheType : public TMCObject
{
	TInstanceRenderingCacheType(IDType type);

	// destroying this element will destroy the list.
	~TInstanceRenderingCacheType();

	TInstanceRenderingCache* FindRenderingCache(uint32 instanceIndex);

	IDType									fType;
	TMCPtr<TInstanceRenderingCacheType>		fNext;
	TMCSmartPtr<TInstanceRenderingCache>	fCaches;
};


struct TRenderingCacheLock : public TMCObject
{
	TRenderingCacheLock() : fCS(NULL) {}
	~TRenderingCacheLock() { if (fCS) {LeaveCS(fCS);} fCS = NULL; }

	void SetCS(TMCCriticalSection* theCS) { fCS=theCS; EnterCS(fCS); }
private:
	TMCPtr<TMCCriticalSection>		fCS;
};

#endif
