X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=ent_skateshop.c;h=56d8c01fe8557bcde628799fde5cb8c3d377f988;hb=1d06671f87a9d24596fc6808d8e0db889a818750;hp=39dec86a993115c9058cdd17118f9a8ae2b24cb6;hpb=9c915fa64d52d8ecfcb6c2a892829f2419dea8a1;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/ent_skateshop.c b/ent_skateshop.c index 39dec86..56d8c01 100644 --- a/ent_skateshop.c +++ b/ent_skateshop.c @@ -27,85 +27,20 @@ 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_board( u32 registry_index ) -{ - addon_reg *reg = NULL; - - if( registry_index < addon_count( k_workshop_file_type_board ) ){ - reg = get_addon_from_index( k_workshop_file_type_board, registry_index ); - - 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; - - SDL_AtomicLock( &global_skateshop.sl_cache_access ); - for( u32 i=0; istate == 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; - } - } -#else - - SDL_AtomicLock( &global_skateshop.sl_cache_access ); - struct cache_board *min_board = lru_volatile_cache_board(); - -#endif - - if( min_board ){ - if( min_board->state == k_cache_board_state_loaded ){ - player_board_unload( &min_board->board ); - min_board->reg_ptr->userdata = NULL; - } - - if( reg ){ - vg_info( "Allocating board (reg:%u) '%s'\n", - registry_index, reg->foldername ); - } - else{ - vg_info( "Pre-allocating board (reg:%u) 'null'\n", registry_index ); - } +VG_STATIC void skateshop_update_viewpage(void){ + u32 page = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX; - 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; - } - else{ - vg_error( "No free boards to load registry!\n" ); + for( u32 i=0; icache_id ); } - - SDL_AtomicUnlock( &global_skateshop.sl_cache_access ); - return min_board; -} - -VG_STATIC void skateshop_update_viewpage(void) -{ - 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_board( 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 ); } } @@ -114,117 +49,25 @@ VG_STATIC void skateshop_update_viewpage(void) * ----------------------------------------------------------------------------- */ -/* - * 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->state = k_cache_board_state_loaded; - - cache_ptr->reg_ptr->userdata = cache_ptr; - SDL_AtomicUnlock( &global_skateshop.sl_cache_access ); - 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(void) -{ - vg_info( "Running load loop\n" ); - char path_buf[4096]; - - for( u32 i=0; istate == k_cache_board_state_load_request ){ - 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 ); - continue; - } - - /* 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; - - - /* load content files - * --------------------------------- */ - - vg_str content_path = folder; - - - vg_msg root = {0}; - root.buf = reg->metadata; - root.len = reg->metadata_len; - root.max = sizeof(reg->metadata); - - 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_error( "No content paths in metadata\n" ); - goto file_is_broken; - } - - 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; - -file_is_broken:; - SDL_AtomicLock( &global_skateshop.sl_cache_access ); - cache_ptr->state = k_cache_board_state_none; - SDL_AtomicUnlock( &global_skateshop.sl_cache_access ); - } - else - SDL_AtomicUnlock( &global_skateshop.sl_cache_access ); - } -} - - VG_STATIC void world_scan_thread( void *_args ){ - addon_mount_content_folder( k_workshop_file_type_world, "maps", ".mdl" ); + addon_mount_content_folder( k_addon_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 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 board_processview_thread( void *_args ){ - workshop_visibile_load_loop(); - skaterift_end_op(); + addon_cache_load_loop(); } VG_STATIC void board_scan_thread( void *_args ){ - addon_mount_content_folder( k_workshop_file_type_board, "boards", ".mdl" ); + 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(); @@ -232,12 +75,10 @@ VG_STATIC void board_scan_thread( void *_args ){ } VG_STATIC void skateshop_op_board_scan(void){ - skaterift_begin_op( k_async_op_board_scan ); vg_loader_start( board_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 ); } @@ -246,96 +87,19 @@ VG_STATIC void skateshop_op_processview(void){ * ----------------------------------------------------------------------------- */ -/* 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->ref_count ++; -} - -/* 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; - } -} - -/* 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( head ){ - if( head == tail ) global_skateshop.cache_tail = NULL; - global_skateshop.cache_head = head->right; - - head->left = NULL; - head->right = NULL; - return head; - } - else return NULL; -} - /* * VG event init */ 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( i32 ib=0; ib=0? &arr[ia]: NULL, - *pc = icleft = pa; - pb->right = pc; - - 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( addon_count(k_workshop_file_type_board) ){ - addon_reg *reg = get_addon_from_index(k_workshop_file_type_board, +static u16 skateshop_selected_cache_id(void){ + if( addon_count(k_addon_type_board) ){ + addon_reg *reg = get_addon_from_index(k_addon_type_board, global_skateshop.selected_board_id); - - SDL_AtomicLock( &global_skateshop.sl_cache_access ); - 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 ); + return reg->cache_id; } - - return NULL; + else return 0; } VG_STATIC void pointcloud_async_end(void *_, u32 __) @@ -349,7 +113,7 @@ VG_STATIC void pointcloud_clear_async(void *_, u32 __) pointcloud_animate( k_pointcloud_anim_opening ); } -VG_STATIC void skateshop_preview_loader_thread( void *_data ) +VG_STATIC void skateshop_world_preview_loader_thread( void *_data ) { addon_reg *reg = _data; @@ -387,31 +151,21 @@ VG_STATIC void skateshop_preview_loader_thread( void *_data ) } } -VG_STATIC void skateshop_preview_loader_thread_and_end( void *_data ){ - skateshop_preview_loader_thread( _data ); - skaterift_end_op(); +VG_STATIC void skateshop_world_preview_loader_thread_and_end( void *_data ){ + skateshop_world_preview_loader_thread( _data ); } -VG_STATIC void skateshop_load_world_preview( addon_reg *reg ) -{ - skaterift_begin_op( k_async_op_world_load_preview ); - vg_loader_start( skateshop_preview_loader_thread_and_end, reg ); +VG_STATIC void skateshop_load_world_preview( addon_reg *reg ){ + vg_loader_start( skateshop_world_preview_loader_thread_and_end, reg ); } /* * VG event preupdate */ void temp_update_playermodel(void); -VG_STATIC void global_skateshop_preupdate(void) -{ - float rate = vg_minf( 1.0f, vg.time_frame_delta * 2.0f ); - global_skateshop.factive = vg_lerpf( global_skateshop.factive, - global_skateshop.active, rate ); - - if( !global_skateshop.active ) return; - +VG_STATIC void ent_skateshop_preupdate( ent_skateshop *shop ){ + /* input filter */ world_instance *world = world_current_instance(); - ent_skateshop *shop = global_skateshop.ptr_ent; /* camera positioning */ ent_camera *ref = mdl_arritm( &world->ent_camera, @@ -420,51 +174,42 @@ 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 ); + player_vector_angles( world_static.focus_cam.angles, dir, 1.0f, 0.0f ); 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 ){ + else if( shop->type == k_skateshop_type_charshop ) v3_sub( ref->transform.co, localplayer.rb.co, lookat ); - } - else{ + 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 ){ - if( skaterift.async_op != k_async_op_none ) return; + if( !vg_loader_availible() ) return; gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" ); gui_helper_action( button_display_string( k_srbind_mback ), "exit" ); - struct cache_board *selected_cache = skateshop_selected_cache_if_loaded(); - - if( selected_cache ){ + u16 cache_id = skateshop_selected_cache_id(); + if( cache_id ){ gui_helper_action( button_display_string( k_srbind_maccept ), "pick" ); } /* * Controls * ---------------------- - * - * TODO: Crash if switch page too quick, delist browse if loading.... */ - u32 opage = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX; if( button_down( k_srbind_mleft ) ){ @@ -475,7 +220,7 @@ VG_STATIC void global_skateshop_preupdate(void) if( button_down( k_srbind_mright ) ){ if( global_skateshop.selected_board_id+1 < - addon_count(k_workshop_file_type_board) ) + addon_count(k_addon_type_board) ) { global_skateshop.selected_board_id ++; } @@ -487,64 +232,71 @@ VG_STATIC void global_skateshop_preupdate(void) skateshop_update_viewpage(); skateshop_op_processview(); } - else if( selected_cache && button_down( k_srbind_maccept ) ){ + else if( cache_id && button_down( k_srbind_maccept )){ vg_info( "chose board from skateshop (%u)\n", global_skateshop.selected_board_id ); - if( localplayer.board_view_slot ){ - unwatch_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; - localplayer.board_view_slot = selected_cache; - watch_cache_board( localplayer.board_view_slot ); - global_skateshop_exit(); - skaterift_write_savedata(); + world_entity_unfocus(); + skaterift_autosave(1); return; } } else if( shop->type == k_skateshop_type_charshop ){ + if( !vg_loader_availible() ) return; + gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" ); gui_helper_action( button_display_string( k_srbind_mback ), "exit" ); gui_helper_action( button_display_string( k_srbind_maccept ), "pick" ); + int changed = 0; + if( button_down( k_srbind_mleft ) ){ - if( k_playermdl_id > 0 ){ - k_playermdl_id --; + if( global_skateshop.selected_player_id > 0 ){ + global_skateshop.selected_player_id --; } else{ - k_playermdl_id = 2; /* HACK */ + global_skateshop.selected_player_id = + addon_count(k_addon_type_player) -1; } - temp_update_playermodel(); /* HACK */ + + changed = 1; } if( button_down( k_srbind_mright ) ){ - if( k_playermdl_id+1 < 3 ){ - k_playermdl_id ++; + if( global_skateshop.selected_player_id+1 < + addon_count(k_addon_type_player) ){ + global_skateshop.selected_player_id ++; } else{ - k_playermdl_id = 0; /* HACK */ + global_skateshop.selected_player_id = 0; } - temp_update_playermodel(); /* HACK */ - /*lol*/ + + changed = 1; + } + + if( changed ){ + player__use_model( &localplayer, global_skateshop.selected_player_id ); + skateshop_op_processview(); } if( button_down( k_srbind_maccept ) ){ - global_skateshop_exit(); + world_entity_unfocus(); } } else if( shop->type == k_skateshop_type_worldshop ){ int browseable = 0, loadable = 0; - if( addon_count(k_workshop_file_type_world) && - ((skaterift.async_op == k_async_op_none)|| - (skaterift.async_op == k_async_op_world_load_preview))){ + if( addon_count(k_addon_type_world) && vg_loader_availible() ){ gui_helper_action( axis_display_string(k_sraxis_mbrowse_h), "browse" ); browseable = 1; } - if( (skaterift.async_op == k_async_op_none) && - global_skateshop.selected_world_id > 0 ){ + if( vg_loader_availible() && global_skateshop.selected_world_id > 0 ){ gui_helper_action( button_display_string(k_srbind_maccept), "open rift" ); loadable = 1; @@ -563,7 +315,7 @@ VG_STATIC void global_skateshop_preupdate(void) if( button_down( k_srbind_mright ) ){ if( global_skateshop.selected_world_id+1 < - addon_count(k_workshop_file_type_world) ) + addon_count(k_addon_type_world) ) { global_skateshop.selected_world_id ++; change = 1; @@ -575,17 +327,15 @@ VG_STATIC void global_skateshop_preupdate(void) pointcloud_animate( k_pointcloud_anim_hiding ); } - if( skaterift.async_op == k_async_op_none ){ - addon_reg *reg = get_addon_from_index( k_workshop_file_type_world, + if( vg_loader_availible() ){ + addon_reg *reg = get_addon_from_index( k_addon_type_world, global_skateshop.selected_world_id ); /* automatically load in clouds */ if( loadable && button_down( k_srbind_maccept ) ){ vg_info( "Select rift (%u)\n", global_skateshop.selected_world_id ); - world_loader.reg = reg; - world_loader.override_name[0] = '\0'; - skaterift_change_world_start(); + skaterift_change_world_start( reg ); return; } else{ @@ -616,16 +366,13 @@ VG_STATIC void global_skateshop_preupdate(void) } if( button_down( k_srbind_mback ) ){ - global_skateshop_exit(); + world_entity_unfocus(); return; } } -VG_STATIC void skateshop_render_boardshop(void) -{ +VG_STATIC void skateshop_render_boardshop( ent_skateshop *shop ){ world_instance *world = world_current_instance(); - ent_skateshop *shop = global_skateshop.ptr_ent; - u32 slot_count = vg_list_size(global_skateshop.shop_view_slots); ent_marker *mark_rack = mdl_arritm( &world->ent_marker, @@ -633,25 +380,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; icache_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; icache_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 ); @@ -659,7 +405,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->reg_index == global_skateshop.selected_board_id ){ + + if( entry->reg_index == global_skateshop.selected_board_id ){ selected = 1.0f; } @@ -668,10 +415,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; @@ -695,7 +443,7 @@ fade_out:; float scale = 0.2f, thickness = 0.03f; - font3d_bind( &gui.font, &main_camera ); + font3d_bind( &gui.font, &skaterift.cam ); shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} ); /* Selection counter @@ -708,24 +456,30 @@ fade_out:; mlocal[3][2] = -0.7f; m4x3_mul( mrack, mlocal, mmdl ); - if( addon_count(k_workshop_file_type_board) ){ + if( addon_count(k_addon_type_board) ){ char buf[16]; int i=0; i+=highscore_intl( buf+i, global_skateshop.selected_board_id+1, 3 ); buf[i++] = '/'; - i+=highscore_intl( buf+i, addon_count(k_workshop_file_type_board), 3 ); + i+=highscore_intl( buf+i, addon_count(k_addon_type_board), 3 ); buf[i++] = '\0'; - font3d_simple_draw( &gui.font, 0, buf, &main_camera, mmdl ); + font3d_simple_draw( &gui.font, 0, k_font_shader_default, + buf, &skaterift.cam, mmdl ); } else{ - font3d_simple_draw( &gui.font, 0, - "Nothing installed", &main_camera, mmdl ); + font3d_simple_draw( &gui.font, 0, k_font_shader_default, + "Nothing installed", &skaterift.cam, mmdl ); } - struct cache_board *cache_ptr = skateshop_selected_cache_if_loaded(); + u16 cache_id = skateshop_selected_cache_id(); + struct addon_cache_entry *entry = vg_pool_item( &cache->pool, cache_id ); + addon_reg *reg = NULL; + + if( entry ) reg = entry->reg_ptr; - if( !cache_ptr ){ + if( !reg ){ + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); global_skateshop.render.item_title = ""; global_skateshop.render.item_desc = ""; return; @@ -734,7 +488,6 @@ fade_out:; if( global_skateshop.render.reg_id != global_skateshop.selected_board_id ){ global_skateshop.render.item_title = ""; global_skateshop.render.item_desc = ""; - addon_reg *reg = cache_ptr->reg_ptr; vg_msg root = {0}; root.buf = reg->metadata; root.len = reg->metadata_len; @@ -752,8 +505,6 @@ fade_out:; global_skateshop.render.reg_id = global_skateshop.selected_board_id; } - addon_reg *reg = cache_ptr->reg_ptr; - /* Skin title * ----------------------------------------------------------------- */ m3x3_zero( mlocal ); @@ -764,8 +515,9 @@ fade_out:; mlocal[3][1] = 0.1f; mlocal[3][2] = 0.0f; m4x3_mul( mtext, mlocal, mmdl ); - font3d_simple_draw( &gui.font, 0, global_skateshop.render.item_title, - &main_camera, mmdl ); + font3d_simple_draw( &gui.font, 0, k_font_shader_default, + global_skateshop.render.item_title, + &skaterift.cam, mmdl ); /* Author name * ----------------------------------------------------------------- */ @@ -777,19 +529,19 @@ fade_out:; mlocal[3][1] = 0.0f; mlocal[3][2] = 0.0f; m4x3_mul( mtext, mlocal, mmdl ); - font3d_simple_draw( &gui.font, 0, global_skateshop.render.item_desc, - &main_camera, mmdl ); + font3d_simple_draw( &gui.font, 0, k_font_shader_default, + global_skateshop.render.item_desc, + &skaterift.cam, mmdl ); + + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); } -VG_STATIC void skateshop_render_charshop(void) -{ +VG_STATIC void skateshop_render_charshop( ent_skateshop *shop ){ } -VG_STATIC void skateshop_render_worldshop(void) -{ +VG_STATIC void skateshop_render_worldshop( ent_skateshop *shop ){ world_instance *world = world_current_instance(); - ent_skateshop *shop = global_skateshop.ptr_ent; ent_marker *mark_display = mdl_arritm( &world->ent_marker, mdl_entity_id_id(shop->worlds.id_display)), *mark_info = mdl_arritm( &world->ent_marker, @@ -798,7 +550,7 @@ VG_STATIC void skateshop_render_worldshop(void) 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, + addon_reg *reg = get_addon_from_index( k_addon_type_world, global_skateshop.selected_world_id ); vg_msg root = {0}; root.buf = reg->metadata; @@ -819,28 +571,27 @@ VG_STATIC void skateshop_render_worldshop(void) vg_strnull( &info, buftext, 128 ); vg_strnull( &subtext, bufsubtext, 128 ); - if( addon_count(k_workshop_file_type_world) ){ - addon_reg *reg = get_addon_from_index( k_workshop_file_type_world, + if( addon_count(k_addon_type_world) ){ + addon_reg *reg = get_addon_from_index( k_addon_type_world, global_skateshop.selected_world_id ); info.i+=highscore_intl( info.buffer+info.i, global_skateshop.selected_world_id+1, 3 ); info.buffer[info.i++] = '/'; info.i+=highscore_intl( info.buffer+info.i, - addon_count(k_workshop_file_type_world), 3 ); + addon_count(k_addon_type_world), 3 ); info.buffer[info.i++] = ' '; info.buffer[info.i] = '\0'; 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 ){ + if( !vg_loader_availible() ){ vg_strcat( &subtext, "Loading..." ); } else{ - addon_reg *reg = get_addon_from_index( k_workshop_file_type_world, + addon_reg *reg = get_addon_from_index( k_addon_type_world, global_skateshop.selected_world_id ); - if( reg->workshop_id ) + if( reg->alias.workshop_id ) vg_strcat( &subtext, "(Workshop) " ); vg_strcat( &subtext, global_skateshop.render.world_loc ); @@ -854,7 +605,7 @@ VG_STATIC void skateshop_render_worldshop(void) m4x3f mtext,mlocal,mtextmdl; mdl_transform_m4x3( &mark_info->transform, mtext ); - font3d_bind( &gui.font, &main_camera ); + font3d_bind( &gui.font, &skaterift.cam ); shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} ); float scale = 0.2f, thickness = 0.015f, scale1 = 0.08f; @@ -865,14 +616,16 @@ VG_STATIC void skateshop_render_worldshop(void) 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 ); + font3d_simple_draw( &gui.font, 0, k_font_shader_default, + buftext, &skaterift.cam, 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 ); + font3d_simple_draw( &gui.font, 0, k_font_shader_default, + bufsubtext, &skaterift.cam, mtextmdl ); /* pointcloud */ m4x3f mmdl; @@ -882,7 +635,7 @@ VG_STATIC void skateshop_render_worldshop(void) glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glDisable(GL_DEPTH_TEST); - pointcloud_render( world, &main_camera, mmdl ); + pointcloud_render( world, &skaterift.cam, mmdl ); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } @@ -890,57 +643,51 @@ VG_STATIC void skateshop_render_worldshop(void) /* * 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_STATIC void skateshop_render( ent_skateshop *shop ){ + if( shop->type == k_skateshop_type_boardshop ) + skateshop_render_boardshop( shop ); + else if( shop->type == k_skateshop_type_charshop ) + skateshop_render_charshop( shop ); + else if( shop->type == k_skateshop_type_worldshop ) + skateshop_render_worldshop( shop ); + else vg_fatal_error( "Unknown store (%u)\n", shop->type ); - } } /* * Entity logic: entrance event */ -VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call ) -{ +VG_STATIC void 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 ) return; + if( !vg_loader_availible() ) return; if( call->function == k_ent_function_trigger ){ - if( localplayer.subsystem != k_player_subsystem_walk ){ - return; - } + if( localplayer.subsystem != k_player_subsystem_walk ) return; vg_info( "Entering skateshop\n" ); + world_entity_focus( call->id ); +#if 0 localplayer.immobile = 1; menu.disable_open = 1; - global_skateshop.active = 1; + skaterift.activity = k_skaterift_skateshop; v3_zero( localplayer.rb.v ); v3_zero( localplayer.rb.w ); localplayer._walk.move_speed = 0.0f; global_skateshop.ptr_ent = shop; +#endif if( shop->type == k_skateshop_type_boardshop ){ skateshop_update_viewpage(); skateshop_op_board_scan(); + } + else if( shop->type == k_skateshop_type_charshop ){ + } else if( shop->type == k_skateshop_type_worldshop ){ pointcloud_animate( k_pointcloud_anim_opening ); @@ -949,16 +696,4 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call ) } } -/* - * 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 */