normal.h

来自「这个例子告诉你2d Arpg游戏中的动态阴影如何生成」· C头文件 代码 · 共 100 行

H
100
字号
#ifndef normal_h
#define normal_h
#include <cassert>

#ifndef NULL
#ifdef  __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif

#define READ_MEMORY( pDataSrc, type ) (*(type *)pDataSrc)

#ifdef _DEBUG
#define debug_assert( c )	assert( c )
#else
#define debug_assert( c )	0
#endif

template <class T>
void SafeRelease( T &p )
{
	if ( p != NULL )
	{
		p->Release();
		p = NULL;
	}
}

template <class T>
void SafeFree( T &p )
{
	if ( p != NULL )
		p->Free();
}

template <class T>
void SafeDelete( T &p )
{
	if ( p != NULL )
	{
		delete p;
		p = NULL;
	}
}

template <class T>
void SafeDeleteArray( T &p )
{
	if ( p != NULL )
	{
		delete [] p;
		p = NULL;
	}
}

template <class T>
void Swap( T &t1, T &t2 )
{
	T temp;
	temp = t1;
	t1 = t2;
	t2 = temp;
}

template < class T >
void QuickSort( T a[], int iSize )
{
	if ( iSize <= 1 ) return;

	int iEnd = iSize - 1;

	T bound = a[iSize / 2];

	Swap( a[0], a[iSize / 2] );

	int i = 1; 

	while ( i <= iEnd )
	{
		if ( a[i] < bound )
		{
			Swap( a[i], a[iEnd] );
			--iEnd;
		}
		else
		{
			++i;
		}
	}
	Swap( a[0], a[i-1] );

	QuickSort( &a[0], i - 1 );

	QuickSort( &a[iEnd + 1], iSize - 1 - iEnd );
	
}

#endif

⌨️ 快捷键说明

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