X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_sfd.h;h=a83fe0a92359c4b8cb9cb885fb30b9dc360474d2;hb=47941822dae18a018c985847b052e70214a3ccc6;hp=0f8e3746d567798e10d847fa4adfb4f3d8e7f645;hpb=4f96bd0040e35ecb21d353ee2b895129682d22c1;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_sfd.h b/world_sfd.h index 0f8e374..a83fe0a 100644 --- a/world_sfd.h +++ b/world_sfd.h @@ -53,43 +53,37 @@ float sfd_encode_glyph( char c ) return (float)value; } -static void sfd_encode( struct sfd_instance *display, u32 row, const char *str ) +VG_STATIC void sfd_encode( u32 row, const char *str ) { int end=0; - u32 row_h = display->h-1-row; + u32 row_h = world.sfd.h -1 -row; - for( int i=0; iw; i++ ) + for( int i=0; ibuffer[display->w*row_h + i] = 0.0f; + world.sfd.buffer[world.sfd.w*row_h + i] = 0.0f; } else { if( !str[i] ) end = 1; - display->buffer[display->w*row_h + i] = sfd_encode_glyph( str[i] ); + world.sfd.buffer[world.sfd.w*row_h + i] = sfd_encode_glyph( str[i] ); } } } -static void sfd_new( struct sfd_instance *display, u32 w, u32 h ) +VG_STATIC void sfd_init( u32 w, u32 h ) { - display->w = w; - display->h = h; - display->buffer = vg_alloc( w*h*sizeof(float)*2 ); - - for( int i=0; ibuffer[i] = 0.0f; } -static void sfd_update( struct sfd_instance *display ) +VG_STATIC void sfd_update(void) { - for( int i=0; iw*display->h; i++ ) + for( int i=0; ibuffer[i], - *cur = target+display->w*display->h; + float *target = &world.sfd.buffer[i*2+0], + *cur = &world.sfd.buffer[i*2+1]; float const rate = vg.time_delta * 15.2313131414f; float d1 = *target-*cur; @@ -105,11 +99,9 @@ static void sfd_update( struct sfd_instance *display ) } } -static void sfd_render( struct sfd_instance *display, - m4x4f projection, v3f camera, m4x3f transform ) +VG_STATIC void sfd_render( m4x4f projection, v3f camera, m4x3f transform ) { - struct subworld_sfd *sfd = &world.sfd; - scene_bind( &sfd->mesh ); + mesh_bind( &world.sfd.mesh_display ); shader_scoretext_use(); shader_scoretext_uTexGarbage(0); @@ -122,13 +114,13 @@ static void sfd_render( struct sfd_instance *display, shader_scoretext_uMdl( transform ); shader_scoretext_uCamera( camera ); - for( int y=0;yh; y++ ) + for( int y=0;yw; x++ ) + for( int x=0; xbuffer[display->h*display->w+y*display->w+x]; + float value = world.sfd.buffer[(y*world.sfd.w+x)*2+1]; shader_scoretext_uInfo( (v3f){ x,y, value } ); - scene_draw( &sfd->mesh ); + mesh_draw( &world.sfd.mesh_display ); } } @@ -142,54 +134,53 @@ static void sfd_render( struct sfd_instance *display, shader_vblend_uMdl( transform ); shader_vblend_uCamera( camera ); - mesh_bind( &sfd->temp ); - mesh_draw( &sfd->temp ); + mesh_bind( &world.sfd.mesh_base ); + mesh_draw( &world.sfd.mesh_base ); } -static int world_sfd_test( int argc, const char *argv[] ) +VG_STATIC int world_sfd_test( int argc, const char *argv[] ) { - struct subworld_sfd *sfd = &world.sfd; - if( argc == 2 ) { - int row = vg_min(vg_max(atoi(argv[0]),0),sfd->tester.h); - sfd_encode( &sfd->tester, row, argv[1] ); + int row = vg_min( vg_max(atoi(argv[0]),0), world.sfd.h); + sfd_encode( row, argv[1] ); } return 0; } -static void world_sfd_init(void) +VG_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){ .name = "sfd", .function = world_sfd_test }); - mdl_header *mboard = mdl_load( "models/rs_scoretext.mdl" ); - scene_init( &sfd->mesh ); + vg_linear_clear( vg_mem.scratch ); + mdl_context *mboard = + mdl_load_full( vg_mem.scratch, "models/rs_scoretext.mdl" ); + + scene *sc = scene_init( vg_mem.scratch, 3000, 8000 ); mdl_node *pn_backer = mdl_node_from_name( mboard, "backer" ); - mdl_submesh *backer = mdl_submesh_from_id( mboard, pn_backer->submesh_start); + mdl_submesh *backer = &mboard->submesh_buffer[ pn_backer->submesh_start ]; mdl_node *pn_card = mdl_node_from_name( mboard, "score_card" ); - mdl_submesh *card = mdl_submesh_from_id( mboard, pn_card->submesh_start ); + mdl_submesh *card = &mboard->submesh_buffer[ pn_card->submesh_start ]; m4x3f identity; m4x3_identity( identity ); for( int i=4;i<6;i++ ) { - u32 vert_start = sfd->mesh.vertex_count; - scene_add_submesh( &sfd->mesh, mboard, card, identity ); + u32 vert_start = sc->vertex_count; + scene_add_submesh( sc, mboard, card, identity ); for( int j=0; jvertex_count; j++ ) { - mdl_vert *vert = &sfd->mesh.verts[ vert_start+j ]; + mdl_vert *vert = &sc->arrvertices[ vert_start+j ]; float const k_glyph_uvw = 1.0f/64.0f; vert->uv[0] -= k_glyph_uvw * (float)(i-4); @@ -200,23 +191,22 @@ static void world_sfd_init(void) vg_acquire_thread_sync(); { - vg_tex2d_init( (vg_tex2d *[]){ &tex_scoretext }, 1 ); + scene_upload( sc, &world.sfd.mesh_display ); + mdl_unpack_submesh( mboard, &world.sfd.mesh_base, backer ); - scene_upload( &sfd->mesh ); - mdl_unpack_submesh( mboard, &sfd->temp, backer ); + vg_tex2d_init( (vg_tex2d *[]){ &tex_scoretext }, 1 ); } vg_release_thread_sync(); - scene_free_offline_buffers( &sfd->mesh ); - sfd_new( &sfd->tester, 27, 13 ); - vg_free( mboard ); -} + int w = 27, + h = 13; + world.sfd.w = w; + world.sfd.h = h; + world.sfd.buffer = vg_linear_alloc( vg_mem.rtmemory, 2*w*h*sizeof(float) ); -static void world_sfd_free(void *_) -{ - mesh_free( &world.sfd.mesh.mesh ); - vg_tex2d_free( (vg_tex2d *[]){ &tex_scoretext }, 1 ); + for( int i=0; i