vg_linear_clear( vg_mem.scratch );
mdl_array_ptr fonts;
- mdl_load_array( &font->mdl, &fonts, "ent_font", vg_mem.scratch );
+ MDL_LOAD_ARRAY( &font->mdl, &fonts, ent_font, vg_mem.scratch );
font->info = *((ent_font *)mdl_arritm(&fonts,0));
- mdl_load_array( &font->mdl, &font->font_variants, "ent_font_variant", alloc);
- mdl_load_array( &font->mdl, &font->glyphs, "ent_glyph", alloc );
+ MDL_LOAD_ARRAY( &font->mdl, &font->font_variants, ent_font_variant, alloc);
+ MDL_LOAD_ARRAY( &font->mdl, &font->glyphs, ent_glyph, alloc );
vg_linear_clear( vg_mem.scratch );
vg_linear_clear( vg_mem.scratch );
- mdl_load_array( &menu.model, &menu.items, "ent_menuitem", alloc );
- mdl_load_array( &menu.model, &menu.markers, "ent_marker", alloc );
- mdl_load_array( &menu.model, &menu.cameras, "ent_camera", alloc );
+ MDL_LOAD_ARRAY( &menu.model, &menu.items, ent_menuitem, alloc );
+ MDL_LOAD_ARRAY( &menu.model, &menu.markers, ent_marker, alloc );
+ MDL_LOAD_ARRAY( &menu.model, &menu.cameras, ent_camera, alloc );
vg_linear_clear( vg_mem.scratch );
#pragma pack(pop)
+typedef u32 mdl_indice;
+
typedef struct mdl_context mdl_context;
typedef struct mdl_array_ptr mdl_array_ptr;
typedef struct mdl_vert mdl_vert;
* Model implementation
*/
-static u32 mdl_query_array_size( mdl_array *arr )
-{
- if( arr->item_count ){
- u32 size = arr->item_size*arr->item_count;
- return vg_align8(size);
- }
- else return 0;
-}
-
static const char *mdl_pstr( mdl_context *mdl, u32 pstr );
static
void mdl_fread_pack_file( mdl_context *mdl, mdl_file *info, void *dst )
/* TODO: Rename these */
static void mdl_load_array_file_buffer( mdl_context *mdl, mdl_array *arr,
- void *buffer )
+ void *buffer, u32 stride )
{
if( arr->item_count ){
fseek( mdl->file, arr->file_offset, SEEK_SET );
- u64 l = fread( buffer, arr->item_size*arr->item_count, 1, mdl->file );
- if( l != 1 ) mdl_load_fatal_corrupt( mdl );
+ if( stride == arr->item_size ){
+ u64 l = fread( buffer, arr->item_size*arr->item_count, 1, mdl->file );
+ if( l != 1 ) mdl_load_fatal_corrupt( mdl );
+ }
+ else {
+ assert( stride >= arr->item_size );
+
+ for( u32 i=0; i<arr->item_count; i++ ){
+ u64 l = fread( buffer+i*stride, arr->item_size, 1, mdl->file );
+ if( l != 1 ) mdl_load_fatal_corrupt( mdl );
+ }
+ }
}
}
-static void mdl_load_array_file( mdl_context *mdl, mdl_array_ptr *ptr,
- mdl_array *arr, void *lin_alloc )
+static void mdl_load_array_file( mdl_context *mdl, mdl_array_ptr *ptr,
+ mdl_array *arr, void *lin_alloc, u32 stride )
{
+ assert( stride >= arr->item_size );
+
if( arr->item_count ){
- u32 size = arr->item_size*arr->item_count;
+ u32 size = stride*arr->item_count;
ptr->data = vg_linear_alloc( lin_alloc, vg_align8(size) );
- mdl_load_array_file_buffer( mdl, arr, ptr->data );
+ mdl_load_array_file_buffer( mdl, arr, ptr->data, stride );
}
- else
+ else{
ptr->data = NULL;
-
+ }
+
+ ptr->stride = stride;
ptr->count = arr->item_count;
- ptr->stride = arr->item_size;
}
static void *mdl_arritm( mdl_array_ptr *arr, u32 index )
return NULL;
}
-static int mdl_load_array( mdl_context *mdl, mdl_array_ptr *ptr,
- const char *name, void *lin_alloc )
+static int _mdl_load_array( mdl_context *mdl, mdl_array_ptr *ptr,
+ const char *name, void *lin_alloc, u32 stride )
{
mdl_array *arr = mdl_find_array( mdl, name );
if( arr ){
- mdl_load_array_file( mdl, ptr, arr, lin_alloc );
+ mdl_load_array_file( mdl, ptr, arr, lin_alloc, stride );
return 1;
}
else{
}
}
-static int mdl_load_mesh_block( mdl_context *mdl, void *lin_alloc )
-{
+#define MDL_LOAD_ARRAY( MDL, PTR, STRUCT, ALLOCATOR ) \
+ _mdl_load_array( MDL, PTR, #STRUCT, ALLOCATOR, sizeof(STRUCT) )
+
+static int mdl_load_mesh_block( mdl_context *mdl, void *lin_alloc ){
int success = 1;
- success &= mdl_load_array( mdl, &mdl->verts, "mdl_vert", lin_alloc );
- success &= mdl_load_array( mdl, &mdl->indices, "mdl_indice", lin_alloc );
+ success &= MDL_LOAD_ARRAY( mdl, &mdl->verts, mdl_vert, lin_alloc );
+ success &= MDL_LOAD_ARRAY( mdl, &mdl->indices, mdl_indice, lin_alloc );
return success;
}
-static int mdl_load_metadata_block( mdl_context *mdl, void *lin_alloc )
-{
+static int mdl_load_metadata_block( mdl_context *mdl, void *lin_alloc ){
int success = 1;
- success &= mdl_load_array( mdl, &mdl->strings, "strings", lin_alloc );
- success &= mdl_load_array( mdl, &mdl->meshs, "mdl_mesh", lin_alloc );
- success &= mdl_load_array( mdl, &mdl->submeshs, "mdl_submesh", lin_alloc );
- success &= mdl_load_array( mdl, &mdl->materials, "mdl_material", lin_alloc );
- success &= mdl_load_array( mdl, &mdl->textures, "mdl_texture", lin_alloc );
- success &= mdl_load_array( mdl, &mdl->armatures, "mdl_armature", lin_alloc );
- success &= mdl_load_array( mdl, &mdl->bones, "mdl_bone", lin_alloc );
- success &= mdl_load_array( mdl, &mdl->animations,"mdl_animation",lin_alloc );
+ success &= _mdl_load_array( mdl, &mdl->strings, "strings", lin_alloc, 1 );
+ success &= MDL_LOAD_ARRAY( mdl, &mdl->meshs, mdl_mesh, lin_alloc );
+ success &= MDL_LOAD_ARRAY( mdl, &mdl->submeshs, mdl_submesh, lin_alloc );
+ success &= MDL_LOAD_ARRAY( mdl, &mdl->materials, mdl_material, lin_alloc );
+ success &= MDL_LOAD_ARRAY( mdl, &mdl->textures, mdl_texture, lin_alloc );
+ success &= MDL_LOAD_ARRAY( mdl, &mdl->armatures, mdl_armature, lin_alloc );
+ success &= MDL_LOAD_ARRAY( mdl, &mdl->bones, mdl_bone, lin_alloc );
+ success &= MDL_LOAD_ARRAY( mdl, &mdl->animations,mdl_animation,lin_alloc );
return success;
}
-static int mdl_load_animation_block( mdl_context *mdl, void *lin_alloc )
-{
- return mdl_load_array( mdl, &mdl->keyframes, "mdl_keyframe", lin_alloc );
+static int mdl_load_animation_block( mdl_context *mdl, void *lin_alloc ){
+ return MDL_LOAD_ARRAY( mdl, &mdl->keyframes, mdl_keyframe, lin_alloc );
}
/*
vg_fatal_error( "Legacy model version incompatable" );
}
- mdl_load_array_file( mdl, &mdl->index, &mdl->info.index, lin_alloc );
+ mdl_load_array_file( mdl, &mdl->index, &mdl->info.index, lin_alloc,
+ sizeof(mdl_array) );
mdl_array *pack = mdl_find_array( mdl, "pack" );
if( pack ) mdl->pack_base_offset = pack->file_offset;
job->indices, job->indice_count );
}
-/* TODO: Find out if this needs deprecating in favour of the new full loader */
static void mdl_async_load_glmesh( mdl_context *mdl, glmesh *mesh )
{
mdl_array *arr_vertices = mdl_find_array( mdl, "mdl_vert" );
mdl_array *arr_indices = mdl_find_array( mdl, "mdl_indice" );
if( arr_vertices && arr_indices ){
- u32 size_verts = vg_align8(mdl_query_array_size( arr_vertices )),
- size_indices = vg_align8(mdl_query_array_size( arr_indices )),
+ u32 size_verts = vg_align8(sizeof(mdl_vert)*arr_vertices->item_count),
+ size_indices = vg_align8(sizeof(mdl_indice)*arr_indices->item_count),
size_hdr = vg_align8(sizeof(struct payload_glmesh_load)),
total = size_hdr + size_verts + size_indices;
job->vertex_count = arr_vertices->item_count;
job->indice_count = arr_indices->item_count;
- mdl_load_array_file_buffer( mdl, arr_vertices, job->verts );
- mdl_load_array_file_buffer( mdl, arr_indices, job->indices );
+ mdl_load_array_file_buffer( mdl, arr_vertices,
+ job->verts, sizeof(mdl_vert) );
+ mdl_load_array_file_buffer( mdl, arr_indices, job->indices,
+ sizeof(mdl_indice) );
/*
* Unpack the indices (if there are meshes)
#include "shaders/model_board_view.h"
#include "depth_compare.h"
+#include "network.h"
+#include "player_remote.h"
+
static void player_load_animation_reference( const char *path ){
mdl_context *meta = &localplayer.skeleton_meta;
mdl_open( meta, path, vg_mem.rtmemory );
dynamic_model_load( &ctx, &board->mdl, path );
mdl_array_ptr markers;
- mdl_load_array( &ctx, &markers, "ent_marker", vg_mem.scratch );
+ MDL_LOAD_ARRAY( &ctx, &markers, ent_marker, vg_mem.scratch );
/* TODO: you get put into a new section, the above is standard mdl loads. */
for( int i=0; i<4; i++ )
mdl_load_animation_block( meta, world->heap );
mdl_load_mesh_block( meta, world->heap );
- /* TODO: Make this a table? */
- mdl_load_array( meta, &world->ent_gate, "ent_gate", heap );
- mdl_load_array( meta, &world->ent_camera, "ent_camera", heap );
- mdl_load_array( meta, &world->ent_spawn, "ent_spawn", heap );
- mdl_load_array( meta, &world->ent_light, "ent_light", heap );
- mdl_load_array( meta, &world->ent_route_node,"ent_route_node", heap );
- mdl_load_array( meta, &world->ent_path_index,"ent_path_index", heap );
- mdl_load_array( meta, &world->ent_checkpoint,"ent_checkpoint", heap );
- mdl_load_array( meta, &world->ent_route, "ent_route", heap );
- mdl_load_array( meta, &world->ent_water, "ent_water", heap );
- mdl_load_array( meta, &world->ent_audio_clip,"ent_audio_clip", heap );
- mdl_load_array( meta, &world->ent_audio, "ent_audio", heap );
- mdl_load_array( meta, &world->ent_volume, "ent_volume", heap );
- mdl_load_array( meta, &world->ent_traffic, "ent_traffic", heap );
- mdl_load_array( meta, &world->ent_marker, "ent_marker", heap );
- mdl_load_array( meta, &world->ent_skateshop, "ent_skateshop", heap );
- mdl_load_array( meta, &world->ent_swspreview,"ent_swspreview", heap );
- mdl_load_array( meta, &world->ent_ccmd, "ent_ccmd", heap );
- mdl_load_array( meta, &world->ent_objective, "ent_objective", heap );
- mdl_load_array( meta, &world->ent_challenge, "ent_challenge", heap );
- mdl_load_array( meta, &world->ent_relay, "ent_relay", heap );
- mdl_load_array( meta, &world->ent_cubemap, "ent_cubemap", heap );
- mdl_load_array( meta, &world->ent_miniworld, "ent_miniworld", heap );
- mdl_load_array( meta, &world->ent_prop, "ent_prop", heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_gate, ent_gate, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_camera, ent_camera, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_spawn, ent_spawn, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_light, ent_light, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_route_node,ent_route_node, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_path_index,ent_path_index, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_checkpoint,ent_checkpoint, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_route, ent_route, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_water, ent_water, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_audio_clip,ent_audio_clip, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_audio, ent_audio, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_volume, ent_volume, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_traffic, ent_traffic, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_marker, ent_marker, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_skateshop, ent_skateshop, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_swspreview,ent_swspreview, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_ccmd, ent_ccmd, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_objective, ent_objective, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_challenge, ent_challenge, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_relay, ent_relay, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_cubemap, ent_cubemap, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_miniworld, ent_miniworld, heap );
+ MDL_LOAD_ARRAY( meta, &world->ent_prop, ent_prop, heap );
mdl_array_ptr infos;
- mdl_load_array( meta, &infos, "ent_worldinfo", vg_mem.scratch );
+ MDL_LOAD_ARRAY( meta, &infos, ent_worldinfo, vg_mem.scratch );
world->skybox = k_skybox_default;
if( mdl_arrcount(&infos) ){
* - this is overriden by the save state when(if) it loads */
ent_spawn *rp = world_find_spawn_by_name( world, "start" );
if( !rp ) rp = world_find_closest_spawn( world, (v3f){0.0f,0.0f,0.0f} );
-
- /* TODO: fallback to searching for a safe location using raycasts */
- assert(rp);
- v3_copy( rp->transform.co, world->player_co );
+ if( rp )
+ v3_copy( rp->transform.co, world->player_co );
+ else{
+ /* FIXME: we need to find a safe place to put the player_co using
+ * raycasts. */
+ v3_zero( world->player_co );
+ }
/* allocate leaderboard buffers */
u32 bs = mdl_arrcount(&world->ent_route)*sizeof(struct leaderboard_cache);