non-meaningful cleanup
[carveJwlIkooP6JGAAIwe30JlM.git] / addon.c
diff --git a/addon.c b/addon.c
index ef92b0083ce4f1ba1c6a49a39d2a0e4c4a191aea..6f60311c52980fefdcb9c76f97bc82f8a76ded4f 100644 (file)
--- a/addon.c
+++ b/addon.c
@@ -7,16 +7,40 @@
 #include "steam.h"
 #include "workshop.h"
 
-static u32 addon_count( enum addon_type type ){
-   return addon_system.registry_type_counts[ type ];
+static u32 addon_count( enum addon_type type, u32 ignoreflags ){
+   if( ignoreflags ){
+      u32 typecount = 0, count = 0;
+      for( u32 i=0; typecount<addon_count( type, 0 ); i++ ){
+         addon_reg *reg = &addon_system.registry[i];
+         if( reg->alias.type == type ){
+            typecount ++;
+
+            if( reg->flags & ignoreflags )
+               continue;
+            
+            count ++;
+         }
+      }
+
+      return count;
+   }
+   else
+      return addon_system.registry_type_counts[ type ];
 }
 
+
 /* these kind of suck, oh well. */
-static addon_reg *get_addon_from_index(enum addon_type type, u32 index){
-   u32 count = 0;
-   for( u32 i=0; count<addon_count(type); i++ ){
+static addon_reg *get_addon_from_index( enum addon_type type, u32 index, 
+                                        u32 ignoreflags ){
+   u32 typecount = 0, count = 0;
+   for( u32 i=0; typecount<addon_count(type,0); i++ ){
       addon_reg *reg = &addon_system.registry[i];
       if( reg->alias.type == type ){
+         typecount ++;
+
+         if( reg->flags & ignoreflags )
+            continue;
+
          if( index == count )
             return reg;
 
@@ -116,7 +140,7 @@ static void invalidate_addon_alias( addon_alias *alias ){
 /*
  * parse uid to alias. returns 1 if successful
  */
-static int addon_uid_to_alias( char uid[ADDON_UID_MAX], addon_alias *alias ){
+static int addon_uid_to_alias( const char *uid, addon_alias *alias ){
 /*           1
  * 01234567890123
  * sr&&&-@@@@@-#*
@@ -230,6 +254,7 @@ static addon_reg *addon_alloc_reg( PublishedFileId_t workshop_id,
    }
 
    addon_reg *reg = &addon_system.registry[ addon_system.registry_count ];
+   reg->flags = 0;
    reg->metadata_len = 0;
    reg->cache_id = 0;
    reg->state = k_addon_state_indexed;
@@ -343,7 +368,7 @@ static addon_reg *addon_mount_local_addon( const char *folder,
       if( (reg->alias.type == type) && (reg->foldername_hash == folder_hash) ){
          if( !strcmp( reg->alias.foldername, folder_name ) ){
             reg->state = k_addon_state_indexed;
-            return NULL;
+            return reg;
          }
       }
    }
@@ -404,7 +429,12 @@ static addon_reg *addon_mount_local_addon( const char *folder,
  * Check all subscribed items
  */
 static void addon_mount_workshop_items(void){
+   if( skaterift.demo_mode ){
+      vg_info( "Won't load workshop items in demo mode\n" );
+      return;
+   }
    if( !steam_ready ) return;
+
    /*
     * Steam workshop scan
     */
@@ -497,16 +527,30 @@ static void addon_mount_content_folder( enum addon_type type,
 /*
  * write the full path of the addon's folder into the vg_str
  */
-static int addon_get_content_folder( addon_reg *reg, vg_str *folder ){
+static int addon_get_content_folder( addon_reg *reg, vg_str *folder, int async){
    if( reg->alias.workshop_id ){
-      vg_async_item *call = 
-         vg_async_alloc( sizeof(struct async_workshop_filepath_info) );
-      struct async_workshop_filepath_info *info = call->payload;
+      struct async_workshop_filepath_info *info = NULL;
+      vg_async_item *call = NULL;
+
+      if( async ){
+         call = vg_async_alloc( sizeof(struct async_workshop_filepath_info) );
+         info = call->payload;
+      }
+      else 
+         info = alloca( sizeof(struct async_workshop_filepath_info) );
+
       info->buf = folder->buffer;
       info->id = reg->alias.workshop_id;
       info->len = folder->len;
-      vg_async_dispatch( call, async_workshop_get_filepath );
-      vg_async_stall(); /* too bad! */
+
+      if( async ){
+         vg_async_dispatch( call, async_workshop_get_filepath );
+         vg_async_stall(); /* too bad! */
+      }
+      else {
+         async_workshop_get_filepath( info, 0 );
+      }
+
       if( info->buf[0] == '\0' ){
          vg_error( "Failed SteamAPI_GetItemInstallInfo(" PRINTF_U64 ")\n",
                      reg->alias.workshop_id );
@@ -535,8 +579,8 @@ static int addon_get_content_folder( addon_reg *reg, vg_str *folder ){
 static u16 addon_cache_fetch( enum addon_type type, u32 reg_index ){
    addon_reg *reg = NULL;
 
-   if( reg_index < addon_count( type ) ){
-      reg = get_addon_from_index( type, reg_index );
+   if( reg_index < addon_count( type, 0 ) ){
+      reg = get_addon_from_index( type, reg_index, 0 );
       if( reg->cache_id ) 
          return reg->cache_id;
    }
@@ -554,8 +598,8 @@ static u16 addon_cache_alloc( enum addon_type type, u32 reg_index ){
    struct addon_cache_entry *new_entry = vg_pool_item( &cache->pool, new_id );
 
    addon_reg *reg = NULL;
-   if( reg_index < addon_count( type ) )
-      reg = get_addon_from_index( type, reg_index );
+   if( reg_index < addon_count( type, 0 ) )
+      reg = get_addon_from_index( type, reg_index, 0 );
 
    if( new_entry ){
       if( new_entry->reg_ptr )
@@ -683,7 +727,7 @@ static void addon_cache_load_loop(void){
             vg_info( "process cache load request (%u#%u, reg:%u)\n",
                         type, id, entry->reg_index );
 
-            if( entry->reg_index >= addon_count(type) ){
+            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 );
@@ -693,12 +737,12 @@ static void addon_cache_load_loop(void){
             SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
 
             /* continue with the request */
-            addon_reg *reg = get_addon_from_index( type, entry->reg_index );
+            addon_reg *reg = get_addon_from_index( type, entry->reg_index, 0 );
             entry->reg_ptr = reg;
 
             vg_str folder;
             vg_strnull( &folder, path_buf, 4096 );
-            if( addon_get_content_folder( 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 );