FIX fsect
authorhgn <hgodden00@gmail.com>
Sun, 4 Jan 2026 08:30:39 +0000 (08:30 +0000)
committerhgn <hgodden00@gmail.com>
Sun, 4 Jan 2026 08:30:39 +0000 (08:30 +0000)
source/engine/vg_asset.c
source/engine/vg_asset.h
source/engine/vg_engine.c
source/graphics/ui.c

index 265a6536dfac9c7c6ca1b21ffe1bcde6ecee1a38..ca66782e51270599186f51da0cc712d5230d6768 100644 (file)
@@ -6,20 +6,26 @@ u32 vg_asset_index( struct vg_asset_list *list, u16 item )
    return pool_index( &list->pool, item );
 }
 
-void vg_allocate_asset_list( struct vg_asset_list *list, u16 asset_count )
+void vg_allocate_asset_list( struct vg_asset_list *list, u16 asset_count, u32 flags )
 {
+   list->flags = flags;
    list->pool.nodes = _heap_allocate( sizeof(struct pool_node) * (u32)asset_count );
    list->pool.count = asset_count;
    list->hashes = _heap_allocate( sizeof(u32)*(u32)asset_count );
    list->keys   = _heap_allocate( 128*(u32)asset_count );
-   list->mutex  = SDL_CreateMutex();
-   ASSERT_CRITICAL( list->mutex );
+   if( flags & ASSET_LIST_MUTEX )
+   {
+      list->mutex = SDL_CreateMutex();
+      ASSERT_CRITICAL( list->mutex );
+   }
+   else list->mutex = NULL;
 }
 
 u16 vg_asset_get( struct vg_asset_list *list, const c8 *key )
 {
    u32 hash = u32_max( 1, buffer_djb2( key, 0 ) );
-   SDL_LockMutex( list->mutex );
+   if( list->flags & ASSET_LIST_MUTEX )
+      SDL_LockMutex( list->mutex );
    u16 n = list->active_chain.head;
    while(n)
    {
@@ -28,51 +34,82 @@ u16 vg_asset_get( struct vg_asset_list *list, const c8 *key )
       {
          if( compare_buffers( key, 0, list->keys, 0 ) )
          {
-            pool_reference( &list->pool, n, +1 );
+            pool_reference( &list->pool, n, 1 );
             return n;
          }
       }
       n = pool_next( &list->pool, n, 1 );
    }
-   SDL_UnlockMutex( list->mutex );
+   if( list->flags & ASSET_LIST_MUTEX )
+      SDL_UnlockMutex( list->mutex );
    return 0;
 }
 
 u16 vg_asset_create( struct vg_asset_list *list, const c8 *key )
 {
-   SDL_LockMutex( list->mutex );
+   if( list->flags & ASSET_LIST_MUTEX )
+      SDL_LockMutex( list->mutex );
    ASSERT_CRITICAL( list->pool.nodes );
    u16 n = pool_allocate( &list->pool, &list->free_chain, &list->active_chain );
    u32 index = pool_index( &list->pool, n );
    ASSERT_CRITICAL( buffer_copy( key, 0, list->keys[index], sizeof(list->keys[index]) ) );
    list->hashes[index] = u32_max( 1, buffer_djb2( list->keys[index], 0 ) );
-   pool_reference( &list->pool, n, +1 );
-   SDL_UnlockMutex( list->mutex );
+   pool_reference( &list->pool, n, 1 );
+   if( list->flags & ASSET_LIST_MUTEX )
+      SDL_UnlockMutex( list->mutex );
    return n;
 }
 
 u16 vg_asset_create_anonymous( struct vg_asset_list *list )
 {
-   SDL_LockMutex( list->mutex );
+   if( list->flags & ASSET_LIST_MUTEX )
+      SDL_LockMutex( list->mutex );
    ASSERT_CRITICAL( list->pool.nodes );
    u16 n = pool_allocate( &list->pool, &list->free_chain, &list->active_chain );
    u32 index = pool_index( &list->pool, n );
    list->hashes[index] = 0;
    buffer_copy( "[anonymous]", 0, list->keys[index], sizeof(list->keys[index]) );
-   pool_reference( &list->pool, n, +1 );
-   SDL_UnlockMutex( list->mutex );
+   pool_reference( &list->pool, n, 1 );
+   if( list->flags & ASSET_LIST_MUTEX )
+      SDL_UnlockMutex( list->mutex );
    return n;
 }
 
+u16 vg_asset_create_reference( struct vg_asset_list *list, u16 item )
+{
+   if( list->flags & ASSET_LIST_MUTEX )
+      SDL_LockMutex( list->mutex );
+   pool_reference( &list->pool, item, 1 );
+   if( list->flags & ASSET_LIST_MUTEX )
+      SDL_UnlockMutex( list->mutex );
+   return item;
+}
+
 b8 vg_asset_release( struct vg_asset_list *list, u16 item )
 {
-   SDL_LockMutex( list->mutex );
-   if( pool_reference( &list->pool, item, -1 ) == 0 )
+   if( list->flags & ASSET_LIST_MUTEX )
+      SDL_LockMutex( list->mutex );
+   if( pool_reference( &list->pool, item, 0 ) == 0 )
    {
       pool_free( &list->pool, &list->free_chain, &list->active_chain, item );
-      SDL_UnlockMutex( list->mutex );
+      if( list->flags & ASSET_LIST_MUTEX )
+         SDL_UnlockMutex( list->mutex );
       return 1;
    }
-   SDL_UnlockMutex( list->mutex );
+   if( list->flags & ASSET_LIST_MUTEX )
+      SDL_UnlockMutex( list->mutex );
    return 0;
 }
