- /* Allocate dynamic world memory arena */
- u32 max_size = 76*1024*1024;
- world.dynamic_vgl = vg_create_linear_allocator( vg_mem.rtmemory, max_size,
- VG_MEMORY_SYSTEM );
-}
-
-VG_STATIC void world_audio_init(void)
-{
- u32 size = vg_linear_remaining( vg_audio.audio_pool )
- - sizeof(vg_linear_allocator);
-
- world.audio_vgl = vg_create_linear_allocator( vg_audio.audio_pool,
- size, VG_MEMORY_SYSTEM );
-}
-
-VG_STATIC void world_trigger_achievement( u32 uid )
-{
- struct logic_achievement *ach = &world.logic_achievements[ uid ];
-
- if( ach->achieved )
- return;
-
- steam_set_achievement( ach->achievement_id );
- steam_store_achievements();
-
- ach->achieved = 1;
-}
-
-VG_STATIC void world_run_relay( struct relay_target *rt );
-VG_STATIC void world_trigger_relay( u32 uid )
-{
- struct logic_relay *relay = &world.logic_relays[ uid ];
-
- for( int i=0; i<relay->target_count; i++ )
- {
- world_run_relay( &relay->targets[i] );
- }
-}
-
-VG_STATIC void world_trigger_audio( u32 uid )
-{
- struct world_audio_thing *wat = &world.audio_things[ uid ];
-
- audio_lock();
- audio_player_playclip( &wat->player,
- &wat->temp_embedded_clip );
- audio_unlock();
-}
-
-VG_STATIC void world_run_relay( struct relay_target *rt )
-{
- struct entity_instruction
- {
- enum classtype classtype;
- void (*p_trigger)( u32 uid );
- }
- entity_instructions[] =
- {
- { k_classtype_logic_achievement, world_trigger_achievement },
- { k_classtype_logic_relay, world_trigger_relay },
- { k_classtype_audio, world_trigger_audio }
- };
-
- for( int i=0; i<vg_list_size(entity_instructions); i++ )
- {
- struct entity_instruction *instr = &entity_instructions[i];
-
- if( instr->classtype == rt->classtype )
- {
- instr->p_trigger( rt->sub_id );
- return;
- }
- }
-
- vg_error( "Don't know how to trigger classtype %d\n", rt->classtype );
-}
-
-VG_STATIC void world_update( v3f pos )
-{
- if( world.switching_to_new_world )
- {
- int all_stopped = 1;
-
- audio_lock();
- for( int i=0; i<world.audio_things_count; i++ )
- {
- struct world_audio_thing *at = &world.audio_things[i];
-
- if( audio_player_is_playing( &at->player ) )
- {
- all_stopped = 0;
- break;
- }
- }
- audio_unlock();
-
- if( all_stopped )
- {
- world.switching_to_new_world = 0;
- world_unload();
- vg_loader_start( world_load );
- return;
- }
- }
-
- world.sky_time += world.sky_rate * vg.time_delta;
- world.sky_rate = vg_lerp( world.sky_rate, world.sky_target_rate,
- vg.time_delta * 5.0 );
-
- world_routes_update();
-#if 0
- world_routes_debug();
-#endif
-
- if( world.route_count > 0 )
- {
- int closest = 0;
- float min_dist = INFINITY;
-
- for( int i=0; i<world.route_count; i++ )
- {
- float d = v3_dist2( world.routes[i].scoreboard_transform[3], pos );
-
- if( d < min_dist )
- {
- min_dist = d;
- closest = i;
- }
- }
-
- if( (world.active_route_board != closest) || network_scores_updated )
- {
- network_scores_updated = 0;
- world.active_route_board = closest;
-
- struct route *route = &world.routes[closest];
-
- u32 id = route->track_id;
-
- if( id != 0xffffffff )
- {
- struct netmsg_board *local_board =
- &scoreboard_client_data.boards[id];
-
- for( int i=0; i<13; i++ )
- {
- sfd_encode( i, &local_board->data[27*i] );
- }
- }
- }
- }
-
- int in_trigger = 0;
- for( int i=0; i<world.trigger_count; i++ )
- {
- struct trigger_zone *zone = &world.triggers[i];
-
- v3f local;
- m4x3_mulv( zone->inv_transform, pos, local );
-
- if( (fabsf(local[0]) <= 1.0f) &&
- (fabsf(local[1]) <= 1.0f) &&
- (fabsf(local[2]) <= 1.0f) )
- {
- in_trigger = 1;
-
- if( !world.in_trigger )
- {
- world_run_relay( &zone->target );
- }
- }
-
- vg_line_boxf_transformed( zone->transform, (boxf){{-1.0f,-1.0f,-1.0f},
- { 1.0f, 1.0f, 1.0f}},
- 0xff00ff00 );
- }