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"
20 * Checks string equality but does a hash check first
22 static inline int const_str_eq( u32 hash
, const char *str
, const char *cmp
)
24 if( hash
== vg_strdjb2(cmp
) )
25 if( !strcmp( str
, cmp
) )
31 * Get an existing cache instance, allocate a new one to be loaded, or NULL if
34 VG_STATIC
struct cache_board
*skateshop_cache_fetch_board( u32 registry_index
)
36 addon_reg
*reg
= NULL
;
38 if( registry_index
< addon_count( k_workshop_file_type_board
) ){
39 reg
= get_addon_from_index( k_workshop_file_type_board
, registry_index
);
46 /* lru eviction. should be a linked list maybe... */
47 double min_time
= 1e300
;
48 struct cache_board
*min_board
= NULL
;
50 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
51 for( u32 i
=0; i
<SKATESHOP_BOARD_CACHE_MAX
; i
++ ){
52 struct cache_board
*cache_ptr
= &global_skateshop
.cache
[i
];
54 if( cache_ptr
->state
== k_cache_board_state_load_request
) continue;
55 if( cache_ptr
->ref_count
) continue;
57 if( cache_ptr
->last_use_time
< min_time
){
58 min_time
= cache_ptr
->last_use_time
;
59 min_board
= cache_ptr
;
64 if( min_board
->state
== k_cache_board_state_loaded
){
65 player_board_unload( &min_board
->board
);
66 min_board
->reg_ptr
->userdata
= NULL
;
70 vg_info( "Allocating board (reg:%u) '%s'\n",
71 registry_index
, reg
->foldername
);
74 vg_info( "Pre-allocating board (reg:%u) 'null'\n", registry_index
);
77 min_board
->reg_ptr
= reg
;
78 min_board
->reg_index
= registry_index
;
79 min_board
->last_use_time
= vg
.time
;
80 min_board
->ref_count
= 0;
81 min_board
->state
= k_cache_board_state_load_request
;
84 vg_error( "No free boards to load registry!\n" );
87 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
91 VG_STATIC
void skateshop_update_viewpage(void)
93 u32 page
= global_skateshop
.selected_board_id
/SKATESHOP_VIEW_SLOT_MAX
;
95 for( u32 i
=0; i
<SKATESHOP_VIEW_SLOT_MAX
; i
++ ){
96 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[i
];
97 u32 request_id
= page
*SKATESHOP_VIEW_SLOT_MAX
+ i
;
99 if( slot
->cache_ptr
) unwatch_cache_board( slot
->cache_ptr
);
101 slot
->cache_ptr
= skateshop_cache_fetch_board( request_id
);
102 if( slot
->cache_ptr
) watch_cache_board( slot
->cache_ptr
);
107 * op/subroutine: k_workshop_op_item_load
108 * -----------------------------------------------------------------------------
112 * Reciever for board completion; only promotes the status in the main thread
114 VG_STATIC
void skateshop_async_board_loaded( void *payload
, u32 size
)
116 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
117 struct cache_board
*cache_ptr
= payload
;
118 cache_ptr
->last_use_time
= vg
.time
;
119 cache_ptr
->state
= k_cache_board_state_loaded
;
121 cache_ptr
->reg_ptr
->userdata
= cache_ptr
;
122 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
123 vg_success( "Async board loaded (%s)\n", cache_ptr
->reg_ptr
->foldername
);
127 * Thread(or subroutine of thread), for checking view slots that weve installed.
128 * Load the model if a view slot wants it
130 VG_STATIC
void workshop_visibile_load_loop(void)
132 vg_info( "Running load loop\n" );
135 for( u32 i
=0; i
<SKATESHOP_BOARD_CACHE_MAX
; i
++ ){
136 struct cache_board
*cache_ptr
= &global_skateshop
.cache
[i
];
138 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
139 if( cache_ptr
->state
== k_cache_board_state_load_request
){
140 if( cache_ptr
->reg_index
>= addon_count(k_workshop_file_type_board
) ){
141 /* should maybe have a different value for this case */
142 cache_ptr
->state
= k_cache_board_state_none
;
143 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
147 /* continue with the request */
148 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
149 addon_reg
*reg
= get_addon_from_index( k_workshop_file_type_board
,
150 cache_ptr
->reg_index
);
151 cache_ptr
->reg_ptr
= reg
;
154 vg_strnull( &folder
, path_buf
, 4096 );
155 if( !addon_get_content_folder( reg
, &folder
) )
159 /* load content files
160 * --------------------------------- */
162 vg_str content_path
= folder
;
166 root
.buf
= reg
->metadata
;
167 root
.len
= reg
->metadata_len
;
168 root
.max
= sizeof(reg
->metadata
);
170 const char *kv_content
= vg_msg_seekkvstr( &root
, "content", 0 );
172 vg_strcat( &content_path
, "/" );
173 vg_strcat( &content_path
, kv_content
);
176 vg_error( "No content paths in metadata\n" );
180 if( !vg_strgood( &content_path
) ) {
181 vg_error( "Metadata path too long\n" );
185 vg_info( "Load content: %s\n", content_path
.buffer
);
186 player_board_load( &cache_ptr
->board
, content_path
.buffer
);
187 vg_async_call( skateshop_async_board_loaded
, cache_ptr
, 0 );
191 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
192 cache_ptr
->state
= k_cache_board_state_none
;
193 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
196 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
201 VG_STATIC
void world_scan_thread( void *_args
){
202 addon_mount_content_folder( k_workshop_file_type_world
, "maps", ".mdl" );
203 addon_mount_workshop_items();
204 vg_async_call( async_addon_reg_update
, NULL
, 0 );
209 * Asynchronous scan of local disk for worlds
211 VG_STATIC
void skateshop_op_world_scan(void){
212 skaterift_begin_op( k_async_op_world_scan
);
213 vg_loader_start( world_scan_thread
, NULL
);
216 VG_STATIC
void board_processview_thread( void *_args
){
217 workshop_visibile_load_loop();
221 VG_STATIC
void board_scan_thread( void *_args
){
222 addon_mount_content_folder( k_workshop_file_type_board
, "boards", ".mdl" );
223 addon_mount_workshop_items();
224 vg_async_call( async_addon_reg_update
, NULL
, 0 );
226 board_processview_thread(NULL
);
229 VG_STATIC
void skateshop_op_board_scan(void){
230 skaterift_begin_op( k_async_op_board_scan
);
231 vg_loader_start( board_scan_thread
, NULL
);
234 VG_STATIC
void skateshop_op_processview(void){
235 skaterift_begin_op( k_async_op_board_scan
);
236 vg_loader_start( board_processview_thread
, NULL
);
241 * -----------------------------------------------------------------------------
244 /* we can only keep using a viewslot pointer for multiple frames if we watch it
245 * using this function */
246 VG_STATIC
void watch_cache_board( struct cache_board
*ptr
){
247 if( ptr
->ref_count
>= 32 ){
248 vg_fatal_error( "dynamic board watch missmatch (limit is 32)\n" );
251 ptr
->last_use_time
= vg
.time
;
255 /* after this is called, the calling code only has access to the pointer for the
256 * duration of the rest of the frame */
257 VG_STATIC
void unwatch_cache_board( struct cache_board
*ptr
){
258 if( ptr
->ref_count
== 0 ){
259 vg_fatal_error( "dynamic board unwatch missmatch (no watchers)\n" );
269 VG_STATIC
void skateshop_init(void){
270 u32 cache_size
= sizeof(struct cache_board
)*SKATESHOP_BOARD_CACHE_MAX
;
271 global_skateshop
.cache
= vg_linear_alloc( vg_mem
.rtmemory
, cache_size
);
272 memset( global_skateshop
.cache
, 0, cache_size
);
274 for( u32 i
=0; i
<SKATESHOP_BOARD_CACHE_MAX
; i
++ ){
275 struct cache_board
*board
= &global_skateshop
.cache
[i
];
276 board
->state
= k_cache_board_state_none
;
277 board
->reg_ptr
= NULL
;
278 board
->reg_index
= 0xffffffff;
279 board
->last_use_time
= -99999.9;
280 board
->ref_count
= 0;
284 VG_STATIC
struct cache_board
*skateshop_selected_cache_if_loaded(void)
286 if( addon_count(k_workshop_file_type_board
) ){
287 addon_reg
*reg
= get_addon_from_index(k_workshop_file_type_board
,
288 global_skateshop
.selected_board_id
);
290 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
292 struct cache_board
*cache_ptr
= reg
->userdata
;
293 if( cache_ptr
->state
== k_cache_board_state_loaded
){
294 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
298 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
304 VG_STATIC
void pointcloud_async_end(void *_
, u32 __
)
306 pointcloud_animate( k_pointcloud_anim_opening
);
309 VG_STATIC
void pointcloud_clear_async(void *_
, u32 __
)
311 pointcloud
.count
= 0;
312 pointcloud_animate( k_pointcloud_anim_opening
);
315 VG_STATIC
void skateshop_preview_loader_thread( void *_data
)
317 addon_reg
*reg
= _data
;
321 vg_strnull( &path
, path_buf
, 4096 );
322 addon_get_content_folder( reg
, &path
);
323 vg_strcat( &path
, "/preview.bin" );
325 vg_linear_clear(vg_mem
.scratch
);
328 void *data
= vg_file_read( vg_mem
.scratch
, path_buf
, &size
);
330 if( size
< sizeof(pointcloud_buffer
) ){
331 vg_async_call( pointcloud_clear_async
, NULL
, 0 );
335 vg_async_item
*call
= vg_async_alloc(size
);
336 pointcloud_buffer
*pcbuf
= call
->payload
;
337 memcpy( pcbuf
, data
, size
);
339 u32 point_count
= (size
-sizeof(pointcloud_buffer
)) /
340 sizeof(struct pointcloud_vert
);
341 pcbuf
->max
= point_count
;
342 pcbuf
->count
= point_count
;
343 pcbuf
->op
= k_pointcloud_op_clear
;
345 vg_async_dispatch( call
, async_pointcloud_sub
);
346 vg_async_call( pointcloud_async_end
, NULL
, 0 );
349 vg_async_call( pointcloud_clear_async
, NULL
, 0 );
353 VG_STATIC
void skateshop_preview_loader_thread_and_end( void *_data
){
354 skateshop_preview_loader_thread( _data
);
358 VG_STATIC
void skateshop_load_world_preview( addon_reg
*reg
)
360 skaterift_begin_op( k_async_op_world_load_preview
);
361 vg_loader_start( skateshop_preview_loader_thread_and_end
, reg
);
367 void temp_update_playermodel(void);
368 VG_STATIC
void global_skateshop_preupdate(void)
370 float rate
= vg_minf( 1.0f
, vg
.time_frame_delta
* 2.0f
);
371 global_skateshop
.factive
= vg_lerpf( global_skateshop
.factive
,
372 global_skateshop
.active
, rate
);
374 if( !global_skateshop
.active
) return;
376 world_instance
*world
= world_current_instance();
377 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
379 /* camera positioning */
380 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
381 mdl_entity_id_id(shop
->id_camera
) );
383 v3f dir
= {0.0f
,-1.0f
,0.0f
};
384 mdl_transform_vector( &ref
->transform
, dir
, dir
);
385 m3x3_mulv( localplayer
.invbasis
, dir
, dir
);
386 player_vector_angles( localplayer
.cam_override_angles
, dir
, 1.0f
, 0.0f
);
389 if( shop
->type
== k_skateshop_type_boardshop
||
390 shop
->type
== k_skateshop_type_worldshop
){
391 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
392 mdl_entity_id_id(shop
->boards
.id_display
) );
394 v3_sub( display
->transform
.co
, localplayer
.rb
.co
, lookat
);
397 else if( shop
->type
== k_skateshop_type_charshop
){
398 v3_sub( ref
->transform
.co
, localplayer
.rb
.co
, lookat
);
401 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
404 q_axis_angle( localplayer
.rb
.q
, (v3f
){0.0f
,1.0f
,0.0f
},
405 atan2f(lookat
[0],lookat
[2]) );
407 v3_copy( ref
->transform
.co
, localplayer
.cam_override_pos
);
408 localplayer
.cam_override_fov
= ref
->fov
;
409 localplayer
.cam_override_strength
= global_skateshop
.factive
;
412 if( shop
->type
== k_skateshop_type_boardshop
){
413 gui_helper_action( axis_display_string( k_sraxis_mbrowse_h
), "browse" );
414 gui_helper_action( button_display_string( k_srbind_mback
), "exit" );
416 struct cache_board
*selected_cache
= skateshop_selected_cache_if_loaded();
418 if( selected_cache
){
419 gui_helper_action( button_display_string( k_srbind_maccept
), "pick" );
424 * ----------------------
427 u32 opage
= global_skateshop
.selected_board_id
/SKATESHOP_VIEW_SLOT_MAX
;
429 if( button_down( k_srbind_mleft
) ){
430 if( global_skateshop
.selected_board_id
> 0 ){
431 global_skateshop
.selected_board_id
--;
435 if( button_down( k_srbind_mright
) ){
436 if( global_skateshop
.selected_board_id
+1 <
437 addon_count(k_workshop_file_type_board
) )
439 global_skateshop
.selected_board_id
++;
443 u32 npage
= global_skateshop
.selected_board_id
/SKATESHOP_VIEW_SLOT_MAX
;
445 if( opage
!= npage
){
446 skateshop_update_viewpage();
447 skateshop_op_processview();
449 else if( selected_cache
&& button_down( k_srbind_maccept
) ){
450 vg_info( "chose board from skateshop (%u)\n",
451 global_skateshop
.selected_board_id
);
453 if( localplayer
.board_view_slot
){
454 unwatch_cache_board( localplayer
.board_view_slot
);
457 localplayer
.board_view_slot
= selected_cache
;
458 watch_cache_board( localplayer
.board_view_slot
);
459 global_skateshop_exit();
460 skaterift_write_savedata();
464 else if( shop
->type
== k_skateshop_type_charshop
){
465 gui_helper_action( axis_display_string( k_sraxis_mbrowse_h
), "browse" );
466 gui_helper_action( button_display_string( k_srbind_mback
), "exit" );
467 gui_helper_action( button_display_string( k_srbind_maccept
), "pick" );
469 if( button_down( k_srbind_mleft
) ){
470 if( k_playermdl_id
> 0 ){
474 k_playermdl_id
= 2; /* HACK */
476 temp_update_playermodel(); /* HACK */
479 if( button_down( k_srbind_mright
) ){
480 if( k_playermdl_id
+1 < 3 ){
484 k_playermdl_id
= 0; /* HACK */
486 temp_update_playermodel(); /* HACK */
490 if( button_down( k_srbind_maccept
) ){
491 global_skateshop_exit();
494 else if( shop
->type
== k_skateshop_type_worldshop
){
498 if( addon_count(k_workshop_file_type_world
) &&
499 ((skaterift
.async_op
== k_async_op_none
)||
500 (skaterift
.async_op
== k_async_op_world_load_preview
))){
501 gui_helper_action( axis_display_string(k_sraxis_mbrowse_h
), "browse" );
505 if( (skaterift
.async_op
== k_async_op_none
) &&
506 global_skateshop
.selected_world_id
> 0 ){
507 gui_helper_action( button_display_string(k_srbind_maccept
),
515 if( button_down( k_srbind_mleft
) ){
516 if( global_skateshop
.selected_world_id
> 0 )
518 global_skateshop
.selected_world_id
--;
523 if( button_down( k_srbind_mright
) ){
524 if( global_skateshop
.selected_world_id
+1 <
525 addon_count(k_workshop_file_type_world
) )
527 global_skateshop
.selected_world_id
++;
533 if( change
&& pointcloud_idle() ){
534 pointcloud_animate( k_pointcloud_anim_hiding
);
537 if( skaterift
.async_op
== k_async_op_none
){
538 addon_reg
*reg
= get_addon_from_index( k_workshop_file_type_world
,
539 global_skateshop
.selected_world_id
);
541 /* automatically load in clouds */
542 if( loadable
&& button_down( k_srbind_maccept
) ){
543 vg_info( "Select rift (%u)\n",
544 global_skateshop
.selected_world_id
);
545 world_loader
.reg
= reg
;
546 world_loader
.override_name
[0] = '\0';
547 skaterift_change_world_start();
551 if( pointcloud
.anim
== k_pointcloud_anim_idle_closed
){
552 if( global_skateshop
.pointcloud_world_id
!=
553 global_skateshop
.selected_world_id
)
555 global_skateshop
.pointcloud_world_id
=
556 global_skateshop
.selected_world_id
;
557 skateshop_load_world_preview( reg
);
560 pointcloud_animate( k_pointcloud_anim_opening
);
563 else if( pointcloud
.anim
== k_pointcloud_anim_idle_open
){
564 if( global_skateshop
.pointcloud_world_id
!=
565 global_skateshop
.selected_world_id
)
567 pointcloud_animate( k_pointcloud_anim_hiding
);
574 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
577 if( button_down( k_srbind_mback
) ){
578 global_skateshop_exit();
583 VG_STATIC
void skateshop_render_boardshop(void)
585 world_instance
*world
= world_current_instance();
586 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
588 u32 slot_count
= vg_list_size(global_skateshop
.shop_view_slots
);
590 ent_marker
*mark_rack
= mdl_arritm( &world
->ent_marker
,
591 mdl_entity_id_id(shop
->boards
.id_rack
)),
592 *mark_display
= mdl_arritm( &world
->ent_marker
,
593 mdl_entity_id_id(shop
->boards
.id_display
));
595 int visibility
[ SKATESHOP_VIEW_SLOT_MAX
];
596 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
597 for( u32 i
=0; i
<SKATESHOP_VIEW_SLOT_MAX
; i
++ ){
598 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[i
];
602 if( slot
->cache_ptr
== NULL
) visibility
[i
] = 0;
603 else if( slot
->cache_ptr
->state
!= k_cache_board_state_loaded
)
606 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
608 /* Render loaded boards in the view slots */
609 for( u32 i
=0; i
<slot_count
; i
++ ){
610 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[i
];
611 float selected
= 0.0f
;
613 if( !visibility
[i
] ) goto fade_out
;
616 transform_identity( &xform
);
618 xform
.co
[0] = -((float)i
- ((float)slot_count
)*0.5f
)*0.45f
;
619 mdl_transform_mul( &mark_rack
->transform
, &xform
, &xform
);
621 if( slot
->cache_ptr
->reg_index
== global_skateshop
.selected_board_id
){
625 float t
= slot
->view_blend
;
626 v3_lerp( xform
.co
, mark_display
->transform
.co
, t
, xform
.co
);
627 q_nlerp( xform
.q
, mark_display
->transform
.q
, t
, xform
.q
);
628 v3_lerp( xform
.s
, mark_display
->transform
.s
, t
, xform
.s
);
631 mdl_transform_m4x3( &xform
, mmdl
);
632 render_board( &main_camera
, world
, &slot
->cache_ptr
->board
, mmdl
,
633 k_board_shader_entity
);
636 float rate
= 5.0f
*vg
.time_delta
;
637 slot
->view_blend
= vg_lerpf( slot
->view_blend
, selected
, rate
);
640 ent_marker
*mark_info
= mdl_arritm( &world
->ent_marker
,
641 mdl_entity_id_id(shop
->boards
.id_info
));
643 mdl_transform_m4x3( &mark_info
->transform
, mtext
);
644 mdl_transform_m4x3( &mark_rack
->transform
, mrack
);
647 const char *text_title
= "Fish - Title";
648 const char *text_author
= "by Shaniqua";
652 m4x3_identity( mlocal
);
657 font3d_bind( &gui
.font
, &main_camera
);
658 shader_model_font_uColour( (v4f
){1.0f
,1.0f
,1.0f
,1.0f
} );
661 * ------------------------------------------------------------------ */
663 v3_zero( mlocal
[3] );
664 mlocal
[0][0] = -scale
*2.0f
;
665 mlocal
[1][2] = -scale
*2.0f
;
666 mlocal
[2][1] = -thickness
;
667 mlocal
[3][2] = -0.7f
;
668 m4x3_mul( mrack
, mlocal
, mmdl
);
670 if( addon_count(k_workshop_file_type_board
) ){
673 i
+=highscore_intl( buf
+i
, global_skateshop
.selected_board_id
+1, 3 );
675 i
+=highscore_intl( buf
+i
, addon_count(k_workshop_file_type_board
), 3 );
678 font3d_simple_draw( &gui
.font
, 0, buf
, &main_camera
, mmdl
);
681 font3d_simple_draw( &gui
.font
, 0,
682 "Nothing installed", &main_camera
, mmdl
);
685 struct cache_board
*cache_ptr
= skateshop_selected_cache_if_loaded();
688 global_skateshop
.render
.item_title
= "";
689 global_skateshop
.render
.item_desc
= "";
693 if( global_skateshop
.render
.reg_id
!= global_skateshop
.selected_board_id
){
694 global_skateshop
.render
.item_title
= "";
695 global_skateshop
.render
.item_desc
= "";
696 addon_reg
*reg
= cache_ptr
->reg_ptr
;
698 root
.buf
= reg
->metadata
;
699 root
.len
= reg
->metadata_len
;
700 root
.max
= sizeof(reg
->metadata
);
702 vg_msg workshop
= root
;
703 if( vg_msg_seekframe( &workshop
, "workshop", 0 ) ){
704 const char *title
= vg_msg_seekkvstr( &workshop
, "title", 0 );
705 if( title
) global_skateshop
.render
.item_title
= title
;
707 const char *dsc
= vg_msg_seekkvstr( &workshop
, "author", 0 );
708 if( dsc
) global_skateshop
.render
.item_desc
= dsc
;
711 global_skateshop
.render
.reg_id
= global_skateshop
.selected_board_id
;
714 addon_reg
*reg
= cache_ptr
->reg_ptr
;
717 * ----------------------------------------------------------------- */
719 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
720 mlocal
[3][0] = -font3d_string_width( &gui
.font
, 0,
721 global_skateshop
.render
.item_title
);
722 mlocal
[3][0] *= scale
*0.5f
;
725 m4x3_mul( mtext
, mlocal
, mmdl
);
726 font3d_simple_draw( &gui
.font
, 0, global_skateshop
.render
.item_title
,
727 &main_camera
, mmdl
);
730 * ----------------------------------------------------------------- */
732 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
733 mlocal
[3][0] = -font3d_string_width( &gui
.font
, 0,
734 global_skateshop
.render
.item_desc
);
735 mlocal
[3][0] *= scale
*0.5f
;
738 m4x3_mul( mtext
, mlocal
, mmdl
);
739 font3d_simple_draw( &gui
.font
, 0, global_skateshop
.render
.item_desc
,
740 &main_camera
, mmdl
);
743 VG_STATIC
void skateshop_render_charshop(void)
747 VG_STATIC
void skateshop_render_worldshop(void)
749 world_instance
*world
= world_current_instance();
751 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
752 ent_marker
*mark_display
= mdl_arritm( &world
->ent_marker
,
753 mdl_entity_id_id(shop
->worlds
.id_display
)),
754 *mark_info
= mdl_arritm( &world
->ent_marker
,
755 mdl_entity_id_id(shop
->boards
.id_info
));
757 if( global_skateshop
.render
.world_reg
!= global_skateshop
.selected_world_id
){
758 global_skateshop
.render
.world_title
= "";
760 addon_reg
*reg
= get_addon_from_index( k_workshop_file_type_world
,
761 global_skateshop
.selected_world_id
);
763 root
.buf
= reg
->metadata
;
764 root
.len
= reg
->metadata_len
;
765 root
.max
= sizeof(reg
->metadata
);
766 vg_msg workshop
= root
;
767 if( vg_msg_seekframe( &workshop
, "workshop", 0 ) ){
768 global_skateshop
.render
.world_title
= vg_msg_seekkvstr( &workshop
,
771 global_skateshop
.render
.world_loc
= vg_msg_seekkvstr(&root
,"location",0);
772 global_skateshop
.render
.world_reg
= global_skateshop
.selected_world_id
;
776 char buftext
[128], bufsubtext
[128];
777 vg_str info
, subtext
;
778 vg_strnull( &info
, buftext
, 128 );
779 vg_strnull( &subtext
, bufsubtext
, 128 );
781 if( addon_count(k_workshop_file_type_world
) ){
782 addon_reg
*reg
= get_addon_from_index( k_workshop_file_type_world
,
783 global_skateshop
.selected_world_id
);
785 info
.i
+=highscore_intl( info
.buffer
+info
.i
,
786 global_skateshop
.selected_world_id
+1, 3 );
787 info
.buffer
[info
.i
++] = '/';
788 info
.i
+=highscore_intl( info
.buffer
+info
.i
,
789 addon_count(k_workshop_file_type_world
), 3 );
790 info
.buffer
[info
.i
++] = ' ';
791 info
.buffer
[info
.i
] = '\0';
793 vg_strcat( &info
, global_skateshop
.render
.world_title
);
794 if( skaterift
.async_op
== k_async_op_world_loading
||
795 skaterift
.async_op
== k_async_op_world_preloading
){
796 vg_strcat( &subtext
, "Loading..." );
799 addon_reg
*reg
= get_addon_from_index( k_workshop_file_type_world
,
800 global_skateshop
.selected_world_id
);
802 if( reg
->workshop_id
)
803 vg_strcat( &subtext
, "(Workshop) " );
805 vg_strcat( &subtext
, global_skateshop
.render
.world_loc
);
809 vg_strcat( &info
, "No worlds installed" );
813 m4x3f mtext
,mlocal
,mtextmdl
;
814 mdl_transform_m4x3( &mark_info
->transform
, mtext
);
816 font3d_bind( &gui
.font
, &main_camera
);
817 shader_model_font_uColour( (v4f
){1.0f
,1.0f
,1.0f
,1.0f
} );
819 float scale
= 0.2f
, thickness
= 0.015f
, scale1
= 0.08f
;
821 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
822 mlocal
[3][0] = -font3d_string_width( &gui
.font
, 0, buftext
);
823 mlocal
[3][0] *= scale
*0.5f
;
826 m4x3_mul( mtext
, mlocal
, mtextmdl
);
827 font3d_simple_draw( &gui
.font
, 0, buftext
, &main_camera
, mtextmdl
);
829 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale1
, scale1
, thickness
} );
830 mlocal
[3][0] = -font3d_string_width( &gui
.font
, 0, bufsubtext
);
831 mlocal
[3][0] *= scale1
*0.5f
;
832 mlocal
[3][1] = -scale1
*0.3f
;
833 m4x3_mul( mtext
, mlocal
, mtextmdl
);
834 font3d_simple_draw( &gui
.font
, 0, bufsubtext
, &main_camera
, mtextmdl
);
838 mdl_transform_m4x3( &mark_display
->transform
, mmdl
);
839 m4x3_rotate_y( mmdl
, vg
.time
* 0.2 );
842 glBlendFunc(GL_ONE
, GL_ONE
);
843 glDisable(GL_DEPTH_TEST
);
844 pointcloud_render( world
, &main_camera
, mmdl
);
846 glEnable(GL_DEPTH_TEST
);
850 * World: render event
852 VG_STATIC
void skateshop_render(void)
854 if( !global_skateshop
.active
) return;
856 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
858 if( shop
->type
== k_skateshop_type_boardshop
){
859 skateshop_render_boardshop();
861 else if( shop
->type
== k_skateshop_type_charshop
){
862 skateshop_render_charshop();
864 else if( shop
->type
== k_skateshop_type_worldshop
){
865 skateshop_render_worldshop();
868 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
873 * Entity logic: entrance event
875 VG_STATIC
void ent_skateshop_call( world_instance
*world
, ent_call
*call
)
877 u32 index
= mdl_entity_id_id( call
->id
);
878 ent_skateshop
*shop
= mdl_arritm( &world
->ent_skateshop
, index
);
879 vg_info( "skateshop_call\n" );
881 if( menu
.active
) return;
882 if( skaterift
.async_op
!= k_async_op_none
) return;
884 if( call
->function
== k_ent_function_trigger
){
885 if( localplayer
.subsystem
!= k_player_subsystem_walk
){
889 vg_info( "Entering skateshop\n" );
891 localplayer
.immobile
= 1;
892 menu
.disable_open
= 1;
893 global_skateshop
.active
= 1;
895 v3_zero( localplayer
.rb
.v
);
896 v3_zero( localplayer
.rb
.w
);
897 localplayer
._walk
.move_speed
= 0.0f
;
898 global_skateshop
.ptr_ent
= shop
;
900 if( shop
->type
== k_skateshop_type_boardshop
){
901 skateshop_update_viewpage();
902 skateshop_op_board_scan();
904 else if( shop
->type
== k_skateshop_type_worldshop
){
905 pointcloud_animate( k_pointcloud_anim_opening
);
906 skateshop_op_world_scan();
912 * Entity logic: exit event
914 VG_STATIC
void global_skateshop_exit(void)
916 vg_info( "exit skateshop\n" );
917 localplayer
.immobile
= 0;
918 global_skateshop
.active
= 0;
919 menu
.disable_open
= 0;
920 srinput
.ignore_input_frames
= 2;
923 #endif /* ENT_SKATESHOP_C */