X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=model.h;h=ca7c0b1d5f73d95c1a913fd5857fa552b9eb368e;hb=6294ef64d948eab2365e39a2645c9843aa96fba8;hp=0547e8ecc17d919dc438dd456ef4acfaac48e15e;hpb=a64c18c5996fd5ac9601239f91b12275f04f9cd9;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/model.h b/model.h index 0547e8e..ca7c0b1 100644 --- a/model.h +++ b/model.h @@ -16,6 +16,7 @@ typedef struct mdl_node mdl_node; typedef struct mdl_file_header mdl_file_header; typedef struct mdl_animation mdl_animation; typedef struct mdl_keyframe mdl_keyframe; +typedef struct mdl_texture mdl_texture; typedef struct mdl_context mdl_context; #define MDL_SIZE_MAX 0x1000000 @@ -28,24 +29,43 @@ typedef struct mdl_context mdl_context; enum classtype { - k_classtype_none = 0, - k_classtype_gate = 1, - k_classtype_block = 2, - k_classtype_spawn = 3, - k_classtype_water = 4, - k_classtype_car_path = 5, - k_classtype_instance = 6, - k_classtype_capsule = 7, - k_classtype_route_node = 8, - k_classtype_route = 9, - k_classtype_bone = 10, - k_classtype_skeleton = 11, - k_classtype_skin = 12, - k_classtype_achievement_box = 13, - k_classtype_audio = 14, - k_classtype_trigger = 15 + k_classtype_none = 0, + k_classtype_gate = 1, + k_classtype_spawn = 3, + k_classtype_water = 4, + k_classtype_route_node = 8, + k_classtype_route = 9, + k_classtype_bone = 10, + k_classtype_skeleton = 11, + k_classtype_skin = 12, + k_classtype_audio = 14, + k_classtype_trigger = 100, + k_classtype_logic_achievement = 101, + k_classtype_logic_relay = 102 }; +enum mdl_shader +{ + k_shader_standard = 0, + k_shader_standard_cutout = 1, + k_shader_terrain_blend = 2, + k_shader_standard_vertex_blend = 3, + k_shader_water = 4 +}; + +enum mdl_surface_prop +{ + k_surface_prop_concrete = 0, + k_surface_prop_wood = 1, + k_surface_prop_grass = 2 +}; + +enum material_flag +{ + k_material_flag_skate_surface = 0x1, + k_material_flag_collision = 0x2, + k_material_flag_grow_grass = 0x4 +}; #pragma pack(push,1) @@ -70,9 +90,26 @@ struct mdl_submesh u32 material_id; }; +struct mdl_texture +{ + u32 pstr_name, + pack_offset, + pack_length; +}; + struct mdl_material { - u32 pstr_name; + u32 pstr_name, + shader, + flags, + surface_prop; + + v4f colour, + colour1; + + u32 tex_diffuse, + tex_decal, + tex_normal; }; struct mdl_node @@ -111,26 +148,27 @@ struct mdl_file_header { u32 identifier, version, file_length, pad0; - u32 vertex_count, vertex_offset, - indice_count, indice_offset, - submesh_count, submesh_offset, - material_count, material_offset, - node_count, node_offset, - anim_count, anim_offset, - strings_length, strings_offset, - entdata_length, entdata_offset, - keyframe_count, keyframe_offset; + u32 + node_count, node_offset, + submesh_count, submesh_offset, + material_count, material_offset, + texture_count, texture_offset, + anim_count, anim_offset, + entdata_size, entdata_offset, + strings_size, strings_offset, + + keyframe_count, keyframe_offset, + + vertex_count, vertex_offset, + indice_count, indice_offset, + + pack_size, pack_offset; }; /* * Entity data structures */ -struct classtype_block -{ - boxf bbx; -}; - struct classtype_gate { u32 target; @@ -139,7 +177,7 @@ struct classtype_gate struct classtype_spawn { - u32 target; + u32 pstr_alias; }; struct classtype_water @@ -147,21 +185,6 @@ struct classtype_water u32 temp; }; -struct classtype_car_path -{ - u32 target, target1; -}; - -struct classtype_instance -{ - u32 pstr_file; -}; - -struct classtype_capsule -{ - float height, radius; -}; - struct classtype_route_node { u32 target, target1; @@ -170,6 +193,7 @@ struct classtype_route_node struct classtype_route { u32 id_start; + u32 pstr_name; v3f colour; }; @@ -199,10 +223,19 @@ struct classtype_skin u32 skeleton; }; -struct classtype_achievement_box +struct classtype_trigger { - u32 pstr_name, - trigger; + u32 target; +}; + +struct classtype_logic_relay +{ + u32 targets[4]; +}; + +struct classtype_logic_achievement +{ + u32 pstr_name; }; struct classtype_audio @@ -225,6 +258,7 @@ struct mdl_context mdl_node *node_buffer; /* mdl_load_metadata() */ mdl_submesh *submesh_buffer; mdl_material *material_buffer; + mdl_texture *texture_buffer; mdl_animation *anim_buffer; void *entdata_buffer; const char *string_buffer; @@ -233,6 +267,8 @@ struct mdl_context mdl_vert *vertex_buffer; /* mdl_load_mesh_data() */ u32 *index_buffer; + + void *pack; /* mdl_load_pack_data() */ }; /* @@ -399,6 +435,7 @@ VG_STATIC void mdl_load_metadata( mdl_context *mdl, void *lin_alloc ) mdl->node_buffer = all_data + (mdl->info.node_offset - lheader); mdl->submesh_buffer = all_data + (mdl->info.submesh_offset - lheader); mdl->material_buffer = all_data + (mdl->info.material_offset - lheader); + mdl->texture_buffer = all_data + (mdl->info.texture_offset - lheader); mdl->anim_buffer = all_data + (mdl->info.anim_offset - lheader); mdl->entdata_buffer = all_data + (mdl->info.entdata_offset - lheader); mdl->string_buffer = all_data + (mdl->info.strings_offset - lheader); @@ -450,6 +487,26 @@ VG_STATIC void mdl_load_anim_data( mdl_context *mdl, void *lin_alloc ) mdl_load_fatal_corrupt( mdl ); } +/* + * Load pack contents + * + * TODO request specific files (low) + */ +VG_STATIC void mdl_load_pack_data( mdl_context *mdl, void *lin_alloc ) +{ + assert( mdl->file ); + + if( mdl->info.pack_size == 0 ) + return; + + mdl->pack = vg_linear_alloc( lin_alloc, mdl->info.pack_size ); + fseek( mdl->file, mdl->info.pack_offset, SEEK_SET ); + + u64 l = fread( mdl->pack, mdl->info.pack_size, 1, mdl->file ); + if( l != 1 ) + mdl_load_fatal_corrupt( mdl ); +} + /* * close file handle */ @@ -459,7 +516,7 @@ VG_STATIC void mdl_close( mdl_context *mdl ) mdl->file = NULL; } -/* open a model */ +/* open a model. TODO: make this flags ( ANIM_DATA|MESH_DATA ... ) */ VG_STATIC mdl_context *mdl_load_full( void *lin_alloc, const char *path ) { /* Inspect the header by opening it, give us the size needed */ @@ -468,7 +525,8 @@ VG_STATIC mdl_context *mdl_load_full( void *lin_alloc, const char *path ) /* create allocator */ u32 tot_size = temp_ctx.info.file_length + sizeof( mdl_context ); - void *data = vg_create_linear_allocator( lin_alloc, tot_size ); + void *data = vg_create_linear_allocator( lin_alloc, tot_size, + VG_MEMORY_SYSTEM ); /* copy context and load all other data */ mdl_context *ctx = vg_linear_alloc( data, sizeof(mdl_context) ); @@ -477,6 +535,7 @@ VG_STATIC mdl_context *mdl_load_full( void *lin_alloc, const char *path ) mdl_load_metadata( ctx, data ); mdl_load_anim_data( ctx, data ); mdl_load_mesh_data( ctx, data ); + mdl_load_pack_data( ctx, data ); mdl_close( ctx ); return ctx;