(50c0271)
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_skateshop.c
index 7dd11c0bcd46ea4e9446061b2343805e4991f81a..1065d4b58ab6a1095cd7d3d7f26e2cf1a5261780 100644 (file)
@@ -1,20 +1,22 @@
-#ifndef ENT_SKATESHOP_C
-#define ENT_SKATESHOP_C
-
-#define VG_GAME
-#include "vg/vg.h"
 #include "vg/vg_steam_ugc.h"
 #include "vg/vg_msg.h"
+#include "vg/vg_tex.h"
+#include "vg/vg_image.h"
+#include "vg/vg_loader.h"
 #include "ent_skateshop.h"
 #include "world.h"
 #include "player.h"
 #include "gui.h"
 #include "menu.h"
-#include "pointcloud.h"
-#include "highscores.h"
 #include "steam.h"
 #include "addon.h"
 #include "save.h"
+#include "network.h"
+
+struct global_skateshop global_skateshop = 
+{
+   .render={.reg_id=0xffffffff,.world_reg=0xffffffff}
+};
 
 /*
  * Checks string equality but does a hash check first
@@ -27,7 +29,7 @@ static inline int const_str_eq( u32 hash, const char *str, const char *cmp )
    return 0;
 }
 
-VG_STATIC void skateshop_update_viewpage(void){
+static void skateshop_update_viewpage(void){
    u32 page = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
 
    for( u32 i=0; i<SKATESHOP_VIEW_SLOT_MAX; i++ ){
@@ -44,139 +46,175 @@ VG_STATIC void skateshop_update_viewpage(void){
    }
 }
 
-/*
- * op/subroutine: k_workshop_op_item_load
- * -----------------------------------------------------------------------------
- */
+struct async_preview_load_thread_data{
+   void *data;
+   addon_reg *reg;
+};
 
