chaos caused by async
[carveJwlIkooP6JGAAIwe30JlM.git] / player_render.c
index ab8942207366aa30d30a435e009b997d0c5c62d5..df0dd6b1d3717e12b84529aecaf7edb90a38dc1e 100644 (file)
@@ -43,30 +43,19 @@ VG_STATIC void player_model_load( struct player_model *mdl, const char *path )
    mdl_context ctx;
    mdl_open( &ctx, path, vg_mem.scratch );
    mdl_load_metadata_block( &ctx, vg_mem.scratch );
-   mdl_load_mesh_block( &ctx, vg_mem.scratch );
 
    if( !mdl_arrcount( &ctx.textures ) )
-      vg_fatal_exit_loop( "No texture in player model" );
+      vg_fatal_error( "No texture in player model" );
 
    mdl_texture *tex0 = mdl_arritm( &ctx.textures, 0 );
    void *data = vg_linear_alloc( vg_mem.scratch, tex0->file.pack_size );
    mdl_fread_pack_file( &ctx, &tex0->file, data );
 
-   vg_acquire_thread_sync();
-   {
-      mdl_unpack_glmesh( &ctx, &mdl->mesh );
-
-      /* upload first texture */
-      mdl->texture = vg_tex2d_new();
-
-      vg_tex2d_set_error();
-      vg_tex2d_qoi( data, tex0->file.pack_size,
-                    mdl_pstr( &ctx, tex0->file.pstr_path ));
-      vg_tex2d_nearest();
-      vg_tex2d_clamp();
-   }
-   vg_release_thread_sync();
+   vg_tex2d_load_qoi_async( data, tex0->file.pack_size,
+                            VG_TEX2D_NEAREST|VG_TEX2D_CLAMP,
+                            &mdl->texture );
 
+   mdl_async_load_glmesh( &ctx, &mdl->mesh );
    mdl_close( &ctx );
 }
 
@@ -77,33 +66,22 @@ VG_STATIC void player_board_load( struct player_board *mdl, const char *path )
    mdl_context ctx;
    mdl_open( &ctx, path, vg_mem.scratch );
    mdl_load_metadata_block( &ctx, vg_mem.scratch );
-   mdl_load_mesh_block( &ctx, vg_mem.scratch );
 
    mdl_array_ptr markers;
    mdl_load_array( &ctx, &markers, "ent_marker", vg_mem.scratch );
 
    if( !mdl_arrcount( &ctx.textures ) )
-      vg_fatal_exit_loop( "No texture in board model" );
+      vg_fatal_error( "No texture in board model" );
 
    mdl_texture *tex0 = mdl_arritm( &ctx.textures, 0 );
    void *data = vg_linear_alloc( vg_mem.scratch, tex0->file.pack_size );
    mdl_fread_pack_file( &ctx, &tex0->file, data );
 
-   vg_acquire_thread_sync();
-   {
-      mdl_unpack_glmesh( &ctx, &mdl->mesh );
-
-      /* upload first texture */
-      mdl->texture = vg_tex2d_new();
-
-      vg_tex2d_set_error();
-      vg_tex2d_qoi( data, tex0->file.pack_size,
-                    mdl_pstr( &ctx, tex0->file.pstr_path ));
-      vg_tex2d_nearest();
-      vg_tex2d_clamp();
-   }
-   vg_release_thread_sync();
+   vg_tex2d_load_qoi_async( data, tex0->file.pack_size,
+                            VG_TEX2D_CLAMP|VG_TEX2D_NEAREST,
+                            &mdl->texture );
 
+   mdl_async_load_glmesh( &ctx, &mdl->mesh );
    mdl_close( &ctx );
 
    for( int i=0; i<4; i++ )