Frame.cpp
上传用户:jalin138
上传日期:2022-02-12
资源大小:5720k
文件大小:3k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. #include "Frame.h"
  2. #include "StateLoading.h"
  3. CFrame::CFrame(void)
  4. {
  5. int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
  6. tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
  7. _CrtSetDbgFlag( tmpFlag );
  8. m_SceneManage = NULL;
  9. m_pGui = NULL;
  10. }
  11. CFrame::~CFrame(void)
  12. {
  13. SAFE_DELETE( m_SceneManage );
  14. SAFE_DELETE( g_Res );
  15. SAFE_DELETE( m_pGui );
  16. g_Hge->Resource_RemoveAllPacks();
  17. g_Hge->System_Shutdown();
  18. g_Hge->Release();
  19. }
  20. // 框架初始化 //传入初始化文件名 // 加载配置
  21. bool CFrame::Init( const char* _IniFileName,
  22.   bool (*Framefunc)(), 
  23.   bool (*Renderfunc)() )
  24. {
  25. g_Hge = hgeCreate( HGE_VERSION );
  26. SAFE_CHECK( g_Hge );
  27. g_Hge->System_SetState( HGE_TITLE, "DuiDuiPeng");
  28. g_Hge->System_SetState( HGE_INIFILE, _IniFileName );
  29. g_Hge->System_SetState( HGE_FRAMEFUNC, Framefunc );
  30. g_Hge->System_SetState( HGE_RENDERFUNC, Renderfunc );
  31. g_Hge->System_SetState( HGE_LOGFILE,g_Hge->Ini_GetString("System","Logfile","game.log") );
  32. g_Hge->System_SetState(HGE_FPS,g_Hge->Ini_GetInt( "System","FpsLimit",60) );
  33. g_Hge->System_SetState( HGE_HIDEMOUSE, (bool)g_Hge->Ini_GetInt("System","HideMouse",0) );
  34. g_Hge->System_SetState( HGE_DONTSUSPEND,(bool)g_Hge->Ini_GetInt( "System","AllowSuspend",1) );
  35. g_Hge->System_SetState( HGE_SHOWSPLASH, (bool)g_Hge->Ini_GetInt( "System","ShowsPlash",0) );
  36. g_Hge->System_SetState( HGE_SCREENWIDTH,g_Hge->Ini_GetInt("Window","Width",800) );
  37. g_Hge->System_SetState( HGE_SCREENHEIGHT,g_Hge->Ini_GetInt("Window","Height",600) );
  38. g_Hge->System_SetState(HGE_SCREENBPP,g_Hge->Ini_GetInt("Window","Bit",32));
  39. g_Hge->System_SetState( HGE_WINDOWED,(bool)g_Hge->Ini_GetInt("Window","Window",0) );
  40. g_Hge->System_SetState( HGE_USESOUND, (bool)g_Hge->Ini_GetInt( "Sound","UseSound",1 ) );
  41. g_Hge->System_SetState( HGE_FXVOLUME,g_Hge->Ini_GetInt("Sound","FxVolume",100) );
  42. g_Hge->System_SetState( HGE_MUSVOLUME,g_Hge->Ini_GetInt("Sound","MusicVolume",100) );
  43. if ( g_Hge->System_Initiate() )
  44. {
  45. return Start();
  46. }
  47. return false;
  48. }
  49. // 起动框架
  50. bool CFrame::Start(void)
  51. {
  52. if ( !g_Hge->Resource_AttachPack( "Res.zip" ) )
  53. return false;
  54. g_Res = new hgeResourceManager( "Res.res" );
  55. SAFE_CHECK( g_Res );
  56. m_SceneManage = new CSceneManage( new CStateLoading() );
  57. SAFE_CHECK( m_SceneManage );
  58. m_pGui = new hgeGUI();
  59. SAFE_CHECK( m_pGui );
  60. hgeSprite *mt_Cursor = g_Res->GetSprite( "Cursor" );
  61. m_pGui->SetCursor( mt_Cursor );
  62. return g_Hge->System_Start();
  63. }
  64. // 运行当前场景
  65. bool CFrame::FrameFunc(void)
  66. {
  67. if ( g_Hge->Input_KeyDown( HGEK_ESCAPE ) )
  68. return true;
  69. if ( m_SceneManage->Logic() )
  70. return true;
  71. m_pGui->Update( 0.01f );
  72. return false;
  73. }
  74. // 渲染
  75. bool CFrame::RenderFunc(void)
  76. {
  77. g_Hge->Gfx_BeginScene();
  78. g_Hge->Gfx_Clear(0);
  79. m_SceneManage->Render();
  80. /*#ifdef _DEBUG*/
  81. float mt_x = 0.0f, mt_y = 0.0f;
  82. g_Hge->Input_GetMousePos( &mt_x, &mt_y );
  83. g_Font->Print( 10, 10, "Mouse:x%d y%d",(int)mt_x, (int)mt_y );
  84. int m_nFps = g_Hge->Timer_GetFPS();
  85. g_Font->Print( 10,25, "FPS:%d", m_nFps );
  86. /*#endif*/
  87. m_pGui->Render();
  88. g_Hge->Gfx_EndScene();
  89. return false;
  90. }