00001 #include "XClone.h" 00002 #include "MainGameState.h" 00003 #include "ConfigOptions.h" 00004 #include "Display.h" 00005 #include "Input.h" 00006 00007 XClone::XClone() : 00008 Application(), 00009 configFile("config.ini") 00010 { 00011 00012 } 00013 00014 XClone::~XClone() 00015 { 00016 00017 } 00018 00019 void XClone::init() 00020 { 00021 ConfigOptions& co = ConfigOptions::instance(); 00022 co.init(); 00023 co.load(configFile); 00024 00025 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) 00026 { 00027 cerr << "Could not initialize SDL: " << SDL_GetError() << endl; 00028 exit(1); 00029 } 00030 atexit(SDL_Quit); 00031 00032 if (TTF_Init() != 0) 00033 { 00034 cerr << "Could not initialize SDL TrueTypeFonts" << TTF_GetError() << endl; 00035 } 00036 00037 Display& d = Display::instance(); 00038 d.init(); 00039 //d.loadFont(co.get<string>(FONT)); 00040 d.loadFont("FreeMono.ttf"); 00041 00042 GameState* gs = new MainGameState(this); 00043 gs->init(); 00044 00045 changeState(gs); 00046 } 00047 00048 void XClone::deinit() 00049 { 00050 popAllStates(); 00051 ConfigOptions::instance().deinit(); 00052 } 00053 00054 void XClone::update() 00055 { 00056 unsigned int currentTime = SDL_GetTicks(); 00057 deltaTime = currentTime - lastUpdateTime; 00058 lastUpdateTime = currentTime; 00059 00060 SDL_Event event; 00061 while(SDL_PollEvent(&event)) 00062 { 00063 Input::instance().processSDLEvent(event); 00064 /* 00065 switch(event.type) 00066 { 00067 case SDL_QUIT: 00068 quit(); 00069 return; 00070 case SDL_MOUSEMOTION: 00071 case SDL_MOUSEBUTTONDOWN: 00072 case SDL_MOUSEBUTTONUP: 00073 case SDL_KEYDOWN: 00074 case SDL_KEYUP: 00075 Input::instance().processSDLEvent(event); 00076 break; 00077 default: 00078 break; 00079 } 00080 */ 00081 } 00082 00083 getCurrentGameState()->update(deltaTime); 00084 Display::instance().render(); 00085 } 00086 00087 void XClone::processSDLEvent(SDL_Event& event) { 00088 getCurrentGameState()->processSDLEvent(event); 00089 }