From cdd75000effac0216588766234cfa5b3e8e304d5 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Wed, 8 Nov 2017 12:26:43 +0100 Subject: Frametime-independent dynamics. --- src/common.hpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/common.hpp') diff --git a/src/common.hpp b/src/common.hpp index f89ae08..df14f6f 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -175,7 +175,7 @@ namespace game { class unit_t; class state_t { - double now; + double now, dt; std::unordered_set units; std::unordered_set selected_units; @@ -185,7 +185,7 @@ namespace game { void start(void); void stop(void); - void tick(double now_); + void tick(double now_, double dt_); // These are called by the interface. void select(rectf_t rect); @@ -213,7 +213,7 @@ namespace interface { public: state_t(sf::RenderWindow *window_, game::state_t *game); - void tick(void); + void tick(double dt); void render_to(render::state_t *render); }; } @@ -264,10 +264,10 @@ namespace render { void drender_text(rectf_t rect, std::string str); void drender_entity(world::entity_t *ent); public: - double now; + double now, dt; state_t(sf::RenderWindow *window_); - void begin_frame(double time_); + void begin_frame(double time_, double dt_); void end_frame(void); void render(game::state_t *game); void render(animated_texture_t *anim, rectf_t bounds, bool mirror = false); @@ -333,3 +333,8 @@ T bilerp(T a, T b, T c, T d, T x, T y) cd = lerp(c, d, x); return lerp(ab, cd, y); } + +static inline float expfade(float a, float b, float l, float dt) +{ + return b + (a - b) * exp(-l * dt); +} -- cgit