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