move rigidbody to vg
[carveJwlIkooP6JGAAIwe30JlM.git] / world_volumes.c
index 0cc1ed608929b03aaf094afd49ff4e4cba7cb5ac..7f2b685170e6f1ce784ef60529e4927dd32516a1 100644 (file)
@@ -19,10 +19,19 @@ static void world_volumes_update( world_instance *world, v3f pos ){
          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 );
-         /* triggr on stay ..... */
       }
       else{
-         /* trigger on exit...... */
+         /* 
+          * 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;
+
+            entity_call( world, &basecall );
+         }
       }
    }
    world_static.active_trigger_volume_count = j;
@@ -37,23 +46,37 @@ static void world_volumes_update( world_instance *world, v3f pos ){
       random_ticks ++;
    }
 
-   float radius = 25.0f;
-   boxf volume_proximity;
-   v3_add( pos, (v3f){ radius, radius, radius }, volume_proximity[1] );
-   v3_sub( pos, (v3f){ radius, radius, radius }, volume_proximity[0] );
+   float radius = 32.0f;
 
    bh_iter it;
-   bh_iter_init_box( 0, &it, volume_proximity );
+   bh_iter_init_range( 0, &it, pos, radius );
    i32 idx;
 
-   while( bh_next( world->volume_bh, &it, &idx ) ){
-      ent_volume *volume = mdl_arritm( &world->ent_volume, 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->type == k_volume_subtype_trigger ){
+      if( volume->flags & k_ent_volume_flag_particles ){
+         vg_line_boxf_transformed( volume->to_world, cube, 0xff00c0ff );
+
+         for( int j=0; j<random_ticks; j++ ){
+            ent_call basecall;
+            basecall.id = id;
+            basecall.data = NULL;
+            basecall.function = 0;
+
+            entity_call( world, &basecall );
+         }
+      }
+      else{
          for( u32 i=0; i<world_static.active_trigger_volume_count; i++ )
-            if( world_static.active_trigger_volumes[i] == idx )
+            if( world_static.active_trigger_volumes[i] == index )
                goto next_volume;
 
          if( world_static.active_trigger_volume_count > 
@@ -64,82 +87,21 @@ static void world_volumes_update( world_instance *world, v3f pos ){
 
          if( (fabsf(local[0]) <= 1.0f) &&
              (fabsf(local[1]) <= 1.0f) &&
-             (fabsf(local[2]) <= 1.0f) )
-         {
+             (fabsf(local[2]) <= 1.0f) ){
             ent_call basecall;
-            basecall.function = k_ent_function_trigger;
-            basecall.id = mdl_entity_id( k_ent_volume, idx );
+            basecall.function = 0;
+            basecall.id = id;
             basecall.data = NULL;
 
             entity_call( world, &basecall );
             world_static.active_trigger_volumes[ 
-               world_static.active_trigger_volume_count ++ ] = idx;
+               world_static.active_trigger_volume_count ++ ] = index;
          }
          else
             vg_line_boxf_transformed( volume->to_world, cube, 0xffcccccc );
       }
-      else if( volume->type == k_volume_subtype_particle ){
-         vg_line_boxf_transformed( volume->to_world, cube, 0xff00c0ff );
-
-         for( int j=0; j<random_ticks; j++ ){
-            ent_call basecall;
-            basecall.id = mdl_entity_id( k_ent_volume, idx );
-            basecall.data = NULL;
-
-            entity_call( world, &basecall );
-         }
-      }
 next_volume:;
    }
 }
 
-/*
- * BVH implementation
- * ----------------------------------------------------------------------------
- */
-
-VG_STATIC void volume_vg_expand_bound( void *user, boxf bound, u32 item_index )
-{
-   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} );
-}
-
-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];
-}
-
-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;
-}
-
-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 );
-}
-
 #endif /* WORLD_VOLUMES_H */