#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"
/*
* 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; type<k_addon_type_max; type++ ){
+ for( u32 type=0; type<k_addon_type_max; type++ )
+ {
struct addon_cache *cache = &addon_system.cache[type];
- for( u32 id=1; id<=cache->pool.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 );
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;
}
}
+/* 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; type<k_addon_type_max; type++ )
+ {
+ struct addon_cache *cache = &addon_system.cache[type];
+
+ for( u32 id=1; id<=cache->pool.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.