X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_gen.h;h=c87112afd6ed15887c648239bd590d00b2f38a9d;hb=1f0e3292c021e8263716e5f4544a1efcedf3f03d;hp=16d64fdefdf8a53af2a1cbb98b28eed71d43702a;hpb=be6707a307bfeec1b45cca8b3fb647e81262be87;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_gen.h b/world_gen.h index 16d64fd..c87112a 100644 --- a/world_gen.h +++ b/world_gen.h @@ -323,36 +323,6 @@ VG_STATIC void world_generate(void) * 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; iinfo.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 ); @@ -363,36 +333,23 @@ VG_STATIC void world_generate(void) */ 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; iinfo.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 ); @@ -422,20 +379,13 @@ VG_STATIC void world_generate(void) 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 */ @@ -546,13 +496,71 @@ VG_STATIC void world_post_process(void) 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; itexture_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; imaterial_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; @@ -575,16 +583,24 @@ VG_STATIC void world_unload(void) 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; @@ -627,6 +643,9 @@ VG_STATIC void world_load(void) 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();