X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_volumes.c;h=ae507d0cffec927296435ae7f3bd0c25677de15e;hb=5fa590f62aa7e62a8b6b07e10556c2ecc54cdca6;hp=c08fe43155de12533c5e106b8779f72a6bfc9895;hpb=342fcbf6fda017bdd38d56ce0fa7c9e59e589f3b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_volumes.c b/world_volumes.c index c08fe43..ae507d0 100644 --- a/world_volumes.c +++ b/world_volumes.c @@ -1,55 +1,103 @@ -#ifndef WORLD_VOLUMES_C -#define WORLD_VOLUMES_C - #include "world_volumes.h" -/* - * BVH implementation - * ---------------------------------------------------------------------------- - */ - -VG_STATIC void volume_vg_expand_bound( void *user, boxf bound, u32 item_index ) +void world_volumes_update( world_instance *world, v3f pos ) { - world_instance *world = user; - - ent_volume *volume = mdl_arritm( &world->ent_volume, item_index ); - - m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f, 1.0f, 1.0f} ); - m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f, 1.0f,-1.0f} ); - m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f,-1.0f, 1.0f} ); - m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f,-1.0f,-1.0f} ); - m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f, 1.0f, 1.0f} ); - m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f, 1.0f,-1.0f} ); - m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f,-1.0f, 1.0f} ); - m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f,-1.0f,-1.0f} ); -} + /* filter and check the existing ones */ + u32 j=0; + for( u32 i=0; ient_volume, idx ); -VG_STATIC float volume_vg_centroid( void *user, u32 item_index, int axis ) -{ - world_instance *world = user; - ent_volume *volume = mdl_arritm( &world->ent_volume, item_index ); - return volume->to_world[3][axis]; -} + v3f local; + m4x3_mulv( volume->to_local, pos, local ); + if( (fabsf(local[0]) <= 1.0f) && + (fabsf(local[1]) <= 1.0f) && + (fabsf(local[2]) <= 1.0f) ) + { + world_static.active_trigger_volumes[ j ++ ] = idx; + boxf cube = {{-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f}}; + vg_line_boxf_transformed( volume->to_world, cube, 0xff00ccff ); + } + else{ + /* + * LEGACY BEHAVIOUR: < v104 does not have leave events + */ + if( world->meta.info.version >= 104 ){ + ent_call basecall; + basecall.function = k_ent_function_trigger_leave; + basecall.id = mdl_entity_id( k_ent_volume, idx ); + basecall.data = NULL; -VG_STATIC void volume_vg_swap( void *user, u32 ia, u32 ib ) -{ - world_instance *world = user; - ent_volume *a = mdl_arritm( &world->ent_volume, ia ), - *b = mdl_arritm( &world->ent_volume, ib ), - temp; - - temp = *a; - *a = *b; - *b = temp; -} + entity_call( world, &basecall ); + } + } + } + world_static.active_trigger_volume_count = j; -VG_STATIC void volume_vg_debug( void *user, u32 item_index ) -{ - world_instance *world = user; - ent_volume *volume = mdl_arritm( &world->ent_volume, item_index ); - vg_line_boxf_transformed( volume->to_world, (boxf){{-1.0f,-1.0f,-1.0f}, - { 1.0f, 1.0f, 1.0f}}, - 0xff00ff00 ); -} + static float random_accum = 0.0f; + random_accum += vg.time_delta; + + u32 random_ticks = 0; + + while( random_accum > 0.1f ){ + random_accum -= 0.1f; + random_ticks ++; + } -#endif /* WORLD_VOLUMES_H */ + float radius = 32.0f; + + bh_iter it; + bh_iter_init_range( 0, &it, pos, radius ); + i32 idx; + + while( bh_next( world->entity_bh, &it, &idx ) ){ + u32 id = world->entity_list[ idx ], + type = mdl_entity_id_type( id ), + index = mdl_entity_id_id( id ); + + if( type != k_ent_volume ) continue; + + ent_volume *volume = mdl_arritm( &world->ent_volume, index ); + boxf cube = {{-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f}}; + + if( volume->flags & k_ent_volume_flag_particles ){ + vg_line_boxf_transformed( volume->to_world, cube, 0xff00c0ff ); + + for( int j=0; j + vg_list_size(world_static.active_trigger_volumes) ) continue; + + v3f local; + m4x3_mulv( volume->to_local, pos, local ); + + if( (fabsf(local[0]) <= 1.0f) && + (fabsf(local[1]) <= 1.0f) && + (fabsf(local[2]) <= 1.0f) ){ + ent_call basecall; + basecall.function = 0; + basecall.id = id; + basecall.data = NULL; + + entity_call( world, &basecall ); + world_static.active_trigger_volumes[ + world_static.active_trigger_volume_count ++ ] = index; + } + else + vg_line_boxf_transformed( volume->to_world, cube, 0xffcccccc ); + } +next_volume:; + } +}