[Super-tux-commit] supertux/lib/special frame_rate.cpp,NONE,1.1 frame_rate.h,NONE,1.1 timer.h,1.4,1.
Brought to you by:
wkendrick
From: Tobias G. <to...@us...> - 2004-07-28 23:06:20
|
Update of /cvsroot/super-tux/supertux/lib/special In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18640/lib/special Modified Files: timer.h Added Files: frame_rate.cpp frame_rate.h Log Message: - Various fixes and cleanups. - Added FrameRate class to SuperTux library - More menu code C++ing. Index: timer.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/timer.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- timer.h 27 Jul 2004 13:25:05 -0000 1.4 +++ timer.h 28 Jul 2004 23:06:12 -0000 1.5 @@ -21,6 +21,8 @@ #ifndef SUPERTUX_TIMER_H #define SUPERTUX_TIMER_H +#include <cstdlib> + namespace SuperTux { --- NEW FILE: frame_rate.cpp --- // // SuperTux // Copyright (C) 2004 Tobias Glaesser <tob...@gm...> // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "SDL.h" #include "../special/frame_rate.h" #include "../special/timer.h" using namespace SuperTux; FrameRate::FrameRate(double fps) { set_fps(fps); } void FrameRate::start() { update_time = last_update_time = Ticks::get(); } void FrameRate::set_fps(double fps) { frame_ms = static_cast<unsigned int>(1000.f/fps); } double FrameRate::get() { return ((double)(update_time-last_update_time))/(double)frame_ms; } void FrameRate::update() { /* Set the time of the last update and the time of the current update */ last_update_time = update_time; update_time = Ticks::get(); /* Pause till next frame, if the machine running the game is too fast: */ /* FIXME: Works great for in OpenGl mode, where the CPU doesn't have to do that much. But the results in SDL mode aren't perfect (thought the 100 FPS are reached), even on an AMD2500+. */ if(last_update_time >= update_time - (frame_ms+2)) { SDL_Delay(frame_ms); update_time = Ticks::get(); } } --- NEW FILE: frame_rate.h --- // // SuperTux // Copyright (C) 2004 Tobias Glaesser <tob...@gm...> // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef SUPERTUX_FRAMERATE_H #define SUPERTUX_FRAMERATE_H namespace SuperTux { class FrameRate { public: FrameRate() {}; FrameRate(double fps); void start(); void set_fps(double fps); double get(); void update(); private: unsigned int last_update_time; unsigned int update_time; unsigned int frame_ms; }; } //namespace SuperTux #endif /*SUPERTUX_FRAMERATE_H*/ |