⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iresource.h

📁 这个是我第一次完成的一个简单的3D ALIEN SHOOTING GAME的RESOURCE MANAGER部分,大家可以看看,然后提点意见~THX
💻 H
字号:
// IResource.h
//

// Author:			Lea Hayes
// Date Created:	11/03/2006
// Date Modified:	26/03/2006

#pragma once

#include "ResException.h"


namespace Resources
{


class IResource
{
// Destruction.
public:
	virtual ~IResource();

// Pure virtual functions which must be overriden.
	virtual void OnProcess(float nTime) = 0;
	virtual void OnRender(float nTime) = 0;

	virtual DWORD GetUniqueID() const = 0;

// Virtual functions which can be overriden.
	virtual void OnDestroy();

	// The following two functions cannot be executed unless
	// are overriden. For this reason any attempt to execute
	// these default functions will result in an assertion.
	//
	virtual HRESULT ReadFromFile(LPCSTR lpszFilename)
	{
		throw ResException(
			"IResource::ReadFromFile must be implemented for file IO.")
			EXTRA_DEBUGINFO;
	}
	virtual HRESULT WriteToFile(LPCSTR lpszFilename)
	{
		throw ResException(
			"IResource::WriteToFile must be implemented for file IO.")
			EXTRA_DEBUGINFO;
	}

// Memory management.
	void Release();

// Methods.
	inline void Process(float nTime)
	{
		OnProcess(nTime);
	}
	inline void Render(float nTime)
	{
		OnRender(nTime);
	}

// Properties.
	inline bool IsResourceBeingUsed() const
	{
		return m_dwUsage > 0;
	}
	inline DWORD GetUsage() const
	{
		return m_dwUsage;
	}

	inline bool IsDirectXResource() const
	{
		return GetUniqueID() < 100;
	}

	inline LPCSTR GetFilePath() const
	{
		return m_szFilePath;
	}

// Protected constructor prevents direct instantiation.
protected:
	IResource();

// Only the resource manager and array classes have access to the
// interfaces protected members.

	friend class ResourceManager;
	friend class ResourceArray;

protected:
	void Acquire(DWORD dwAddUsage = 1U);
	void Destroy();

	inline void Attach(LPVOID pResArray)
	{
		m_pArray = pResArray;
	}

	void SetFilePath(LPCSTR lpszFilePath);

// Attributes.
private:
	DWORD m_dwUsage;			// Resource usage information.
	LPVOID m_pArray;			// Associated resource array.
	LPSTR m_szFilePath;			// File and path.
};

typedef IResource * LPRESOURCE;


}; // namespace Resources

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -