summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Michelotti <michelotti.matthew@gmail.com>2018-06-01 20:10:35 -0500
committerMatthew Michelotti <michelotti.matthew@gmail.com>2018-06-01 20:10:35 -0500
commit78e2ef70ba2213ea7e4ac407f99a14e52d15af2f (patch)
tree331c66d102363a90768fb442c2c4487081ee347e
parent69d101be10c9d590bb9f74a458bb8be0ed072085 (diff)
capping timestep at 15 FPS
-rw-r--r--gate/src/app_info.rs2
-rw-r--r--gate/src/core/sdl/mod.rs2
-rw-r--r--gate/src/core/wasm/mod.rs2
-rw-r--r--gate/src/lib.rs2
4 files changed, 5 insertions, 3 deletions
diff --git a/gate/src/app_info.rs b/gate/src/app_info.rs
index 90dc1e7..80364a0 100644
--- a/gate/src/app_info.rs
+++ b/gate/src/app_info.rs
@@ -103,7 +103,7 @@ impl AppInfo {
/// Specifies the target frames-per-second (default is `60.`).
pub fn target_fps(mut self, target_fps: f64) -> Self {
- assert!(target_fps > 10. && target_fps < 200., "unrealistic target_fps: {}", target_fps);
+ assert!(target_fps >= 20. && target_fps < 200., "unrealistic target_fps: {}", target_fps);
self.target_fps = target_fps;
self
}
diff --git a/gate/src/core/sdl/mod.rs b/gate/src/core/sdl/mod.rs
index e4006c1..4072096 100644
--- a/gate/src/core/sdl/mod.rs
+++ b/gate/src/core/sdl/mod.rs
@@ -100,7 +100,7 @@ pub fn run<AS: AppAssetId, AP: App<AS>>(info: AppInfo, mut app: AP) {
event_handler.process_events(&mut app, &mut ctx, &renderer);
if ctx.close_requested() { break; }
- app.advance(elapsed, &mut ctx);
+ app.advance(elapsed.min(::MAX_TIMESTEP), &mut ctx);
if ctx.close_requested() { break; }
}
}
diff --git a/gate/src/core/wasm/mod.rs b/gate/src/core/wasm/mod.rs
index ccdce54..541f920 100644
--- a/gate/src/core/wasm/mod.rs
+++ b/gate/src/core/wasm/mod.rs
@@ -121,7 +121,7 @@ impl<AS: AppAssetId, AP: App<AS>> TraitAppRunner for AppRunner<AS, AP> {
fn update_and_draw(&mut self, time_sec: f64) {
let elapsed = self.last_time_sec.map(|x| time_sec - x).unwrap_or(0.0).max(0.0).min(0.1);
if elapsed > 0.0 {
- self.app.advance(elapsed, &mut self.ctx);
+ self.app.advance(elapsed.min(::MAX_TIMESTEP), &mut self.ctx);
}
self.last_time_sec = Some(time_sec);
diff --git a/gate/src/lib.rs b/gate/src/lib.rs
index 72b4e40..bbbd375 100644
--- a/gate/src/lib.rs
+++ b/gate/src/lib.rs
@@ -73,6 +73,8 @@ pub use app_info::AppInfo;
use asset_id::AppAssetId;
use renderer::Renderer;
+const MAX_TIMESTEP: f64 = 1. / 15.;
+
/// Invoke this in a `main` method to run the `App`.
///
/// Will panic if this method is called more than once.