X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=ent_skateshop.c;h=c10352d5ff0a53f33cfd4fea3161b1f15c4e032c;hb=1c56bc84c9ad3da49c9d2447ec97aaf7f6038601;hp=bfec73f9edaf24fe6082b90af3182f7fb2875478;hpb=6b036c10d38e7d691eb0bc06c29235b450c3ff10;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/ent_skateshop.c b/ent_skateshop.c index bfec73f..c10352d 100644 --- a/ent_skateshop.c +++ b/ent_skateshop.c @@ -10,7 +10,6 @@ #include "player.h" #include "gui.h" #include "menu.h" -#include "pointcloud.h" #include "highscores.h" #include "steam.h" #include "addon.h" @@ -45,6 +44,76 @@ static void skateshop_update_viewpage(void){ } } +struct async_preview_load_thread_data{ + void *data; + addon_reg *reg; +}; + +static void skateshop_async_preview_imageload( void *data, u32 len ){ + struct async_preview_load_thread_data *inf = data; + + if( inf->data ){ + glBindTexture( GL_TEXTURE_2D, global_skateshop.tex_preview ); + glTexSubImage2D( GL_TEXTURE_2D, 0,0,0, + WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT, + GL_RGB, GL_UNSIGNED_BYTE, inf->data ); + glGenerateMipmap( GL_TEXTURE_2D ); + stbi_image_free( inf->data ); + + skaterift.rt_textures[k_skaterift_rt_workshop_preview] = + global_skateshop.tex_preview; + } + else { + skaterift.rt_textures[k_skaterift_rt_workshop_preview] = + global_skateshop.tex_preview_err; + } + + SDL_AtomicLock( &addon_system.sl_cache_using_resources ); + global_skateshop.reg_loaded_preview = inf->reg; + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); +} + +static void skateshop_update_preview_image_thread(void *_args){ + char path_buf[4096]; + vg_str folder; + vg_strnull( &folder, path_buf, sizeof(path_buf) ); + + SDL_AtomicLock( &addon_system.sl_cache_using_resources ); + addon_reg *reg_preview = global_skateshop.reg_preview; + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); + + if( !addon_get_content_folder( reg_preview, &folder, 1 ) ){ + SDL_AtomicLock( &addon_system.sl_cache_using_resources ); + global_skateshop.reg_loaded_preview = reg_preview; + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); + return; + } + + vg_strcat( &folder, "/preview.jpg" ); + vg_async_item *call = + vg_async_alloc( sizeof(struct async_preview_load_thread_data) ); + struct async_preview_load_thread_data *inf = call->payload; + + inf->reg = reg_preview; + + if( vg_strgood( &folder ) ){ + stbi_set_flip_vertically_on_load(1); + int x, y, nc; + inf->data = stbi_load( folder.buffer, &x, &y, &nc, 3 ); + + if( inf->data ){ + if( (x != WORKSHOP_PREVIEW_WIDTH) || (y != WORKSHOP_PREVIEW_HEIGHT) ){ + vg_error( "Resolution does not match framebuffer, so we can't" + " show it\n" ); + stbi_image_free( inf->data ); + inf->data = NULL; + } + } + + vg_async_dispatch( call, skateshop_async_preview_imageload ); + } +} + /* * op/subroutine: k_workshop_op_item_load * ----------------------------------------------------------------------------- @@ -85,6 +154,12 @@ static void skateshop_autostart_loading(void){ if( !vg_loader_availible() ) return; SDL_AtomicLock( &addon_system.sl_cache_using_resources ); + if( global_skateshop.reg_preview != global_skateshop.reg_loaded_preview ){ + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); + vg_loader_start( skateshop_update_preview_image_thread, NULL ); + return; + } + for( u32 type=0; typepool, id ); if( entry->state == k_addon_cache_state_load_request ){ SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); - goto launch; + vg_loader_start( board_processview_thread, NULL ); + return; } } } SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); - return; -launch: - vg_loader_start( board_processview_thread, NULL ); } /* @@ -107,78 +180,42 @@ launch: * ----------------------------------------------------------------------------- */ +static void skateshop_init_async(void *_data,u32 size){ + glGenTextures( 1, &global_skateshop.tex_preview ); + glBindTexture( GL_TEXTURE_2D, global_skateshop.tex_preview ); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, + WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT, + 0, GL_RGB, GL_UNSIGNED_BYTE, NULL ); + + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); +} + /* * VG event init */ static void skateshop_init(void){ + vg_async_call( skateshop_init_async, NULL, 0 ); + vg_tex2d_replace_with_error( &global_skateshop.tex_preview_err ); + vg_async_stall(); + + skaterift.rt_textures[ k_skaterift_rt_workshop_preview ] = + global_skateshop.tex_preview_err; } static u16 skateshop_selected_cache_id(void){ - if( addon_count(k_addon_type_board) ){ - addon_reg *reg = get_addon_from_index(k_addon_type_board, - global_skateshop.selected_board_id); + if( addon_count(k_addon_type_board, ADDON_REG_HIDDEN) ){ + addon_reg *reg = get_addon_from_index( + k_addon_type_board, global_skateshop.selected_board_id, + ADDON_REG_HIDDEN ); return reg->cache_id; } else return 0; } -static void pointcloud_async_end(void *_, u32 __) -{ - pointcloud_animate( k_pointcloud_anim_opening ); -} - -static void pointcloud_clear_async(void *_, u32 __) -{ - pointcloud.count = 0; - pointcloud_animate( k_pointcloud_anim_opening ); -} - -static void skateshop_world_preview_loader_thread( void *_data ) -{ - addon_reg *reg = _data; - - char path_buf[4096]; - vg_str path; - vg_strnull( &path, path_buf, 4096 ); - addon_get_content_folder( reg, &path ); - vg_strcat( &path, "/preview.bin" ); - - vg_linear_clear(vg_mem.scratch); - u32 size; - - void *data = vg_file_read( vg_mem.scratch, path_buf, &size ); - if( data ){ - if( size < sizeof(pointcloud_buffer) ){ - vg_async_call( pointcloud_clear_async, NULL, 0 ); - return; - } - - vg_async_item *call = vg_async_alloc(size); - pointcloud_buffer *pcbuf = call->payload; - memcpy( pcbuf, data, size ); - - u32 point_count = (size-sizeof(pointcloud_buffer)) / - sizeof(struct pointcloud_vert); - pcbuf->max = point_count; - pcbuf->count = point_count; - pcbuf->op = k_pointcloud_op_clear; - - vg_async_dispatch( call, async_pointcloud_sub ); - vg_async_call( pointcloud_async_end, NULL, 0 ); - } - else{ - vg_async_call( pointcloud_clear_async, NULL, 0 ); - } -} - -static void skateshop_world_preview_loader_thread_and_end( void *_data ){ - skateshop_world_preview_loader_thread( _data ); -} - -static void skateshop_load_world_preview( addon_reg *reg ){ - vg_loader_start( skateshop_world_preview_loader_thread_and_end, reg ); -} - /* * VG event preupdate */ @@ -195,8 +232,7 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ v3f dir = {0.0f,-1.0f,0.0f}; mdl_transform_vector( &ref->transform, dir, dir ); - m3x3_mulv( localplayer.invbasis, dir, dir ); - player_vector_angles( world_static.focus_cam.angles, dir, 1.0f, 0.0f ); + v3_angles( dir, world_static.focus_cam.angles ); v3f lookat; if( shop->type == k_skateshop_type_boardshop || @@ -220,13 +256,8 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ if( shop->type == k_skateshop_type_boardshop ){ if( !vg_loader_availible() ) return; - gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" ); - gui_helper_action( button_display_string( k_srbind_mback ), "exit" ); - u16 cache_id = skateshop_selected_cache_id(); - if( cache_id ){ - gui_helper_action( button_display_string( k_srbind_maccept ), "pick" ); - } + global_skateshop.helper_pick->greyed = !cache_id; /* * Controls @@ -240,10 +271,9 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ } } + u32 valid_count = addon_count( k_addon_type_board, 0 ); if( button_down( k_srbind_mright ) ){ - if( global_skateshop.selected_board_id+1 < - addon_count(k_addon_type_board) ) - { + if( global_skateshop.selected_board_id+1 < valid_count ){ global_skateshop.selected_board_id ++; } } @@ -252,7 +282,6 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ if( opage != npage ){ skateshop_update_viewpage(); - //skateshop_op_processview(); } else if( cache_id && button_down( k_srbind_maccept )){ vg_info( "chose board from skateshop (%u)\n", @@ -264,6 +293,7 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ network_send_item( k_netmsg_playeritem_board ); world_entity_unfocus(); + gui_helper_clear(); skaterift_autosave(1); return; } @@ -271,27 +301,22 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ else if( shop->type == k_skateshop_type_charshop ){ if( !vg_loader_availible() ) return; - gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" ); - gui_helper_action( button_display_string( k_srbind_mback ), "exit" ); - gui_helper_action( button_display_string( k_srbind_maccept ), "pick" ); - int changed = 0; + u32 valid_count = addon_count( k_addon_type_player, ADDON_REG_HIDDEN ); if( button_down( k_srbind_mleft ) ){ if( global_skateshop.selected_player_id > 0 ){ global_skateshop.selected_player_id --; } else{ - global_skateshop.selected_player_id = - addon_count(k_addon_type_player) -1; + global_skateshop.selected_player_id = valid_count-1; } changed = 1; } if( button_down( k_srbind_mright ) ){ - if( global_skateshop.selected_player_id+1 < - addon_count(k_addon_type_player) ){ + if( global_skateshop.selected_player_id+1 < valid_count ){ global_skateshop.selected_player_id ++; } else{ @@ -302,32 +327,40 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ } if( changed ){ - player__use_model( global_skateshop.selected_player_id ); - //skateshop_op_processview(); + addon_reg *addon = get_addon_from_index( + k_addon_type_player, global_skateshop.selected_player_id, + ADDON_REG_HIDDEN ); + + u32 real_id = get_index_from_addon( + k_addon_type_player, addon ); + + player__use_model( real_id ); } if( button_down( k_srbind_maccept ) ){ network_send_item( k_netmsg_playeritem_player ); world_entity_unfocus(); + gui_helper_clear(); } } else if( shop->type == k_skateshop_type_worldshop ){ int browseable = 0, loadable = 0; - if( addon_count(k_addon_type_world) && vg_loader_availible() ){ - gui_helper_action( axis_display_string(k_sraxis_mbrowse_h), "browse" ); + u32 valid_count = addon_count( k_addon_type_world, ADDON_REG_HIDDEN ); + + if( valid_count && vg_loader_availible() ) browseable = 1; - } - if( vg_loader_availible() && global_skateshop.selected_world_id > 0 ){ - gui_helper_action( button_display_string(k_srbind_maccept), - "open rift" ); + if( vg_loader_availible() ) loadable = 1; - } + + global_skateshop.helper_browse->greyed = !browseable; + global_skateshop.helper_pick->greyed = !loadable; - int change = 0; + addon_reg *selected_world = NULL; + int change = 0; if( browseable ){ if( button_down( k_srbind_mleft ) ){ if( global_skateshop.selected_world_id > 0 ){ @@ -337,50 +370,25 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ } if( button_down( k_srbind_mright ) ){ - if( global_skateshop.selected_world_id+1 < - addon_count(k_addon_type_world) ) - { + if( global_skateshop.selected_world_id+1 < valid_count ){ global_skateshop.selected_world_id ++; change = 1; } } - } - - if( change && pointcloud_idle() ){ - pointcloud_animate( k_pointcloud_anim_hiding ); - } - if( vg_loader_availible() ){ - addon_reg *reg = get_addon_from_index( k_addon_type_world, - global_skateshop.selected_world_id ); + selected_world = get_addon_from_index( k_addon_type_world, + global_skateshop.selected_world_id, ADDON_REG_HIDDEN ); - /* automatically load in clouds */ - if( loadable && button_down( k_srbind_maccept ) ){ - vg_info( "Select rift (%u)\n", - global_skateshop.selected_world_id ); - skaterift_change_world_start( reg ); - return; + if( change || (global_skateshop.reg_preview == NULL) ){ + SDL_AtomicLock( &addon_system.sl_cache_using_resources ); + global_skateshop.reg_preview = selected_world; + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); } - else{ - if( pointcloud.anim == k_pointcloud_anim_idle_closed ){ - if( global_skateshop.pointcloud_world_id != - global_skateshop.selected_world_id ) - { - global_skateshop.pointcloud_world_id = - global_skateshop.selected_world_id; - skateshop_load_world_preview( reg ); - } - else{ - pointcloud_animate( k_pointcloud_anim_opening ); - } - } - else if( pointcloud.anim == k_pointcloud_anim_idle_open ){ - if( global_skateshop.pointcloud_world_id != - global_skateshop.selected_world_id ) - { - pointcloud_animate( k_pointcloud_anim_hiding ); - } - } + } + + if( loadable ){ + if( button_down( k_srbind_maccept ) ){ + skaterift_change_world_start( selected_world ); } } } @@ -393,6 +401,7 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ network_send_item( k_netmsg_playeritem_player ); world_entity_unfocus(); + gui_helper_clear(); return; } } @@ -482,14 +491,14 @@ fade_out:; mlocal[3][2] = -0.7f; m4x3_mul( mrack, mlocal, mmdl ); - if( addon_count(k_addon_type_board) ){ + u32 valid_count = addon_count(k_addon_type_board,0); + if( valid_count ){ char buf[16]; - int i=0; - i+=highscore_intl( buf+i, global_skateshop.selected_board_id+1, 3 ); - buf[i++] = '/'; - i+=highscore_intl( buf+i, addon_count(k_addon_type_board), 3 ); - buf[i++] = '\0'; - + vg_str str; + vg_strnull( &str, buf, sizeof(buf) ); + vg_strcati32( &str, global_skateshop.selected_board_id+1 ); + vg_strcatch( &str, '/' ); + vg_strcati32( &str, valid_count ); font3d_simple_draw( 0, buf, &skaterift.cam, mmdl ); } else{ @@ -566,12 +575,13 @@ static void skateshop_render_worldshop( ent_skateshop *shop ){ mdl_entity_id_id(shop->boards.id_info)); if( global_skateshop.render.world_reg != global_skateshop.selected_world_id){ - global_skateshop.render.world_title = ""; + global_skateshop.render.world_title = "missing: workshop.title"; addon_reg *reg = get_addon_from_index( k_addon_type_world, - global_skateshop.selected_world_id ); + global_skateshop.selected_world_id, ADDON_REG_HIDDEN ); vg_msg msg; vg_msg_init( &msg, reg->metadata, reg->metadata_len ); + global_skateshop.render.world_loc = vg_msg_getkvstr( &msg, "location" ); global_skateshop.render.world_reg = global_skateshop.selected_world_id; @@ -579,6 +589,9 @@ static void skateshop_render_worldshop( ent_skateshop *shop ){ global_skateshop.render.world_title = vg_msg_getkvstr( &msg, "title"); vg_msg_skip_frame( &msg ); } + else { + vg_warn( "No workshop body\n" ); + } } /* Text */ @@ -587,25 +600,20 @@ static void skateshop_render_worldshop( ent_skateshop *shop ){ vg_strnull( &info, buftext, 128 ); vg_strnull( &subtext, bufsubtext, 128 ); - if( addon_count(k_addon_type_world) ){ - addon_reg *reg = get_addon_from_index( k_addon_type_world, - global_skateshop.selected_world_id ); - - info.i+=highscore_intl( info.buffer+info.i, - global_skateshop.selected_world_id+1, 3 ); - info.buffer[info.i++] = '/'; - info.i+=highscore_intl( info.buffer+info.i, - addon_count(k_addon_type_world), 3 ); - info.buffer[info.i++] = ' '; - info.buffer[info.i] = '\0'; - + u32 valid_count = addon_count(k_addon_type_world,ADDON_REG_HIDDEN); + if( valid_count ){ + vg_strcati32( &info, global_skateshop.selected_world_id+1 ); + vg_strcatch( &info, '/' ); + vg_strcati32( &info, valid_count ); + vg_strcatch( &info, ' ' ); vg_strcat( &info, global_skateshop.render.world_title ); + if( !vg_loader_availible() ){ vg_strcat( &subtext, "Loading..." ); } else{ addon_reg *reg = get_addon_from_index( k_addon_type_world, - global_skateshop.selected_world_id ); + global_skateshop.selected_world_id, ADDON_REG_HIDDEN ); if( reg->alias.workshop_id ) vg_strcat( &subtext, "(Workshop) " ); @@ -614,10 +622,9 @@ static void skateshop_render_worldshop( ent_skateshop *shop ){ } } else{ - vg_strcat( &info, "No worlds installed" ); + vg_strcat( &info, "No workshop worlds installed" ); } - m4x3f mtext,mlocal,mtextmdl; mdl_transform_m4x3( &mark_info->transform, mtext ); @@ -641,6 +648,7 @@ static void skateshop_render_worldshop( ent_skateshop *shop ){ m4x3_mul( mtext, mlocal, mtextmdl ); font3d_simple_draw( 0, bufsubtext, &skaterift.cam, mtextmdl ); +#if 0 /* pointcloud */ m4x3f mmdl; mdl_transform_m4x3( &mark_display->transform, mmdl ); @@ -652,6 +660,7 @@ static void skateshop_render_worldshop( ent_skateshop *shop ){ pointcloud_render( world, &skaterift.cam, mmdl ); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); +#endif } /* @@ -668,6 +677,23 @@ static void skateshop_render( ent_skateshop *shop ){ vg_fatal_error( "Unknown store (%u)\n", shop->type ); } +static void ent_skateshop_helpers_pickable( const char *acceptance ){ + vg_str text; + + if( gui_new_helper( input_button_list[k_srbind_mback], &text )) + vg_strcat( &text, "exit" ); + + if( (global_skateshop.helper_pick = gui_new_helper( + input_button_list[k_srbind_maccept], &text))){ + vg_strcat( &text, acceptance ); + } + + if( (global_skateshop.helper_browse = gui_new_helper( + input_axis_list[k_sraxis_mbrowse_h], &text ))){ + vg_strcat( &text, "browse" ); + } +} + /* * Entity logic: entrance event */ @@ -685,26 +711,18 @@ static void ent_skateshop_call( world_instance *world, ent_call *call ){ vg_info( "Entering skateshop\n" ); world_entity_focus( call->id ); -#if 0 - localplayer.immobile = 1; - menu.disable_open = 1; - skaterift.activity = k_skaterift_skateshop; - - v3_zero( localplayer.rb.v ); - v3_zero( localplayer.rb.w ); - localplayer._walk.move_speed = 0.0f; - global_skateshop.ptr_ent = shop; -#endif + gui_helper_clear(); if( shop->type == k_skateshop_type_boardshop ){ skateshop_update_viewpage(); skateshop_op_board_scan(); + ent_skateshop_helpers_pickable( "pick" ); } else if( shop->type == k_skateshop_type_charshop ){ - + ent_skateshop_helpers_pickable( "pick" ); } else if( shop->type == k_skateshop_type_worldshop ){ - pointcloud_animate( k_pointcloud_anim_opening ); + ent_skateshop_helpers_pickable( "open rift" ); skateshop_op_world_scan(); } }