compile_obj_transform( obj, audio.transform )
audio.clip_start = audio_clip_count
audio.clip_count = len(obj_data.files)
+ audio_clip_count += audio.clip_count
audio.max_channels = obj_data.max_channels
audio.volume = obj_data.volume
cv_ent_volume( obj )
#}
elif ent_type == 'ent_audio':#{
- cv_draw_sphere( obj.location, obj.scale[0], (1,1,0) )
+ if obj.SR_data.ent_audio[0].flag_3d:
+ cv_draw_sphere( obj.location, obj.scale[0], (1,1,0) )
#}
#}
#}
bh_node *node = &bh->nodes[ inode ];
box_init_inf( node->bbx );
- for( u32 i=0; i<node->count; i++ )
- {
+ for( u32 i=0; i<node->count; i++ ){
u32 idx = node->start+i;
bh->system->expand_bound( bh->user, node->bbx, idx );
}
i32 i = node->start,
j = i + node->count-1;
- while( i <= j )
- {
+ while( i <= j ){
if( bh->system->item_centroid( bh->user, i, axis ) < split )
i ++;
- else
- {
+ else{
bh->system->item_swap( bh->user, i, j );
j --;
}
if( item_count > 2 )
bh_subdivide( bh, 0 );
- totsize = sizeof(bh_tree) + sizeof(bh_node) * bh->node_count;
+ totsize = vg_align8(sizeof(bh_tree) + sizeof(bh_node) * bh->node_count);
bh = vg_linear_resize( lin_alloc, bh, totsize );
vg_success( "BVH done, size: %u/%u\n", bh->node_count, (alloc_count*2-1) );
{
vg_line_boxf( node->bbx, 0xff00ff00 );
- if( bh->system->item_debug )
- {
- for( u32 i=0; i<node->count; i++ )
- {
+ if( bh->system->item_debug ){
+ for( u32 i=0; i<node->count; i++ ){
u32 idx = node->start+i;
bh->system->item_debug( bh->user, idx );
}
if( (pos[0] >= node->bbx[0][0] && pos[0] <= node->bbx[1][0]) &&
(pos[2] >= node->bbx[0][2] && pos[2] <= node->bbx[1][2]) )
{
- if( !node->count )
- {
+ if( !node->count ){
vg_line_boxf( node->bbx, colour );
bh_debug_trace( bh, node->il, pos, colour );
bh_debug_trace( bh, node->ir, pos, colour );
}
- else
- {
+ else{
if( bh->system->item_debug )
bh_debug_leaf( bh, node );
}
dir_inv[1] = 1.0f/dir[1];
dir_inv[2] = 1.0f/dir[2];
- while(depth)
- {
+ while(depth){
bh_node *inode = &bh->nodes[ stack[depth] ];
- if( ray_aabb1( inode->bbx, co, dir_inv, hit->dist ) )
- {
- if( inode->count )
- {
- for( u32 i=0; i<inode->count; i++ )
- {
+ if( ray_aabb1( inode->bbx, co, dir_inv, hit->dist ) ){
+ if( inode->count ){
+ for( u32 i=0; i<inode->count; i++ ){
u32 idx = inode->start+i;
if( bh->system->cast_ray )
depth --;
}
- else
- {
- if( depth+1 >= vg_list_size(stack) )
- {
+ else{
+ if( depth+1 >= vg_list_size(stack) ){
vg_error( "Maximum stack reached!\n" );
return count;
}
depth ++;
}
}
- else
- {
+ else{
depth --;
}
}
VG_STATIC int bh_next( bh_tree *bh, bh_iter *it, boxf box, int *em )
{
- while( it->depth >= 0 )
- {
+ while( it->depth >= 0 ){
bh_node *inode = &bh->nodes[ it->stack[it->depth].id ];
/* Only process overlapping nodes */
- if( !box_overlap( inode->bbx, box ) )
- {
+ if( !box_overlap( inode->bbx, box ) ){
it->depth --;
continue;
}
- if( inode->count )
- {
- if( it->i < inode->count )
- {
+ if( inode->count ){
+ if( it->i < inode->count ){
*em = inode->start+it->i;
it->i ++;
return 1;
}
- else
- {
+ else{
it->depth --;
it->i = 0;
}
}
- else
- {
- if( it->depth+1 >= vg_list_size(it->stack) )
- {
+ else{
+ if( it->depth+1 >= vg_list_size(it->stack) ){
vg_error( "Maximum stack reached!\n" );
return 0;
}
queue[0] = 0;
- while( depth >= 0 )
- {
+ while( depth >= 0 ){
bh_node *inode = &bh->nodes[ queue[depth] ];
v3f p1;
/* branch into node if its closer than current best */
float node_dist = v3_dist2( pos, p1 );
- if( node_dist < max_dist )
- {
- if( inode->count )
- {
- for( int i=0; i<inode->count; i++ )
- {
+ if( node_dist < max_dist ){
+ if( inode->count ){
+ for( int i=0; i<inode->count; i++ ){
v3f p2;
bh->system->item_closest( bh->user, inode->start+i, pos, p2 );
float item_dist = v3_dist2( pos, p2 );
- if( item_dist < max_dist )
- {
+ if( item_dist < max_dist ){
max_dist = item_dist;
v3_copy( p2, closest );
best_item = inode->start+i;
depth --;
}
- else
- {
+ else{
queue[depth] = inode->il;
queue[depth+1] = inode->ir;
m3x3_mulv( player->invbasis, player->rb.v, v_local );
v2f d = { v3_dot( ax, v0 ), v0[1] },
- v = { v3_dot( ax, player->rb.v ), v_local[1] };
+ v = { v3_dot( ax, v_local ), v_local[1] };
float a = atan2f( v[1], v[0] ),
m = v2_length( v ),
if( s->aud_main ){
s->aud_main->colour = 0x00103efe;
audio_channel_set_spacial( s->aud_main, player->rb.co, 40.0f );
- audio_channel_slope_volume( s->aud_main, 0.05f, vol_main );
+ //audio_channel_slope_volume( s->aud_main, 0.05f, vol_main );
+ audio_channel_edit_volume( s->aud_main, vol_main, 1 );
audio_channel_sidechain_lfo( s->aud_main, 0, sidechain_amt );
float rate = 1.0f + (attn-0.5f)*0.2f;
if( s->aud_slide ){
s->aud_slide->colour = 0x00103efe;
audio_channel_set_spacial( s->aud_slide, player->rb.co, 40.0f );
- audio_channel_slope_volume( s->aud_slide, 0.05f, vol_slide );
+ //audio_channel_slope_volume( s->aud_slide, 0.05f, vol_slide );
+ audio_channel_edit_volume( s->aud_slide, vol_slide, 1 );
audio_channel_sidechain_lfo( s->aud_slide, 0, sidechain_amt );
}
if( s->aud_air ){
s->aud_air->colour = 0x00103efe;
audio_channel_set_spacial( s->aud_air, player->rb.co, 40.0f );
- audio_channel_slope_volume( s->aud_air, 0.05f, vol_air );
+ //audio_channel_slope_volume( s->aud_air, 0.05f, vol_air );
+ audio_channel_edit_volume( s->aud_air, vol_air, 1 );
}
audio_unlock();
indice_count = pscene->indice_count,
vertex_length = vertex_count * sizeof(scene_vert),
index_length = indice_count * sizeof(u32),
- tot_size = sizeof(scene) + vertex_length + index_length;
+ tot_size = vg_align8(sizeof(scene) + vertex_length + index_length);
/* copy down index data */
void *dst_indices = pscene->arrvertices + vertex_count;
int main( int argc, char *argv[] )
{
- vg_mem.use_libc_malloc = 1;
+ vg_mem.use_libc_malloc = 0;
vg_set_mem_quota( 160*1024*1024 );
vg_enter( argc, argv, "Voyager Game Engine" );
call->function = k_ent_function_particle_spawn;
call->data = co;
-
entity_call( world, call );
}
- else if( volume->type == k_volume_subtype_trigger ){
- /* TODO */
- }
+ else
+ entity_call( world, call );
}
}
{
ent_audio *audio = mdl_arritm( &world->ent_audio, call->ent.index );
+ v3f sound_co;
+
if( call->function == k_ent_function_particle_spawn ){
- float chance = vg_randf()*100.0f,
- bar = 0.0f;
+ v3_copy( call->data, sound_co );
+ }
+ else if( call->function == k_ent_function_trigger ){
+ v3_copy( audio->transform.co, sound_co );
+ }
+ else
+ vg_fatal_exit_loop( "ent_audio_call (invalid function id)" );
+
+ float chance = vg_randf()*100.0f,
+ bar = 0.0f;
- for( u32 i=0; i<audio->clip_count; i++ ){
- ent_audio_clip *clip = mdl_arritm( &world->ent_audio_clip,
- audio->clip_start+i );
+ for( u32 i=0; i<audio->clip_count; i++ ){
+ ent_audio_clip *clip = mdl_arritm( &world->ent_audio_clip,
+ audio->clip_start+i );
- float mod = world->probabilities[ audio->probability_curve ],
- p = clip->probability * mod;
+ float mod = world->probabilities[ audio->probability_curve ],
+ p = clip->probability * mod;
- bar += p;
+ bar += p;
- if( chance < bar ){
- float *pos = call->data;
+ if( chance < bar ){
- audio_lock();
+ audio_lock();
- if( audio->behaviour == k_channel_behaviour_unlimited ){
- audio_oneshot_3d( &clip->clip, pos,
- audio->transform.s[0],
- audio->volume );
+ if( audio->behaviour == k_channel_behaviour_unlimited ){
+ audio_oneshot_3d( &clip->clip, sound_co,
+ audio->transform.s[0],
+ audio->volume );
+ }
+ else if( audio->behaviour == k_channel_behaviour_discard_if_full ){
+ audio_channel *ch =
+ audio_get_group_idle_channel( audio->group,
+ audio->max_channels );
+
+ if( ch ){
+ audio_channel_init( ch, &clip->clip, audio->flags );
+ audio_channel_group( ch, audio->group );
+ audio_channel_set_spacial( ch, sound_co, audio->transform.s[0] );
+ audio_channel_edit_volume( ch, audio->volume, 1 );
+ ch = audio_relinquish_channel( ch );
}
- else if( audio->behaviour == k_channel_behaviour_discard_if_full ){
- audio_channel *ch =
- audio_get_group_idle_channel( audio->group,
- audio->max_channels );
-
- if( ch ){
- audio_channel_init( ch, &clip->clip, audio->flags );
- audio_channel_group( ch, audio->group );
- audio_channel_set_spacial( ch, pos, audio->transform.s[0] );
- audio_channel_edit_volume( ch, audio->volume, 1 );
- ch = audio_relinquish_channel( ch );
+ }
+ else if( audio->behaviour == k_channel_behaviour_crossfade_if_full){
+ audio_channel *ch =
+ audio_get_group_idle_channel( audio->group,
+ audio->max_channels );
+
+ /* group is full */
+ if( !ch ){
+ audio_channel *existing =
+ audio_get_group_first_active_channel( audio->group );
+
+ if( existing ){
+ if( existing->source == &clip->clip ){
+ audio_unlock();
+ return;
+ }
+
+ existing = audio_channel_fadeout( existing, audio->crossfade);
}
- }
- else if( audio->behaviour == k_channel_behaviour_crossfade_if_full){
-
- }
-
+ ch = audio_get_first_idle_channel();
+ }
- audio_unlock();
- break;
+ if( ch ){
+ audio_channel_init( ch, &clip->clip, audio->flags );
+ audio_channel_group( ch, audio->group );
+ audio_channel_fadein( ch, audio->crossfade );
+ ch = audio_relinquish_channel( ch );
+ }
}
+
+ audio_unlock();
+ return;
}
}
}
if( volume->type == k_volume_subtype_trigger ){
v3f local;
m4x3_mulv( volume->to_local, pos, local );
- vg_line_boxf_transformed( volume->to_world, cube, 0xff00ff00 );
if( (fabsf(local[0]) <= 1.0f) &&
(fabsf(local[1]) <= 1.0f) &&
(fabsf(local[2]) <= 1.0f) )
{
in_volume = 1;
+ vg_line_boxf_transformed( volume->to_world, cube, 0xff00ff00 );
if( !world_global.in_volume ){
ent_call basecall;
entity_call( world, &basecall );
}
}
+ else
+ vg_line_boxf_transformed( volume->to_world, cube, 0xff0000ff );
}
else if( volume->type == k_volume_subtype_particle ){
vg_line_boxf_transformed( volume->to_world, cube, 0xff00c0ff );
int total_cubes = icubes_count[0]*icubes_count[1]*icubes_count[2];
u32 *cubes_index = vg_linear_alloc( world_global.generic_heap,
- total_cubes * sizeof(u32) * 2.0f );
+ vg_align8(total_cubes*sizeof(u32)*2) );
vg_info( "Computing light cubes (%d) [%f %f %f] -> [%f %f %f]\n",
total_cubes, cubes_min[0], -cubes_min[2], cubes_min[1],
world->texture_count = world->meta.textures.count+1;
world->textures = vg_linear_alloc( world_global.generic_heap,
- sizeof(GLuint)*world->texture_count );
+ vg_align8(sizeof(GLuint)*world->texture_count) );
vg_acquire_thread_sync();
{
world->surface_count = world->meta.materials.count+1;
world->surfaces = vg_linear_alloc( world_global.generic_heap,
- sizeof(struct world_surface)*world->surface_count );
+ vg_align8(sizeof(struct world_surface)*world->surface_count) );
/* error material */
struct world_surface *errmat = &world->surfaces[0];
for( u32 j=0; j<mdl_arrcount(&world->ent_volume); j++ ){
ent_volume *volume = mdl_arritm( &world->ent_volume, j );
mdl_transform_m4x3( &volume->transform, volume->to_world );
- m4x3_invert_affine( volume->to_world, volume->to_local );
+ m4x3_invert_full( volume->to_world, volume->to_local );
}
/* audio packs */