map binary data
[carveJwlIkooP6JGAAIwe30JlM.git] / world_volumes.c
1 #include "world_volumes.h"
2
3 void world_volumes_update( world_instance *world, v3f pos )
4 {
5 /* filter and check the existing ones */
6 u32 j=0;
7 for( u32 i=0; i<world_static.active_trigger_volume_count; i++ ){
8 i32 idx = world_static.active_trigger_volumes[i];
9 ent_volume *volume = mdl_arritm( &world->ent_volume, idx );
10
11 v3f local;
12 m4x3_mulv( volume->to_local, pos, local );
13 if( (fabsf(local[0]) <= 1.0f) &&
14 (fabsf(local[1]) <= 1.0f) &&
15 (fabsf(local[2]) <= 1.0f) )
16 {
17 world_static.active_trigger_volumes[ j ++ ] = idx;
18 boxf cube = {{-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f}};
19 vg_line_boxf_transformed( volume->to_world, cube, 0xff00ccff );
20 }
21 else{
22 /*
23 * LEGACY BEHAVIOUR: < v104 does not have leave events
24 */
25 if( world->meta.info.version >= 104 ){
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 }
35 world_static.active_trigger_volume_count = j;
36
37 static float random_accum = 0.0f;
38 random_accum += vg.time_delta;
39
40 u32 random_ticks = 0;
41
42 while( random_accum > 0.1f ){
43 random_accum -= 0.1f;
44 random_ticks ++;
45 }
46
47 float radius = 32.0f;
48
49 bh_iter it;
50 bh_iter_init_range( 0, &it, pos, radius );
51 i32 idx;
52
53 while( bh_next( world->entity_bh, &it, &idx ) ){
54 u32 id = world->entity_list[ idx ],
55 type = mdl_entity_id_type( id ),
56 index = mdl_entity_id_id( id );
57
58 if( type != k_ent_volume ) continue;
59
60 ent_volume *volume = mdl_arritm( &world->ent_volume, index );
61 boxf cube = {{-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f}};
62
63 if( volume->flags & k_ent_volume_flag_particles ){
64 vg_line_boxf_transformed( volume->to_world, cube, 0xff00c0ff );
65
66 for( int j=0; j<random_ticks; j++ ){
67 ent_call basecall;
68 basecall.id = id;
69 basecall.data = NULL;
70 basecall.function = 0;
71
72 entity_call( world, &basecall );
73 }
74 }
75 else{
76 for( u32 i=0; i<world_static.active_trigger_volume_count; i++ )
77 if( world_static.active_trigger_volumes[i] == index )
78 goto next_volume;
79
80 if( world_static.active_trigger_volume_count >
81 vg_list_size(world_static.active_trigger_volumes) ) continue;
82
83 v3f local;
84 m4x3_mulv( volume->to_local, pos, local );
85
86 if( (fabsf(local[0]) <= 1.0f) &&
87 (fabsf(local[1]) <= 1.0f) &&
88 (fabsf(local[2]) <= 1.0f) ){
89 ent_call basecall;
90 basecall.function = 0;
91 basecall.id = id;
92 basecall.data = NULL;
93
94 entity_call( world, &basecall );
95 world_static.active_trigger_volumes[
96 world_static.active_trigger_volume_count ++ ] = index;
97 }
98 else
99 vg_line_boxf_transformed( volume->to_world, cube, 0xffcccccc );
100 }
101 next_volume:;
102 }
103 }