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)
{
{
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 );
+}
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) )
{
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 )
{