treewars/gamecore.cpp

74 lines
899 B
C++

#include "gamecore.h"
#include "drawutils.h"
#ifdef DEBUG
#include <iostream>
#endif
GameCore::GameCore()
{
display = NULL;
is_running = true;
}
int GameCore::execute()
{
if (!init()) return 1;
SDL_Event event;
while (is_running)
{
while(SDL_PollEvent(&event))
handle_event(&event);
iterate();
render();
}
cleanup();
return 0;
}
bool GameCore::init()
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) return false;
display = SDL_SetVideoMode(800,600,32, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (display == NULL)
{
#ifdef DEBUG
std::cerr << "GameCore::init(): error: Couldn't create main surface\n";
#endif
return false;
}
return true;
}
void GameCore::render()
{
}
void GameCore::iterate()
{
}
void GameCore::cleanup()
{
SDL_FreeSurface(display);
SDL_Quit();
}
void GameCore::on_exit()
{
is_running = false;
}