Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1.  
  2. #include "GameEngine.h"
  3.  
  4. GameEngine::GameEngine()
  5. {
  6.  
  7. }
  8.  
  9. GameEngine::~GameEngine()
  10. {
  11.  
  12. }
  13.  
  14.  
  15.  
  16. void GameEngine::Init(bool isDebug)
  17. {
  18. mDebug = isDebug;
  19.  
  20. if (isDebug)
  21. pspDebugScreenInit(); // do this so that we can use pspDebugScreenPrintf
  22.  
  23. sceCtrlSetSamplingCycle(0);
  24. sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
  25.  
  26. mpGraphicCore = GraphicCore::GetInstance();
  27.  
  28. //GraphicCore::Init();
  29. mpSoundCore = SoundCore::GetInstance();
  30. //mSoundCore->Init();
  31. //SoundCore::GetInstance()->Init();
  32.  
  33. mDone = false;
  34.  
  35.  
  36. Create();
  37.  
  38. mTickFrequency = sceRtcGetTickResolution();
  39. sceRtcGetCurrentTick(&mLastTime);
  40. }
  41.  
  42.  
  43. void GameEngine::End()
  44. {
  45. mDone = true;
  46. }
  47.  
  48.  
  49.  
  50. int GameEngine::Timer_GetTime(void)
  51. {
  52. u64 curr;
  53. sceRtcGetCurrentTick(&curr);
  54. return (int)(curr / mTickFrequency);
  55. }
  56.  
  57.  
  58. float GameEngine::Timer_GetDelta()
  59. {
  60. return mDelta;
  61. }
  62.  
  63.  
  64. float GameEngine::Timer_GetFPS()
  65. {
  66. return 1000.0f / mDelta;
  67. }
  68.  
  69.  
  70. void GameEngine::Run()
  71. {
  72.  
  73. u64 curr;
  74. while (!mDone)
  75. {
  76. sceRtcGetCurrentTick(&curr);
  77.  
  78. mDelta = (curr-mLastTime) / (float)mTickFrequency * 1000.0f;
  79. mLastTime = curr;
  80.  
  81.  
  82. sceCtrlPeekBufferPositive(&mCtrlPad, 1); // using sceCtrlPeekBufferPositive is faster than sceCtrlReadBufferPositive
  83. // because sceCtrlReadBufferPositive waits for vsync internally
  84.  
  85. Update();
  86.  
  87. mpGraphicCore->BeginRender();
  88. Render();
  89. mpGraphicCore->EndRender();
  90.  
  91. mOldButtons = mCtrlPad.Buttons;
  92.  
  93.  
  94. if(GetButtonState(PSP_CTRL_LTRIGGER))
  95. {
  96.  
  97. mDebug = !mDebug;
  98. }
  99.  
  100. }
  101.  
  102. // GraphicCore::Destroy();
  103.  
  104. // SoundCore::GetInstance()->Destroy();
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement