diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-11-08 12:26:43 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-11-08 12:26:43 +0100 |
commit | cdd75000effac0216588766234cfa5b3e8e304d5 (patch) | |
tree | 3832063bf12dae9e8b29c9e787d08dc75a9ba704 /src/common.hpp | |
parent | c5a621b3ebeb180d2181df35038ed856714b64e2 (diff) |
Frametime-independent dynamics.
Diffstat (limited to 'src/common.hpp')
-rw-r--r-- | src/common.hpp | 15 |
1 files changed, 10 insertions, 5 deletions
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<unit_t*> units; std::unordered_set<unit_t*> 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); +} |