performance wins!
[carveJwlIkooP6JGAAIwe30JlM.git] / audio.h
diff --git a/audio.h b/audio.h
index 097093350608dd972b38e31e7178cd814b4a9f83..5e29a96c08fc6503981dc104f07b4e433e1933db 100644 (file)
--- a/audio.h
+++ b/audio.h
@@ -9,11 +9,6 @@
 
 #include "world.h"
 
-VG_STATIC float audio_occlusion_current = 0.0f,
-             k_audio_occlusion_rate  = 1.0f;
-
-VG_STATIC int k_audio_debug_soundscape = 0;
-
 audio_clip audio_board[] =
 {
    { .path="sound/skate_hpf.ogg" },
@@ -131,9 +126,20 @@ audio_clip audio_rewind[] = {
 audio_clip audio_ui[] = {
    { .path = "sound/ui_click.ogg" },
    { .path = "sound/ui_ding.ogg" },
+   { .path = "sound/teleport.ogg" }
+};
+
+audio_clip audio_challenge[] = {
+   { .path = "sound/objective0.ogg" },
+   { .path = "sound/objective1.ogg" },
+   { .path = "sound/objective_win.ogg" },
+   { .path = "sound/ui_good.ogg" },
+   { .path = "sound/ui_inf.ogg" },
+   { .path = "sound/ui_ok.ogg" },
+   { .path = "sound/objective_fail.ogg" }
 };
 
-VG_STATIC void audio_init(void)
+static void audio_init(void)
 {
    audio_clip_loadn( audio_board, vg_list_size(audio_board), NULL );
    audio_clip_loadn( audio_taps, vg_list_size(audio_taps), NULL );
@@ -155,22 +161,7 @@ VG_STATIC void audio_init(void)
                      vg_list_size(audio_footsteps_wood), NULL );
    audio_clip_loadn( audio_rewind, vg_list_size(audio_rewind), NULL );
    audio_clip_loadn( audio_ui, vg_list_size(audio_ui), NULL );
-
-   vg_var_push( (struct vg_var){
-      .name = "aud_debug_soundscape",
-      .data = &k_audio_debug_soundscape,
-      .data_type = k_var_dtype_i32,
-      .opt_i32 = { .min=0, .max=1, .clamp=0 },
-      .persistent = 1
-   });
-
-   vg_var_push( (struct vg_var){
-      .name = "aud_occlusion_rate",
-      .data = &k_audio_occlusion_rate,
-      .data_type = k_var_dtype_f32,
-      .opt_f32 = { .clamp = 0 },
-      .persistent = 1
-   });
+   audio_clip_loadn( audio_challenge, vg_list_size(audio_challenge), NULL );
 
    audio_lock();
    audio_set_lfo_wave( 0, k_lfo_polynomial_bipolar, 80.0f );
@@ -178,7 +169,7 @@ VG_STATIC void audio_init(void)
    audio_unlock();
 }
 
-VG_STATIC void audio_free(void)
+static void audio_free(void)
 {
    /* TODO! */
    vg_warn( "UNIMPLEMENTED: audio_free()\n" );
@@ -191,61 +182,15 @@ enum audio_sprite_type
    k_audio_sprite_type_water
 };
 
-/*
- * Trace out a random point, near the player to try and determine water areas
- */
-VG_STATIC enum audio_sprite_type audio_sample_sprite_random( v3f origin, 
-                                                             v3f output )
-{
-   v3f chance = { (vg_randf()-0.5f) * 30.0f, 
-                  8.0f,
-                  (vg_randf()-0.5f) * 30.0f };
-   
-   v3f pos;
-   v3_add( chance, origin, pos );
-
-   ray_hit contact;
-   contact.dist = vg_minf( 16.0f, pos[1] );
-
-   world_instance *world = get_active_world();
-   
-   if( ray_world( world, pos, (v3f){0.0f,-1.0f,0.0f}, &contact ) ){
-      struct world_surface *mat = ray_hit_surface( world, &contact );
-
-      if( mat->info.surface_prop == k_surface_prop_grass){
-         v3_copy( contact.pos, output );
-         return k_audio_sprite_type_grass;
-      }
-      else{
-#if 0
-         vg_line( pos, contact.pos, 0xff0000ff );
-         vg_line_pt3( contact.pos, 0.3f, 0xff0000ff );
-#endif
-         return k_audio_sprite_type_none;
-      }
-   }
-
-   output[0] = pos[0];
-   output[1] = 0.0f;
-   output[2] = pos[2];
-
-   float dist = fabsf(output[1] - origin[1]);
-   
-   if( world->water.enabled && dist<=40.0f )
-      return k_audio_sprite_type_water;
-   else
-      return k_audio_sprite_type_none;
-}
-
-VG_STATIC void audio_ambient_sprite_play( v3f co, audio_clip *clip )
+static void audio_ambient_sprite_play( v3f co, audio_clip *clip )
 {
    audio_lock();
-   u32 channel_id = 31342352;
-   audio_channel *ch = audio_get_group_idle_channel( channel_id, 4 );
+   u16 group_id = 0xfff0;
+   audio_channel *ch = audio_get_group_idle_channel( group_id, 4 );
 
    if( ch ){
       audio_channel_init( ch, clip, AUDIO_FLAG_SPACIAL_3D );
-      audio_channel_group( ch, channel_id );
+      audio_channel_group( ch, group_id );
       audio_channel_set_spacial( ch, co, 80.0f );
       audio_channel_edit_volume( ch, 1.0f, 1 );
       ch = audio_relinquish_channel( ch );
@@ -253,10 +198,12 @@ VG_STATIC void audio_ambient_sprite_play( v3f co, audio_clip *clip )
    audio_unlock();
 }
 
-VG_STATIC void audio_ambient_sprites_update( world_instance *world, v3f co )
+static
+enum audio_sprite_type world_audio_sample_sprite_random(v3f origin, v3f output);
+static void audio_ambient_sprites_update( world_instance *world, v3f co )
 {
    static float accum = 0.0f;
-   accum += vg.frame_delta;
+   accum += vg.time_delta;
 
    if( accum > 0.1f )
       accum -= 0.1f;
@@ -264,15 +211,17 @@ VG_STATIC void audio_ambient_sprites_update( world_instance *world, v3f co )
 
    v3f sprite_pos;
    enum audio_sprite_type sprite_type = 
-      audio_sample_sprite_random( co, sprite_pos );
+      world_audio_sample_sprite_random( co, sprite_pos );
    
    if( sprite_type != k_audio_sprite_type_none ){
       if( sprite_type == k_audio_sprite_type_grass ){
-         audio_ambient_sprite_play( sprite_pos, &audio_grass[rand()%4] );
+         audio_ambient_sprite_play( sprite_pos, &audio_grass[vg_randu32()%4] );
       }
       else if( sprite_type == k_audio_sprite_type_water ){
-         if( world->water.enabled )
-            audio_ambient_sprite_play( sprite_pos, &audio_water[rand()%6] );
+         if( world->water.enabled ){
+            audio_ambient_sprite_play( sprite_pos, 
+                                       &audio_water[vg_randu32()%6] );
+         }
       }
    }
 }