1 #ifndef ENT_SKATESHOP_C
2 #define ENT_SKATESHOP_C
6 #include "vg/vg_steam_ugc.h"
7 #include "ent_skateshop.h"
12 #include "pointcloud.h"
15 * Checks string equality but does a hash check first
17 static inline int const_str_eq( u32 hash
, const char *str
, const char *cmp
)
19 if( hash
== vg_strdjb2(cmp
) )
20 if( !strcmp( str
, cmp
) )
26 * Get an existing cache instance, allocate a new one to be loaded, or NULL if
29 VG_STATIC
struct cache_board
*skateshop_cache_fetch( u32 registry_index
)
31 struct registry_board
*reg
= NULL
;
33 if( registry_index
< global_skateshop
.registry_count
){
34 reg
= &global_skateshop
.registry
[ registry_index
];
37 return reg
->cache_ptr
;
41 /* lru eviction. should be a linked list maybe... */
42 double min_time
= 1e300
;
43 struct cache_board
*min_board
= NULL
;
45 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
46 for( u32 i
=0; i
<SKATESHOP_BOARD_CACHE_MAX
; i
++ ){
47 struct cache_board
*cache_ptr
= &global_skateshop
.cache
[i
];
49 if( cache_ptr
->state
== k_cache_board_state_load_request
) continue;
50 if( cache_ptr
->ref_count
) continue;
52 if( cache_ptr
->last_use_time
< min_time
){
53 min_time
= cache_ptr
->last_use_time
;
54 min_board
= cache_ptr
;
59 if( min_board
->state
== k_cache_board_state_loaded
){
60 struct registry_board
*other
=
61 &global_skateshop
.registry
[ min_board
->registry_id
];
63 vg_info( "Deallocating board: '%s'\n", min_board
, other
->filename
);
65 player_board_unload( &min_board
->board
);
66 other
->cache_ptr
= NULL
;
70 vg_info( "Allocating board (reg:%u) '%s'\n",
71 registry_index
, reg
->filename
);
74 vg_info( "Pre-allocating board (reg:%u) 'null'\n", registry_index
);
77 min_board
->registry_id
= 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_registry_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( request_id
);
101 if( slot
->cache_ptr
) watch_cache_board( slot
->cache_ptr
);
105 /* generic reciever */
106 VG_STATIC
void workshop_async_any_complete( void *data
, u32 size
)
112 * op/subroutine: k_workshop_op_item_load
113 * -----------------------------------------------------------------------------
117 * Reciever for board completion; only promotes the status in the main thread
119 VG_STATIC
void skateshop_async_board_loaded( void *payload
, u32 size
)
121 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
122 struct cache_board
*cache_ptr
= payload
;
123 cache_ptr
->last_use_time
= vg
.time
;
124 cache_ptr
->state
= k_cache_board_state_loaded
;
126 struct registry_board
*reg
=
127 &global_skateshop
.registry
[ cache_ptr
->registry_id
];
128 reg
->cache_ptr
= cache_ptr
;
129 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
131 vg_success( "Async board loaded (%s)\n", reg
->filename
);
135 * Thread(or subroutine of thread), for checking view slots that weve installed.
136 * Load the model if a view slot wants it
138 VG_STATIC
void workshop_visibile_load_loop_thread( void *_args
)
141 for( u32 i
=0; i
<SKATESHOP_BOARD_CACHE_MAX
; i
++ ){
142 struct cache_board
*cache_ptr
= &global_skateshop
.cache
[i
];
144 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
145 if( cache_ptr
->state
== k_cache_board_state_load_request
){
146 if( cache_ptr
->registry_id
>= global_skateshop
.registry_count
){
147 /* should maybe have a different value for this case */
148 cache_ptr
->state
= k_cache_board_state_none
;
149 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
153 /* continue with the request */
154 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
156 struct registry_board
*reg
=
157 &global_skateshop
.registry
[ cache_ptr
->registry_id
];
159 if( reg
->workshop_id
){
160 vg_async_item
*call
=
161 vg_async_alloc( sizeof(struct async_workshop_filepath_info
) );
163 struct async_workshop_filepath_info
*info
= call
->payload
;
165 info
->id
= reg
->workshop_id
;
166 info
->len
= vg_list_size(path
) - strlen("/board.mdl")-1;
167 vg_async_dispatch( call
, async_workshop_get_filepath
);
168 vg_async_stall(); /* too bad! */
170 if( path
[0] == '\0' ){
171 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
172 cache_ptr
->state
= k_cache_board_state_none
;
173 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
175 vg_error( "Failed SteamAPI_GetItemInstallInfo(" PRINTF_U64
")\n",
180 strcat( path
, "/board.mdl" );
184 snprintf( path
, 256, "models/boards/%s", reg
->filename
);
187 player_board_load( &cache_ptr
->board
, path
);
188 vg_async_call( skateshop_async_board_loaded
, cache_ptr
, 0 );
191 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
193 vg_async_call( workshop_async_any_complete
, NULL
, 0 );
197 * op: k_workshop_op_item_scan
198 * -----------------------------------------------------------------------------
202 * Reciever for scan completion. copies the registry_count back into t0
204 VG_STATIC
void workshop_async_reg_update( void *data
, u32 size
)
206 vg_info( "Registry update notify\n" );
207 global_skateshop
.registry_count
= global_skateshop
.t1_registry_count
;
210 VG_STATIC
void workshop_steam_scan(void)
213 * Steam workshop scan
215 vg_info( "Scanning steam workshop for boards\n" );
216 PublishedFileId_t workshop_ids
[ SKATESHOP_REGISTRY_MAX
];
217 u32 workshop_count
= SKATESHOP_REGISTRY_MAX
;
219 vg_async_item
*call
= vg_async_alloc(
220 sizeof(struct async_workshop_installed_files_info
));
221 struct async_workshop_installed_files_info
*info
= call
->payload
;
222 info
->buffer
= workshop_ids
;
223 info
->len
= &workshop_count
;
224 vg_async_dispatch( call
, async_workshop_get_installed_files
);
227 for( u32 j
=0; j
<workshop_count
; j
++ ){
228 PublishedFileId_t id
= workshop_ids
[j
];
230 for( u32 i
=0; i
<global_skateshop
.t1_registry_count
; i
++ ){
231 struct registry_board
*reg
= &global_skateshop
.registry
[i
];
233 if( reg
->workshop_id
== id
){
234 reg
->state
= k_registry_board_state_indexed
;
235 goto next_file_workshop
;
239 if( global_skateshop
.t1_registry_count
== SKATESHOP_REGISTRY_MAX
){
240 vg_error( "You have too many boards installed!\n" );
244 vg_info( "new listing from the steam workshop!: "PRINTF_U64
"\n", id
);
246 struct registry_board
*reg
= &global_skateshop
.registry
[
247 global_skateshop
.t1_registry_count
++ ];
249 reg
->cache_ptr
= NULL
;
250 snprintf( reg
->filename
, 64, PRINTF_U64
, id
);
251 reg
->filename_hash
= vg_strdjb2( reg
->filename
);
252 reg
->workshop_id
= id
;
253 reg
->state
= k_registry_board_state_indexed
;
255 workshop_file_info_clear( ®
->workshop
);
256 strcpy( reg
->workshop
.title
, "Workshop file" );
258 /* load the metadata off the disk */
259 vg_async_item
*call
=
260 vg_async_alloc( sizeof(struct async_workshop_filepath_info
) );
262 const char *meta_file
= "/board.mdl.inf";
264 struct async_workshop_filepath_info
*info
= call
->payload
;
266 info
->id
= reg
->workshop_id
;
267 info
->len
= vg_list_size(path
) - strlen(meta_file
)-1;
268 vg_async_dispatch( call
, async_workshop_get_filepath
);
269 vg_async_stall(); /* too bad! */
271 strcat( path
, meta_file
);
272 workshop_load_metadata( path
, ®
->workshop
);
279 * Async thread which scans local files for boards, as well as scheduling
280 * synchronous calls to the workshop
282 VG_STATIC
void workshop_scan_thread( void *_args
)
284 vg_linear_clear( vg_mem
.scratch
);
286 for( u32 i
=0; i
<global_skateshop
.t1_registry_count
; i
++ ){
287 struct registry_board
*reg
= &global_skateshop
.registry
[i
];
288 reg
->state
= k_registry_board_state_indexed_absent
;
294 vg_info( "Scanning models/boards/*.mdl\n" );
296 tinydir_open( &dir
, "models/boards" );
298 while( dir
.has_next
){
300 tinydir_readfile( &dir
, &file
);
303 u32 hash
= vg_strdjb2( file
.name
);
305 for( u32 i
=0; i
<global_skateshop
.t1_registry_count
; i
++ ){
306 struct registry_board
*reg
= &global_skateshop
.registry
[i
];
308 if( const_str_eq( hash
, file
.name
, reg
->filename
) ){
309 reg
->state
= k_registry_board_state_indexed
;
314 if( global_skateshop
.t1_registry_count
== SKATESHOP_REGISTRY_MAX
){
315 vg_error( "You have too many boards installed!\n" );
319 vg_info( "new listing!: %s\n", file
.name
);
321 struct registry_board
*reg
=
322 &global_skateshop
.registry
[global_skateshop
.t1_registry_count
++];
324 reg
->cache_ptr
= NULL
;
325 vg_strncpy( file
.name
, reg
->filename
, 64, k_strncpy_always_add_null
);
326 vg_strncpy( file
.name
, reg
->workshop
.title
,
327 64, k_strncpy_always_add_null
);
328 reg
->filename_hash
= hash
;
329 reg
->workshop_id
= 0;
330 reg
->state
= k_registry_board_state_indexed
;
331 reg
->workshop
.author
= 0;
332 strcpy( reg
->workshop
.author_name
, "custom" );
335 next_file
: tinydir_next( &dir
);
340 if( steam_ready
) workshop_steam_scan();
342 vg_async_call( workshop_async_reg_update
, NULL
, 0 );
344 workshop_visibile_load_loop_thread(NULL
);
348 * Asynchronous scan of local disk for items and add them to the registry
350 VG_STATIC
void workshop_op_item_scan(void)
352 skaterift_begin_op( k_workshop_op_item_scan
);
353 vg_loader_start( workshop_scan_thread
, NULL
);
358 * -----------------------------------------------------------------------------
361 /* we can only keep using a viewslot pointer for multiple frames if we watch it
362 * using this function */
363 VG_STATIC
void watch_cache_board( struct cache_board
*ptr
)
365 if( ptr
->ref_count
>= 32 ){
366 vg_fatal_error( "dynamic board watch missmatch (limit is 32)\n" );
369 ptr
->last_use_time
= vg
.time
;
373 /* after this is called, the calling code only has access to the pointer for the
374 * duration of the rest of the frame */
375 VG_STATIC
void unwatch_cache_board( struct cache_board
*ptr
)
377 if( ptr
->ref_count
== 0 ){
378 vg_fatal_error( "dynamic board unwatch missmatch (no watchers)\n" );
385 * Callback handler for persona state changes,
386 * it sets the author names on the registries
388 VG_STATIC
void callback_persona_statechange( CallbackMsg_t
*msg
)
390 PersonaStateChange_t
*info
= (PersonaStateChange_t
*)msg
->m_pubParam
;
391 ISteamFriends
*hSteamFriends
= SteamAPI_SteamFriends();
393 if( info
->m_nChangeFlags
& k_EPersonaChangeName
){
394 for( u32 i
=0; i
<global_skateshop
.registry_count
; i
++ ){
395 struct registry_board
*reg
= &global_skateshop
.registry
[i
];
396 if( reg
->workshop
.author
== info
->m_ulSteamID
){
397 const char *name
= SteamAPI_ISteamFriends_GetFriendPersonaName(
398 hSteamFriends
, info
->m_ulSteamID
);
399 str_utf8_collapse( name
, reg
->workshop
.author_name
, 32 );
408 VG_STATIC
void skateshop_init(void)
410 u32 reg_size
= sizeof(struct registry_board
)*SKATESHOP_REGISTRY_MAX
,
411 cache_size
= sizeof(struct cache_board
)*SKATESHOP_BOARD_CACHE_MAX
;
413 global_skateshop
.registry
= vg_linear_alloc( vg_mem
.rtmemory
, reg_size
);
414 global_skateshop
.registry_count
= 0;
415 global_skateshop
.cache
= vg_linear_alloc( vg_mem
.rtmemory
, cache_size
);
417 memset( global_skateshop
.cache
, 0, cache_size
);
419 for( u32 i
=0; i
<SKATESHOP_BOARD_CACHE_MAX
; i
++ ){
420 struct cache_board
*board
= &global_skateshop
.cache
[i
];
421 board
->state
= k_cache_board_state_none
;
422 board
->registry_id
= 0xffffffff;
423 board
->last_use_time
= -99999.9;
424 board
->ref_count
= 0;
428 steam_register_callback( k_iPersonaStateChange
,
429 callback_persona_statechange
);
433 VG_STATIC
struct cache_board
*skateshop_selected_cache_if_loaded(void)
435 if( global_skateshop
.registry_count
> 0 ){
436 u32 reg_id
= global_skateshop
.selected_registry_id
;
437 struct registry_board
*reg
= &global_skateshop
.registry
[ reg_id
];
439 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
440 if( reg
->cache_ptr
&&
441 (reg
->cache_ptr
->state
== k_cache_board_state_loaded
) )
443 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
444 return reg
->cache_ptr
;
446 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
455 void temp_update_playermodel(void);
456 VG_STATIC
void global_skateshop_preupdate(void)
458 float rate
= vg_minf( 1.0f
, vg
.time_frame_delta
* 2.0f
);
459 global_skateshop
.factive
= vg_lerpf( global_skateshop
.factive
,
460 global_skateshop
.active
, rate
);
462 if( !global_skateshop
.active
) return;
464 world_instance
*world
= get_active_world();
466 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
468 /* camera positioning */
469 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
470 mdl_entity_id_id(shop
->id_camera
) );
472 v3f dir
= {0.0f
,-1.0f
,0.0f
};
473 mdl_transform_vector( &ref
->transform
, dir
, dir
);
474 m3x3_mulv( localplayer
.invbasis
, dir
, dir
);
475 player_vector_angles( localplayer
.cam_override_angles
, dir
, 1.0f
, 0.0f
);
478 if( shop
->type
== k_skateshop_type_boardshop
||
479 shop
->type
== k_skateshop_type_worldshop
){
480 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
481 mdl_entity_id_id(shop
->boards
.id_display
) );
483 v3_sub( display
->transform
.co
, localplayer
.rb
.co
, lookat
);
486 else if( shop
->type
== k_skateshop_type_charshop
){
487 v3_sub( ref
->transform
.co
, localplayer
.rb
.co
, lookat
);
490 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
493 q_axis_angle( localplayer
.rb
.q
, (v3f
){0.0f
,1.0f
,0.0f
},
494 atan2f(lookat
[0],lookat
[2]) );
496 v3_copy( ref
->transform
.co
, localplayer
.cam_override_pos
);
497 localplayer
.cam_override_fov
= ref
->fov
;
498 localplayer
.cam_override_strength
= global_skateshop
.factive
;
501 if( shop
->type
== k_skateshop_type_boardshop
){
502 gui_helper_action( axis_display_string( k_sraxis_mbrowse_h
), "browse" );
503 gui_helper_action( button_display_string( k_srbind_mback
), "exit" );
505 struct cache_board
*selected_cache
= skateshop_selected_cache_if_loaded();
507 if( selected_cache
){
508 gui_helper_action( button_display_string( k_srbind_maccept
), "pick" );
513 * ----------------------
516 if( button_down( k_srbind_mleft
) ){
517 if( global_skateshop
.selected_registry_id
> 0 ){
518 global_skateshop
.selected_registry_id
--;
522 if( button_down( k_srbind_mright
) ){
523 if( global_skateshop
.selected_registry_id
+1 <
524 global_skateshop
.registry_count
)
526 global_skateshop
.selected_registry_id
++;
530 if( selected_cache
&& button_down( k_srbind_maccept
) ){
531 vg_info( "chose board from skateshop (%u)\n",
532 global_skateshop
.selected_registry_id
);
534 if( localplayer
.board_view_slot
){
535 unwatch_cache_board( localplayer
.board_view_slot
);
538 localplayer
.board_view_slot
= selected_cache
;
539 watch_cache_board( localplayer
.board_view_slot
);
541 global_skateshop_exit();
545 else if( shop
->type
== k_skateshop_type_charshop
){
546 gui_helper_action( axis_display_string( k_sraxis_mbrowse_h
), "browse" );
547 gui_helper_action( button_display_string( k_srbind_mback
), "exit" );
548 gui_helper_action( button_display_string( k_srbind_maccept
), "pick" );
550 if( button_down( k_srbind_mleft
) ){
551 if( cl_playermdl_id
> 0 ){
555 cl_playermdl_id
= 2; /* HACK */
557 temp_update_playermodel(); /* HACK */
560 if( button_down( k_srbind_mright
) ){
561 if( cl_playermdl_id
+1 < 3 ){
565 cl_playermdl_id
= 0; /* HACK */
567 temp_update_playermodel(); /* HACK */
571 if( button_down( k_srbind_maccept
) ){
572 global_skateshop_exit();
575 else if( shop
->type
== k_skateshop_type_worldshop
){
576 gui_helper_action( axis_display_string( k_sraxis_mbrowse_h
), "browse" );
579 joystick_state( k_srjoystick_steer
, input
);
580 pointcloud
.control
[0] += input
[0] * vg
.time_delta
;
581 pointcloud
.control
[2] += input
[1] * vg
.time_delta
;
583 pointcloud
.control
[0] = vg_clampf( pointcloud
.control
[0], -10.0f
, 10.0f
);
584 pointcloud
.control
[2] = vg_clampf( pointcloud
.control
[2], -10.0f
, 10.0f
);
586 if( button_press( k_srbind_trick1
) ){
587 pointcloud
.control
[3] += vg
.time_delta
*0.2f
;
589 if( button_press( k_srbind_trick0
) ){
590 pointcloud
.control
[3] -= vg
.time_delta
*0.2f
;
592 pointcloud
.control
[3] = vg_clampf( pointcloud
.control
[3], 0.001f
, 10.0f
);
595 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
598 if( button_down( k_srbind_mback
) ){
599 global_skateshop_exit();
604 VG_STATIC
void skateshop_render_boardshop(void)
606 world_instance
*world
= get_active_world();
607 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
609 u32 slot_count
= vg_list_size(global_skateshop
.shop_view_slots
);
611 ent_marker
*mark_rack
= mdl_arritm( &world
->ent_marker
,
612 mdl_entity_id_id(shop
->boards
.id_rack
)),
613 *mark_display
= mdl_arritm( &world
->ent_marker
,
614 mdl_entity_id_id(shop
->boards
.id_display
));
616 int visibility
[ SKATESHOP_VIEW_SLOT_MAX
];
617 SDL_AtomicLock( &global_skateshop
.sl_cache_access
);
618 for( u32 i
=0; i
<SKATESHOP_VIEW_SLOT_MAX
; i
++ ){
619 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[i
];
623 if( slot
->cache_ptr
== NULL
) visibility
[i
] = 0;
624 else if( slot
->cache_ptr
->state
!= k_cache_board_state_loaded
)
627 SDL_AtomicUnlock( &global_skateshop
.sl_cache_access
);
629 /* Render loaded boards in the view slots */
630 for( u32 i
=0; i
<slot_count
; i
++ ){
631 struct shop_view_slot
*slot
= &global_skateshop
.shop_view_slots
[i
];
632 float selected
= 0.0f
;
634 if( !visibility
[i
] ) goto fade_out
;
637 transform_identity( &xform
);
639 xform
.co
[0] = -((float)i
- ((float)slot_count
)*0.5f
)*0.45f
;
640 mdl_transform_mul( &mark_rack
->transform
, &xform
, &xform
);
642 if( slot
->cache_ptr
->registry_id
==
643 global_skateshop
.selected_registry_id
){
647 float t
= slot
->view_blend
;
648 v3_lerp( xform
.co
, mark_display
->transform
.co
, t
, xform
.co
);
649 q_nlerp( xform
.q
, mark_display
->transform
.q
, t
, xform
.q
);
650 v3_lerp( xform
.s
, mark_display
->transform
.s
, t
, xform
.s
);
653 mdl_transform_m4x3( &xform
, mmdl
);
654 render_board( &main_camera
, world
, &slot
->cache_ptr
->board
, mmdl
,
655 k_board_shader_entity
);
658 float rate
= 5.0f
*vg
.time_delta
;
659 slot
->view_blend
= vg_lerpf( slot
->view_blend
, selected
, rate
);
662 ent_marker
*mark_info
= mdl_arritm( &world
->ent_marker
,
663 mdl_entity_id_id(shop
->boards
.id_info
));
665 mdl_transform_m4x3( &mark_info
->transform
, mtext
);
666 mdl_transform_m4x3( &mark_rack
->transform
, mrack
);
669 const char *text_title
= "Fish - Title";
670 const char *text_author
= "by Shaniqua";
674 m4x3_identity( mlocal
);
679 font3d_bind( &world_global
.font
, &main_camera
);
680 shader_model_font_uColour( (v4f
){1.0f
,1.0f
,1.0f
,1.0f
} );
683 * ------------------------------------------------------------------ */
685 v3_zero( mlocal
[3] );
686 mlocal
[0][0] = -scale
*2.0f
;
687 mlocal
[1][2] = -scale
*2.0f
;
688 mlocal
[2][1] = -thickness
;
689 mlocal
[3][2] = -0.7f
;
690 m4x3_mul( mrack
, mlocal
, mmdl
);
692 if( global_skateshop
.registry_count
== 0 ){
693 font3d_simple_draw( &world_global
.font
, 0,
694 "Nothing installed", &main_camera
, mmdl
);
699 i
+=highscore_intl( buf
+i
, global_skateshop
.selected_registry_id
+1, 3 );
701 i
+=highscore_intl( buf
+i
, global_skateshop
.registry_count
, 3 );
704 font3d_simple_draw( &world_global
.font
, 0, buf
, &main_camera
, mmdl
);
707 struct cache_board
*cache_ptr
= skateshop_selected_cache_if_loaded();
708 if( !cache_ptr
) return;
710 struct registry_board
*reg
=
711 &global_skateshop
.registry
[cache_ptr
->registry_id
];
712 struct workshop_file_info
*info
= ®
->workshop
;
715 * ----------------------------------------------------------------- */
717 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
718 mlocal
[3][0] = -font3d_string_width( &world_global
.font
, 0, info
->title
);
719 mlocal
[3][0] *= scale
*0.5f
;
721 m4x3_mul( mtext
, mlocal
, mmdl
);
722 font3d_simple_draw( &world_global
.font
, 0, info
->title
, &main_camera
, mmdl
);
725 * ----------------------------------------------------------------- */
727 m3x3_setdiagonalv3( mlocal
, (v3f
){ scale
, scale
, thickness
} );
728 mlocal
[3][0] = -font3d_string_width( &world_global
.font
, 0,
730 mlocal
[3][0] *= scale
*0.5f
;
732 m4x3_mul( mtext
, mlocal
, mmdl
);
733 font3d_simple_draw( &world_global
.font
, 0,
734 info
->author_name
, &main_camera
, mmdl
);
737 VG_STATIC
void skateshop_render_charshop(void)
741 VG_STATIC
void skateshop_render_worldshop(void)
743 world_instance
*world
= get_active_world();
746 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
747 ent_marker
*mark_display
= mdl_arritm( &world
->ent_marker
,
748 mdl_entity_id_id(shop
->worlds
.id_display
));
749 mdl_transform_m4x3( &mark_display
->transform
, mmdl
);
753 v3_sub( world
->scene_geo
.bbx
[1], world
->scene_geo
.bbx
[0], vol
);
755 v2f rect
= { 1.0f
, 1.0f
},
756 map
= { vol
[0], vol
[2] },
759 f32 rp
= rect
[0] * map
[1],
760 rc
= rect
[1] * map
[0];
763 if( rc
> rp
) axis
= 0;
767 result
[axis
] = rect
[axis
];
768 result
[other
] = (rect
[axis
] * map
[other
]) / map
[axis
];
771 m4x3_identity( mlocal
);
773 mlocal
[0][0] = result
[0];
774 mlocal
[2][2] = result
[1];
775 mlocal
[1][1] = (vol
[1]/vol
[0]) * mlocal
[0][0];
776 mlocal
[3][0] = (rect
[0]-result
[0])*0.5f
- rect
[0]*0.5f
; /* sea level? */
777 mlocal
[3][2] = (rect
[1]-result
[1])*0.5f
- rect
[1]*0.5f
;
778 m4x3_mul( mmdl
, mlocal
, mx
);
782 glBlendFunc(GL_ONE
, GL_ONE
);
783 glDisable(GL_DEPTH_TEST
);
785 pointcloud_render( world
, &main_camera
, mx
);
787 glEnable(GL_DEPTH_TEST
);
791 * World: render event
793 VG_STATIC
void skateshop_render(void)
795 if( !global_skateshop
.active
) return;
797 ent_skateshop
*shop
= global_skateshop
.ptr_ent
;
799 if( shop
->type
== k_skateshop_type_boardshop
){
800 skateshop_render_boardshop();
802 else if( shop
->type
== k_skateshop_type_charshop
){
803 skateshop_render_charshop();
805 else if( shop
->type
== k_skateshop_type_worldshop
){
806 skateshop_render_worldshop();
809 vg_fatal_error( "Unknown store (%u)\n", shop
->type
);
814 * Entity logic: entrance event
816 VG_STATIC
void ent_skateshop_call( world_instance
*world
, ent_call
*call
)
818 u32 index
= mdl_entity_id_id( call
->id
);
819 ent_skateshop
*shop
= mdl_arritm( &world
->ent_skateshop
, index
);
820 vg_info( "skateshop_call\n" );
822 if( menu
.active
) return;
823 if( skaterift
.async_op
!= k_async_op_none
) return;
825 if( call
->function
== k_ent_function_trigger
){
826 if( localplayer
.subsystem
!= k_player_subsystem_walk
){
830 vg_info( "Entering skateshop\n" );
832 localplayer
.immobile
= 1;
833 menu
.disable_open
= 1;
834 global_skateshop
.active
= 1;
836 v3_zero( localplayer
.rb
.v
);
837 v3_zero( localplayer
.rb
.w
);
838 localplayer
._walk
.move_speed
= 0.0f
;
839 global_skateshop
.ptr_ent
= shop
;
841 if( shop
->type
== k_skateshop_type_boardshop
){
842 skateshop_update_viewpage();
843 workshop_op_item_scan();
849 * Entity logic: exit event
851 VG_STATIC
void global_skateshop_exit(void)
853 vg_info( "exit skateshop\n" );
854 localplayer
.immobile
= 0;
855 global_skateshop
.active
= 0;
856 menu
.disable_open
= 0;
857 srinput
.ignore_input_frames
= 2;
860 #endif /* ENT_SKATESHOP_C */