smol skinning changes and cvars
authorhgn <hgodden00@gmail.com>
Sat, 25 Oct 2025 01:08:06 +0000 (02:08 +0100)
committerhgn <hgodden00@gmail.com>
Sat, 25 Oct 2025 01:08:06 +0000 (02:08 +0100)
source/console/console_system.c
source/engine/engine.kv
source/engine/metascene.h
source/engine/model.c
source/engine/model.h
source/engine/shaders/blit_colour.fs [new file with mode: 0644]
source/engine/shaders/blit_colour.vs [new file with mode: 0644]
source/engine/vg_engine.c
source/engine/vg_lines.c
source/tools/metacompiler.c

index c30470f1eab8e318c3a632227fe9026861e287a8..7545f765476091471cfd1fdc227fba6abfc75592 100644 (file)
@@ -1,10 +1,23 @@
 #include "foundation.h"
 #include "console_system.h"
 
-struct console_command 
+struct console_item
 {
    const c8 *alias;
-   i32 (*fn)( struct console_arguments *args );
+   enum console_item_type
+   {
+      k_console_item_ccmd,
+      k_console_item_cvar_i32,
+      k_console_item_cvar_f32
+   }
+   type;
+
+   union
+   {
+      i32 (*fn)( struct console_arguments *args );
+      i32 *_i32;
+      f32 *_f32;
+   };
 };
 
 #include "generated/console.c"
@@ -63,7 +76,7 @@ void _console_execute( const c8 *command, b8 silent, b8 cheat_allowed )
    args.count = 0;
 
    u32 temp_frame = _start_temporary_frame();
-   struct console_command *target_command = NULL;
+   struct console_item *target_command = NULL;
 
    // TODO: warning if we put to many or to few arguments & required ones.
    for( u32 i=0; i<ARRAY_COUNT(args.arguments)+1; i ++ )
@@ -74,9 +87,9 @@ void _console_execute( const c8 *command, b8 silent, b8 cheat_allowed )
       {
          if( i == 0 )
          {
-            for( u32 j=0; j<ARRAY_COUNT(_console_commands); j ++ )
+            for( u32 j=0; j<ARRAY_COUNT(_console_items); j ++ )
             {
-               struct console_command *cmd = &_console_commands[j];
+               struct console_item *cmd = &_console_items[j];
                if( compare_buffers( cmd->alias, 0, command+start, length ) )
                {
                   target_command = cmd;
@@ -104,7 +117,45 @@ void _console_execute( const c8 *command, b8 silent, b8 cheat_allowed )
    }
 
    if( target_command )
-      target_command->fn( &args );
+   {
+      if( target_command->type == k_console_item_ccmd )
+         target_command->fn( &args );
+      else
+      {
+         const c8 *set_to = console_get_argument( &args, 0 );
+         if( set_to )
+         {
+            struct stream string;
+            stream_open_buffer_read( &string, set_to, buffer_last_index( set_to, 0, 0 ), 0 );
+
+            if( target_command->type == k_console_item_cvar_f32 )
+            {
+               f64 f;
+               if( string_parse_f64( &string, &f ) == k_string_parse_ok )
+                  *target_command->_f32 = f;
+            }
+            if( target_command->type == k_console_item_cvar_i32 )
+            {
+               i64 i;
+               if( string_parse_i64( &string, &i ) == k_string_parse_ok )
+                  *target_command->_i32 = i;
+            }
+
+            $log( $info, {"Value set"} );
+         }
+         else
+         {
+            if( target_command->type == k_console_item_cvar_f32 )
+            {
+               $log( $info, {"The value of "}, {target_command->alias}, {"(f32) is: "}, $float( *target_command->_f32 ) );
+            }
+            else if( target_command->type == k_console_item_cvar_i32 )
+            {
+               $log( $info, {"The value of "}, {target_command->alias}, {"(i32) is: "}, $signed( *target_command->_i32 ) );
+            }
+         }
+      }
+   }
 
    _end_temporary_frame( temp_frame );
 }
index c29fc6283c54883ba05da393c488be476c18f73b..93bebf34ff5f79597392d07e62dff7b1b344e767 100644 (file)
@@ -296,14 +296,26 @@ shader
       }
    }
 }
-
-cvar
+shader
 {
-   name test
-   type u32
-   default 5
-   cheat 1
-   description "This is just a test variable!"
+   name blit_colour
+   subshader
+   {
+      type vertex
+      add shaders/blit_colour.vs
+   }
+
+   subshader
+   {
+      type fragment
+      add shaders/blit_colour.fs
+
+      uniform
+      {
+         type vec4
+         alias uColour
+      }
+   }
 }
 
 hook
@@ -311,7 +323,6 @@ hook
    event START
    function "_shaders_compile"
 }
-}
 
 
 
@@ -337,8 +348,8 @@ hook
 }
 cvar
 {
-   name debug_lines
-   type u32
+   name vg_lines_enable
+   type i32
    default 0
    cheat 1
    description "Show line debuggers"
index a82063de81d5839ff2de77d822b50d1487f263ce..505d3531178e3657f413680cbc49e41e2eefc3ec 100644 (file)
@@ -171,8 +171,7 @@ enum anim_apply
    k_anim_apply_defer_ik,
    k_anim_apply_deffered_only,
    k_anim_apply_absolute
-}
-anim_apply;
+};
 
 void skeleton_apply_pose( struct ms_skeleton *skele, struct ms_keyframe *pose, enum anim_apply passtype, f32 final_mtx[][4][3] );
 void skeleton_decompose_mtx_absolute( struct ms_skeleton *skele, struct ms_keyframe *anim, f32 final_mtx[][4][3] );
index 5e34c1ca02075b69ad2537a7b47a0b0eb8040183..f0ac2bb00a16bf3e76ea87908f2f6ce745a5cf6a 100644 (file)
@@ -547,3 +547,14 @@ i32 vg_model_get_submesh_index( struct vg_model *model, const c8 *mesh_name )
       return -1;
    return  mesh->submesh_start;
 }
+
+void vg_model_bind_texture( struct vg_model *model, GLuint target, u32 tex_id, u32 slot )
+{
+   if( tex_id )
+   {
+      union mdl_texture *mdl_tex = &model->textures[ tex_id -1 ];
+      vg_tex_bind( target, &mdl_tex->tex, slot );
+   }
+   else
+      vg_tex_bind( target, NULL, slot );
+}
index fe90a959c414c8a1e7d605097a2d941e1214404a..b8dfe436eb5cf1e294f2375e5c2ded2ae76a359d 100644 (file)
@@ -267,6 +267,7 @@ struct stream *vg_model_stream_pack_stream( struct vg_model_stream_context *ctx,
 /* Rendering operations
  * ----------------------------------------------------------------------------------------------------------------- */
 void vg_model_bind_mesh( struct vg_model *model );
+void vg_model_bind_texture( struct vg_model *model, GLuint target, u32 tex_id, u32 slot );
 void vg_model_draw_elements( u32 start, u32 count );
 void vg_model_draw_submesh( struct mdl_submesh *sm );
 i32  vg_model_get_mesh_index( struct vg_model *model, const c8 *name );
diff --git a/source/engine/shaders/blit_colour.fs b/source/engine/shaders/blit_colour.fs
new file mode 100644 (file)
index 0000000..070cb51
--- /dev/null
@@ -0,0 +1,6 @@
+out vec4 FragColor;
+
+void main()
+{
+   FragColor = uColour;
+}
diff --git a/source/engine/shaders/blit_colour.vs b/source/engine/shaders/blit_colour.vs
new file mode 100644 (file)
index 0000000..beb5f34
--- /dev/null
@@ -0,0 +1,6 @@
+layout (location=0) in vec2 a_co;
+
+void main()
+{
+   gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);
+}
index 493f911323f105b9bcaa6d70be37540cc090a42b..1c3db8ba29a356ece0b7b5160c44221f23bb29a5 100644 (file)
@@ -258,7 +258,7 @@ L_new_frame:;
    }
    _engine.time = actual_time;
    _engine.time_delta = actual_delta;
-   _engine.time_fixed_extrapolate = fixed_accumulator / (1.0/60.0);
+   _engine.time_fixed_extrapolate = fixed_accumulator;// / (1.0/60.0);
 
    i32 pw = _engine.w, ph = _engine.h;
    //glfwGetFramebufferSize( _engine.window_handle, &_engine.w, &_engine.h );
index ec9d611a32646af50577a82bcdd1dfaabc578059..311d6e409e437e0e078bd2044e774beeab74978c 100644 (file)
@@ -3,6 +3,7 @@
 #include "common_maths.h"
 #include "vg_async.h"
 #include "vg_shader.h"
+#include "console_system.h"
 #include <stddef.h>
 
 struct vg_lines
@@ -58,6 +59,9 @@ void _vg_lines_init(void)
 
 void vg_lines_draw( f32 pv[4][4] )
 {
+   if( _cvar_vg_lines_enable == 0 )
+      return;
+
    _shader_bind( k_shader_debug_lines );
    _shader_debug_lines_uPv( pv );
 
index e925b44c1d6bc6ba19915949bf3ece0b2d127405..964605748128a3b9cef3a1ba04e5449296ccd86b 100644 (file)
@@ -345,6 +345,7 @@ void _codegen_shaders(void)
       const c8 *type;
       const c8 *alias;
       const c8 *shader_name;
+      const c8 *count;
    };
    struct stretchy_allocator uniforms;
    stretchy_init( &uniforms, sizeof(struct uniform_info) );
@@ -364,7 +365,7 @@ void _codegen_shaders(void)
       { "mat3",         "f32 m[3][3]",  "glUniformMatrix3fv",     "1,GL_FALSE,(f32*)m" },
       { "mat4",         "f32 m[4][4]",  "glUniformMatrix4fv",     "1,GL_FALSE,(f32*)m" },
       { "float",        "f32 f",        "glUniform1f",            "f" },
-      { "mat4x3",       "f32 m[4][3]",  "glUniformMatrix4x3fv",   "1,GL_FALSE,(f32*)m" },
+      { "mat4x3",       "f32 (*m)[4][3], u32 c","glUniformMatrix4x3fv", "c,GL_FALSE,(f32*)m" },
       { "sampler2D",    "i32 i",        "glUniform1i",            "i" },
       { "usampler3D",   "i32 i",        "glUniform1i",            "i" },
       { "samplerCube",  "i32 i",        "glUniform1i",            "i" },
@@ -452,6 +453,7 @@ void _codegen_shaders(void)
             uniform->glsl_index = -1;
             uniform->type = keyvalues_read_string( &_assembly, uniform_it, "type", NULL );
             uniform->alias = keyvalues_read_string( &_assembly, uniform_it, "alias", NULL );
+            uniform->count = keyvalues_read_string( &_assembly, uniform_it, "count", NULL );
             uniform->shader_name = shader_name;
             ASSERT_CRITICAL( uniform->type && uniform->alias );
 
@@ -466,7 +468,14 @@ void _codegen_shaders(void)
             ASSERT_CRITICAL( uniform->glsl_index != -1 );
             uniform_count ++;
 
-            $v_string( &C, {"uniform "}, {uniform->type}, {" "}, {uniform->alias}, {";\\n"} );
+            if( uniform->count )
+            {
+               $v_string( &C, {"uniform "}, {uniform->type}, {" "}, {uniform->alias}, {"["},{uniform->count},{"];\\n"} );
+            }
+            else
+            {
+               $v_string( &C, {"uniform "}, {uniform->type}, {" "}, {uniform->alias}, {";\\n"} );
+            }
          }
          $v_string( &C, {"\",\n"}, {"         },\n"} );
          subshader_count ++;
@@ -558,7 +567,7 @@ void _codegen_console(void)
    stream_open_file( &H, "generated/console.h", k_stream_write );
    stream_open_file( &C, "generated/console.c", k_stream_write );
 
-   $v_string( &C, {"static struct console_command _console_commands[] = \n{\n"} );
+   $v_string( &C, {"static struct console_item _console_items[] = \n{\n"} );
                   
    u32 ccmd_it = 0;
    while( keyvalues_foreach( &_assembly, &ccmd_it, 0, "ccmd" ) )
@@ -568,10 +577,34 @@ void _codegen_console(void)
       ASSERT_CRITICAL( name && function );
 
       $v_string( &H, {"i32 "}, {function}, {"( struct console_arguments *args );\n"} );
-      $v_string( &C, {"   {\n      .alias = \""}, {name}, {"\",\n      .fn = "}, {function}, {"\n   },\n"} );
+      $v_string( &C, {"   {\n      .alias = \""}, {name}, {"\",\n      .type = k_console_item_ccmd,\n      .fn = "}, {function}, {"\n   },\n"} );
+   }
+
+   u32 cvar_it = 0;
+   while( keyvalues_foreach( &_assembly, &cvar_it, 0, "cvar" ) )
+   {
+      const c8 *name = keyvalues_read_string( &_assembly, cvar_it, "name", NULL );
+      const c8 *type = keyvalues_read_string( &_assembly, cvar_it, "type", NULL );
+      const c8 *value = keyvalues_read_string( &_assembly, cvar_it, "default", NULL );
+      const c8 *cheat = keyvalues_read_string( &_assembly, cvar_it, "cheat", NULL );
+      ASSERT_CRITICAL( name && type && value );
+      $v_string( &H, {"extern "}, {type}, {" _cvar_"}, {name}, {";\n"} );
+      $v_string( &C, {"   {\n      .alias = \""}, {name}, {"\",\n      .type = k_console_item_cvar_"},{type},
+                     {",\n      ._"},{type},{" = &_cvar_"}, {name}, {"\n   },\n"} );
    }
    $v_string( &C, {"};\n\n"} );
 
+   cvar_it = 0;
+   while( keyvalues_foreach( &_assembly, &cvar_it, 0, "cvar" ) )
+   {
+      const c8 *name = keyvalues_read_string( &_assembly, cvar_it, "name", NULL );
+      const c8 *type = keyvalues_read_string( &_assembly, cvar_it, "type", NULL );
+      const c8 *value = keyvalues_read_string( &_assembly, cvar_it, "default", NULL );
+      const c8 *cheat = keyvalues_read_string( &_assembly, cvar_it, "cheat", NULL );
+      ASSERT_CRITICAL( name && type && value );
+      $v_string( &C, {type}, {" _cvar_"}, {name}, {" = "}, {value}, {";\n"} );
+   }
+
    stream_close( &H );
    stream_close( &C );
 }