#include "steam.h"
#include "addon.h"
#include "save.h"
+#include "network.h"
/*
* Checks string equality but does a hash check first
return 0;
}
-VG_STATIC void skateshop_update_viewpage(void){
+static void skateshop_update_viewpage(void){
u32 page = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
for( u32 i=0; i<SKATESHOP_VIEW_SLOT_MAX; i++ ){
* -----------------------------------------------------------------------------
*/
-VG_STATIC void world_scan_thread( void *_args ){
+static void world_scan_thread( void *_args ){
addon_mount_content_folder( k_addon_type_world, "maps", ".mdl" );
addon_mount_workshop_items();
vg_async_call( async_addon_reg_update, NULL, 0 );
/*
* Asynchronous scan of local disk for worlds
*/
-VG_STATIC void skateshop_op_world_scan(void){
+static void skateshop_op_world_scan(void){
vg_loader_start( world_scan_thread, NULL );
}
-VG_STATIC void board_processview_thread( void *_args ){
+static void board_processview_thread( void *_args ){
addon_cache_load_loop();
}
-VG_STATIC void board_scan_thread( void *_args ){
+static void board_scan_thread( void *_args ){
addon_mount_content_folder( k_addon_type_board, "boards", ".mdl" );
addon_mount_workshop_items();
vg_async_call( async_addon_reg_update, NULL, 0 );
board_processview_thread(NULL);
}
-VG_STATIC void skateshop_op_board_scan(void){
+/* TODO: migrate to addon.c */
+static void skateshop_op_board_scan(void){
vg_loader_start( board_scan_thread, NULL );
}
-VG_STATIC void skateshop_op_processview(void){
+/* TODO: migrate to addon.c */
+static void skateshop_autostart_loading(void){
+ if( !vg_loader_availible() ) return;
+
+ SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+ for( u32 type=0; type<k_addon_type_max; type++ ){
+ struct addon_cache *cache = &addon_system.cache[type];
+
+ for( u32 id=1; id<=cache->pool.count; id++ ){
+ addon_cache_entry *entry = vg_pool_item( &cache->pool, id );
+ if( entry->state == k_addon_cache_state_load_request ){
+ SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
+ goto launch;
+ }
+ }
+ }
+ SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
+ return;
+launch:
vg_loader_start( board_processview_thread, NULL );
}
/*
* VG event init
*/
-VG_STATIC void skateshop_init(void){
+static void skateshop_init(void){
}
static u16 skateshop_selected_cache_id(void){
else return 0;
}
-VG_STATIC void pointcloud_async_end(void *_, u32 __)
+static void pointcloud_async_end(void *_, u32 __)
{
pointcloud_animate( k_pointcloud_anim_opening );
}
-VG_STATIC void pointcloud_clear_async(void *_, u32 __)
+static void pointcloud_clear_async(void *_, u32 __)
{
pointcloud.count = 0;
pointcloud_animate( k_pointcloud_anim_opening );
}
-VG_STATIC void skateshop_world_preview_loader_thread( void *_data )
+static void skateshop_world_preview_loader_thread( void *_data )
{
addon_reg *reg = _data;
}
}
-VG_STATIC void skateshop_world_preview_loader_thread_and_end( void *_data ){
+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 ){
+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;
+static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){
+ if( !active ) return;
+ /* 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,
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( opage != npage ){
skateshop_update_viewpage();
- skateshop_op_processview();
+ //skateshop_op_processview();
}
else if( cache_id && button_down( k_srbind_maccept )){
vg_info( "chose board from skateshop (%u)\n",
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;
+ network_send_item( k_netmsg_playeritem_board );
- global_skateshop_exit();
- skaterift_write_savedata();
+ world_entity_unfocus();
+ skaterift_autosave(1);
return;
}
}
}
if( changed ){
- player__use_model( &localplayer, global_skateshop.selected_player_id );
- skateshop_op_processview();
+ player__use_model( global_skateshop.selected_player_id );
+ //skateshop_op_processview();
}
if( button_down( k_srbind_maccept ) ){
- global_skateshop_exit();
+ network_send_item( k_netmsg_playeritem_player );
+ world_entity_unfocus();
}
}
else if( shop->type == k_skateshop_type_worldshop ){
if( browseable ){
if( button_down( k_srbind_mleft ) ){
- if( global_skateshop.selected_world_id > 0 )
- {
+ if( global_skateshop.selected_world_id > 0 ){
global_skateshop.selected_world_id --;
change = 1;
}
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{
}
if( button_down( k_srbind_mback ) ){
- global_skateshop_exit();
+ if( shop->type == k_skateshop_type_charshop )
+ network_send_item( k_netmsg_playeritem_player );
+
+ world_entity_unfocus();
return;
}
}
-VG_STATIC void skateshop_render_boardshop(void)
-{
+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,
q_nlerp( xform.q, mark_display->transform.q, t, xform.q );
v3_lerp( xform.s, mark_display->transform.s, t, xform.s );
- struct board_pose pose = {0};
+ struct player_board_pose pose = {0};
m4x3f mmdl;
mdl_transform_m4x3( &xform, mmdl );
- render_board( &main_camera, world, board, mmdl,
+ render_board( &skaterift.cam, world, board, mmdl,
&pose, k_board_shader_entity );
fade_out:;
float scale = 0.2f,
thickness = 0.03f;
- font3d_bind( &gui.font, &main_camera );
+ font3d_bind( &gui.font, k_font_shader_default, 0, world, &skaterift.cam );
shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
/* Selection counter
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( 0, buf, &skaterift.cam, mmdl );
}
else{
- font3d_simple_draw( &gui.font, 0,
- "Nothing installed", &main_camera, mmdl );
+ font3d_simple_draw( 0, "Nothing installed", &skaterift.cam, mmdl );
}
u16 cache_id = skateshop_selected_cache_id();
if( global_skateshop.render.reg_id != global_skateshop.selected_board_id ){
global_skateshop.render.item_title = "";
global_skateshop.render.item_desc = "";
- 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 ) ){
- const char *title = vg_msg_seekkvstr( &workshop, "title", 0 );
+ vg_msg msg;
+ vg_msg_init( &msg, reg->metadata, reg->metadata_len );
+
+ if( vg_msg_seekframe( &msg, "workshop" ) ){
+ const char *title = vg_msg_getkvstr( &msg, "title" );
if( title ) global_skateshop.render.item_title = title;
- const char *dsc = vg_msg_seekkvstr( &workshop, "author", 0 );
+ const char *dsc = vg_msg_getkvstr( &msg, "author" );
if( dsc ) global_skateshop.render.item_desc = dsc;
+ vg_msg_skip_frame( &msg );
}
global_skateshop.render.reg_id = global_skateshop.selected_board_id;
* ----------------------------------------------------------------- */
m3x3_zero( mlocal );
m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
- mlocal[3][0] = -font3d_string_width( &gui.font, 0,
- global_skateshop.render.item_title );
+ mlocal[3][0] = -font3d_string_width( 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, global_skateshop.render.item_title,
- &main_camera, mmdl );
+ font3d_simple_draw( 0, global_skateshop.render.item_title,
+ &skaterift.cam, mmdl );
/* Author name
* ----------------------------------------------------------------- */
scale *= 0.4f;
m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
- mlocal[3][0] = -font3d_string_width( &gui.font, 0,
- global_skateshop.render.item_desc );
+ mlocal[3][0] = -font3d_string_width( 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, global_skateshop.render.item_desc,
- &main_camera, mmdl );
+ font3d_simple_draw( 0, global_skateshop.render.item_desc,
+ &skaterift.cam, mmdl );
SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
}
-VG_STATIC void skateshop_render_charshop(void)
-{
+static void skateshop_render_charshop( ent_skateshop *shop ){
}
-VG_STATIC void skateshop_render_worldshop(void)
-{
+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,
addon_reg *reg = get_addon_from_index( k_addon_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);
+ 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;
+
+ if( vg_msg_seekframe( &msg, "workshop" ) ){
+ global_skateshop.render.world_title = vg_msg_getkvstr( &msg, "title");
+ vg_msg_skip_frame( &msg );
+ }
}
/* Text */
m4x3f mtext,mlocal,mtextmdl;
mdl_transform_m4x3( &mark_info->transform, mtext );
- font3d_bind( &gui.font, &main_camera );
+ font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &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;
m3x3_zero( mlocal );
m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
- mlocal[3][0] = -font3d_string_width( &gui.font, 0, buftext );
+ mlocal[3][0] = -font3d_string_width( 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( &gui.font, 0, buftext, &main_camera, mtextmdl );
+ font3d_simple_draw( 0, buftext, &skaterift.cam, mtextmdl );
m3x3_setdiagonalv3( mlocal, (v3f){ scale1, scale1, thickness } );
- mlocal[3][0] = -font3d_string_width( &gui.font, 0, bufsubtext );
+ mlocal[3][0] = -font3d_string_width( 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( 0, bufsubtext, &skaterift.cam, mtextmdl );
/* pointcloud */
m4x3f mmdl;
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);
}
/*
* 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{
+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 )
-{
+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.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();
}
}
-/*
- * 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 */