00001 #include <SDL/SDL.h> 00002 #include <iostream> 00003 #include <string> 00004 00005 #include "application.h" 00006 #include "graphics.h" 00007 #include "util.h" 00008 #include "sound.h" 00009 #include "input.h" 00010 #include "nncmath.h" 00011 #include "game.h" 00012 00013 // Constructor 00014 Application::Application(string title, int w, int h) 00015 : GD(title, w, h) 00016 { 00017 GD.hideMouse(true); 00018 //GD.lockMouse(true); 00019 NNCMath::MathInit(); 00020 00021 init(); 00022 } 00023 00024 Application::~Application() 00025 { 00026 close(); 00027 } 00028 00029 // This should read in some data. CM 00030 int Application::init() 00031 { 00032 frame_count = 0; 00033 00034 CurrentGame = new Game(GD, ID, SD); 00035 00036 return 0; 00037 } 00038 00039 // Free the data from init 00040 int Application::close() 00041 { 00042 delete CurrentGame; 00043 00044 return 0; 00045 } 00046 00047 int Application::Run() 00048 { 00049 nnctime et, st = Util_GetTime(); 00050 00051 // Infinite loop until exit = true. CM 00052 do { 00053 SDL_Event e; 00054 bool exit = false; 00055 00056 while (SDL_PollEvent (&e)) { 00057 if(ID.Update(e)) continue; 00058 00059 // Input didn't handle the message, we must. 00060 if(e.type == SDL_QUIT) { 00061 exit = true; 00062 break; 00063 } 00064 } 00065 00066 if(ID.IsPressed(Input::FAST_QUIT) || exit) 00067 break; 00068 00069 frame_count++; 00070 } while (CurrentGame->step() == false); 00071 00072 // Calculate FPS 00073 et = Util_DiffTime(&st, NULL); 00074 00075 double secs = et.secs + et.msecs / 1000.0; 00076 double fps = (double)frame_count / (secs); 00077 00078 cout << "Frames Per Second: " << fps << endl; 00079 00080 return 0; 00081 } 00082