Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-05-06 21:07:11 +0000
committerStijn Buys <ingar@osirion.org>2008-05-06 21:07:11 +0000
commit91d3a0352088611d3b78d3344b7a2bf2d4955a0a (patch)
tree74c0a6adf15ae15aa144f66f20272c1fd58a7db3 /src/core/gameinterface.cc
parent8fefc1d995083f0d4a9873f216ccc6e15688d0a9 (diff)
client-side frame interpolation: frames and timers
Diffstat (limited to 'src/core/gameinterface.cc')
-rw-r--r--src/core/gameinterface.cc48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 5789592..8d351a0 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -91,7 +91,53 @@ void GameInterface::clear()
// remove all models
model::Model::clear();
+
+ game_previousframetime = 0;
+ game_serverframetime = 0;
+ game_clientframetime = 0;
+ game_timestep = 0;
+ game_frames = 0;
}
+void GameInterface::reset_clientstate(float servertime)
+{
+ game_timestep = (servertime - game_serverframetime);
+
+ if (game_timestep < 0)
+ game_timestep = 0;
+
+ game_previousframetime = game_serverframetime;
+ game_serverframetime = servertime;
+ game_clientframetime = game_previousframetime;
+
+ std::map<unsigned int, core::Entity *>::iterator it;
+ for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
+
+ core::Entity *entity = (*it).second;
+
+ if (entity->state() && !(entity->flags() & Entity::Static))
+ entity->state()->assign(entity);
+ }
+
+ game_frames = 0;
+}
-} // namespace core
+void GameInterface::update_clientstate()
+{
+ game_frames++;
+ game_clientframetime += game_timestep;
+
+ if (game_clientframetime > game_serverframetime)
+ game_clientframetime = game_serverframetime;
+}
+
+float GameInterface::timeoffset() {
+ float d = game_serverframetime - game_previousframetime;
+ if (d < 0)
+ d = 1;
+ float t = game_serverframetime - game_clientframetime;
+
+ return t/d;
+}
+
+}