(50c0271)
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_skateshop.c
index 40362219b37b9d8ae1c6479c7ebad3b6077cd469..1065d4b58ab6a1095cd7d3d7f26e2cf1a5261780 100644 (file)
@@ -1,15 +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 "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
@@ -22,448 +29,192 @@ static inline int const_str_eq( u32 hash, const char *str, const char *cmp )
    return 0;
 }
 
-/*
- * Get an existing cache instance, allocate a new one to be loaded, or NULL if
- * there is no space
- */
-VG_STATIC struct cache_board *skateshop_cache_fetch( u32 registry_index )
-{
-   struct registry_board *reg = NULL;
-
-   if( registry_index < global_skateshop.registry_count ){
-      reg = &global_skateshop.registry[ registry_index ];
-
-      if( reg->cache_ptr ){
-         return reg->cache_ptr;
-      }
-   }
+static void skateshop_update_viewpage(void){
+   u32 page = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
 
-   /* lru eviction. should be a linked list maybe... */
-   double min_time = 1e300;
-   struct cache_board *min_board = NULL;
-
-   SDL_AtomicLock( &global_skateshop.sl_cache_access );
-   for( u32 i=0; i<SKATESHOP_BOARD_CACHE_MAX; i++ ){
-      struct cache_board *cache_ptr = &global_skateshop.cache[i];
-
-      if( cache_ptr->state == k_cache_board_state_load_request ) continue;
-      if( cache_ptr->ref_count ) continue;
-
-      if( cache_ptr->last_use_time < min_time ){
-         min_time = cache_ptr->last_use_time;
-         min_board = cache_ptr;
-      }
-   }
-
-   if( min_board ){
-      if( min_board->state == k_cache_board_state_loaded ){
-         struct registry_board *other = 
-            &global_skateshop.registry[ min_board->registry_id ];
-
-         vg_info( "Deallocating board: '%s'\n", min_board, other->filename );
-
-         player_board_unload( &min_board->board );
-         other->cache_ptr = NULL;
-      }
-
-      if( reg ){
-         vg_info( "Allocating board (reg:%u) '%s'\n", 
-                  registry_index, reg->filename );
-      }
-      else{
-         vg_info( "Pre-allocating board (reg:%u) 'null'\n", registry_index );
-      }
-
-      min_board->registry_id = registry_index;
-      min_board->last_use_time = vg.time;
-      min_board->ref_count = 0;
-      min_board->state = k_cache_board_state_load_request;
-   }
-   else{
-      vg_error( "No free boards to load registry!\n" );
+   for( u32 i=0; i<SKATESHOP_VIEW_SLOT_MAX; i++ ){
+      u32 j = SKATESHOP_VIEW_SLOT_MAX-1-i;
+      struct shop_view_slot *slot = &global_skateshop.shop_view_slots[j];
+      addon_cache_unwatch( k_addon_type_board, slot->cache_id );
    }
-
-   SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
-   return min_board;
-}
-
-VG_STATIC void skateshop_update_viewpage(void)
-{
-   u32 page = global_skateshop.selected_registry_id/SKATESHOP_VIEW_SLOT_MAX;
    
    for( u32 i=0; i<SKATESHOP_VIEW_SLOT_MAX; i++ ){
       struct shop_view_slot *slot = &global_skateshop.shop_view_slots[i];
       u32 request_id = page*SKATESHOP_VIEW_SLOT_MAX + i;
-      
-      if( slot->cache_ptr ) unwatch_cache_board( slot->cache_ptr );
-
-      slot->cache_ptr = skateshop_cache_fetch( request_id );
-      if( slot->cache_ptr ) watch_cache_board( slot->cache_ptr );
+      slot->cache_id = addon_cache_create_viewer( k_addon_type_board,
+                                                  request_id );
    }
 }
 
-/* generic reciever */
-VG_STATIC void workshop_async_any_complete( void *data, u32 size )
-{
-   skaterift_end_op();
-}
+struct async_preview_load_thread_data{
+   void *data;
+   addon_reg *reg;
+};
 
-/*
- * op/subroutine: k_workshop_op_item_load
- * -----------------------------------------------------------------------------
- */
+static void skateshop_async_preview_imageload( void *data, u32 len ){
+   struct async_preview_load_thread_data *inf = data;
 
-/*
- * Reciever for board completion; only promotes the status in the main thread
- */
-VG_STATIC void skateshop_async_board_loaded( void *payload, u32 size )
-{
-   SDL_AtomicLock( &global_skateshop.sl_cache_access );
-   struct cache_board *cache_ptr = payload;
-   cache_ptr->last_use_time = vg.time;
-   cache_ptr->state = k_cache_board_state_loaded;
+   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 );
 
-   struct registry_board *reg = 
-      &global_skateshop.registry[ cache_ptr->registry_id ];
-   reg->cache_ptr = cache_ptr;
-   SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
+      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_success( "Async board loaded (%s)\n", reg->filename );
+   SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+   global_skateshop.reg_loaded_preview = inf->reg;
+   SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
 }
 
-/*
- * Thread(or subroutine of thread), for checking view slots that weve installed.
- * Load the model if a view slot wants it
- */
-VG_STATIC void workshop_visibile_load_loop_thread( void *_args )
+static void skateshop_update_preview_image_thread(void *_args)
 {
-   char path[1024];
-   for( u32 i=0; i<SKATESHOP_BOARD_CACHE_MAX; i++ ){
-      struct cache_board *cache_ptr = &global_skateshop.cache[i];
-
-      SDL_AtomicLock( &global_skateshop.sl_cache_access );
-      if( cache_ptr->state == k_cache_board_state_load_request ){
-         if( cache_ptr->registry_id >= global_skateshop.registry_count ){
-            /* should maybe have a different value for this case */
-            cache_ptr->state = k_cache_board_state_none;
-            SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
-            continue;
-         }
-
-         /* continue with the request */
-         SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
-
-         struct registry_board *reg = 
-            &global_skateshop.registry[ cache_ptr->registry_id ];
-
-         if( reg->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;
-            info->id = reg->workshop_id;
-            info->len = vg_list_size(path) - strlen("/board.mdl")-1;
-            vg_async_dispatch( call, async_workshop_get_filepath );
-            vg_async_stall(); /* too bad! */
-
-            if( path[0] == '\0' ){
-               SDL_AtomicLock( &global_skateshop.sl_cache_access );
-               cache_ptr->state = k_cache_board_state_none;
-               SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
-
-               vg_error( "Failed SteamAPI_GetItemInstallInfo(" PRINTF_U64 ")\n",
-                           reg->workshop_id );
-               continue;
-            }
-            else{
-               strcat( path, "/board.mdl" );
-            }
-         }
-         else{
-            snprintf( path, 256, "models/boards/%s", reg->filename );
-         }
-
-         player_board_load( &cache_ptr->board, path );
-         vg_async_call( skateshop_async_board_loaded, cache_ptr, 0 );
-      }
-      else
-         SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
+   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_async_call( workshop_async_any_complete, NULL, 0 );
-}
-
-/*
- * op: k_workshop_op_item_scan
- * -----------------------------------------------------------------------------
- */
 
-/*
- * Reciever for scan completion. copies the registry_count back into t0
- */
-VG_STATIC void workshop_async_reg_update( void *data, u32 size )
-{
-   vg_info( "Registry update notify\n" );
-   global_skateshop.registry_count = global_skateshop.t1_registry_count;
-}
-
-VG_STATIC void workshop_steam_scan(void)
-{
-   /*
-    * Steam workshop scan
-    */
-   vg_info( "Scanning steam workshop for boards\n" );
-   PublishedFileId_t workshop_ids[ SKATESHOP_REGISTRY_MAX ];
-   u32 workshop_count = SKATESHOP_REGISTRY_MAX;
-
-   vg_async_item *call = vg_async_alloc(
-                           sizeof(struct async_workshop_installed_files_info));
-   struct async_workshop_installed_files_info *info = call->payload;
-   info->buffer = workshop_ids;
-   info->len = &workshop_count;
-   vg_async_dispatch( call, async_workshop_get_installed_files );
-   vg_async_stall();
+   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;
 
-   for( u32 j=0; j<workshop_count; j++ ){
-      PublishedFileId_t id = workshop_ids[j];
+   inf->reg = reg_preview;
 
-      for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
-         struct registry_board *reg = &global_skateshop.registry[i];
+   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( reg->workshop_id == id ){
-            reg->state = k_registry_board_state_indexed;
-            goto next_file_workshop;
+      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;
          }
       }
 
-      if( global_skateshop.t1_registry_count == SKATESHOP_REGISTRY_MAX ){
-         vg_error( "You have too many boards installed!\n" );
-         break;
-      }
-
-      vg_info( "new listing from the steam workshop!: "PRINTF_U64"\n", id );
-
-      struct registry_board *reg = &global_skateshop.registry[
-                                       global_skateshop.t1_registry_count ++ ];
-
-      reg->cache_ptr = NULL;
-      snprintf( reg->filename, 64, PRINTF_U64, id );
-      reg->filename_hash = vg_strdjb2( reg->filename );
-      reg->workshop_id = id;
-      reg->state = k_registry_board_state_indexed;
-
-      workshop_file_info_clear( &reg->workshop );
-      strcpy( reg->workshop.title, "Workshop file" );
-
-      /* load the metadata off the disk */
-      vg_async_item *call = 
-         vg_async_alloc( sizeof(struct async_workshop_filepath_info) );
-
-      const char *meta_file = "/board.mdl.inf";
-      char path[ 1024 ];
-      struct async_workshop_filepath_info *info = call->payload;
-      info->buf = path;
-      info->id = reg->workshop_id;
-      info->len = vg_list_size(path) - strlen(meta_file)-1;
-      vg_async_dispatch( call, async_workshop_get_filepath );
-      vg_async_stall(); /* too bad! */
-
-      strcat( path, meta_file );
-      workshop_load_metadata( path, &reg->workshop );
+      vg_async_dispatch( call, skateshop_async_preview_imageload );
+   }
+   else
+   {
+      vg_error( "Path too long to workshop preview image.\n" );
 
-next_file_workshop:;
+      SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+      global_skateshop.reg_loaded_preview = reg_preview;
+      SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
    }
 }
 
-/*
- * Async thread which scans local files for boards, as well as scheduling 
- * synchronous calls to the workshop
- */
-VG_STATIC void workshop_scan_thread( void *_args )
+void skateshop_world_preview_preupdate(void)
 {
-   vg_linear_clear( vg_mem.scratch );
-
-   for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
-      struct registry_board *reg = &global_skateshop.registry[i];
-      reg->state = k_registry_board_state_indexed_absent;
-   }
-
-   /*
-    * Local disk scan
-    */
-   vg_info( "Scanning models/boards/*.mdl\n" );
-   tinydir_dir dir;
-   tinydir_open( &dir, "models/boards" );
-
-   while( dir.has_next ){
-      tinydir_file file;
-      tinydir_readfile( &dir, &file );
-      
-      if( file.is_reg ){
-         u32 hash = vg_strdjb2( file.name );
-
-         for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
-            struct registry_board *reg = &global_skateshop.registry[i];
-
-            if( const_str_eq( hash, file.name, reg->filename ) ){
-               reg->state = k_registry_board_state_indexed;
-               goto next_file;
-            }
-         }
-
-         if( global_skateshop.t1_registry_count == SKATESHOP_REGISTRY_MAX ){
-            vg_error( "You have too many boards installed!\n" );
-            break;
-         }
-
-         vg_info( "new listing!: %s\n", file.name );
-
-         struct registry_board *reg = 
-            &global_skateshop.registry[global_skateshop.t1_registry_count ++];
-
-         reg->cache_ptr = NULL;
-         vg_strncpy( file.name, reg->filename, 64, k_strncpy_always_add_null );
-         vg_strncpy( file.name, reg->workshop.title,
-                     64, k_strncpy_always_add_null );
-         reg->filename_hash = hash;
-         reg->workshop_id = 0;
-         reg->state = k_registry_board_state_indexed;
-         reg->workshop.author = 0;
-         strcpy( reg->workshop.author_name, "custom" );
+   /* 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 );
       }
-
-next_file: tinydir_next( &dir );
+      else SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
    }
-
-   tinydir_close(&dir);
-
-   if( steam_ready ) workshop_steam_scan();
-   
-   vg_async_call( workshop_async_reg_update, NULL, 0 );
-   vg_async_stall();
-   workshop_visibile_load_loop_thread(NULL);
 }
 
 /*
- * Asynchronous scan of local disk for items and add them to the registry
+ * op/subroutine: k_workshop_op_item_load
+ * -----------------------------------------------------------------------------
  */
-VG_STATIC void workshop_op_item_scan(void)
-{
-   skaterift_begin_op( k_workshop_op_item_scan );
-   vg_loader_start( workshop_scan_thread, NULL );
-}
 
 /*
  * Regular stuff
  * -----------------------------------------------------------------------------
  */
 
-/* we can only keep using a viewslot pointer for multiple frames if we watch it
- * using this function */
-VG_STATIC void watch_cache_board( struct cache_board *ptr )
-{
-   if( ptr->ref_count >= 32 ){
-      vg_fatal_error( "dynamic board watch missmatch (limit is 32)\n" );
-   }
-
-   ptr->last_use_time = vg.time;
-   ptr->ref_count ++;
-}
-
-/* after this is called, the calling code only has access to the pointer for the
- * duration of the rest of the frame */
-VG_STATIC void unwatch_cache_board( struct cache_board *ptr )
-{
-   if( ptr->ref_count == 0 ){
-      vg_fatal_error( "dynamic board unwatch missmatch (no watchers)\n" );
-   }
-
-   ptr->ref_count --;
-}
-
-/*
- * Callback handler for persona state changes,
- * it sets the author names on the registries
- */
-VG_STATIC void callback_persona_statechange( CallbackMsg_t *msg )
-{
-   PersonaStateChange_t *info = (PersonaStateChange_t *)msg->m_pubParam;
-   ISteamFriends *hSteamFriends = SteamAPI_SteamFriends();
-
-   if( info->m_nChangeFlags & k_EPersonaChangeName ){
-      for( u32 i=0; i<global_skateshop.registry_count; i++ ){
-         struct registry_board *reg = &global_skateshop.registry[i];
-         if( reg->workshop.author == info->m_ulSteamID ){
-            const char *name = SteamAPI_ISteamFriends_GetFriendPersonaName( 
-                                    hSteamFriends, info->m_ulSteamID );
-            str_utf8_collapse( name, reg->workshop.author_name, 32 );
-         }
-      }
-   }
+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)
 {
-   u32 reg_size   = sizeof(struct registry_board)*SKATESHOP_REGISTRY_MAX,
-       cache_size = sizeof(struct cache_board)*SKATESHOP_BOARD_CACHE_MAX;
-   
-   global_skateshop.registry = vg_linear_alloc( vg_mem.rtmemory, reg_size );
-   global_skateshop.registry_count = 0;
-   global_skateshop.cache = vg_linear_alloc( vg_mem.rtmemory, cache_size );
-
-   memset( global_skateshop.cache, 0, cache_size );
-
-   for( u32 i=0; i<SKATESHOP_BOARD_CACHE_MAX; i++ ){
-      struct cache_board *board = &global_skateshop.cache[i];
-      board->state = k_cache_board_state_none;
-      board->registry_id = 0xffffffff;
-      board->last_use_time = -99999.9;
-      board->ref_count = 0;
-   }
+   vg_async_call( skateshop_init_async, NULL, 0 );
+}
 
-   if( steam_ready ){
-      steam_register_callback( k_iPersonaStateChange, 
-                               callback_persona_statechange );
+static u16 skateshop_selected_cache_id(void){
+   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 struct cache_board *skateshop_selected_cache_if_loaded(void)
-{
-   if( global_skateshop.registry_count > 0 ){
-      u32 reg_id = global_skateshop.selected_registry_id;
-      struct registry_board *reg = &global_skateshop.registry[ reg_id ];
+static void skateshop_server_helper_update(void){
+   vg_str text;
+   vg_strnull( &text, global_skateshop.helper_toggle->text, 
+               sizeof(global_skateshop.helper_toggle->text) );
 
-      SDL_AtomicLock( &global_skateshop.sl_cache_access );
-      if( reg->cache_ptr && 
-         (reg->cache_ptr->state == k_cache_board_state_loaded ) )
-      {
-         SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
-         return reg->cache_ptr;
-      }
-      SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
+   if( skaterift.demo_mode ){
+      vg_strcat( &text, "Not availible in demo" );
+   }
+   else {
+      if( network_client.user_intent == k_server_intent_online )
+         vg_strcat( &text, "Disconnect" );
+      else
+         vg_strcat( &text, "Go Online" );
    }
-
-   return NULL;
 }
 
 /*
  * VG event preupdate 
  */
 void temp_update_playermodel(void);
-VG_STATIC void global_skateshop_preupdate(void)
+void ent_skateshop_preupdate( ent_skateshop *shop, int active )
 {
-   float rate = vg_minf( 1.0f, vg.time_frame_delta * 2.0f );
-   global_skateshop.factive = vg_lerpf( global_skateshop.factive, 
-                                        global_skateshop.active, rate );
+   if( !active ) return;
 
-   if( !global_skateshop.active ) return;
-
-   world_instance *world = get_active_world();
-
-   ent_skateshop *shop = global_skateshop.ptr_ent;
+   /* input filter */
+   world_instance *world = world_current_instance();
 
    /* camera positioning */
    ent_camera *ref = mdl_arritm( &world->ent_camera, 
@@ -471,141 +222,228 @@ 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( localplayer.cam_override_angles, dir, 1.0f, 0.0f );
+   v3_angles( dir, world_static.focus_cam.angles );
 
    v3f lookat;
    if( shop->type == k_skateshop_type_boardshop ||
        shop->type == k_skateshop_type_worldshop ){
       ent_marker *display = mdl_arritm( &world->ent_marker,
                                     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 ){
       v3_sub( ref->transform.co, localplayer.rb.co, lookat );
    }
-   else{
-      vg_fatal_error( "Unknown store (%u)\n", shop->type );
+   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, localplayer.cam_override_pos );
-   localplayer.cam_override_fov = ref->fov;
-   localplayer.cam_override_strength = global_skateshop.factive;
+   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 ){
-      gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" );
-      gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
+      if( !vg_loader_availible() ) return;
 
-      struct cache_board *selected_cache = skateshop_selected_cache_if_loaded();
-
-      if( selected_cache ){
-         gui_helper_action( button_display_string( k_srbind_maccept ), "pick" );
-      }
+      u16 cache_id = skateshop_selected_cache_id();
+      global_skateshop.helper_pick->greyed = !cache_id;
 
       /*
        * Controls
        * ----------------------
        */
+      u32 opage = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
 
       if( button_down( k_srbind_mleft ) ){
-         if( global_skateshop.selected_registry_id > 0 ){
-            global_skateshop.selected_registry_id --;
+         if( global_skateshop.selected_board_id > 0 ){
+            global_skateshop.selected_board_id --;
          }
       }
 
+      u32 valid_count = addon_count( k_addon_type_board, 0 );
       if( button_down( k_srbind_mright ) ){
-         if( global_skateshop.selected_registry_id+1 < 
-                  global_skateshop.registry_count )
-         {
-            global_skateshop.selected_registry_id ++;
+         if( global_skateshop.selected_board_id+1 < valid_count ){
+            global_skateshop.selected_board_id ++;
          }
       }
 
-      if( selected_cache && button_down( k_srbind_maccept ) ){
-         vg_info( "chose board from skateshop (%u)\n", 
-                     global_skateshop.selected_registry_id );
+      u32 npage = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
 
-         if( localplayer.board_view_slot ){
-            unwatch_cache_board( localplayer.board_view_slot );
-         }
+      if( opage != npage ){
+         skateshop_update_viewpage();
+      }
+      else if( cache_id && button_down( k_srbind_maccept )){
+         vg_info( "chose board from skateshop (%u)\n", 
+                     global_skateshop.selected_board_id );
 
-         localplayer.board_view_slot = selected_cache;
-         watch_cache_board( localplayer.board_view_slot );
+         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();
+         world_entity_exit_modal();
+         world_entity_clear_focus();
+         gui_helper_clear();
+         skaterift_autosave(1);
          return;
       }
    }
    else if( shop->type == k_skateshop_type_charshop ){
-      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" );
+      if( !vg_loader_availible() ) return;
+
+      int changed = 0;
+      u32 valid_count = addon_count( k_addon_type_player, ADDON_REG_HIDDEN );
 
       if( button_down( k_srbind_mleft ) ){
-         if( cl_playermdl_id > 0 ){
-            cl_playermdl_id --;
+         if( global_skateshop.selected_player_id > 0 ){
+            global_skateshop.selected_player_id --;
          }
          else{
-            cl_playermdl_id = 2; /* HACK */
+            global_skateshop.selected_player_id = valid_count-1;
          }
-         temp_update_playermodel(); /* HACK */
+
+         changed = 1;
       }
 
       if( button_down( k_srbind_mright ) ){
-         if( cl_playermdl_id+1 < 3 ){
-            cl_playermdl_id ++;
+         if( global_skateshop.selected_player_id+1 < valid_count ){
+            global_skateshop.selected_player_id ++;
          }
          else{
-            cl_playermdl_id = 0;  /* HACK */
+            global_skateshop.selected_player_id = 0;
          }
-         temp_update_playermodel(); /* HACK */
-         /*lol*/
+
+         changed = 1;
+      }
+
+      if( changed ){
+         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 ){
-      gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" );
+      int browseable = 0,
+          loadable = 0;
 
-      v2f input;
-      joystick_state( k_srjoystick_steer, input );
-      pointcloud.control[0] += input[0] * vg.time_delta;
-      pointcloud.control[2] += input[1] * vg.time_delta;
+      u32 valid_count = addon_count( k_addon_type_world, ADDON_REG_HIDDEN );
 
-      pointcloud.control[0] = vg_clampf( pointcloud.control[0], -10.0f, 10.0f );
-      pointcloud.control[2] = vg_clampf( pointcloud.control[2], -10.0f, 10.0f );
+      if( valid_count && vg_loader_availible() )
+         browseable = 1;
 
-      if( button_press( k_srbind_trick1 ) ){
-         pointcloud.control[3] += vg.time_delta*0.2f;
+      if( valid_count && vg_loader_availible() )
+         loadable = 1;
+
+      global_skateshop.helper_browse->greyed = !browseable;
+      global_skateshop.helper_pick->greyed = !loadable;
+      
+      addon_reg *selected_world = NULL;
+
+      int change = 0;
+      if( browseable ){
+         if( button_down( k_srbind_mleft ) ){
+            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 < valid_count ){
+               global_skateshop.selected_world_id ++;
+               change = 1;
+            }
+         }
+
+         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( loadable ){
+         if( button_down( k_srbind_maccept ) ){
+            skaterift_change_world_start( selected_world );
+         }
+      }
+   }
+   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;
       }
-      if( button_press( k_srbind_trick0 ) ){
-         pointcloud.control[3] -= vg.time_delta*0.2f;
-}
-      pointcloud.control[3] = vg_clampf( pointcloud.control[3], 0.001f, 10.0f );
    }
    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)
+void skateshop_world_preupdate( world_instance *world )
 {
-   world_instance *world = get_active_world();
-   ent_skateshop *shop = global_skateshop.ptr_ent;
+   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, 
@@ -613,25 +451,24 @@ VG_STATIC void skateshop_render_boardshop(void)
               *mark_display = mdl_arritm( &world->ent_marker,
                                   mdl_entity_id_id(shop->boards.id_display));
 
-   int visibility[ SKATESHOP_VIEW_SLOT_MAX ];
-   SDL_AtomicLock( &global_skateshop.sl_cache_access );
-   for( u32 i=0; i<SKATESHOP_VIEW_SLOT_MAX; i++ ){
-      struct shop_view_slot *slot = &global_skateshop.shop_view_slots[i];
-
-      visibility[i] = 1;
-
-      if( slot->cache_ptr == NULL ) visibility[i] = 0;
-      else if( slot->cache_ptr->state != k_cache_board_state_loaded )
-         visibility[i] = 0;
-   }
-   SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
+   SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+   struct addon_cache *cache = &addon_system.cache[k_addon_type_board];
    
    /* Render loaded boards in the view slots */
    for( u32 i=0; i<slot_count; i++ ){
       struct shop_view_slot *slot = &global_skateshop.shop_view_slots[i];
       float selected = 0.0f;
 
-      if( !visibility[i] ) goto fade_out;
+      if( !slot->cache_id ) 
+         goto fade_out;
+
+      addon_cache_entry *entry = vg_pool_item( &cache->pool, slot->cache_id );
+
+      if( entry->state != k_addon_cache_state_loaded )
+         goto fade_out;
+
+      struct player_board *board = 
+         addon_cache_item( k_addon_type_board, slot->cache_id );
 
       mdl_transform xform;
       transform_identity( &xform );
@@ -639,8 +476,8 @@ VG_STATIC void skateshop_render_boardshop(void)
       xform.co[0] = -((float)i - ((float)slot_count)*0.5f)*0.45f;
       mdl_transform_mul( &mark_rack->transform, &xform, &xform );
 
-      if( slot->cache_ptr->registry_id == 
-          global_skateshop.selected_registry_id ){
+
+      if( entry->reg_index == global_skateshop.selected_board_id ){
          selected = 1.0f;
       }
 
@@ -649,10 +486,11 @@ VG_STATIC void skateshop_render_boardshop(void)
       q_nlerp( xform.q, mark_display->transform.q, t, xform.q );
       v3_lerp( xform.s, mark_display->transform.s, t, xform.s );
 
+      struct player_board_pose pose = {0};
       m4x3f mmdl;
       mdl_transform_m4x3( &xform, mmdl );
-      render_board( &main_camera, world, &slot->cache_ptr->board, mmdl,
-                    k_board_shader_entity );
+      render_board( &skaterift.cam, world, board, mmdl, 
+                    &pose, k_board_shader_entity );
 
 fade_out:;
       float rate = 5.0f*vg.time_delta;
@@ -665,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( &world_global.font, &main_camera );
+   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
@@ -689,176 +522,328 @@ fade_out:;
    mlocal[3][2] = -0.7f;
    m4x3_mul( mrack, mlocal, mmdl );
 
-   if( global_skateshop.registry_count == 0 ){
-      font3d_simple_draw( &world_global.font, 0, 
-                          "Nothing installed", &main_camera, mmdl );
+   u32 valid_count = addon_count(k_addon_type_board,0);
+   if( valid_count ){
+      char buf[16];
+      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{
-      char buf[16];
-      int i=0;
-      i+=highscore_intl( buf+i, global_skateshop.selected_registry_id+1, 3 );
-      buf[i++] = '/';
-      i+=highscore_intl( buf+i, global_skateshop.registry_count, 3 );
-      buf[i++] = '\0';
+      font3d_simple_draw( 0, "Nothing installed", &skaterift.cam, mmdl );
+   }
+
+   u16 cache_id = skateshop_selected_cache_id();
+   struct addon_cache_entry *entry = vg_pool_item( &cache->pool, cache_id );
+   addon_reg *reg = NULL;
 
-      font3d_simple_draw( &world_global.font, 0, buf, &main_camera, mmdl );
+   if( entry ) reg = entry->reg_ptr;
+
+   if( !reg ){
+      SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
+      global_skateshop.render.item_title = "";
+      global_skateshop.render.item_desc = "";
+      return;
    }
 
-   struct cache_board *cache_ptr = skateshop_selected_cache_if_loaded();
-   if( !cache_ptr ) return;
+   if( global_skateshop.render.reg_id != global_skateshop.selected_board_id ){
+      global_skateshop.render.item_title = "";
+      global_skateshop.render.item_desc = "";
+      vg_msg msg;
+      vg_msg_init( &msg, reg->metadata, reg->metadata_len );
 
-   struct registry_board *reg = 
-      &global_skateshop.registry[cache_ptr->registry_id];
-   struct workshop_file_info *info = &reg->workshop;
+      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_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;
+   }
 
    /* Skin title
     * ----------------------------------------------------------------- */
    m3x3_zero( mlocal );
    m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
-   mlocal[3][0] = -font3d_string_width( &world_global.font, 0, info->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( &world_global.font, 0, info->title, &main_camera, mmdl );
+   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( &world_global.font, 0, 
-                                        info->author_name );
+   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( &world_global.font, 0, 
-                       info->author_name, &main_camera, mmdl );
+   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)
-{
-   world_instance *world = get_active_world();
+static void skateshop_render_worldshop( ent_skateshop *shop ){
+   world_instance *world = world_current_instance();
 
-   m4x3f mmdl;
-   ent_skateshop *shop = global_skateshop.ptr_ent;
    ent_marker *mark_display = mdl_arritm( &world->ent_marker,
-                                  mdl_entity_id_id(shop->worlds.id_display));
-   mdl_transform_m4x3( &mark_display->transform, mmdl );
+                                  mdl_entity_id_id(shop->worlds.id_display)),
+              *mark_info = mdl_arritm( &world->ent_marker, 
+                                  mdl_entity_id_id(shop->boards.id_info));
 
-   /* TODO? ... */
-#if 0
-   v3f vol;
-   v3_sub( world->scene_geo.bbx[1], world->scene_geo.bbx[0], vol );
+   if( global_skateshop.render.world_reg != global_skateshop.selected_world_id){
+      global_skateshop.render.world_title = "missing: workshop.title";
+
+      addon_reg *reg = get_addon_from_index( k_addon_type_world,
+            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 );
 
-   v2f rect = { 1.0f, 1.0f },
-       map  = { vol[0], vol[2] },
-       result;
+         global_skateshop.render.world_loc = vg_msg_getkvstr(&msg,"location");
+         global_skateshop.render.world_reg = global_skateshop.selected_world_id;
 
-   f32 rp = rect[0] * map[1],
-       rc = rect[1] * map[0];
+         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;
+      }
+   }
+
+none:;
+
+   /* Text */
+   char buftext[128], bufsubtext[128];
+   vg_str info, subtext;
+   vg_strnull( &info, buftext, 128 );
+   vg_strnull( &subtext, bufsubtext, 128 );
    
-   u32 axis, other;
-   if( rc > rp ) axis = 0;
-   else          axis = 1;
-   other = axis ^ 0x1;
+   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() )
+      {
+         vg_strcat( &subtext, "Loading..." );
+      }
+      else
+      {
+         addon_reg *reg = get_addon_from_index( k_addon_type_world,
+                     global_skateshop.selected_world_id, ADDON_REG_HIDDEN );
 
-   result[axis] = rect[axis];
-   result[other] = (rect[axis] * map[other]) / map[axis];
+         if( reg->alias.workshop_id )
+            vg_strcat( &subtext, "(Workshop) " );
 
-   m4x3f mlocal, mx;
-   m4x3_identity( mlocal );
+         vg_strcat( &subtext, global_skateshop.render.world_loc );
+      }
+   }
+   else
+   {
+      vg_strcat( &info, "No workshop worlds installed" );
+   }
 
-   mlocal[0][0] = result[0];
-   mlocal[2][2] = result[1];
-   mlocal[1][1] = (vol[1]/vol[0]) * mlocal[0][0];
-   mlocal[3][0] = (rect[0]-result[0])*0.5f - rect[0]*0.5f;  /* sea level? */
-   mlocal[3][2] = (rect[1]-result[1])*0.5f - rect[1]*0.5f;
-   m4x3_mul( mmdl, mlocal, mx );
-#endif
+   m4x3f mtext,mlocal,mtextmdl;
+   mdl_transform_m4x3( &mark_info->transform, mtext );
 
-   m4x3_rotate_y( mmdl, vg.time * 0.2 );
+   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} );
 
-#if 1
-   glEnable(GL_BLEND);
-   glBlendFunc(GL_ONE, GL_ONE);
-   glDisable(GL_DEPTH_TEST);
-#endif
-   pointcloud_render( world, &main_camera, mmdl );
-   glDisable(GL_BLEND);
-   glEnable(GL_DEPTH_TEST);
+   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( 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( 0, buftext, &skaterift.cam, mtextmdl );
+
+   m3x3_setdiagonalv3( mlocal, (v3f){ scale1, scale1, thickness } );
+   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( 0, bufsubtext, &skaterift.cam, mtextmdl );
 }
 
 /*
  * World: render event
  */
-VG_STATIC void skateshop_render(void)
+void skateshop_render( ent_skateshop *shop )
 {
-   if( !global_skateshop.active ) return;
-      
-   ent_skateshop *shop = global_skateshop.ptr_ent;
+   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
+      vg_fatal_error( "Unknown store (%u)\n", shop->type );
+}
 
-   if( shop->type == k_skateshop_type_boardshop ){
-      skateshop_render_boardshop();
-   }
-   else if( shop->type == k_skateshop_type_charshop ){
-      skateshop_render_charshop();
+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( menu.active ) return;
-   if( skaterift.async_op != k_async_op_none ) 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;
-      global_skateshop.active = 1;
-
-      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();
-         workshop_op_item_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_worldshop )
+      {
+         ent_skateshop_helpers_pickable( "open rift" );
+         vg_loader_start( world_scan_thread, NULL );
+      }
+      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;
-   global_skateshop.active = 0;
-   menu.disable_open = 0;
-   srinput.ignore_input_frames = 2;
-}
-
-#endif /* ENT_SKATESHOP_C */