1 #ifndef ENT_SKATESHOP_C
2 #define ENT_SKATESHOP_C
6 #include "vg/vg_steam_ugc.h"
8 #include "ent_skateshop.h"
13 #include "pointcloud.h"
14 #include "highscores.h"
19 * Checks string equality but does a hash check first
21 static inline int const_str_eq( u32 hash
, const char *str
, const char *cmp
)
23 if( hash
== vg_strdjb2(cmp
) )
24 if( !strcmp( str
, cmp
) )
30 * Get an existing cache instance, allocate a new one to be loaded, or NULL if
33 VG_STATIC
struct cache_board
*skateshop_cache_fetch_board( u32 registry_index
)
35 addon_reg
*reg
= NULL
;
37 if( registry_index
< addon_count( k_workshop_file_type_board
) ){
38 reg
= get_addon_from_index( k_workshop_file_type_board
, registry_index
);
45 /* lru eviction. should be a linked list maybe... */
46 double min_time
= 1e300
;
47 struct cache_board
*min_board
= NULL
;
49 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
50 for( u32 i
=0; i
<SKATESHOP_BOARD_CACHE_MAX
; i
++ ){
51 struct cache_board
*cache_ptr
= &global_skateshop
.cache
[i
];
53 if( cache_ptr
->state
== k_cache_board_state_load_request
) continue;
54 if( cache_ptr
->ref_count
) continue;
56 if( cache_ptr
->last_use_time
< min_time
){
57 min_time
= cache_ptr
->last_use_time
;
58 min_board
= cache_ptr
;
63 if( min_board
->state
== k_cache_board_state_loaded
){
64 player_board_unload( &min_board
->board
);
65 min_board
->reg_ptr
->userdata
= NULL
;
69 vg_info( "Allocating board (reg:%u) '%s'\n",
70 registry_index
, reg
->foldername
);
73 vg_info( "Pre-allocating board (reg:%u) 'null'\n", registry_index
);
76 min_board
->reg_ptr
= reg
;
77 min_board
->reg_index
= registry_index
;
78 min_board
->last_use_time
= vg
.time
;
79 min_board
->ref_count
= 0;
80 min_board
->state
= k_cache_board_state_load_request
;
83 vg_error( "No free boards to load registry!\n" );
86 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
90 VG_STATIC
void skateshop_update_viewpage(void)
92 u32 page
= global_skateshop
.selected_board_id
/SKATESHOP_VIEW_SLOT_MAX
;
94 for( u32 i
=0; i
<SKATESHOP_VIEW_SLOT_MAX
; i
++ ){
95 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[i
];
96 u32 request_id
= page
*SKATESHOP_VIEW_SLOT_MAX
+ i
;
98 if( slot
->cache_ptr
) unwatch_cache_board( slot
->cache_ptr
);
100 slot
->cache_ptr
= skateshop_cache_fetch_board( request_id
);
101 if( slot
->cache_ptr
) watch_cache_board( slot
->cache_ptr
);
106 * op/subroutine: k_workshop_op_item_load
107 * -----------------------------------------------------------------------------
111 * Reciever for board completion; only promotes the status in the main thread
113 VG_STATIC
void skateshop_async_board_loaded( void *payload
, u32 size
)
115 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
116 struct cache_board
*cache_ptr
= payload
;
117 cache_ptr
->last_use_time
= vg
.time
;
118 cache_ptr
->state
= k_cache_board_state_loaded
;
120 cache_ptr
->reg_ptr
->userdata
= cache_ptr
;
121 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
122 vg_success( "Async board loaded (%s)\n", cache_ptr
->reg_ptr
->foldername
);
126 * Thread(or subroutine of thread), for checking view slots that weve installed.
127 * Load the model if a view slot wants it
129 VG_STATIC
void workshop_visibile_load_loop(void)
131 vg_info( "Running load loop\n" );
134 for( u32 i
=0; i
<SKATESHOP_BOARD_CACHE_MAX
; i
++ ){
135 struct cache_board
*cache_ptr
= &global_skateshop
.cache
[i
];
137 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
138 if( cache_ptr
->state
== k_cache_board_state_load_request
){
139 if( cache_ptr
->reg_index
>= addon_count(k_workshop_file_type_board
) ){
140 /* should maybe have a different value for this case */
141 cache_ptr
->state
= k_cache_board_state_none
;
142 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
146 /* continue with the request */
147 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
148 cache_ptr
->reg_ptr
= get_addon_from_index( k_workshop_file_type_board
,
149 cache_ptr
->reg_index
);
152 vg_strnull( &folder
, path_buf
, 4096 );
153 if( !addon_get_content_folder( cache_ptr
->reg_ptr
, &folder
) )
157 /* load content files
158 * --------------------------------- */
160 vg_str content_path
= folder
;
163 vg_msg_init( &root
, cache_ptr
->reg_ptr
->metadata
,
164 cache_ptr
->reg_ptr
->metadata_len
);
166 const char *kv_content
= vg_msg_seekkvstr( &root
, "content", 0 );
168 vg_strcat( &content_path
, "/" );
169 vg_strcat( &content_path
, kv_content
);
172 vg_error( "No content paths in metadata\n" );
176 if( !vg_strgood( &content_path
) ) {
177 vg_error( "Metadata path too long\n" );
181 vg_info( "Load content: %s\n", content_path
.buffer
);
182 player_board_load( &cache_ptr
->board
, content_path
.buffer
);
183 vg_async_call( skateshop_async_board_loaded
, cache_ptr
, 0 );
187 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
188 cache_ptr
->state
= k_cache_board_state_none
;
189 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
192 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
197 VG_STATIC
void world_scan_thread( void *_args
){
198 addon_mount_content_folder( k_workshop_file_type_world
, "maps", ".mdl" );
199 addon_mount_workshop_items();
200 vg_async_call( async_addon_reg_update
, NULL
, 0 );
205 * Asynchronous scan of local disk for worlds
207 VG_STATIC
void skateshop_op_world_scan(void){
208 skaterift_begin_op( k_async_op_world_scan
);
209 vg_loader_start( world_scan_thread
, NULL
);
212 VG_STATIC
void board_processview_thread( void *_args
){
213 workshop_visibile_load_loop();
217 VG_STATIC
void board_scan_thread( void *_args
){
218 addon_mount_content_folder( k_workshop_file_type_board
, "boards", ".mdl" );
219 addon_mount_workshop_items();
220 vg_async_call( async_addon_reg_update
, NULL
, 0 );
222 board_processview_thread(NULL
);
225 VG_STATIC
void skateshop_op_board_scan(void){
226 skaterift_begin_op( k_async_op_board_scan
);
227 vg_loader_start( board_scan_thread
, NULL
);
230 VG_STATIC
void skateshop_op_processview(void){
231 skaterift_begin_op( k_async_op_board_scan
);
232 vg_loader_start( board_processview_thread
, NULL
);
237 * -----------------------------------------------------------------------------
240 /* we can only keep using a viewslot pointer for multiple frames if we watch it
241 * using this function */
242 VG_STATIC
void watch_cache_board( struct cache_board
*ptr
){
243 if( ptr
->ref_count
>= 32 ){
244 vg_fatal_error( "dynamic board watch missmatch (limit is 32)\n" );
247 ptr
->last_use_time
= vg
.time
;
251 /* after this is called, the calling code only has access to the pointer for the
252 * duration of the rest of the frame */
253 VG_STATIC
void unwatch_cache_board( struct cache_board
*ptr
){
254 if( ptr
->ref_count
== 0 ){
255 vg_fatal_error( "dynamic board unwatch missmatch (no watchers)\n" );
265 VG_STATIC
void skateshop_init(void){
266 u32 cache_size
= sizeof(struct cache_board
)*SKATESHOP_BOARD_CACHE_MAX
;
267 global_skateshop
.cache
= vg_linear_alloc( vg_mem
.rtmemory
, cache_size
);
268 memset( global_skateshop
.cache
, 0, cache_size
);
270 for( u32 i
=0; i
<SKATESHOP_BOARD_CACHE_MAX
; i
++ ){
271 struct cache_board
*board
= &global_skateshop
.cache
[i
];
272 board
->state
= k_cache_board_state_none
;
273 board
->reg_ptr
= NULL
;
274 board
->reg_index
= 0xffffffff;
275 board
->last_use_time
= -99999.9;
276 board
->ref_count
= 0;
280 VG_STATIC
struct cache_board
*skateshop_selected_cache_if_loaded(void)
282 if( addon_count(k_workshop_file_type_board
) ){
283 addon_reg
*reg
= get_addon_from_index(k_workshop_file_type_board
,
284 global_skateshop
.selected_board_id
);
286 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
288 struct cache_board
*cache_ptr
= reg
->userdata
;
289 if( cache_ptr
->state
== k_cache_board_state_loaded
){
290 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
294 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
300 VG_STATIC
void pointcloud_async_end(void *_
, u32 __
)
302 pointcloud_animate( k_pointcloud_anim_opening
);
306 VG_STATIC
void pointcloud_clear_async(void *_
, u32 __
)
308 pointcloud
.count
= 0;
309 pointcloud_animate( k_pointcloud_anim_opening
);
313 VG_STATIC
void skateshop_preview_loader_thread( void *_data
)
315 addon_reg
*reg
= _data
;
319 vg_strnull( &path
, path_buf
, 4096 );
320 addon_get_content_folder( reg
, &path
);
321 vg_strcat( &path
, "/preview.bin" );
323 vg_linear_clear(vg_mem
.scratch
);
326 void *data
= vg_file_read( vg_mem
.scratch
, path_buf
, &size
);
328 if( size
< sizeof(pointcloud_buffer
) ){
329 vg_async_call( pointcloud_clear_async
, NULL
, 0 );
333 vg_async_item
*call
= vg_async_alloc(size
);
334 pointcloud_buffer
*pcbuf
= call
->payload
;
335 memcpy( pcbuf
, data
, size
);
337 u32 point_count
= (size
-sizeof(pointcloud_buffer
)) /
338 sizeof(struct pointcloud_vert
);
339 pcbuf
->max
= point_count
;
340 pcbuf
->count
= point_count
;
341 pcbuf
->op
= k_pointcloud_op_clear
;
343 vg_async_dispatch( call
, async_pointcloud_sub
);
344 vg_async_call( pointcloud_async_end
, NULL
, 0 );
347 vg_async_call( pointcloud_clear_async
, NULL
, 0 );
351 VG_STATIC
void skateshop_load_world_preview( addon_reg
*reg
)
353 skaterift_begin_op( k_async_op_world_load_preview
);
354 vg_loader_start( skateshop_preview_loader_thread
, reg
);
360 void temp_update_playermodel(void);
361 VG_STATIC
void global_skateshop_preupdate(void)
363 float rate
= vg_minf( 1.0f
, vg
.time_frame_delta
* 2.0f
);
364 global_skateshop
.factive
= vg_lerpf( global_skateshop
.factive
,
365 global_skateshop
.active
, rate
);
367 if( !global_skateshop
.active
) return;
369 world_instance
*world
= world_current_instance();
370 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
372 /* camera positioning */
373 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
374 mdl_entity_id_id(shop
->id_camera
) );
376 v3f dir
= {0.0f
,-1.0f
,0.0f
};
377 mdl_transform_vector( &ref
->transform
, dir
, dir
);
378 m3x3_mulv( localplayer
.invbasis
, dir
, dir
);
379 player_vector_angles( localplayer
.cam_override_angles
, dir
, 1.0f
, 0.0f
);
382 if( shop
->type
== k_skateshop_type_boardshop
||
383 shop
->type
== k_skateshop_type_worldshop
){
384 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
385 mdl_entity_id_id(shop
->boards
.id_display
) );
387 v3_sub( display
->transform
.co
, localplayer
.rb
.co
, lookat
);
390 else if( shop
->type
== k_skateshop_type_charshop
){
391 v3_sub( ref
->transform
.co
, localplayer
.rb
.co
, lookat
);
394 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
397 q_axis_angle( localplayer
.rb
.q
, (v3f
){0.0f
,1.0f
,0.0f
},
398 atan2f(lookat
[0],lookat
[2]) );
400 v3_copy( ref
->transform
.co
, localplayer
.cam_override_pos
);
401 localplayer
.cam_override_fov
= ref
->fov
;
402 localplayer
.cam_override_strength
= global_skateshop
.factive
;
405 if( shop
->type
== k_skateshop_type_boardshop
){
406 gui_helper_action( axis_display_string( k_sraxis_mbrowse_h
), "browse" );
407 gui_helper_action( button_display_string( k_srbind_mback
), "exit" );
409 struct cache_board
*selected_cache
= skateshop_selected_cache_if_loaded();
411 if( selected_cache
){
412 gui_helper_action( button_display_string( k_srbind_maccept
), "pick" );
417 * ----------------------
420 u32 opage
= global_skateshop
.selected_board_id
/SKATESHOP_VIEW_SLOT_MAX
;
422 if( button_down( k_srbind_mleft
) ){
423 if( global_skateshop
.selected_board_id
> 0 ){
424 global_skateshop
.selected_board_id
--;
428 if( button_down( k_srbind_mright
) ){
429 if( global_skateshop
.selected_board_id
+1 <
430 addon_count(k_workshop_file_type_board
) )
432 global_skateshop
.selected_board_id
++;
436 u32 npage
= global_skateshop
.selected_board_id
/SKATESHOP_VIEW_SLOT_MAX
;
438 if( opage
!= npage
){
439 skateshop_update_viewpage();
440 skateshop_op_processview();
442 else if( selected_cache
&& button_down( k_srbind_maccept
) ){
443 vg_info( "chose board from skateshop (%u)\n",
444 global_skateshop
.selected_board_id
);
446 if( localplayer
.board_view_slot
){
447 unwatch_cache_board( localplayer
.board_view_slot
);
450 localplayer
.board_view_slot
= selected_cache
;
451 watch_cache_board( localplayer
.board_view_slot
);
452 global_skateshop_exit();
456 else if( shop
->type
== k_skateshop_type_charshop
){
457 gui_helper_action( axis_display_string( k_sraxis_mbrowse_h
), "browse" );
458 gui_helper_action( button_display_string( k_srbind_mback
), "exit" );
459 gui_helper_action( button_display_string( k_srbind_maccept
), "pick" );
461 if( button_down( k_srbind_mleft
) ){
462 if( cl_playermdl_id
> 0 ){
466 cl_playermdl_id
= 2; /* HACK */
468 temp_update_playermodel(); /* HACK */
471 if( button_down( k_srbind_mright
) ){
472 if( cl_playermdl_id
+1 < 3 ){
476 cl_playermdl_id
= 0; /* HACK */
478 temp_update_playermodel(); /* HACK */
482 if( button_down( k_srbind_maccept
) ){
483 global_skateshop_exit();
486 else if( shop
->type
== k_skateshop_type_worldshop
){
490 if( addon_count(k_workshop_file_type_world
) &&
491 ((skaterift
.async_op
== k_async_op_none
)||
492 (skaterift
.async_op
== k_async_op_world_load_preview
))){
493 gui_helper_action( axis_display_string(k_sraxis_mbrowse_h
), "browse" );
497 if( (skaterift
.async_op
== k_async_op_none
) &&
498 global_skateshop
.selected_world_id
> 0 ){
499 gui_helper_action( button_display_string(k_srbind_maccept
),
507 if( button_down( k_srbind_mleft
) ){
508 if( global_skateshop
.selected_world_id
> 0 )
510 global_skateshop
.selected_world_id
--;
515 if( button_down( k_srbind_mright
) ){
516 if( global_skateshop
.selected_world_id
+1 <
517 addon_count(k_workshop_file_type_world
) )
519 global_skateshop
.selected_world_id
++;
525 if( change
&& pointcloud_idle() ){
526 pointcloud_animate( k_pointcloud_anim_hiding
);
529 if( skaterift
.async_op
== k_async_op_none
){
530 addon_reg
*reg
= get_addon_from_index( k_workshop_file_type_world
,
531 global_skateshop
.selected_world_id
);
533 /* automatically load in clouds */
534 if( loadable
&& button_down( k_srbind_maccept
) ){
535 vg_info( "Select rift (%u)\n",
536 global_skateshop
.selected_world_id
);
537 world_loader
.reg
= reg
;
538 world_loader
.override_name
[0] = '\0';
539 skaterift_change_world_start();
543 if( pointcloud
.anim
== k_pointcloud_anim_idle_closed
){
544 if( global_skateshop
.pointcloud_world_id
!=
545 global_skateshop
.selected_world_id
)
547 global_skateshop
.pointcloud_world_id
=
548 global_skateshop
.selected_world_id
;
549 skateshop_load_world_preview( reg
);
552 pointcloud_animate( k_pointcloud_anim_opening
);
555 else if( pointcloud
.anim
== k_pointcloud_anim_idle_open
){
556 if( global_skateshop
.pointcloud_world_id
!=
557 global_skateshop
.selected_world_id
)
559 pointcloud_animate( k_pointcloud_anim_hiding
);
566 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
569 if( button_down( k_srbind_mback
) ){
570 global_skateshop_exit();
575 VG_STATIC
void skateshop_render_boardshop(void)
577 world_instance
*world
= world_current_instance();
578 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
580 u32 slot_count
= vg_list_size(global_skateshop
.shop_view_slots
);
582 ent_marker
*mark_rack
= mdl_arritm( &world
->ent_marker
,
583 mdl_entity_id_id(shop
->boards
.id_rack
)),
584 *mark_display
= mdl_arritm( &world
->ent_marker
,
585 mdl_entity_id_id(shop
->boards
.id_display
));
587 int visibility
[ SKATESHOP_VIEW_SLOT_MAX
];
588 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
589 for( u32 i
=0; i
<SKATESHOP_VIEW_SLOT_MAX
; i
++ ){
590 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[i
];
594 if( slot
->cache_ptr
== NULL
) visibility
[i
] = 0;
595 else if( slot
->cache_ptr
->state
!= k_cache_board_state_loaded
)
598 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
600 /* Render loaded boards in the view slots */
601 for( u32 i
=0; i
<slot_count
; i
++ ){
602 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[i
];
603 float selected
= 0.0f
;
605 if( !visibility
[i
] ) goto fade_out
;
608 transform_identity( &xform
);
610 xform
.co
[0] = -((float)i
- ((float)slot_count
)*0.5f
)*0.45f
;
611 mdl_transform_mul( &mark_rack
->transform
, &xform
, &xform
);
613 if( slot
->cache_ptr
->reg_index
== global_skateshop
.selected_board_id
){
617 float t
= slot
->view_blend
;
618 v3_lerp( xform
.co
, mark_display
->transform
.co
, t
, xform
.co
);
619 q_nlerp( xform
.q
, mark_display
->transform
.q
, t
, xform
.q
);
620 v3_lerp( xform
.s
, mark_display
->transform
.s
, t
, xform
.s
);
623 mdl_transform_m4x3( &xform
, mmdl
);
624 render_board( &main_camera
, world
, &slot
->cache_ptr
->board
, mmdl
,
625 k_board_shader_entity
);
628 float rate
= 5.0f
*vg
.time_delta
;
629 slot
->view_blend
= vg_lerpf( slot
->view_blend
, selected
, rate
);
632 ent_marker
*mark_info
= mdl_arritm( &world
->ent_marker
,
633 mdl_entity_id_id(shop
->boards
.id_info
));
635 mdl_transform_m4x3( &mark_info
->transform
, mtext
);
636 mdl_transform_m4x3( &mark_rack
->transform
, mrack
);
639 const char *text_title
= "Fish - Title";
640 const char *text_author
= "by Shaniqua";
644 m4x3_identity( mlocal
);
649 font3d_bind( &gui
.font
, &main_camera
);
650 shader_model_font_uColour( (v4f
){1.0f
,1.0f
,1.0f
,1.0f
} );
653 * ------------------------------------------------------------------ */
655 v3_zero( mlocal
[3] );
656 mlocal
[0][0] = -scale
*2.0f
;
657 mlocal
[1][2] = -scale
*2.0f
;
658 mlocal
[2][1] = -thickness
;
659 mlocal
[3][2] = -0.7f
;
660 m4x3_mul( mrack
, mlocal
, mmdl
);
662 if( addon_count(k_workshop_file_type_board
) ){
665 i
+=highscore_intl( buf
+i
, global_skateshop
.selected_board_id
+1, 3 );
667 i
+=highscore_intl( buf
+i
, addon_count(k_workshop_file_type_board
), 3 );
670 font3d_simple_draw( &gui
.font
, 0, buf
, &main_camera
, mmdl
);
673 font3d_simple_draw( &gui
.font
, 0,
674 "Nothing installed", &main_camera
, mmdl
);
677 struct cache_board
*cache_ptr
= skateshop_selected_cache_if_loaded();
680 global_skateshop
.render
.item_title
= "";
681 global_skateshop
.render
.item_desc
= "";
685 if( global_skateshop
.render
.reg_id
!= global_skateshop
.selected_board_id
){
686 global_skateshop
.render
.item_title
= "";
687 global_skateshop
.render
.item_desc
= "";
688 addon_reg
*reg
= cache_ptr
->reg_ptr
;
690 vg_msg_init( &root
, reg
->metadata
, reg
->metadata_len
);
692 vg_msg workshop
= root
;
693 if( vg_msg_seekframe( &workshop
, "workshop", 0 ) ){
694 const char *title
= vg_msg_seekkvstr( &workshop
, "title", 0 );
695 if( title
) global_skateshop
.render
.item_title
= title
;
697 const char *dsc
= vg_msg_seekkvstr( &workshop
, "author", 0 );
698 if( dsc
) global_skateshop
.render
.item_desc
= dsc
;
701 global_skateshop
.render
.reg_id
= global_skateshop
.selected_board_id
;
704 addon_reg
*reg
= cache_ptr
->reg_ptr
;
707 * ----------------------------------------------------------------- */
709 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
710 mlocal
[3][0] = -font3d_string_width( &gui
.font
, 0,
711 global_skateshop
.render
.item_title
);
712 mlocal
[3][0] *= scale
*0.5f
;
715 m4x3_mul( mtext
, mlocal
, mmdl
);
716 font3d_simple_draw( &gui
.font
, 0, global_skateshop
.render
.item_title
,
717 &main_camera
, mmdl
);
720 * ----------------------------------------------------------------- */
722 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
723 mlocal
[3][0] = -font3d_string_width( &gui
.font
, 0,
724 global_skateshop
.render
.item_desc
);
725 mlocal
[3][0] *= scale
*0.5f
;
728 m4x3_mul( mtext
, mlocal
, mmdl
);
729 font3d_simple_draw( &gui
.font
, 0, global_skateshop
.render
.item_desc
,
730 &main_camera
, mmdl
);
733 VG_STATIC
void skateshop_render_charshop(void)
737 VG_STATIC
void skateshop_render_worldshop(void)
739 world_instance
*world
= world_current_instance();
741 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
742 ent_marker
*mark_display
= mdl_arritm( &world
->ent_marker
,
743 mdl_entity_id_id(shop
->worlds
.id_display
)),
744 *mark_info
= mdl_arritm( &world
->ent_marker
,
745 mdl_entity_id_id(shop
->boards
.id_info
));
747 if( global_skateshop
.render
.world_reg
!= global_skateshop
.selected_world_id
){
748 global_skateshop
.render
.world_title
= "";
750 addon_reg
*reg
= get_addon_from_index( k_workshop_file_type_world
,
751 global_skateshop
.selected_world_id
);
753 vg_msg_init( &root
, reg
->metadata
, reg
->metadata_len
);
754 vg_msg workshop
= root
;
755 if( vg_msg_seekframe( &workshop
, "workshop", 0 ) ){
756 global_skateshop
.render
.world_title
= vg_msg_seekkvstr( &workshop
,
759 global_skateshop
.render
.world_loc
= vg_msg_seekkvstr(&root
,"location",0);
760 global_skateshop
.render
.world_reg
= global_skateshop
.selected_world_id
;
764 char buftext
[128], bufsubtext
[128];
765 vg_str info
, subtext
;
766 vg_strnull( &info
, buftext
, 128 );
767 vg_strnull( &subtext
, bufsubtext
, 128 );
769 if( addon_count(k_workshop_file_type_world
) ){
770 addon_reg
*reg
= get_addon_from_index( k_workshop_file_type_world
,
771 global_skateshop
.selected_world_id
);
773 info
.i
+=highscore_intl( info
.buffer
+info
.i
,
774 global_skateshop
.selected_world_id
+1, 3 );
775 info
.buffer
[info
.i
++] = '/';
776 info
.i
+=highscore_intl( info
.buffer
+info
.i
,
777 addon_count(k_workshop_file_type_world
), 3 );
778 info
.buffer
[info
.i
++] = ' ';
779 info
.buffer
[info
.i
] = '\0';
781 vg_strcat( &info
, global_skateshop
.render
.world_title
);
782 if( skaterift
.async_op
== k_async_op_world_loading
||
783 skaterift
.async_op
== k_async_op_world_preloading
){
784 vg_strcat( &subtext
, "Loading..." );
787 addon_reg
*reg
= get_addon_from_index( k_workshop_file_type_world
,
788 global_skateshop
.selected_world_id
);
790 if( reg
->workshop_id
)
791 vg_strcat( &subtext
, "(Workshop) " );
793 vg_strcat( &subtext
, global_skateshop
.render
.world_loc
);
797 vg_strcat( &info
, "No worlds installed" );
801 m4x3f mtext
,mlocal
,mtextmdl
;
802 mdl_transform_m4x3( &mark_info
->transform
, mtext
);
804 font3d_bind( &gui
.font
, &main_camera
);
805 shader_model_font_uColour( (v4f
){1.0f
,1.0f
,1.0f
,1.0f
} );
807 float scale
= 0.2f
, thickness
= 0.015f
, scale1
= 0.08f
;
809 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
810 mlocal
[3][0] = -font3d_string_width( &gui
.font
, 0, buftext
);
811 mlocal
[3][0] *= scale
*0.5f
;
814 m4x3_mul( mtext
, mlocal
, mtextmdl
);
815 font3d_simple_draw( &gui
.font
, 0, buftext
, &main_camera
, mtextmdl
);
817 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale1
, scale1
, thickness
} );
818 mlocal
[3][0] = -font3d_string_width( &gui
.font
, 0, bufsubtext
);
819 mlocal
[3][0] *= scale1
*0.5f
;
820 mlocal
[3][1] = -scale1
*0.3f
;
821 m4x3_mul( mtext
, mlocal
, mtextmdl
);
822 font3d_simple_draw( &gui
.font
, 0, bufsubtext
, &main_camera
, mtextmdl
);
826 mdl_transform_m4x3( &mark_display
->transform
, mmdl
);
827 m4x3_rotate_y( mmdl
, vg
.time
* 0.2 );
830 glBlendFunc(GL_ONE
, GL_ONE
);
831 glDisable(GL_DEPTH_TEST
);
832 pointcloud_render( world
, &main_camera
, mmdl
);
834 glEnable(GL_DEPTH_TEST
);
838 * World: render event
840 VG_STATIC
void skateshop_render(void)
842 if( !global_skateshop
.active
) return;
844 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
846 if( shop
->type
== k_skateshop_type_boardshop
){
847 skateshop_render_boardshop();
849 else if( shop
->type
== k_skateshop_type_charshop
){
850 skateshop_render_charshop();
852 else if( shop
->type
== k_skateshop_type_worldshop
){
853 skateshop_render_worldshop();
856 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
861 * Entity logic: entrance event
863 VG_STATIC
void ent_skateshop_call( world_instance
*world
, ent_call
*call
)
865 u32 index
= mdl_entity_id_id( call
->id
);
866 ent_skateshop
*shop
= mdl_arritm( &world
->ent_skateshop
, index
);
867 vg_info( "skateshop_call\n" );
869 if( menu
.active
) return;
870 if( skaterift
.async_op
!= k_async_op_none
) return;
872 if( call
->function
== k_ent_function_trigger
){
873 if( localplayer
.subsystem
!= k_player_subsystem_walk
){
877 vg_info( "Entering skateshop\n" );
879 localplayer
.immobile
= 1;
880 menu
.disable_open
= 1;
881 global_skateshop
.active
= 1;
883 v3_zero( localplayer
.rb
.v
);
884 v3_zero( localplayer
.rb
.w
);
885 localplayer
._walk
.move_speed
= 0.0f
;
886 global_skateshop
.ptr_ent
= shop
;
888 if( shop
->type
== k_skateshop_type_boardshop
){
889 skateshop_update_viewpage();
890 skateshop_op_board_scan();
892 else if( shop
->type
== k_skateshop_type_worldshop
){
893 pointcloud_animate( k_pointcloud_anim_opening
);
894 skateshop_op_world_scan();
900 * Entity logic: exit event
902 VG_STATIC
void global_skateshop_exit(void)
904 vg_info( "exit skateshop\n" );
905 localplayer
.immobile
= 0;
906 global_skateshop
.active
= 0;
907 menu
.disable_open
= 0;
908 srinput
.ignore_input_frames
= 2;
911 #endif /* ENT_SKATESHOP_C */