#include "world.h"
#include "player.h"
#include "gui.h"
+#include "menu.h"
+#include "pointcloud.h"
/*
* Checks string equality but does a hash check first
/* generic reciever */
VG_STATIC void workshop_async_any_complete( void *data, u32 size )
{
- workshop_end_op();
+ skaterift_end_op();
}
/*
global_skateshop.registry_count = global_skateshop.t1_registry_count;
}
-/*
- * 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_STATIC void workshop_steam_scan(void)
{
- vg_linear_clear( vg_mem.scratch );
-
- for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
- struct registry_board *reg = &global_skateshop.registry[i];
- reg->state = k_registry_board_state_indexed_absent;
- }
-
- /*
- * 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; i<global_skateshop.t1_registry_count; i++ ){
- struct registry_board *reg = &global_skateshop.registry[i];
-
- if( const_str_eq( hash, file.name, reg->filename ) ){
- 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 );
- vg_strncpy( file.name, reg->workshop.title,
- 64, k_strncpy_always_add_null );
- reg->filename_hash = hash;
- reg->workshop_id = 0;
- reg->state = k_registry_board_state_indexed;
- reg->workshop.author = 0;
- strcpy( reg->workshop.author_name, "custom" );
- }
-
-next_file: tinydir_next( &dir );
- }
-
- tinydir_close(&dir);
-
/*
* Steam workshop scan
*/
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; i<global_skateshop.t1_registry_count; i++ ){
+ struct registry_board *reg = &global_skateshop.registry[i];
+ reg->state = k_registry_board_state_indexed_absent;
+ }
+
+ /*
+ * 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; i<global_skateshop.t1_registry_count; i++ ){
+ struct registry_board *reg = &global_skateshop.registry[i];
+
+ if( const_str_eq( hash, file.name, reg->filename ) ){
+ 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 );
+ vg_strncpy( file.name, reg->workshop.title,
+ 64, k_strncpy_always_add_null );
+ reg->filename_hash = hash;
+ reg->workshop_id = 0;
+ reg->state = k_registry_board_state_indexed;
+ reg->workshop.author = 0;
+ strcpy( reg->workshop.author_name, "custom" );
+ }
+
+next_file: tinydir_next( &dir );
+ }
+
+ tinydir_close(&dir);
+
+ if( steam_ready ) workshop_steam_scan();
vg_async_call( workshop_async_reg_update, NULL, 0 );
vg_async_stall();
*/
VG_STATIC void workshop_op_item_scan(void)
{
- workshop_begin_op( k_workshop_op_item_scan );
+ skaterift_begin_op( k_workshop_op_item_scan );
vg_loader_start( workshop_scan_thread, NULL );
}
/*
* 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 );
world_instance *world = get_active_world();
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]) );
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( selected_cache && button_down( k_srbind_maccept ) ){
- vg_info( "chose board from skateshop (%u)\n",
- global_skateshop.selected_registry_id );
+ 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( localplayer.board_view_slot ){
- unwatch_cache_board( localplayer.board_view_slot );
+ if( button_down( k_srbind_maccept ) ){
+ global_skateshop_exit();
}
+ }
+ else if( shop->type == k_skateshop_type_worldshop ){
+ gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" );
- localplayer.board_view_slot = selected_cache;
- watch_cache_board( localplayer.board_view_slot );
+ v2f input;
+ joystick_state( k_srjoystick_steer, input );
+ pointcloud.control[0] += input[0] * vg.time_delta;
+ pointcloud.control[2] += input[1] * vg.time_delta;
- global_skateshop_exit();
- return;
+ 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_press( k_srbind_trick1 ) ){
+ pointcloud.control[3] += vg.time_delta*0.2f;
+ }
+ 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 );
}
if( button_down( k_srbind_mback ) ){
}
}
-/*
- * World: render event
- */
-VG_STATIC void skateshop_render(void)
+VG_STATIC void skateshop_render_boardshop(void)
{
- if( !global_skateshop.active ) return;
-
- ent_skateshop *shop = global_skateshop.ptr_ent;
world_instance *world = get_active_world();
+ 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,
- 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 );
}
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 );
info->author_name, &main_camera, mmdl );
}
+VG_STATIC void skateshop_render_charshop(void)
+{
+}
+
+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];
+
+ 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];
+
+ m4x3f mlocal, mx;
+ m4x3_identity( mlocal );
+
+ 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
+
+ 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);
+}
+
+/*
+ * 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 );
+ }
+}
+
/*
* Entity logic: entrance event
*/
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;
vg_info( "Entering skateshop\n" );
localplayer.immobile = 1;
+ menu.disable_open = 1;
global_skateshop.active = 1;
v3_zero( localplayer.rb.v );
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();
+ }
}
}
vg_info( "exit skateshop\n" );
localplayer.immobile = 0;
global_skateshop.active = 0;
+ menu.disable_open = 0;
srinput.ignore_input_frames = 2;
}