frame rate independence
[carveJwlIkooP6JGAAIwe30JlM.git] / player_audio.h
index b5ba7359fc85524c8b02f2c9b4d59d9c87a440db..757f495a1b761e3d94da2bafad365d5828cad33a 100644 (file)
@@ -1,3 +1,7 @@
+/*
+ * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
+ */
+
 #ifndef PLAYER_AUDIO_H
 #define PLAYER_AUDIO_H
 
@@ -10,15 +14,6 @@ static void player_audio(void)
 {
    struct player_phys *phys = &player.phys;
 
-   static int _ding = 0;
-   
-   int last = _ding;
-   _ding = glfwGetKey(vg_window, GLFW_KEY_C);
-
-   int trigger_ding = 0;
-   if( _ding && !last )
-      trigger_ding = 1;
-
    static int _air = 0;
 
    int l2 = _air;
@@ -31,7 +26,7 @@ static void player_audio(void)
 
    audio_lock();
    
-   double revert_delta = vg_time - last_revert;
+   double revert_delta = vg.time - last_revert;
    if( phys->on_board && (!_air && l2) && (fabsf(phys->slip) > 0.5f) && 
          (revert_delta > 0.7) )
    {
@@ -40,11 +35,11 @@ static void player_audio(void)
       audio_player_set_vol( &audio_player_extra, 2.0f );
       audio_player_playclip( &audio_player_extra, &audio_lands[rand()%5] );
 
-      last_revert = vg_time;
+      last_revert = vg.time;
    }
 
    static float air = 0.0f;
-   air = vg_lerpf(air, phys->in_air? 1.0f: 0.0f, 5.0f*ktimestep);
+   air = vg_lerpf(air, phys->in_air? 1.0f: 0.0f, 5.0f*VG_TIMESTEP_FIXED );
 
    /* Spacial info */
    v3f ears = { 1.0f,0.0f,0.0f };
@@ -53,13 +48,11 @@ static void player_audio(void)
    float *cam = player.camera[3],
          *pos = phys->rb.co;
    
-   if( trigger_ding )
-      audio_player_playclip( &audio_player_extra, &audio_ding );
-
    audio_player_set_position( &audio_player0, phys->rb.co );
    audio_player_set_position( &audio_player1, phys->rb.co );
    audio_player_set_position( &audio_player2, phys->rb.co );
    audio_player_set_position( &audio_player_gate, world.render_gate_pos );
+   audio_player_set_vol( &audio_player_gate, 5.0f );
 
    v3_sub( phys->rb.co, player.camera[3], delta );
    v3_normalize( delta );
@@ -112,6 +105,7 @@ static void player_audio(void)
       audio_player_set_vol( &audio_player0, 0.0f );
       audio_player_set_vol( &audio_player1, 0.0f );
       audio_player_set_vol( &audio_player2, 0.0f );
+      audio_player_set_vol( &audio_player3, 0.0f );
 
       int walk_phase = 0;
       if( vg_fractf(player.walk_timer) > 0.5f )