yes
authorhgn <hgodden00@gmail.com>
Wed, 4 Jun 2025 20:54:35 +0000 (21:54 +0100)
committerhgn <hgodden00@gmail.com>
Wed, 4 Jun 2025 20:54:35 +0000 (21:54 +0100)
vg_console.c
vg_db.c
vg_db.h
vg_log.h

index 6fa079521bdad56b9715da1bd3183ce9b7a1f739..2e803b16490af7848fc3cc9229779815303a7e3e 100644 (file)
@@ -114,7 +114,7 @@ static void _vg_console_free(void)
  * returns number of tokens
  * dst must be as long as src
  */
-static int vg_console_tokenize( const char *src, char *dst, const char *args[8] )
+static int vg_console_tokenize( const char *src, char *dst, const char *args[32] )
 {
        int arg_count = 0,
        in_token = 0;
@@ -130,7 +130,7 @@ static int vg_console_tokenize( const char *src, char *dst, const char *args[8]
 
                                in_token = 0;
                                
-                               if( arg_count == 8 )
+                               if( arg_count == 32 )
                                        break;
                        }
                        else
@@ -185,7 +185,7 @@ static vg_cmd *vg_console_match_cmd( const char *kw )
 void vg_execute_console_input( const char *cmd, bool silent, bool cheat_override )
 {
        char temp[512];
-       char const *args[8];
+       char const *args[32];
        int arg_count = vg_console_tokenize( cmd, temp, args );
        
        if( arg_count == 0 )
@@ -388,7 +388,7 @@ static void console_update_suggestions( ui_context *ctx )
       return;
 
    char temp[128];
-   const char *args[8];
+   const char *args[32];
 
    int token_count = vg_console_tokenize( vg_console.input, temp, args );
    if( !token_count ) return;
diff --git a/vg_db.c b/vg_db.c
index 1f9d8ab430c2fa0a7196ee73ec8813a392d36b90..3f3acca8128a807fe2620652aa2646291768cf28 100644 (file)
--- a/vg_db.c
+++ b/vg_db.c
@@ -557,6 +557,74 @@ void vg_db_tree_init( vg_db *db, u64 tree_address )
    }
 }
 
+void vg_db_tree_iter_init( vg_db *db, vg_tree_iter *iter, u64 tree_addr )
+{
+   iter->depth = 0;
+   iter->key = 0;
+   iter->value = 0;
+   iter->has_next = 0;
+
+   struct vg_db_address_tree tree;
+   vg_db_read( db, tree_addr, &tree, sizeof(tree) );
+
+       /* go to far left */
+   u64 t_offset = tree.root_node_offset;
+   while( t_offset )
+   {
+      iter->route[ iter->depth ] = t_offset;
+      vg_db_address_node *t_node = &iter->route_nodes[ iter->depth ];
+      vg_db_read( db, t_offset, t_node, sizeof(vg_db_address_node) );
+      t_offset = t_node->left_offset;
+      iter->depth ++;
+      iter->has_next = 1;
+   }
+}
+
+bool vg_db_tree_iter( vg_db *db, vg_tree_iter *iter )
+{
+   if( iter->has_next )
+   {
+      vg_db_address_node *t_node = &iter->route_nodes[ iter->depth-1 ];
+      iter->key = t_node->key;
+      iter->value = t_node->value;
+   
+      /* right once, then left all way */
+      if( t_node->right_offset )
+      {
+         u64 t_offset = t_node->right_offset;
+         while( t_offset )
+         {
+            iter->route[ iter->depth ] = t_offset;
+            vg_db_address_node *t_node = &iter->route_nodes[ iter->depth ];
+            vg_db_read( db, t_offset, t_node, sizeof(vg_db_address_node) );
+            t_offset = t_node->left_offset;
+            iter->depth ++;
+         }
+      }
+      else
+      {
+         u64 t_offset = iter->route[ iter->depth-1 ];
+         while(1)
+         {
+            iter->depth --;
+            if( iter->depth == 0 )
+            {
+               iter->has_next = 0;
+               break;
+            }
+
+            if( iter->route_nodes[ iter->depth-1 ].left_offset == t_offset )
+               break;
+            else 
+               t_offset = iter->route[ iter->depth-1 ];
+         }
+      }
+
+      return 1;
+   }
+   else return 0;
+}
+
 /* Randomized skiplist 
  * ------------------------------------------------------------------------------------------------------------------ */
 
@@ -725,9 +793,9 @@ bool vg_db_skipper_iter( vg_db *db, vg_skipper_context *ctx, u16 *out_index )
 /* Dumb table
  * ------------------------------------------------------------------------------------------------------------------ */
                             
