X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_audio.h;h=3071af3097802e2ec7870bf8bb6abdca8806a47f;hb=d13f2700b1773551307685cc7c34c804ccd6d664;hp=01c13fcd7db6bc3f9f01d0b93827b732d6f0cb4d;hpb=2ca677a0ec9d00db46a8b97bec30dbea8280a79b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_audio.h b/player_audio.h index 01c13fc..3071af3 100644 --- a/player_audio.h +++ b/player_audio.h @@ -1,3 +1,12 @@ +/* + * Copyright 2021-2022 (C) Mount0 Software, Harry Godden - All Rights Reserved + * ----------------------------------------------------------------------------- + * + * Player audio + * + * ----------------------------------------------------------------------------- + */ + #ifndef PLAYER_AUDIO_H #define PLAYER_AUDIO_H @@ -8,19 +17,12 @@ */ static void player_audio(void) { - static int _ding = 0; - - int last = _ding; - _ding = glfwGetKey(vg_window, GLFW_KEY_C); - - int trigger_ding = 0; - if( _ding && !last ) - trigger_ding = 1; + struct player_phys *phys = &player.phys; static int _air = 0; int l2 = _air; - _air = player.in_air; + _air = phys->in_air; static double last_revert = -2000.0; @@ -30,10 +32,10 @@ static void player_audio(void) audio_lock(); double revert_delta = vg_time - last_revert; - if( player.on_board && (!_air && l2) && (fabsf(player.slip) > 0.5f) && + if( phys->on_board && (!_air && l2) && (fabsf(phys->slip) > 0.5f) && (revert_delta > 0.7) ) { - audio_player_set_position( &audio_player_extra, player.rb.co ); + audio_player_set_position( &audio_player_extra, phys->rb.co ); audio_player_set_flags( &audio_player_extra, AUDIO_FLAG_SPACIAL_3D ); audio_player_set_vol( &audio_player_extra, 2.0f ); audio_player_playclip( &audio_player_extra, &audio_lands[rand()%5] ); @@ -42,24 +44,22 @@ static void player_audio(void) } static float air = 0.0f; - air = vg_lerpf(air, player.in_air? 1.0f: 0.0f, 5.0f*ktimestep); + air = vg_lerpf(air, phys->in_air? 1.0f: 0.0f, 5.0f*ktimestep); /* Spacial info */ v3f ears = { 1.0f,0.0f,0.0f }; v3f delta; float *cam = player.camera[3], - *pos = player.rb.co; + *pos = phys->rb.co; - if( trigger_ding ) - audio_player_playclip( &audio_player_extra, &audio_ding ); - - audio_player_set_position( &audio_player0, player.rb.co ); - audio_player_set_position( &audio_player1, player.rb.co ); - audio_player_set_position( &audio_player2, player.rb.co ); + 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( player.rb.co, player.camera[3], delta ); + v3_sub( phys->rb.co, player.camera[3], delta ); v3_normalize( delta ); m3x3_mulv( player.camera, ears, ears ); @@ -84,7 +84,7 @@ static void player_audio(void) { v3f waterpos; enum audio_sprite_type sprite_type = - audio_sample_sprite_random( player.rb.co, waterpos ); + audio_sample_sprite_random( phys->rb.co, waterpos ); if( sprite_type != k_audio_sprite_type_none ) { @@ -105,11 +105,12 @@ static void player_audio(void) } } - if( freecam || player.is_dead || !player.on_board ) + if( freecam || player.is_dead || !phys->on_board ) { 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 ) @@ -117,10 +118,10 @@ static void player_audio(void) else walk_phase = 0; - if( (player.step_phase != walk_phase) && !player.in_air ) + if( (player.step_phase != walk_phase) && !phys->in_air ) { audio_player_set_flags( &audio_player_extra, AUDIO_FLAG_SPACIAL_3D ); - audio_player_set_position( &audio_player_extra, player.rb.co ); + audio_player_set_position( &audio_player_extra, phys->rb.co ); audio_player_set_vol( &audio_player_extra, 6.0f ); audio_player_playclip( &audio_player_extra, &audio_footsteps[rand()%4] ); @@ -131,9 +132,9 @@ static void player_audio(void) else { /* Composite */ - float speed = vg_minf(v3_length( player.rb.v )*0.1f,1.0f), + float speed = vg_minf(v3_length( phys->rb.v )*0.1f,1.0f), attn = speed, - slide = vg_clampf( fabsf(player.slip), 0.0f, 1.0f ), + slide = vg_clampf( fabsf(phys->slip), 0.0f, 1.0f ), vol0 = (1.0f-air)*attn*(1.0f-slide), vol1 = air *attn, vol2 = (1.0f-air)*attn*slide;