x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
GameEngine.cpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\DarkPuzzle\GameEngine\GameEngine.cpp
旋转
特效
属性
历史版本
//#include "DXUT.h" #include "DarkPuzzle.h" #include "GameEngine.h" using namespace DarkBattle; #include "fcntl.h" #include "io.h" #include
#include "conio.h" namespace DarkBattle{ //init all the default values float GameEngine::SpotLightRange = 30.0f; float GameEngine::SpotLightRadius = 15.0f; float GameEngine::PointLightRange = 40.0f; float GameEngine::RunVelocity = 10.0f; float GameEngine::RunVelocityEpsilon = 1.0f; float GameEngine::RunAcceleration = 2.0f; float GameEngine::lightDirectionalDir[3] = {0.6f,0.2f,0.3f}; float GameEngine::RangeEpsilon = 0.1f; double GameEngine::PreferedFrameRate = 40; GameEngine::Mouse GameEngine::storedMouse = GameEngine::Mouse(); CRITICAL_SECTION GameEngine::cs_mousePos; void GameEngine::LightDirectionalDir(float vals[3]){ memcpy(GameEngine::lightDirectionalDir,vals,3*sizeof(float)); } IDirect3DDevice9* GetD3DDevice(){ return DXUTGetD3D9Device(); }; //GameLevel* theGameLevel = NULL; #ifdef _DEBUG FILE* fdebug; FILE* fdebugIn; #endif // _DEBUG #ifdef _DEBUG void GameEngine::initConsole(){ //int hConHandle; //long lStdHandle; //CONSOLE_SCREEN_BUFFER_INFO coninfo; ////FILE *fp; //// allocate a console for this app //AllocConsole(); //// set the screen buffer to be big enough to let us scroll text //GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), // &coninfo); //coninfo.dwSize.Y = 40; //SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), // coninfo.dwSize); //// redirect unbuffered STDOUT to the console //lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); //hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); //fdebug = _fdopen( hConHandle, "w" ); //*stdout = *fdebug; //setvbuf( stdout, NULL, _IONBF, 0 ); //// redirect unbuffered STDIN to the console //lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE); //hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); //fdebugIn = _fdopen( hConHandle, "r" ); //*stdin = *fdebugIn; //setvbuf( stdin, NULL, _IONBF, 0 ); //ios::sync_with_stdio(); AllocConsole(); int hCrtIn; hCrtIn = _open_osfhandle((long) GetStdHandle(STD_INPUT_HANDLE), _O_TEXT ); assert(hCrtIn!=-1); fdebugIn = _fdopen( hCrtIn, "r" ); *stdin = *fdebugIn; setvbuf( fdebugIn, NULL, _IONBF, 0 ); std::cin.clear(); int hCrt; hCrt = _open_osfhandle( (long) GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT ); assert(hCrt!=-1); fdebug = _fdopen( hCrt, "w" ); *stdout = *fdebug; //uncomment this line for capturing all printf or cout outputs to stdout setvbuf( fdebug, NULL, _IONBF, 0 ); std::cout.clear(); DEBUG_OUTPUT("Debug console started!\n"); //char* aa; //fscanf(fdebugIn,"%s\n",&aa); //DEBUG_OUTPUT("%d",23); //DEBUG_OUTPUT("Hi!\n"); //myConsole = ConStream(); } #endif // _DEBUG GameEngine* GameEngine::theGameEngine = NULL; GameEngine::GameEngine(IDirect3DDevice9* pd3dDevice):GameScreen(pd3dDevice){ CDXUTIMEEditBox::Initialize( DXUTGetHWND() ); assert(theGameEngine==NULL); theGameEngine = this; InitializeCriticalSection(&cs_mousePos); this->pCurrentScreen = NULL; this->pOverlayUI = NULL; #ifdef _DEBUG initConsole(); #endif // _DEBUG pCurrentScreen = new GameLevel(pd3dDevice); //theGameLevel = (GameLevel*)pCurrentScreen; pOverlayUI = new GameUI(pd3dDevice); myEngine = new ScriptEngine(); myEngine->ReLoadConstants(); //TODO: init everything here //pCurrentScreen->OnCreateDevice(); ((GameLevel*)pCurrentScreen)->LoadContent(pd3dDevice,"level3"); }; GameEngine::~GameEngine(){ SAFE_DELETE(pCurrentScreen); SAFE_DELETE(pOverlayUI); SAFE_DELETE(myEngine); DeleteCriticalSection(&cs_mousePos); assert(theGameEngine!=NULL); theGameEngine = NULL; } void GameEngine::KeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext ){ if (GameUI::GetInstance()->IsEditing()) return; if (bKeyDown){ switch(nChar){ case 'S': GameLevel::GetInstance()->controllableCharacter->Move(Character::Direction::DOWN); break; case 'W': GameLevel::GetInstance()->controllableCharacter->Move(Character::Direction::UP); break; case 'A': GameLevel::GetInstance()->controllableCharacter->Move(Character::Direction::LEFT); break; case 'D': GameLevel::GetInstance()->controllableCharacter->Move(Character::Direction::RIGHT); break; case VK_SPACE: GameLevel::GetInstance()->controllableCharacter->Jump(); break; case 'Q': GameLevel::GetInstance()->angle -= 90*DXUTGetElapsedTime(); break; case 'E': GameLevel::GetInstance()->angle += 90*DXUTGetElapsedTime(); break; case 'F': if (bAltDown){ DXUTToggleFullScreen(); } break; } } } void GameEngine::MouseProc( bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos, void* pUserContext ){ float width = (float)DXUTGetD3D9BackBufferSurfaceDesc()->Width; float height = (float)DXUTGetD3D9BackBufferSurfaceDesc()->Height; //RECT rect = DXUTGetWindowClientRect(); //xPos -= rect.left; //yPos -= rect.top; EnterCriticalSection(&cs_mousePos); storedMouse.x = (float)(xPos-width/2)/width*2; storedMouse.y = (float)(yPos-height/2)/height*2; storedMouse.leftOld = storedMouse.leftButtonDown; storedMouse.rightOld = storedMouse.rightButtonDown; storedMouse.leftButtonDown = bLeftButtonDown; storedMouse.rightButtonDown = bRightButtonDown; LeaveCriticalSection(&cs_mousePos); if (bLeftButtonDown){ GameUI::GetInstance()->isEditing = false; } } GameEngine::Mouse GameEngine::GetMouseState(){ EnterCriticalSection(&cs_mousePos); Mouse ret = storedMouse; LeaveCriticalSection(&cs_mousePos); return ret; } void GameEngine::OnResetDevice(IDirect3DDevice9* pd3dDevice){ pOverlayUI->OnResetDevice(pd3dDevice); pCurrentScreen->OnResetDevice(pd3dDevice); } void GameEngine::OnFrameMove(float elapsedTime){ pCurrentScreen->OnFrameMove(elapsedTime); pOverlayUI->OnFrameMove(elapsedTime); //TODO: console input handling //if (kbhit()){ // char* str = new char[200]; // char* strHead = str; // char ch; // do{ // ch = getch(); // *str = ch; // str++; // }while (ch!='\n'); // *str = 0; // ReadConsoleInputA() // SAFE_DELETE_ARRAY(str); //} //INPUT_RECORD inputRecord; //DWORD eventRead; //PeekConsoleInputA(stdin,&inputRecord,1,&eventRead); //if (eventRead!=0){ // int aa; // aa=0; //} } void GameEngine::OnRender(IDirect3DDevice9* pd3dDevice){ HRESULT hr; // Clear the render target and the zbuffer V( pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0) ); // Render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { pCurrentScreen->OnRender(pd3dDevice); pOverlayUI->OnRender(pd3dDevice); V( pd3dDevice->EndScene() ); } } void GameEngine::OnLostDevice(){ pCurrentScreen->OnLostDevice(); pOverlayUI->OnLostDevice(); } void GameEngine::SetNewScreen(GameScreen* newScreen){ //TODO: set new screen here delete pCurrentScreen; pCurrentScreen = newScreen; } }
GameEngine.cpp
网页地址
文件地址
上一页
29/65
下一页
下载
( 7 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.