[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3507 - in trunk/pingus/src: . screen
From: |
plouj at BerliOS |
Subject: |
[Pingus-CVS] r3507 - in trunk/pingus/src: . screen |
Date: |
Sun, 11 Nov 2007 05:14:35 +0100 |
Author: plouj
Date: 2007-11-11 05:14:34 +0100 (Sun, 11 Nov 2007)
New Revision: 3507
Modified:
trunk/pingus/src/globals.cpp
trunk/pingus/src/globals.hpp
trunk/pingus/src/pingus_main.cpp
trunk/pingus/src/pingus_options.hpp
trunk/pingus/src/screen/screen_manager.cpp
Log:
added global framerate regulation code
Modified: trunk/pingus/src/globals.cpp
===================================================================
--- trunk/pingus/src/globals.cpp 2007-11-11 04:07:54 UTC (rev 3506)
+++ trunk/pingus/src/globals.cpp 2007-11-11 04:14:34 UTC (rev 3507)
@@ -21,6 +21,7 @@
int game_speed = 20;
+float desired_fps = 40;
bool print_fps = false;
int verbose = 0;
bool music_enabled = true;
Modified: trunk/pingus/src/globals.hpp
===================================================================
--- trunk/pingus/src/globals.hpp 2007-11-11 04:07:54 UTC (rev 3506)
+++ trunk/pingus/src/globals.hpp 2007-11-11 04:14:34 UTC (rev 3507)
@@ -28,6 +28,7 @@
extern int game_speed; ///< -t, --set-speed
+extern float desired_fps; ///< -k, --set-fps
extern bool print_fps; ///< --print-fps
extern int verbose; ///< -v, --verbose
Modified: trunk/pingus/src/pingus_main.cpp
===================================================================
--- trunk/pingus/src/pingus_main.cpp 2007-11-11 04:07:54 UTC (rev 3506)
+++ trunk/pingus/src/pingus_main.cpp 2007-11-11 04:14:34 UTC (rev 3507)
@@ -242,6 +242,9 @@
if (options.speed.is_set())
game_speed = options.speed.get();
+ if (options.desiredfps.is_set())
+ desired_fps = options.desiredfps.get();
+
if (options.tile_size.is_set())
tile_size = options.tile_size.get();
@@ -327,6 +330,8 @@
_("Set both min and max frameskip to N"));
argp.add_option('t', "speed", "SPEED",
_("Set the game speed (0=fastest, >0=slower)"));
+ argp.add_option('k', "fps", "FPS",
+ _("Set the desired game framerate (frames per second)"));
argp.add_option(344, "tile-size", "INT",
_("Set the size of the map tiles (default: 32)"));
argp.add_option(332, "fast-mode", "",
@@ -360,6 +365,10 @@
cmd_options.speed.set(StringUtil::to<int>(argp.get_argument()));
break;
+ case 'k': // -k, --set-fps
+
cmd_options.desiredfps.set(StringUtil::to<float>(argp.get_argument()));
+ break;
+
case 's': // -s, --disable-sound
cmd_options.disable_sound.set(true);
break;
Modified: trunk/pingus/src/pingus_options.hpp
===================================================================
--- trunk/pingus/src/pingus_options.hpp 2007-11-11 04:07:54 UTC (rev 3506)
+++ trunk/pingus/src/pingus_options.hpp 2007-11-11 04:14:34 UTC (rev 3507)
@@ -92,6 +92,7 @@
Value<int> min_frame_skip;
Value<int> max_frame_skip;
Value<int> speed;
+ Value<float> desiredfps;
Value<int> tile_size;
Value<bool> fast_mode;
};
Modified: trunk/pingus/src/screen/screen_manager.cpp
===================================================================
--- trunk/pingus/src/screen/screen_manager.cpp 2007-11-11 04:07:54 UTC (rev
3506)
+++ trunk/pingus/src/screen/screen_manager.cpp 2007-11-11 04:14:34 UTC (rev
3507)
@@ -64,12 +64,15 @@
show_swcursor(swcursor_enabled);
DeltaManager delta_manager;
+ DeltaManager frame_timer;
// Main loop for the menu
while (!screens.empty())
{
// how long the previous frame (iteration) took (if any)
float time_delta = delta_manager.getset();
+ // start the frame timer
+ frame_timer.set();
// previous frame took more than one second
if (time_delta > 1.0)
@@ -139,11 +142,15 @@
else
{
//std::cout << "ScreenManager: fading screens" << std::endl;
+ //FIXME: this shouldn't be done in one iteration of this loop (one
frame)
fade_over(last_screen, get_current_screen());
}
- // Stupid hack to make this thing take less CPU
- SDL_Delay(1);
+ // cap the framerate at the desired value
+ if (frame_timer.get() < 1 / desired_fps) {
+ // idle delay to make the frame take as long as we want it to
+ SDL_Delay(static_cast<Uint32>(1000 *((1 / desired_fps) -
frame_timer.get())));
+ }
}
delete input_controller;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3507 - in trunk/pingus/src: . screen,
plouj at BerliOS <=