-void vg_db_dumb_table_init( vg_db *db, u64 table_address, u32 structure_size, u32 max_entries )
+void vg_db_table_init( vg_db *db, u64 table_address, u32 structure_size, u32 max_entries )
 {
-   vg_db_dumb_table table;
+   vg_db_table table;
    vg_db_read( db, table_address, &table, sizeof(table) );
    if( table.array_address == 0 )
    {
@@ -738,23 +806,23 @@ void vg_db_dumb_table_init( vg_db *db, u64 table_address, u32 structure_size, u3
    }
 }
 
-u16 vg_db_dumb_table_count( vg_db *db, u64 table_address )
+u16 vg_db_table_count( vg_db *db, u64 table_address )
 {
    u16 count;
-   vg_db_read( db, table_address + offsetof(vg_db_dumb_table,current_entries), &count, sizeof(count) );
+   vg_db_read( db, table_address + offsetof(vg_db_table,current_entries), &count, sizeof(count) );
    return count;
 }
 
-u64 vg_db_dumb_table_get( vg_db *db, u64 table_address, u16 index )
+u64 vg_db_table_get( vg_db *db, u64 table_address, u16 index )
 {
-   vg_db_dumb_table table;
+   vg_db_table table;
    vg_db_read( db, table_address, &table, sizeof(table) );
    return table.array_address + (u64)index * (u64)table.structure_size;
 }
 
-u64 vg_db_dumb_table_append( vg_db *db, u64 table_address )
+u64 vg_db_table_append( vg_db *db, u64 table_address )
 {
-   vg_db_dumb_table table;
+   vg_db_table table;
    vg_db_read( db, table_address, &table, sizeof(table) );
    if( table.current_entries < table.max_entries )
    {
diff --git a/vg_db.h b/vg_db.h
index e72666fdaddc1121aa9b06fafc693c22f394671b..b7fe29cd09ebf9812fc34a69b6218f76cf9c8053 100644 (file)
--- a/vg_db.h
+++ b/vg_db.h
@@ -16,16 +16,39 @@ typedef struct vg_db_page vg_db_page;
 typedef struct vg_db_address_cluster vg_db_address_cluster;
 typedef struct vg_db_address_node vg_db_address_node;
 typedef struct vg_db_address_tree vg_db_address_tree;
-typedef struct vg_db_dumb_table vg_db_dumb_table;
+typedef struct vg_db_table vg_db_table;
 typedef struct vg_db_skip vg_db_skip;
 typedef struct vg_db_skipper vg_db_skipper;
+typedef struct vg_tree_iter vg_tree_iter;
 
 struct vg_db_address_tree
 {
    u64 root_node_offset, last_node_offset;
 };
 
-struct vg_db_dumb_table
+struct vg_db_address_cluster
+{
+   u16 count;
+   struct vg_db_address_node
+   {
+      u64 left_offset, right_offset;
+      u64 key, value;
+      u32 level;
+   }
+   entries[];
+};
+
+struct vg_tree_iter
+{
+   u64 route[32];
+   vg_db_address_node route_nodes[32];
+   u32 depth;
+   bool has_next;
+
+   u64 key, value;
+};
+
+struct vg_db_table
 {
    u16 max_entries, current_entries;
    u32 structure_size;
@@ -40,18 +63,6 @@ struct vg_db_header
    vg_db_address_tree address_tree;
 };
 
-struct vg_db_address_cluster
-{
-   u16 count;
-   struct vg_db_address_node
-   {
-      u64 left_offset, right_offset;
-      u64 key, value;
-      u32 level;
-   }
-   entries[];
-};
-
 struct vg_db_skip
 {
    u16 links[7];
@@ -112,12 +123,14 @@ u64 vg_db_virtual_allocate( vg_db *db, u64 bytes );
 void vg_db_tree_init( vg_db *db, u64 tree_address );
 void vg_db_tree_map( vg_db *db, u64 tree_address, u64 key, u64 value );
 u64 vg_db_translate( vg_db *db, u64 tree_address, u64 key );
+void vg_db_tree_iter_init( vg_db *db, vg_tree_iter *iter, u64 tree_addr );
+bool vg_db_tree_iter( vg_db *db, vg_tree_iter *iter );
 
 /* Dumb table - Just an array in virtual address space */
-void vg_db_dumb_table_init( vg_db *db, u64 table_address, u32 structure_size, u32 max_entries );
-u16 vg_db_dumb_table_count( vg_db *db, u64 table_address );
-u64 vg_db_dumb_table_get( vg_db *db, u64 table_address, u16 index );
-u64 vg_db_dumb_table_append( vg_db *db, u64 table_address );
+void vg_db_table_init( vg_db *db, u64 table_address, u32 structure_size, u32 max_entries );
+u16 vg_db_table_count( vg_db *db, u64 table_address );
+u64 vg_db_table_get( vg_db *db, u64 table_address, u16 index );
+u64 vg_db_table_append( vg_db *db, u64 table_address );
 
 /* Skipper - For indexing and sorting a dumb table */
 typedef struct vg_skipper_context vg_skipper_context;
index f768f8fdea802e0c15cb15328a17cd9664f537b2..a3a80f3e16eda2814da850bf724d4f74c507df82 100644 (file)
--- a/vg_log.h
+++ b/vg_log.h
 #define PRINTF_v3f( V3 ) "%.4f %.4f %.4f\n",      V3[0], V3[1], V3[2]
 #define PRINTF_v4f( V4 ) "%.4f %.4f %.4f %.4f\n", V4[0], V4[1], V4[2], V4[3]
 
+/* fuck off you stupid fucks */
 #ifdef _WIN32
  #define PRINTF_U64 "%llu"
+ #define PRINTF_X64 "%llx"
 #else
  #define PRINTF_U64 "%lu"
+ #define PRINTF_X64 "%lx"
 #endif
 
 #ifdef VG_ENGINE