yed
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_skateshop.c
index e1e154875ae549fa8936ac12a9fab1832daa7fc2..7898f5877d33d7fe185c70a0124d915a0d69963f 100644 (file)
@@ -130,7 +130,6 @@ VG_STATIC void workshop_visibile_load_loop(void)
 {
    vg_info( "Running load loop\n" );
    char path_buf[4096];
-   vg_str folder;
 
    for( u32 i=0; i<SKATESHOP_BOARD_CACHE_MAX; i++ ){
       struct cache_board *cache_ptr = &global_skateshop.cache[i];
@@ -146,36 +145,14 @@ VG_STATIC void workshop_visibile_load_loop(void)
 
          /* continue with the request */
          SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
-
          cache_ptr->reg_ptr = get_addon_from_index( k_workshop_file_type_board,
                                                     cache_ptr->reg_index );
 
-         if( cache_ptr->reg_ptr->workshop_id ){
-            vg_async_item *call = 
-               vg_async_alloc( sizeof(struct async_workshop_filepath_info) );
-
-            struct async_workshop_filepath_info *info = call->payload;
-            info->buf = path_buf;
-            info->id = cache_ptr->reg_ptr->workshop_id;
-            info->len = vg_list_size(path_buf);
-            vg_async_dispatch( call, async_workshop_get_filepath );
-            vg_async_stall(); /* too bad! */
-
-            if( path_buf[0] == '\0' ){
-               vg_error( "Failed SteamAPI_GetItemInstallInfo(" PRINTF_U64 ")\n",
-                           cache_ptr->reg_ptr->workshop_id );
-               goto file_is_broken;
-            }
+         vg_str folder;
+         vg_strnull( &folder, path_buf, 4096 );
+         if( !addon_get_content_folder( cache_ptr->reg_ptr, &folder ) )
+            goto file_is_broken;
 
-            folder.buffer = path_buf;
-            folder.i = strlen(path_buf);
-            folder.len = 4096;
-         }
-         else{
-            vg_strnull( &folder, path_buf, 4096 );
-            vg_strcat( &folder, "boards/" );
-            vg_strcat( &folder, cache_ptr->reg_ptr->foldername );
-         }
 
          /* load content files
           * --------------------------------- */
@@ -336,45 +313,38 @@ VG_STATIC void pointcloud_clear_async(void *_, u32 __)
 VG_STATIC void skateshop_preview_loader_thread( void *_data )
 {
    addon_reg *reg = _data;
+
+   char path_buf[4096];
+   vg_str path;
+   vg_strnull( &path, path_buf, 4096 );
+   addon_get_content_folder( reg, &path );
+   vg_strcat( &path, "/preview.bin" );
+
+   vg_linear_clear(vg_mem.scratch);
+   u32 size;
    
-   if( reg->workshop_id ){
-      vg_error( "Workshop files unsupported\n" );
-      vg_async_call( pointcloud_clear_async, NULL, 0 );
-   }
-   else{
-      char path_buf[4096];
-      vg_str path;
-      vg_strnull( &path, path_buf, 4096 );
-      vg_strcat( &path, "maps/" );
-      vg_strcat( &path, reg->foldername );
-      vg_strcat( &path, "/preview.bin" );
-
-      vg_linear_clear(vg_mem.scratch);
-      u32 size;
-      
-      void *data = vg_file_read( vg_mem.scratch, path_buf, &size );
-      if( data ){
-         if( size < sizeof(pointcloud_buffer) ){
-            vg_async_call( pointcloud_clear_async, NULL, 0 );
-            return;
-         }
-         
-         vg_async_item *call = vg_async_alloc(size);
-         pointcloud_buffer *pcbuf = call->payload;
-         memcpy( pcbuf, data, size );
-
-         u32 point_count = (size-sizeof(pointcloud_buffer)) /
-                              sizeof(struct pointcloud_vert);
-         pcbuf->max = point_count;
-         pcbuf->count = point_count;
-         pcbuf->op = k_pointcloud_op_clear;
-
-         vg_async_dispatch( call, async_pointcloud_sub );
-         vg_async_call( pointcloud_async_end, NULL, 0 );
-      }
-      else{
+   void *data = vg_file_read( vg_mem.scratch, path_buf, &size );
+   if( data ){
+      if( size < sizeof(pointcloud_buffer) ){
          vg_async_call( pointcloud_clear_async, NULL, 0 );
+         return;
       }
+      
+      vg_async_item *call = vg_async_alloc(size);
+      pointcloud_buffer *pcbuf = call->payload;
+      memcpy( pcbuf, data, size );
+
+      u32 point_count = (size-sizeof(pointcloud_buffer)) /
+                           sizeof(struct pointcloud_vert);
+      pcbuf->max = point_count;
+      pcbuf->count = point_count;
+      pcbuf->op = k_pointcloud_op_clear;
+
+      vg_async_dispatch( call, async_pointcloud_sub );
+      vg_async_call( pointcloud_async_end, NULL, 0 );
+   }
+   else{
+      vg_async_call( pointcloud_clear_async, NULL, 0 );
    }
 }
 
@@ -564,7 +534,9 @@ VG_STATIC void global_skateshop_preupdate(void)
          if( loadable && button_down( k_srbind_maccept ) ){
             vg_info( "Select rift (%u)\n", 
                       global_skateshop.selected_world_id );
-            skaterift_change_world( reg->foldername );
+            world_loader.reg = reg;
+            world_loader.override_name[0] = '\0';
+            skaterift_change_world_start();
             return;
          }
          else{
@@ -711,6 +683,8 @@ fade_out:;
    }
 
    if( global_skateshop.render.reg_id != global_skateshop.selected_board_id ){
+      global_skateshop.render.item_title = "";
+      global_skateshop.render.item_desc = "";
       addon_reg *reg = cache_ptr->reg_ptr;
       vg_msg root;
       vg_msg_init( &root, reg->metadata, reg->metadata_len );
@@ -719,6 +693,9 @@ fade_out:;
       if( vg_msg_seekframe( &workshop, "workshop", 0 ) ){
          const char *title = vg_msg_seekkvstr( &workshop, "title", 0 );
          if( title ) global_skateshop.render.item_title = title;
+
+         const char *dsc = vg_msg_seekkvstr( &workshop, "author", 0 );
+         if( dsc ) global_skateshop.render.item_desc = dsc;
       }
 
       global_skateshop.render.reg_id = global_skateshop.selected_board_id;
@@ -743,7 +720,8 @@ fade_out:;
     * ----------------------------------------------------------------- */
    scale *= 0.4f;
    m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
-   mlocal[3][0] = -font3d_string_width( &gui.font, 0, "JA" );
+   mlocal[3][0] = -font3d_string_width( &gui.font, 0, 
+                                        global_skateshop.render.item_desc );
    mlocal[3][0] *= scale*0.5f;
    mlocal[3][1] = 0.0f;
    mlocal[3][2] = 0.0f;
@@ -767,6 +745,8 @@ VG_STATIC void skateshop_render_worldshop(void)
                                   mdl_entity_id_id(shop->boards.id_info));
 
    if( global_skateshop.render.world_reg != global_skateshop.selected_world_id){
+      global_skateshop.render.world_title = "";
+
       addon_reg *reg = get_addon_from_index( k_workshop_file_type_world,
                                        global_skateshop.selected_world_id );
       vg_msg root;
@@ -804,6 +784,12 @@ VG_STATIC void skateshop_render_worldshop(void)
          vg_strcat( &subtext, "Loading..." );
       }
       else{
+         addon_reg *reg = get_addon_from_index( k_workshop_file_type_world,
+                                          global_skateshop.selected_world_id );
+
+         if( reg->workshop_id )
+            vg_strcat( &subtext, "(Workshop) " );
+
          vg_strcat( &subtext, global_skateshop.render.world_loc );
       }
    }