X-Git-Url: https://harrygodden.com/git/?p=csRadar.git;a=blobdiff_plain;f=vmf.h;fp=vmf.h;h=4829d48174599bb6906c802e0cfeef0446d3a20c;hp=c3abc2a4026c9b5486cd4aec533d9e7829ea7941;hb=d7339f0f28ca5b35ad60a393ca270cbae1a154c6;hpb=3e1642e28847218d89d1bec2f8b035c10359ac91 diff --git a/vmf.h b/vmf.h index c3abc2a..4829d48 100644 --- a/vmf.h +++ b/vmf.h @@ -61,6 +61,8 @@ struct vmf_map u32 hash; mdl_mesh_t mdl; + + int need_load; } *models; @@ -293,7 +295,7 @@ ESolidResult solidgen_push( vmf_solid *ctx, vdf_node *node ) if( num_planes >= SOLID_MAX_SIDES ) { flag = k_ESolidResult_maxsides; - fprintf( stderr, "Solid over maxsides limit (%i)\n", SOLID_MAX_SIDES ); + log_error( "Solid over maxsides limit (%i)\n", SOLID_MAX_SIDES ); break; } @@ -385,7 +387,7 @@ ESolidResult solidgen_push( vmf_solid *ctx, vdf_node *node ) if( csr_sb_count( face->indices ) < 3 ) { flag = k_ESolidResult_degenerate; - fprintf( stderr, "Skipping degenerate face\n" ); + log_error( "Skipping degenerate face\n" ); continue; } @@ -403,7 +405,7 @@ ESolidResult solidgen_push( vmf_solid *ctx, vdf_node *node ) if( csr_sb_count( face->indices ) != 4 ) { flag = k_ESolidResult_degenerate; - fprintf( stderr, "Skipping degenerate displacement\n" ); + log_error( "Skipping degenerate displacement\n" ); continue; } @@ -572,6 +574,9 @@ void vmf_populate_models( vdf_node *vmf, vmf_map *map ) map->models = csr_sb_reserve( map->models, 1, sizeof( struct vmf_model )); struct vmf_model *entry = &map->models[ csr_sb_count( map->models ) ]; + entry->need_load = 0; + mdl_error( &entry->mdl ); // (just setting arrays to 0) + entry->str = csr_malloc( strlen( model_path ) +1 ); strcpy( entry->str, model_path ); entry->hash = djb2( (const unsigned char *)model_path ); @@ -588,11 +593,11 @@ void vmf_populate_models( vdf_node *vmf, vmf_map *map ) } // Load all models -void vmf_load_models( vmf_map *map ) +void vmf_index_models( vmf_map *map ) { - printf( "Loading all models\n" ); + log_info( "Indexing all models\n" ); - // Error model. TODO: Maybe don't have this be junk data. + // Error model == blank map->models = csr_sb_reserve( map->models, 1, sizeof( struct vmf_model )); csr_sb_use( map->models ); mdl_error( &map->models[0].mdl ); @@ -605,27 +610,34 @@ void vmf_load_models( vmf_map *map ) vmf_populate_models( map->cache[i].root, map ); } - printf( "Indexed (%u) models\n", csr_sb_count( map->models )-1 ); - + log_info( "Indexed (%u) models\n", csr_sb_count( map->models )-1 ); +} + +void vmf_load_models( vmf_map *map ) +{ u32 num_success = 0; + u32 num_reqs = 0; - // Load model data - // TODO: Make nice loading bar for( int i = 1; i < csr_sb_count( map->models ); i ++ ) { struct vmf_model *mdl = &map->models[i]; - if( mdl_from_find_files( mdl->str, &mdl->mdl ) ) - { - num_success ++; - } - else + if( mdl->need_load ) { - fprintf( stderr, "Failed to load model: %s\n", mdl->str ); + num_reqs ++; + + if( mdl_from_find_files( mdl->str, &mdl->mdl ) ) + { + num_success ++; + } + else + { + log_warn( "Failed to load model: %s\n", mdl->str ); + } } } - printf( "Done (%u of %u loaded)\n", num_success, csr_sb_count( map->models )-1 ); + log_info( "Done (%u of %u loaded)\n", num_success, num_reqs ); } u32 vmf_init_subvmf( vmf_map *map, const char *subvmf ); @@ -663,38 +675,37 @@ u32 vmf_init_subvmf( vmf_map *map, const char *subvmf ) { if( !strcmp( map->cache[i].name, subvmf ) ) { - return i+1; + if( map->cache[i].root ) + return i+1; + else + return 0; } } } - printf( "Loading subvmf: %s\n", subvmf ); - id = csr_sb_count( map->cache ); map->cache = csr_sb_reserve( map->cache, 1, sizeof( struct vmf_instance )); struct vmf_instance *inst = &map->cache[ id ]; + csr_sb_use( map->cache ); + inst->hash = hash; + inst->name = csr_malloc( strlen( subvmf )+1 ); + strcpy( inst->name, subvmf ); + if( (inst->root = vdf_open_file( subvmf )) ) - { - csr_sb_use( map->cache ); - - inst->hash = hash; - inst->name = csr_malloc( strlen( subvmf )+1 ); - strcpy( inst->name, subvmf ); - + { // Recursive load other instances - vmf_load_all_instances( map, inst->root ); - + vmf_load_all_instances( map, inst->root ); return id+1; } else { - fprintf( stderr, "Failed to load instance file\n" ); + log_error( "Failed to load instance file: %s\n", subvmf ); return 0; } } -vmf_map *vmf_init( const char *path, int load_models ) +vmf_map *vmf_init( const char *path ) { vmf_map *map = csr_calloc( sizeof( vmf_map ) ); map->root = vdf_open_file( path ); @@ -709,11 +720,7 @@ vmf_map *vmf_init( const char *path, int load_models ) vmf_load_all_instances( map, map->root ); // Other resources - if( load_models ) - { - vmf_load_models( map ); - } - + vmf_index_models( map ); return map; } @@ -721,7 +728,9 @@ void vmf_free( vmf_map *map ) { for( int i = 0; i < csr_sb_count( map->cache ); i ++ ) { - vdf_free_r( map->cache[i].root ); + if( map->cache[i].root ) + vdf_free_r( map->cache[i].root ); + free( map->cache[i].name ); } @@ -737,51 +746,6 @@ void vmf_free( vmf_map *map ) free( map ); } -void solidgen_to_obj( vmf_solid *ctx, const char *path ) -{ - FILE *fp = fopen( path, "w" ); - - if( fp ) - { - fprintf( fp, "o vmf_export\n" ); - - vmf_vert *vert; - - // Write vertex block - for( int i = 0; i < csr_sb_count( ctx->verts ); i ++ ) - { - vert = &ctx->verts[i]; - fprintf( fp, "v %f %f %f\n", vert->co[0], vert->co[1], vert->co[2] ); - } - - // Write normals block - for( int i = 0; i < csr_sb_count( ctx->verts ); i ++ ) - { - vert = &ctx->verts[i]; - fprintf( fp, "vn %f %f %f\n", vert->nrm[0], vert->nrm[1], vert->nrm[2] ); - } - - fprintf( fp, "s off\n" ); - - // Indices - for( int i = 0; i < csr_sb_count( ctx->indices )/3; i ++ ) - { - u32 * base = ctx->indices + i*3; - fprintf( fp, "f %u//%u %u//%u %u//%u\n", - base[2]+1, base[2]+1, - base[1]+1, base[1]+1, - base[0]+1, base[0]+1 - ); - } - - fclose( fp ); - } - else - { - fprintf( stderr, "Could not open %s for writing\n", path ); - } -} - void vmf_entity_transform( vdf_node *ent, m4x3f mat ) { v3f angles = {0.f,0.f,0.f};