From: hgn Date: Sat, 22 Oct 2022 02:49:05 +0000 (+0100) Subject: jdidjjjjjjjjjjjjjjjjjjjjjj X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=commitdiff_plain;h=a83978cdbdf393dc37362bff71d828b9b00c6879 jdidjjjjjjjjjjjjjjjjjjjjjj --- diff --git a/src/vg/vg.h b/src/vg/vg.h index e125f26..299c9b0 100644 --- a/src/vg/vg.h +++ b/src/vg/vg.h @@ -75,8 +75,11 @@ struct vg /* Runtime */ double time, - time_last, time_delta, + frame_delta, + time_real, + time_real_last, + time_rate, accumulator; int fixed_iterations; @@ -100,7 +103,7 @@ struct vg const char *gamepad_name; int gamepad_id; } -static vg; +static vg = { .time_rate = 1.0 }; struct vg_thread_info { @@ -503,14 +506,20 @@ static void vg_enter( int argc, char *argv[], const char *window_name ) v2_copy( (v2f){ 0.0f, 0.0f }, vg.mouse_wheel ); glfwPollEvents(); - vg.time_last = vg.time; - vg.time = glfwGetTime(); - vg.time_delta = vg.time-vg.time_last; + vg.time_real_last = vg.time_real; + vg.time_real = glfwGetTime(); + vg.frame_delta = vg.time_real-vg.time_real_last; + + /* scaled time */ + vg.time_delta = vg.frame_delta * vg.time_rate; + vg.time += vg.time_delta; if( vg.is_loaded ) { +#if 0 glClearColor( 0.0f,sinf(vg.time*20.0)*0.5f+0.5f,0.0f,1.0f ); glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); +#endif if( !loaded ) { diff --git a/src/vg/vg_audio.h b/src/vg/vg_audio.h index a1d863e..9770980 100644 --- a/src/vg/vg_audio.h +++ b/src/vg/vg_audio.h @@ -48,6 +48,7 @@ #define AUDIO_FLAG_LOOP 0x1 #define AUDIO_FLAG_ONESHOT 0x2 #define AUDIO_FLAG_SPACIAL_3D 0x4 +#define AUDIO_FLAG_AUTO_START 0x8 #define FADEOUT_LENGTH 1100 #define FADEOUT_DIVISOR (1.0f/(float)FADEOUT_LENGTH) diff --git a/src/vg/vg_m.h b/src/vg/vg_m.h index 03f197f..0736752 100644 --- a/src/vg/vg_m.h +++ b/src/vg/vg_m.h @@ -298,6 +298,19 @@ static inline float vg_lerpf( float a, float b, float t ) return a + t*(b-a); } +static inline double vg_lerp( double a, double b, double t ) +{ + return a + t*(b-a); +} + +/* correctly lerp around circular period -pi -> pi */ +static float vg_alerpf( float a, float b, float t ) +{ + float d = fmodf( b-a, VG_TAUf ), + s = fmodf( 2.0f*d, VG_TAUf ) - d; + return a + s*t; +} + static inline void v3_lerp( v3f a, v3f b, float t, v3f d ) { d[0] = a[0] + t*(b[0]-a[0]); @@ -1209,7 +1222,14 @@ static inline void q_inv( v4f q, v4f d ) static inline void q_nlerp( v4f a, v4f b, float t, v4f d ) { - v4_lerp( a, b, t, d ); + if( v4_dot(a,b) < 0.0f ) + { + v4_muls( b, -1.0f, d ); + v4_lerp( a, d, t, d ); + } + else + v4_lerp( a, b, t, d ); + q_normalize( d ); }