switch to entity list
[carveJwlIkooP6JGAAIwe30JlM.git] / world_volumes.c
1 #ifndef WORLD_VOLUMES_C
2 #define WORLD_VOLUMES_C
3
4 #include "world_volumes.h"
5
6 static void world_volumes_update( world_instance *world, v3f pos ){
7 /* filter and check the existing ones */
8 u32 j=0;
9 for( u32 i=0; i<world_static.active_trigger_volume_count; i++ ){
10 i32 idx = world_static.active_trigger_volumes[i];
11 ent_volume *volume = mdl_arritm( &world->ent_volume, idx );
12
13 v3f local;
14 m4x3_mulv( volume->to_local, pos, local );
15 if( (fabsf(local[0]) <= 1.0f) &&
16 (fabsf(local[1]) <= 1.0f) &&
17 (fabsf(local[2]) <= 1.0f) )
18 {
19 world_static.active_trigger_volumes[ j ++ ] = idx;
20 boxf cube = {{-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f}};
21 vg_line_boxf_transformed( volume->to_world, cube, 0xff00ccff );
22 /* triggr on stay ..... */
23 }
24 else{
25 /* trigger on exit...... */
26 }
27 }
28 world_static.active_trigger_volume_count = j;
29
30 static float random_accum = 0.0f;
31 random_accum += vg.time_delta;
32
33 u32 random_ticks = 0;
34
35 while( random_accum > 0.1f ){
36 random_accum -= 0.1f;
37 random_ticks ++;
38 }
39
40 float radius = 25.0f;
41 boxf volume_proximity;
42 v3_add( pos, (v3f){ radius, radius, radius }, volume_proximity[1] );
43 v3_sub( pos, (v3f){ radius, radius, radius }, volume_proximity[0] );
44
45 bh_iter it;
46 bh_iter_init_box( 0, &it, volume_proximity );
47 i32 idx;
48
49 while( bh_next( world->entity_bh, &it, &idx ) ){
50 u32 id = world->entity_list[ idx ],
51 type = mdl_entity_id_type( id ),
52 index = mdl_entity_id_id( id );
53
54 if( type != k_ent_volume ) continue;
55
56 ent_volume *volume = mdl_arritm( &world->ent_volume, index );
57 boxf cube = {{-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f}};
58
59 if( volume->flags & k_ent_volume_flag_particles ){
60 vg_line_boxf_transformed( volume->to_world, cube, 0xff00c0ff );
61
62 for( int j=0; j<random_ticks; j++ ){
63 ent_call basecall;
64 basecall.id = id;
65 basecall.data = NULL;
66 basecall.function = 0;
67
68 entity_call( world, &basecall );
69 }
70 }
71 else{
72 for( u32 i=0; i<world_static.active_trigger_volume_count; i++ )
73 if( world_static.active_trigger_volumes[i] == index )
74 goto next_volume;
75
76 if( world_static.active_trigger_volume_count >
77 vg_list_size(world_static.active_trigger_volumes) ) continue;
78
79 v3f local;
80 m4x3_mulv( volume->to_local, pos, local );
81
82 if( (fabsf(local[0]) <= 1.0f) &&
83 (fabsf(local[1]) <= 1.0f) &&
84 (fabsf(local[2]) <= 1.0f) ){
85 ent_call basecall;
86 basecall.function = 0;
87 basecall.id = id;
88 basecall.data = NULL;
89
90 entity_call( world, &basecall );
91 world_static.active_trigger_volumes[
92 world_static.active_trigger_volume_count ++ ] = index;
93 }
94 else
95 vg_line_boxf_transformed( volume->to_world, cube, 0xffcccccc );
96 }
97 next_volume:;
98 }
99 }
100
101 #endif /* WORLD_VOLUMES_H */