Frame.cpp
上传用户:jalin138
上传日期:2022-02-12
资源大小:5720k
文件大小:3k
- #include "Frame.h"
- #include "StateLoading.h"
- CFrame::CFrame(void)
- {
- int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
- tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
- _CrtSetDbgFlag( tmpFlag );
- m_SceneManage = NULL;
- m_pGui = NULL;
- }
- CFrame::~CFrame(void)
- {
- SAFE_DELETE( m_SceneManage );
- SAFE_DELETE( g_Res );
- SAFE_DELETE( m_pGui );
- g_Hge->Resource_RemoveAllPacks();
- g_Hge->System_Shutdown();
- g_Hge->Release();
- }
- // 框架初始化 //传入初始化文件名 // 加载配置
- bool CFrame::Init( const char* _IniFileName,
- bool (*Framefunc)(),
- bool (*Renderfunc)() )
- {
- g_Hge = hgeCreate( HGE_VERSION );
- SAFE_CHECK( g_Hge );
- g_Hge->System_SetState( HGE_TITLE, "DuiDuiPeng");
- g_Hge->System_SetState( HGE_INIFILE, _IniFileName );
- g_Hge->System_SetState( HGE_FRAMEFUNC, Framefunc );
- g_Hge->System_SetState( HGE_RENDERFUNC, Renderfunc );
- g_Hge->System_SetState( HGE_LOGFILE,g_Hge->Ini_GetString("System","Logfile","game.log") );
- g_Hge->System_SetState(HGE_FPS,g_Hge->Ini_GetInt( "System","FpsLimit",60) );
- g_Hge->System_SetState( HGE_HIDEMOUSE, (bool)g_Hge->Ini_GetInt("System","HideMouse",0) );
- g_Hge->System_SetState( HGE_DONTSUSPEND,(bool)g_Hge->Ini_GetInt( "System","AllowSuspend",1) );
- g_Hge->System_SetState( HGE_SHOWSPLASH, (bool)g_Hge->Ini_GetInt( "System","ShowsPlash",0) );
- g_Hge->System_SetState( HGE_SCREENWIDTH,g_Hge->Ini_GetInt("Window","Width",800) );
- g_Hge->System_SetState( HGE_SCREENHEIGHT,g_Hge->Ini_GetInt("Window","Height",600) );
- g_Hge->System_SetState(HGE_SCREENBPP,g_Hge->Ini_GetInt("Window","Bit",32));
- g_Hge->System_SetState( HGE_WINDOWED,(bool)g_Hge->Ini_GetInt("Window","Window",0) );
- g_Hge->System_SetState( HGE_USESOUND, (bool)g_Hge->Ini_GetInt( "Sound","UseSound",1 ) );
- g_Hge->System_SetState( HGE_FXVOLUME,g_Hge->Ini_GetInt("Sound","FxVolume",100) );
- g_Hge->System_SetState( HGE_MUSVOLUME,g_Hge->Ini_GetInt("Sound","MusicVolume",100) );
-
- if ( g_Hge->System_Initiate() )
- {
- return Start();
- }
- return false;
- }
- // 起动框架
- bool CFrame::Start(void)
- {
- if ( !g_Hge->Resource_AttachPack( "Res.zip" ) )
- return false;
-
- g_Res = new hgeResourceManager( "Res.res" );
- SAFE_CHECK( g_Res );
- m_SceneManage = new CSceneManage( new CStateLoading() );
- SAFE_CHECK( m_SceneManage );
- m_pGui = new hgeGUI();
- SAFE_CHECK( m_pGui );
- hgeSprite *mt_Cursor = g_Res->GetSprite( "Cursor" );
- m_pGui->SetCursor( mt_Cursor );
- return g_Hge->System_Start();
- }
- // 运行当前场景
- bool CFrame::FrameFunc(void)
- {
- if ( g_Hge->Input_KeyDown( HGEK_ESCAPE ) )
- return true;
- if ( m_SceneManage->Logic() )
- return true;
- m_pGui->Update( 0.01f );
- return false;
- }
- // 渲染
- bool CFrame::RenderFunc(void)
- {
- g_Hge->Gfx_BeginScene();
- g_Hge->Gfx_Clear(0);
-
- m_SceneManage->Render();
- /*#ifdef _DEBUG*/
- float mt_x = 0.0f, mt_y = 0.0f;
- g_Hge->Input_GetMousePos( &mt_x, &mt_y );
- g_Font->Print( 10, 10, "Mouse:x%d y%d",(int)mt_x, (int)mt_y );
- int m_nFps = g_Hge->Timer_GetFPS();
- g_Font->Print( 10,25, "FPS:%d", m_nFps );
- /*#endif*/
-
- m_pGui->Render();
- g_Hge->Gfx_EndScene();
- return false;
- }