From: hgn Date: Sun, 4 Jan 2026 08:30:39 +0000 (+0000) Subject: FIX X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=a02c42d9fc54f647406f0c5c051ea8b4e58d02d7;p=vg.git FIX --- diff --git a/source/engine/vg_asset.c b/source/engine/vg_asset.c index 265a653..ca66782 100644 --- a/source/engine/vg_asset.c +++ b/source/engine/vg_asset.c @@ -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 ); +} diff --git a/source/engine/vg_asset.h b/source/engine/vg_asset.h index 0b6d552..90b8ff7 100644 --- a/source/engine/vg_asset.h +++ b/source/engine/vg_asset.h @@ -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 ); diff --git a/source/engine/vg_engine.c b/source/engine/vg_engine.c index c1fbba0..cfaab17 100644 --- a/source/engine/vg_engine.c +++ b/source/engine/vg_engine.c @@ -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 ) { diff --git a/source/graphics/ui.c b/source/graphics/ui.c index a161fab..b1356ad 100644 --- a/source/graphics/ui.c +++ b/source/graphics/ui.c @@ -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 ) )