?? general.h
字號:
//========================================================
/**
* @file general.h
*
* 項目描述: 構造游戲引擎
* 文件描述: 常用結構和全局函數(shù)
* 適用平臺: Windows98/2000/NT/XP
*
* 作者: WWBOSS
* 電子郵件: wwboss123@gmail.com
* 創(chuàng)建日期: 2007-07-26
* 修改日期: 2007-07-26
*
*/
//========================================================
#ifndef _GENERAL_H_
#define _GENERAL_H_
#include "stdafx.h"
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <stdio.h>
#pragma warning(disable: 4267)
/** 一些常量 */
#define F3D_DEPTH 800.f
#define SYS_HWND (SWindowInfo::GetSysWinInfo()->m_hWnd)
#define SYS_WIDTH (SWindowInfo::GetSysWinInfo()->m_iWidth)
#define SYS_HEIGHT (SWindowInfo::GetSysWinInfo()->m_iHeight)
#define SYS_KEYBOARD (CInput::GetSysInput()->GetKeyboard())
#define SYS_MOUSE (CInput::GetSysInput()->GetMouse())
/** 按鈕的狀態(tài) */
#define BUTTON_NORMAL 0
#define BUTTON_ACTIVE 1
#define BUTTON_DISABLE 2
#define BUTTON_DOWNL 3
#define BUTTON_DOWNR 4
#define BUTTON_CLICK 5
/** 按鈕上字的類型 */
#define BTN_TEXT_LEFT 0
#define BTN_TEXT_CENTER 1
#define BTN_TEXT_RIGHT 2
/** 游戲進度 */
#define GAME_INIT 0
#define GAME_TITLE 1
#define GAME_CG 2
#define GAME_MENU 3
#define GAME_SETTING 4
#define GAME_MAIN 5
#define GAME_END 6
/** 常用宏 */
#define _ERROR(info) MessageBox(NULL,info,"error",MB_OK)
#define _DELETE(X) try{ if((X)!=NULL){delete (X); (X) = NULL; } } catch(...) { _ERROR("error delete!"); }
#define _DELETE_ARRAY(X)try{ if((X)!=NULL){delete[] (X); (X) = NULL; } } catch(...) { _ERROR("error delete[]!"); }
#define _FREE(X) try{ if((X)!=NULL){free(X);(X)=NULL; } } catch(...) { _ERROR("error free()!"); }
#define _RELEASE(A) try{ if((A)!=NULL){(A)->Release(); (A) = NULL; } } catch(...) { _ERROR("error ->Release!"); }
/** 定義顏色的類型 */
typedef DWORD DWCOLOR;
/** 隨機數(shù) */
#define _RANDOM(nMax) (rand()*nMax/RAND_MAX)
/** 將INI文件中的int型數(shù)轉化為float型 */
#define PERSENT(iNum) ((float)(iNum)*0.01f)
/**\brief
* 在v1和v2之間隨機返回一個數(shù)
*/
template<class T>
inline static T RangedRandom(T v1,T v2)
{
return v1 + (v2-v1)*((T)rand())/((T)RAND_MAX);
}
/**\brief
* 獲取文件長度
*/
static int GetFileLength(char *name)
{
int fh, nbytes;
fh = _open( name, _O_RDONLY );//只讀模式
if( fh== -1 ){return -1;}
nbytes=_filelength(fh);
_close(fh);
return nbytes;
}
/**\brief
* 判斷文件是否存在
*/
static BOOL CheckFile(char *name)
{
//查找文件
WIN32_FIND_DATA fdt;
HANDLE hFile = FindFirstFile(name,&fdt);
if( hFile ==INVALID_HANDLE_VALUE )
return FALSE;
else
{
FindClose(hFile);
return TRUE;
}
}
/**\brief
* 由文件名獲取文件路徑
*/
static char* GetFilePath(char *filename)
{
char *Ret;
int Len=strlen(filename);
Ret=(char *)malloc(Len+1);
strcpy(Ret, filename);
for(int i=Len-1; i>=0; i--)
{
if( Ret[i] == '\\' )//從后向前找'\'
break;
Ret[i]=0; //設置成結束點
}
return Ret;
}
/**\brief
* 從文件名含路徑分離出文件名不含路徑
*/
static char* GetFileName(char* filename)
{
char * szTemp = strrchr(filename,'\\'); //找最后一個'\'
++szTemp; //跳過'\'
char *Ret = (char*)malloc(strlen(szTemp)+1);
strcpy(Ret,szTemp);
return Ret;
}
/**\brief
* 顯示調試信息
*/
static void ShowMessage(char *msg,...)
{
va_list va;
char str[256];
va_start(va,msg);
vsprintf(str,msg,va);
va_end(va);
MessageBox(NULL,str,"Message",MB_OK);
}
/**\brief
* char to wchar
*/
static WCHAR* WChar(char *str)
{
WORD *wchr;
//將后兩個參數(shù)設置成NULL和0
//得到需要的緩沖區(qū)長度
int wsize=MultiByteToWideChar(CP_ACP, NULL, str, strlen(str), NULL, 0);
wchr=new WORD[wsize+1]; //多出一個放0
MultiByteToWideChar(CP_ACP, NULL, str, strlen(str), wchr, wsize);
wchr[wsize]=0;
return wchr;
}
/**\brief
* wchar to char
*/
static char* Char(WCHAR *str)
{
char *chr;
chr=new char[wcslen(str)+1];
memset(chr, 0, wcslen(str)+1);
for(unsigned int i=0;i<wcslen(str);++i)
{
chr[i]=(unsigned char)str[i];
}
return chr;
}
/**\brief
* 開始2D渲染
*/
static void BeginOrtho(int _width,int _height)
{
//glMatrixMode(GL_MODELVIEW);
//glPushMatrix();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,_width,0,_height,-1,F3D_DEPTH);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/**\brief
* 結束2D渲染
*/
static void EndOrtho()
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
//glMatrixMode(GL_MODELVIEW);
//glPopMatrix();
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -