X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_sfd.h;h=0f8e3746d567798e10d847fa4adfb4f3d8e7f645;hb=15beb60ade240af4e00b0d204f7e89a4d35dca36;hp=c6fa66b0fdb49942485fb85c8fb3ab022fc22132;hpb=86dbcd5796ed674ca9433cce1ace8bef322cd121;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_sfd.h b/world_sfd.h index c6fa66b..0f8e374 100644 --- a/world_sfd.h +++ b/world_sfd.h @@ -1,3 +1,7 @@ +/* + * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved + */ + #ifndef SFD_H #define SFD_H @@ -52,18 +56,20 @@ float sfd_encode_glyph( char c ) static void sfd_encode( struct sfd_instance *display, u32 row, const char *str ) { int end=0; + u32 row_h = display->h-1-row; + for( int i=0; iw; i++ ) { if( end ) { - display->buffer[display->w*row + i] = 0.0f; + display->buffer[display->w*row_h + i] = 0.0f; } else { if( !str[i] ) end = 1; - display->buffer[display->w*row + i] = sfd_encode_glyph( str[i] ); + display->buffer[display->w*row_h + i] = sfd_encode_glyph( str[i] ); } } } @@ -72,7 +78,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; ibuffer[i] = 0.0f; @@ -85,7 +91,7 @@ static void sfd_update( struct sfd_instance *display ) float *target = &display->buffer[i], *cur = target+display->w*display->h; - float const rate = ktimestep*15.2313131414f; + float const rate = vg.time_delta * 15.2313131414f; float d1 = *target-*cur; if( fabsf(d1) > rate ) @@ -155,6 +161,9 @@ static int world_sfd_test( int argc, const char *argv[] ) static void world_sfd_init(void) { + vg_info( "world_sfd_init\n" ); + shader_scoretext_register(); + struct subworld_sfd *sfd = &world.sfd; vg_function_push( (struct vg_cmd){ @@ -163,20 +172,17 @@ static void world_sfd_init(void) }); mdl_header *mboard = mdl_load( "models/rs_scoretext.mdl" ); - scene_init( &sfd->mesh ); - mdl_node *pn_card = mdl_node_from_name( mboard, "score_card" ); - mdl_submesh *card = mdl_submesh_from_id( mboard, pn_card->submesh_start ); - mdl_node *pn_backer = mdl_node_from_name( mboard, "backer" ); mdl_submesh *backer = mdl_submesh_from_id( mboard, pn_backer->submesh_start); - mdl_unpack_submesh( mboard, &sfd->temp, backer ); + mdl_node *pn_card = mdl_node_from_name( mboard, "score_card" ); + mdl_submesh *card = mdl_submesh_from_id( mboard, pn_card->submesh_start ); m4x3f identity; m4x3_identity( identity ); - for( int i=0;i<8;i++ ) + for( int i=4;i<6;i++ ) { u32 vert_start = sfd->mesh.vertex_count; scene_add_submesh( &sfd->mesh, mboard, card, identity ); @@ -192,22 +198,24 @@ static void world_sfd_init(void) } } - scene_upload( &sfd->mesh ); - scene_free_offline_buffers( &sfd->mesh ); + vg_acquire_thread_sync(); + { + vg_tex2d_init( (vg_tex2d *[]){ &tex_scoretext }, 1 ); - free( mboard ); - vg_tex2d_init( (vg_tex2d *[]){ &tex_scoretext }, 1 ); + 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 ); + vg_free( mboard ); } -static void world_sfd_register(void) -{ - shader_scoretext_register(); -} -static void world_sfd_free(void) +static void world_sfd_free(void *_) { + mesh_free( &world.sfd.mesh.mesh ); vg_tex2d_free( (vg_tex2d *[]){ &tex_scoretext }, 1 ); }