5 #include "world_audio.h"
7 /* finds any active playing in world and fades them out, we can only do this
9 VG_STATIC
void world_fadeout_audio( world_instance
*world
)
11 if( world
->status
!= k_world_status_unloading
){
12 vg_fatal_error( "World status must be set to 'unloading', to fadeout"
16 u8 world_id
= (world
- world_static
.worlds
) + 1;
19 for( u32 i
=0; i
<AUDIO_CHANNELS
; i
++ ){
20 audio_channel
*ch
= &vg_audio
.channels
[i
];
22 if( ch
->allocated
&& (ch
->world_id
== world_id
) ){
23 ch
= audio_channel_fadeout( ch
, 1.0f
);
30 * Trace out a random point, near the player to try and determine water areas
33 enum audio_sprite_type
world_audio_sample_sprite_random(v3f origin
, v3f output
)
35 v3f chance
= { (vg_randf64()-0.5f
) * 30.0f
,
37 (vg_randf64()-0.5f
) * 30.0f
};
40 v3_add( chance
, origin
, pos
);
43 contact
.dist
= vg_minf( 16.0f
, pos
[1] );
45 world_instance
*world
= world_current_instance();
47 if( ray_world( world
, pos
, (v3f
){0.0f
,-1.0f
,0.0f
}, &contact
) ){
48 struct world_surface
*mat
= ray_hit_surface( world
, &contact
);
50 if( mat
->info
.surface_prop
== k_surface_prop_grass
){
51 v3_copy( contact
.pos
, output
);
52 return k_audio_sprite_type_grass
;
55 return k_audio_sprite_type_none
;
63 float dist
= fabsf(output
[1] - origin
[1]);
65 if( world
->water
.enabled
&& dist
<=40.0f
)
66 return k_audio_sprite_type_water
;
68 return k_audio_sprite_type_none
;
71 VG_STATIC
void world_audio_sample_distances( v3f co
, int *index
, float *value
)
73 float inr3
= 0.57735027,
76 v3f sample_directions
[] = {
77 { -1.0f
, 0.0f
, 0.0f
},
80 { 0.0f
, 0.0f
, -1.0f
},
82 { 0.0f
, -1.0f
, 0.0f
},
83 { -inr3
, inr3
, inr3
},
85 { -inr3
, inr3
, -inr3
},
86 { inr3
, inr3
, -inr3
},
87 { -inr2
, 0.0f
, inr2
},
89 { -inr2
, 0.0f
, -inr2
},
90 { inr2
, 0.0f
, -inr2
},
94 static float distances
[16];
100 v3_copy( sample_directions
[ si
], rd
);
101 v3_add( co
, (v3f
){0.0f
,1.5f
,0.0f
}, ro
);
106 for( int i
=0; i
<10; i
++ ){
107 if( ray_world( world_current_instance(), rc
, rd
, &ray
) ){
108 dist
= (float)i
*5.0f
+ ray
.dist
;
112 v3_muladds( rc
, rd
, ray
.dist
, rc
);
116 distances
[si
] = dist
;
118 if( vg_audio
.debug_ui
&& vg_lines
.draw
){
119 for( int i
=0; i
<14; i
++ ){
120 if( distances
[i
] != 200.0f
){
121 u32 colours
[] = { VG__RED
, VG__BLUE
, VG__GREEN
,
122 VG__CYAN
, VG__YELOW
, VG__PINK
,
125 u32 colour
= colours
[i
%7];
128 v3_muladds( ro
, sample_directions
[i
], distances
[i
], p1
);
129 vg_line( ro
, p1
, colour
);
130 vg_line_point( p1
, 0.1f
, colour
);
143 #endif /* WORLD_AUDIO_C */