* Compile meshes into the world scenes
*/
world.scene_geo = scene_init( world.dynamic_vgl, 350000, 1200000 );
-
- /*
- * TODO: System to dynamically allocate these
- */
- u32 mat_surf = 0,
- mat_surf_oob = 0,
- mat_vertex_blend = 0,
- mat_alphatest = 0,
- mat_graffiti = 0,
- mat_subworld = 0,
- mat_terrain = 0;
-
- for( int i=1; i<world.meta->info.material_count; i++ )
- {
- mdl_material *mat = &world.meta->material_buffer[ i ];
- const char *mat_name = mdl_pstr( world.meta, mat->pstr_name );
-
- if( !strcmp( "surf", mat_name ))
- mat_surf = i;
- else if( !strcmp( "surf_oob", mat_name ))
- mat_surf_oob = i;
- else if( !strcmp( "vertex_blend", mat_name ))
- mat_vertex_blend = i;
- else if( !strcmp( "alphatest", mat_name ))
- mat_alphatest = i;
- else if( !strcmp( "graffitibox", mat_name ))
- mat_graffiti = i;
- else if( !strcmp( "terrain", mat_name ) )
- mat_terrain = i;
- }
m4x3f midentity;
m4x3_identity( midentity );
*/
vg_info( "Generating collidable geometry\n" );
- vg_info( "terrain...\n" );
- /* terrain */
- if( mat_terrain )
- world_add_all_if_material( midentity, world.scene_geo,
- world.meta, mat_terrain );
- scene_copy_slice( world.scene_geo, &world.sm_terrain );
-
- /* oob */
- vg_info( "oob...\n" );
- if( mat_surf_oob )
- world_add_all_if_material( midentity, world.scene_geo,
- world.meta, mat_surf_oob );
- else
- vg_warn( "No OOB surface\n" );
- scene_copy_slice( world.scene_geo, &world.sm_geo_std_oob );
-
-
- /* surface */
- vg_info( "surface...\n" );
- if( mat_surf )
- world_add_all_if_material( midentity, world.scene_geo,
- world.meta, mat_surf );
- scene_copy_slice( world.scene_geo, &world.sm_geo_std );
-
- /* vertex_blend */
- vg_info( "vertex blend...\n" );
- if( mat_vertex_blend )
- world_add_all_if_material( midentity, world.scene_geo,
- world.meta, mat_vertex_blend);
- scene_copy_slice( world.scene_geo, &world.sm_geo_vb );
+
+
+ for( int i=0; i<world.material_count; i++ )
+ {
+ struct world_material *mat = &world.materials[ i ];
+
+ if( mat->info.flags & k_material_flag_collision )
+ {
+ world_add_all_if_material( midentity, world.scene_geo, world.meta, i );
+ scene_copy_slice( world.scene_geo, &mat->sm_geo );
+ }
+ }
+
+
+
+
+
/* compress that bad boy */
world.scene_geo = scene_fix( world.dynamic_vgl, world.scene_geo );
world.scene_no_collide = scene_init( world.dynamic_vgl, 200000, 500000 );
+#if 0
vg_info( "Applying foliage\n" );
srand(0);
world_apply_procedural_foliage();
scene_copy_slice( world.scene_no_collide, &world.sm_foliage_main );
+#endif
- vg_info( "alphatest...\n" );
- world_add_all_if_material( midentity, world.scene_no_collide,
- world.meta, mat_alphatest );
- scene_copy_slice( world.scene_no_collide, &world.sm_foliage_alphatest );
-
- vg_info( "graffiti...\n" );
- world_add_all_if_material( midentity, world.scene_no_collide,
- world.meta, mat_graffiti );
- scene_copy_slice( world.scene_no_collide, &world.sm_graffiti );
/* upload and free that */
reset_player( 1, (const char *[]){"start"} );
}
+VG_STATIC void world_process_resources(void)
+{
+ vg_info( "Loading textures\n" );
+ world.texture_count = world.meta->info.texture_count;
+ world.textures =
+ vg_linear_alloc( world.dynamic_vgl, sizeof(GLuint)*world.texture_count );
+
+ vg_acquire_thread_sync();
+ {
+ /* error texture */
+ world.textures[0] = vg_tex2d_new();
+ vg_tex2d_set_error();
+ vg_tex2d_nearest();
+ vg_tex2d_repeat();
+
+ for( int i=1; i<world.texture_count; i++ )
+ {
+ mdl_texture *tex = &world.meta->texture_buffer[i];
+
+ if( !tex->pack_offset )
+ {
+ vg_release_thread_sync();
+ vg_fatal_exit_loop( "World models must have packed textures!" );
+ }
+
+ vg_linear_clear( vg_mem.scratch );
+ world.textures[i] = vg_tex2d_new();
+ vg_tex2d_set_error();
+ vg_tex2d_qoi( world.meta->pack + tex->pack_offset, tex->pack_length,
+ mdl_pstr( world.meta, tex->pstr_name ));
+ vg_tex2d_nearest();
+ vg_tex2d_repeat();
+ }
+ }
+ vg_release_thread_sync();
+
+ vg_info( "Loading materials\n" );
+
+ u32 size = sizeof(struct world_material) * world.meta->info.material_count;
+ world.materials = vg_linear_alloc( world.dynamic_vgl, size );
+
+ world.material_count = world.meta->info.material_count;
+ memset( world.materials, 0, size );
+
+ for( int i=1; i<world.material_count; i++ )
+ world.materials[i].info = world.meta->material_buffer[i];
+
+ /* error material */
+ struct world_material *errmat = &world.materials[0];
+ v4_copy( (v4f){ 1.0f,0.0f,0.0f,1.0f }, errmat->info.colour );
+ v4_copy( (v4f){ 1.0f,0.0f,0.0f,1.0f }, errmat->info.colour1 );
+ errmat->info.flags = 0x00;
+ errmat->info.pstr_name = 0; /* useless? */
+ errmat->info.shader = -1;
+ errmat->info.tex_decal = 0;
+ errmat->info.tex_diffuse = 0;
+ errmat->info.tex_normal = 0;
+}
VG_STATIC void world_unload(void)
{
/* free meshes */
+ mesh_free( &world.mesh_route_lines );
mesh_free( &world.mesh_geo );
mesh_free( &world.mesh_no_collide );
- mesh_free( &world.mesh_route_lines );
mesh_free( &world.mesh_water );
world.time = 0.0;
uib->xpos = 0.0f;
}
+ /* delete textures and meshes */
+ glDeleteTextures( world.texture_count, world.textures );
+
/* delete the entire block of memory */
vg_linear_clear( world.dynamic_vgl );
vg_linear_clear( world.audio_vgl );
/* 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_lines = NULL;
world.scene_no_collide = NULL;
+ world.scene_lines = NULL;
world.geo_bh = NULL;
world.trigger_bh = NULL;
world.meta = mdl_load_full( world.dynamic_vgl, world.world_name );
vg_info( "Loading world: %s\n", world.world_name );
+ /* process resources from pack */
+ world_process_resources();
+
/* dynamic allocations */
world_ents_allocate();
world_routes_allocate();