code is no longer based :(
[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 ent_call basecall;
27 basecall.function = k_ent_function_trigger_leave;
28 basecall.id = mdl_entity_id( k_ent_volume, idx );
29 basecall.data = NULL;
30
31 entity_call( world, &basecall );
32 }
33 }
34 world_static.active_trigger_volume_count = j;
35
36 static float random_accum = 0.0f;
37 random_accum += vg.time_delta;
38
39 u32 random_ticks = 0;
40
41 while( random_accum > 0.1f ){
42 random_accum -= 0.1f;
43 random_ticks ++;
44 }
45
46 float radius = 32.0f;
47
48 bh_iter it;
49 bh_iter_init_range( 0, &it, pos, radius );
50 i32 idx;
51
52 while( bh_next( world->entity_bh, &it, &idx ) ){
53 u32 id = world->entity_list[ idx ],
54 type = mdl_entity_id_type( id ),
55 index = mdl_entity_id_id( id );
56
57 if( type != k_ent_volume ) continue;
58
59 ent_volume *volume = mdl_arritm( &world->ent_volume, index );
60 boxf cube = {{-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f}};
61
62 if( volume->flags & k_ent_volume_flag_particles ){
63 vg_line_boxf_transformed( volume->to_world, cube, 0xff00c0ff );
64
65 for( int j=0; j<random_ticks; j++ ){
66 ent_call basecall;
67 basecall.id = id;
68 basecall.data = NULL;
69 basecall.function = 0;
70
71 entity_call( world, &basecall );
72 }
73 }
74 else{
75 for( u32 i=0; i<world_static.active_trigger_volume_count; i++ )
76 if( world_static.active_trigger_volumes[i] == index )
77 goto next_volume;
78
79 if( world_static.active_trigger_volume_count >
80 vg_list_size(world_static.active_trigger_volumes) ) continue;
81
82 v3f local;
83 m4x3_mulv( volume->to_local, pos, local );
84
85 if( (fabsf(local[0]) <= 1.0f) &&
86 (fabsf(local[1]) <= 1.0f) &&
87 (fabsf(local[2]) <= 1.0f) ){
88 ent_call basecall;
89 basecall.function = 0;
90 basecall.id = id;
91 basecall.data = NULL;
92
93 entity_call( world, &basecall );
94 world_static.active_trigger_volumes[
95 world_static.active_trigger_volume_count ++ ] = index;
96 }
97 else
98 vg_line_boxf_transformed( volume->to_world, cube, 0xffcccccc );
99 }
100 next_volume:;
101 }
102 }
103
104 #endif /* WORLD_VOLUMES_H */