diff options
Diffstat (limited to 'src/client/application.cc')
-rw-r--r-- | src/client/application.cc | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/src/client/application.cc b/src/client/application.cc index 5822600..b7505a1 100644 --- a/src/client/application.cc +++ b/src/client/application.cc @@ -1,7 +1,7 @@ /* client/application.cc - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 */ // project headers @@ -15,7 +15,8 @@ // C++ headers #include <cmath> -namespace client { +namespace client +{ extern "C" void func_con_toggle(std::stringstream &args) { @@ -33,16 +34,16 @@ void Application::init() // initialize core core::ApplicationInterface::init(); - con_debug << "Initializing client..." << std::endl; + con_print << "Initializing client..." << std::endl; // Initialize the video subsystem video.init(); if (!video.initialized) { - quit(1); - } + quit(1); + } - // initialize input - input.init(); + // initialize input + input.init(); // register our engine functions core::func_register("con_toggle", func_con_toggle); @@ -52,41 +53,46 @@ void Application::run() { Uint32 chrono = SDL_GetTicks(); - while(true) { - Uint32 current = SDL_GetTicks(); - - // overflow protection ~49 days - if (current < chrono) { - chrono = current; - } + while (true) { + Uint32 current = SDL_GetTicks(); - // update the game chronometers - float elapsed = (float) ( current - chrono) / 1000.0f; - chrono = current; + // overflow protection ~49 days + if (current < chrono) { + chrono = current; + } - core::ApplicationInterface::frame(elapsed); + // update the core chronometer + float seconds = ((float)(current - chrono)) / 1000.0f; + frame(seconds); + + // update the video chronometers and draw + video.frame(seconds); + if (seconds > 0) + current_fps = floorf(1/seconds); + else + current_fps = 9999; - // update the video chronometers and draw - video.draw(elapsed); + // process input + input.frame(); - // process input - input.process(); - } + // update the main loop chronometer + chrono = current; + } } -void Application::shutdown() +void Application::shutdown() { con_debug << "Shutting down client..." << std::endl; console.flush(); input.shutdown(); console.flush(); - + video.shutdown(); console.flush(); - core::ApplicationInterface::shutdown(); + core::ApplicationInterface::shutdown(); console.flush(); quit(0); |