gameerrors.h

来自「Visual C++ 游戏开发与设计实例 源代码(所有)」· C头文件 代码 · 共 99 行

H
99
字号
/*******************************************************************
 *         Advanced 3D Game Programming using DirectX 7.0
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *   Title: GameErrors.h
 *    Desc: errors that game functions can have
 *          
 * copyright (c) 1999 by Adrian Perez
 * See license.txt for modification and distribution information
 ******************************************************************/

#ifndef _GAMEERRORS_H
#define _GAMEERRORS_H

#include <string>
#include "GameGlobals.h"

//==========--------------------------  

/**
 * This code is slow, using dynamic memory, but since we only use them
 * when something Really Bad happens, the user won't notice that their
 * application exits abmornally a few nanoseconds slower than usual
 */
class cGameError
{
	std::string m_errorText;
public:
	cGameError( const char* errorText )
	{
		DP1("***\n*** [ERROR] cGameError thrown! text: [%s]\n***\n", errorText );
		m_errorText = std::string( errorText );
	}

	const char* GetText()
	{
		return m_errorText.c_str();
	}
};

//==========--------------------------  

enum eResult
{
	resAllGood		= 0, // function passed with flying colors
	resFalse		= 1, // function worked and returns value 'false'
	resFailed		= -1, // function failed miserably
	resNotImpl		= -2, // function has not been implemented
	resForceDWord = 0x7FFFFFFF
};

inline bool Succeeded( eResult in )
{
	if( in >= 0 )
		return true;
	return false;
}

inline bool Failed( eResult in )
{
	if( in < 0 )
		return true;
	return false;
}

/**
 * The Right Way to release our COM interfaces.
 * If they're still valid, release them, then
 * invalidate them.
 */
template <class T>
inline void SafeRelease( T& iface )
{
	if( iface )
	{
		iface->Release();
		iface = NULL;
	}
}


/**
 * Make sure the release brings our refcount to 0.
 */
template <class T>
inline void ExtraSafeRelease( T& iface )
{
	long refCount = 0;

	if( iface )
	{
		if( 0 < ( refCount = iface->Release() ) )
		{
			DP0("[ExtraSafeRelease]: ERROR: Interface was not released enough!");
		}
		iface = NULL;
	}
}

#endif //_GAMEERRORS_H

⌨️ 快捷键说明

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