-VG_STATIC void world_scan_thread( void *_args ){
-   addon_mount_content_folder( k_addon_type_world, "maps", ".mdl" );
-   addon_mount_workshop_items();
-   vg_async_call( async_addon_reg_update, NULL, 0 );
-}
+static void skateshop_async_preview_imageload( void *data, u32 len ){
+   struct async_preview_load_thread_data *inf = data;
 
-/*
- * Asynchronous scan of local disk for worlds
- */
-VG_STATIC void skateshop_op_world_scan(void){
-   vg_loader_start( world_scan_thread, NULL );
-}
+   if( inf->data ){
+      glBindTexture( GL_TEXTURE_2D, global_skateshop.tex_preview );
+      glTexSubImage2D( GL_TEXTURE_2D, 0,0,0,
+                        WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT, 
+                        GL_RGB, GL_UNSIGNED_BYTE, inf->data );
+      glGenerateMipmap( GL_TEXTURE_2D );
+      stbi_image_free( inf->data );
 
-VG_STATIC void board_processview_thread( void *_args ){
-   addon_cache_load_loop();
-}
+      skaterift.rt_textures[k_skaterift_rt_workshop_preview] =
+         global_skateshop.tex_preview;
+   }
+   else {
+      skaterift.rt_textures[k_skaterift_rt_workshop_preview] = vg.tex_missing;
+   }
 
-VG_STATIC void board_scan_thread( void *_args ){
-   addon_mount_content_folder( k_addon_type_board, "boards", ".mdl" );
-   addon_mount_workshop_items();
-   vg_async_call( async_addon_reg_update, NULL, 0 );
-   vg_async_stall();
-   board_processview_thread(NULL);
+   SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+   global_skateshop.reg_loaded_preview = inf->reg;
+   SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
 }
 
-VG_STATIC void skateshop_op_board_scan(void){
-   vg_loader_start( board_scan_thread, NULL );
+static void skateshop_update_preview_image_thread(void *_args)
+{
+   char path_buf[4096];
+   vg_str folder;
+   vg_strnull( &folder, path_buf, sizeof(path_buf) );
+
+   SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+   addon_reg *reg_preview = global_skateshop.reg_preview;
+   SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
+
+   if( !addon_get_content_folder( reg_preview, &folder, 1 ) )
+   {
+      SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+      global_skateshop.reg_loaded_preview = reg_preview;
+      SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
+      return;
+   }
+
+   vg_strcat( &folder, "/preview.jpg" );
+   vg_async_item *call = 
+      vg_async_alloc( sizeof(struct async_preview_load_thread_data) );
+   struct async_preview_load_thread_data *inf = call->payload;
+
+   inf->reg = reg_preview;
+
+   if( vg_strgood( &folder ) )
+   {
+      stbi_set_flip_vertically_on_load(1);
+      int x, y, nc;
+      inf->data = stbi_load( folder.buffer, &x, &y, &nc, 3 );
+
+      if( inf->data )
+      {
+         if( (x != WORKSHOP_PREVIEW_WIDTH) || (y != WORKSHOP_PREVIEW_HEIGHT) )
+         {
+            vg_error( "Resolution does not match framebuffer, so we can't"
+                      " show it\n" );
+            stbi_image_free( inf->data );
+            inf->data = NULL;
+         }
+      }
+
+      vg_async_dispatch( call, skateshop_async_preview_imageload );
+   }
+   else
+   {
+      vg_error( "Path too long to workshop preview image.\n" );
+
+      SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+      global_skateshop.reg_loaded_preview = reg_preview;
+      SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
+   }
 }
 
-VG_STATIC void skateshop_op_processview(void){
-   vg_loader_start( board_processview_thread, NULL );
+void skateshop_world_preview_preupdate(void)
+{
+   /* try to load preview image if we availible to do. */
+   if( vg_loader_availible() )
+   {
+      SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+      if( global_skateshop.reg_preview != global_skateshop.reg_loaded_preview )
+      {
+         SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
+         vg_loader_start( skateshop_update_preview_image_thread, NULL );
+      }
+      else SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
+   }
 }
 
+/*
+ * op/subroutine: k_workshop_op_item_load
+ * -----------------------------------------------------------------------------
+ */
+
 /*
  * Regular stuff
  * -----------------------------------------------------------------------------
  */
 
+static void skateshop_init_async(void *_data,u32 size){
+       glGenTextures( 1, &global_skateshop.tex_preview );
+       glBindTexture( GL_TEXTURE_2D, global_skateshop.tex_preview );
+   glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 
+                  WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT,
+                  0, GL_RGB, GL_UNSIGNED_BYTE, NULL );
+
+   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
+                    GL_LINEAR_MIPMAP_LINEAR );
+   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
+   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
+
+   skaterift.rt_textures[ k_skaterift_rt_workshop_preview ] = vg.tex_missing;
+   skaterift.rt_textures[ k_skaterift_rt_server_status ] = vg.tex_missing;
+   render_server_status_gui();
+}
+
 /*
  * VG event init
  */
-VG_STATIC void skateshop_init(void){
+void skateshop_init(void)
+{
+   vg_async_call( skateshop_init_async, NULL, 0 );
 }
 
 static u16 skateshop_selected_cache_id(void){
-   if( addon_count(k_addon_type_board) ){
-      addon_reg *reg = get_addon_from_index(k_addon_type_board,
-                                            global_skateshop.selected_board_id);
+   if( addon_count(k_addon_type_board, ADDON_REG_HIDDEN) ){
+      addon_reg *reg = get_addon_from_index( 
+            k_addon_type_board, global_skateshop.selected_board_id,
+            ADDON_REG_HIDDEN );
       return reg->cache_id;
    }
    else return 0;
 }
 
-VG_STATIC void pointcloud_async_end(void *_, u32 __)
-{
-   pointcloud_animate( k_pointcloud_anim_opening );
-}
-
-VG_STATIC void pointcloud_clear_async(void *_, u32 __)
-{
-   pointcloud.count = 0;
-   pointcloud_animate( k_pointcloud_anim_opening );
-}
+static void skateshop_server_helper_update(void){
+   vg_str text;
+   vg_strnull( &text, global_skateshop.helper_toggle->text, 
+               sizeof(global_skateshop.helper_toggle->text) );
 
-VG_STATIC void skateshop_world_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;
-   
-   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 );
+   if( skaterift.demo_mode ){
+      vg_strcat( &text, "Not availible in demo" );
    }
-   else{
-      vg_async_call( pointcloud_clear_async, NULL, 0 );
+   else {
+      if( network_client.user_intent == k_server_intent_online )
+         vg_strcat( &text, "Disconnect" );
+      else
+         vg_strcat( &text, "Go Online" );
    }
 }
 
-VG_STATIC void skateshop_world_preview_loader_thread_and_end( void *_data ){
-   skateshop_world_preview_loader_thread( _data );
-}
-
-VG_STATIC void skateshop_load_world_preview( addon_reg *reg ){
-   vg_loader_start( skateshop_world_preview_loader_thread_and_end, reg );
-}
-
 /*
  * VG event preupdate 
  */
 void temp_update_playermodel(void);
-VG_STATIC void global_skateshop_preupdate(void){
-   float rate = vg_minf( 1.0f, vg.time_frame_delta * 2.0f );
-   int active = 0;
-   if( skaterift.activity == k_skaterift_skateshop )
-      active = 1;
-
-   vg_slewf( &global_skateshop.factive, active, 
-             vg.time_frame_delta * (1.0f/0.5f) );
-
+void ent_skateshop_preupdate( ent_skateshop *shop, int active )
+{
    if( !active ) return;
 
    /* input filter */
    world_instance *world = world_current_instance();
-   ent_skateshop *shop = global_skateshop.ptr_ent;
 
    /* camera positioning */
    ent_camera *ref = mdl_arritm( &world->ent_camera, 
@@ -184,8 +222,7 @@ VG_STATIC void global_skateshop_preupdate(void){
       
    v3f dir = {0.0f,-1.0f,0.0f};
    mdl_transform_vector( &ref->transform, dir, dir );
-   m3x3_mulv( localplayer.invbasis, dir, dir );
-   player_vector_angles( global_skateshop.cam.angles, dir, 1.0f, 0.0f );
+   v3_angles( dir, world_static.focus_cam.angles );
 
    v3f lookat;
    if( shop->type == k_skateshop_type_boardshop ||
@@ -194,28 +231,29 @@ VG_STATIC void global_skateshop_preupdate(void){
                                     mdl_entity_id_id(shop->boards.id_display) );
       v3_sub( display->transform.co, localplayer.rb.co, lookat );
    }
-   else if( shop->type == k_skateshop_type_charshop )
+   else if( shop->type == k_skateshop_type_charshop ){
       v3_sub( ref->transform.co, localplayer.rb.co, lookat );
+   }
+   else if( shop->type == k_skateshop_type_server ){
+      ent_prop *prop = mdl_arritm( &world->ent_prop,
+            mdl_entity_id_id(shop->server.id_lever) );
+      v3_sub( prop->transform.co, localplayer.rb.co, lookat );
+   }
    else
       vg_fatal_error( "Unknown store (%u)\n", shop->type );
 
    q_axis_angle( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f}, 
                  atan2f(lookat[0],lookat[2]) );
 
-   v3_copy( ref->transform.co, global_skateshop.cam.pos );
-   global_skateshop.cam.fov = ref->fov;
+   v3_copy( ref->transform.co, world_static.focus_cam.pos );
+   world_static.focus_cam.fov = ref->fov;
 
    /* input */
    if( shop->type == k_skateshop_type_boardshop ){
       if( !vg_loader_availible() ) return;
 
-      gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" );
-      gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
-
       u16 cache_id = skateshop_selected_cache_id();
-      if( cache_id ){
-         gui_helper_action( button_display_string( k_srbind_maccept ), "pick" );
-      }
+      global_skateshop.helper_pick->greyed = !cache_id;
 
       /*
        * Controls
@@ -229,10 +267,9 @@ VG_STATIC void global_skateshop_preupdate(void){
          }
       }
 
+      u32 valid_count = addon_count( k_addon_type_board, 0 );
       if( button_down( k_srbind_mright ) ){
-         if( global_skateshop.selected_board_id+1 < 
-               addon_count(k_addon_type_board) )
-         {
+         if( global_skateshop.selected_board_id+1 < valid_count ){
             global_skateshop.selected_board_id ++;
          }
       }
@@ -241,7 +278,6 @@ VG_STATIC void global_skateshop_preupdate(void){
 
       if( opage != npage ){
          skateshop_update_viewpage();
-         skateshop_op_processview();
       }
       else if( cache_id && button_down( k_srbind_maccept )){
          vg_info( "chose board from skateshop (%u)\n", 
@@ -250,36 +286,34 @@ VG_STATIC void global_skateshop_preupdate(void){
          addon_cache_unwatch( k_addon_type_board, localplayer.board_view_slot );
          addon_cache_watch( k_addon_type_board, cache_id );
          localplayer.board_view_slot = cache_id;
+         network_send_item( k_netmsg_playeritem_board );
 
-         global_skateshop_exit();
-         skaterift_write_savedata();
+         world_entity_exit_modal();
+         world_entity_clear_focus();
+         gui_helper_clear();
+         skaterift_autosave(1);
          return;
       }
    }
    else if( shop->type == k_skateshop_type_charshop ){
       if( !vg_loader_availible() ) return;
 
-      gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" );
-      gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
-      gui_helper_action( button_display_string( k_srbind_maccept ), "pick" );
-
       int changed = 0;
+      u32 valid_count = addon_count( k_addon_type_player, ADDON_REG_HIDDEN );
 
       if( button_down( k_srbind_mleft ) ){
          if( global_skateshop.selected_player_id > 0 ){
             global_skateshop.selected_player_id --;
          }
          else{
-            global_skateshop.selected_player_id = 
-               addon_count(k_addon_type_player) -1;
+            global_skateshop.selected_player_id = valid_count-1;
          }
 
          changed = 1;
       }
 
       if( button_down( k_srbind_mright ) ){
-         if( global_skateshop.selected_player_id+1 < 
-               addon_count(k_addon_type_player) ){
+         if( global_skateshop.selected_player_id+1 < valid_count ){
             global_skateshop.selected_player_id ++;
          }
          else{
@@ -290,102 +324,126 @@ VG_STATIC void global_skateshop_preupdate(void){
       }
 
       if( changed ){
-         player__use_model( &localplayer, global_skateshop.selected_player_id );
-         skateshop_op_processview();
+         addon_reg *addon = get_addon_from_index( 
+               k_addon_type_player, global_skateshop.selected_player_id,
+               ADDON_REG_HIDDEN );
+
+         u32 real_id = get_index_from_addon( 
+               k_addon_type_player, addon );
+
+         player__use_model( real_id );
       }
 
       if( button_down( k_srbind_maccept ) ){
-         global_skateshop_exit();
+         network_send_item( k_netmsg_playeritem_player );
+         world_entity_exit_modal();
+         world_entity_clear_focus();
+         gui_helper_clear();
       }
    }
    else if( shop->type == k_skateshop_type_worldshop ){
       int browseable = 0,
           loadable = 0;
 
-      if( addon_count(k_addon_type_world) && vg_loader_availible() ){
-         gui_helper_action( axis_display_string(k_sraxis_mbrowse_h), "browse" );
+      u32 valid_count = addon_count( k_addon_type_world, ADDON_REG_HIDDEN );
+
+      if( valid_count && vg_loader_availible() )
          browseable = 1;
-      }
 
-      if( vg_loader_availible() && global_skateshop.selected_world_id > 0 ){
-         gui_helper_action( button_display_string(k_srbind_maccept), 
-                            "open rift" );
+      if( valid_count && vg_loader_availible() )
          loadable = 1;
-      }
+
+      global_skateshop.helper_browse->greyed = !browseable;
+      global_skateshop.helper_pick->greyed = !loadable;
       
-      int change = 0;
+      addon_reg *selected_world = NULL;
 
+      int change = 0;
       if( browseable ){
          if( button_down( k_srbind_mleft ) ){
-            if( global_skateshop.selected_world_id > 0 )
-            {
+            if( global_skateshop.selected_world_id > 0 ){
                global_skateshop.selected_world_id --;
                change = 1;
             }
          }
 
          if( button_down( k_srbind_mright ) ){
-            if( global_skateshop.selected_world_id+1 < 
-                     addon_count(k_addon_type_world) )
-            {
+            if( global_skateshop.selected_world_id+1 < valid_count ){
                global_skateshop.selected_world_id ++;
                change = 1;
             }
          }
-      }
-      
-      if( change && pointcloud_idle() ){
-         pointcloud_animate( k_pointcloud_anim_hiding );
+
+         selected_world = get_addon_from_index( k_addon_type_world, 
+                     global_skateshop.selected_world_id, ADDON_REG_HIDDEN );
+
+         if( change || (global_skateshop.reg_preview == NULL) ){
+            SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+            global_skateshop.reg_preview = selected_world;
+            SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
+         }
       }
 
-      if( vg_loader_availible() ){
-         addon_reg *reg = get_addon_from_index( k_addon_type_world,
-            global_skateshop.selected_world_id );
-
-         /* automatically load in clouds */
-         if( loadable && button_down( k_srbind_maccept ) ){
-            vg_info( "Select rift (%u)\n", 
-                      global_skateshop.selected_world_id );
-            skaterift_change_world_start( reg );
-            return;
+      if( loadable ){
+         if( button_down( k_srbind_maccept ) ){
+            skaterift_change_world_start( selected_world );
          }
-         else{
-            if( pointcloud.anim == k_pointcloud_anim_idle_closed ){
-               if( global_skateshop.pointcloud_world_id !=
-                     global_skateshop.selected_world_id )
-               {
-                  global_skateshop.pointcloud_world_id = 
-                     global_skateshop.selected_world_id;
-                  skateshop_load_world_preview( reg );
-               }
-               else{
-                  pointcloud_animate( k_pointcloud_anim_opening );
-               }
-            }
-            else if( pointcloud.anim == k_pointcloud_anim_idle_open ){
-               if( global_skateshop.pointcloud_world_id !=
-                     global_skateshop.selected_world_id )
-               {
-                  pointcloud_animate( k_pointcloud_anim_hiding );
-               }
-            }
+      }
+   }
+   else if( shop->type == k_skateshop_type_server ){
+      f64 delta = vg.time_real - network_client.last_intent_change;
+
+      if( (delta > 5.0) && (!skaterift.demo_mode) ){
+         global_skateshop.helper_pick->greyed = 0;
+         if( button_down( k_srbind_maccept ) ){
+            network_client.user_intent = !network_client.user_intent;
+            network_client.last_intent_change = vg.time_real;
+            skateshop_server_helper_update();
+            render_server_status_gui();
          }
       }
+      else {
+         global_skateshop.helper_pick->greyed = 1;
+      }
    }
    else{
       vg_fatal_error( "Unknown store (%u)\n", shop->type );
    }
 
-   if( button_down( k_srbind_mback ) ){
-      global_skateshop_exit();
+   if( button_down( k_srbind_mback ) )
+   {
+      if( shop->type == k_skateshop_type_charshop )
+         network_send_item( k_netmsg_playeritem_player );
+
+      world_entity_exit_modal();
+      world_entity_clear_focus();
+      gui_helper_clear();
       return;
    }
 }
 
-VG_STATIC void skateshop_render_boardshop(void){
-   world_instance *world = world_current_instance();
-   ent_skateshop *shop = global_skateshop.ptr_ent;
+void skateshop_world_preupdate( world_instance *world )
+{
+   for( u32 i=0; i<mdl_arrcount(&world->ent_skateshop); i++ ){
+      ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, i );
 
+      if( shop->type == k_skateshop_type_server ){
+         f32 a = network_client.user_intent;
+
+         vg_slewf( &network_client.fintent, a, vg.time_frame_delta );
+         a = (vg_smoothstepf( network_client.fintent ) - 0.5f) * (VG_PIf/2.0f);
+
+         ent_prop *lever = mdl_arritm( &world->ent_prop,
+               mdl_entity_id_id(shop->server.id_lever) );
+
+         /* we need parent transforms now? */
+         q_axis_angle( lever->transform.q, (v3f){0,0,1}, a );
+      }
+   }
+}
+
+static void skateshop_render_boardshop( ent_skateshop *shop ){
+   world_instance *world = world_current_instance();
    u32 slot_count = vg_list_size(global_skateshop.shop_view_slots);
 
    ent_marker *mark_rack = mdl_arritm( &world->ent_marker, 
@@ -445,18 +503,13 @@ fade_out:;
    mdl_transform_m4x3( &mark_info->transform, mtext );
    mdl_transform_m4x3( &mark_rack->transform, mrack );
 
-#if 0
-   const char *text_title = "Fish - Title";
-   const char *text_author = "by Shaniqua";
-#endif
-
    m4x3f mlocal, mmdl;
    m4x3_identity( mlocal );
 
    float scale = 0.2f,
          thickness = 0.03f;
 
-   font3d_bind( &gui.font, &skaterift.cam );
+   font3d_bind( &gui.font, k_font_shader_default, 0, world, &skaterift.cam );
    shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
 
    /* Selection counter
@@ -469,19 +522,18 @@ fade_out:;
    mlocal[3][2] = -0.7f;
    m4x3_mul( mrack, mlocal, mmdl );
 
-   if( addon_count(k_addon_type_board) ){
+   u32 valid_count = addon_count(k_addon_type_board,0);
+   if( valid_count ){
       char buf[16];
-      int i=0;
-      i+=highscore_intl( buf+i, global_skateshop.selected_board_id+1, 3 );
-      buf[i++] = '/';
-      i+=highscore_intl( buf+i, addon_count(k_addon_type_board), 3 );
-      buf[i++] = '\0';
-
-      font3d_simple_draw( &gui.font, 0, buf, &skaterift.cam, mmdl );
+      vg_str str;
+      vg_strnull( &str, buf, sizeof(buf) );
+      vg_strcati32( &str, global_skateshop.selected_board_id+1 );
+      vg_strcatch( &str, '/' );
+      vg_strcati32( &str, valid_count );
+      font3d_simple_draw( 0, buf, &skaterift.cam, mmdl );
    }
    else{
-      font3d_simple_draw( &gui.font, 0, 
-                          "Nothing installed", &skaterift.cam, mmdl );
+      font3d_simple_draw( 0, "Nothing installed", &skaterift.cam, mmdl );
    }
 
    u16 cache_id = skateshop_selected_cache_id();
@@ -500,18 +552,16 @@ fade_out:;
    if( global_skateshop.render.reg_id != global_skateshop.selected_board_id ){
       global_skateshop.render.item_title = "";
       global_skateshop.render.item_desc = "";
-      vg_msg root = {0};
-      root.buf = reg->metadata;
-      root.len = reg->metadata_len;
-      root.max = sizeof(reg->metadata);
-
-      vg_msg workshop = root;
-      if( vg_msg_seekframe( &workshop, "workshop", 0 ) ){
-         const char *title = vg_msg_seekkvstr( &workshop, "title", 0 );
+      vg_msg msg;
+      vg_msg_init( &msg, reg->metadata, reg->metadata_len );
+
+      if( vg_msg_seekframe( &msg, "workshop" ) ){
+         const char *title = vg_msg_getkvstr( &msg, "title" );
          if( title ) global_skateshop.render.item_title = title;
 
-         const char *dsc = vg_msg_seekkvstr( &workshop, "author", 0 );
+         const char *dsc = vg_msg_getkvstr( &msg, "author" );
          if( dsc ) global_skateshop.render.item_desc = dsc;
+         vg_msg_skip_frame( &msg );
       }
 
       global_skateshop.render.reg_id = global_skateshop.selected_board_id;
@@ -521,88 +571,96 @@ fade_out:;
     * ----------------------------------------------------------------- */
    m3x3_zero( mlocal );
    m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
-   mlocal[3][0] = -font3d_string_width( &gui.font, 0, 
-                                        global_skateshop.render.item_title );
+   mlocal[3][0] = -font3d_string_width( 0, global_skateshop.render.item_title );
    mlocal[3][0] *= scale*0.5f;
    mlocal[3][1] = 0.1f;
    mlocal[3][2] = 0.0f;
    m4x3_mul( mtext, mlocal, mmdl );
-   font3d_simple_draw( &gui.font, 0, global_skateshop.render.item_title, 
+   font3d_simple_draw( 0, global_skateshop.render.item_title, 
                        &skaterift.cam, mmdl );
 
    /* Author name
     * ----------------------------------------------------------------- */
    scale *= 0.4f;
    m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
-   mlocal[3][0] = -font3d_string_width( &gui.font, 0, 
-                                        global_skateshop.render.item_desc );
+   mlocal[3][0] = -font3d_string_width( 0, global_skateshop.render.item_desc );
    mlocal[3][0] *= scale*0.5f;
    mlocal[3][1] = 0.0f;
    mlocal[3][2] = 0.0f;
    m4x3_mul( mtext, mlocal, mmdl );
-   font3d_simple_draw( &gui.font, 0, global_skateshop.render.item_desc, 
+   font3d_simple_draw( 0, global_skateshop.render.item_desc, 
                        &skaterift.cam, mmdl );
 
    SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
 }
 
-VG_STATIC void skateshop_render_charshop(void)
-{
+static void skateshop_render_charshop( ent_skateshop *shop ){
 }
 
-VG_STATIC void skateshop_render_worldshop(void)
-{
+static void skateshop_render_worldshop( ent_skateshop *shop ){
    world_instance *world = world_current_instance();
 
-   ent_skateshop *shop = global_skateshop.ptr_ent;
    ent_marker *mark_display = mdl_arritm( &world->ent_marker,
                                   mdl_entity_id_id(shop->worlds.id_display)),
               *mark_info = mdl_arritm( &world->ent_marker, 
                                   mdl_entity_id_id(shop->boards.id_info));
 
    if( global_skateshop.render.world_reg != global_skateshop.selected_world_id){
-      global_skateshop.render.world_title = "";
+      global_skateshop.render.world_title = "missing: workshop.title";
 
       addon_reg *reg = get_addon_from_index( k_addon_type_world,
-                                       global_skateshop.selected_world_id );
-      vg_msg root = {0};
-      root.buf = reg->metadata;
-      root.len = reg->metadata_len;
-      root.max = sizeof(reg->metadata);
-      vg_msg workshop = root;
-      if( vg_msg_seekframe( &workshop, "workshop", 0 ) ){
-         global_skateshop.render.world_title = vg_msg_seekkvstr( &workshop, 
-                                                                 "title", 0 );
+            global_skateshop.selected_world_id, ADDON_REG_HIDDEN );
+
+      if( !reg ) 
+         goto none;
+
+      if( reg->alias.workshop_id )
+      {
+         vg_msg msg;
+         vg_msg_init( &msg, reg->metadata, reg->metadata_len );
+
+         global_skateshop.render.world_loc = vg_msg_getkvstr(&msg,"location");
+         global_skateshop.render.world_reg = global_skateshop.selected_world_id;
+
+         if( vg_msg_seekframe( &msg, "workshop" ) )
+         {
+            global_skateshop.render.world_title = vg_msg_getkvstr(&msg,"title");
+            vg_msg_skip_frame( &msg );
+         }
+         else {
+            vg_warn( "No workshop body\n" );
+         }
+      }
+      else {
+         global_skateshop.render.world_title = reg->alias.foldername;
       }
-      global_skateshop.render.world_loc = vg_msg_seekkvstr(&root,"location",0);
-      global_skateshop.render.world_reg = global_skateshop.selected_world_id;
    }
 
+none:;
+
    /* Text */
    char buftext[128], bufsubtext[128];
    vg_str info, subtext;
    vg_strnull( &info, buftext, 128 );
    vg_strnull( &subtext, bufsubtext, 128 );
    
-   if( addon_count(k_addon_type_world) ){
-      addon_reg *reg = get_addon_from_index( k_addon_type_world,
-                           global_skateshop.selected_world_id );
-
-      info.i+=highscore_intl( info.buffer+info.i, 
-                              global_skateshop.selected_world_id+1, 3 );
-      info.buffer[info.i++] = '/';
-      info.i+=highscore_intl( info.buffer+info.i, 
-                              addon_count(k_addon_type_world), 3 );
-      info.buffer[info.i++] = ' ';
-      info.buffer[info.i] = '\0';
-
+   u32 valid_count = addon_count(k_addon_type_world,ADDON_REG_HIDDEN);
+   if( valid_count )
+   {
+      vg_strcati32( &info, global_skateshop.selected_world_id+1 );
+      vg_strcatch( &info, '/' );
+      vg_strcati32( &info, valid_count );
+      vg_strcatch( &info, ' ' );
       vg_strcat( &info, global_skateshop.render.world_title );
-      if( !vg_loader_availible() ){
+
+      if( !vg_loader_availible() )
+      {
          vg_strcat( &subtext, "Loading..." );
       }
-      else{
+      else
+      {
          addon_reg *reg = get_addon_from_index( k_addon_type_world,
-                                          global_skateshop.selected_world_id );
+                     global_skateshop.selected_world_id, ADDON_REG_HIDDEN );
 
          if( reg->alias.workshop_id )
             vg_strcat( &subtext, "(Workshop) " );
@@ -610,118 +668,182 @@ VG_STATIC void skateshop_render_worldshop(void)
          vg_strcat( &subtext, global_skateshop.render.world_loc );
       }
    }
-   else{
-      vg_strcat( &info, "No worlds installed" );
+   else
+   {
+      vg_strcat( &info, "No workshop worlds installed" );
    }
 
-
    m4x3f mtext,mlocal,mtextmdl;
    mdl_transform_m4x3( &mark_info->transform, mtext );
 
-   font3d_bind( &gui.font, &skaterift.cam );
+   font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &skaterift.cam );
    shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
 
    float scale = 0.2f, thickness = 0.015f, scale1 = 0.08f;
    m3x3_zero( mlocal );
    m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
-   mlocal[3][0] = -font3d_string_width( &gui.font, 0, buftext );
+   mlocal[3][0] = -font3d_string_width( 0, buftext );
    mlocal[3][0] *= scale*0.5f;
    mlocal[3][1] = 0.1f;
    mlocal[3][2] = 0.0f;
    m4x3_mul( mtext, mlocal, mtextmdl );
-   font3d_simple_draw( &gui.font, 0, buftext, &skaterift.cam, mtextmdl );
+   font3d_simple_draw( 0, buftext, &skaterift.cam, mtextmdl );
 
    m3x3_setdiagonalv3( mlocal, (v3f){ scale1, scale1, thickness } );
-   mlocal[3][0] = -font3d_string_width( &gui.font, 0, bufsubtext );
+   mlocal[3][0] = -font3d_string_width( 0, bufsubtext );
    mlocal[3][0] *= scale1*0.5f;
    mlocal[3][1] = -scale1*0.3f;
    m4x3_mul( mtext, mlocal, mtextmdl );
-   font3d_simple_draw( &gui.font, 0, bufsubtext, &skaterift.cam, mtextmdl );
-
-   /* pointcloud */
-   m4x3f mmdl;
-   mdl_transform_m4x3( &mark_display->transform, mmdl );
-   m4x3_rotate_y( mmdl, vg.time * 0.2 );
-
-   glEnable(GL_BLEND);
-   glBlendFunc(GL_ONE, GL_ONE);
-   glDisable(GL_DEPTH_TEST);
-   pointcloud_render( world, &skaterift.cam, mmdl );
-   glDisable(GL_BLEND);
-   glEnable(GL_DEPTH_TEST);
+   font3d_simple_draw( 0, bufsubtext, &skaterift.cam, mtextmdl );
 }
 
 /*
  * World: render event
  */
-VG_STATIC void skateshop_render(void){
-   if( skaterift.activity != k_skaterift_skateshop ) return;
-      
-   ent_skateshop *shop = global_skateshop.ptr_ent;
-
-   if( shop->type == k_skateshop_type_boardshop ){
-      skateshop_render_boardshop();
+void skateshop_render( ent_skateshop *shop )
+{
+   if( shop->type == k_skateshop_type_boardshop )
+      skateshop_render_boardshop( shop );
+   else if( shop->type == k_skateshop_type_charshop )
+      skateshop_render_charshop( shop );
+   else if( shop->type == k_skateshop_type_worldshop )
+      skateshop_render_worldshop( shop );
+   else if( shop->type == k_skateshop_type_server ){
    }
-   else if( shop->type == k_skateshop_type_charshop ){
-      skateshop_render_charshop();
+   else
+      vg_fatal_error( "Unknown store (%u)\n", shop->type );
+}
+
+void skateshop_render_nonfocused( world_instance *world, vg_camera *cam )
+{
+   for( u32 j=0; j<mdl_arrcount( &world->ent_skateshop ); j ++ )
+   {
+      ent_skateshop *shop = mdl_arritm(&world->ent_skateshop, j );
+
+      if( shop->type != k_skateshop_type_boardshop ) continue;
+
+      f32 dist2 = v3_dist2( cam->pos, shop->transform.co ),
+          maxdist = 50.0f;
+
+      if( dist2 > maxdist*maxdist ) continue;
+      ent_marker *mark_rack = mdl_arritm( &world->ent_marker, 
+                                     mdl_entity_id_id(shop->boards.id_rack));
+
+      if( !mark_rack ) 
+         continue;
+
+      u32 slot_count = vg_list_size(global_skateshop.shop_view_slots);
+      for( u32 i=0; i<slot_count; i++ )
+      {
+         struct player_board *board = &localplayer.fallback_board;
+
+         mdl_transform xform;
+         transform_identity( &xform );
+
+         xform.co[0] = -((float)i - ((float)slot_count)*0.5f)*0.45f;
+         mdl_transform_mul( &mark_rack->transform, &xform, &xform );
+
+         struct player_board_pose pose = {0};
+         m4x3f mmdl;
+         mdl_transform_m4x3( &xform, mmdl );
+         render_board( cam, world, board, mmdl, &pose, k_board_shader_entity );
+      }
    }
-   else if( shop->type == k_skateshop_type_worldshop ){
-      skateshop_render_worldshop();
+}
+
+static void ent_skateshop_helpers_pickable( const char *acceptance )
+{
+   vg_str text;
+
+   if( gui_new_helper( input_button_list[k_srbind_mback], &text ))
+      vg_strcat( &text, "exit" );
+
+   if( (global_skateshop.helper_pick = gui_new_helper(
+               input_button_list[k_srbind_maccept], &text))){
+      vg_strcat( &text, acceptance );
    }
-   else{
-      vg_fatal_error( "Unknown store (%u)\n", shop->type );
+
+   if( (global_skateshop.helper_browse = gui_new_helper( 
+               input_axis_list[k_sraxis_mbrowse_h], &text ))){
+      vg_strcat( &text, "browse" );
    }
 }
 
+static void board_scan_thread( void *_args )
+{
+   addon_mount_content_folder( k_addon_type_board, "boards", ".mdl" );
+   addon_mount_workshop_items();
+   vg_async_call( async_addon_reg_update, NULL, 0 );
+   vg_async_stall();
+
+   /* 04.03.24
+    * REVIEW: This is removed as it *should* be done on the preupdate of the 
+    *         addon system.
+    *
+    *         Verify that it works the same.
+    */
+#if 0
+   board_processview_thread(NULL);
+#endif
+}
+
+static void world_scan_thread( void *_args )
+{
+   addon_mount_content_folder( k_addon_type_world, "maps", ".mdl" );
+   addon_mount_workshop_items();
+   vg_async_call( async_addon_reg_update, NULL, 0 );
+}
+
 /*
  * Entity logic: entrance event
  */
-VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
+entity_call_result ent_skateshop_call( world_instance *world, ent_call *call )
 {
    u32 index = mdl_entity_id_id( call->id );
    ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, index );
    vg_info( "skateshop_call\n" );
 
-   if( skaterift.activity != k_skaterift_default ) return;
-   if( !vg_loader_availible() ) return;
+   if( (skaterift.activity != k_skaterift_default) || 
+       !vg_loader_availible() ) 
+      return k_entity_call_result_invalid;
 
-   if( call->function == k_ent_function_trigger ){
-      if( localplayer.subsystem != k_player_subsystem_walk ) return;
+   if( call->function == k_ent_function_trigger )
+   {
+      if( localplayer.subsystem != k_player_subsystem_walk )
+         return k_entity_call_result_OK;
       
       vg_info( "Entering skateshop\n" );
 
-      localplayer.immobile = 1;
-      menu.disable_open = 1;
-      skaterift.activity = k_skaterift_skateshop;
-
-      v3_zero( localplayer.rb.v );
-      v3_zero( localplayer.rb.w );
-      localplayer._walk.move_speed = 0.0f;
-      global_skateshop.ptr_ent = shop;
+      world_entity_set_focus( call->id );
+      world_entity_focus_modal();
+      gui_helper_clear();
       
-      if( shop->type == k_skateshop_type_boardshop ){
+      if( shop->type == k_skateshop_type_boardshop )
+      {
          skateshop_update_viewpage();
-         skateshop_op_board_scan();
+         vg_loader_start( board_scan_thread, NULL );
+         ent_skateshop_helpers_pickable( "pick" );
+      }
+      else if( shop->type == k_skateshop_type_charshop )
+      {
+         ent_skateshop_helpers_pickable( "pick" );
       }
-      else if( shop->type == k_skateshop_type_charshop ){
-         
+      else if( shop->type == k_skateshop_type_worldshop )
+      {
+         ent_skateshop_helpers_pickable( "open rift" );
+         vg_loader_start( world_scan_thread, NULL );
       }
-      else if( shop->type == k_skateshop_type_worldshop ){
-         pointcloud_animate( k_pointcloud_anim_opening );
-         skateshop_op_world_scan();
+      else if( shop->type == k_skateshop_type_server )
+      {
+         vg_str text;
+         global_skateshop.helper_pick = gui_new_helper(
+                     input_button_list[k_srbind_maccept], &text);
+         if( gui_new_helper( input_button_list[k_srbind_mback], &text ))
+            vg_strcat( &text, "exit" );
+         skateshop_server_helper_update();
       }
+      return k_entity_call_result_OK;
    }
+   else
+      return k_entity_call_result_unhandled;
 }
-
-/*
- * Entity logic: exit event
- */
-VG_STATIC void global_skateshop_exit(void){
-   vg_info( "exit skateshop\n" );
-   localplayer.immobile = 0;
-   skaterift.activity = k_skaterift_default;
-   menu.disable_open = 0;
-   srinput.enabled = 0;
-}
-
-#endif /* ENT_SKATESHOP_C */