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_focus_context
*ctx
)
217 world_instance
*world
= ctx
->world
;
218 ent_skateshop
*shop
= mdl_arritm( &world
->ent_skateshop
, ctx
->index
);
220 /* camera positioning */
221 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
222 mdl_entity_id_id(shop
->id_camera
) );
224 v3f dir
= {0.0f
,-1.0f
,0.0f
};
225 mdl_transform_vector( &ref
->transform
, dir
, dir
);
226 v3_angles( dir
, world_static
.focus_cam
.angles
);
229 if( shop
->type
== k_skateshop_type_boardshop
||
230 shop
->type
== k_skateshop_type_worldshop
){
231 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
232 mdl_entity_id_id(shop
->boards
.id_display
) );
233 v3_sub( display
->transform
.co
, localplayer
.rb
.co
, lookat
);
235 else if( shop
->type
== k_skateshop_type_charshop
){
236 v3_sub( ref
->transform
.co
, localplayer
.rb
.co
, lookat
);
238 else if( shop
->type
== k_skateshop_type_server
){
239 ent_prop
*prop
= mdl_arritm( &world
->ent_prop
,
240 mdl_entity_id_id(shop
->server
.id_lever
) );
241 v3_sub( prop
->transform
.co
, localplayer
.rb
.co
, lookat
);
244 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
246 q_axis_angle( localplayer
.rb
.q
, (v3f
){0.0f
,1.0f
,0.0f
},
247 atan2f(lookat
[0],lookat
[2]) );
249 v3_copy( ref
->transform
.co
, world_static
.focus_cam
.pos
);
250 world_static
.focus_cam
.fov
= ref
->fov
;
253 if( shop
->type
== k_skateshop_type_boardshop
){
254 if( !vg_loader_availible() ) return;
256 u16 cache_id
= skateshop_selected_cache_id();
257 global_skateshop
.helper_pick
->greyed
= !cache_id
;
261 * ----------------------
263 u32 opage
= global_skateshop
.selected_board_id
/SKATESHOP_VIEW_SLOT_MAX
;
265 if( button_down( k_srbind_mleft
) ){
266 if( global_skateshop
.selected_board_id
> 0 ){
267 global_skateshop
.selected_board_id
--;
271 u32 valid_count
= addon_count( k_addon_type_board
, 0 );
272 if( button_down( k_srbind_mright
) ){
273 if( global_skateshop
.selected_board_id
+1 < valid_count
){
274 global_skateshop
.selected_board_id
++;
278 u32 npage
= global_skateshop
.selected_board_id
/SKATESHOP_VIEW_SLOT_MAX
;
280 if( opage
!= npage
){
281 skateshop_update_viewpage();
283 else if( cache_id
&& button_down( k_srbind_maccept
)){
284 vg_info( "chose board from skateshop (%u)\n",
285 global_skateshop
.selected_board_id
);
287 addon_cache_unwatch( k_addon_type_board
, localplayer
.board_view_slot
);
288 addon_cache_watch( k_addon_type_board
, cache_id
);
289 localplayer
.board_view_slot
= cache_id
;
290 network_send_item( k_netmsg_playeritem_board
);
292 world_entity_exit_modal();
293 world_entity_clear_focus();
295 skaterift_autosave(1);
299 else if( shop
->type
== k_skateshop_type_charshop
){
300 if( !vg_loader_availible() ) return;
303 u32 valid_count
= addon_count( k_addon_type_player
, ADDON_REG_HIDDEN
);
305 if( button_down( k_srbind_mleft
) ){
306 if( global_skateshop
.selected_player_id
> 0 ){
307 global_skateshop
.selected_player_id
--;
310 global_skateshop
.selected_player_id
= valid_count
-1;
316 if( button_down( k_srbind_mright
) ){
317 if( global_skateshop
.selected_player_id
+1 < valid_count
){
318 global_skateshop
.selected_player_id
++;
321 global_skateshop
.selected_player_id
= 0;
328 addon_reg
*addon
= get_addon_from_index(
329 k_addon_type_player
, global_skateshop
.selected_player_id
,
332 u32 real_id
= get_index_from_addon(
333 k_addon_type_player
, addon
);
335 player__use_model( real_id
);
338 if( button_down( k_srbind_maccept
) ){
339 network_send_item( k_netmsg_playeritem_player
);
340 world_entity_exit_modal();
341 world_entity_clear_focus();
345 else if( shop
->type
== k_skateshop_type_worldshop
){
349 u32 valid_count
= addon_count( k_addon_type_world
, ADDON_REG_HIDDEN
);
351 if( valid_count
&& vg_loader_availible() )
354 if( valid_count
&& vg_loader_availible() )
357 global_skateshop
.helper_browse
->greyed
= !browseable
;
358 global_skateshop
.helper_pick
->greyed
= !loadable
;
360 addon_reg
*selected_world
= NULL
;
364 if( button_down( k_srbind_mleft
) ){
365 if( global_skateshop
.selected_world_id
> 0 ){
366 global_skateshop
.selected_world_id
--;
371 if( button_down( k_srbind_mright
) ){
372 if( global_skateshop
.selected_world_id
+1 < valid_count
){
373 global_skateshop
.selected_world_id
++;
378 selected_world
= get_addon_from_index( k_addon_type_world
,
379 global_skateshop
.selected_world_id
, ADDON_REG_HIDDEN
);
381 if( change
|| (global_skateshop
.reg_preview
== NULL
) ){
382 SDL_AtomicLock( &addon_system
.sl_cache_using_resources
);
383 global_skateshop
.reg_preview
= selected_world
;
384 SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
389 if( button_down( k_srbind_maccept
) ){
390 skaterift_change_world_start( selected_world
);
394 else if( shop
->type
== k_skateshop_type_server
){
395 f64 delta
= vg
.time_real
- network_client
.last_intent_change
;
397 if( (delta
> 5.0) && (!skaterift
.demo_mode
) ){
398 global_skateshop
.helper_pick
->greyed
= 0;
399 if( button_down( k_srbind_maccept
) ){
400 network_client
.user_intent
= !network_client
.user_intent
;
401 network_client
.last_intent_change
= vg
.time_real
;
402 skateshop_server_helper_update();
403 render_server_status_gui();
407 global_skateshop
.helper_pick
->greyed
= 1;
411 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
414 if( button_down( k_srbind_mback
) )
416 if( shop
->type
== k_skateshop_type_charshop
)
417 network_send_item( k_netmsg_playeritem_player
);
419 world_entity_exit_modal();
420 world_entity_clear_focus();
426 void skateshop_world_preupdate( world_instance
*world
)
428 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_skateshop
); i
++ ){
429 ent_skateshop
*shop
= mdl_arritm( &world
->ent_skateshop
, i
);
431 if( shop
->type
== k_skateshop_type_server
){
432 f32 a
= network_client
.user_intent
;
434 vg_slewf( &network_client
.fintent
, a
, vg
.time_frame_delta
);
435 a
= (vg_smoothstepf( network_client
.fintent
) - 0.5f
) * (VG_PIf
/2.0f
);
437 ent_prop
*lever
= mdl_arritm( &world
->ent_prop
,
438 mdl_entity_id_id(shop
->server
.id_lever
) );
440 /* we need parent transforms now? */
441 q_axis_angle( lever
->transform
.q
, (v3f
){0,0,1}, a
);
446 static void skateshop_render_boardshop( ent_skateshop
*shop
){
447 world_instance
*world
= world_current_instance();
448 u32 slot_count
= vg_list_size(global_skateshop
.shop_view_slots
);
450 ent_marker
*mark_rack
= mdl_arritm( &world
->ent_marker
,
451 mdl_entity_id_id(shop
->boards
.id_rack
)),
452 *mark_display
= mdl_arritm( &world
->ent_marker
,
453 mdl_entity_id_id(shop
->boards
.id_display
));
455 SDL_AtomicLock( &addon_system
.sl_cache_using_resources
);
456 struct addon_cache
*cache
= &addon_system
.cache
[k_addon_type_board
];
458 /* Render loaded boards in the view slots */
459 for( u32 i
=0; i
<slot_count
; i
++ ){
460 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[i
];
461 float selected
= 0.0f
;
463 if( !slot
->cache_id
)
466 addon_cache_entry
*entry
= vg_pool_item( &cache
->pool
, slot
->cache_id
);
468 if( entry
->state
!= k_addon_cache_state_loaded
)
471 struct player_board
*board
=
472 addon_cache_item( k_addon_type_board
, slot
->cache_id
);
475 transform_identity( &xform
);
477 xform
.co
[0] = -((float)i
- ((float)slot_count
)*0.5f
)*0.45f
;
478 mdl_transform_mul( &mark_rack
->transform
, &xform
, &xform
);
481 if( entry
->reg_index
== global_skateshop
.selected_board_id
){
485 float t
= slot
->view_blend
;
486 v3_lerp( xform
.co
, mark_display
->transform
.co
, t
, xform
.co
);
487 q_nlerp( xform
.q
, mark_display
->transform
.q
, t
, xform
.q
);
488 v3_lerp( xform
.s
, mark_display
->transform
.s
, t
, xform
.s
);
490 struct player_board_pose pose
= {0};
492 mdl_transform_m4x3( &xform
, mmdl
);
493 render_board( &skaterift
.cam
, world
, board
, mmdl
,
494 &pose
, k_board_shader_entity
);
497 float rate
= 5.0f
*vg
.time_delta
;
498 slot
->view_blend
= vg_lerpf( slot
->view_blend
, selected
, rate
);
501 ent_marker
*mark_info
= mdl_arritm( &world
->ent_marker
,
502 mdl_entity_id_id(shop
->boards
.id_info
));
504 mdl_transform_m4x3( &mark_info
->transform
, mtext
);
505 mdl_transform_m4x3( &mark_rack
->transform
, mrack
);
508 m4x3_identity( mlocal
);
513 font3d_bind( &gui
.font
, k_font_shader_default
, 0, world
, &skaterift
.cam
);
514 shader_model_font_uColour( (v4f
){1.0f
,1.0f
,1.0f
,1.0f
} );
517 * ------------------------------------------------------------------ */
519 v3_zero( mlocal
[3] );
520 mlocal
[0][0] = -scale
*2.0f
;
521 mlocal
[1][2] = -scale
*2.0f
;
522 mlocal
[2][1] = -thickness
;
523 mlocal
[3][2] = -0.7f
;
524 m4x3_mul( mrack
, mlocal
, mmdl
);
526 u32 valid_count
= addon_count(k_addon_type_board
,0);
530 vg_strnull( &str
, buf
, sizeof(buf
) );
531 vg_strcati32( &str
, global_skateshop
.selected_board_id
+1 );
532 vg_strcatch( &str
, '/' );
533 vg_strcati32( &str
, valid_count
);
534 font3d_simple_draw( 0, buf
, &skaterift
.cam
, mmdl
);
537 font3d_simple_draw( 0, "Nothing installed", &skaterift
.cam
, mmdl
);
540 u16 cache_id
= skateshop_selected_cache_id();
541 struct addon_cache_entry
*entry
= vg_pool_item( &cache
->pool
, cache_id
);
542 addon_reg
*reg
= NULL
;
544 if( entry
) reg
= entry
->reg_ptr
;
547 SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
548 global_skateshop
.render
.item_title
= "";
549 global_skateshop
.render
.item_desc
= "";
553 if( global_skateshop
.render
.reg_id
!= global_skateshop
.selected_board_id
){
554 global_skateshop
.render
.item_title
= "";
555 global_skateshop
.render
.item_desc
= "";
557 vg_msg_init( &msg
, reg
->metadata
, reg
->metadata_len
);
559 if( vg_msg_seekframe( &msg
, "workshop" ) ){
560 const char *title
= vg_msg_getkvstr( &msg
, "title" );
561 if( title
) global_skateshop
.render
.item_title
= title
;
563 const char *dsc
= vg_msg_getkvstr( &msg
, "author" );
564 if( dsc
) global_skateshop
.render
.item_desc
= dsc
;
565 vg_msg_skip_frame( &msg
);
568 global_skateshop
.render
.reg_id
= global_skateshop
.selected_board_id
;
572 * ----------------------------------------------------------------- */
574 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
575 mlocal
[3][0] = -font3d_string_width( 0, global_skateshop
.render
.item_title
);
576 mlocal
[3][0] *= scale
*0.5f
;
579 m4x3_mul( mtext
, mlocal
, mmdl
);
580 font3d_simple_draw( 0, global_skateshop
.render
.item_title
,
581 &skaterift
.cam
, mmdl
);
584 * ----------------------------------------------------------------- */
586 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
587 mlocal
[3][0] = -font3d_string_width( 0, global_skateshop
.render
.item_desc
);
588 mlocal
[3][0] *= scale
*0.5f
;
591 m4x3_mul( mtext
, mlocal
, mmdl
);
592 font3d_simple_draw( 0, global_skateshop
.render
.item_desc
,
593 &skaterift
.cam
, mmdl
);
595 SDL_AtomicUnlock( &addon_system
.sl_cache_using_resources
);
598 static void skateshop_render_charshop( ent_skateshop
*shop
){
601 static void skateshop_render_worldshop( ent_skateshop
*shop
){
602 world_instance
*world
= world_current_instance();
604 ent_marker
*mark_display
= mdl_arritm( &world
->ent_marker
,
605 mdl_entity_id_id(shop
->worlds
.id_display
)),
606 *mark_info
= mdl_arritm( &world
->ent_marker
,
607 mdl_entity_id_id(shop
->boards
.id_info
));
609 if( global_skateshop
.render
.world_reg
!= global_skateshop
.selected_world_id
){
610 global_skateshop
.render
.world_title
= "missing: workshop.title";
612 addon_reg
*reg
= get_addon_from_index( k_addon_type_world
,
613 global_skateshop
.selected_world_id
, ADDON_REG_HIDDEN
);
618 if( reg
->alias
.workshop_id
)
621 vg_msg_init( &msg
, reg
->metadata
, reg
->metadata_len
);
623 global_skateshop
.render
.world_loc
= vg_msg_getkvstr(&msg
,"location");
624 global_skateshop
.render
.world_reg
= global_skateshop
.selected_world_id
;
626 if( vg_msg_seekframe( &msg
, "workshop" ) )
628 global_skateshop
.render
.world_title
= vg_msg_getkvstr(&msg
,"title");
629 vg_msg_skip_frame( &msg
);
632 vg_warn( "No workshop body\n" );
636 global_skateshop
.render
.world_title
= reg
->alias
.foldername
;
643 char buftext
[128], bufsubtext
[128];
644 vg_str info
, subtext
;
645 vg_strnull( &info
, buftext
, 128 );
646 vg_strnull( &subtext
, bufsubtext
, 128 );
648 u32 valid_count
= addon_count(k_addon_type_world
,ADDON_REG_HIDDEN
);
651 vg_strcati32( &info
, global_skateshop
.selected_world_id
+1 );
652 vg_strcatch( &info
, '/' );
653 vg_strcati32( &info
, valid_count
);
654 vg_strcatch( &info
, ' ' );
655 vg_strcat( &info
, global_skateshop
.render
.world_title
);
657 if( !vg_loader_availible() )
659 vg_strcat( &subtext
, "Loading..." );
663 addon_reg
*reg
= get_addon_from_index( k_addon_type_world
,
664 global_skateshop
.selected_world_id
, ADDON_REG_HIDDEN
);
666 if( reg
->alias
.workshop_id
)
667 vg_strcat( &subtext
, "(Workshop) " );
669 vg_strcat( &subtext
, global_skateshop
.render
.world_loc
);
674 vg_strcat( &info
, "No workshop worlds installed" );
677 m4x3f mtext
,mlocal
,mtextmdl
;
678 mdl_transform_m4x3( &mark_info
->transform
, mtext
);
680 font3d_bind( &gui
.font
, k_font_shader_default
, 0, NULL
, &skaterift
.cam
);
681 shader_model_font_uColour( (v4f
){1.0f
,1.0f
,1.0f
,1.0f
} );
683 float scale
= 0.2f
, thickness
= 0.015f
, scale1
= 0.08f
;
685 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
686 mlocal
[3][0] = -font3d_string_width( 0, buftext
);
687 mlocal
[3][0] *= scale
*0.5f
;
690 m4x3_mul( mtext
, mlocal
, mtextmdl
);
691 font3d_simple_draw( 0, buftext
, &skaterift
.cam
, mtextmdl
);
693 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale1
, scale1
, thickness
} );
694 mlocal
[3][0] = -font3d_string_width( 0, bufsubtext
);
695 mlocal
[3][0] *= scale1
*0.5f
;
696 mlocal
[3][1] = -scale1
*0.3f
;
697 m4x3_mul( mtext
, mlocal
, mtextmdl
);
698 font3d_simple_draw( 0, bufsubtext
, &skaterift
.cam
, mtextmdl
);
702 * World: render event
704 void skateshop_render( ent_skateshop
*shop
)
706 if( shop
->type
== k_skateshop_type_boardshop
)
707 skateshop_render_boardshop( shop
);
708 else if( shop
->type
== k_skateshop_type_charshop
)
709 skateshop_render_charshop( shop
);
710 else if( shop
->type
== k_skateshop_type_worldshop
)
711 skateshop_render_worldshop( shop
);
712 else if( shop
->type
== k_skateshop_type_server
){
715 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
718 void skateshop_render_nonfocused( world_instance
*world
, vg_camera
*cam
)
720 for( u32 j
=0; j
<mdl_arrcount( &world
->ent_skateshop
); j
++ )
722 ent_skateshop
*shop
= mdl_arritm(&world
->ent_skateshop
, j
);
724 if( shop
->type
!= k_skateshop_type_boardshop
) continue;
726 f32 dist2
= v3_dist2( cam
->pos
, shop
->transform
.co
),
729 if( dist2
> maxdist
*maxdist
) continue;
730 ent_marker
*mark_rack
= mdl_arritm( &world
->ent_marker
,
731 mdl_entity_id_id(shop
->boards
.id_rack
));
736 u32 slot_count
= vg_list_size(global_skateshop
.shop_view_slots
);
737 for( u32 i
=0; i
<slot_count
; i
++ )
739 struct player_board
*board
= &localplayer
.fallback_board
;
742 transform_identity( &xform
);
744 xform
.co
[0] = -((float)i
- ((float)slot_count
)*0.5f
)*0.45f
;
745 mdl_transform_mul( &mark_rack
->transform
, &xform
, &xform
);
747 struct player_board_pose pose
= {0};
749 mdl_transform_m4x3( &xform
, mmdl
);
750 render_board( cam
, world
, board
, mmdl
, &pose
, k_board_shader_entity
);
755 static void ent_skateshop_helpers_pickable( const char *acceptance
)
759 if( gui_new_helper( input_button_list
[k_srbind_mback
], &text
))
760 vg_strcat( &text
, "exit" );
762 if( (global_skateshop
.helper_pick
= gui_new_helper(
763 input_button_list
[k_srbind_maccept
], &text
))){
764 vg_strcat( &text
, acceptance
);
767 if( (global_skateshop
.helper_browse
= gui_new_helper(
768 input_axis_list
[k_sraxis_mbrowse_h
], &text
))){
769 vg_strcat( &text
, "browse" );
773 static void board_scan_thread( void *_args
)
775 addon_mount_content_folder( k_addon_type_board
, "boards", ".mdl" );
776 addon_mount_workshop_items();
777 vg_async_call( async_addon_reg_update
, NULL
, 0 );
781 * REVIEW: This is removed as it *should* be done on the preupdate of the
784 * Verify that it works the same.
787 board_processview_thread(NULL
);
791 static void world_scan_thread( void *_args
)
793 addon_mount_content_folder( k_addon_type_world
, "maps", ".mdl" );
794 addon_mount_workshop_items();
795 vg_async_call( async_addon_reg_update
, NULL
, 0 );
799 * Entity logic: entrance event
801 entity_call_result
ent_skateshop_call( world_instance
*world
, ent_call
*call
)
803 u32 index
= mdl_entity_id_id( call
->id
);
804 ent_skateshop
*shop
= mdl_arritm( &world
->ent_skateshop
, index
);
805 vg_info( "skateshop_call\n" );
807 if( (skaterift
.activity
!= k_skaterift_default
) ||
808 !vg_loader_availible() )
809 return k_entity_call_result_invalid
;
811 if( call
->function
== k_ent_function_trigger
)
813 if( localplayer
.subsystem
!= k_player_subsystem_walk
)
814 return k_entity_call_result_OK
;
816 vg_info( "Entering skateshop\n" );
818 world_entity_set_focus( call
->id
);
819 world_entity_focus_modal();
822 if( shop
->type
== k_skateshop_type_boardshop
)
824 skateshop_update_viewpage();
825 vg_loader_start( board_scan_thread
, NULL
);
826 ent_skateshop_helpers_pickable( "pick" );
828 else if( shop
->type
== k_skateshop_type_charshop
)
830 ent_skateshop_helpers_pickable( "pick" );
832 else if( shop
->type
== k_skateshop_type_worldshop
)
834 ent_skateshop_helpers_pickable( "open rift" );
835 vg_loader_start( world_scan_thread
, NULL
);
837 else if( shop
->type
== k_skateshop_type_server
)
840 global_skateshop
.helper_pick
= gui_new_helper(
841 input_button_list
[k_srbind_maccept
], &text
);
842 if( gui_new_helper( input_button_list
[k_srbind_mback
], &text
))
843 vg_strcat( &text
, "exit" );
844 skateshop_server_helper_update();
846 return k_entity_call_result_OK
;
849 return k_entity_call_result_unhandled
;