2011-06-22 20:12:22 +00:00
|
|
|
/* Do basic initialization, get the loop going */
|
|
|
|
|
2011-06-28 02:07:52 +00:00
|
|
|
#include "gamestate.h"
|
|
|
|
#include "game.h"
|
2011-06-28 02:35:52 +00:00
|
|
|
#include "debug.h"
|
2011-06-28 02:07:52 +00:00
|
|
|
#include <SDL.h>
|
2011-06-22 20:12:22 +00:00
|
|
|
|
2011-06-28 02:07:52 +00:00
|
|
|
int main(int argc, char** argv)
|
2011-06-22 20:12:22 +00:00
|
|
|
{
|
2011-06-28 02:07:52 +00:00
|
|
|
// Barebones setup for our game
|
|
|
|
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) return false;
|
|
|
|
SDL_WM_SetCaption("TreeWars","TreeWars");
|
|
|
|
|
2011-06-28 02:35:52 +00:00
|
|
|
SDL_Surface* display = SDL_SetVideoMode(800, 600, 32,
|
|
|
|
SDL_HWSURFACE | SDL_DOUBLEBUF);
|
|
|
|
if (display == NULL)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
std::cerr << "debug: main: error: Couldn't create main surface\n";
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-06-28 02:07:52 +00:00
|
|
|
stack<GameState*> state_stack;
|
|
|
|
|
|
|
|
// initialize the stack by initting and pushing the initial state(s)
|
2011-06-28 02:35:52 +00:00
|
|
|
GameState* tmpstate = new Game(display);
|
|
|
|
if (!tmpstate->init()) return 1;
|
2011-06-28 02:07:52 +00:00
|
|
|
state_stack.push(tmpstate);
|
|
|
|
|
|
|
|
while (!state_stack.empty())
|
|
|
|
{
|
|
|
|
GameState* state = state_stack.top();
|
|
|
|
try {
|
|
|
|
state->execute(state_stack);
|
|
|
|
} catch (StateExit& e) {
|
|
|
|
|
|
|
|
// remove the old state
|
|
|
|
state_stack.pop();
|
|
|
|
delete state;
|
|
|
|
|
|
|
|
// init the new state, discarding it if we fail
|
|
|
|
while (!(state_stack.empty() || state_stack.top()->init()))
|
|
|
|
{
|
|
|
|
state_stack.pop();
|
|
|
|
delete state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-28 02:35:52 +00:00
|
|
|
SDL_FreeSurface(display);
|
2011-06-28 02:07:52 +00:00
|
|
|
SDL_Quit();
|
|
|
|
|
|
|
|
return 0;
|
2011-06-22 20:12:22 +00:00
|
|
|
}
|