Advertisement
Guest User

GameProbsMan

a guest
Jan 21st, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. [VectorEngine.h]
  2. #ifndef _CAPP_H_
  3. #define _CAPP_H_
  4. #include  <SDL.h>
  5.  
  6. class VectorEngine
  7. {
  8.  
  9.     private:
  10.        
  11.             bool                     running;
  12.             SDL_Window*        Surf_Display;
  13.  
  14.     public:
  15.                               VectorEngine();
  16.             void                 onExecute();
  17.             bool                    OnInit();
  18.             void   OnEvent(SDL_Event* Event);
  19.             void                    OnTick();
  20.             void                  OnRender();
  21.             void                 OnCLeanup();
  22. };
  23. #endif
  24.  
  25. [Main.cpp]
  26. #include"VectorEngine.h"
  27. #include <Windows.h>
  28.  
  29.  
  30. const int TICKS_PER_SECOND = 25;
  31. const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
  32. const int MAX_RENDERSKIPS = 5;
  33.  
  34.  
  35.     VectorEngine::VectorEngine()
  36. {
  37.     Surf_Display = NULL;
  38.     running = true;
  39.     OnInit();
  40.     onExecute();
  41.  
  42. }
  43.  
  44.     void VectorEngine::onExecute()
  45. {  
  46.         SDL_Event Event;
  47.         DWORD next_game_tick = GetTickCount();
  48.         while (running)
  49.         {
  50.             int skippedRenders = 0;
  51.             while (GetTickCount()> next_game_tick && skippedRenders < MAX_RENDERSKIPS)
  52.             {
  53.                 OnTick();
  54.                 next_game_tick += SKIP_TICKS;
  55.                 skippedRenders++;
  56.             }
  57.             OnRender();
  58.  
  59.         }
  60.  
  61.        
  62. }
  63.    
  64.     int main (int argc, char* argv[])
  65. {
  66.         VectorEngine  *vecEngine = new VectorEngine();
  67.         return 0;
  68. }
  69.  
  70.  
  71. [Oninit.cpp]
  72.     #include "VectorEngine.h"
  73.  
  74.   bool VectorEngine::OnInit()
  75. {
  76.        
  77.         SDL_Init(SDL_INIT_EVERYTHING);
  78.         Surf_Display = SDL_CreateWindow("My Game Window",
  79.             SDL_WINDOWPOS_UNDEFINED,
  80.             SDL_WINDOWPOS_UNDEFINED,
  81.             640, 480,
  82.             SDL_WINDOW_SHOWN| SDL_WINDOW_OPENGL);
  83.        
  84.        
  85.         return true;
  86. }
  87.  
  88. [OnCLeanup.cpp]
  89.  
  90. #include"VectorEngine.h"
  91.  
  92.     void VectorEngine::OnCLeanup()
  93. {
  94.         SDL_Quit();
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement