?? asl_utils.h
字號:
//-----------------------------------------------------------------------------
//
// ____ Azure Star Game Engine 藍星游戲引擎 ____
//
// Copyright (c) 2006, 藍星工作室
// All rights reserved.
//
// 文件名稱: asl_utils.h
// 摘 要: ASL庫實用組件, 任何本庫文件必須包含本文件
//
// 當前版本: 1.0
// 作 者: 湯 祺
// 創建日期: 2006-7-15
//
//-----------------------------------------------------------------------------
#ifndef ASL_UTILITY_INCLUDE
#define ASL_UTILITY_INCLUDE
#pragma once
// 用戶態下引用庫
#ifndef ASL_LIB
#ifdef _DEBUG
#pragma comment(lib, "ASLD.lib")
#else
#pragma comment(lib, "ASL.lib")
#endif
#endif
// 消除VC不支持標準異常規范的警告
#pragma warning( disable : 4290 )
// 用STRICT方式編譯所有文件
#ifndef STRICT
#define STRICT
#endif
// 包含標準頭文件
#include <windows.h>
#include <stdio.h>
// 包含調試文件
#ifdef _DEBUG
#include <crtdbg.h>
#endif
//-----------------------------------------------------------------------------
namespace ASL
{
//-----------------------------------------------------------------------------
// 斷言定義
//-----------------------------------------------------------------------------
#ifndef ASSERT
#ifdef _DEBUG
#define ASSERT(expr) _ASSERT(expr)
#else
#define ASSERT(expr)
#endif
#endif
//-----------------------------------------------------------------------------
// 智能delete, releas宏
//-----------------------------------------------------------------------------
// 刪除一個對象
#define SAFE_DELETE(p) { if ((p) != NULL) { delete (p); (p) = NULL; } }
// 刪除一個數組
#define SAFE_DELETE_ARRAY(p) { if ((p) != NULL) { delete [](p); (p) = NULL; } }
// 刪除一個GDI對象
#define SAFE_DELETE_GDIOBJ(p) { if ((p) != NULL) { DeleteObject(p); (p) = NULL; } }
// 釋放DirectX對象
#define SAFE_RELEASE(p) { if ((p) != NULL) { (p)->Release(); (p) = NULL; } }
//-----------------------------------------------------------------------------
// 全局實用函數
//-----------------------------------------------------------------------------
// 打開Debug版的內存泄漏檢測(Release版無作用)
void EnableMemoryLeakCheck();
// 檢測DirectX版本是否在8以上
bool CheckDXVersion8(void);
// 取應用程序路徑
LPCSTR GetAppPath(void);
// 取應用程序目錄下某子目錄的絕對路徑
LPCSTR GetAbsPath(LPCSTR szDir);
// 檢測CPU是否支持MMX指令
bool IsMMX();
// 快速創建字體
HFONT CreateFontFast(LPCSTR face, int height, bool bold = false,
bool italic = false, bool underline = false);
// 將16位數擴展為64位(拷貝4份)
__int64 Bit16To64(WORD val);
//-----------------------------------------------------------------------------
// 日志記錄工具, 定義DISABLE_LOG則無效
//-----------------------------------------------------------------------------
// 日志類僅供Log()函數使用
class ASLLog
{
friend void Log(LPCSTR format, ...);
private:
static ASLLog& Instance(void) { static ASLLog instance; return instance; }
void WriteLog(LPCSTR msg) { fputs(msg, m_pFile); }
private:
ASLLog(void) { m_pFile = fopen("Log.txt", "wt"); }
~ASLLog(void) { fclose(m_pFile); }
private:
FILE *m_pFile;
};
// 記錄日志的全局函數
#ifndef DISABLE_LOG
inline void Log(LPCSTR format, ...)
{
va_list va;
char str[256];
// 處理格式化字符串
va_start(va, format);
vsprintf(str, format, va);
va_end(va);
ASLLog::Instance().WriteLog(str);
}
#else
inline void Log(LPCSTR format, ...) {}
#endif
//-----------------------------------------------------------------------------
// 異常類
//-----------------------------------------------------------------------------
// 異常基類
class ASLException
{
public:
virtual LPCSTR GetErrorMessage(void) const
{ static char szGeneric[] = "發生嚴重錯誤"; return szGeneric; }
};
// 簡單異常
class ASLSimpleException : public ASLException
{
public:
ASLSimpleException(LPCSTR szMessage)
{ strcpy(m_szMessage, szMessage); }
virtual LPCSTR GetErrorMessage(void) const
{ return m_szMessage; }
private:
char m_szMessage[128];
};
// Ini異常
class ASLIniException : public ASLException
{
public:
ASLIniException(LPCSTR szFileName, LPCSTR szKey)
{ sprintf(m_szMessage, "Ini文件 %s 鍵值 %s 讀取失敗", szFileName, szKey); }
virtual LPCSTR GetErrorMessage(void) const
{ return m_szMessage; }
private:
char m_szMessage[128];
};
// 文件異常
class ASLFileException : public ASLException
{
public:
enum Cause
{
Generic,
OpenFailed,
WriteFailed,
BadFormat
};
ASLFileException(LPCSTR szFileName, Cause cause = ASLFileException::Generic)
{ strcpy(m_szFileName, szFileName); m_Cause = cause; }
virtual LPCSTR GetErrorMessage(void) const;
inline Cause GetCause(void) const { return m_Cause; }
private:
char m_szFileName[128];
Cause m_Cause;
};
// DirectX異常
class ASLDirectXException : public ASLException
{
public:
enum DirectType
{
DirectX,
DirectDraw,
DirectMusic,
DirectSound,
DirectInput
};
ASLDirectXException(LPCSTR szDesc, HRESULT hr,
DirectType dt = ASLDirectXException::DirectX)
{ strcpy(m_szDesc, szDesc); m_hr = hr; m_DirectType = dt; }
virtual LPCSTR GetErrorMessage(void) const;
inline DirectType GetDirectType(void) const { return m_DirectType; }
private:
DirectType m_DirectType;
char m_szDesc[128];
HRESULT m_hr;
};
// DirectDraw異常
class ASLDirectDrawException : public ASLDirectXException
{
public:
ASLDirectDrawException(LPCSTR szDesc, HRESULT hr)
: ASLDirectXException(szDesc, hr, ASLDirectXException::DirectDraw) {}
};
// DirectMusic異常
class ASLDirectMusicException : public ASLDirectXException
{
public:
ASLDirectMusicException(LPCSTR szDesc, HRESULT hr)
: ASLDirectXException(szDesc, hr, ASLDirectXException::DirectMusic) {}
};
// DirectSound異常
class ASLDirectSoundException : public ASLDirectXException
{
public:
ASLDirectSoundException(LPCSTR szDesc, HRESULT hr)
: ASLDirectXException(szDesc, hr, ASLDirectXException::DirectSound) {}
};
// DirectInput異常
class ASLDirectInputException : public ASLDirectXException
{
public:
ASLDirectInputException(LPCSTR szDesc, HRESULT hr)
: ASLDirectXException(szDesc, hr, ASLDirectXException::DirectInput) {}
};
} // namespace ASL
#endif // ASL_UTILITY_INCLUDE
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -