.name = "Gate"
};
-static int audio_init(void)
+static void audio_init(void)
{
audio_player_init( &audio_player0 );
audio_player_init( &audio_player1 );
.opt_f32 = { .clamp = 0 },
.persistent = 1
});
-
- return 1;
}
static void audio_free(void*_)
{
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;
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 )
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;
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;
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 )
highscore_malloc( playerinfo_pool_size, sizeof(highscore_playerinfo));
if( !sys->playerinfo_data )
{
- free( sys->data );
+ vg_free( sys->data );
return 0;
}
highscores_free();
}
-int vg_preload(void)
+void vg_preload(void)
{
vg_convar_push( (struct vg_convar){
.name = "cl_ui",
"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)
audio_debug_soundscapes();
}
-void vg_free(void)
-{
-}
-
#if 0
static void run_light_widget( struct light_widget *lw )
{
{
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 );
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 )
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 );
+ }
}
if( size < sizeof(mdl_header) )
{
- free( header );
+ vg_free( header );
vg_error( "Invalid file '%s' (too small for header)\n", path );
return NULL;
}
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;
}
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;
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;
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;
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;
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;
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 )
#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);
}
}
-static int network_init(void)
+static void network_init(void)
{
if( steam_ready )
{
on_server_connect_status );
request_auth_ticket();
}
-
- return 1;
}
static void network_end(void*_)
* -----------------------------------------------------------------------------
*/
-static int player_init(void) /* 1 */
+static void player_init(void) /* 1 */
{
rb_init( &player.phys.rb );
rb_init( &player.collide_front );
.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 */
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];
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
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;
}
}
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
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 ++ )
}
}
-__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;
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 )
/*
* 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" );
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
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 };
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 );
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 *_)
mdl_submesh submesh;
};
-#if 0
-GLuint tex_dual_noise;
-#endif
-
static void scene_init( scene *pscene )
{
pscene->verts = NULL;
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 );
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];
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;
}
&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 )
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 */
}
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 )
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++ )
{
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 );
return 1;
error_dealloc:
- free( skele->bones );
- free( skele->ik );
+ vg_free( skele->bones );
+ vg_free( skele->ik );
return 0;
}
static struct gworld
{
+ struct subworld_gen
+ {
+
+ }
+ subworld_gen;
+
/* gameplay */
struct respawn_point
{
* -----------------------------------------------------------------------------
*/
-static int world_init(void)
+static void world_init(void)
{
shader_terrain_register();
shader_sky_register();
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 )
}
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
}
/*
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();
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*_)
#include "world.h"
-
static void world_add_all_if_material( m4x3f transform, scene *pscene,
mdl_header *mdl, u32 id )
{
}
}
- free( mfoliage );
+ vg_free( mfoliage );
}
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 )
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 );
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
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 );
/*
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*_)
*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 */
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,
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;
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);
}
}
- world_routes_gen_meshes();
+ world_routes_create_all_meshes();
}
/*
* -----------------------------------------------------------------------------
*/
-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)
{
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;
return 0;
}
-static int world_sfd_init(void)
+static void world_sfd_init(void)
{
vg_info( "world_sfd_init\n" );
shader_scoretext_register();
}
}
- 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 );
}
.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 *_)