X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=ent_skateshop.c;h=2957c8f4be07e8240af807a42feb931091a49b1d;hb=b1d22bbb87583cea9fde7620eb1fc16189be5113;hp=ce0ca5d2b55236f98164197d906a469df462b681;hpb=6afe1eb8c0283fdf65aaf117db8c33689c21552d;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/ent_skateshop.c b/ent_skateshop.c index ce0ca5d..2957c8f 100644 --- a/ent_skateshop.c +++ b/ent_skateshop.c @@ -13,6 +13,8 @@ #include "pointcloud.h" #include "highscores.h" #include "steam.h" +#include "addon.h" +#include "save.h" /* * Checks string equality but does a hash check first @@ -29,18 +31,19 @@ static inline int const_str_eq( u32 hash, const char *str, const char *cmp ) * 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 ) +VG_STATIC struct cache_board *skateshop_cache_fetch_board( u32 registry_index ) { - struct registry_board *reg = NULL; + addon_reg *reg = NULL; - if( registry_index < global_skateshop.registry_count ){ - reg = &global_skateshop.registry[ registry_index ]; + if( registry_index < addon_count( k_workshop_file_type_board ) ){ + reg = get_addon_from_index( k_workshop_file_type_board, registry_index ); - if( reg->cache_ptr ){ - return reg->cache_ptr; + if( reg->userdata ){ + return reg->userdata; } } +#if 0 /* lru eviction. should be a linked list maybe... */ double min_time = 1e300; struct cache_board *min_board = NULL; @@ -57,16 +60,17 @@ VG_STATIC struct cache_board *skateshop_cache_fetch( u32 registry_index ) min_board = cache_ptr; } } +#else - if( min_board ){ - if( min_board->state == k_cache_board_state_loaded ){ - struct registry_board *other = - &global_skateshop.registry[ min_board->registry_id ]; + SDL_AtomicLock( &global_skateshop.sl_cache_access ); + struct cache_board *min_board = lru_volatile_cache_board(); - vg_info( "Deallocating board: '%s'\n", min_board, other->foldername ); +#endif + if( min_board ){ + if( min_board->state == k_cache_board_state_loaded ){ player_board_unload( &min_board->board ); - other->cache_ptr = NULL; + min_board->reg_ptr->userdata = NULL; } if( reg ){ @@ -77,8 +81,8 @@ VG_STATIC struct cache_board *skateshop_cache_fetch( u32 registry_index ) 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->reg_ptr = reg; + min_board->reg_index = registry_index; min_board->ref_count = 0; min_board->state = k_cache_board_state_load_request; } @@ -92,7 +96,7 @@ VG_STATIC struct cache_board *skateshop_cache_fetch( u32 registry_index ) VG_STATIC void skateshop_update_viewpage(void) { - u32 page = global_skateshop.selected_registry_id/SKATESHOP_VIEW_SLOT_MAX; + u32 page = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX; for( u32 i=0; icache_ptr ) unwatch_cache_board( slot->cache_ptr ); - slot->cache_ptr = skateshop_cache_fetch( request_id ); + slot->cache_ptr = skateshop_cache_fetch_board( request_id ); if( slot->cache_ptr ) watch_cache_board( slot->cache_ptr ); } } @@ -117,32 +121,28 @@ 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; - struct registry_board *reg = - &global_skateshop.registry[ cache_ptr->registry_id ]; - reg->cache_ptr = cache_ptr; + cache_ptr->reg_ptr->userdata = cache_ptr; SDL_AtomicUnlock( &global_skateshop.sl_cache_access ); - - vg_success( "Async board loaded (%s)\n", reg->foldername ); + vg_success( "Async board loaded (%s)\n", cache_ptr->reg_ptr->foldername ); } /* * 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 ) +VG_STATIC void workshop_visibile_load_loop(void) { + vg_info( "Running load loop\n" ); char path_buf[4096]; - vg_str folder; for( u32 i=0; istate == k_cache_board_state_load_request ){ - if( cache_ptr->registry_id >= global_skateshop.registry_count ){ + if( cache_ptr->reg_index >= addon_count(k_workshop_file_type_board) ){ /* should maybe have a different value for this case */ cache_ptr->state = k_cache_board_state_none; SDL_AtomicUnlock( &global_skateshop.sl_cache_access ); @@ -151,83 +151,43 @@ VG_STATIC void workshop_visibile_load_loop_thread( void *_args ) /* continue with the request */ SDL_AtomicUnlock( &global_skateshop.sl_cache_access ); + addon_reg *reg = get_addon_from_index( k_workshop_file_type_board, + cache_ptr->reg_index ); + cache_ptr->reg_ptr = reg; + + vg_str folder; + vg_strnull( &folder, path_buf, 4096 ); + if( !addon_get_content_folder( reg, &folder ) ) + goto file_is_broken; - 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) ); + /* load content files + * --------------------------------- */ - struct async_workshop_filepath_info *info = call->payload; - info->buf = path_buf; - info->id = reg->workshop_id; - info->len = vg_list_size(path_buf); - vg_async_dispatch( call, async_workshop_get_filepath ); - vg_async_stall(); /* too bad! */ + vg_str content_path = folder; - if( path_buf[0] == '\0' ){ - vg_error( "Failed SteamAPI_GetItemInstallInfo(" PRINTF_U64 ")\n", - reg->workshop_id ); - goto file_is_broken; - } + vg_msg root = {0}; + root.buf = reg->metadata; + root.len = reg->metadata_len; + root.max = sizeof(reg->metadata); - folder.buffer = path_buf; - folder.i = strlen(path_buf); - folder.len = 4096; + const char *kv_content = vg_msg_seekkvstr( &root, "content", 0 ); + if( kv_content ){ + vg_strcat( &content_path, "/" ); + vg_strcat( &content_path, kv_content ); } else{ - vg_strnull( &folder, path_buf, 4096 ); - vg_strcat( &folder, "boards/" ); - vg_strcat( &folder, reg->foldername ); - } - - vg_str meta_path = folder; - vg_strcat( &meta_path, "/addon.inf" ); - - if( !vg_strgood( &meta_path ) ) { - vg_error( "Metadata path too long\n" ); + vg_error( "No content paths in metadata\n" ); goto file_is_broken; } - u8 meta[512]; - FILE *fp = fopen( meta_path.buffer, "rb" ); - - if( !fp ) goto file_is_broken; - - u32 l = fread( meta, 1, 512, fp ); - if( l != 512 ){ - if( !feof(fp) ){ - fclose(fp); - vg_error( "unknown error codition" ); - goto file_is_broken; - } - } - fclose(fp); - - /* load content files - * --------------------------------- */ - - vg_str content_path = folder; - - vg_msg msg; - vg_msg_init( &msg, meta, l ); - vg_msg_cmd cmd; - while( vg_msg_next( &msg, &cmd ) ){ - if( (msg.depth == 0) && (cmd.code == k_vg_msg_code_kvstring) ){ - if( VG_STRDJB2_EQ( "content", cmd.key, cmd.key_djb2 ) ){ - vg_strcat( &content_path, "/" ); - vg_strcat( &content_path, cmd.value._buf ); - break; - } - } - } if( !vg_strgood( &content_path ) ) { vg_error( "Metadata path too long\n" ); goto file_is_broken; } - + + vg_info( "Load content: %s\n", content_path.buffer ); player_board_load( &cache_ptr->board, content_path.buffer ); vg_async_call( skateshop_async_board_loaded, cache_ptr, 0 ); continue; @@ -240,390 +200,45 @@ file_is_broken:; else SDL_AtomicUnlock( &global_skateshop.sl_cache_access ); } - 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(); - - for( u32 j=0; jworkshop_id == id ){ - reg->state = k_registry_board_state_indexed; - goto next_file_workshop; - } - } - for( u32 i=0; iworkshop_id == id ){ - reg->state = k_registry_board_state_indexed; - goto next_file_workshop; - } - } - - /* new one, lets find out what type it is - * ---------------------------------------------------------------*/ - vg_info( "new listing from the steam workshop!: "PRINTF_U64"\n", id ); - vg_async_item *call1 = - vg_async_alloc( sizeof(struct async_workshop_filepath_info) ); - - char path[ 4096 ]; - - struct async_workshop_filepath_info *info = call1->payload; - info->buf = path; - info->id = id; - info->len = vg_list_size(path); - vg_async_dispatch( call1, async_workshop_get_filepath ); - vg_async_stall(); /* too bad! */ - - vg_info( "%s\n", path ); - vg_str folder = {.buffer = path, .i=strlen(path), .len=4096}; - vg_str meta_path = folder; - vg_strcat( &meta_path, "/addon.inf" ); - if( !vg_strgood( &meta_path ) ){ - vg_error( "The metadata path is too long\n" ); - goto next_file_workshop; - } - u8 meta[512]; - FILE *fp = fopen( meta_path.buffer, "rb" ); - if( !fp ){ - vg_error( "Could not open the '%s'\n", meta_path.buffer ); - goto next_file_workshop; - } - - u32 l = fread( meta, 1, 512, fp ); - if( l != 512 ){ - if( !feof(fp) ){ - fclose(fp); - vg_error( "unknown error codition" ); - goto next_file_workshop; - } - } - fclose(fp); - - enum workshop_file_type type = k_workshop_file_type_none; - vg_msg msg; - vg_msg_init( &msg, meta, l ); - - vg_msg_cmd cmd; - while( vg_msg_next( &msg, &cmd ) ){ - if( (msg.depth == 1) && (cmd.code == k_vg_msg_code_frame) ){ - if( VG_STRDJB2_EQ( "workshop", cmd.key, cmd.key_djb2 ) ){ - u32 depth = msg.depth; - while( (msg.depth == depth) && vg_msg_next( &msg, &cmd ) ){ - if( cmd.code & k_vg_msg_code_unsigned ){ - if( VG_STRDJB2_EQ( "type", cmd.key, cmd.key_djb2 ) ){ - type = cmd.value._u32; - } - } - } - } - } - } - - if( type == k_workshop_file_type_none ){ - vg_error( "Cannot determine addon type\n" ); - goto next_file_workshop; - } - - /* now that we have the type - * ------------------------------------------------------------------*/ - - if( type == k_workshop_file_type_board ){ - if( global_skateshop.t1_registry_count == SKATESHOP_REGISTRY_MAX ){ - vg_error( "You have too many boards installed!\n" ); - goto next_file_workshop; - } - - struct registry_board *reg = &global_skateshop.registry[ - global_skateshop.t1_registry_count ++ ]; - - reg->cache_ptr = NULL; - snprintf( reg->foldername, 64, PRINTF_U64, id ); - reg->foldername_hash = vg_strdjb2( reg->foldername ); - reg->workshop_id = id; - reg->state = k_registry_board_state_indexed; - } - else if( type == k_workshop_file_type_world ){ - if( global_skateshop.t1_world_registry_count == SKATESHOP_WORLDS_MAX ){ - vg_error( "You have too many worlds installed!\n" ); - goto next_file_workshop; - } - - struct registry_world *reg = &global_skateshop.world_registry[ - global_skateshop.t1_world_registry_count ++ ]; - - snprintf( reg->foldername, 64, PRINTF_U64, id ); - reg->foldername_hash = vg_strdjb2( reg->foldername ); - reg->type = k_world_load_type_workshop; - reg->workshop_id = id; - reg->state = k_registry_board_state_indexed; - } - -next_file_workshop:; - } -} - -/* - * 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 ) -{ - vg_linear_clear( vg_mem.scratch ); - - for( u32 i=0; istate = k_registry_board_state_indexed_absent; - } - -#if 0 - /* - * 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; ifilename ) ){ - 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 ); -#if 0 - vg_strncpy( file.name, reg->workshop.title, - 64, k_strncpy_always_add_null ); -#endif - reg->filename_hash = hash; - reg->workshop_id = 0; - reg->state = k_registry_board_state_indexed; - -#if 0 - reg->workshop.author = 0; - strcpy( reg->workshop.author_name, "custom" ); -#endif - } - -next_file: tinydir_next( &dir ); - } - - tinydir_close(&dir); -#endif - - if( steam_ready ) workshop_steam_scan(); - - vg_async_call( workshop_async_reg_update, NULL, 0 ); - vg_async_stall(); - workshop_visibile_load_loop_thread(NULL); +VG_STATIC void world_scan_thread( void *_args ){ + addon_mount_content_folder( k_workshop_file_type_world, "maps", ".mdl" ); + addon_mount_workshop_items(); + vg_async_call( async_addon_reg_update, NULL, 0 ); + skaterift_end_op(); } /* - * 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) -{ - skaterift_begin_op( k_workshop_op_item_scan ); - vg_loader_start( workshop_scan_thread, NULL ); +VG_STATIC void skateshop_op_world_scan(void){ + skaterift_begin_op( k_async_op_world_scan ); + vg_loader_start( world_scan_thread, NULL ); } -/* - * op: k_async_op_world_scan - * ----------------------------------------------------------------------------- - */ - -/* - * 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; +VG_STATIC void board_processview_thread( void *_args ){ + workshop_visibile_load_loop(); skaterift_end_op(); } -/* - * 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; ifoldername ) ){ - reg->state = k_registry_board_state_indexed; - return; - } - } - - if( global_skateshop.t1_world_registry_count == SKATESHOP_WORLDS_MAX ){ - vg_error( "You have too many worlds installed!\n" ); - return; - } - - vg_info( "new listing!: %s\n", folder_name ); - - struct registry_world *reg = &global_skateshop.world_registry[ - global_skateshop.t1_world_registry_count ++ ]; - - 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; +VG_STATIC void board_scan_thread( void *_args ){ + addon_mount_content_folder( k_workshop_file_type_board, "boards", ".mdl" ); + addon_mount_workshop_items(); + vg_async_call( async_addon_reg_update, NULL, 0 ); + vg_async_stall(); + board_processview_thread(NULL); } -/* - * 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 ); - - for( u32 i=0; istate = k_registry_board_state_indexed_absent; - } - - /* - * Local disk scan - */ - vg_info( "Scanning maps/*.mdl\n" ); - - 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 +VG_STATIC void skateshop_op_board_scan(void){ + skaterift_begin_op( k_async_op_board_scan ); + vg_loader_start( board_scan_thread, NULL ); } -/* - * Asynchronous scan of local disk for worlds - */ -VG_STATIC void skateshop_op_world_scan(void) -{ - skaterift_begin_op( k_async_op_world_scan ); - vg_loader_start( world_scan_thread, NULL ); +VG_STATIC void skateshop_op_processview(void){ + skaterift_begin_op( k_async_op_board_scan ); + vg_loader_start( board_processview_thread, NULL ); } /* @@ -631,94 +246,91 @@ VG_STATIC void skateshop_op_world_scan(void) * ----------------------------------------------------------------------------- */ -/* 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 ) -{ +/* adds one more watch */ +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 after this no more watches, places back into the volatile list */ +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 --; + if( !ptr->ref_count ){ + struct cache_board *head = global_skateshop.cache_head, + *tail = global_skateshop.cache_tail; + + if( tail ) tail->right = ptr; + ptr->left = tail; + global_skateshop.cache_tail = ptr; + + if( !head ) global_skateshop.cache_head = ptr; + } } -/* - * 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(); +/* retrieve oldest pointer from the volatile list (and remove it) */ +VG_STATIC struct cache_board *lru_volatile_cache_board(void){ + struct cache_board *head = global_skateshop.cache_head, + *tail = global_skateshop.cache_tail; -#if 0 - if( info->m_nChangeFlags & k_EPersonaChangeName ){ - for( u32 i=0; iworkshop.author == info->m_ulSteamID ){ - const char *name = SteamAPI_ISteamFriends_GetFriendPersonaName( - hSteamFriends, info->m_ulSteamID ); - str_utf8_collapse( name, reg->workshop.author_name, 32 ); - } - } + if( head ){ + if( head == tail ) global_skateshop.cache_tail = NULL; + global_skateshop.cache_head = head->right; + + head->left = NULL; + head->right = NULL; + return head; } -#endif + else return NULL; } /* * VG event init */ -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.world_registry = - vg_linear_alloc( vg_mem.rtmemory, wreg_size ); +VG_STATIC void skateshop_init(void){ + u32 cache_size = sizeof(struct cache_board)*SKATESHOP_BOARD_CACHE_MAX; global_skateshop.cache = vg_linear_alloc( vg_mem.rtmemory, cache_size ); - memset( global_skateshop.cache, 0, cache_size ); - for( u32 i=0; istate = k_cache_board_state_none; - board->registry_id = 0xffffffff; - board->last_use_time = -99999.9; - board->ref_count = 0; - } + for( i32 ib=0; ib=0? &arr[ia]: NULL, + *pc = icleft = pa; + pb->right = pc; - if( steam_ready ){ - steam_register_callback( k_iPersonaStateChange, - callback_persona_statechange ); + pb->state = k_cache_board_state_none; + pb->reg_ptr= NULL; + pb->reg_index = 0xffffffff; + pb->ref_count = 0; } + + global_skateshop.cache_head = global_skateshop.cache; + global_skateshop.cache_tail = + &global_skateshop.cache[SKATESHOP_BOARD_CACHE_MAX-1]; } 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 ]; + if( addon_count(k_workshop_file_type_board) ){ + addon_reg *reg = get_addon_from_index(k_workshop_file_type_board, + global_skateshop.selected_board_id); 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; + if( reg->userdata ){ + struct cache_board *cache_ptr = reg->userdata; + if( cache_ptr->state == k_cache_board_state_loaded ){ + SDL_AtomicUnlock( &global_skateshop.sl_cache_access ); + return cache_ptr; + } } SDL_AtomicUnlock( &global_skateshop.sl_cache_access ); } @@ -729,64 +341,61 @@ VG_STATIC struct cache_board *skateshop_selected_cache_if_loaded(void) 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; + addon_reg *reg = _data; + + char path_buf[4096]; + vg_str path; + vg_strnull( &path, path_buf, 4096 ); + addon_get_content_folder( reg, &path ); + vg_strcat( &path, "/preview.bin" ); + + vg_linear_clear(vg_mem.scratch); + u32 size; - if( reg->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{ + 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 ); } } -VG_STATIC void skateshop_load_world_preview( struct registry_world *reg ) +VG_STATIC void skateshop_preview_loader_thread_and_end( void *_data ){ + skateshop_preview_loader_thread( _data ); + skaterift_end_op(); +} + +VG_STATIC void skateshop_load_world_preview( addon_reg *reg ) { skaterift_begin_op( k_async_op_world_load_preview ); - vg_loader_start( skateshop_preview_loader_thread, reg ); + vg_loader_start( skateshop_preview_loader_thread_and_end, reg ); } /* @@ -852,23 +461,31 @@ VG_STATIC void global_skateshop_preupdate(void) * ---------------------- */ + 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 --; } } if( button_down( k_srbind_mright ) ){ - if( global_skateshop.selected_registry_id+1 < - global_skateshop.registry_count ) + if( global_skateshop.selected_board_id+1 < + addon_count(k_workshop_file_type_board) ) { - global_skateshop.selected_registry_id ++; + global_skateshop.selected_board_id ++; } } - if( selected_cache && button_down( k_srbind_maccept ) ){ + u32 npage = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX; + + if( opage != npage ){ + skateshop_update_viewpage(); + skateshop_op_processview(); + } + else if( selected_cache && button_down( k_srbind_maccept ) ){ vg_info( "chose board from skateshop (%u)\n", - global_skateshop.selected_registry_id ); + global_skateshop.selected_board_id ); if( localplayer.board_view_slot ){ unwatch_cache_board( localplayer.board_view_slot ); @@ -876,8 +493,8 @@ VG_STATIC void global_skateshop_preupdate(void) localplayer.board_view_slot = selected_cache; watch_cache_board( localplayer.board_view_slot ); - global_skateshop_exit(); + skaterift_write_savedata(); return; } } @@ -887,21 +504,21 @@ VG_STATIC void global_skateshop_preupdate(void) gui_helper_action( button_display_string( k_srbind_maccept ), "pick" ); if( button_down( k_srbind_mleft ) ){ - if( cl_playermdl_id > 0 ){ - cl_playermdl_id --; + if( k_playermdl_id > 0 ){ + k_playermdl_id --; } else{ - cl_playermdl_id = 2; /* HACK */ + k_playermdl_id = 2; /* HACK */ } temp_update_playermodel(); /* HACK */ } if( button_down( k_srbind_mright ) ){ - if( cl_playermdl_id+1 < 3 ){ - cl_playermdl_id ++; + if( k_playermdl_id+1 < 3 ){ + k_playermdl_id ++; } else{ - cl_playermdl_id = 0; /* HACK */ + k_playermdl_id = 0; /* HACK */ } temp_update_playermodel(); /* HACK */ /*lol*/ @@ -915,15 +532,17 @@ VG_STATIC void global_skateshop_preupdate(void) int browseable = 0, loadable = 0; - if( global_skateshop.world_registry_count && + if( addon_count(k_workshop_file_type_world) && ((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( skaterift.async_op == k_async_op_none ){ - gui_helper_action( button_display_string(k_srbind_maccept), "load" ); + if( (skaterift.async_op == k_async_op_none) && + global_skateshop.selected_world_id > 0 ){ + gui_helper_action( button_display_string(k_srbind_maccept), + "open rift" ); loadable = 1; } @@ -940,7 +559,7 @@ VG_STATIC void global_skateshop_preupdate(void) if( button_down( k_srbind_mright ) ){ if( global_skateshop.selected_world_id+1 < - global_skateshop.world_registry_count ) + addon_count(k_workshop_file_type_world) ) { global_skateshop.selected_world_id ++; change = 1; @@ -953,14 +572,16 @@ VG_STATIC void global_skateshop_preupdate(void) } if( skaterift.async_op == k_async_op_none ){ - struct registry_world *rw = &global_skateshop.world_registry[ - global_skateshop.selected_world_id ]; + addon_reg *reg = get_addon_from_index( k_workshop_file_type_world, + global_skateshop.selected_world_id ); /* automatically load in clouds */ if( loadable && button_down( k_srbind_maccept ) ){ - vg_info( "Select world (%u)\n", + vg_info( "Select rift (%u)\n", global_skateshop.selected_world_id ); - skaterift_change_world( rw->foldername ); + world_loader.reg = reg; + world_loader.override_name[0] = '\0'; + skaterift_change_world_start(); return; } else{ @@ -970,7 +591,7 @@ VG_STATIC void global_skateshop_preupdate(void) { global_skateshop.pointcloud_world_id = global_skateshop.selected_world_id; - skateshop_load_world_preview( rw ); + skateshop_load_world_preview( reg ); } else{ pointcloud_animate( k_pointcloud_anim_opening ); @@ -1034,8 +655,7 @@ 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( slot->cache_ptr->reg_index == global_skateshop.selected_board_id ){ selected = 1.0f; } @@ -1084,52 +704,77 @@ fade_out:; mlocal[3][2] = -0.7f; m4x3_mul( mrack, mlocal, mmdl ); - if( global_skateshop.registry_count == 0 ){ - font3d_simple_draw( &gui.font, 0, - "Nothing installed", &main_camera, mmdl ); - } - else{ + if( addon_count(k_workshop_file_type_board) ){ char buf[16]; int i=0; - i+=highscore_intl( buf+i, global_skateshop.selected_registry_id+1, 3 ); + i+=highscore_intl( buf+i, global_skateshop.selected_board_id+1, 3 ); buf[i++] = '/'; - i+=highscore_intl( buf+i, global_skateshop.registry_count, 3 ); + i+=highscore_intl( buf+i, addon_count(k_workshop_file_type_board), 3 ); buf[i++] = '\0'; font3d_simple_draw( &gui.font, 0, buf, &main_camera, mmdl ); } + else{ + font3d_simple_draw( &gui.font, 0, + "Nothing installed", &main_camera, mmdl ); + } struct cache_board *cache_ptr = skateshop_selected_cache_if_loaded(); - if( !cache_ptr ) return; - struct registry_board *reg = - &global_skateshop.registry[cache_ptr->registry_id]; + if( !cache_ptr ){ + global_skateshop.render.item_title = ""; + global_skateshop.render.item_desc = ""; + return; + } + + if( global_skateshop.render.reg_id != global_skateshop.selected_board_id ){ + global_skateshop.render.item_title = ""; + global_skateshop.render.item_desc = ""; + addon_reg *reg = cache_ptr->reg_ptr; + vg_msg root = {0}; + root.buf = reg->metadata; + root.len = reg->metadata_len; + root.max = sizeof(reg->metadata); -#if 0 - struct workshop_file_info *info = ®->workshop; + vg_msg workshop = root; + if( vg_msg_seekframe( &workshop, "workshop", 0 ) ){ + const char *title = vg_msg_seekkvstr( &workshop, "title", 0 ); + if( title ) global_skateshop.render.item_title = title; + + const char *dsc = vg_msg_seekkvstr( &workshop, "author", 0 ); + if( dsc ) global_skateshop.render.item_desc = dsc; + } + + global_skateshop.render.reg_id = global_skateshop.selected_board_id; + } + + addon_reg *reg = cache_ptr->reg_ptr; /* Skin title * ----------------------------------------------------------------- */ m3x3_zero( mlocal ); m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } ); - mlocal[3][0] = -font3d_string_width( &gui.font, 0, info->title ); + mlocal[3][0] = -font3d_string_width( &gui.font, 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, info->title, &main_camera, mmdl ); + font3d_simple_draw( &gui.font, 0, global_skateshop.render.item_title, + &main_camera, mmdl ); /* Author name * ----------------------------------------------------------------- */ scale *= 0.4f; m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } ); - mlocal[3][0] = -font3d_string_width( &gui.font, 0, info->author_name ); + mlocal[3][0] = -font3d_string_width( &gui.font, 0, + global_skateshop.render.item_desc ); mlocal[3][0] *= scale*0.5f; mlocal[3][1] = 0.0f; mlocal[3][2] = 0.0f; m4x3_mul( mtext, mlocal, mmdl ); - font3d_simple_draw( &gui.font, 0, info->author_name, &main_camera, mmdl ); -#endif + font3d_simple_draw( &gui.font, 0, global_skateshop.render.item_desc, + &main_camera, mmdl ); } VG_STATIC void skateshop_render_charshop(void) @@ -1146,31 +791,55 @@ VG_STATIC void skateshop_render_worldshop(void) *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 = ""; + + addon_reg *reg = get_addon_from_index( k_workshop_file_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.render.world_loc = vg_msg_seekkvstr(&root,"location",0); + global_skateshop.render.world_reg = global_skateshop.selected_world_id; + } + /* 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 ]; + if( addon_count(k_workshop_file_type_world) ){ + addon_reg *reg = get_addon_from_index( k_workshop_file_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, - global_skateshop.world_registry_count, 3 ); + addon_count(k_workshop_file_type_world), 3 ); info.buffer[info.i++] = ' '; info.buffer[info.i] = '\0'; - vg_strcat( &info, rw->foldername ); + vg_strcat( &info, global_skateshop.render.world_title ); 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" ); + addon_reg *reg = get_addon_from_index( k_workshop_file_type_world, + global_skateshop.selected_world_id ); + + if( reg->workshop_id ) + vg_strcat( &subtext, "(Workshop) " ); + + vg_strcat( &subtext, global_skateshop.render.world_loc ); } } else{ @@ -1267,7 +936,7 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call ) if( shop->type == k_skateshop_type_boardshop ){ skateshop_update_viewpage(); - workshop_op_item_scan(); + skateshop_op_board_scan(); } else if( shop->type == k_skateshop_type_worldshop ){ pointcloud_animate( k_pointcloud_anim_opening );