+
+u16 vg_asset_count( struct vg_asset_list *list )
+{
+   return list->active_chain.count;
+}
+
+u16 vg_asset_iterate( struct vg_asset_list *list, u16 previous_item )
+{
+   if( previous_item == 0 )
+      return list->active_chain.head;
+   else 
+      return pool_next( &list->pool, previous_item, 1 );
+}
index 0b6d5522c229512b7779c66d4b471bff36808079..90b8ff711df848a16909c3f926c9d43815f3627a 100644 (file)
@@ -1,9 +1,12 @@
 #pragma once
 #include "foundation.h"
-#include "shader_props.h"
+
+#define ASSET_LIST_MUTEX 0x1
 
 struct vg_asset_list
 {
+   u32 flags;
+
    struct pool_allocator pool;
    struct pool_chain free_chain, active_chain;
    void *mutex;
@@ -12,10 +15,14 @@ struct vg_asset_list
    c8  (*keys)   [ 128 ];
 };
 
-void vg_allocate_asset_list( struct vg_asset_list *list, u16 asset_count );
+void vg_allocate_asset_list( struct vg_asset_list *list, u16 asset_count, u32 flags );
 
 u32 vg_asset_index( struct vg_asset_list *list, u16 item );
 u16 vg_asset_get( struct vg_asset_list *list, const c8 *key );
 u16 vg_asset_create( struct vg_asset_list *list, const c8 *key );
 u16 vg_asset_create_anonymous( struct vg_asset_list *list );
 b8  vg_asset_release( struct vg_asset_list *list, u16 item );
+u16 vg_asset_create_reference( struct vg_asset_list *list, u16 item );
+
+u16 vg_asset_count( struct vg_asset_list *list );
+u16 vg_asset_iterate( struct vg_asset_list *list, u16 previous_item );
index c1fbba0406aad352fb1c950d3322006b7bcf269a..cfaab176e9ff3451137b770bd54a7d0ba3c004cb 100644 (file)
@@ -354,7 +354,8 @@ void _vg_engine_frame( b8 engine_update )
             else             action = k_button_down;
          }
          else action = k_button_up;
-         _input_callback_buttonlike( k_input_device_keyboard, ev->key, action, ev->mod & (SDL_KMOD_LSHIFT|SDL_KMOD_LCTRL|SDL_KMOD_LALT) );
+         _input_callback_buttonlike( k_input_device_keyboard, ev->key, action, 
+                                     ev->mod & (SDL_KMOD_LSHIFT|SDL_KMOD_LCTRL|SDL_KMOD_LALT) );
       }
       else if( (e.type == SDL_EVENT_MOUSE_BUTTON_DOWN) || (e.type == SDL_EVENT_MOUSE_BUTTON_UP) )
       {
@@ -362,12 +363,18 @@ void _vg_engine_frame( b8 engine_update )
          enum input_button_action action;
          if( ev->type == SDL_EVENT_MOUSE_BUTTON_DOWN ) action = k_button_down;
          else action = k_button_up;
-         _input_callback_buttonlike( k_input_device_mouse, ev->button, action, 0 ); // FIXME: MODIFIERS
+         _input_callback_buttonlike( k_input_device_mouse, ev->button, action, 
+                                     SDL_GetModState() & (SDL_KMOD_LSHIFT|SDL_KMOD_LCTRL|SDL_KMOD_LALT) );
       }
       else if( e.type == SDL_EVENT_MOUSE_MOTION )
       {
          SDL_MouseMotionEvent *ev = (SDL_MouseMotionEvent *)&e;
-         _ui_set_mouse( ev->x / _engine_ui.divisor, ev->y / _engine_ui.divisor, 0 ); //FIXME: MODIFIERS
+         u32 sdl_mods = SDL_GetModState(),
+             vg_mods  = 0x0;
+         if( sdl_mods & SDL_KMOD_LSHIFT ) vg_mods |= UI_KEYBOARD_SHIFT;
+         if( sdl_mods & SDL_KMOD_LCTRL ) vg_mods |= UI_KEYBOARD_CONTROL;
+         if( sdl_mods & SDL_KMOD_LALT ) vg_mods |= UI_KEYBOARD_ALT;
+         _ui_set_mouse( ev->x / _engine_ui.divisor, ev->y / _engine_ui.divisor, vg_mods );
       }
       else if( e.type == SDL_EVENT_TEXT_INPUT )
       {
index a161fab1a8ae819f0aa732c304931b2fbd9f4561..b1356adca4eb4ed5507bf7f7faf96e3a48b18b0a 100644 (file)
@@ -276,8 +276,9 @@ static b8 rect_eq( i16 a[4], i16 b[4] )
 
 enum button_action _ui_button( i16 rect[4] )
 {
-   union colour debug_colour = (union colour){{ 200, 200, 200, 50 }};
    enum button_action action = k_button_none;
+   if( _ui.active_control_type == k_ui_control_dropdown )
+      return action;
 
    b8 mouse_in_box = 0;
    if( ui_inside_rect( rect, _ui.mouse_co ) )