X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=addon.c;h=1b9f62264e2cb6c94752afb415676c675a637d02;hb=670daa775dec0954adb27354c3e37c66fc6567dd;hp=59b3e320978561fcc6552aef45b3541476ddd243;hpb=d0069069f683eab48418faed415de932896d08ee;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/addon.c b/addon.c index 59b3e32..1b9f622 100644 --- a/addon.c +++ b/addon.c @@ -1,4 +1,6 @@ #include "vg/vg_engine.h" +#include "vg/vg_io.h" +#include "vg/vg_loader.h" #include "addon.h" #include "addon_types.h" #include "vg/vg_msg.h" @@ -729,23 +731,27 @@ static void addon_cache_free_item( enum addon_type type, u16 id ){ /* * Goes over cache item load requests and calls the above ^ */ -void addon_cache_load_loop(void) +static void T1_addon_cache_load_loop(void *_) { vg_info( "Running load loop\n" ); char path_buf[4096]; - for( u32 type=0; typepool.count; id++ ){ + for( u32 id=1; id<=cache->pool.count; id++ ) + { addon_cache_entry *entry = vg_pool_item( &cache->pool, id ); SDL_AtomicLock( &addon_system.sl_cache_using_resources ); - if( entry->state == k_addon_cache_state_load_request ){ + if( entry->state == k_addon_cache_state_load_request ) + { vg_info( "process cache load request (%u#%u, reg:%u)\n", type, id, entry->reg_index ); - if( entry->reg_index >= addon_count(type,0) ){ + if( entry->reg_index >= addon_count(type,0) ) + { /* should maybe have a different value for this case */ entry->state = k_addon_cache_state_none; SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); @@ -760,8 +766,10 @@ void addon_cache_load_loop(void) vg_str folder; vg_strnull( &folder, path_buf, 4096 ); - if( addon_get_content_folder( reg, &folder, 1 ) ){ - if( addon_cache_load_request( type, id, reg, folder ) ){ + if( addon_get_content_folder( reg, &folder, 1 ) ) + { + if( addon_cache_load_request( type, id, reg, folder ) ) + { vg_async_call( async_addon_setstate, entry, k_addon_cache_state_loaded ); continue; @@ -779,6 +787,30 @@ void addon_cache_load_loop(void) } } +/* TODO: migrate to addon.c */ +void addon_system_pre_update(void) +{ + if( !vg_loader_availible() ) return; + + SDL_AtomicLock( &addon_system.sl_cache_using_resources ); + for( u32 type=0; typepool.count; id++ ) + { + addon_cache_entry *entry = vg_pool_item( &cache->pool, id ); + if( entry->state == k_addon_cache_state_load_request ) + { + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); + vg_loader_start( T1_addon_cache_load_loop, NULL ); + return; + } + } + } + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); +} + /* * Perform the cache interactions required to create a viewslot which will * eventually be loaded by other parts of the system.