1 #include "vg/vg_steam_ugc.h"
4 #include "vg/vg_image.h"
5 #include "vg/vg_loader.h"
6 #include "ent_skateshop.h"
16 struct global_skateshop global_skateshop
=
18 .render
={.reg_id
=0xffffffff,.world_reg
=0xffffffff}
22 * Checks string equality but does a hash check first
24 static inline int const_str_eq( u32 hash
, const char *str
, const char *cmp
)
26 if( hash
== vg_strdjb2(cmp
) )
27 if( !strcmp( str
, cmp
) )
32 static void skateshop_update_viewpage(void){
33 u32 page
= global_skateshop
.selected_board_id
/SKATESHOP_VIEW_SLOT_MAX
;
35 for( u32 i
=0; i
<SKATESHOP_VIEW_SLOT_MAX
; i
++ ){
36 u32 j
= SKATESHOP_VIEW_SLOT_MAX
-1-i
;
37 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[j
];
38 addon_cache_unwatch( k_addon_type_board
, slot
->cache_id
);
41 for( u32 i
=0; i
<SKATESHOP_VIEW_SLOT_MAX
; i
++ ){
42 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[i
];
43 u32 request_id
= page
*SKATESHOP_VIEW_SLOT_MAX
+ i
;
44 slot
->cache_id
= addon_cache_create_viewer( k_addon_type_board
,
49 struct async_preview_load_thread_data
{
54 static void skateshop_async_preview_imageload( void *data
, u32 len
){
55 struct async_preview_load_thread_data
*inf
= data
;
58 glBindTexture( GL_TEXTURE_2D
, global_skateshop
.tex_preview
);
59 glTexSubImage2D( GL_TEXTURE_2D
, 0,0,0,
60 WORKSHOP_PREVIEW_WIDTH
, WORKSHOP_PREVIEW_HEIGHT
,
61 GL_RGB
, GL_UNSIGNED_BYTE
, inf
->data
);
62 glGenerateMipmap( GL_TEXTURE_2D
);
63 stbi_image_free( inf
->data
);
65 skaterift
.rt_textures
[k_skaterift_rt_workshop_preview
] =
66 global_skateshop
.tex_preview
;
69 skaterift
.rt_textures
[k_skaterift_rt_workshop_preview
] = vg
.tex_missing
;
72 SDL_AtomicLock( &addon_system
.sl_cache_using_resources
);
73 global_skateshop
.reg_loaded_preview
= inf
->reg
;
74 SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
77 static void skateshop_update_preview_image_thread(void *_args
)
81 vg_strnull( &folder
, path_buf
, sizeof(path_buf
) );
83 SDL_AtomicLock( &addon_system
.sl_cache_using_resources
);
84 addon_reg
*reg_preview
= global_skateshop
.reg_preview
;
85 SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
87 if( !addon_get_content_folder( reg_preview
, &folder
, 1 ) )
89 SDL_AtomicLock( &addon_system
.sl_cache_using_resources
);
90 global_skateshop
.reg_loaded_preview
= reg_preview
;
91 SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
95 vg_strcat( &folder
, "/preview.jpg" );
97 vg_async_alloc( sizeof(struct async_preview_load_thread_data
) );
98 struct async_preview_load_thread_data
*inf
= call
->payload
;
100 inf
->reg
= reg_preview
;
102 if( vg_strgood( &folder
) )
104 stbi_set_flip_vertically_on_load(1);
106 inf
->data
= stbi_load( folder
.buffer
, &x
, &y
, &nc
, 3 );
110 if( (x
!= WORKSHOP_PREVIEW_WIDTH
) || (y
!= WORKSHOP_PREVIEW_HEIGHT
) )
112 vg_error( "Resolution does not match framebuffer, so we can't"
114 stbi_image_free( inf
->data
);
119 vg_async_dispatch( call
, skateshop_async_preview_imageload
);
123 vg_error( "Path too long to workshop preview image.\n" );
125 SDL_AtomicLock( &addon_system
.sl_cache_using_resources
);
126 global_skateshop
.reg_loaded_preview
= reg_preview
;
127 SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
131 void skateshop_world_preview_preupdate(void)
133 /* try to load preview image if we availible to do. */
134 if( vg_loader_availible() )
136 SDL_AtomicLock( &addon_system
.sl_cache_using_resources
);
137 if( global_skateshop
.reg_preview
!= global_skateshop
.reg_loaded_preview
)
139 SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
140 vg_loader_start( skateshop_update_preview_image_thread
, NULL
);
142 else SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
147 * op/subroutine: k_workshop_op_item_load
148 * -----------------------------------------------------------------------------
153 * -----------------------------------------------------------------------------
156 static void skateshop_init_async(void *_data
,u32 size
){
157 glGenTextures( 1, &global_skateshop
.tex_preview
);
158 glBindTexture( GL_TEXTURE_2D
, global_skateshop
.tex_preview
);
159 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGB
,
160 WORKSHOP_PREVIEW_WIDTH
, WORKSHOP_PREVIEW_HEIGHT
,
161 0, GL_RGB
, GL_UNSIGNED_BYTE
, NULL
);
163 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
164 GL_LINEAR_MIPMAP_LINEAR
);
165 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
166 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
167 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
169 skaterift
.rt_textures
[ k_skaterift_rt_workshop_preview
] = vg
.tex_missing
;
170 skaterift
.rt_textures
[ k_skaterift_rt_server_status
] = vg
.tex_missing
;
171 render_server_status_gui();
177 void skateshop_init(void)
179 vg_async_call( skateshop_init_async
, NULL
, 0 );
182 static u16
skateshop_selected_cache_id(void){
183 if( addon_count(k_addon_type_board
, ADDON_REG_HIDDEN
) ){
184 addon_reg
*reg
= get_addon_from_index(
185 k_addon_type_board
, global_skateshop
.selected_board_id
,
187 return reg
->cache_id
;
192 static void skateshop_server_helper_update(void){
194 vg_strnull( &text
, global_skateshop
.helper_toggle
->text
,
195 sizeof(global_skateshop
.helper_toggle
->text
) );
197 if( skaterift
.demo_mode
){
198 vg_strcat( &text
, "Not availible in demo" );
201 if( network_client
.user_intent
== k_server_intent_online
)
202 vg_strcat( &text
, "Disconnect" );
204 vg_strcat( &text
, "Go Online" );
211 void temp_update_playermodel(void);
212 void ent_skateshop_preupdate( ent_skateshop
*shop
, int active
)
214 if( !active
) return;
217 world_instance
*world
= world_current_instance();
219 /* camera positioning */
220 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
221 mdl_entity_id_id(shop
->id_camera
) );
223 v3f dir
= {0.0f
,-1.0f
,0.0f
};
224 mdl_transform_vector( &ref
->transform
, dir
, dir
);
225 v3_angles( dir
, world_static
.focus_cam
.angles
);
228 if( shop
->type
== k_skateshop_type_boardshop
||
229 shop
->type
== k_skateshop_type_worldshop
){
230 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
231 mdl_entity_id_id(shop
->boards
.id_display
) );
232 v3_sub( display
->transform
.co
, localplayer
.rb
.co
, lookat
);
234 else if( shop
->type
== k_skateshop_type_charshop
){
235 v3_sub( ref
->transform
.co
, localplayer
.rb
.co
, lookat
);
237 else if( shop
->type
== k_skateshop_type_server
){
238 ent_prop
*prop
= mdl_arritm( &world
->ent_prop
,
239 mdl_entity_id_id(shop
->server
.id_lever
) );
240 v3_sub( prop
->transform
.co
, localplayer
.rb
.co
, lookat
);
243 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
245 q_axis_angle( localplayer
.rb
.q
, (v3f
){0.0f
,1.0f
,0.0f
},
246 atan2f(lookat
[0],lookat
[2]) );
248 v3_copy( ref
->transform
.co
, world_static
.focus_cam
.pos
);
249 world_static
.focus_cam
.fov
= ref
->fov
;
252 if( shop
->type
== k_skateshop_type_boardshop
){
253 if( !vg_loader_availible() ) return;
255 u16 cache_id
= skateshop_selected_cache_id();
256 global_skateshop
.helper_pick
->greyed
= !cache_id
;
260 * ----------------------
262 u32 opage
= global_skateshop
.selected_board_id
/SKATESHOP_VIEW_SLOT_MAX
;
264 if( button_down( k_srbind_mleft
) ){
265 if( global_skateshop
.selected_board_id
> 0 ){
266 global_skateshop
.selected_board_id
--;
270 u32 valid_count
= addon_count( k_addon_type_board
, 0 );
271 if( button_down( k_srbind_mright
) ){
272 if( global_skateshop
.selected_board_id
+1 < valid_count
){
273 global_skateshop
.selected_board_id
++;
277 u32 npage
= global_skateshop
.selected_board_id
/SKATESHOP_VIEW_SLOT_MAX
;
279 if( opage
!= npage
){
280 skateshop_update_viewpage();
282 else if( cache_id
&& button_down( k_srbind_maccept
)){
283 vg_info( "chose board from skateshop (%u)\n",
284 global_skateshop
.selected_board_id
);
286 addon_cache_unwatch( k_addon_type_board
, localplayer
.board_view_slot
);
287 addon_cache_watch( k_addon_type_board
, cache_id
);
288 localplayer
.board_view_slot
= cache_id
;
289 network_send_item( k_netmsg_playeritem_board
);
291 world_entity_exit_modal();
292 world_entity_clear_focus();
294 skaterift_autosave(1);
298 else if( shop
->type
== k_skateshop_type_charshop
){
299 if( !vg_loader_availible() ) return;
302 u32 valid_count
= addon_count( k_addon_type_player
, ADDON_REG_HIDDEN
);
304 if( button_down( k_srbind_mleft
) ){
305 if( global_skateshop
.selected_player_id
> 0 ){
306 global_skateshop
.selected_player_id
--;
309 global_skateshop
.selected_player_id
= valid_count
-1;
315 if( button_down( k_srbind_mright
) ){
316 if( global_skateshop
.selected_player_id
+1 < valid_count
){
317 global_skateshop
.selected_player_id
++;
320 global_skateshop
.selected_player_id
= 0;
327 addon_reg
*addon
= get_addon_from_index(
328 k_addon_type_player
, global_skateshop
.selected_player_id
,
331 u32 real_id
= get_index_from_addon(
332 k_addon_type_player
, addon
);
334 player__use_model( real_id
);
337 if( button_down( k_srbind_maccept
) ){
338 network_send_item( k_netmsg_playeritem_player
);
339 world_entity_exit_modal();
340 world_entity_clear_focus();
344 else if( shop
->type
== k_skateshop_type_worldshop
){
348 u32 valid_count
= addon_count( k_addon_type_world
, ADDON_REG_HIDDEN
);
350 if( valid_count
&& vg_loader_availible() )
353 if( valid_count
&& vg_loader_availible() )
356 global_skateshop
.helper_browse
->greyed
= !browseable
;
357 global_skateshop
.helper_pick
->greyed
= !loadable
;
359 addon_reg
*selected_world
= NULL
;
363 if( button_down( k_srbind_mleft
) ){
364 if( global_skateshop
.selected_world_id
> 0 ){
365 global_skateshop
.selected_world_id
--;
370 if( button_down( k_srbind_mright
) ){
371 if( global_skateshop
.selected_world_id
+1 < valid_count
){
372 global_skateshop
.selected_world_id
++;
377 selected_world
= get_addon_from_index( k_addon_type_world
,
378 global_skateshop
.selected_world_id
, ADDON_REG_HIDDEN
);
380 if( change
|| (global_skateshop
.reg_preview
== NULL
) ){
381 SDL_AtomicLock( &addon_system
.sl_cache_using_resources
);
382 global_skateshop
.reg_preview
= selected_world
;
383 SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
388 if( button_down( k_srbind_maccept
) ){
389 skaterift_change_world_start( selected_world
);
393 else if( shop
->type
== k_skateshop_type_server
){
394 f64 delta
= vg
.time_real
- network_client
.last_intent_change
;
396 if( (delta
> 5.0) && (!skaterift
.demo_mode
) ){
397 global_skateshop
.helper_pick
->greyed
= 0;
398 if( button_down( k_srbind_maccept
) ){
399 network_client
.user_intent
= !network_client
.user_intent
;
400 network_client
.last_intent_change
= vg
.time_real
;
401 skateshop_server_helper_update();
402 render_server_status_gui();
406 global_skateshop
.helper_pick
->greyed
= 1;
410 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
413 if( button_down( k_srbind_mback
) )
415 if( shop
->type
== k_skateshop_type_charshop
)
416 network_send_item( k_netmsg_playeritem_player
);
418 world_entity_exit_modal();
419 world_entity_clear_focus();
425 void skateshop_world_preupdate( world_instance
*world
)
427 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_skateshop
); i
++ ){
428 ent_skateshop
*shop
= mdl_arritm( &world
->ent_skateshop
, i
);
430 if( shop
->type
== k_skateshop_type_server
){
431 f32 a
= network_client
.user_intent
;
433 vg_slewf( &network_client
.fintent
, a
, vg
.time_frame_delta
);
434 a
= (vg_smoothstepf( network_client
.fintent
) - 0.5f
) * (VG_PIf
/2.0f
);
436 ent_prop
*lever
= mdl_arritm( &world
->ent_prop
,
437 mdl_entity_id_id(shop
->server
.id_lever
) );
439 /* we need parent transforms now? */
440 q_axis_angle( lever
->transform
.q
, (v3f
){0,0,1}, a
);
445 static void skateshop_render_boardshop( ent_skateshop
*shop
){
446 world_instance
*world
= world_current_instance();
447 u32 slot_count
= vg_list_size(global_skateshop
.shop_view_slots
);
449 ent_marker
*mark_rack
= mdl_arritm( &world
->ent_marker
,
450 mdl_entity_id_id(shop
->boards
.id_rack
)),
451 *mark_display
= mdl_arritm( &world
->ent_marker
,
452 mdl_entity_id_id(shop
->boards
.id_display
));
454 SDL_AtomicLock( &addon_system
.sl_cache_using_resources
);
455 struct addon_cache
*cache
= &addon_system
.cache
[k_addon_type_board
];
457 /* Render loaded boards in the view slots */
458 for( u32 i
=0; i
<slot_count
; i
++ ){
459 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[i
];
460 float selected
= 0.0f
;
462 if( !slot
->cache_id
)
465 addon_cache_entry
*entry
= vg_pool_item( &cache
->pool
, slot
->cache_id
);
467 if( entry
->state
!= k_addon_cache_state_loaded
)
470 struct player_board
*board
=
471 addon_cache_item( k_addon_type_board
, slot
->cache_id
);
474 transform_identity( &xform
);
476 xform
.co
[0] = -((float)i
- ((float)slot_count
)*0.5f
)*0.45f
;
477 mdl_transform_mul( &mark_rack
->transform
, &xform
, &xform
);
480 if( entry
->reg_index
== global_skateshop
.selected_board_id
){
484 float t
= slot
->view_blend
;
485 v3_lerp( xform
.co
, mark_display
->transform
.co
, t
, xform
.co
);
486 q_nlerp( xform
.q
, mark_display
->transform
.q
, t
, xform
.q
);
487 v3_lerp( xform
.s
, mark_display
->transform
.s
, t
, xform
.s
);
489 struct player_board_pose pose
= {0};
491 mdl_transform_m4x3( &xform
, mmdl
);
492 render_board( &skaterift
.cam
, world
, board
, mmdl
,
493 &pose
, k_board_shader_entity
);
496 float rate
= 5.0f
*vg
.time_delta
;
497 slot
->view_blend
= vg_lerpf( slot
->view_blend
, selected
, rate
);
500 ent_marker
*mark_info
= mdl_arritm( &world
->ent_marker
,
501 mdl_entity_id_id(shop
->boards
.id_info
));
503 mdl_transform_m4x3( &mark_info
->transform
, mtext
);
504 mdl_transform_m4x3( &mark_rack
->transform
, mrack
);
507 m4x3_identity( mlocal
);
512 font3d_bind( &gui
.font
, k_font_shader_default
, 0, world
, &skaterift
.cam
);
513 shader_model_font_uColour( (v4f
){1.0f
,1.0f
,1.0f
,1.0f
} );
516 * ------------------------------------------------------------------ */
518 v3_zero( mlocal
[3] );
519 mlocal
[0][0] = -scale
*2.0f
;
520 mlocal
[1][2] = -scale
*2.0f
;
521 mlocal
[2][1] = -thickness
;
522 mlocal
[3][2] = -0.7f
;
523 m4x3_mul( mrack
, mlocal
, mmdl
);
525 u32 valid_count
= addon_count(k_addon_type_board
,0);
529 vg_strnull( &str
, buf
, sizeof(buf
) );
530 vg_strcati32( &str
, global_skateshop
.selected_board_id
+1 );
531 vg_strcatch( &str
, '/' );
532 vg_strcati32( &str
, valid_count
);
533 font3d_simple_draw( 0, buf
, &skaterift
.cam
, mmdl
);
536 font3d_simple_draw( 0, "Nothing installed", &skaterift
.cam
, mmdl
);
539 u16 cache_id
= skateshop_selected_cache_id();
540 struct addon_cache_entry
*entry
= vg_pool_item( &cache
->pool
, cache_id
);
541 addon_reg
*reg
= NULL
;
543 if( entry
) reg
= entry
->reg_ptr
;
546 SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
547 global_skateshop
.render
.item_title
= "";
548 global_skateshop
.render
.item_desc
= "";
552 if( global_skateshop
.render
.reg_id
!= global_skateshop
.selected_board_id
){
553 global_skateshop
.render
.item_title
= "";
554 global_skateshop
.render
.item_desc
= "";
556 vg_msg_init( &msg
, reg
->metadata
, reg
->metadata_len
);
558 if( vg_msg_seekframe( &msg
, "workshop" ) ){
559 const char *title
= vg_msg_getkvstr( &msg
, "title" );
560 if( title
) global_skateshop
.render
.item_title
= title
;
562 const char *dsc
= vg_msg_getkvstr( &msg
, "author" );
563 if( dsc
) global_skateshop
.render
.item_desc
= dsc
;
564 vg_msg_skip_frame( &msg
);
567 global_skateshop
.render
.reg_id
= global_skateshop
.selected_board_id
;
571 * ----------------------------------------------------------------- */
573 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
574 mlocal
[3][0] = -font3d_string_width( 0, global_skateshop
.render
.item_title
);
575 mlocal
[3][0] *= scale
*0.5f
;
578 m4x3_mul( mtext
, mlocal
, mmdl
);
579 font3d_simple_draw( 0, global_skateshop
.render
.item_title
,
580 &skaterift
.cam
, mmdl
);
583 * ----------------------------------------------------------------- */
585 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
586 mlocal
[3][0] = -font3d_string_width( 0, global_skateshop
.render
.item_desc
);
587 mlocal
[3][0] *= scale
*0.5f
;
590 m4x3_mul( mtext
, mlocal
, mmdl
);
591 font3d_simple_draw( 0, global_skateshop
.render
.item_desc
,
592 &skaterift
.cam
, mmdl
);
594 SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
597 static void skateshop_render_charshop( ent_skateshop
*shop
){
600 static void skateshop_render_worldshop( ent_skateshop
*shop
){
601 world_instance
*world
= world_current_instance();
603 ent_marker
*mark_display
= mdl_arritm( &world
->ent_marker
,
604 mdl_entity_id_id(shop
->worlds
.id_display
)),
605 *mark_info
= mdl_arritm( &world
->ent_marker
,
606 mdl_entity_id_id(shop
->boards
.id_info
));
608 if( global_skateshop
.render
.world_reg
!= global_skateshop
.selected_world_id
){
609 global_skateshop
.render
.world_title
= "missing: workshop.title";
611 addon_reg
*reg
= get_addon_from_index( k_addon_type_world
,
612 global_skateshop
.selected_world_id
, ADDON_REG_HIDDEN
);
617 if( reg
->alias
.workshop_id
)
620 vg_msg_init( &msg
, reg
->metadata
, reg
->metadata_len
);
622 global_skateshop
.render
.world_loc
= vg_msg_getkvstr(&msg
,"location");
623 global_skateshop
.render
.world_reg
= global_skateshop
.selected_world_id
;
625 if( vg_msg_seekframe( &msg
, "workshop" ) )
627 global_skateshop
.render
.world_title
= vg_msg_getkvstr(&msg
,"title");
628 vg_msg_skip_frame( &msg
);
631 vg_warn( "No workshop body\n" );
635 global_skateshop
.render
.world_title
= reg
->alias
.foldername
;
642 char buftext
[128], bufsubtext
[128];
643 vg_str info
, subtext
;
644 vg_strnull( &info
, buftext
, 128 );
645 vg_strnull( &subtext
, bufsubtext
, 128 );
647 u32 valid_count
= addon_count(k_addon_type_world
,ADDON_REG_HIDDEN
);
650 vg_strcati32( &info
, global_skateshop
.selected_world_id
+1 );
651 vg_strcatch( &info
, '/' );
652 vg_strcati32( &info
, valid_count
);
653 vg_strcatch( &info
, ' ' );
654 vg_strcat( &info
, global_skateshop
.render
.world_title
);
656 if( !vg_loader_availible() )
658 vg_strcat( &subtext
, "Loading..." );
662 addon_reg
*reg
= get_addon_from_index( k_addon_type_world
,
663 global_skateshop
.selected_world_id
, ADDON_REG_HIDDEN
);
665 if( reg
->alias
.workshop_id
)
666 vg_strcat( &subtext
, "(Workshop) " );
668 vg_strcat( &subtext
, global_skateshop
.render
.world_loc
);
673 vg_strcat( &info
, "No workshop worlds installed" );
676 m4x3f mtext
,mlocal
,mtextmdl
;
677 mdl_transform_m4x3( &mark_info
->transform
, mtext
);
679 font3d_bind( &gui
.font
, k_font_shader_default
, 0, NULL
, &skaterift
.cam
);
680 shader_model_font_uColour( (v4f
){1.0f
,1.0f
,1.0f
,1.0f
} );
682 float scale
= 0.2f
, thickness
= 0.015f
, scale1
= 0.08f
;
684 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
685 mlocal
[3][0] = -font3d_string_width( 0, buftext
);
686 mlocal
[3][0] *= scale
*0.5f
;
689 m4x3_mul( mtext
, mlocal
, mtextmdl
);
690 font3d_simple_draw( 0, buftext
, &skaterift
.cam
, mtextmdl
);
692 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale1
, scale1
, thickness
} );
693 mlocal
[3][0] = -font3d_string_width( 0, bufsubtext
);
694 mlocal
[3][0] *= scale1
*0.5f
;
695 mlocal
[3][1] = -scale1
*0.3f
;
696 m4x3_mul( mtext
, mlocal
, mtextmdl
);
697 font3d_simple_draw( 0, bufsubtext
, &skaterift
.cam
, mtextmdl
);
701 * World: render event
703 void skateshop_render( ent_skateshop
*shop
)
705 if( shop
->type
== k_skateshop_type_boardshop
)
706 skateshop_render_boardshop( shop
);
707 else if( shop
->type
== k_skateshop_type_charshop
)
708 skateshop_render_charshop( shop
);
709 else if( shop
->type
== k_skateshop_type_worldshop
)
710 skateshop_render_worldshop( shop
);
711 else if( shop
->type
== k_skateshop_type_server
){
714 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
717 void skateshop_render_nonfocused( world_instance
*world
, vg_camera
*cam
)
719 for( u32 j
=0; j
<mdl_arrcount( &world
->ent_skateshop
); j
++ )
721 ent_skateshop
*shop
= mdl_arritm(&world
->ent_skateshop
, j
);
723 if( shop
->type
!= k_skateshop_type_boardshop
) continue;
725 f32 dist2
= v3_dist2( cam
->pos
, shop
->transform
.co
),
728 if( dist2
> maxdist
*maxdist
) continue;
729 ent_marker
*mark_rack
= mdl_arritm( &world
->ent_marker
,
730 mdl_entity_id_id(shop
->boards
.id_rack
));
735 u32 slot_count
= vg_list_size(global_skateshop
.shop_view_slots
);
736 for( u32 i
=0; i
<slot_count
; i
++ )
738 struct player_board
*board
= &localplayer
.fallback_board
;
741 transform_identity( &xform
);
743 xform
.co
[0] = -((float)i
- ((float)slot_count
)*0.5f
)*0.45f
;
744 mdl_transform_mul( &mark_rack
->transform
, &xform
, &xform
);
746 struct player_board_pose pose
= {0};
748 mdl_transform_m4x3( &xform
, mmdl
);
749 render_board( cam
, world
, board
, mmdl
, &pose
, k_board_shader_entity
);
754 static void ent_skateshop_helpers_pickable( const char *acceptance
)
758 if( gui_new_helper( input_button_list
[k_srbind_mback
], &text
))
759 vg_strcat( &text
, "exit" );
761 if( (global_skateshop
.helper_pick
= gui_new_helper(
762 input_button_list
[k_srbind_maccept
], &text
))){
763 vg_strcat( &text
, acceptance
);
766 if( (global_skateshop
.helper_browse
= gui_new_helper(
767 input_axis_list
[k_sraxis_mbrowse_h
], &text
))){
768 vg_strcat( &text
, "browse" );
772 static void board_scan_thread( void *_args
)
774 addon_mount_content_folder( k_addon_type_board
, "boards", ".mdl" );
775 addon_mount_workshop_items();
776 vg_async_call( async_addon_reg_update
, NULL
, 0 );
780 * REVIEW: This is removed as it *should* be done on the preupdate of the
783 * Verify that it works the same.
786 board_processview_thread(NULL
);
790 static void world_scan_thread( void *_args
)
792 addon_mount_content_folder( k_addon_type_world
, "maps", ".mdl" );
793 addon_mount_workshop_items();
794 vg_async_call( async_addon_reg_update
, NULL
, 0 );
798 * Entity logic: entrance event
800 void ent_skateshop_call( world_instance
*world
, ent_call
*call
)
802 u32 index
= mdl_entity_id_id( call
->id
);
803 ent_skateshop
*shop
= mdl_arritm( &world
->ent_skateshop
, index
);
804 vg_info( "skateshop_call\n" );
806 if( skaterift
.activity
!= k_skaterift_default
) return;
807 if( !vg_loader_availible() ) return;
809 if( call
->function
== k_ent_function_trigger
)
811 if( localplayer
.subsystem
!= k_player_subsystem_walk
) return;
813 vg_info( "Entering skateshop\n" );
815 world_entity_set_focus( call
->id
);
816 world_entity_focus_modal();
819 if( shop
->type
== k_skateshop_type_boardshop
)
821 skateshop_update_viewpage();
822 vg_loader_start( board_scan_thread
, NULL
);
823 ent_skateshop_helpers_pickable( "pick" );
825 else if( shop
->type
== k_skateshop_type_charshop
)
827 ent_skateshop_helpers_pickable( "pick" );
829 else if( shop
->type
== k_skateshop_type_worldshop
)
831 ent_skateshop_helpers_pickable( "open rift" );
832 vg_loader_start( world_scan_thread
, NULL
);
834 else if( shop
->type
== k_skateshop_type_server
)
837 global_skateshop
.helper_pick
= gui_new_helper(
838 input_button_list
[k_srbind_maccept
], &text
);
839 if( gui_new_helper( input_button_list
[k_srbind_mback
], &text
))
840 vg_strcat( &text
, "exit" );
841 skateshop_server_helper_update();