#define AUDIO_H
#include "common.h"
+#include "world.h"
+
+static float audio_occlusion_current = 0.0f,
+ k_audio_occlusion_rate = 1.0f;
+
+static int k_audio_debug_soundscape = 0;
sfx_vol_control audio_vol_all = { .val = 1.0f, .name = "All" };
.sources = "sound/skate.ogg\0"
"sound/wheel.ogg\0"
"sound/slide.ogg\0"
+ "sound/reverb.ogg\0"
};
sfx_system audio_player0 =
.flags = SFX_FLAG_REPEAT | SFX_FLAG_PERSISTENT
};
+sfx_system audio_player3 =
+{
+ .vol = 0.0f,
+ .ch = 1,
+ .vol_src = &audio_vol_all,
+ .name = "Player3",
+ .flags = SFX_FLAG_REPEAT | SFX_FLAG_PERSISTENT
+};
+
static void audio_init(void)
{
sfx_set_init( &audio_board, NULL );
sfx_set_play( &audio_board, &audio_player0, 0 );
sfx_set_play( &audio_board, &audio_player1, 1 );
sfx_set_play( &audio_board, &audio_player2, 2 );
+ sfx_set_play( &audio_board, &audio_player3, 3 );
+
+ vg_convar_push( (struct vg_convar){
+ .name = "aud_debug_soundscape",
+ .data = &k_audio_debug_soundscape,
+ .data_type = k_convar_dtype_i32,
+ .opt_i32 = { .min=0, .max=1, .clamp=0 },
+ .persistent = 1
+ });
+
+ vg_convar_push( (struct vg_convar){
+ .name = "aud_occlusion_rate",
+ .data = &k_audio_occlusion_rate,
+ .data_type = k_convar_dtype_f32,
+ .opt_f32 = { .clamp = 0 },
+ .persistent = 1
+ });
}
static void audio_free(void)
sfx_set_free( &audio_board );
}
+static void audio_sample_occlusion( v3f origin )
+{
+ float d = 0.0f,
+ sample_dist = 880.0f;
+
+ int sample_count = 8;
+
+ for( int i=0; i<sample_count; i++ )
+ {
+ v3f dir;
+ dir[0] = vg_randf();
+ dir[1] = vg_randf();
+ dir[2] = vg_randf();
+
+ v3_muls( dir, 2.0f, dir );
+ v3_sub( dir, (v3f){1.0f,1.0f,1.0f}, dir );
+
+ v3_normalize( dir );
+
+ ray_hit contact;
+ contact.dist = 15.0f;
+
+ if( ray_world( origin, dir, &contact ) )
+ {
+ d += contact.dist;
+
+ vg_line( origin, contact.pos, 0xff0000ff );
+ vg_line_pt3( contact.pos, 0.1f, 0xff0000ff );
+ }
+ else
+ {
+ v3f p1;
+ v3_muladds( origin, dir, sample_dist, p1 );
+ vg_line( origin, p1, 0xffcccccc );
+
+ d += sample_dist;
+ }
+ }
+
+ float occlusion = 1.0f - (d * (1.0f/(sample_dist*(float)sample_count))),
+ rate = ktimestep * k_audio_occlusion_rate,
+ target = powf( occlusion, 6.0f );
+ audio_occlusion_current = vg_lerpf( audio_occlusion_current, target, rate );
+}
+
+static void audio_debug_soundscapes(void)
+{
+ if( !k_audio_debug_soundscape ) return;
+
+ char buf[64];
+ snprintf( buf, 31, "occlusion: %.5f", audio_occlusion_current );
+
+ ui_global_ctx.cursor[0] = 10;
+ ui_global_ctx.cursor[1] = 10;
+ ui_global_ctx.cursor[2] = audio_occlusion_current * 200.0f;
+ ui_global_ctx.cursor[3] = 20;
+
+ gui_fill_rect( ui_global_ctx.cursor, 0x55cccccc );
+ gui_text( ui_global_ctx.cursor, buf, 1, 0 );
+}
+
#endif /* AUDIO_H */
("angle_limits",(c_float*3)*2),
("hitbox",(c_float*3)*2)]
+class subclass_audio_channel(Structure):
+ _pack_ = 1
+ _fields_ = [("sound",c_uint32),
+ ("target",c_uint32),
+ ("")]
+
+class classtype_audio_system(Structure):
+ _pack_ = 1
+ _fields_ = [("")]
+
+class classtype_audio_zone(Structure):
+ _pack_ = 1
+ _fields_ = [("system",c_uint32)]
+
# Exporter
# ==============================================================================
.persistent = 1
});
+ vg_convar_push( (struct vg_convar){
+ .name = "rd_floaty",
+ .data = &k_ragdoll_floatyiness,
+ .data_type = k_convar_dtype_f32,
+ .opt_f32 = { .clamp = 0 },
+ .persistent = 1
+ });
+
+ vg_convar_push( (struct vg_convar){
+ .name = "rd_floatd",
+ .data = &k_ragdoll_floatydrag,
+ .data_type = k_convar_dtype_f32,
+ .opt_f32 = { .clamp = 0 },
+ .persistent = 1
+ });
+
vg_convar_push( (struct vg_convar){
.name = "dt",
.data = &ktimestep,
render_world_routes_ui();
}
//glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+
+ audio_debug_soundscapes();
#if 0
static double last_b_press = 0.0;
*/
static void player_audio(void)
{
+ audio_sample_occlusion( player.camera[3] );
+
float speed = vg_minf(v3_length( player.rb.v )*0.1f,1.0f),
attn = v3_dist( player.rb.co, player.camera[3] )+1.0f;
attn = (1.0f/(attn*attn)) * speed;
static float air = 0.0f;
- air = vg_lerpf(air, player.in_air? 1.0f: 0.0f, 0.7f);
+ air = vg_lerpf(air, player.in_air? 1.0f: 0.0f, 5.0f*ktimestep);
v3f ears = { 1.0f,0.0f,0.0f };
v3f delta;
v3_sub( player.rb.co, player.camera[3], delta );
v3_normalize( delta );
m3x3_mulv( player.camera, ears, ears );
-
+
float pan = v3_dot( ears, delta );
audio_player0.pan = pan;
audio_player1.pan = pan;
audio_player2.pan = pan;
+ audio_player3.pan = 0.0f;
+
if( freecam )
{
audio_player0.vol = 0.0f;
audio_player2.vol = (1.0f-air)*attn*slide;
}
}
+
+ audio_player3.vol = audio_player0.vol * audio_occlusion_current * 2.0f;
}
/*
player.on_board ^= 0x1;
}
- if( glfwGetKey( vg_window, GLFW_KEY_O ) )
+ if( (glfwGetKey( vg_window, GLFW_KEY_O ) || (player.rb.co[1] < 0.0f)) &&
+ !player.is_dead)
{
character_ragdoll_copypose( &player.mdl, player.rb.v );
player.is_dead = 1;
#include "skeleton_animator.h"
#include "shaders/viewchar.h"
+static float k_ragdoll_floatyiness = 10.0f,
+ k_ragdoll_floatydrag = 1.0f;
+
vg_tex2d tex_characters = { .path = "textures/ch_gradient.qoi" };
static void character_register(void)
rb_debug_constraint_limits( &pj->rb, &pp->rb, lca, pj->limits );
}
}
+
+ v4f plane = {0.0f,1.0f,0.0f,0.0f};
+ rb_effect_simple_bouyency( &pj->rb, plane, k_ragdoll_floatyiness,
+ k_ragdoll_floatydrag );
}
/* CONSTRAINTS */
}
}
+/*
+ * Effectors
+ */
+
+static void rb_effect_simple_bouyency( rigidbody *ra, v4f plane,
+ float amt, float drag )
+{
+ /* float */
+ float depth = v3_dot( plane, ra->co ) - plane[3],
+ lambda = vg_clampf( -depth, 0.0f, 1.0f ) * amt;
+
+ v3_muladds( ra->v, plane, lambda * ktimestep, ra->v );
+
+ if( depth < 0.0f )
+ v3_muls( ra->v, 1.0f-(drag*ktimestep), ra->v );
+}
+
/*
* -----------------------------------------------------------------------------
* BVH implementation, this is ONLY for static rigidbodies, its to slow for