scoreboards
[carveJwlIkooP6JGAAIwe30JlM.git] / world_sfd.h
index 88f73316585dc28980d4b708da56045be628dafa..29244e8c843caf70dfcb3ad73b3e60323b3a6035 100644 (file)
@@ -1,8 +1,10 @@
+/*
+ * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
+ */
+
 #ifndef SFD_H
 #define SFD_H
 
-#include "common.h"
-#include "model.h"
 #include "world.h"
 
 #include "shaders/scoretext.h"
 vg_tex2d tex_scoretext = { .path = "textures/scoretext.qoi",
                            .flags = VG_TEXTURE_CLAMP|VG_TEXTURE_NEAREST };
 
-struct sfd_instance
-{
-   float *buffer;
-
-   u32 w,h;
-};
-
-
-struct subworld_sfd
-{
-   scene mesh;
-   mdl_submesh *sm_module, *sm_card;
-   glmesh temp;
-
-   struct sfd_instance tester;
-};
-
-static struct subworld_sfd *subworld_sfd(void);
-
+/* 
+ * TODO: utf-8 -> ascii
+ */
 
 float sfd_encode_glyph( char c )
 {
@@ -44,7 +30,7 @@ float sfd_encode_glyph( char c )
       value = 63-c;
    else
    {
-      int base = 'A'+11+27;
+      int base = 11+26;
 
       switch( c )
       {
@@ -58,8 +44,8 @@ float sfd_encode_glyph( char c )
          case '*': value=base+7; break;
          case '+': value=base+8; break;
          case '-': value=base+9; break;
-         case ':': value=base+10; break;
-         case '/': value=base+11; break;
+         case '/': value=base+10; break;
+         case ':': value=base+11; break;
          default: value=0; break;
       }
    }
@@ -90,7 +76,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;
@@ -103,7 +89,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 )
@@ -120,7 +106,7 @@ static void sfd_update( struct sfd_instance *display )
 static void sfd_render( struct sfd_instance *display, 
                         m4x4f projection, v3f camera, m4x3f transform )
 {
-   struct subworld_sfd *sfd = subworld_sfd();
+   struct subworld_sfd *sfd = &world.sfd;
    scene_bind( &sfd->mesh );
 
    shader_scoretext_use();
@@ -160,7 +146,7 @@ static void sfd_render( struct sfd_instance *display,
 
 static int world_sfd_test( int argc, const char *argv[] )
 {
-   struct subworld_sfd *sfd = subworld_sfd();
+   struct subworld_sfd *sfd = &world.sfd;
 
    if( argc == 2 )
    {
@@ -173,7 +159,10 @@ static int world_sfd_test( int argc, const char *argv[] )
 
 static void world_sfd_init(void)
 {
-   struct subworld_sfd *sfd = subworld_sfd();
+   vg_info( "world_sfd_init\n" );
+   shader_scoretext_register();
+
+   struct subworld_sfd *sfd = &world.sfd;
 
        vg_function_push( (struct vg_cmd){
                .name = "sfd",
@@ -181,20 +170,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 );
@@ -206,26 +192,28 @@ static void world_sfd_init(void)
          float const k_glyph_uvw = 1.0f/64.0f;
          vert->uv[0] -= k_glyph_uvw * (float)(i-4);
          vert->colour[0] = 0.0f;
-         vert->colour[1] = i-4;
+         vert->colour[1] = i*36;
       }
    }
 
-   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();
 
-   sfd_new( &sfd->tester, 16, 8 );
+   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 );
 }