change shader properties to be vg_msg based
[carveJwlIkooP6JGAAIwe30JlM.git] / addon.c
diff --git a/addon.c b/addon.c
index b67db74f925e9b883116c70de183eec55c703701..34e16f8e42b995a3028bec2f655dd551d2475cd8 100644 (file)
--- a/addon.c
+++ b/addon.c
@@ -1,9 +1,12 @@
 #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"
 #include "steam.h"
 #include "workshop.h"
+#include <string.h>
 
 struct addon_system addon_system;
 
@@ -343,11 +346,13 @@ static addon_reg *addon_mount_workshop_folder( PublishedFileId_t workshop_id,
    vg_msg msg;
    vg_msg_init( &msg, reg->metadata, reg->metadata_len );
 
-   if( vg_msg_seekframe( &msg, "workshop" )){
-      vg_msg_getkvintg( &msg, "type", k_vg_msg_u32, &type );
+   if( vg_msg_seekframe( &msg, "workshop" ))
+   {
+      vg_msg_getkvintg( &msg, "type", k_vg_msg_u32, &type, NULL );
    }
 
-   if( type == k_addon_type_none ){
+   if( type == k_addon_type_none )
+   {
       vg_error( "Cannot determine addon type\n" );
       return NULL;
    }
@@ -728,23 +733,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; 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 );
@@ -759,8 +768,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;
@@ -778,6 +789,29 @@ void addon_cache_load_loop(void)
    }
 }
 
+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.