Back to index

extremetuxracer  0.5beta
bench.cpp
Go to the documentation of this file.
00001 /* 
00002  * PPRacer 
00003  * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
00004  * 
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019  
00020 #include "bench.h"
00021 
00022 #include "game_mgr.h"
00023 
00024 Benchmark::mode_t Benchmark::sm_mode = Benchmark::NONE;
00025 
00026 std::string Benchmark::sm_course;
00027 double Benchmark::sm_frames=0.0;
00028 double Benchmark::sm_oldFrames=0.0;
00029 int Benchmark::sm_framesCounter=0;
00030 int Benchmark::sm_maxFrames=0;
00031 int Benchmark::sm_fc=0;
00032 pp::Vec2d Benchmark::sm_pos;
00033 double Benchmark::sm_timeStep=-1;
00034 race_conditions_t Benchmark::sm_condition=RACE_CONDITIONS_SUNNY;
00035        
00036 Benchmark::Benchmark()
00037 {
00038        
00039        
00040 }
00041 
00042 Benchmark::~Benchmark()
00043 {
00044               
00045        
00046 }
00047 
00048 void
00049 Benchmark::loop(float timeStep)
00050 {
00051        static std::list<CourseData>::iterator it;
00052        
00053        it = openCourseList.begin();
00054 
00055        for (it=openCourseList.begin(); 
00056               it != openCourseList.end();
00057               it++)
00058        {
00059               if((*it).course == sm_course) break;                    
00060        }
00061        
00062        if( it != openCourseList.end() ){
00063               gameMgr->setCurrentRace(it);
00064               gameMgr->getCurrentRace().condition = sm_condition;
00065        }else{
00066               std::cout << "Benchmark error: unable to set course: " 
00067                                    << sm_course << std::endl;
00068               exit(0);
00069        }
00070        
00071        set_game_mode( LOADING );
00072 }
00073 
00074 void
00075 Benchmark::setCourse(const char* course)
00076 {
00077        sm_course = course;  
00078        if(sm_mode == Benchmark::NONE){
00079               sm_mode = Benchmark::DEMO;
00080        }
00081 }
00082 
00083 void
00084 Benchmark::setMaxFrames(int frames)
00085 {
00086        sm_maxFrames = frames;
00087 }
00088 
00089 void
00090 Benchmark::setPosition(pp::Vec2d &position)
00091 {
00092        sm_pos = position;
00093 }
00094 
00095 pp::Vec2d&
00096 Benchmark::getPosition()
00097 {
00098        return sm_pos;
00099 }
00100 
00101 void
00102 Benchmark::setMode(Benchmark::mode_t mode)
00103 {
00104        sm_mode = mode;
00105 }
00106 
00107 Benchmark::mode_t
00108 Benchmark::getMode()
00109 {
00110        return sm_mode;
00111 }
00112 
00113 void
00114 Benchmark::setTimeStep(double timeStep)
00115 {
00116        sm_timeStep = timeStep;
00117 }
00118 
00119 double
00120 Benchmark::getTimeStep()
00121 {
00122        return sm_timeStep;
00123 }
00124 
00125 void
00126 Benchmark::setRaceCondition(int condition)
00127 {
00128        if (condition > 0 && 
00129               condition < RACE_CONDITIONS_NUM_CONDITIONS)
00130        {
00131               sm_condition = (race_conditions_t) condition;
00132        }
00133 }
00134 
00135 void
00136 Benchmark::updateFPS(double fps)
00137 {
00138        sm_frames+=fps;
00139        sm_framesCounter++;
00140        
00141        if(sm_fc>=2){
00142               sm_fc=0;
00143               std::cout << "FPS: "<< (sm_frames-sm_oldFrames)/3 << std::endl;
00144               sm_oldFrames = sm_frames;          
00145        }else{
00146               sm_fc++;
00147        }
00148               
00149        if( sm_maxFrames > 0 && sm_frames >= sm_maxFrames ){
00150               set_game_mode(GAME_OVER);          
00151        }
00152 }
00153 
00154 void
00155 Benchmark::displayState()
00156 {
00157        std::cout << std::endl;
00158        std::cout << "Frames: "
00159                      << sm_frames << std::endl;
00160        
00161        std::cout << "Average FPS: "
00162                      << sm_frames/sm_framesCounter << std::endl;
00163 }