jdidjjjjjjjjjjjjjjjjjjjjjj
authorhgn <hgodden00@gmail.com>
Sat, 22 Oct 2022 02:49:05 +0000 (03:49 +0100)
committerhgn <hgodden00@gmail.com>
Sat, 22 Oct 2022 02:49:05 +0000 (03:49 +0100)
src/vg/vg.h
src/vg/vg_audio.h
src/vg/vg_m.h

index e125f26a3c4111c3fa6c10c23f4d15ee2a5bee71..299c9b0112d1e5a83510e7d32d4c3b3fe6df3868 100644 (file)
@@ -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 )
          {
index a1d863e68baca746983656c9a0d23f8d50aa1203..97709806df90ee1baac4db69fea3aa7bc9598d70 100644 (file)
@@ -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)
index 03f197f94b18003b731430a6ac2228ce38eb2b62..0736752364113b85a711349926d3df5208e22f2a 100644 (file)
@@ -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 );
 }