2012-01-08 11:39:03 -06:00
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <SDL/SDL.h>
|
2012-01-14 12:51:24 -06:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2012-01-08 11:39:03 -06:00
|
|
|
#include "Config.h"
|
2012-01-15 13:35:40 -06:00
|
|
|
#include "Global.h"
|
2012-01-08 11:39:03 -06:00
|
|
|
#include "Graphics.h"
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
#include "interface/Engine.h"
|
2012-01-08 11:39:03 -06:00
|
|
|
#include "interface/Button.h"
|
2012-01-10 17:18:37 -06:00
|
|
|
#include "interface/Panel.h"
|
|
|
|
#include "interface/ControlFactory.h"
|
2012-01-14 12:51:24 -06:00
|
|
|
#include "interface/Point.h"
|
|
|
|
#include "interface/Label.h"
|
2012-01-08 11:39:03 -06:00
|
|
|
|
2012-01-17 14:46:06 -06:00
|
|
|
#include "game/GameController.h"
|
|
|
|
#include "game/GameView.h"
|
|
|
|
|
2012-01-19 07:44:59 -06:00
|
|
|
#include "client/HTTP.h"
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
using namespace std;
|
|
|
|
|
2012-01-08 11:39:03 -06:00
|
|
|
SDL_Surface * SDLOpen()
|
|
|
|
{
|
2012-01-14 12:51:24 -06:00
|
|
|
#if defined(WIN32) && defined(WINCONSOLE)
|
|
|
|
FILE * console = fopen("CON", "w" );
|
|
|
|
#endif
|
2012-01-08 11:39:03 -06:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO)<0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError());
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-14 12:51:24 -06:00
|
|
|
#if defined(WIN32) && defined(WINCONSOLE)
|
|
|
|
//On Windows, SDL redirects stdout to stdout.txt, which can be annoying when debugging, here we redirect back to the console
|
|
|
|
if (console)
|
|
|
|
{
|
|
|
|
freopen("CON", "w", stdout);
|
|
|
|
freopen("con", "w", stderr);
|
|
|
|
fclose(console);
|
|
|
|
}
|
|
|
|
#endif
|
2012-01-08 11:39:03 -06:00
|
|
|
atexit(SDL_Quit);
|
|
|
|
return SDL_SetVideoMode(XRES + BARSIZE, YRES + MENUSIZE, 32, SDL_SWSURFACE);
|
|
|
|
}
|
|
|
|
|
2012-01-15 13:35:40 -06:00
|
|
|
/*int SDLPoll(SDL_Event * event)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
|
|
|
while (SDL_PollEvent(event))
|
|
|
|
{
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case SDL_QUIT:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2012-01-15 13:35:40 -06:00
|
|
|
}*/
|
2012-01-08 11:39:03 -06:00
|
|
|
|
|
|
|
int main(int argc, char * argv[])
|
|
|
|
{
|
2012-01-14 12:51:24 -06:00
|
|
|
int elapsedTime = 0, currentTime = 0, lastTime = 0, currentFrame = 0;
|
2012-01-15 13:35:40 -06:00
|
|
|
float fps = 0, fpsLimit = 30, delta = 1.0f;
|
2012-01-08 11:39:03 -06:00
|
|
|
|
2012-01-17 14:46:06 -06:00
|
|
|
ui::Engine::Ref().g = new Graphics();
|
|
|
|
ui::Engine::Ref().g->AttachSDLSurface(SDLOpen());
|
2012-01-15 13:35:40 -06:00
|
|
|
|
2012-01-20 16:07:49 -06:00
|
|
|
ui::Engine * engine = &ui::Engine::Ref();
|
2012-01-15 13:35:40 -06:00
|
|
|
engine->Begin(XRES, YRES);
|
2012-01-17 14:46:06 -06:00
|
|
|
|
|
|
|
GameController * gameController = new GameController();
|
|
|
|
engine->ShowWindow(gameController->GetView());
|
2012-01-08 11:39:03 -06:00
|
|
|
|
|
|
|
SDL_Event event;
|
2012-01-15 13:35:40 -06:00
|
|
|
while(engine->Running())
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
2012-01-15 13:35:40 -06:00
|
|
|
event.type = 0;
|
|
|
|
while (SDL_PollEvent(&event))
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
2012-01-15 13:35:40 -06:00
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case SDL_QUIT:
|
|
|
|
engine->Exit();
|
|
|
|
break;
|
|
|
|
case SDL_KEYDOWN:
|
2012-01-20 16:07:49 -06:00
|
|
|
engine->onKeyPress(event.key.keysym.sym, false, false, false);
|
2012-01-15 13:35:40 -06:00
|
|
|
break;
|
|
|
|
case SDL_KEYUP:
|
|
|
|
break;
|
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
engine->onMouseMove(event.motion.x, event.motion.y);
|
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
engine->onMouseClick(event.motion.x, event.motion.y, event.button.button);
|
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
engine->onMouseUnclick(event.motion.x, event.motion.y, event.button.button);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
event.type = 0; //Clear last event
|
2012-01-08 11:39:03 -06:00
|
|
|
}
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
engine->Tick(delta);
|
|
|
|
engine->Draw();
|
2012-01-08 11:39:03 -06:00
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
currentFrame++;
|
|
|
|
currentTime = SDL_GetTicks();
|
|
|
|
elapsedTime = currentTime - lastTime;
|
2012-01-15 13:35:40 -06:00
|
|
|
if((currentFrame>2 || elapsedTime > 1000*2/ui::Engine::Ref().FpsLimit) && elapsedTime && currentFrame*1000/elapsedTime > ui::Engine::Ref().FpsLimit)
|
|
|
|
{
|
|
|
|
while (currentFrame*1000/elapsedTime > ui::Engine::Ref().FpsLimit)
|
|
|
|
{
|
|
|
|
SDL_Delay(1);
|
|
|
|
currentTime = SDL_GetTicks();
|
|
|
|
elapsedTime = currentTime-lastTime;
|
|
|
|
}
|
|
|
|
}
|
2012-01-14 12:51:24 -06:00
|
|
|
if(elapsedTime>=1000)
|
|
|
|
{
|
|
|
|
fps = (((float)currentFrame)/((float)elapsedTime))*1000.0f;
|
|
|
|
currentFrame = 0;
|
|
|
|
lastTime = currentTime;
|
|
|
|
delta = 60.0f/fps;
|
|
|
|
}
|
2012-01-08 11:39:03 -06:00
|
|
|
}
|
|
|
|
}
|