OpenVideo Documentation

   Main Page       Modules       Class Hierarchy       Alphabetical List       Compound List       File List       Compound Members       Related Pages   

game.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // PocketHAL
00004 // Copyright 2004 by Thierry Tremblay
00005 //
00007 
00008 #include "game.h"
00009 
00010 
00011 
00012 namespace PHAL
00013 {
00014 
00016 //
00017 // Game
00018 //
00020 
00021 Game::Game()
00022 :   m_display( 0 )
00023 {
00024 }
00025 
00026 
00027 
00028 Game::~Game()
00029 {
00030     delete m_display;
00031 }
00032 
00033 
00034 
00035 bool Game::Initialize()
00036 {
00037     m_bShutdown = false;
00038 
00039     if (!GameBase::Initialize( m_config ))
00040         return false;
00041 
00042     DisplayParameters params( m_config.m_orientation );
00043     
00044     m_display = Display::Create( GameBase::GetWindow(), params );
00045     if (!m_display)
00046         return false;
00047 
00048     m_lastInactivityReset = GetClock();
00049 
00050     return true;
00051 }
00052 
00053 
00054 
00055 bool Game::Run()
00056 {
00057     if (!Initialize())
00058         return false;
00059 
00060     if (!OnInitialize())
00061         return false;
00062 
00063     return GameBase::Run();
00064 }
00065 
00066 
00067 
00068 void Game::Shutdown()
00069 {
00070     m_bShutdown = true;
00071 }
00072 
00073 
00074 
00075 void Game::BuildFPSString( int fps )
00076 {
00077     if (fps > 99999)
00078         fps = 99999;
00079 
00080     int i0 = fps / 10000; fps -= i0 * 10000;
00081     int i1 = fps / 1000; fps -= i1 * 1000;
00082     int i2 = fps / 100; fps -= i2 * 100;
00083     int i3 = fps / 10; fps -= i3 * 10;
00084     int i4 = fps;
00085 
00086     m_fpsString[0] = char('0' + i0);
00087     m_fpsString[1] = char('0' + i1);
00088     m_fpsString[2] = char('0' + i2);
00089     m_fpsString[3] = char('.');
00090     m_fpsString[4] = char('0' + i3);
00091     m_fpsString[5] = char('0' + i4);
00092     m_fpsString[6] = char(0);
00093 }
00094 
00095 
00096 
00098 // IGame callbacks
00100    
00101 bool Game::OnInitialize()
00102 {
00103     m_lastFPSTime = GetClock();
00104     m_nbFrames    = 0;
00105     m_fps         = 0;
00106 
00107     BuildFPSString( 0 );
00108 
00109     return true;
00110 }
00111 
00112 
00113 void Game::OnShutdown()
00114 {
00115     delete m_display;
00116     m_display = 0;
00117 }
00118 
00119 
00120 bool Game::OnGameLoop()
00121 {
00122     ++m_nbFrames;
00123 
00124     // Check if it is time to calculate the FPS
00125     uint32_t now   = GetClock();
00126     uint32_t delta = now - m_lastFPSTime;
00127     
00128     if (delta >= 500)
00129     {
00130         // Calculate FPS
00131         m_fps = (m_nbFrames*100000) / delta;
00132 
00133         BuildFPSString( m_fps );
00134 
00135         // Reset vars
00136         m_lastFPSTime = now;
00137         m_nbFrames    = 0;
00138     }
00139 
00140 
00141     // Reset inactivity once in a while
00142     if (now - m_lastInactivityReset >= 5000)
00143     {
00144         m_lastInactivityReset = now;
00145         ResetInactivity();
00146     }
00147 
00148 
00149     return !m_bShutdown;
00150 }
00151 
00152 
00153 void Game::OnSuspend()
00154 {
00155     #if defined(PHAL_PLATFORM_SYMBIAN)
00156     m_display->HandleForegroundEvent( false );
00157     #endif
00158 }
00159 
00160 
00161 void Game::OnResume()
00162 {
00163     #if defined(PHAL_PLATFORM_SYMBIAN)
00164     m_display->HandleForegroundEvent( true );
00165     #endif
00166 
00167     m_lastInactivityReset = GetClock();
00168 }
00169 
00170 
00171 void Game::OnKeyDown( int key )
00172 {
00173     Shutdown();
00174 }
00175 
00176 
00177 void Game::OnKeyUp( int key )
00178 {
00179 }
00180 
00181 
00182 void Game::OnStylusDown( Point p )
00183 {
00184 }
00185 
00186 
00187 void Game::OnStylusMove( Point p )
00188 {
00189 }
00190 
00191 
00192 void Game::OnStylusUp( Point p )
00193 {
00194 }
00195 
00196 
00197 
00198 
00199 } // end of namespace PHAL
 This page was generated at Wed May 31 13:04:16 2006 for OpenVideo by Doxygen.
 If you have any comments, please send a message to schmalstieg@icg.tu-graz.ac.at.
www.studierstube.org