1 #include "vg/vg_steam.h"
2 #include "vg/vg_steam_user_stats.h"
6 #include "world_load.h"
10 #include "ent_challenge.h"
11 #include "ent_skateshop.h"
12 #include "ent_route.h"
13 #include "ent_traffic.h"
14 #include "ent_glider.h"
15 #include "ent_region.h"
18 #include "player_walk.h"
20 bh_system bh_system_entity_list
=
22 .expand_bound
= entity_bh_expand_bound
,
23 .item_centroid
= entity_bh_centroid
,
24 .item_closest
= entity_bh_closest
,
25 .item_swap
= entity_bh_swap
,
26 .item_debug
= entity_bh_debug
,
30 void world_entity_set_focus( u32 entity_id
)
32 if( world_static
.focused_entity
)
34 vg_warn( "Entity %u#%u tried to take focus from %u#%u\n",
35 mdl_entity_id_type( entity_id
),
36 mdl_entity_id_id( entity_id
),
37 mdl_entity_id_type( world_static
.focused_entity
),
38 mdl_entity_id_id( world_static
.focused_entity
) );
42 world_static
.focused_entity
= entity_id
;
45 void world_entity_focus_modal(void)
47 localplayer
.immobile
= 1;
48 menu
.disable_open
= 1;
49 srinput
.state
= k_input_state_resume
;
51 v3_zero( localplayer
.rb
.v
);
52 v3_zero( localplayer
.rb
.w
);
53 player_walk
.move_speed
= 0.0f
;
54 skaterift
.activity
= k_skaterift_ent_focus
;
57 void world_entity_exit_modal(void)
59 if( skaterift
.activity
!= k_skaterift_ent_focus
)
61 vg_warn( "Entity %u#%u tried to exit modal when we weren't in one\n",
62 mdl_entity_id_type( world_static
.focused_entity
),
63 mdl_entity_id_id( world_static
.focused_entity
) );
67 localplayer
.immobile
= 0;
68 menu
.disable_open
= 0;
69 srinput
.state
= k_input_state_resume
;
70 skaterift
.activity
= k_skaterift_default
;
73 void world_entity_clear_focus(void)
75 if( skaterift
.activity
== k_skaterift_ent_focus
)
77 vg_warn( "Entity %u#%u tried to clear focus before exiting modal\n",
78 mdl_entity_id_type( world_static
.focused_entity
),
79 mdl_entity_id_id( world_static
.focused_entity
) );
83 world_static
.focused_entity
= 0;
86 void world_entity_focus_camera( world_instance
*world
, u32 uid
)
88 if( mdl_entity_id_type( uid
) == k_ent_camera
){
89 u32 index
= mdl_entity_id_id( uid
);
90 ent_camera
*cam
= mdl_arritm( &world
->ent_camera
, index
);
92 v3f dir
= {0.0f
,-1.0f
,0.0f
};
93 mdl_transform_vector( &cam
->transform
, dir
, dir
);
94 v3_angles( dir
, world_static
.focus_cam
.angles
);
95 v3_copy( cam
->transform
.co
, world_static
.focus_cam
.pos
);
96 world_static
.focus_cam
.fov
= cam
->fov
;
99 vg_camera_copy( &localplayer
.cam
, &world_static
.focus_cam
);
102 world_static
.focus_cam
.nearz
= localplayer
.cam
.nearz
;
103 world_static
.focus_cam
.farz
= localplayer
.cam
.farz
;
107 /* logic preupdate */
108 void world_entity_focus_preupdate(void)
110 f32 rate
= vg_minf( 1.0f
, vg
.time_frame_delta
* 2.0f
);
112 if( skaterift
.activity
== k_skaterift_ent_focus
)
115 vg_slewf( &world_static
.focus_strength
, active
,
116 vg
.time_frame_delta
* (1.0f
/0.5f
) );
118 u32 type
= mdl_entity_id_type( world_static
.focused_entity
),
119 index
= mdl_entity_id_id( world_static
.focused_entity
);
120 world_instance
*world
= world_current_instance();
123 if( type
== k_ent_skateshop
)
125 ent_skateshop
*skateshop
= mdl_arritm( &world
->ent_skateshop
, index
);
126 ent_skateshop_preupdate( skateshop
, active
);
128 else if( type
== k_ent_challenge
)
130 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
131 ent_challenge_preupdate( challenge
, active
);
133 else if( type
== k_ent_route
)
135 ent_route
*route
= mdl_arritm( &world
->ent_route
, index
);
136 ent_route_preupdate( route
, active
);
138 else if( type
== k_ent_npc
)
140 ent_npc
*npc
= mdl_arritm( &world
->ent_npc
, index
);
141 ent_npc_preupdate( npc
, active
);
145 /* additional renderings like text etc.. */
146 void world_entity_focus_render(void)
148 world_instance
*world
= world_current_instance();
149 if( skaterift
.activity
!= k_skaterift_ent_focus
){
150 skateshop_render_nonfocused( world
, &skaterift
.cam
);
154 u32 type
= mdl_entity_id_type( world_static
.focused_entity
),
155 index
= mdl_entity_id_id( world_static
.focused_entity
);
157 if( type
== k_ent_skateshop
){
158 ent_skateshop
*skateshop
= mdl_arritm( &world
->ent_skateshop
, index
);
159 skateshop_render( skateshop
);
161 else if( type
== k_ent_challenge
){}
162 else if( type
== k_ent_route
){}
163 else if( type
== k_ent_miniworld
){}
164 else if( type
== k_ent_npc
){}
166 vg_fatal_error( "Programming error\n" );
170 void world_gen_entities_init( world_instance
*world
)
173 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_light
); j
++ ){
174 ent_light
*light
= mdl_arritm( &world
->ent_light
, j
);
177 q_m3x3( light
->transform
.q
, to_world
);
178 v3_copy( light
->transform
.co
, to_world
[3] );
179 m4x3_invert_affine( to_world
, light
->inverse_world
);
181 light
->angle_sin_cos
[0] = sinf( light
->angle
* 0.5f
);
182 light
->angle_sin_cos
[1] = cosf( light
->angle
* 0.5f
);
185 vg_async_call( world_link_gates_async
, world
, 0 );
189 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_water
); j
++ ){
190 ent_water
*water
= mdl_arritm( &world
->ent_water
, j
);
191 if( world
->water
.enabled
){
192 vg_warn( "Multiple water surfaces in level!\n" );
196 world
->water
.enabled
= 1;
197 water_set_surface( world
, water
->transform
.co
[1] );
201 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_volume
); j
++ ){
202 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, j
);
203 mdl_transform_m4x3( &volume
->transform
, volume
->to_world
);
204 m4x3_invert_full( volume
->to_world
, volume
->to_local
);
208 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_audio
); j
++ ){
209 ent_audio
*audio
= mdl_arritm( &world
->ent_audio
, j
);
211 for( u32 k
=0; k
<audio
->clip_count
; k
++ ){
212 ent_audio_clip
*clip
= mdl_arritm( &world
->ent_audio_clip
,
213 audio
->clip_start
+k
);
215 if( clip
->_
.file
.pack_size
){
216 u32 size
= clip
->_
.file
.pack_size
,
217 offset
= clip
->_
.file
.pack_offset
;
219 /* embedded files are fine to clear the scratch buffer, only
220 * external audio uses it */
222 vg_linear_clear( vg_mem
.scratch
);
223 void *data
= vg_linear_alloc( vg_mem
.scratch
,
224 clip
->_
.file
.pack_size
);
226 mdl_fread_pack_file( &world
->meta
, &clip
->_
.file
, data
);
228 clip
->_
.clip
.path
= NULL
;
229 clip
->_
.clip
.flags
= audio
->flags
;
230 clip
->_
.clip
.data
= data
;
231 clip
->_
.clip
.size
= size
;
234 clip
->_
.clip
.path
= mdl_pstr(&world
->meta
,clip
->_
.file
.pstr_path
);
235 clip
->_
.clip
.flags
= audio
->flags
;
236 clip
->_
.clip
.data
= NULL
;
237 clip
->_
.clip
.size
= 0;
240 audio_clip_load( &clip
->_
.clip
, world
->heap
);
244 /* create generic entity hierachy for those who need it */
245 u32 indexed_count
= 0;
248 mdl_array_ptr
*array
;
251 { k_ent_gate
, &world
->ent_gate
},
252 { k_ent_objective
, &world
->ent_objective
},
253 { k_ent_volume
, &world
->ent_volume
},
254 { k_ent_challenge
, &world
->ent_challenge
},
255 { k_ent_glider
, &world
->ent_glider
},
256 { k_ent_npc
, &world
->ent_npc
}
259 for( u32 i
=0; i
<vg_list_size(indexables
); i
++ )
260 indexed_count
+= mdl_arrcount( indexables
[i
].array
);
261 vg_info( "indexing %u entities\n", indexed_count
);
263 world
->entity_list
= vg_linear_alloc( world
->heap
,
264 vg_align8(indexed_count
*sizeof(u32
)));
267 for( u32 i
=0; i
<vg_list_size(indexables
); i
++ ){
268 u32 type
= indexables
[i
].type
,
269 count
= mdl_arrcount( indexables
[i
].array
);
271 for( u32 j
=0; j
<count
; j
++ )
272 world
->entity_list
[index
++] = mdl_entity_id( type
, j
);
275 world
->entity_bh
= bh_create( world
->heap
, &bh_system_entity_list
, world
,
278 world
->tar_min
= world
->entity_bh
->nodes
[0].bbx
[0][1];
279 world
->tar_max
= world
->entity_bh
->nodes
[0].bbx
[1][1] + 20.0f
;
281 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_marker
); i
++ ){
282 ent_marker
*marker
= mdl_arritm( &world
->ent_marker
, i
);
284 if( MDL_CONST_PSTREQ( &world
->meta
, marker
->pstr_alias
, "tar_min" ) )
285 world
->tar_min
= marker
->transform
.co
[1];
287 if( MDL_CONST_PSTREQ( &world
->meta
, marker
->pstr_alias
, "tar_max" ) )
288 world
->tar_max
= marker
->transform
.co
[1];
292 ent_spawn
*world_find_closest_spawn( world_instance
*world
, v3f position
)
294 ent_spawn
*rp
= NULL
, *r
;
295 float min_dist
= INFINITY
;
297 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_spawn
); i
++ ){
298 r
= mdl_arritm( &world
->ent_spawn
, i
);
299 float d
= v3_dist2( r
->transform
.co
, position
);
308 if( mdl_arrcount(&world
->ent_spawn
) ){
309 vg_warn( "Invalid distances to spawns.. defaulting to first one.\n" );
310 return mdl_arritm( &world
->ent_spawn
, 0 );
313 vg_error( "There are no spawns in the level!\n" );
320 ent_spawn
*world_find_spawn_by_name( world_instance
*world
, const char *name
)
322 ent_spawn
*rp
= NULL
, *r
;
323 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_spawn
); i
++ ){
324 r
= mdl_arritm( &world
->ent_spawn
, i
);
325 if( !strcmp( mdl_pstr(&world
->meta
, r
->pstr_name
), name
) ){
332 vg_warn( "No spawn named '%s'\n", name
);
337 void world_default_spawn_pos( world_instance
*world
, v3f pos
)
339 ent_spawn
*rp
= world_find_spawn_by_name( world
, "start" );
340 if( !rp
) rp
= world_find_closest_spawn( world
, (v3f
){0,0,0} );
342 v3_copy( rp
->transform
.co
, pos
);
345 vg_error( "There are no valid spawns in the world\n" );
350 void ent_volume_call( world_instance
*world
, ent_call
*call
)
352 u32 index
= mdl_entity_id_id( call
->id
);
353 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, index
);
354 if( !volume
->target
) return;
356 if( call
->function
== k_ent_function_trigger
){
357 call
->id
= volume
->target
;
359 if( volume
->flags
& k_ent_volume_flag_particles
){
360 float *co
= alloca( sizeof(float)*3 );
361 co
[0] = vg_randf64(&vg
.rand
)*2.0f
-1.0f
;
362 co
[1] = vg_randf64(&vg
.rand
)*2.0f
-1.0f
;
363 co
[2] = vg_randf64(&vg
.rand
)*2.0f
-1.0f
;
364 m4x3_mulv( volume
->to_world
, co
, co
);
366 call
->function
= k_ent_function_particle_spawn
;
368 entity_call( world
, call
);
371 call
->function
= volume
->trigger
.event
;
372 entity_call( world
, call
);
375 else if( call
->function
== k_ent_function_trigger_leave
){
376 call
->id
= volume
->target
;
378 if( volume
->flags
& k_ent_volume_flag_particles
){
379 vg_warn( "Invalid condition; calling leave on particle volume.\n" );
382 call
->function
= volume
->trigger
.event_leave
;
383 entity_call( world
, call
);
388 void ent_audio_call( world_instance
*world
, ent_call
*call
)
390 if( world
->status
== k_world_status_unloading
){
391 vg_warn( "cannot modify audio while unloading world\n" );
395 u8 world_id
= (world
- world_static
.instances
) + 1;
396 u32 index
= mdl_entity_id_id( call
->id
);
397 ent_audio
*audio
= mdl_arritm( &world
->ent_audio
, index
);
401 if( call
->function
== k_ent_function_particle_spawn
){
402 v3_copy( call
->data
, sound_co
);
404 else if( call
->function
== k_ent_function_trigger
){
405 v3_copy( audio
->transform
.co
, sound_co
);
410 float chance
= vg_randf64(&vg
.rand
)*100.0f
,
413 for( u32 i
=0; i
<audio
->clip_count
; i
++ ){
414 ent_audio_clip
*clip
= mdl_arritm( &world
->ent_audio_clip
,
415 audio
->clip_start
+i
);
417 float mod
= world
->probabilities
[ audio
->probability_curve
],
418 p
= clip
->probability
* mod
;
425 if( audio
->behaviour
== k_channel_behaviour_unlimited
)
427 audio_oneshot_3d( &clip
->_
.clip
, sound_co
,
428 audio
->transform
.s
[0],
431 else if( audio
->behaviour
== k_channel_behaviour_discard_if_full
)
434 audio_get_group_idle_channel( audio
->group
,
435 audio
->max_channels
);
439 audio_channel_init( ch
, &clip
->_
.clip
, audio
->flags
);
440 audio_channel_group( ch
, audio
->group
);
441 audio_channel_world( ch
, world_id
);
442 audio_channel_set_spacial( ch
, sound_co
, audio
->transform
.s
[0] );
443 audio_channel_edit_volume( ch
, audio
->volume
, 1 );
444 ch
= audio_relinquish_channel( ch
);
447 else if( audio
->behaviour
== k_channel_behaviour_crossfade_if_full
)
450 audio_get_group_idle_channel( audio
->group
,
451 audio
->max_channels
);
455 audio_channel
*existing
=
456 audio_get_group_first_active_channel( audio
->group
);
459 if( existing
->source
== &clip
->_
.clip
){
465 existing
= audio_channel_fadeout(existing
, audio
->crossfade
);
468 ch
= audio_get_first_idle_channel();
473 audio_channel_init( ch
, &clip
->_
.clip
, audio
->flags
);
474 audio_channel_group( ch
, audio
->group
);
475 audio_channel_world( ch
, world_id
);
476 audio_channel_fadein( ch
, audio
->crossfade
);
477 ch
= audio_relinquish_channel( ch
);
488 void ent_ccmd_call( world_instance
*world
, ent_call
*call
)
490 if( call
->function
== k_ent_function_trigger
){
491 u32 index
= mdl_entity_id_id( call
->id
);
492 ent_ccmd
*ccmd
= mdl_arritm( &world
->ent_ccmd
, index
);
493 vg_execute_console_input( mdl_pstr(&world
->meta
, ccmd
->pstr_command
),
500 * ----------------------------------------------------------------------------
503 void entity_bh_expand_bound( void *user
, boxf bound
, u32 item_index
)
505 world_instance
*world
= user
;
507 u32 id
= world
->entity_list
[ item_index
],
508 type
= mdl_entity_id_type( id
),
509 index
= mdl_entity_id_id( id
);
511 if( type
== k_ent_gate
){
512 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, index
);
513 boxf box
= {{ -gate
->dimensions
[0], -gate
->dimensions
[1], -0.1f
},
514 { gate
->dimensions
[0], gate
->dimensions
[1], 0.1f
}};
516 m4x3_expand_aabb_aabb( gate
->to_world
, bound
, box
);
518 else if( type
== k_ent_objective
){
519 ent_objective
*objective
= mdl_arritm( &world
->ent_objective
, index
);
521 /* TODO: This might be more work than necessary. could maybe just get
522 * away with representing them as points */
527 for( u32 i
=0; i
<objective
->submesh_count
; i
++ ){
528 mdl_submesh
*sm
= mdl_arritm( &world
->meta
.submeshs
,
529 objective
->submesh_start
+i
);
530 box_concat( box
, sm
->bbx
);
534 mdl_transform_m4x3( &objective
->transform
, transform
);
535 m4x3_expand_aabb_aabb( transform
, bound
, box
);
537 else if( type
== k_ent_volume
){
538 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, index
);
539 m4x3_expand_aabb_aabb( volume
->to_world
, bound
,
540 (boxf
){{-1.0f
,-1.0f
,-1.0f
},{ 1.0f
, 1.0f
, 1.0f
}} );
542 else if( type
== k_ent_challenge
){
543 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
545 boxf box
= {{-1.2f
*0.5f
,-0.72f
*0.5f
,-0.01f
*0.5f
},
546 { 1.2f
*0.5f
, 0.72f
*0.5f
, 0.01f
*0.5f
}};
548 mdl_transform_m4x3( &challenge
->transform
, transform
);
549 m4x3_expand_aabb_aabb( transform
, bound
, box
);
551 else if( type
== k_ent_glider
){
552 ent_glider
*glider
= mdl_arritm( &world
->ent_glider
, index
);
554 mdl_transform_m4x3( &glider
->transform
, transform
);
555 m4x3_expand_aabb_aabb( transform
, bound
,
556 (boxf
){{-1.0f
,-1.0f
,-1.0f
},{ 1.0f
, 1.0f
, 1.0f
}} );
558 else if( type
== k_ent_npc
)
560 ent_npc
*npc
= mdl_arritm( &world
->ent_npc
, index
);
561 box_addpt( bound
, npc
->transform
.co
);
564 vg_fatal_error( "Programming error\n" );
568 float entity_bh_centroid( void *user
, u32 item_index
, int axis
)
570 world_instance
*world
= user
;
572 u32 id
= world
->entity_list
[ item_index
],
573 type
= mdl_entity_id_type( id
),
574 index
= mdl_entity_id_id( id
);
576 if( type
== k_ent_gate
){
577 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, index
);
578 return gate
->to_world
[3][axis
];
580 else if( type
== k_ent_objective
){
581 ent_objective
*objective
= mdl_arritm( &world
->ent_objective
, index
);
582 return objective
->transform
.co
[axis
];
584 else if( type
== k_ent_volume
){
585 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, index
);
586 return volume
->transform
.co
[axis
];
588 else if( type
== k_ent_challenge
)
590 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
591 return challenge
->transform
.co
[axis
];
593 else if( type
== k_ent_glider
)
595 ent_glider
*glider
= mdl_arritm( &world
->ent_glider
, index
);
596 return glider
->transform
.co
[axis
];
598 else if( type
== k_ent_npc
)
600 ent_npc
*npc
= mdl_arritm( &world
->ent_npc
, index
);
601 return npc
->transform
.co
[axis
];
605 vg_fatal_error( "Programming error\n" );
610 void entity_bh_swap( void *user
, u32 ia
, u32 ib
)
612 world_instance
*world
= user
;
614 u32 a
= world
->entity_list
[ ia
],
615 b
= world
->entity_list
[ ib
];
617 world
->entity_list
[ ia
] = b
;
618 world
->entity_list
[ ib
] = a
;
621 void entity_bh_debug( void *user
, u32 item_index
){
622 world_instance
*world
= user
;
624 u32 id
= world
->entity_list
[ item_index
],
625 type
= mdl_entity_id_type( id
),
626 index
= mdl_entity_id_id( id
);
628 if( type
== k_ent_gate
){
629 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, index
);
630 boxf box
= {{ -gate
->dimensions
[0], -gate
->dimensions
[1], -0.1f
},
631 { gate
->dimensions
[0], gate
->dimensions
[1], 0.1f
}};
632 vg_line_boxf_transformed( gate
->to_world
, box
, 0xf000ff00 );
634 else if( type
== k_ent_objective
){
635 ent_objective
*objective
= mdl_arritm( &world
->ent_objective
, index
);
639 for( u32 i
=0; i
<objective
->submesh_count
; i
++ ){
640 mdl_submesh
*sm
= mdl_arritm( &world
->meta
.submeshs
,
641 objective
->submesh_start
+i
);
642 box_concat( box
, sm
->bbx
);
646 mdl_transform_m4x3( &objective
->transform
, transform
);
647 vg_line_boxf_transformed( transform
, box
, 0xf000ff00 );
649 else if( type
== k_ent_volume
){
650 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, index
);
651 vg_line_boxf_transformed( volume
->to_world
,
652 (boxf
){{-1.0f
,-1.0f
,-1.0f
},{ 1.0f
, 1.0f
, 1.0f
}},
655 else if( type
== k_ent_challenge
){
656 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
658 boxf box
= {{-1.2f
*0.5f
,-0.72f
*0.5f
,-0.01f
*0.5f
},
659 { 1.2f
*0.5f
, 0.72f
*0.5f
, 0.01f
*0.5f
}};
661 mdl_transform_m4x3( &challenge
->transform
, transform
);
662 vg_line_boxf_transformed( transform
, box
, 0xf0ff0000 );
665 vg_fatal_error( "Programming error\n" );
669 void update_ach_models(void)
671 world_instance
*hub
= &world_static
.instances
[k_world_purpose_hub
];
672 if( hub
->status
!= k_world_status_loaded
) return;
674 for( u32 i
=0; i
<mdl_arrcount( &hub
->ent_prop
); i
++ ){
675 ent_prop
*prop
= mdl_arritm( &hub
->ent_prop
, i
);
676 if( prop
->flags
& 0x2 ){
677 if( MDL_CONST_PSTREQ( &hub
->meta
, prop
->pstr_alias
, "MARC" ) )
678 if( skaterift
.achievements
& 0x1 )
680 if( MDL_CONST_PSTREQ( &hub
->meta
, prop
->pstr_alias
, "ALBERT" ) )
681 if( skaterift
.achievements
& 0x2 )
683 if( MDL_CONST_PSTREQ( &hub
->meta
, prop
->pstr_alias
, "JANET" ) )
684 if( skaterift
.achievements
& 0x4 )
686 if( MDL_CONST_PSTREQ( &hub
->meta
, prop
->pstr_alias
, "BERNADETTA" ) )
687 if( skaterift
.achievements
& 0x8 )
693 void entity_bh_closest( void *user
, u32 item_index
, v3f point
, v3f closest
)
695 world_instance
*world
= user
;
697 u32 id
= world
->entity_list
[ item_index
],
698 type
= mdl_entity_id_type( id
),
699 index
= mdl_entity_id_id( id
);
701 if( type
== k_ent_gate
){
702 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, index
);
703 v3_copy( gate
->to_world
[3], closest
);
705 else if( type
== k_ent_objective
){
706 ent_objective
*challenge
= mdl_arritm( &world
->ent_objective
, index
);
707 v3_copy( challenge
->transform
.co
, closest
);
709 else if( type
== k_ent_volume
){
710 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, index
);
711 v3_copy( volume
->to_world
[3], closest
);
713 else if( type
== k_ent_challenge
){
714 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
715 v3_copy( challenge
->transform
.co
, closest
);
718 vg_fatal_error( "Programming error\n" );
722 void world_entity_start( world_instance
*world
, vg_msg
*sav
)
724 vg_info( "Start instance %p\n", world
);
726 world
->probabilities
[ k_probability_curve_constant
] = 1.0f
;
727 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_audio
); i
++ )
729 ent_audio
*audio
= mdl_arritm(&world
->ent_audio
,i
);
730 if( audio
->flags
& AUDIO_FLAG_AUTO_START
)
734 call
.function
= k_ent_function_trigger
;
735 call
.id
= mdl_entity_id( k_ent_audio
, i
);
736 entity_call( world
, &call
);
741 * ----------------------------------------------------------------------- */
743 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_challenge
); i
++ ){
744 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, i
);
745 const char *alias
= mdl_pstr( &world
->meta
, challenge
->pstr_alias
);
748 vg_msg_getkvintg( sav
, alias
, k_vg_msg_u32
, &result
);
754 call
.id
= mdl_entity_id( k_ent_challenge
, i
);
755 entity_call( world
, &call
);
759 vg_msg routes_block
= *sav
;
760 if( vg_msg_seekframe( &routes_block
, "routes" ) ){
761 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
762 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
764 vg_msg route_info
= routes_block
;
765 if( vg_msg_seekframe( &route_info
,
766 mdl_pstr(&world
->meta
,route
->pstr_name
) ) ){
769 vg_msg_getkvintg( &route_info
, "flags", k_vg_msg_u32
, &flags
);
770 route
->flags
|= flags
;
772 vg_msg_getkvintg( &route_info
, "best_laptime", k_vg_msg_f64
,
773 &route
->best_laptime
);
775 f32 sections
[ route
->checkpoints_count
];
777 if( vg_msg_getkvcmd( &route_info
, "sections", &cmd
) ){
778 vg_msg_cast( cmd
.value
, cmd
.code
, sections
,
780 vg_msg_count_bits(route
->checkpoints_count
) );
783 for( u32 j
=0; j
<route
->checkpoints_count
; j
++ )
787 for( u32 j
=0; j
<route
->checkpoints_count
; j
++ ){
788 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
,
789 route
->checkpoints_start
+ j
);
791 cp
->best_time
= sections
[j
];
794 /* LEGACY: check if steam achievements can give us a medal */
795 if( steam_ready
&& steam_stats_ready
){
796 for( u32 j
=0; j
<vg_list_size(track_infos
); j
++ ){
797 struct track_info
*inf
= &track_infos
[j
];
798 if( !strcmp(inf
->name
,
799 mdl_pstr(&world
->meta
,route
->pstr_name
))){
801 steamapi_bool set
= 0;
802 if( SteamAPI_ISteamUserStats_GetAchievement(
803 hSteamUserStats
, inf
->achievement_id
, &set
) )
806 route
->flags
|= k_ent_route_flag_achieve_silver
;
816 ent_region_re_eval( world
);
819 void world_entity_serialize( world_instance
*world
, vg_msg
*sav
)
821 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_challenge
); i
++ ){
822 ent_challenge
*challenge
= mdl_arritm(&world
->ent_challenge
,i
);
824 const char *alias
= mdl_pstr(&world
->meta
,challenge
->pstr_alias
);
825 vg_msg_wkvnum( sav
, alias
, k_vg_msg_u32
, 1, &challenge
->status
);
828 if( mdl_arrcount(&world
->ent_route
) ){
829 vg_msg_frame( sav
, "routes" );
830 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
831 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
833 vg_msg_frame( sav
, mdl_pstr( &world
->meta
, route
->pstr_name
) );
835 vg_msg_wkvnum( sav
, "flags", k_vg_msg_u32
, 1, &route
->flags
);
836 vg_msg_wkvnum( sav
, "best_laptime",
837 k_vg_msg_f64
, 1, &route
->best_laptime
);
839 f32 sections
[ route
->checkpoints_count
];
841 for( u32 j
=0; j
<route
->checkpoints_count
; j
++ ){
842 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
,
843 route
->checkpoints_start
+ j
);
845 sections
[j
] = cp
->best_time
;
848 vg_msg_wkvnum( sav
, "sections", k_vg_msg_f32
,
849 route
->checkpoints_count
, sections
);
851 vg_msg_end_frame( sav
);
853 vg_msg_end_frame( sav
);