From 8e6fc9eb9ad708512049a7ac79d790c08331b59e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sat, 17 Jun 2017 20:31:46 -0400 Subject: [PATCH] gamnit: pass the elapsed time in the world of each sprite set to the shader MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/gamnit/flat.nit | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/gamnit/flat.nit b/lib/gamnit/flat.nit index b278029..b70d010 100644 --- a/lib/gamnit/flat.nit +++ b/lib/gamnit/flat.nit @@ -393,6 +393,7 @@ redef class App perf_clock_main.lapse var dt = clock.lapse.to_f update dt + frame_dt = dt sys.perfs["gamnit flat update client"].add perf_clock_main.lapse # Draw and flip screen @@ -404,6 +405,8 @@ redef class App assert gl_error == gl_NO_ERROR else print_error gl_error end + private var frame_dt = 0.0 + # Draw the whole screen, all `glDraw...` calls should be executed here protected fun frame_core_draw(display: GamnitDisplay) do @@ -425,6 +428,9 @@ redef class App simple_2d_program.use simple_2d_program.mvp.uniform camera.mvp_matrix + sprite_set.time += frame_dt*sprite_set.time_mod + simple_2d_program.time.uniform sprite_set.time + # draw sprite_set.draw end @@ -507,6 +513,9 @@ private class Simple2dProgram // Model view projection matrix uniform mat4 mvp; + // Current world time, in seconds + uniform float time; + // Rotation matrix attribute vec4 rotation_row0; attribute vec4 rotation_row1; @@ -675,6 +684,12 @@ private class SpriteSet # Sprites needing resorting in `contexts_map` var sprites_to_remap = new Array[Sprite] + # Animation speed multiplier (0.0 to pause, 1.0 for normal speed, etc.) + var time_mod = 1.0 is writable + + # Seconds elapsed since the launch of the program, in world time responding to `time_mod` + var time = 0.0 + # Add a sprite to the appropriate context fun map_sprite(sprite: Sprite) do -- 1.7.9.5