[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3506 - trunk/pingus/src
From: |
plouj at BerliOS |
Subject: |
[Pingus-CVS] r3506 - trunk/pingus/src |
Date: |
Sun, 11 Nov 2007 05:07:55 +0100 |
Author: plouj
Date: 2007-11-11 05:07:54 +0100 (Sun, 11 Nov 2007)
New Revision: 3506
Modified:
trunk/pingus/src/game_session.cpp
trunk/pingus/src/game_session.hpp
Log:
decoupled constant world updates from framerate regulation (and temporarily
removed rate regulation)
Modified: trunk/pingus/src/game_session.cpp
===================================================================
--- trunk/pingus/src/game_session.cpp 2007-11-09 10:57:45 UTC (rev 3505)
+++ trunk/pingus/src/game_session.cpp 2007-11-11 04:07:54 UTC (rev 3506)
@@ -51,6 +51,9 @@
number_of_redraws = 0;
number_of_updates = 0;
+ // the world is initially on time
+ world_delay = 0;
+
left_over_time = 0;
pout(PINGUS_DEBUG_LOADING) << "PingusGameSession" << std::endl;
}
@@ -131,15 +134,12 @@
}
// how long did the previous frame processing take (ignoring idle delay)
- int time_passed = int(delta.get_time() * 1000) + left_over_time;
- // how long we want each world update to take
+ int time_passed = int(delta.get_time() * 1000) + world_delay;
+ // how much time each world update represents
int update_time = game_speed;
- left_over_time = 0;
-
- // update the world (and the objects in it) in constant steps to account
- // for the time the previous frame took
- {
+ //left_over_time = 0;
+ if (0){
int i;
for (i = 0;
((i * update_time < time_passed)
@@ -151,16 +151,26 @@
server->update ();
++number_of_updates;
}
+ }
- // Time that got not used for updates
- left_over_time = time_passed - (i * update_time);
+ // update the world (and the objects in it) in constant steps to account
+ // for the time the previous frame took
+
+ // invariant: world_updates - the number of times the world
+ // has been updated during this frame
+ int world_updates = 0;
+
+ while ((world_updates+1)*update_time <= time_passed) {
+ server->update ();
+ ++number_of_updates;
+ world_updates++;
}
+ // save how far behind is the world compared to the actual time
+ // so that we can account for that while updating in the next frame
+ world_delay = time_passed - (world_updates*update_time);
- if (left_over_time < 0 && time_passed < update_time)
- {
- // FIXME: This doesn't really belong here
- SDL_Delay(-left_over_time);
- }
+ // Time that got not used for updates
+ //left_over_time = time_passed - (i * update_time);
// Client is independend of the update limit, well, not completly...
client->update(delta);
Modified: trunk/pingus/src/game_session.hpp
===================================================================
--- trunk/pingus/src/game_session.hpp 2007-11-09 10:57:45 UTC (rev 3505)
+++ trunk/pingus/src/game_session.hpp 2007-11-11 04:07:54 UTC (rev 3506)
@@ -50,6 +50,8 @@
update() */
int left_over_time;
+ int world_delay; ///< how many milliseconds is the world behind the actual
time
+
/** Number of updates */
unsigned int number_of_updates;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3506 - trunk/pingus/src,
plouj at BerliOS <=