+ /* free meshes */
+ mesh_free( &world->mesh_route_lines );
+ mesh_free( &world->mesh_geo );
+ mesh_free( &world->mesh_no_collide );
+
+ glDeleteBuffers( 1, &world->tbo_light_entities );
+ glDeleteTextures( 1, &world->tex_light_entities );
+ glDeleteTextures( 1, &world->tex_light_cubes );
+
+ /* FIXME: CANT DO THIS HERE */
+ world_global.time = 0.0;
+ world_global.rewind_from = 0.0;
+ world_global.rewind_to = 0.0;
+ world_global.last_use = 0.0;
+ world_global.active_gate = 0;
+ world_global.current_run_version = 2;
+ world_global.active_route_board = 0;
+
+ for( int i=0; i<vg_list_size(world_global.ui_bars); i++ )
+ {
+ struct route_ui_bar *uib = &world_global.ui_bars[i];
+ uib->segment_start = 0;
+ uib->segment_count = 0;
+ uib->fade_start = 0;
+ uib->fade_count = 0;
+ uib->fade_timer_start = 0.0;
+ uib->xpos = 0.0f;
+ }
+
+ /* delete textures and meshes */
+ glDeleteTextures( world->texture_count, world->textures );
+
+ /* delete the entire block of memory */
+ /* FIXME: WE CANT DO THIS SHIT ANYMORE, NEED TO DEALLOC FROM ABOVE */
+#if 0
+ vg_linear_clear( world->dynamic_vgl );
+ vg_linear_clear( world->audio_vgl );
+#endif
+
+
+ vg_release_thread_sync();
+}
+
+VG_STATIC void world_clean( world_instance *world )
+{
+ /* clean dangling pointers */
+ world->meta = NULL;
+
+ world->textures = NULL;
+ world->texture_count = 0;
+ world->materials = NULL;
+ world->material_count = 0;
+
+ world->scene_geo = NULL;
+ world->scene_no_collide = NULL;
+ world->scene_lines = NULL;
+
+ world->geo_bh = NULL;
+ world->trigger_bh = NULL;
+ world->audio_bh = NULL;
+
+ world->spawns = NULL;
+ world->spawn_count = 0;
+
+ world->audio_things = NULL;
+ world->audio_things_count = 0;
+
+ world->triggers = NULL;
+ world->trigger_count = 0;
+
+ world->lights = NULL;
+ world->light_count = 0;
+
+ world->logic_relays = NULL;
+ world->relay_count = 0;
+
+ world->logic_achievements = NULL;
+ world->achievement_count = 0;
+
+ world->nodes = NULL;
+ world->node_count = 0;
+
+ world->routes = NULL;
+ world->route_count = 0;
+
+ world->gates = NULL;
+ world->gate_count = 0;
+
+ world->collectors = NULL;
+ world->collector_count = 0;
+
+ world->nonlocal_gates = NULL;
+ world->nonlocalgate_count = 0;
+
+ world->water.enabled = 0;
+
+
+ /* default lighting conditions
+ * -------------------------------------------------------------*/
+ struct ub_world_lighting *state = &world->ub_lighting;
+
+ state->g_light_preview = 0;
+ state->g_shadow_samples = 8;
+ state->g_water_fog = 0.04f;
+
+ v4_zero( state->g_water_plane );
+ v4_zero( state->g_depth_bounds );
+
+ state->g_shadow_length = 9.50f;
+ state->g_shadow_spread = 0.65f;
+
+ v3_copy( (v3f){0.37f, 0.54f, 0.97f}, state->g_daysky_colour );
+ v3_copy( (v3f){0.03f, 0.05f, 0.20f}, state->g_nightsky_colour );
+ v3_copy( (v3f){1.00f, 0.32f, 0.01f}, state->g_sunset_colour );
+ v3_copy( (v3f){0.13f, 0.17f, 0.35f}, state->g_ambient_colour );
+ v3_copy( (v3f){0.25f, 0.17f, 0.51f}, state->g_sunset_ambient );
+ v3_copy( (v3f){1.10f, 0.89f, 0.35f}, state->g_sun_colour );
+}
+
+VG_STATIC void world_load( world_instance *world, const char *path )
+{
+ world_unload( world );
+ world_clean( world );
+
+ world->meta = mdl_load_full( world_global.generic_heap, path );
+ vg_info( "Loading world: %s\n", path );
+
+ /* process resources from pack */
+ world_process_resources( world );
+
+ /* dynamic allocations */
+ world_ents_allocate( world );
+ world_routes_allocate( world );
+
+ /* meta processing */
+ world_routes_process( world );
+ world_entities_process( world );
+
+ /* main bulk */
+ world_generate( world );
+ world_routes_generate( world );
+ world_post_process( world );