📄 resman.h
字号:
// ResMan.h
//
// Author: Lea Hayes
// Date Created: 10/03/2006
// Date Modified: 24/03/2006
// Description: This resource manager has been designed to simplify
// resource management. In-order to utilise resource
// management on a custom resource type the specific
// resource interface must be derived upon.
//
#pragma once
#include "ResArray.h"
// Predefined unique resource IDs:
namespace Resources
{
const DWORD DIRECTX_TEXTURE = 1U;
const DWORD DIRECTX_OBJECTX = 2U;
const DWORD DIRECTX_FONT = 3U;
const DWORD DIRECTX_SOUNDFX = 4U;
const DWORD DIRECTX_MUSIC = 5U;
class ResourceManager
{
// Private construction prevents any further instantiation.
private:
ResourceManager();
// Destruction.
public:
virtual ~ResourceManager();
static void Destroy();
// Resource handle.
typedef ResArrayHandle ResHandle;
static const ResHandle NullHandle;
// File and path management.
static bool CheckFilePath(LPCSTR lpszFilePath);
static LPCSTR ResolveFilePath(LPCSTR lpszFilename,
LPCSTR lpszResFolder = NULL);
// Resource management.
static HRESULT PreloadTexture(LPCSTR lpszFilename);
static HRESULT PreloadObjectX(LPCSTR lpszFilename);
static HRESULT PreloadFont(LPCSTR lpszFontName, INT nHeight, UINT nWidth,
bool bBold, bool bItalic, UINT nMipLevels, LPCSTR lpszTypeFace);
static void AppendCustom(LPRESOURCE pCustomRes);
static ResHandle AquireTexture(LPCSTR lpszFilename);
static ResHandle AquireObjectX(LPCSTR lpszFilename);
static ResHandle AquireFont(LPCSTR lpszFontName, INT nHeight, UINT nWidth,
bool bBold, bool bItalic, UINT nMipLevels, LPCSTR lpszTypeFace);
static inline ResHandle AquireFirstCustom(LPCSTR lpszFilename)
{
return m_sGlobal.m_arCustom.Aquire(lpszFilename);
}
static inline ResHandle AquireFirstCustom(DWORD dwUniqueID)
{
return m_sGlobal.m_arCustom.Aquire(dwUniqueID);
}
static inline ResHandle AquireCustomByIndex(size_t nIndex)
{
return m_sGlobal.m_arCustom.AquireByIndex(nIndex);
}
inline static ResHandle AquireNextCustom(const ResHandle& prev,
LPCSTR lpszFilename)
{
return m_sGlobal.m_arCustom.AquireNext(prev, lpszFilename);
}
inline static ResHandle AquireNextCustom(const ResHandle& prev,
DWORD dwUniqueID)
{
return m_sGlobal.m_arCustom.AquireNext(prev, dwUniqueID);
}
static inline void Release(ResHandle &handle)
{
handle->Release();
handle = NullHandle;
}
// Properties.
static void EnableAutoFreeUnused(bool bEnable = true);
static inline LPDIRECT3DDEVICE9 GetActiveDevice()
{
return m_sGlobal.m_pDevice;
}
static inline void SetActiveDevice(LPDIRECT3DDEVICE9 pDevice)
{
m_sGlobal.m_pDevice = pDevice;
}
// Attributes.
private:
ResourceArray m_arDirectX;
ResourceArray m_arCustom;
LPDIRECT3DDEVICE9 m_pDevice;
// The one and only resource manager.
static ResourceManager m_sGlobal;
};
// The following macro will improve upon the readability of derived
// source. Also the definition abstracts other programmers from the
// DMA which is occuring here.
//
#define CREATE_RESOURCE(class_name) \
new class_name
#define OPEN_RESOURCE(class_name, filename) \
new class_name(filename)
// Proposed Usage:
// ResourceManager::CreateEntity(CREATE_RESOURCE(MyEntity));
//
}; // namespace Resources
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -