X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=ent_skateshop.c;h=a3e12dca52986e6b39c14c12b97e75f759321348;hb=63b5ac44f74599b21c4b9b18398c29b797337bea;hp=40362219b37b9d8ae1c6479c7ebad3b6077cd469;hpb=38e07d851915d4ea3d25eeb28a3ace78fb0d1c12;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/ent_skateshop.c b/ent_skateshop.c index 4036221..a3e12dc 100644 --- a/ent_skateshop.c +++ b/ent_skateshop.c @@ -353,6 +353,147 @@ VG_STATIC void workshop_op_item_scan(void) vg_loader_start( workshop_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; + 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; +} + +/* + * 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 ) ) break; + + 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 worlds + */ +VG_STATIC void skateshop_op_world_scan(void) +{ + skaterift_begin_op( k_async_op_world_scan ); + vg_loader_start( world_scan_thread, NULL ); +} + /* * Regular stuff * ----------------------------------------------------------------------------- @@ -408,10 +549,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 ); @@ -573,23 +716,36 @@ VG_STATIC void global_skateshop_preupdate(void) } } else if( shop->type == k_skateshop_type_worldshop ){ - gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" ); - - v2f input; - joystick_state( k_srjoystick_steer, input ); - pointcloud.control[0] += input[0] * vg.time_delta; - pointcloud.control[2] += input[1] * vg.time_delta; + if( global_skateshop.world_registry_count ){ + gui_helper_action( axis_display_string(k_sraxis_mbrowse_h), "browse" ); + } + + int change = 0; + if( button_down( k_srbind_mleft ) ){ + if( global_skateshop.selected_world_id > 0 ){ + global_skateshop.selected_world_id --; + change = 1; + } + } - pointcloud.control[0] = vg_clampf( pointcloud.control[0], -10.0f, 10.0f ); - pointcloud.control[2] = vg_clampf( pointcloud.control[2], -10.0f, 10.0f ); + if( 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.anim == k_pointcloud_anim_idle) ){ + pointcloud.anim = k_pointcloud_anim_hiding; + pointcloud.anim_start = vg.time; + } - if( button_press( k_srbind_trick1 ) ){ - pointcloud.control[3] += vg.time_delta*0.2f; + if( button_down( k_srbind_maccept ) ){ + vg_info( "Select world (%u)\n", global_skateshop.selected_world_id ); + global_skateshop_exit(); + return; } - if( button_press( k_srbind_trick0 ) ){ - pointcloud.control[3] -= vg.time_delta*0.2f; -} - pointcloud.control[3] = vg_clampf( pointcloud.control[3], 0.001f, 10.0f ); } else{ vg_fatal_error( "Unknown store (%u)\n", shop->type ); @@ -718,6 +874,7 @@ fade_out:; mlocal[3][0] = -font3d_string_width( &world_global.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 ); @@ -729,6 +886,7 @@ fade_out:; 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 ); @@ -742,50 +900,74 @@ VG_STATIC void skateshop_render_worldshop(void) { world_instance *world = get_active_world(); - m4x3f mmdl; ent_skateshop *shop = global_skateshop.ptr_ent; ent_marker *mark_display = mdl_arritm( &world->ent_marker, - mdl_entity_id_id(shop->worlds.id_display)); - mdl_transform_m4x3( &mark_display->transform, mmdl ); - - /* TODO? ... */ -#if 0 - v3f vol; - v3_sub( world->scene_geo.bbx[1], world->scene_geo.bbx[0], vol ); - - v2f rect = { 1.0f, 1.0f }, - map = { vol[0], vol[2] }, - result; - - f32 rp = rect[0] * map[1], - rc = rect[1] * map[0]; + 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 ); - u32 axis, other; - if( rc > rp ) axis = 0; - else axis = 1; - other = axis ^ 0x1; - - result[axis] = rect[axis]; - result[other] = (rect[axis] * map[other]) / map[axis]; + 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'; + + if( rw->meta_present ){ + vg_fatal_error(""); + } + else{ + vg_strcat( &info, rw->foldername ); + vg_strcat( &subtext, "No information" ); + } + } + else{ + vg_strcat( &info, "No worlds installed" ); + } - m4x3f mlocal, mx; - m4x3_identity( mlocal ); + m4x3f mtext,mlocal,mtextmdl; + mdl_transform_m4x3( &mark_info->transform, mtext ); - mlocal[0][0] = result[0]; - mlocal[2][2] = result[1]; - mlocal[1][1] = (vol[1]/vol[0]) * mlocal[0][0]; - mlocal[3][0] = (rect[0]-result[0])*0.5f - rect[0]*0.5f; /* sea level? */ - mlocal[3][2] = (rect[1]-result[1])*0.5f - rect[1]*0.5f; - m4x3_mul( mmdl, mlocal, mx ); -#endif + font3d_bind( &world_global.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( &world_global.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( &world_global.font, 0, buftext, &main_camera, mtextmdl ); + + m3x3_setdiagonalv3( mlocal, (v3f){ scale1, scale1, thickness } ); + mlocal[3][0] = -font3d_string_width( &world_global.font, 0, bufsubtext ); + mlocal[3][0] *= scale1*0.5f; + mlocal[3][1] = -scale1*0.3f; + m4x3_mul( mtext, mlocal, mtextmdl ); + font3d_simple_draw( &world_global.font, 0, bufsubtext, + &main_camera, mtextmdl ); + + /* pointcloud */ + m4x3f mmdl; + mdl_transform_m4x3( &mark_display->transform, mmdl ); m4x3_rotate_y( mmdl, vg.time * 0.2 ); -#if 1 glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glDisable(GL_DEPTH_TEST); -#endif pointcloud_render( world, &main_camera, mmdl ); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); @@ -846,6 +1028,11 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call ) skateshop_update_viewpage(); workshop_op_item_scan(); } + else if( shop->type == k_skateshop_type_worldshop ){ + pointcloud.anim = k_pointcloud_anim_opening; + pointcloud.anim_start = vg.time; + skateshop_op_world_scan(); + } } }