Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [VectorEngine.h]
- #ifndef _CAPP_H_
- #define _CAPP_H_
- #include <SDL.h>
- class VectorEngine
- {
- private:
- bool running;
- SDL_Window* Surf_Display;
- public:
- VectorEngine();
- void onExecute();
- bool OnInit();
- void OnEvent(SDL_Event* Event);
- void OnTick();
- void OnRender();
- void OnCLeanup();
- };
- #endif
- [Main.cpp]
- #include"VectorEngine.h"
- #include <Windows.h>
- const int TICKS_PER_SECOND = 25;
- const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
- const int MAX_RENDERSKIPS = 5;
- VectorEngine::VectorEngine()
- {
- Surf_Display = NULL;
- running = true;
- OnInit();
- onExecute();
- }
- void VectorEngine::onExecute()
- {
- SDL_Event Event;
- DWORD next_game_tick = GetTickCount();
- while (running)
- {
- int skippedRenders = 0;
- while (GetTickCount()> next_game_tick && skippedRenders < MAX_RENDERSKIPS)
- {
- OnTick();
- next_game_tick += SKIP_TICKS;
- skippedRenders++;
- }
- OnRender();
- }
- }
- int main (int argc, char* argv[])
- {
- VectorEngine *vecEngine = new VectorEngine();
- return 0;
- }
- [Oninit.cpp]
- #include "VectorEngine.h"
- bool VectorEngine::OnInit()
- {
- SDL_Init(SDL_INIT_EVERYTHING);
- Surf_Display = SDL_CreateWindow("My Game Window",
- SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED,
- 640, 480,
- SDL_WINDOW_SHOWN| SDL_WINDOW_OPENGL);
- return true;
- }
- [OnCLeanup.cpp]
- #include"VectorEngine.h"
- void VectorEngine::OnCLeanup()
- {
- SDL_Quit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement