Fix major overstep with last commit
authorhgn <hgodden00@gmail.com>
Fri, 7 Oct 2022 03:55:52 +0000 (04:55 +0100)
committerhgn <hgodden00@gmail.com>
Fri, 7 Oct 2022 03:55:52 +0000 (04:55 +0100)
20 files changed:
audio.h
bvh.h
common.h
highscores.h
main.c
model.h
network.h
player.h
player_model.h
player_ragdoll.h
render.h
scene.h
skeleton.h
world.h
world_gate.h
world_gen.h
world_render.h
world_routes.h
world_sfd.h
world_water.h

diff --git a/audio.h b/audio.h
index f6baa201a409e29d8f79d88f3f2ad2b0dc259132..fc9330c1a629d7cc7fb4bb3f3c0e93c5e4e08e91 100644 (file)
--- a/audio.h
+++ b/audio.h
@@ -120,7 +120,7 @@ audio_player audio_player_gate =
    .name = "Gate"
 };
 
-static int audio_init(void)
+static void audio_init(void)
 {
    audio_player_init( &audio_player0 );
    audio_player_init( &audio_player1 );
@@ -187,8 +187,6 @@ static int audio_init(void)
       .opt_f32 = { .clamp = 0 },
       .persistent = 1
    });
-
-   return 1;
 }
 
 static void audio_free(void*_)
diff --git a/bvh.h b/bvh.h
index 27e23b5af516dd0fc8ae809b7c6844400741cf7d..25be1e5fe0e152be57fef01d060c3a5af93393f5 100644 (file)
--- a/bvh.h
+++ b/bvh.h
@@ -135,7 +135,7 @@ static void bh_create( bh_tree *bh, bh_system *sys, void *user, u32 item_count )
 {
    bh->system = sys;
    bh->user = user;
-   bh->nodes = malloc( sizeof(bh_node) * (item_count*2-1) );
+   bh->nodes = vg_alloc( sizeof(bh_node) * (item_count*2-1) );
 
    bh_node *root = &bh->nodes[0];
    bh->node_count = 1;
@@ -148,8 +148,12 @@ static void bh_create( bh_tree *bh, bh_system *sys, void *user, u32 item_count )
    bh_update_bounds( bh, 0 );
    bh_subdivide( bh, 0 );
 
-   bh->nodes = realloc( bh->nodes, sizeof(bh_node) * bh->node_count );
+   bh->nodes = vg_realloc( bh->nodes, sizeof(bh_node) * bh->node_count );
    vg_success( "BVH done, size: %u/%u\n", bh->node_count, (item_count*2-1) );
+
+#if 0
+   vg_fatal_exit_loop( "Test crash from loader" );
+#endif
 }
 
 static void bh_debug_node( bh_tree *bh, u32 inode, v3f pos, u32 colour )
index fa22207f3e2eb8c7709550f1b3d35d3a757e5b4b..a1cad243f7e33d499e7b414bce967483c20859e3 100644 (file)
--- a/common.h
+++ b/common.h
@@ -35,18 +35,6 @@ struct ray_hit
    v3f pos, normal;
 };
 
-/* TODO: he needs a home somewhere */
-static void eval_bezier_time( v3f p0, v3f p1, v3f h0, v3f h1, float t, v3f p )
-{
-   float tt = t*t,
-         ttt = tt*t;
-
-   v3_muls( p1, ttt, p );
-   v3_muladds( p, h1, 3.0f*tt  -3.0f*ttt, p );
-   v3_muladds( p, h0, 3.0f*ttt -6.0f*tt  +3.0f*t, p );
-   v3_muladds( p, p0, 3.0f*tt  -ttt -3.0f*t +1.0f, p );
-}
-
 static int network_scores_updated = 0;
 
 
index 78db2ad3105961b74a2f6115ba15c8d7e1e0858c..7ea5413173df1895b40a857971d5a5d8110ed2bc 100644 (file)
@@ -128,7 +128,7 @@ static int highscore_cmp_playerinfo_playerid( void *a, void *b )
 static void *highscore_malloc( u32 count, u32 size )
 {
    size_t requested_mem = size * count;
-   void *data = malloc( requested_mem );
+   void *data = vg_alloc( requested_mem );
 
    requested_mem /= 1024;
    requested_mem /= 1024;
@@ -146,8 +146,8 @@ static void *highscore_malloc( u32 count, u32 size )
 
 static void highscores_free(void)
 {
-   free( highscore_system.data );
-   free( highscore_system.playerinfo_data );
+   vg_free( highscore_system.data );
+   vg_free( highscore_system.playerinfo_data );
 }
 
 static int highscores_init( u32 pool_size, u32 playerinfo_pool_size )
@@ -161,7 +161,7 @@ static int highscores_init( u32 pool_size, u32 playerinfo_pool_size )
       highscore_malloc( playerinfo_pool_size, sizeof(highscore_playerinfo));
    if( !sys->playerinfo_data ) 
    {
-      free( sys->data );
+      vg_free( sys->data );
       return 0;
    }
 
diff --git a/main.c b/main.c
index fb53847515fe81382283495ec14ec71944506ad7..81584dd5b0b97800e2ca20f9f6459428e776620f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -40,7 +40,7 @@ static void highscores_save_at_exit(void*_)
    highscores_free();
 }
 
-int vg_preload(void)
+void vg_preload(void)
 {
    vg_convar_push( (struct vg_convar){
       .name = "cl_ui",
@@ -59,42 +59,30 @@ vg_info("            '        ' '--' [] '----- '----- '     ' '---'  "
         "SOFTWARE" );
 
    highscores_init( 2000, 50 );
-   if( !vg_loader_highwater( highscores_save_at_exit, NULL ) )         return 0;
+   vg_loader_highwater( NULL, highscores_save_at_exit, NULL );
 
    vg_sleep_ms(200);
 
-   if( !steam_init() )                                                 return 0;
-   if( !vg_loader_highwater( steam_end, NULL ) )                       return 0;
+   steam_init();
+   vg_loader_highwater( NULL, steam_end, NULL );
 
-   if( !network_init() )                                               return 0;
-   if( !vg_loader_highwater( network_end, NULL ) )                     return 0;
-
-   return 1;
+   vg_loader_highwater( network_init, network_end, NULL );
 }
 
-int vg_load(void)
+void vg_load(void)
 {
-   if( !render_init() )                                                return 0;
-   if( !vg_loader_highwater( render_free, NULL ) )                     return 0;
-
-   if( !world_init() )                                                 return 0;
-
-   if( !player_init() )                                                return 0;
-   if( !vg_loader_highwater( player_model_free, NULL ) )               return 0;
-
-
+   vg_loader_highwater( render_init, render_free, NULL );
+   vg_loader_highwater( world_init, world_free, NULL );
+   vg_loader_highwater( player_init, NULL, NULL );
 
-   if( !vg_bake_shaders() )                                            return 0;
+   if( !vg_bake_shaders() )
+      vg_fatal_exit_loop( "Did not load all shaders" );
 
-
-   if( !audio_init() )                                                 return 0;
-   if( !vg_loader_highwater( audio_free, NULL ) )                      return 0;
+   vg_loader_highwater( audio_init, audio_free, NULL );
 
    /* FInal step */
    world_load();
    vg_console_load_autos();
-
-   return 1;
 }
 
 static void vg_start(void)
@@ -279,10 +267,6 @@ void vg_ui(void)
    audio_debug_soundscapes();
 }
 
-void vg_free(void)
-{
-}
-
 #if 0
 static void run_light_widget( struct light_widget *lw )
 {
diff --git a/model.h b/model.h
index 59b75beeb797e89aab8356eeedc5002cc77fa079..d72e93cc29a4ff90e3611c308394d4921d154925 100644 (file)
--- a/model.h
+++ b/model.h
@@ -182,13 +182,15 @@ struct glmesh
 {
    GLuint vao, vbo, ebo;
    u32 indice_count;
+   u32 loaded;
 };
 
-__attribute__((warn_unused_result))
-static int mesh_upload( glmesh *mesh,
-      mdl_vert *verts, u32 vert_count,
-      u32 *indices, u32 indice_count )
+static void mesh_upload( glmesh *mesh,
+                         mdl_vert *verts, u32 vert_count,
+                         u32 *indices, u32 indice_count )
 {
+   //assert( mesh->loaded == 0 );
+
    glGenVertexArrays( 1, &mesh->vao );
    glGenBuffers( 1, &mesh->vbo );
    glGenBuffers( 1, &mesh->ebo );
@@ -233,13 +235,10 @@ static int mesh_upload( glmesh *mesh,
          stride, (void *)offsetof(mdl_vert, groups) );
    glEnableVertexAttribArray( 5 );
 
-   if( VG_CHECK_GL_ERR() )
-   {
-      return 0;
-   }
+   VG_CHECK_GL_ERR();
 
    mesh->indice_count = indice_count;
-   return 1;
+   mesh->loaded = 1;
 }
 
 static void mesh_bind( glmesh *mesh )
@@ -260,9 +259,12 @@ static void mesh_draw( glmesh *mesh )
 
 static void mesh_free( glmesh *mesh )
 {
-   glDeleteVertexArrays( 1, &mesh->vao );
-   glDeleteBuffers( 1, &mesh->ebo );
-   glDeleteBuffers( 1, &mesh->vbo );
+   if( mesh->loaded )
+   {
+      glDeleteVertexArrays( 1, &mesh->vao );
+      glDeleteBuffers( 1, &mesh->ebo );
+      glDeleteBuffers( 1, &mesh->vbo );
+   }
 }
 
 
@@ -286,7 +288,7 @@ static mdl_header *mdl_load( const char *path )
 
    if( size < sizeof(mdl_header) )
    {
-      free( header );
+      vg_free( header );
       vg_error( "Invalid file '%s' (too small for header)\n", path );
       return NULL;
    }
@@ -296,7 +298,7 @@ static mdl_header *mdl_load( const char *path )
       vg_error( "Invalid file '%s'"
                 "(wrong .file_length, %ub != real file size %ub)\n", 
                 path, header->file_length, size );
-      free( header );
+      vg_free( header );
       return NULL;
    }
 
@@ -347,7 +349,7 @@ static mdl_header *mdl_load( const char *path )
 
       if( ri->count > ri->max_count )
       {
-         free( header );
+         vg_free( header );
          vg_error( "'%s': '%s' buffer exceeds the maximum (%u/%u)\n",
                path, ri->desc, ri->count, ri->max_count );
          return NULL;
@@ -355,7 +357,7 @@ static mdl_header *mdl_load( const char *path )
 
       if( ri->offset >= header->file_length )
       {
-         free( header );
+         vg_free( header );
          vg_error( "'%s': '%s' buffer offset is out of range\n",
                path, ri->desc );
          return NULL;
@@ -363,7 +365,7 @@ static mdl_header *mdl_load( const char *path )
 
       if( ri->offset + ri->size*ri->count > header->file_length )
       {
-         free( header );
+         vg_free( header );
          vg_error( "'%s': '%s' buffer size is out of range\n",
                path, ri->desc );
          return NULL;
@@ -378,7 +380,7 @@ static mdl_header *mdl_load( const char *path )
          if( ri->offset >= rj->offset && 
                (ri->offset+ri->size*ri->count < rj->offset+rj->size*rj->count))
          {
-            free( header );
+            vg_free( header );
             vg_error( "'%s': '%s' buffer overlaps '%s'\n",
                   path, ri->desc, rj->desc );
             return NULL;
@@ -470,15 +472,13 @@ static void mdl_node_transform( mdl_node *pnode, m4x3f transform )
    v3_copy( pnode->co, transform[3] );
 }
 
-__attribute__((warn_unused_result))
-static int mdl_unpack_submesh( mdl_header *mdl, glmesh *mesh, mdl_submesh *sm )
+static void mdl_unpack_submesh( mdl_header *mdl, glmesh *mesh, mdl_submesh *sm )
 {
-   return mesh_upload( mesh, mdl_submesh_vertices( mdl, sm ), sm->vertex_count,
-                             mdl_submesh_indices( mdl, sm ), sm->indice_count );
+   mesh_upload( mesh, mdl_submesh_vertices( mdl, sm ), sm->vertex_count,
+                      mdl_submesh_indices( mdl, sm ), sm->indice_count );
 }
 
-__attribute__((warn_unused_result))
-static int mdl_unpack_glmesh( mdl_header *mdl, glmesh *mesh )
+static void mdl_unpack_glmesh( mdl_header *mdl, glmesh *mesh )
 {
    u32 offset = mdl_submesh_from_id( mdl, 0 )->vertex_count;
 
@@ -496,8 +496,8 @@ static int mdl_unpack_glmesh( mdl_header *mdl, glmesh *mesh )
    mdl_vert *vertex_base = mdl_baseptr( mdl, mdl->vertex_offset );
    u32 *indice_base = mdl_baseptr( mdl, mdl->indice_offset );
 
-   return mesh_upload( mesh, vertex_base, mdl->vertex_count,
-                       indice_base, mdl->indice_count ); 
+   mesh_upload( mesh, vertex_base, mdl->vertex_count,
+                      indice_base, mdl->indice_count ); 
 }
 
 static void mdl_draw_submesh( mdl_submesh *sm )
index 42bee347766226016a3b85b522a437062ecf21e1..10e85dc231314fffb46fe60a7727373b2d787e4e 100644 (file)
--- a/network.h
+++ b/network.h
@@ -12,7 +12,7 @@
 #define SR_USE_LOCALHOST
 
 /* Call it at start; Connects us to the gameserver */
-static int network_init(void);
+static void network_init(void);
 
 /* Run this from main loop */
 static void network_update(void);
@@ -334,7 +334,7 @@ static void network_update(void)
    }
 }
 
-static int network_init(void)
+static void network_init(void)
 {
    if( steam_ready )
    {
@@ -342,8 +342,6 @@ static int network_init(void)
                                on_server_connect_status );
       request_auth_ticket();
    }
-
-   return 1;
 }
 
 static void network_end(void*_)
index 0a226afaffe04541c3315dfc602dd81f859c88f0..f03747a5098cf5afc8effde12f13fc0dce416a8b 100644 (file)
--- a/player.h
+++ b/player.h
@@ -177,7 +177,7 @@ static void player_restore_frame(void);
  * -----------------------------------------------------------------------------
  */
 
-static int player_init(void)                                             /* 1 */
+static void player_init(void)                                            /* 1 */
 {
    rb_init( &player.phys.rb );
    rb_init( &player.collide_front );
@@ -228,7 +228,8 @@ static int player_init(void)                                             /* 1 */
                .function = reset_player
        });
 
-   return player_model_init();
+   /* other systems */
+   vg_loader_highwater( player_model_init, player_model_free, NULL );
 }
 
 static void player_update(void)                                          /* 2 */
index e0693b16433aad19987cf4b81ade116c0d6269e4..97b476897c3500a1bfde5e17e1f7340717887b4f 100644 (file)
 
 vg_tex2d tex_characters = { .path = "textures/ch_gradient.qoi" };
 
-static int player_model_init(void)
+static void player_model_init(void)
 {
    shader_viewchar_register();
-
-   if( vg_acquire_thread_sync(1) )
+   vg_acquire_thread_sync();
    {
       vg_tex2d_init( (vg_tex2d *[]){ &tex_characters }, 1 );
-      vg_release_thread_sync(1);
-      return 1;
    }
-   else
-      return 0;
+   vg_release_thread_sync();
 }
 
 static void player_model_free(void *_)
 {
+   mesh_free( &player.mdl.mesh );
    vg_tex2d_free( (vg_tex2d *[]){ &tex_characters }, 1 );
 }
 
 /*
  * Load model from file (.mdl)
  */
-static int player_load_model( const char *name )
+static void player_load_model( const char *name )
 {
    char buf[64];
 
@@ -41,14 +38,15 @@ static int player_load_model( const char *name )
    mdl_header *src = mdl_load( buf );
 
    if( !src )
-      return 0;
+   {
+      vg_error( "Could not load model\n" );
+      return;
+   }
 
-   struct player_model *mdl = &player.mdl;
-   
-   if( !mdl_unpack_glmesh( src, &mdl->mesh ) )
-      goto il_free_err;
+   struct player_model temp;
 
-   skeleton_setup( &mdl->sk, src );
+   mdl_unpack_glmesh( src, &temp.mesh );
+   skeleton_setup( &temp.sk, src );
 
    /* 
     * Link animations
@@ -59,29 +57,30 @@ static int player_load_model( const char *name )
       struct skeleton_anim **anim;
    }
    anims[] = {
-      { "pose_stand",   &mdl->anim_stand },
-      { "pose_highg",   &mdl->anim_highg },
-      { "pose_slide",   &mdl->anim_slide },
-      { "pose_air",     &mdl->anim_air   },
-      { "push",         &mdl->anim_push  },
-      { "push_reverse", &mdl->anim_push_reverse },
-      { "ollie",        &mdl->anim_ollie },
-      { "ollie_reverse",&mdl->anim_ollie_reverse },
-      { "grabs",        &mdl->anim_grabs },
-      { "walk",         &mdl->anim_walk  },
-      { "run",          &mdl->anim_run   },
-      { "idle_cycle",   &mdl->anim_idle  }
+      { "pose_stand",   &temp.anim_stand },
+      { "pose_highg",   &temp.anim_highg },
+      { "pose_slide",   &temp.anim_slide },
+      { "pose_air",     &temp.anim_air   },
+      { "push",         &temp.anim_push  },
+      { "push_reverse", &temp.anim_push_reverse },
+      { "ollie",        &temp.anim_ollie },
+      { "ollie_reverse",&temp.anim_ollie_reverse },
+      { "grabs",        &temp.anim_grabs },
+      { "walk",         &temp.anim_walk  },
+      { "run",          &temp.anim_run   },
+      { "idle_cycle",   &temp.anim_idle  }
    };
    
    for( int i=0; i<vg_list_size(anims); i++ )
    {
-      *anims[i].anim = skeleton_get_anim( &mdl->sk, anims[i].name );
+      *anims[i].anim = skeleton_get_anim( &temp.sk, anims[i].name );
       
       if( !(*anims[i].anim) )
       {
          vg_error( "Animation '%s' is missing from character '%s'\n",
                      anims[i].name, name );
-         goto il_free_err;
+         vg_free( src );
+         return;
       }
    }
 
@@ -94,33 +93,32 @@ static int player_load_model( const char *name )
       u32 *bone_id;
    }
    bones[] = {
-      { "hips",      &mdl->id_hip },
-      { "hand.IK.L", &mdl->id_ik_hand_l },
-      { "hand.IK.R", &mdl->id_ik_hand_r },
-      { "elbow.L",   &mdl->id_ik_elbow_l },
-      { "elbow.R",   &mdl->id_ik_elbow_r },
-      { "head",      &mdl->id_head }
+      { "hips",      &temp.id_hip },
+      { "hand.IK.L", &temp.id_ik_hand_l },
+      { "hand.IK.R", &temp.id_ik_hand_r },
+      { "elbow.L",   &temp.id_ik_elbow_l },
+      { "elbow.R",   &temp.id_ik_elbow_r },
+      { "head",      &temp.id_head }
    };
 
    for( int i=0; i<vg_list_size(bones); i++ )
    {
-      *bones[i].bone_id = skeleton_bone_id( &mdl->sk, bones[i].name );
+      *bones[i].bone_id = skeleton_bone_id( &temp.sk, bones[i].name );
 
       if( !(*bones[i].bone_id) )
       {
          vg_error( "Required bone '%s' is missing from character '%s'\n",
                      bones[i].name, name );
-         goto il_free_err;
+         vg_free( src );
+         return;
       }
    }
 
+   /* swap temp into actual model */
+   mesh_free( &player.mdl.mesh );
+   player.mdl = temp;
    player_init_ragdoll( src );
-   free( src );
-   return 1;
-
-il_free_err:
-   free( src );
-   return 0;
+   vg_free( src );
 }
 
 #endif
index 9079bbc1d8c057ed24f7dd582c0b92ab7d9956fe..7fff465d8766ebd61858bc33fd3061c564b6d61c 100644 (file)
@@ -19,7 +19,7 @@ static void player_init_ragdoll( mdl_header *src )
       return;
    }
 
-   mdl->ragdoll = malloc(sizeof(struct ragdoll_part) * mdl->sk.collider_count);
+   mdl->ragdoll = vg_alloc(sizeof(struct ragdoll_part)*mdl->sk.collider_count);
    mdl->ragdoll_count = 0;
 
    for( u32 i=0; i<mdl->sk.bone_count; i ++ )
index 6a5b56d5beffc50b0aec45fbd7b56dfc9f13058d..706cf9b14de229dabdadba2b419e16135c5dd179 100644 (file)
--- a/render.h
+++ b/render.h
@@ -189,8 +189,7 @@ static void fb_use( struct framebuffer *fb )
    }
 }
 
-__attribute__((warn_unused_result))
-static int fb_init( struct framebuffer *fb )
+static void fb_init( struct framebuffer *fb )
 {
    i32 ix = vg_window_x / fb->div,
        iy = vg_window_y / fb->div;
@@ -216,15 +215,8 @@ static int fb_init( struct framebuffer *fb )
          GL_RENDERBUFFER, fb->rb );
    glBindFramebuffer( GL_FRAMEBUFFER, 0 );
 
-   if( VG_CHECK_GL_ERR() )
-   {
-      fb->allocated = 0;
-      vg_error( "Error while creating standard framebuffer\n" );
-      return 0;
-   }
-
+   VG_CHECK_GL_ERR();
    fb->allocated = 1;
-   return 1;
 }
 
 static void fb_free( struct framebuffer *fb )
@@ -268,14 +260,14 @@ static void render_fb_resize(void)
 /*
  * Vg
  */
-static int render_init(void)
+static void render_init(void)
 {
    shader_blit_register();
    shader_standard_register();
    shader_vblend_register();
    shader_unlit_register();
 
-   if( vg_acquire_thread_sync(1) )
+   vg_acquire_thread_sync();
    {
       vg_info( "Allocating framebuffers\n" );
 
@@ -293,12 +285,7 @@ static int render_init(void)
             GL_TEXTURE_2D, 
             gpipeline.rgb_background, 0);
 
-      if( VG_CHECK_GL_ERR() )
-      {
-         vg_error( "Error while creating back buffer\n" );
-         vg_release_thread_sync(1);
-         return 0;
-      }
+      VG_CHECK_GL_ERR();
 
       /* 
        * World depth map, maybe this should be moved to world.h
@@ -319,13 +306,7 @@ static int render_init(void)
             GL_TEXTURE_2D, 
             gpipeline.rgb_depthmap, 0);
 
-      if( VG_CHECK_GL_ERR() )
-      {
-         vg_error( "Error while creating world depth buffer\n" );
-         glBindFramebuffer( GL_FRAMEBUFFER, 0 );
-         vg_release_thread_sync(1);
-         return 0;
-      }
+      VG_CHECK_GL_ERR();
 
       float quad[] = { 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                        0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f };
@@ -340,13 +321,7 @@ static int render_init(void)
             sizeof(float)*2, (void*)0 );
       glEnableVertexAttribArray( 0 );
 
-      if( VG_CHECK_GL_ERR() )
-      {
-         vg_error( "Error while creating fsquad\n" );
-         glBindFramebuffer( GL_FRAMEBUFFER, 0 );
-         vg_release_thread_sync(1);
-         return 0;
-      }
+      VG_CHECK_GL_ERR();
 
       glGenBuffers( 1, &gpipeline.ubo_world_lighting );
       glBindBuffer( GL_UNIFORM_BUFFER, gpipeline.ubo_world_lighting );
@@ -356,23 +331,15 @@ static int render_init(void)
       render_update_lighting_ub();
       glBindBufferBase( GL_UNIFORM_BUFFER, 0, gpipeline.ubo_world_lighting );
 
-      if( VG_CHECK_GL_ERR() )
-      {
-         vg_error( "Error while creating world uniform buffers\n" );
-         glBindFramebuffer( GL_FRAMEBUFFER, 0 );
-         vg_release_thread_sync(1);
-         return 0;
-      }
+      VG_CHECK_GL_ERR();
 
       glBindFramebuffer( GL_FRAMEBUFFER, 0 );
       vg_success( "Done\n" );
       
       gpipeline.ready = 1;
-      vg_release_thread_sync(1);
-      return 1;
    }
-   else
-      return 0;
+
+   vg_release_thread_sync();
 }
 
 static void render_free(void *_)
diff --git a/scene.h b/scene.h
index acfc56b95c501dba14a0ecf456fcf6e63973e50d..d4d81ec6b59f44c8a40c5654f20c9dbb755d8276 100644 (file)
--- a/scene.h
+++ b/scene.h
@@ -28,10 +28,6 @@ struct scene
    mdl_submesh submesh;
 };
 
-#if 0
-GLuint tex_dual_noise;
-#endif
-
 static void scene_init( scene *pscene )
 {
    pscene->verts = NULL;
@@ -45,55 +41,19 @@ static void scene_init( scene *pscene )
 
    v3_fill( pscene->bbx[0],  999999.9f );
    v3_fill( pscene->bbx[1], -999999.9f );
-
-#if 0
-   static int noise_ready = 0;
-   if( !noise_ready )
-   {
-      noise_ready = 1;
-
-      u8 *buf = malloc( 256*256*2 );
-
-      for( int i=0; i<256*256; i++ )
-      {
-         u8 val = rand()&0xff;
-         buf[i*2] = val;
-      }
-
-      for( int y=0; y<256; y++ )
-      {
-         for( int x=0; x<256; x++ )
-         {
-            u8 *pr = &buf[(y*256+x)*2],
-               *pg = &buf[(((y+17)&0xff)*256+((x+37)&0xff))*2+1];
-            *pg = *pr;
-         }
-      }
-      
-      /* TODO: This texture should be delted somewhere */
-      glGenTextures( 1, &tex_dual_noise );
-      glBindTexture( GL_TEXTURE_2D, tex_dual_noise );
-      glTexImage2D( GL_TEXTURE_2D, 0, GL_RG, 256, 256, 0, GL_RG,
-            GL_UNSIGNED_BYTE, buf );
-
-      vg_tex2d_linear();
-      vg_tex2d_repeat();
-
-      free( buf );
-   }
-#endif
 }
 
 /* 
  * Append a model into the scene with a given transform
  */
 static void scene_add_submesh( scene *pscene, mdl_header *mdl, 
-      mdl_submesh *sm, m4x3f transform )
+                               mdl_submesh *sm, m4x3f transform )
 {
-   pscene->verts = buffer_reserve( pscene->verts, pscene->vertex_count, 
-         &pscene->vertex_cap, sm->vertex_count, sizeof(mdl_vert) );
+   pscene->verts  = buffer_reserve( pscene->verts, pscene->vertex_count, 
+                    &pscene->vertex_cap, sm->vertex_count, sizeof(mdl_vert) );
+
    pscene->indices = buffer_reserve( pscene->indices, pscene->indice_count,
-         &pscene->indice_cap, sm->indice_count, sizeof(u32) );
+                     &pscene->indice_cap, sm->indice_count, sizeof(u32) );
 
    m3x3f normal_matrix;
    m3x3_copy( transform, normal_matrix );
@@ -141,7 +101,7 @@ static void scene_add_submesh( scene *pscene, mdl_header *mdl,
 static void scene_push_tri( scene *pscene, u32 tri[3] )
 {
    pscene->indices = buffer_reserve( pscene->indices, pscene->indice_count,
-         &pscene->indice_cap, 3, sizeof(u32) );
+                                    &pscene->indice_cap, 3, sizeof(u32) );
 
    u32 *dst = &pscene->indices[pscene->indice_count];
    dst[0] = tri[0];
@@ -154,8 +114,7 @@ static void scene_push_tri( scene *pscene, u32 tri[3] )
 static void scene_push_vert( scene *pscene, mdl_vert *v )
 {
    pscene->verts = buffer_reserve( pscene->verts, pscene->vertex_count, 
-         &pscene->vertex_cap, 1, sizeof(mdl_vert) );
-
+                                  &pscene->vertex_cap, 1, sizeof(mdl_vert) );
    pscene->verts[pscene->vertex_count ++] = *v;
 }
 
@@ -180,21 +139,15 @@ static void scene_fix( scene *pscene )
          &pscene->indice_cap, sizeof( mdl_vert ));
 }
 
-__attribute__((warn_unused_result))
-static int scene_upload( scene *pscene )
+static void scene_upload( scene *pscene )
 {
-   if( ! mesh_upload( &pscene->mesh,
-         pscene->verts, pscene->vertex_count,
-         pscene->indices, pscene->indice_count ) )
-   {
-      return 0;
-   }
+   mesh_upload( &pscene->mesh,
+                pscene->verts, pscene->vertex_count,
+                pscene->indices, pscene->indice_count );
 
    vg_info( "Scene upload\n" );
    vg_info( "   indices:%u\n", pscene->indice_count );
    vg_info( "   verts:%u\n", pscene->vertex_count );
-
-   return 1;
 }
 
 static void scene_bind( scene *pscene )
@@ -209,13 +162,14 @@ static void scene_draw( scene *pscene )
 
 static void scene_free_offline_buffers( scene *pscene )
 {
-   free( pscene->verts );
-   free( pscene->indices );
+   vg_free( pscene->verts );
+   vg_free( pscene->indices );
 }
 
 static void scene_free( scene *pscene )
 {
    scene_free_offline_buffers( pscene );
+
    /* TODO: bvh */
 }
 
index abbef4e0d9445fa1a17ec14f83d068371f81a9a9..788bd197f9c70203244900147267f06349dc0c37 100644 (file)
@@ -416,8 +416,8 @@ static int skeleton_setup( struct skeleton *skele, mdl_header *mdl )
          skele->bone_count = inf->channels;
          skele->ik_count = inf->ik_count;
          skele->collider_count = inf->collider_count;
-         skele->bones = malloc(sizeof(struct skeleton_bone)*skele->bone_count);
-         skele->ik = malloc(sizeof(struct skeleton_ik)*skele->ik_count);
+         skele->bones =vg_alloc(sizeof(struct skeleton_bone)*skele->bone_count);
+         skele->ik = vg_alloc(sizeof(struct skeleton_ik)*skele->ik_count);
          skeleton_root = i;
       }
       else if( skele->bone_count )
@@ -522,9 +522,9 @@ static int skeleton_setup( struct skeleton *skele, mdl_header *mdl )
    skele->bones[0].parent = 0xffffffff;
    skele->bones[0].collider = 0;
    
-   skele->final_mtx = malloc( sizeof(m4x3f) * skele->bone_count );
+   skele->final_mtx = vg_alloc( sizeof(m4x3f) * skele->bone_count );
    skele->anim_count = inf->anim_count;
-   skele->anims = malloc( sizeof(struct skeleton_anim) * inf->anim_count);
+   skele->anims = vg_alloc( sizeof(struct skeleton_anim) * inf->anim_count);
    
    for( int i=0; i<inf->anim_count; i++ )
    {
@@ -537,7 +537,7 @@ static int skeleton_setup( struct skeleton *skele, mdl_header *mdl )
 
       u32 total_keyframes = (skele->bone_count-1)*anim->length;
       size_t block_size = sizeof(mdl_keyframe) * total_keyframes;
-      mdl_keyframe *dst = malloc( block_size );
+      mdl_keyframe *dst = vg_alloc( block_size );
 
       skele->anims[i].anim_data = dst;
       memcpy( dst, mdl_get_animdata( mdl, anim ), block_size );
@@ -549,8 +549,8 @@ static int skeleton_setup( struct skeleton *skele, mdl_header *mdl )
    return 1;
 
 error_dealloc:
-   free( skele->bones );
-   free( skele->ik );
+   vg_free( skele->bones );
+   vg_free( skele->ik );
    return 0;
 }
 
diff --git a/world.h b/world.h
index 8c5837d5c77cff4f7c117bf6e0954e83fac66cdf..9ae654e27937333728d5db924b404edb88723176 100644 (file)
--- a/world.h
+++ b/world.h
@@ -40,6 +40,12 @@ enum { k_route_ui_max_indices = k_max_ui_elements*k_max_element_indices };
 
 static struct gworld
 {
+   struct subworld_gen
+   {
+      
+   }
+   subworld_gen;
+
    /* gameplay */
    struct respawn_point
    {
@@ -233,7 +239,7 @@ static int ray_world( v3f pos, v3f dir, ray_hit *hit );
  * -----------------------------------------------------------------------------
  */
 
-static int world_init(void)
+static void world_init(void)
 {
    shader_terrain_register();
    shader_sky_register();
@@ -244,78 +250,42 @@ static int world_init(void)
 
    vg_info( "Loading world resources\n" );
 
-   mdl_header *mcars = mdl_load( "models/rs_cars.mdl" );
+   VG_REQUIRED_ASSET( mdl_header*, mcars, mdl_load, "models/rs_cars.mdl" );
+   VG_REQUIRED_ASSET( mdl_header*, msky,  mdl_load, "models/rs_skydome.mdl" );
+
    mdl_node *nholden = mdl_node_from_name( mcars, "holden" );
    world.car_holden = *mdl_node_submesh( mcars, nholden, 0 );
 
-   mdl_header *msky = mdl_load("models/rs_skydome.mdl");
    mdl_node *nlower = mdl_node_from_name( msky, "dome_lower" ),
             *nupper = mdl_node_from_name( msky, "dome_upper" );
    
    world.dome_lower = *mdl_node_submesh( msky, nlower, 0 );
    world.dome_upper = *mdl_node_submesh( msky, nupper, 0 );
 
-   /* TODO: cleanup resource acquisition */
-   if( !mcars || !msky )
-   {
-      free( mcars );
-      free( msky );
-      return 0;
-   }
-
-   if( vg_acquire_thread_sync(1) )
-   {
-      if( !mdl_unpack_glmesh( mcars, &world.cars ) )
-      {
-         free( mcars );
-         free( msky );
-         vg_release_thread_sync(1);
-         return 0;
-      }
-
-      if( !mdl_unpack_glmesh( msky, &world.skydome ) )
-      {
-         mesh_free( &world.cars );
-         free( mcars );
-         free( msky );
-         vg_release_thread_sync(1);
-         return 0;
-      }
-
-      vg_release_thread_sync(1);
-   }
-   else
+   vg_acquire_thread_sync();
    {
-      free(mcars);
-      free(msky);
-      return 0;
+      mdl_unpack_glmesh( mcars, &world.cars );
+      mdl_unpack_glmesh( msky, &world.skydome );
    }
+   vg_release_thread_sync();
 
-   free(mcars);
-   free(msky);
-
-   vg_info( "Loading other world systems\n" );
-
-   if( !vg_loader_highwater( (void *)mesh_free, &world.cars ) )        return 0;
-   if( !vg_loader_highwater( (void *)mesh_free, &world.skydome ) )     return 0;
+   vg_free(mcars);
+   vg_free(msky);
 
    /* Other systems */
+   vg_info( "Loading other world systems\n" );
 
-   if( !world_render_init() )                                          return 0;
-   if( !vg_loader_highwater( world_render_free, NULL ) )               return 0;
-
-   if( !world_sfd_init() )                                             return 0;
-   if( !vg_loader_highwater( world_sfd_free, NULL ) )                  return 0;
-
-   if( !world_water_init() )                                           return 0;
-   if( !vg_loader_highwater( world_water_free, NULL ) )                return 0;
-
-   if( !world_gates_init() )                                           return 0;
-   if( !vg_loader_highwater( world_gates_free, NULL ) )                return 0;
+   vg_loader_highwater( world_render_init, world_render_free, NULL );
+   vg_loader_highwater( world_sfd_init, world_sfd_free, NULL );
+   vg_loader_highwater( world_water_init, world_water_free, NULL );
+   vg_loader_highwater( world_gates_init, world_gates_free, NULL );
+   vg_loader_highwater( world_routes_init, world_routes_free, NULL );
+}
 
-   if( !world_routes_init() )                                          return 0;
-   if( !vg_loader_highwater( world_routes_free, NULL ) )               return 0;
-   return 1;
+static void world_free( void *_ )
+{
+   mesh_free( &world.cars );
+   mesh_free( &world.skydome );
 }
 
 static void world_update( v3f pos )
@@ -359,24 +329,6 @@ static void world_update( v3f pos )
    }
    
    sfd_update( &world.sfd.tester );
-
-#if 0
-   rb_solver_reset();
-   rb_build_manifold_terrain_sphere( &world.mr_ball );
-   
-   for( int i=0; i<5; i++ )
-      rb_solve_contacts( rb_contact_buffer, rb_contact_count );
-
-   rb_iter( &world.mr_ball );
-   rb_update_transform( &world.mr_ball );
-   rb_debug( &world.mr_ball, 0 );
-
-   for( int i=0; i<vg_list_size(world.van_man); i++ )
-   {
-      traffic_drive( &world.van_man[i] );
-      traffic_visualize_car( &world.van_man[i] );
-   }
-#endif
 }
 
 /* 
index 8434fb1e6c27a3ed45c6515478766dd319b07ad6..083d68be351fd983effc4017362a3f4167509dfc 100644 (file)
@@ -42,7 +42,7 @@ static void gate_transform_update( teleport_gate *gate )
    m4x3_mul( gate->recv_to_world, to_local, gate->transport );
 }
 
-static int world_gates_init(void)
+static void world_gates_init(void)
 {
    vg_info( "world_gates_init\n" );
    shader_gate_register();
@@ -50,32 +50,12 @@ static int world_gates_init(void)
 
    mdl_header *mgate = mdl_load( "models/rs_gate.mdl" );
 
-   if( vg_acquire_thread_sync(1) )
+   vg_acquire_thread_sync();
    {
-      if( !fb_init( &grender.fb ) )
-      {
-         free( mgate );
-         vg_release_thread_sync(1);
-         return 0;
-      }
-
-      if( !mdl_unpack_glmesh( mgate, &grender.mdl ) )
-      {
-         free( mgate );
-         fb_free( &grender.fb );
-         vg_release_thread_sync(1);
-         return 0;
-      }
-
-      vg_release_thread_sync(1);
+      fb_init( &grender.fb );
+      mdl_unpack_glmesh( mgate, &grender.mdl );
    }
-   else
-   {
-      free( mgate );
-      return 0;
-   }
-
-   return 1;
+   vg_release_thread_sync();
 }
 
 static void world_gates_free(void*_)
index d9037c9191fb0e97eb2e59cf5bf8f7c5be9c6ee4..4906603eda65f04d77bc3d77a6995a1b430944cc 100644 (file)
@@ -3,7 +3,6 @@
 
 #include "world.h"
 
-
 static void world_add_all_if_material( m4x3f transform, scene *pscene, 
                                        mdl_header *mdl, u32 id )
 {
@@ -87,7 +86,7 @@ static void world_apply_procedural_foliage(void)
       }
    }
 
-   free( mfoliage );
+   vg_free( mfoliage );
 }
 
 static void world_load(void)
@@ -129,17 +128,13 @@ static void world_load(void)
          
          if( sm )
          {
-
-            if( vg_acquire_thread_sync(1) )
+            vg_acquire_thread_sync();
             {
                glmesh surf;
-               if( mdl_unpack_submesh( mworld, &surf, sm ) )
-               {
-                  water_set_surface( &surf, pnode->co[1] );
-               }
-
-               vg_release_thread_sync(1);
+               mdl_unpack_submesh( mworld, &surf, sm );
+               water_set_surface( &surf, pnode->co[1] );
             }
+            vg_release_thread_sync();
          }
       }
       else if( pnode->classtype == k_classtype_car_path )
@@ -270,15 +265,9 @@ static void world_load(void)
       world_add_all_if_material( midentity, &world.geo,mworld,mat_vertex_blend);
    scene_copy_slice( &world.geo, &world.sm_geo_vb );
 
-   if( vg_acquire_thread_sync(1) )
-   {
-      if( !scene_upload( &world.geo ) )
-      {
-
-      }
-
-      vg_release_thread_sync(1);
-   }
+   vg_acquire_thread_sync();
+   scene_upload( &world.geo );
+   vg_release_thread_sync();
 
    scene_bh_create( &world.geo );
 
@@ -298,12 +287,9 @@ static void world_load(void)
    scene_copy_slice( &world.foliage, &world.sm_graffiti );
 
 
-   if( vg_acquire_thread_sync(1) )
+   vg_acquire_thread_sync();
    {
-      if( !scene_upload( &world.foliage ) )
-      {
-         
-      }
+      scene_upload( &world.foliage );
 
       /* 
        * Rendering the depth map
@@ -360,17 +346,17 @@ static void world_load(void)
 
       winfo->g_water_fog = 0.04f;
       render_update_lighting_ub();
-
-      vg_release_thread_sync(1);
    }
 
+   vg_release_thread_sync();
+
    world_routes_loadfrom( mworld );
 
    for( int i=0; i<world.instance_cache_count; i++ )
-      free( world.instance_cache[i].mdl );
+      vg_free( world.instance_cache[i].mdl );
 
-   free( world.instance_cache );
-   free( mworld );
+   vg_free( world.instance_cache );
+   vg_free( mworld );
    scene_free_offline_buffers( &world.foliage );
 
    /*
index 65494a5be204ea8f6e25b6e7adfddadb3f32a4f7..52b291376d155b6ffb27afe8c2cde1fc0921dc44 100644 (file)
@@ -15,22 +15,18 @@ vg_tex2d tex_alphatest = { .path = "textures/alphatest.qoi",
 vg_tex2d tex_graffiti = { .path = "textures/graffitibox.qoi",
                                  .flags = VG_TEXTURE_NEAREST };
 
-static int world_render_init(void)
+static void world_render_init(void)
 {
    vg_info( "Loading default world textures\n" );
 
-   if( vg_acquire_thread_sync(1) )
+   vg_acquire_thread_sync();
    {
       vg_tex2d_init( (vg_tex2d *[]){ &tex_terrain_colours, 
                                      &tex_terrain_noise,
                                      &tex_alphatest,
                                      &tex_graffiti }, 4 );
-
-      vg_release_thread_sync(1);
-      return 1;
    }
-
-   return 0;
+   vg_release_thread_sync();
 }
 
 static void world_render_free(void*_)
index 141cbc0fc9470602684c7c292c50b64e821fca3d..7920588e27e9672717669b890f7557d343d13b9a 100644 (file)
@@ -726,146 +726,145 @@ static void world_id_fixup( u32 *uid, mdl_header *mdl )
       *uid = 0xffffffff;
 }
 
-/* 
- * Create the strips of colour that run through the world along course paths
- */
-static int world_routes_gen_meshes(void)
+static void world_routes_create_mesh( u32 route_id )
 {
-   vg_info( "Generating route meshes\n" );
-
    struct subworld_routes *r = &world.routes;
-   scene_init( &r->scene_lines );
+   struct route *route = &r->routes[ route_id ];
 
-   for( int i=0; i<r->route_count; i++ )
-   {
-      struct route *route = &r->routes[i];
+   u32 stack[64];
+   u32 si = world_routes_get_path( route->start, stack );
 
-      u32 stack[64];
-      u32 si = world_routes_get_path( route->start, stack );
+   u32 last_valid = 0;
 
-      u32 last_valid = 0;
+   for( int sj=0; sj<si; sj++ )
+   {
+      int sk=(sj+1)%si;
 
-      for( int sj=0; sj<si; sj++ )
+      struct route_node *rnj = &r->nodes[ stack[sj] ],
+                        *rnk = &r->nodes[ stack[sk] ],
+                        *rnl;
+      
+      if( rnj->special_type && rnk->special_type )
       {
-         int sk=(sj+1)%si;
-
-         struct route_node *rnj = &r->nodes[ stack[sj] ],
-                           *rnk = &r->nodes[ stack[sk] ],
-                           *rnl;
-         
-         if( rnj->special_type && rnk->special_type )
-         {
-            last_valid = 0;
-            continue;
-         }
+         last_valid = 0;
+         continue;
+      }
 
-         float base_x0 = (float)rnj->ref_count*-0.5f + (float)rnj->current_refs,
-               base_x1 = (float)rnk->ref_count*-0.5f + (float)rnk->current_refs;
+      float base_x0 = (float)rnj->ref_count*-0.5f + (float)rnj->current_refs,
+            base_x1 = (float)rnk->ref_count*-0.5f + (float)rnk->current_refs;
 
-         if( rnk->special_type )
-         {
-            rnl = &r->nodes[ rnk->next[0] ];
-            base_x1 = (float)rnl->ref_count*-0.5f + (float)rnl->current_refs;
-         }
+      if( rnk->special_type )
+      {
+         rnl = &r->nodes[ rnk->next[0] ];
+         base_x1 = (float)rnl->ref_count*-0.5f + (float)rnl->current_refs;
+      }
 
-         if( sk == 0 )
-         {
-            base_x1 -= 1.0f;
-         }
+      if( sk == 0 )
+      {
+         base_x1 -= 1.0f;
+      }
 
-         v3f p0, h0, p1, h1, p, pd;
-         
-         v3_copy( rnj->co, p0 );
-         v3_muladds( rnj->co, rnj->h,  1.0f, h0 );
-         v3_copy( rnk->co, p1 );
-         v3_muladds( rnk->co, rnk->h, -1.0f, h1 );
+      v3f p0, h0, p1, h1, p, pd;
+      
+      v3_copy( rnj->co, p0 );
+      v3_muladds( rnj->co, rnj->h,  1.0f, h0 );
+      v3_copy( rnk->co, p1 );
+      v3_muladds( rnk->co, rnk->h, -1.0f, h1 );
 
-         float t=0.0f;
-         int it = 0;
+      float t=0.0f;
+      int it = 0;
 
-         for( int it=0; it<256; it ++ )
-         {
-            float const k_sample_dist = 0.02f;
-            eval_bezier_time( p0,p1,h0,h1, t,p );
-            eval_bezier_time( p0,p1,h0,h1, t+k_sample_dist,pd );
+      for( int it=0; it<256; it ++ )
+      {
+         float const k_sample_dist = 0.02f;
+         eval_bezier_time( p0,p1,h0,h1, t,p );
+         eval_bezier_time( p0,p1,h0,h1, t+k_sample_dist,pd );
 
-            float mod = k_sample_dist / v3_dist( p, pd );
+         float mod = k_sample_dist / v3_dist( p, pd );
 
-            v3f v0,up, right;
-            v3_muls( rnj->up, 1.0f-t, up );
-            v3_muladds( up, rnk->up, t, up );
+         v3f v0,up, right;
+         v3_muls( rnj->up, 1.0f-t, up );
+         v3_muladds( up, rnk->up, t, up );
 
-            v3_sub( pd,p,v0 );
-            v3_cross( up, v0, right );
-            v3_normalize( right );
+         v3_sub( pd,p,v0 );
+         v3_cross( up, v0, right );
+         v3_normalize( right );
 
-            float cur_x = (1.0f-t)*base_x0 + t*base_x1;
-            
-            v3f sc, sa, sb, down;
-            v3_muladds( p, right, cur_x, sc );
-            v3_muladds( sc, up, 1.5f, sc );
-            v3_muladds( sc, right,  0.45f, sa );
-            v3_muladds( sc, right, -0.45f, sb );
-            v3_muls( up, -1.0f, down );
+         float cur_x = (1.0f-t)*base_x0 + t*base_x1;
+         
+         v3f sc, sa, sb, down;
+         v3_muladds( p, right, cur_x, sc );
+         v3_muladds( sc, up, 1.5f, sc );
+         v3_muladds( sc, right,  0.45f, sa );
+         v3_muladds( sc, right, -0.45f, sb );
+         v3_muls( up, -1.0f, down );
+         
+         ray_hit ha, hb;
+         ha.dist = 8.0f;
+         hb.dist = 8.0f;
+         if( ray_world( sa, down, &ha ) && 
+             ray_world( sb, down, &hb ))
+         {
+            mdl_vert va, vb;
             
-            ray_hit ha, hb;
-            ha.dist = 8.0f;
-            hb.dist = 8.0f;
-            if(ray_world( sa, down, &ha ) && 
-               ray_world( sb, down, &hb ))
-            {
-               mdl_vert va, vb;
-               
-               v3_muladds( ha.pos, up, 0.06f, va.co );
-               v3_muladds( hb.pos, up, 0.06f, vb.co );
-               v3_copy( up, va.norm );
-               v3_copy( up, vb.norm );
-               v2_zero( va.uv );
-               v2_zero( vb.uv );
-
-               scene_push_vert( &r->scene_lines, &va );
-               scene_push_vert( &r->scene_lines, &vb );
-
-               if( last_valid )
-               {
-                  /* Connect them with triangles */
-                  scene_push_tri( &r->scene_lines, (u32[3]){ 
-                        last_valid+0-2, last_valid+1-2, last_valid+2-2} );
-                  scene_push_tri( &r->scene_lines, (u32[3]){ 
-                        last_valid+1-2, last_valid+3-2, last_valid+2-2} );
-               }
-               
-               last_valid = r->scene_lines.vertex_count;
-            }
-            else
-               last_valid = 0;
+            v3_muladds( ha.pos, up, 0.06f, va.co );
+            v3_muladds( hb.pos, up, 0.06f, vb.co );
+            v3_copy( up, va.norm );
+            v3_copy( up, vb.norm );
+            v2_zero( va.uv );
+            v2_zero( vb.uv );
 
-            t += 1.0f*mod;
+            scene_push_vert( &r->scene_lines, &va );
+            scene_push_vert( &r->scene_lines, &vb );
 
-            if( t >= 1.0f )
+            if( last_valid )
             {
-               /* TODO special case for end of loop, need to add triangles
-                *      between first and last rungs */
-               break;
+               /* Connect them with triangles */
+               scene_push_tri( &r->scene_lines, (u32[3]){ 
+                     last_valid+0-2, last_valid+1-2, last_valid+2-2} );
+               scene_push_tri( &r->scene_lines, (u32[3]){ 
+                     last_valid+1-2, last_valid+3-2, last_valid+2-2} );
             }
+            
+            last_valid = r->scene_lines.vertex_count;
          }
+         else
+            last_valid = 0;
+
+         t += 1.0f*mod;
 
-         rnj->current_refs ++;
+         if( t >= 1.0f )
+         {
+            /* TODO special case for end of loop, need to add triangles
+             *      between first and last rungs */
+            break;
+         }
       }
 
-      scene_copy_slice( &r->scene_lines, &route->sm );
+      rnj->current_refs ++;
    }
 
-   if( vg_acquire_thread_sync(1) )
+   scene_copy_slice( &r->scene_lines, &route->sm );
+}
+
+/* 
+ * Create the strips of colour that run through the world along course paths
+ */
+static int world_routes_create_all_meshes(void)
+{
+   vg_info( "Generating route meshes\n" );
+
+   struct subworld_routes *r = &world.routes;
+   scene_init( &r->scene_lines );
+
+   for( u32 i=0; i<r->route_count; i++ )
+      world_routes_create_mesh( i );
+
+   vg_acquire_thread_sync();
    {
-      if( !scene_upload( &r->scene_lines ) )
-      {
-         vg_release_thread_sync(1);
-         return 0;
-      }
+      scene_upload( &r->scene_lines );
 
       /* UI buffers */
-
       for( int i=0; i<r->route_count; i++ )
       {
          /* OpenGL strips */
@@ -880,7 +879,8 @@ static int world_routes_gen_meshes(void)
 
          glBindBuffer( GL_ARRAY_BUFFER, route->ui.vbo );
          glBufferData( GL_ARRAY_BUFFER, k_route_ui_max_verts*stride, 
-               NULL, GL_DYNAMIC_DRAW );
+                       NULL, GL_DYNAMIC_DRAW );
+
          glBindVertexArray( route->ui.vao );
          glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, route->ui.ebo );
          glBufferData( GL_ELEMENT_ARRAY_BUFFER, 
@@ -891,13 +891,8 @@ static int world_routes_gen_meshes(void)
          glEnableVertexAttribArray( 0 );
          VG_CHECK_GL_ERR();
       }
-
-      vg_release_thread_sync(1);
-   }
-   else
-   {
-      return 0;
    }
+   vg_release_thread_sync();
 
    scene_free_offline_buffers( &r->scene_lines );
    return 1;
@@ -910,15 +905,14 @@ static void world_routes_loadfrom( mdl_header *mdl )
 
    struct subworld_routes *r = &world.routes;
    r->nodes = NULL;
-   r->node_count = 0;
-   r->node_cap = 0;
-   r->routes = NULL;
+   r->node_count = 0; r->node_cap = 0; r->routes = NULL;
    r->route_count = 0;
    r->route_cap = 0;
    r->gates = NULL;
    r->gate_count = 0;
    r->gate_cap = 0;
 
+   /* TODO Break this up */
    for( int i=0; i<mdl->node_count; i++ )
    {
       mdl_node *pnode = mdl_node_from_id(mdl,i);
@@ -1087,7 +1081,7 @@ static void world_routes_loadfrom( mdl_header *mdl )
       }
    }
 
-   world_routes_gen_meshes();
+   world_routes_create_all_meshes();
 }
 
 /* 
@@ -1096,24 +1090,22 @@ static void world_routes_loadfrom( mdl_header *mdl )
  * -----------------------------------------------------------------------------
  */
 
-static int world_routes_init(void)
+static void world_routes_init(void)
 {
    struct subworld_routes *r = &world.routes;
    r->current_run_version = 2;
 
    shader_route_register();
    shader_routeui_register();
-
-   return 1;
 }
 
 static void world_routes_free(void*_)
 {
    struct subworld_routes *r = &world.routes;
 
-   free( r->nodes );
-   free( r->routes );
-   free( r->gates );
+   vg_free( r->nodes );
+   vg_free( r->routes );
+   vg_free( r->gates );
 }
 
 static void world_routes_update(void)
index 05f191d1d9b9cae9cb9b4aff1b0439cca68c6e4d..f765910e56dd71bb7aa89eebd9ef2756d0d6934a 100644 (file)
@@ -72,7 +72,7 @@ static void sfd_new( struct sfd_instance *display, u32 w, u32 h )
 {
    display->w = w;
    display->h = h;
-   display->buffer = malloc( w*h*sizeof(float)*2 );
+   display->buffer = vg_alloc( w*h*sizeof(float)*2 );
 
    for( int i=0; i<w*h*2; i++ )
       display->buffer[i] = 0.0f;
@@ -153,7 +153,7 @@ static int world_sfd_test( int argc, const char *argv[] )
    return 0;
 }
 
-static int world_sfd_init(void)
+static void world_sfd_init(void)
 {
    vg_info( "world_sfd_init\n" );
    shader_scoretext_register();
@@ -192,33 +192,18 @@ static int world_sfd_init(void)
       }
    }
 
