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"
17 #include "ent_camera.h"
19 #include "player_walk.h"
21 bh_system bh_system_entity_list
=
23 .expand_bound
= entity_bh_expand_bound
,
24 .item_centroid
= entity_bh_centroid
,
25 .item_closest
= entity_bh_closest
,
26 .item_swap
= entity_bh_swap
,
27 .item_debug
= entity_bh_debug
,
31 void world_entity_set_focus( u32 entity_id
)
33 if( world_static
.focused_entity
)
35 vg_warn( "Entity %u#%u tried to take focus from %u#%u\n",
36 mdl_entity_id_type( entity_id
),
37 mdl_entity_id_id( entity_id
),
38 mdl_entity_id_type( world_static
.focused_entity
),
39 mdl_entity_id_id( world_static
.focused_entity
) );
43 world_static
.focused_entity
= entity_id
;
46 void world_entity_focus_modal(void)
48 localplayer
.immobile
= 1;
49 menu
.disable_open
= 1;
50 srinput
.state
= k_input_state_resume
;
52 v3_zero( localplayer
.rb
.v
);
53 v3_zero( localplayer
.rb
.w
);
54 player_walk
.move_speed
= 0.0f
;
55 skaterift
.activity
= k_skaterift_ent_focus
;
58 void world_entity_exit_modal(void)
60 if( skaterift
.activity
!= k_skaterift_ent_focus
)
62 vg_warn( "Entity %u#%u tried to exit modal when we weren't in one\n",
63 mdl_entity_id_type( world_static
.focused_entity
),
64 mdl_entity_id_id( world_static
.focused_entity
) );
68 localplayer
.immobile
= 0;
69 menu
.disable_open
= 0;
70 srinput
.state
= k_input_state_resume
;
71 skaterift
.activity
= k_skaterift_default
;
74 void world_entity_clear_focus(void)
76 if( skaterift
.activity
== k_skaterift_ent_focus
)
78 vg_warn( "Entity %u#%u tried to clear focus before exiting modal\n",
79 mdl_entity_id_type( world_static
.focused_entity
),
80 mdl_entity_id_id( world_static
.focused_entity
) );
84 world_static
.focused_entity
= 0;
87 void world_entity_focus_camera( world_instance
*world
, u32 uid
)
89 if( mdl_entity_id_type( uid
) == k_ent_camera
)
91 u32 index
= mdl_entity_id_id( uid
);
92 ent_camera
*cam
= mdl_arritm( &world
->ent_camera
, index
);
93 ent_camera_unpack( cam
, &world_static
.focus_cam
);
97 vg_camera_copy( &localplayer
.cam
, &world_static
.focus_cam
);
100 world_static
.focus_cam
.nearz
= localplayer
.cam
.nearz
;
101 world_static
.focus_cam
.farz
= localplayer
.cam
.farz
;
105 /* logic preupdate */
106 void world_entity_focus_preupdate(void)
108 f32 rate
= vg_minf( 1.0f
, vg
.time_frame_delta
* 2.0f
);
110 if( skaterift
.activity
== k_skaterift_ent_focus
)
113 vg_slewf( &world_static
.focus_strength
, active
,
114 vg
.time_frame_delta
* (1.0f
/0.5f
) );
116 if( world_static
.focused_entity
== 0 )
119 u32 type
= mdl_entity_id_type( world_static
.focused_entity
),
120 index
= mdl_entity_id_id( world_static
.focused_entity
);
122 world_instance
*world
= world_current_instance();
124 static void (*table
[])( ent_focus_context
*ctx
) =
126 [ k_ent_skateshop
] = ent_skateshop_preupdate
,
127 [ k_ent_challenge
] = ent_challenge_preupdate
,
128 [ k_ent_route
] = ent_route_preupdate
,
129 [ k_ent_npc
] = ent_npc_preupdate
,
132 if( (type
> vg_list_size(table
)) || (table
[type
] == NULL
) )
134 vg_fatal_error( "No pre-update method set for entity (%u#%u)\n",
138 table
[type
]( &(ent_focus_context
){
141 .active
= active
} );
144 /* additional renderings like text etc.. */
145 void world_entity_focus_render(void)
147 world_instance
*world
= world_current_instance();
148 if( skaterift
.activity
!= k_skaterift_ent_focus
){
149 skateshop_render_nonfocused( world
, &skaterift
.cam
);
153 u32 type
= mdl_entity_id_type( world_static
.focused_entity
),
154 index
= mdl_entity_id_id( world_static
.focused_entity
);
156 if( type
== k_ent_skateshop
){
157 ent_skateshop
*skateshop
= mdl_arritm( &world
->ent_skateshop
, index
);
158 skateshop_render( skateshop
);
160 else if( type
== k_ent_challenge
){}
161 else if( type
== k_ent_route
){}
162 else if( type
== k_ent_miniworld
){}
163 else if( type
== k_ent_npc
){}
165 vg_fatal_error( "Programming error\n" );
169 void world_gen_entities_init( world_instance
*world
)
172 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_light
); j
++ ){
173 ent_light
*light
= mdl_arritm( &world
->ent_light
, j
);
176 q_m3x3( light
->transform
.q
, to_world
);
177 v3_copy( light
->transform
.co
, to_world
[3] );
178 m4x3_invert_affine( to_world
, light
->inverse_world
);
180 light
->angle_sin_cos
[0] = sinf( light
->angle
* 0.5f
);
181 light
->angle_sin_cos
[1] = cosf( light
->angle
* 0.5f
);
184 vg_async_call( world_link_gates_async
, world
, 0 );
188 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_water
); j
++ ){
189 ent_water
*water
= mdl_arritm( &world
->ent_water
, j
);
190 if( world
->water
.enabled
){
191 vg_warn( "Multiple water surfaces in level!\n" );
195 world
->water
.enabled
= 1;
196 water_set_surface( world
, water
->transform
.co
[1] );
200 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_volume
); j
++ ){
201 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, j
);
202 mdl_transform_m4x3( &volume
->transform
, volume
->to_world
);
203 m4x3_invert_full( volume
->to_world
, volume
->to_local
);
207 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_audio
); j
++ ){
208 ent_audio
*audio
= mdl_arritm( &world
->ent_audio
, j
);
210 for( u32 k
=0; k
<audio
->clip_count
; k
++ ){
211 ent_audio_clip
*clip
= mdl_arritm( &world
->ent_audio_clip
,
212 audio
->clip_start
+k
);
214 if( clip
->_
.file
.pack_size
){
215 u32 size
= clip
->_
.file
.pack_size
,
216 offset
= clip
->_
.file
.pack_offset
;
218 /* embedded files are fine to clear the scratch buffer, only
219 * external audio uses it */
221 vg_linear_clear( vg_mem
.scratch
);
222 void *data
= vg_linear_alloc( vg_mem
.scratch
,
223 clip
->_
.file
.pack_size
);
225 mdl_fread_pack_file( &world
->meta
, &clip
->_
.file
, data
);
227 clip
->_
.clip
.path
= NULL
;
228 clip
->_
.clip
.flags
= audio
->flags
;
229 clip
->_
.clip
.data
= data
;
230 clip
->_
.clip
.size
= size
;
233 clip
->_
.clip
.path
= mdl_pstr(&world
->meta
,clip
->_
.file
.pstr_path
);
234 clip
->_
.clip
.flags
= audio
->flags
;
235 clip
->_
.clip
.data
= NULL
;
236 clip
->_
.clip
.size
= 0;
239 audio_clip_load( &clip
->_
.clip
, world
->heap
);
243 /* create generic entity hierachy for those who need it */
244 u32 indexed_count
= 0;
247 mdl_array_ptr
*array
;
250 { k_ent_gate
, &world
->ent_gate
},
251 { k_ent_objective
, &world
->ent_objective
},
252 { k_ent_volume
, &world
->ent_volume
},
253 { k_ent_challenge
, &world
->ent_challenge
},
254 { k_ent_glider
, &world
->ent_glider
},
255 { k_ent_npc
, &world
->ent_npc
}
258 for( u32 i
=0; i
<vg_list_size(indexables
); i
++ )
259 indexed_count
+= mdl_arrcount( indexables
[i
].array
);
260 vg_info( "indexing %u entities\n", indexed_count
);
262 world
->entity_list
= vg_linear_alloc( world
->heap
,
263 vg_align8(indexed_count
*sizeof(u32
)));
266 for( u32 i
=0; i
<vg_list_size(indexables
); i
++ ){
267 u32 type
= indexables
[i
].type
,
268 count
= mdl_arrcount( indexables
[i
].array
);
270 for( u32 j
=0; j
<count
; j
++ )
271 world
->entity_list
[index
++] = mdl_entity_id( type
, j
);
274 world
->entity_bh
= bh_create( world
->heap
, &bh_system_entity_list
, world
,
277 world
->tar_min
= world
->entity_bh
->nodes
[0].bbx
[0][1];
278 world
->tar_max
= world
->entity_bh
->nodes
[0].bbx
[1][1] + 20.0f
;
280 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_marker
); i
++ ){
281 ent_marker
*marker
= mdl_arritm( &world
->ent_marker
, i
);
283 if( MDL_CONST_PSTREQ( &world
->meta
, marker
->pstr_alias
, "tar_min" ) )
284 world
->tar_min
= marker
->transform
.co
[1];
286 if( MDL_CONST_PSTREQ( &world
->meta
, marker
->pstr_alias
, "tar_max" ) )
287 world
->tar_max
= marker
->transform
.co
[1];
291 ent_spawn
*world_find_closest_spawn( world_instance
*world
, v3f position
)
293 ent_spawn
*rp
= NULL
, *r
;
294 float min_dist
= INFINITY
;
296 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_spawn
); i
++ ){
297 r
= mdl_arritm( &world
->ent_spawn
, i
);
298 float d
= v3_dist2( r
->transform
.co
, position
);
307 if( mdl_arrcount(&world
->ent_spawn
) ){
308 vg_warn( "Invalid distances to spawns.. defaulting to first one.\n" );
309 return mdl_arritm( &world
->ent_spawn
, 0 );
312 vg_error( "There are no spawns in the level!\n" );
319 ent_spawn
*world_find_spawn_by_name( world_instance
*world
, const char *name
)
321 ent_spawn
*rp
= NULL
, *r
;
322 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_spawn
); i
++ ){
323 r
= mdl_arritm( &world
->ent_spawn
, i
);
324 if( !strcmp( mdl_pstr(&world
->meta
, r
->pstr_name
), name
) ){
331 vg_warn( "No spawn named '%s'\n", name
);
336 void world_default_spawn_pos( world_instance
*world
, v3f pos
)
338 ent_spawn
*rp
= world_find_spawn_by_name( world
, "start" );
339 if( !rp
) rp
= world_find_closest_spawn( world
, (v3f
){0,0,0} );
341 v3_copy( rp
->transform
.co
, pos
);
344 vg_error( "There are no valid spawns in the world\n" );
349 entity_call_result
ent_volume_call( world_instance
*world
, ent_call
*call
)
351 u32 index
= mdl_entity_id_id( call
->id
);
352 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, index
);
354 if( !volume
->target
)
355 return k_entity_call_result_OK
;
357 if( call
->function
== k_ent_function_trigger
)
359 call
->id
= volume
->target
;
361 if( volume
->flags
& k_ent_volume_flag_particles
)
363 float *co
= alloca( sizeof(float)*3 );
364 co
[0] = vg_randf64(&vg
.rand
)*2.0f
-1.0f
;
365 co
[1] = vg_randf64(&vg
.rand
)*2.0f
-1.0f
;
366 co
[2] = vg_randf64(&vg
.rand
)*2.0f
-1.0f
;
367 m4x3_mulv( volume
->to_world
, co
, co
);
369 call
->function
= k_ent_function_particle_spawn
;
371 entity_call( world
, call
);
375 call
->function
= volume
->trigger
.event
;
376 entity_call( world
, call
);
379 return k_entity_call_result_OK
;
381 else if( call
->function
== k_ent_function_trigger_leave
)
383 call
->id
= volume
->target
;
385 if( volume
->flags
& k_ent_volume_flag_particles
)
387 vg_warn( "Invalid condition; calling leave on particle volume.\n" );
391 call
->function
= volume
->trigger
.event_leave
;
392 entity_call( world
, call
);
395 return k_entity_call_result_OK
;
398 return k_entity_call_result_unhandled
;
401 entity_call_result
ent_audio_call( world_instance
*world
, ent_call
*call
)
403 if( world
->status
== k_world_status_unloading
)
405 vg_warn( "cannot modify audio while unloading world\n" );
406 return k_entity_call_result_invalid
;
409 u8 world_id
= (world
- world_static
.instances
) + 1;
410 u32 index
= mdl_entity_id_id( call
->id
);
411 ent_audio
*audio
= mdl_arritm( &world
->ent_audio
, index
);
415 if( call
->function
== k_ent_function_particle_spawn
)
417 v3_copy( call
->data
, sound_co
);
419 else if( call
->function
== k_ent_function_trigger
)
421 v3_copy( audio
->transform
.co
, sound_co
);
424 return k_entity_call_result_unhandled
;
426 float chance
= vg_randf64(&vg
.rand
)*100.0f
,
429 for( u32 i
=0; i
<audio
->clip_count
; i
++ ){
430 ent_audio_clip
*clip
= mdl_arritm( &world
->ent_audio_clip
,
431 audio
->clip_start
+i
);
433 float mod
= world
->probabilities
[ audio
->probability_curve
],
434 p
= clip
->probability
* mod
;
441 if( audio
->behaviour
== k_channel_behaviour_unlimited
)
443 audio_oneshot_3d( &clip
->_
.clip
, sound_co
,
444 audio
->transform
.s
[0],
447 else if( audio
->behaviour
== k_channel_behaviour_discard_if_full
)
450 audio_get_group_idle_channel( audio
->group
,
451 audio
->max_channels
);
455 audio_channel_init( ch
, &clip
->_
.clip
, audio
->flags
);
456 audio_channel_group( ch
, audio
->group
);
457 audio_channel_world( ch
, world_id
);
458 audio_channel_set_spacial( ch
, sound_co
, audio
->transform
.s
[0] );
459 audio_channel_edit_volume( ch
, audio
->volume
, 1 );
460 ch
= audio_relinquish_channel( ch
);
463 else if( audio
->behaviour
== k_channel_behaviour_crossfade_if_full
)
466 audio_get_group_idle_channel( audio
->group
,
467 audio
->max_channels
);
471 audio_channel
*existing
=
472 audio_get_group_first_active_channel( audio
->group
);
475 if( existing
->source
== &clip
->_
.clip
){
477 return k_entity_call_result_OK
;
481 existing
= audio_channel_fadeout(existing
, audio
->crossfade
);
484 ch
= audio_get_first_idle_channel();
489 audio_channel_init( ch
, &clip
->_
.clip
, audio
->flags
);
490 audio_channel_group( ch
, audio
->group
);
491 audio_channel_world( ch
, world_id
);
492 audio_channel_fadein( ch
, audio
->crossfade
);
493 ch
= audio_relinquish_channel( ch
);
498 return k_entity_call_result_OK
;
501 return k_entity_call_result_OK
;
505 entity_call_result
ent_ccmd_call( world_instance
*world
, ent_call
*call
)
507 if( call
->function
== k_ent_function_trigger
)
509 u32 index
= mdl_entity_id_id( call
->id
);
510 ent_ccmd
*ccmd
= mdl_arritm( &world
->ent_ccmd
, index
);
511 vg_execute_console_input( mdl_pstr(&world
->meta
, ccmd
->pstr_command
), 0 );
512 return k_entity_call_result_OK
;
515 return k_entity_call_result_unhandled
;
520 * ----------------------------------------------------------------------------
523 void entity_bh_expand_bound( void *user
, boxf bound
, u32 item_index
)
525 world_instance
*world
= user
;
527 u32 id
= world
->entity_list
[ item_index
],
528 type
= mdl_entity_id_type( id
),
529 index
= mdl_entity_id_id( id
);
531 if( type
== k_ent_gate
){
532 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, index
);
533 boxf box
= {{ -gate
->dimensions
[0], -gate
->dimensions
[1], -0.1f
},
534 { gate
->dimensions
[0], gate
->dimensions
[1], 0.1f
}};
536 m4x3_expand_aabb_aabb( gate
->to_world
, bound
, box
);
538 else if( type
== k_ent_objective
){
539 ent_objective
*objective
= mdl_arritm( &world
->ent_objective
, index
);
541 /* TODO: This might be more work than necessary. could maybe just get
542 * away with representing them as points */
547 for( u32 i
=0; i
<objective
->submesh_count
; i
++ ){
548 mdl_submesh
*sm
= mdl_arritm( &world
->meta
.submeshs
,
549 objective
->submesh_start
+i
);
550 box_concat( box
, sm
->bbx
);
554 mdl_transform_m4x3( &objective
->transform
, transform
);
555 m4x3_expand_aabb_aabb( transform
, bound
, box
);
557 else if( type
== k_ent_volume
){
558 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, index
);
559 m4x3_expand_aabb_aabb( volume
->to_world
, bound
,
560 (boxf
){{-1.0f
,-1.0f
,-1.0f
},{ 1.0f
, 1.0f
, 1.0f
}} );
562 else if( type
== k_ent_challenge
){
563 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
565 boxf box
= {{-1.2f
*0.5f
,-0.72f
*0.5f
,-0.01f
*0.5f
},
566 { 1.2f
*0.5f
, 0.72f
*0.5f
, 0.01f
*0.5f
}};
568 mdl_transform_m4x3( &challenge
->transform
, transform
);
569 m4x3_expand_aabb_aabb( transform
, bound
, box
);
571 else if( type
== k_ent_glider
){
572 ent_glider
*glider
= mdl_arritm( &world
->ent_glider
, index
);
574 mdl_transform_m4x3( &glider
->transform
, transform
);
575 m4x3_expand_aabb_aabb( transform
, bound
,
576 (boxf
){{-1.0f
,-1.0f
,-1.0f
},{ 1.0f
, 1.0f
, 1.0f
}} );
578 else if( type
== k_ent_npc
)
580 ent_npc
*npc
= mdl_arritm( &world
->ent_npc
, index
);
581 box_addpt( bound
, npc
->transform
.co
);
584 vg_fatal_error( "Programming error\n" );
588 float entity_bh_centroid( void *user
, u32 item_index
, int axis
)
590 world_instance
*world
= user
;
592 u32 id
= world
->entity_list
[ item_index
],
593 type
= mdl_entity_id_type( id
),
594 index
= mdl_entity_id_id( id
);
596 if( type
== k_ent_gate
){
597 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, index
);
598 return gate
->to_world
[3][axis
];
600 else if( type
== k_ent_objective
){
601 ent_objective
*objective
= mdl_arritm( &world
->ent_objective
, index
);
602 return objective
->transform
.co
[axis
];
604 else if( type
== k_ent_volume
){
605 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, index
);
606 return volume
->transform
.co
[axis
];
608 else if( type
== k_ent_challenge
)
610 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
611 return challenge
->transform
.co
[axis
];
613 else if( type
== k_ent_glider
)
615 ent_glider
*glider
= mdl_arritm( &world
->ent_glider
, index
);
616 return glider
->transform
.co
[axis
];
618 else if( type
== k_ent_npc
)
620 ent_npc
*npc
= mdl_arritm( &world
->ent_npc
, index
);
621 return npc
->transform
.co
[axis
];
625 vg_fatal_error( "Programming error\n" );
630 void entity_bh_swap( void *user
, u32 ia
, u32 ib
)
632 world_instance
*world
= user
;
634 u32 a
= world
->entity_list
[ ia
],
635 b
= world
->entity_list
[ ib
];
637 world
->entity_list
[ ia
] = b
;
638 world
->entity_list
[ ib
] = a
;
641 void entity_bh_debug( void *user
, u32 item_index
){
642 world_instance
*world
= user
;
644 u32 id
= world
->entity_list
[ item_index
],
645 type
= mdl_entity_id_type( id
),
646 index
= mdl_entity_id_id( id
);
648 if( type
== k_ent_gate
){
649 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, index
);
650 boxf box
= {{ -gate
->dimensions
[0], -gate
->dimensions
[1], -0.1f
},
651 { gate
->dimensions
[0], gate
->dimensions
[1], 0.1f
}};
652 vg_line_boxf_transformed( gate
->to_world
, box
, 0xf000ff00 );
654 else if( type
== k_ent_objective
){
655 ent_objective
*objective
= mdl_arritm( &world
->ent_objective
, index
);
659 for( u32 i
=0; i
<objective
->submesh_count
; i
++ ){
660 mdl_submesh
*sm
= mdl_arritm( &world
->meta
.submeshs
,
661 objective
->submesh_start
+i
);
662 box_concat( box
, sm
->bbx
);
666 mdl_transform_m4x3( &objective
->transform
, transform
);
667 vg_line_boxf_transformed( transform
, box
, 0xf000ff00 );
669 else if( type
== k_ent_volume
){
670 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, index
);
671 vg_line_boxf_transformed( volume
->to_world
,
672 (boxf
){{-1.0f
,-1.0f
,-1.0f
},{ 1.0f
, 1.0f
, 1.0f
}},
675 else if( type
== k_ent_challenge
){
676 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
678 boxf box
= {{-1.2f
*0.5f
,-0.72f
*0.5f
,-0.01f
*0.5f
},
679 { 1.2f
*0.5f
, 0.72f
*0.5f
, 0.01f
*0.5f
}};
681 mdl_transform_m4x3( &challenge
->transform
, transform
);
682 vg_line_boxf_transformed( transform
, box
, 0xf0ff0000 );
685 vg_fatal_error( "Programming error\n" );
689 void update_ach_models(void)
691 world_instance
*hub
= &world_static
.instances
[k_world_purpose_hub
];
692 if( hub
->status
!= k_world_status_loaded
) return;
694 for( u32 i
=0; i
<mdl_arrcount( &hub
->ent_prop
); i
++ ){
695 ent_prop
*prop
= mdl_arritm( &hub
->ent_prop
, i
);
696 if( prop
->flags
& 0x2 ){
697 if( MDL_CONST_PSTREQ( &hub
->meta
, prop
->pstr_alias
, "MARC" ) )
698 if( skaterift
.achievements
& 0x1 )
700 if( MDL_CONST_PSTREQ( &hub
->meta
, prop
->pstr_alias
, "ALBERT" ) )
701 if( skaterift
.achievements
& 0x2 )
703 if( MDL_CONST_PSTREQ( &hub
->meta
, prop
->pstr_alias
, "JANET" ) )
704 if( skaterift
.achievements
& 0x4 )
706 if( MDL_CONST_PSTREQ( &hub
->meta
, prop
->pstr_alias
, "BERNADETTA" ) )
707 if( skaterift
.achievements
& 0x8 )
713 void entity_bh_closest( void *user
, u32 item_index
, v3f point
, v3f closest
)
715 world_instance
*world
= user
;
717 u32 id
= world
->entity_list
[ item_index
],
718 type
= mdl_entity_id_type( id
),
719 index
= mdl_entity_id_id( id
);
721 if( type
== k_ent_gate
){
722 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, index
);
723 v3_copy( gate
->to_world
[3], closest
);
725 else if( type
== k_ent_objective
){
726 ent_objective
*challenge
= mdl_arritm( &world
->ent_objective
, index
);
727 v3_copy( challenge
->transform
.co
, closest
);
729 else if( type
== k_ent_volume
){
730 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, index
);
731 v3_copy( volume
->to_world
[3], closest
);
733 else if( type
== k_ent_challenge
){
734 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
735 v3_copy( challenge
->transform
.co
, closest
);
738 vg_fatal_error( "Programming error\n" );
742 void world_entity_start( world_instance
*world
, vg_msg
*sav
)
744 vg_info( "Start instance %p\n", world
);
746 world
->probabilities
[ k_probability_curve_constant
] = 1.0f
;
747 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_audio
); i
++ )
749 ent_audio
*audio
= mdl_arritm(&world
->ent_audio
,i
);
750 if( audio
->flags
& AUDIO_FLAG_AUTO_START
)
754 call
.function
= k_ent_function_trigger
;
755 call
.id
= mdl_entity_id( k_ent_audio
, i
);
756 entity_call( world
, &call
);
761 * ----------------------------------------------------------------------- */
763 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_challenge
); i
++ ){
764 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, i
);
765 const char *alias
= mdl_pstr( &world
->meta
, challenge
->pstr_alias
);
768 vg_msg_getkvintg( sav
, alias
, k_vg_msg_u32
, &result
, NULL
);
774 call
.id
= mdl_entity_id( k_ent_challenge
, i
);
775 entity_call( world
, &call
);
779 vg_msg routes_block
= *sav
;
780 if( vg_msg_seekframe( &routes_block
, "routes" ) ){
781 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
782 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
784 vg_msg route_info
= routes_block
;
785 if( vg_msg_seekframe( &route_info
,
786 mdl_pstr(&world
->meta
,route
->pstr_name
) ) ){
789 vg_msg_getkvintg( &route_info
, "flags", k_vg_msg_u32
,
791 route
->flags
|= flags
;
793 vg_msg_getkvintg( &route_info
, "best_laptime", k_vg_msg_f64
,
794 &route
->best_laptime
, NULL
);
796 f32 sections
[ route
->checkpoints_count
];
798 if( vg_msg_getkvcmd( &route_info
, "sections", &cmd
) ){
799 vg_msg_cast( cmd
.value
, cmd
.code
, sections
,
801 vg_msg_count_bits(route
->checkpoints_count
) );
804 for( u32 j
=0; j
<route
->checkpoints_count
; j
++ )
808 for( u32 j
=0; j
<route
->checkpoints_count
; j
++ ){
809 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
,
810 route
->checkpoints_start
+ j
);
812 cp
->best_time
= sections
[j
];
815 /* LEGACY: check if steam achievements can give us a medal */
816 if( steam_ready
&& steam_stats_ready
){
817 for( u32 j
=0; j
<vg_list_size(track_infos
); j
++ ){
818 struct track_info
*inf
= &track_infos
[j
];
819 if( !strcmp(inf
->name
,
820 mdl_pstr(&world
->meta
,route
->pstr_name
))){
822 steamapi_bool set
= 0;
823 if( SteamAPI_ISteamUserStats_GetAchievement(
824 hSteamUserStats
, inf
->achievement_id
, &set
) )
827 route
->flags
|= k_ent_route_flag_achieve_silver
;
837 ent_region_re_eval( world
);
840 void world_entity_serialize( world_instance
*world
, vg_msg
*sav
)
842 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_challenge
); i
++ ){
843 ent_challenge
*challenge
= mdl_arritm(&world
->ent_challenge
,i
);
845 const char *alias
= mdl_pstr(&world
->meta
,challenge
->pstr_alias
);
846 vg_msg_wkvnum( sav
, alias
, k_vg_msg_u32
, 1, &challenge
->status
);
849 if( mdl_arrcount(&world
->ent_route
) ){
850 vg_msg_frame( sav
, "routes" );
851 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
852 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
854 vg_msg_frame( sav
, mdl_pstr( &world
->meta
, route
->pstr_name
) );
856 vg_msg_wkvnum( sav
, "flags", k_vg_msg_u32
, 1, &route
->flags
);
857 vg_msg_wkvnum( sav
, "best_laptime",
858 k_vg_msg_f64
, 1, &route
->best_laptime
);
860 f32 sections
[ route
->checkpoints_count
];
862 for( u32 j
=0; j
<route
->checkpoints_count
; j
++ ){
863 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
,
864 route
->checkpoints_start
+ j
);
866 sections
[j
] = cp
->best_time
;
869 vg_msg_wkvnum( sav
, "sections", k_vg_msg_f32
,
870 route
->checkpoints_count
, sections
);
872 vg_msg_end_frame( sav
);
874 vg_msg_end_frame( sav
);