mission is possible 2
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_skateshop.c
index aeeaf702f76a11f6be6a175f3a07b853c44bab71..a667599bc31afaa5a07b95005d615db1f93f0a02 100644 (file)
@@ -8,6 +8,9 @@
 #include "world.h"
 #include "player.h"
 #include "gui.h"
+#include "menu.h"
+#include "pointcloud.h"
+#include "highscores.h"
 
 /*
  * Checks string equality but does a hash check first
@@ -100,12 +103,6 @@ VG_STATIC void skateshop_update_viewpage(void)
    }
 }
 
-/* generic reciever */
-VG_STATIC void workshop_async_any_complete( void *data, u32 size )
-{
-   workshop_end_op();
-}
-
 /*
  * op/subroutine: k_workshop_op_item_load
  * -----------------------------------------------------------------------------
@@ -205,6 +202,74 @@ VG_STATIC void workshop_async_reg_update( void *data, u32 size )
    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();
+
+   for( u32 j=0; j<workshop_count; j++ ){
+      PublishedFileId_t id = workshop_ids[j];
+
+      for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
+         struct registry_board *reg = &global_skateshop.registry[i];
+
+         if( reg->workshop_id == id ){
+            reg->state = k_registry_board_state_indexed;
+            goto next_file_workshop;
+         }
+      }
+
+      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 );
+
+next_file_workshop:;
+   }
+}
+
 /*
  * Async thread which scans local files for boards, as well as scheduling 
  * synchronous calls to the workshop
@@ -267,83 +332,162 @@ next_file: tinydir_next( &dir );
 
    tinydir_close(&dir);
 
-   /*
-    * 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 );
+   if( steam_ready ) workshop_steam_scan();
+   
+   vg_async_call( workshop_async_reg_update, NULL, 0 );
    vg_async_stall();
+   workshop_visibile_load_loop_thread(NULL);
+}
 
-   for( u32 j=0; j<workshop_count; j++ ){
-      PublishedFileId_t id = workshop_ids[j];
+/*
+ * Asynchronous scan of local disk for items and add them to the registry
+ */
+VG_STATIC void workshop_op_item_scan(void)
+{
+   skaterift_begin_op( k_workshop_op_item_scan );
+   vg_loader_start( workshop_scan_thread, NULL );
+}
 
-      for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
-         struct registry_board *reg = &global_skateshop.registry[i];
+/*
+ * op: k_async_op_world_scan
+ * -----------------------------------------------------------------------------
+ */
 
-         if( reg->workshop_id == id ){
-            reg->state = k_registry_board_state_indexed;
-            goto next_file_workshop;
-         }
-      }
+/*
+ * Reciever for scan completion. copies the registry_count back into t0
+ */
+VG_STATIC void workshop_async_world_reg_update( void *data, u32 size )
+{
+   vg_info( "World registry update notify\n" );
+   global_skateshop.world_registry_count = 
+      global_skateshop.t1_world_registry_count;
+   skaterift_end_op();
+}
 
-      if( global_skateshop.t1_registry_count == SKATESHOP_REGISTRY_MAX ){
-         vg_error( "You have too many boards installed!\n" );
-         break;
+/*
+ * Add a local world folder to the registry, it will verify existing ones are 
+ * still there too.
+ */
+VG_STATIC void world_scan_register_local( const char *folder_name )
+{
+   u32 hash = vg_strdjb2( folder_name );
+   for( u32 i=0; i<global_skateshop.t1_world_registry_count; i++ ){
+      struct registry_world *reg = 
+         &global_skateshop.world_registry[i];
+
+      if( const_str_eq( hash, folder_name, reg->foldername ) ){
+         reg->state = k_registry_board_state_indexed;
+         return;
       }
+   }
 
-      vg_info( "new listing from the steam workshop!: "PRINTF_U64"\n", id );
+   if( global_skateshop.t1_world_registry_count == SKATESHOP_WORLDS_MAX ){
+      vg_error( "You have too many worlds installed!\n" );
+      return;
+   }
 
-      struct registry_board *reg = &global_skateshop.registry[
-                                       global_skateshop.t1_registry_count ++ ];
+   vg_info( "new listing!: %s\n", folder_name );
 
-      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;
+   struct registry_world *reg = &global_skateshop.world_registry[
+      global_skateshop.t1_world_registry_count ++ ];
 
-      workshop_file_info_clear( &reg->workshop );
-      strcpy( reg->workshop.title, "Workshop file" );
+   vg_strncpy( folder_name, reg->foldername, 64, k_strncpy_overflow_fatal );
+   reg->foldername_hash = hash;
+   reg->state = k_registry_board_state_indexed;
+   //reg->meta_present = 0;
+   reg->type = k_world_load_type_local;
+}
 
-      /* load the metadata off the disk */
-      vg_async_item *call = 
-         vg_async_alloc( sizeof(struct async_workshop_filepath_info) );
+/*
+ * Async thread which scans local files for boards, as well as scheduling 
+ * synchronous calls to the workshop
+ */
+VG_STATIC void world_scan_thread( void *_args )
+{
+   vg_linear_clear( vg_mem.scratch );
 
-      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! */
+   for( u32 i=0; i<global_skateshop.t1_world_registry_count; i++ ){
+      struct registry_world *reg = &global_skateshop.world_registry[i];
+      reg->state = k_registry_board_state_indexed_absent;
+   }
 
-      strcat( path, meta_file );
-      workshop_load_metadata( path, &reg->workshop );
+   /*
+    * Local disk scan
+    */
+   vg_info( "Scanning maps/*.mdl\n" );
 
-next_file_workshop:;
+   char path_buf[4096];
+   vg_str path;
+   vg_strnull( &path, path_buf, 4096 );
+   vg_strcat( &path, "maps/" );
+
+   DIR *dir = opendir( path.buffer );
+   if( !dir ){
+      vg_error( "opendir('maps') failed\n" );
+      vg_async_call( workshop_async_any_complete, NULL, 0 );
+      return;
+   }
+
+   struct dirent *entry;
+   while( (entry = readdir(dir)) ){
+      if( entry->d_type == DT_DIR ){
+         if( entry->d_name[0] == '.' ) continue;
+
+         vg_str folder = path;
+         char *folder_name = folder.buffer+folder.i;
+
+         if( strlen( entry->d_name ) >
+               vg_list_size(global_skateshop.world_registry[0].foldername)){
+            vg_warn( "Map folder too long: %s\n", entry->d_name );
+            continue;
+         }
+
+         vg_strcat( &folder, entry->d_name );
+         if( !vg_strgood( &folder ) ) break;
+
+         DIR *subdir = opendir( folder.buffer );
+         while( (entry = readdir(subdir)) ){
+            if( entry->d_type == DT_REG ){
+               if( entry->d_name[0] == '.' ) continue;
+
+               vg_str file = folder;
+               vg_strcat( &file, "/" );
+               vg_strcat( &file, entry->d_name );
+               if( !vg_strgood( &file ) ) continue;
+
+               char *ext = vg_strch( &file, '.' );
+               if( !ext ) continue;
+               if( strcmp(ext,".mdl") ) continue;
+               
+               vg_strcat( &folder, "" );
+               world_scan_register_local( folder_name );
+            }
+         }
+         closedir(subdir);
+      }
    }
+   closedir(dir);
+
+   vg_async_call( workshop_async_world_reg_update, NULL, 0 );
+
+#if 0
+   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);
+#endif
 }
 
 /*
- * Asynchronous scan of local disk for items and add them to the registry
+ * Asynchronous scan of local disk for worlds
  */
-VG_STATIC void workshop_op_item_scan(void)
+VG_STATIC void skateshop_op_world_scan(void)
 {
-   workshop_begin_op( k_workshop_op_item_scan );
-   vg_loader_start( workshop_scan_thread, NULL );
+   skaterift_begin_op( k_async_op_world_scan );
+   vg_loader_start( world_scan_thread, NULL );
 }
 
 /*
@@ -401,10 +545,12 @@ VG_STATIC void callback_persona_statechange( CallbackMsg_t *msg )
 VG_STATIC void skateshop_init(void)
 {
    u32 reg_size   = sizeof(struct registry_board)*SKATESHOP_REGISTRY_MAX,
+       wreg_size  = sizeof(struct registry_world)*SKATESHOP_WORLDS_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.world_registry = 
+      vg_linear_alloc( vg_mem.rtmemory, wreg_size );
    global_skateshop.cache = vg_linear_alloc( vg_mem.rtmemory, cache_size );
 
    memset( global_skateshop.cache, 0, cache_size );
@@ -442,9 +588,73 @@ VG_STATIC struct cache_board *skateshop_selected_cache_if_loaded(void)
    return NULL;
 }
 
+VG_STATIC void pointcloud_async_end(void *_, u32 __)
+{
+   pointcloud_animate( k_pointcloud_anim_opening );
+   skaterift_end_op();
+}
+
+VG_STATIC void pointcloud_clear_async(void *_, u32 __)
+{
+   pointcloud.count = 0;
+   pointcloud_animate( k_pointcloud_anim_opening );
+   skaterift_end_op();
+}
+
+VG_STATIC void skateshop_preview_loader_thread( void *_data )
+{
+   struct registry_world *reg = _data;
+   
+   if( reg->type == k_world_load_type_local ){
+      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{
+         vg_async_call( pointcloud_clear_async, NULL, 0 );
+      }
+   }
+   else{
+      vg_async_call( pointcloud_clear_async, NULL, 0 );
+   }
+}
+
+VG_STATIC void skateshop_load_world_preview( struct registry_world *reg )
+{
+   skaterift_begin_op( k_async_op_world_load_preview );
+   vg_loader_start( skateshop_preview_loader_thread, 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 );
@@ -453,21 +663,34 @@ VG_STATIC void global_skateshop_preupdate(void)
 
    if( !global_skateshop.active ) return;
 
-   world_instance *world = get_active_world();
-
+   world_instance *world = world_current_instance();
    ent_skateshop *shop = global_skateshop.ptr_ent;
+
+   /* camera positioning */
    ent_camera *ref = mdl_arritm( &world->ent_camera, 
                                  mdl_entity_id_id(shop->id_camera) );
-   ent_marker *display = mdl_arritm( &world->ent_marker,
-                                 mdl_entity_id_id(shop->id_display) );
-   
+      
    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 );
-   
+
    v3f lookat;
-   v3_sub( display->transform.co, localplayer.rb.co, 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 );
+   }
+
    q_axis_angle( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f}, 
                  atan2f(lookat[0],lookat[2]) );
 
@@ -475,60 +698,158 @@ VG_STATIC void global_skateshop_preupdate(void)
    localplayer.cam_override_fov = ref->fov;
    localplayer.cam_override_strength = global_skateshop.factive;
 
-   gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" );
-   gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
+   /* 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" );
 
-   int moved = 0;
-   struct cache_board *selected_cache = skateshop_selected_cache_if_loaded();
+      struct cache_board *selected_cache = skateshop_selected_cache_if_loaded();
 
-   if( selected_cache ){
-      gui_helper_action( button_display_string( k_srbind_maccept ), "pick" );
-   }
+      if( selected_cache ){
+         gui_helper_action( button_display_string( k_srbind_maccept ), "pick" );
+      }
 
-   /*
-    * Controls
-    * ----------------------
-    */
+      /*
+       * Controls
+       * ----------------------
+       */
 
-   if( global_skateshop.interaction_cooldown > 0.0f ){
-      global_skateshop.interaction_cooldown -= vg.time_delta;
-      return;
-   }
+      if( button_down( k_srbind_mleft ) ){
+         if( global_skateshop.selected_registry_id > 0 ){
+            global_skateshop.selected_registry_id --;
+         }
+      }
 
-   if( button_down( k_srbind_mleft ) ){
-      if( global_skateshop.selected_registry_id > 0 ){
-         global_skateshop.selected_registry_id --;
-         moved = 1;
+      if( button_down( k_srbind_mright ) ){
+         if( global_skateshop.selected_registry_id+1 < 
+                  global_skateshop.registry_count )
+         {
+            global_skateshop.selected_registry_id ++;
+         }
       }
-   }
 
-   if( button_down( k_srbind_mright ) ){
-      if( global_skateshop.selected_registry_id+1 < 
-               global_skateshop.registry_count )
-      {
-         global_skateshop.selected_registry_id ++;
-         moved = 1;
+      if( selected_cache && button_down( k_srbind_maccept ) ){
+         vg_info( "chose board from skateshop (%u)\n", 
+                     global_skateshop.selected_registry_id );
+
+         if( localplayer.board_view_slot ){
+            unwatch_cache_board( localplayer.board_view_slot );
+         }
+
+         localplayer.board_view_slot = selected_cache;
+         watch_cache_board( localplayer.board_view_slot );
+
+         global_skateshop_exit();
+         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( moved ){
-      global_skateshop.interaction_cooldown = 0.125f;
-      return;
+      if( button_down( k_srbind_mleft ) ){
+         if( cl_playermdl_id > 0 ){
+            cl_playermdl_id --;
+         }
+         else{
+            cl_playermdl_id = 2; /* HACK */
+         }
+         temp_update_playermodel(); /* HACK */
+      }
+
+      if( button_down( k_srbind_mright ) ){
+         if( cl_playermdl_id+1 < 3 ){
+            cl_playermdl_id ++;
+         }
+         else{
+            cl_playermdl_id = 0;  /* HACK */
+         }
+         temp_update_playermodel(); /* HACK */
+         /*lol*/
+      }
+
+      if( button_down( k_srbind_maccept ) ){
+         global_skateshop_exit();
+      }
    }
+   else if( shop->type == k_skateshop_type_worldshop ){
+      int browseable = 0,
+          loadable = 0;
+
+      if( global_skateshop.world_registry_count &&
+            ((skaterift.async_op == k_async_op_none)||
+             (skaterift.async_op == k_async_op_world_load_preview))){
+         gui_helper_action( axis_display_string(k_sraxis_mbrowse_h), "browse" );
+         browseable = 1;
+      }
 
-   if( selected_cache && button_down( k_srbind_maccept ) ){
-      vg_info( "chose board from skateshop (%u)\n", 
-                  global_skateshop.selected_registry_id );
+      if( skaterift.async_op == k_async_op_none ){
+         gui_helper_action( button_display_string(k_srbind_maccept), "load" );
+         loadable = 1;
+      }
+      
+      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( localplayer.board_view_slot ){
-         unwatch_cache_board( localplayer.board_view_slot );
+         if( button_down( k_srbind_mright ) ){
+            if( global_skateshop.selected_world_id+1 < 
+                     global_skateshop.world_registry_count )
+            {
+               global_skateshop.selected_world_id ++;
+               change = 1;
+            }
+         }
+      }
+      
+      if( change && pointcloud_idle() ){
+         pointcloud_animate( k_pointcloud_anim_hiding );
       }
 
-      localplayer.board_view_slot = selected_cache;
-      watch_cache_board( localplayer.board_view_slot );
+      if( skaterift.async_op == k_async_op_none ){
+         struct registry_world *rw = &global_skateshop.world_registry[
+            global_skateshop.selected_world_id ];
 
-      global_skateshop_exit();
-      return;
+         /* automatically load in clouds */
+         if( loadable && button_down( k_srbind_maccept ) ){
+            vg_info( "Select world (%u)\n", 
+                      global_skateshop.selected_world_id );
+            skaterift_change_world( rw->foldername );
+            return;
+         }
+         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( rw );
+               }
+               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{
+      vg_fatal_error( "Unknown store (%u)\n", shop->type );
    }
 
    if( button_down( k_srbind_mback ) ){
@@ -537,22 +858,17 @@ VG_STATIC void global_skateshop_preupdate(void)
    }
 }
 
-/*
- * World: render event
- */
-VG_STATIC void skateshop_render(void)
+VG_STATIC void skateshop_render_boardshop(void)
 {
-   if( !global_skateshop.active ) return;
-      
+   world_instance *world = world_current_instance();
    ent_skateshop *shop = global_skateshop.ptr_ent;
-   world_instance *world = get_active_world();
 
    u32 slot_count = vg_list_size(global_skateshop.shop_view_slots);
 
    ent_marker *mark_rack = mdl_arritm( &world->ent_marker, 
-                                  mdl_entity_id_id(shop->id_rack)),
+                                  mdl_entity_id_id(shop->boards.id_rack)),
               *mark_display = mdl_arritm( &world->ent_marker,
-                                  mdl_entity_id_id(shop->id_display));
+                                  mdl_entity_id_id(shop->boards.id_display));
 
    int visibility[ SKATESHOP_VIEW_SLOT_MAX ];
    SDL_AtomicLock( &global_skateshop.sl_cache_access );
@@ -601,7 +917,7 @@ fade_out:;
    }
 
    ent_marker *mark_info = mdl_arritm( &world->ent_marker, 
-                                        mdl_entity_id_id(shop->id_info));
+                                        mdl_entity_id_id(shop->boards.id_info));
    m4x3f mtext, mrack;
    mdl_transform_m4x3( &mark_info->transform, mtext );
    mdl_transform_m4x3( &mark_rack->transform, mrack );
@@ -617,7 +933,7 @@ fade_out:;
    float scale = 0.2f,
          thickness = 0.03f;
 
-   font3d_bind( &world_global.font, &main_camera );
+   font3d_bind( &gui.font, &main_camera );
    shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
 
    /* Selection counter
@@ -631,7 +947,7 @@ fade_out:;
    m4x3_mul( mrack, mlocal, mmdl );
 
    if( global_skateshop.registry_count == 0 ){
-      font3d_simple_draw( &world_global.font, 0, 
+      font3d_simple_draw( &gui.font, 0, 
                           "Nothing installed", &main_camera, mmdl );
    }
    else{
@@ -642,7 +958,7 @@ fade_out:;
       i+=highscore_intl( buf+i, global_skateshop.registry_count, 3 );
       buf[i++] = '\0';
 
-      font3d_simple_draw( &world_global.font, 0, buf, &main_camera, mmdl );
+      font3d_simple_draw( &gui.font, 0, buf, &main_camera, mmdl );
    }
 
    struct cache_board *cache_ptr = skateshop_selected_cache_if_loaded();
@@ -656,23 +972,128 @@ fade_out:;
     * ----------------------------------------------------------------- */
    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( &gui.font, 0, info->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( &gui.font, 0, info->title, &main_camera, 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( &gui.font, 0, info->author_name );
    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( &gui.font, 0, info->author_name, &main_camera, mmdl );
+}
+
+VG_STATIC void skateshop_render_charshop(void)
+{
+}
+
+VG_STATIC void skateshop_render_worldshop(void)
+{
+   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));
+
+   /* Text */
+   char buftext[128], bufsubtext[128];
+   vg_str info, subtext;
+   vg_strnull( &info, buftext, 128 );
+   vg_strnull( &subtext, bufsubtext, 128 );
+   
+   if( global_skateshop.world_registry_count ){
+      struct registry_world *rw = &global_skateshop.world_registry[
+         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, 
+                              global_skateshop.world_registry_count, 3 );
+      info.buffer[info.i++] = ' ';
+      info.buffer[info.i] = '\0';
+
+      vg_strcat( &info, rw->foldername );
+      if( skaterift.async_op == k_async_op_world_loading ||
+          skaterift.async_op == k_async_op_world_preloading ){
+         vg_strcat( &subtext, "Loading..." );
+      }
+      else{
+         vg_strcat( &subtext, "No information" );
+      }
+   }
+   else{
+      vg_strcat( &info, "No worlds installed" );
+   }
+
+
+   m4x3f mtext,mlocal,mtextmdl;
+   mdl_transform_m4x3( &mark_info->transform, mtext );
+
+   font3d_bind( &gui.font, &main_camera );
+   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] *= 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, &main_camera, mtextmdl );
+
+   m3x3_setdiagonalv3( mlocal, (v3f){ scale1, scale1, thickness } );
+   mlocal[3][0] = -font3d_string_width( &gui.font, 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, &main_camera, 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, &main_camera, mmdl );
+   glDisable(GL_BLEND);
+   glEnable(GL_DEPTH_TEST);
+}
+
+/*
+ * World: render event
+ */
+VG_STATIC void skateshop_render(void)
+{
+   if( !global_skateshop.active ) return;
+      
+   ent_skateshop *shop = global_skateshop.ptr_ent;
+
+   if( shop->type == k_skateshop_type_boardshop ){
+      skateshop_render_boardshop();
+   }
+   else if( shop->type == k_skateshop_type_charshop ){
+      skateshop_render_charshop();
+   }
+   else if( shop->type == k_skateshop_type_worldshop ){
+      skateshop_render_worldshop();
+   }
+   else{
+      vg_fatal_error( "Unknown store (%u)\n", shop->type );
+   }
 }
 
 /*
@@ -684,6 +1105,9 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
    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( call->function == k_ent_function_trigger ){
       if( localplayer.subsystem != k_player_subsystem_walk ){
          return;
@@ -692,6 +1116,7 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
       vg_info( "Entering skateshop\n" );
 
       localplayer.immobile = 1;
+      menu.disable_open = 1;
       global_skateshop.active = 1;
 
       v3_zero( localplayer.rb.v );
@@ -699,8 +1124,14 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
       localplayer._walk.move_speed = 0.0f;
       global_skateshop.ptr_ent = shop;
       
-      skateshop_update_viewpage();
-      workshop_op_item_scan();
+      if( shop->type == k_skateshop_type_boardshop ){
+         skateshop_update_viewpage();
+         workshop_op_item_scan();
+      }
+      else if( shop->type == k_skateshop_type_worldshop ){
+         pointcloud_animate( k_pointcloud_anim_opening );
+         skateshop_op_world_scan();
+      }
    }
 }
 
@@ -712,6 +1143,7 @@ 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;
 }