-   if( vg_acquire_thread_sync(1) )
+   vg_acquire_thread_sync();
    {
       vg_tex2d_init( (vg_tex2d *[]){ &tex_scoretext }, 1 );
-      if( !scene_upload( &sfd->mesh ) )
-      {
-         vg_release_thread_sync(1);
-         return 0;
-      }
-
-      if( !mdl_unpack_submesh( mboard, &sfd->temp, backer ) )
-      {
-         vg_release_thread_sync(1);
-         return 0;
-      }
 
-      vg_release_thread_sync(1);
-   }
-   else
-   {
-      free( mboard );
-      return 0;
+      scene_upload( &sfd->mesh );
+      mdl_unpack_submesh( mboard, &sfd->temp, backer );
    }
+   vg_release_thread_sync();
 
    scene_free_offline_buffers( &sfd->mesh );
    sfd_new( &sfd->tester, 27, 13 );
-   free( mboard );
-   return 1;
+   vg_free( mboard );
 }
 
 
index 11d9594d6fada5c0729b066d172db2cb7467b73a..ab67e76601b1823501dc670501931e1879a2299c 100644 (file)
@@ -26,28 +26,20 @@ wrender =
    .fbdepth   = { .format = GL_RGBA, .div = 4 }
 };
 
-static int world_water_init(void)
+static void world_water_init(void)
 {
    vg_info( "world_water_init\n" );
    shader_water_register();
    
-   if( vg_acquire_thread_sync(1) )
+   vg_acquire_thread_sync();
    {
-      if( !fb_init( &wrender.fbreflect ) ||
-          !fb_init( &wrender.fbdepth ) )
-      {
-         vg_release_thread_sync(1);
-         return 0;
-      }
+      fb_init( &wrender.fbreflect );
+      fb_init( &wrender.fbdepth );
 
       vg_tex2d_init( (vg_tex2d *[]){&tex_water_surf}, 1 );
-
       vg_success( "done\n" );
-      vg_release_thread_sync(1);
-      return 1;
    }
-   else
-      return 0;
+   vg_release_thread_sync();
 }
 
 static void world_water_free(void *_)