new menu start
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_skateshop.c
1 #ifndef ENT_SKATESHOP_C
2 #define ENT_SKATESHOP_C
3
4 #define VG_GAME
5 #include "vg/vg.h"
6 #include "vg/vg_steam_ugc.h"
7 #include "ent_skateshop.h"
8 #include "world.h"
9 #include "player.h"
10 #include "gui.h"
11 #include "menu.h"
12
13 /*
14 * Checks string equality but does a hash check first
15 */
16 static inline int const_str_eq( u32 hash, const char *str, const char *cmp )
17 {
18 if( hash == vg_strdjb2(cmp) )
19 if( !strcmp( str, cmp ) )
20 return 1;
21 return 0;
22 }
23
24 /*
25 * Get an existing cache instance, allocate a new one to be loaded, or NULL if
26 * there is no space
27 */
28 VG_STATIC struct cache_board *skateshop_cache_fetch( u32 registry_index )
29 {
30 struct registry_board *reg = NULL;
31
32 if( registry_index < global_skateshop.registry_count ){
33 reg = &global_skateshop.registry[ registry_index ];
34
35 if( reg->cache_ptr ){
36 return reg->cache_ptr;
37 }
38 }
39
40 /* lru eviction. should be a linked list maybe... */
41 double min_time = 1e300;
42 struct cache_board *min_board = NULL;
43
44 SDL_AtomicLock( &global_skateshop.sl_cache_access );
45 for( u32 i=0; i<SKATESHOP_BOARD_CACHE_MAX; i++ ){
46 struct cache_board *cache_ptr = &global_skateshop.cache[i];
47
48 if( cache_ptr->state == k_cache_board_state_load_request ) continue;
49 if( cache_ptr->ref_count ) continue;
50
51 if( cache_ptr->last_use_time < min_time ){
52 min_time = cache_ptr->last_use_time;
53 min_board = cache_ptr;
54 }
55 }
56
57 if( min_board ){
58 if( min_board->state == k_cache_board_state_loaded ){
59 struct registry_board *other =
60 &global_skateshop.registry[ min_board->registry_id ];
61
62 vg_info( "Deallocating board: '%s'\n", min_board, other->filename );
63
64 player_board_unload( &min_board->board );
65 other->cache_ptr = NULL;
66 }
67
68 if( reg ){
69 vg_info( "Allocating board (reg:%u) '%s'\n",
70 registry_index, reg->filename );
71 }
72 else{
73 vg_info( "Pre-allocating board (reg:%u) 'null'\n", registry_index );
74 }
75
76 min_board->registry_id = registry_index;
77 min_board->last_use_time = vg.time;
78 min_board->ref_count = 0;
79 min_board->state = k_cache_board_state_load_request;
80 }
81 else{
82 vg_error( "No free boards to load registry!\n" );
83 }
84
85 SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
86 return min_board;
87 }
88
89 VG_STATIC void skateshop_update_viewpage(void)
90 {
91 u32 page = global_skateshop.selected_registry_id/SKATESHOP_VIEW_SLOT_MAX;
92
93 for( u32 i=0; i<SKATESHOP_VIEW_SLOT_MAX; i++ ){
94 struct shop_view_slot *slot = &global_skateshop.shop_view_slots[i];
95 u32 request_id = page*SKATESHOP_VIEW_SLOT_MAX + i;
96
97 if( slot->cache_ptr ) unwatch_cache_board( slot->cache_ptr );
98
99 slot->cache_ptr = skateshop_cache_fetch( request_id );
100 if( slot->cache_ptr ) watch_cache_board( slot->cache_ptr );
101 }
102 }
103
104 /* generic reciever */
105 VG_STATIC void workshop_async_any_complete( void *data, u32 size )
106 {
107 workshop_end_op();
108 }
109
110 /*
111 * op/subroutine: k_workshop_op_item_load
112 * -----------------------------------------------------------------------------
113 */
114
115 /*
116 * Reciever for board completion; only promotes the status in the main thread
117 */
118 VG_STATIC void skateshop_async_board_loaded( void *payload, u32 size )
119 {
120 SDL_AtomicLock( &global_skateshop.sl_cache_access );
121 struct cache_board *cache_ptr = payload;
122 cache_ptr->last_use_time = vg.time;
123 cache_ptr->state = k_cache_board_state_loaded;
124
125 struct registry_board *reg =
126 &global_skateshop.registry[ cache_ptr->registry_id ];
127 reg->cache_ptr = cache_ptr;
128 SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
129
130 vg_success( "Async board loaded (%s)\n", reg->filename );
131 }
132
133 /*
134 * Thread(or subroutine of thread), for checking view slots that weve installed.
135 * Load the model if a view slot wants it
136 */
137 VG_STATIC void workshop_visibile_load_loop_thread( void *_args )
138 {
139 char path[1024];
140 for( u32 i=0; i<SKATESHOP_BOARD_CACHE_MAX; i++ ){
141 struct cache_board *cache_ptr = &global_skateshop.cache[i];
142
143 SDL_AtomicLock( &global_skateshop.sl_cache_access );
144 if( cache_ptr->state == k_cache_board_state_load_request ){
145 if( cache_ptr->registry_id >= global_skateshop.registry_count ){
146 /* should maybe have a different value for this case */
147 cache_ptr->state = k_cache_board_state_none;
148 SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
149 continue;
150 }
151
152 /* continue with the request */
153 SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
154
155 struct registry_board *reg =
156 &global_skateshop.registry[ cache_ptr->registry_id ];
157
158 if( reg->workshop_id ){
159 vg_async_item *call =
160 vg_async_alloc( sizeof(struct async_workshop_filepath_info) );
161
162 struct async_workshop_filepath_info *info = call->payload;
163 info->buf = path;
164 info->id = reg->workshop_id;
165 info->len = vg_list_size(path) - strlen("/board.mdl")-1;
166 vg_async_dispatch( call, async_workshop_get_filepath );
167 vg_async_stall(); /* too bad! */
168
169 if( path[0] == '\0' ){
170 SDL_AtomicLock( &global_skateshop.sl_cache_access );
171 cache_ptr->state = k_cache_board_state_none;
172 SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
173
174 vg_error( "Failed SteamAPI_GetItemInstallInfo(" PRINTF_U64 ")\n",
175 reg->workshop_id );
176 continue;
177 }
178 else{
179 strcat( path, "/board.mdl" );
180 }
181 }
182 else{
183 snprintf( path, 256, "models/boards/%s", reg->filename );
184 }
185
186 player_board_load( &cache_ptr->board, path );
187 vg_async_call( skateshop_async_board_loaded, cache_ptr, 0 );
188 }
189 else
190 SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
191 }
192 vg_async_call( workshop_async_any_complete, NULL, 0 );
193 }
194
195 /*
196 * op: k_workshop_op_item_scan
197 * -----------------------------------------------------------------------------
198 */
199
200 /*
201 * Reciever for scan completion. copies the registry_count back into t0
202 */
203 VG_STATIC void workshop_async_reg_update( void *data, u32 size )
204 {
205 vg_info( "Registry update notify\n" );
206 global_skateshop.registry_count = global_skateshop.t1_registry_count;
207 }
208
209 VG_STATIC void workshop_steam_scan(void)
210 {
211 /*
212 * Steam workshop scan
213 */
214 vg_info( "Scanning steam workshop for boards\n" );
215 PublishedFileId_t workshop_ids[ SKATESHOP_REGISTRY_MAX ];
216 u32 workshop_count = SKATESHOP_REGISTRY_MAX;
217
218 vg_async_item *call = vg_async_alloc(
219 sizeof(struct async_workshop_installed_files_info));
220 struct async_workshop_installed_files_info *info = call->payload;
221 info->buffer = workshop_ids;
222 info->len = &workshop_count;
223 vg_async_dispatch( call, async_workshop_get_installed_files );
224 vg_async_stall();
225
226 for( u32 j=0; j<workshop_count; j++ ){
227 PublishedFileId_t id = workshop_ids[j];
228
229 for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
230 struct registry_board *reg = &global_skateshop.registry[i];
231
232 if( reg->workshop_id == id ){
233 reg->state = k_registry_board_state_indexed;
234 goto next_file_workshop;
235 }
236 }
237
238 if( global_skateshop.t1_registry_count == SKATESHOP_REGISTRY_MAX ){
239 vg_error( "You have too many boards installed!\n" );
240 break;
241 }
242
243 vg_info( "new listing from the steam workshop!: "PRINTF_U64"\n", id );
244
245 struct registry_board *reg = &global_skateshop.registry[
246 global_skateshop.t1_registry_count ++ ];
247
248 reg->cache_ptr = NULL;
249 snprintf( reg->filename, 64, PRINTF_U64, id );
250 reg->filename_hash = vg_strdjb2( reg->filename );
251 reg->workshop_id = id;
252 reg->state = k_registry_board_state_indexed;
253
254 workshop_file_info_clear( &reg->workshop );
255 strcpy( reg->workshop.title, "Workshop file" );
256
257 /* load the metadata off the disk */
258 vg_async_item *call =
259 vg_async_alloc( sizeof(struct async_workshop_filepath_info) );
260
261 const char *meta_file = "/board.mdl.inf";
262 char path[ 1024 ];
263 struct async_workshop_filepath_info *info = call->payload;
264 info->buf = path;
265 info->id = reg->workshop_id;
266 info->len = vg_list_size(path) - strlen(meta_file)-1;
267 vg_async_dispatch( call, async_workshop_get_filepath );
268 vg_async_stall(); /* too bad! */
269
270 strcat( path, meta_file );
271 workshop_load_metadata( path, &reg->workshop );
272
273 next_file_workshop:;
274 }
275 }
276
277 /*
278 * Async thread which scans local files for boards, as well as scheduling
279 * synchronous calls to the workshop
280 */
281 VG_STATIC void workshop_scan_thread( void *_args )
282 {
283 vg_linear_clear( vg_mem.scratch );
284
285 for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
286 struct registry_board *reg = &global_skateshop.registry[i];
287 reg->state = k_registry_board_state_indexed_absent;
288 }
289
290 /*
291 * Local disk scan
292 */
293 vg_info( "Scanning models/boards/*.mdl\n" );
294 tinydir_dir dir;
295 tinydir_open( &dir, "models/boards" );
296
297 while( dir.has_next ){
298 tinydir_file file;
299 tinydir_readfile( &dir, &file );
300
301 if( file.is_reg ){
302 u32 hash = vg_strdjb2( file.name );
303
304 for( u32 i=0; i<global_skateshop.t1_registry_count; i++ ){
305 struct registry_board *reg = &global_skateshop.registry[i];
306
307 if( const_str_eq( hash, file.name, reg->filename ) ){
308 reg->state = k_registry_board_state_indexed;
309 goto next_file;
310 }
311 }
312
313 if( global_skateshop.t1_registry_count == SKATESHOP_REGISTRY_MAX ){
314 vg_error( "You have too many boards installed!\n" );
315 break;
316 }
317
318 vg_info( "new listing!: %s\n", file.name );
319
320 struct registry_board *reg =
321 &global_skateshop.registry[global_skateshop.t1_registry_count ++];
322
323 reg->cache_ptr = NULL;
324 vg_strncpy( file.name, reg->filename, 64, k_strncpy_always_add_null );
325 vg_strncpy( file.name, reg->workshop.title,
326 64, k_strncpy_always_add_null );
327 reg->filename_hash = hash;
328 reg->workshop_id = 0;
329 reg->state = k_registry_board_state_indexed;
330 reg->workshop.author = 0;
331 strcpy( reg->workshop.author_name, "custom" );
332 }
333
334 next_file: tinydir_next( &dir );
335 }
336
337 tinydir_close(&dir);
338
339 if( steam_ready ) workshop_steam_scan();
340
341 vg_async_call( workshop_async_reg_update, NULL, 0 );
342 vg_async_stall();
343 workshop_visibile_load_loop_thread(NULL);
344 }
345
346 /*
347 * Asynchronous scan of local disk for items and add them to the registry
348 */
349 VG_STATIC void workshop_op_item_scan(void)
350 {
351 workshop_begin_op( k_workshop_op_item_scan );
352 vg_loader_start( workshop_scan_thread, NULL );
353 }
354
355 /*
356 * Regular stuff
357 * -----------------------------------------------------------------------------
358 */
359
360 /* we can only keep using a viewslot pointer for multiple frames if we watch it
361 * using this function */
362 VG_STATIC void watch_cache_board( struct cache_board *ptr )
363 {
364 if( ptr->ref_count >= 32 ){
365 vg_fatal_error( "dynamic board watch missmatch (limit is 32)\n" );
366 }
367
368 ptr->last_use_time = vg.time;
369 ptr->ref_count ++;
370 }
371
372 /* after this is called, the calling code only has access to the pointer for the
373 * duration of the rest of the frame */
374 VG_STATIC void unwatch_cache_board( struct cache_board *ptr )
375 {
376 if( ptr->ref_count == 0 ){
377 vg_fatal_error( "dynamic board unwatch missmatch (no watchers)\n" );
378 }
379
380 ptr->ref_count --;
381 }
382
383 /*
384 * Callback handler for persona state changes,
385 * it sets the author names on the registries
386 */
387 VG_STATIC void callback_persona_statechange( CallbackMsg_t *msg )
388 {
389 PersonaStateChange_t *info = (PersonaStateChange_t *)msg->m_pubParam;
390 ISteamFriends *hSteamFriends = SteamAPI_SteamFriends();
391
392 if( info->m_nChangeFlags & k_EPersonaChangeName ){
393 for( u32 i=0; i<global_skateshop.registry_count; i++ ){
394 struct registry_board *reg = &global_skateshop.registry[i];
395 if( reg->workshop.author == info->m_ulSteamID ){
396 const char *name = SteamAPI_ISteamFriends_GetFriendPersonaName(
397 hSteamFriends, info->m_ulSteamID );
398 str_utf8_collapse( name, reg->workshop.author_name, 32 );
399 }
400 }
401 }
402 }
403
404 /*
405 * VG event init
406 */
407 VG_STATIC void skateshop_init(void)
408 {
409 u32 reg_size = sizeof(struct registry_board)*SKATESHOP_REGISTRY_MAX,
410 cache_size = sizeof(struct cache_board)*SKATESHOP_BOARD_CACHE_MAX;
411
412 global_skateshop.registry = vg_linear_alloc( vg_mem.rtmemory, reg_size );
413 global_skateshop.registry_count = 0;
414 global_skateshop.cache = vg_linear_alloc( vg_mem.rtmemory, cache_size );
415
416 memset( global_skateshop.cache, 0, cache_size );
417
418 for( u32 i=0; i<SKATESHOP_BOARD_CACHE_MAX; i++ ){
419 struct cache_board *board = &global_skateshop.cache[i];
420 board->state = k_cache_board_state_none;
421 board->registry_id = 0xffffffff;
422 board->last_use_time = -99999.9;
423 board->ref_count = 0;
424 }
425
426 if( steam_ready ){
427 steam_register_callback( k_iPersonaStateChange,
428 callback_persona_statechange );
429 }
430 }
431
432 VG_STATIC struct cache_board *skateshop_selected_cache_if_loaded(void)
433 {
434 if( global_skateshop.registry_count > 0 ){
435 u32 reg_id = global_skateshop.selected_registry_id;
436 struct registry_board *reg = &global_skateshop.registry[ reg_id ];
437
438 SDL_AtomicLock( &global_skateshop.sl_cache_access );
439 if( reg->cache_ptr &&
440 (reg->cache_ptr->state == k_cache_board_state_loaded ) )
441 {
442 SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
443 return reg->cache_ptr;
444 }
445 SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
446 }
447
448 return NULL;
449 }
450
451 /*
452 * VG event preupdate
453 */
454 VG_STATIC void global_skateshop_preupdate(void)
455 {
456 float rate = vg_minf( 1.0f, vg.time_frame_delta * 2.0f );
457 global_skateshop.factive = vg_lerpf( global_skateshop.factive,
458 global_skateshop.active, rate );
459
460 if( !global_skateshop.active ) return;
461
462 world_instance *world = get_active_world();
463
464 ent_skateshop *shop = global_skateshop.ptr_ent;
465 ent_camera *ref = mdl_arritm( &world->ent_camera,
466 mdl_entity_id_id(shop->id_camera) );
467 ent_marker *display = mdl_arritm( &world->ent_marker,
468 mdl_entity_id_id(shop->id_display) );
469
470 v3f dir = {0.0f,-1.0f,0.0f};
471 mdl_transform_vector( &ref->transform, dir, dir );
472 player_vector_angles( localplayer.cam_override_angles, dir, 1.0f, 0.0f );
473
474 v3f lookat;
475 v3_sub( display->transform.co, localplayer.rb.co, lookat );
476
477 q_axis_angle( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f},
478 atan2f(lookat[0],lookat[2]) );
479
480 v3_copy( ref->transform.co, localplayer.cam_override_pos );
481 localplayer.cam_override_fov = ref->fov;
482 localplayer.cam_override_strength = global_skateshop.factive;
483
484 gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" );
485 gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
486
487 int moved = 0;
488 struct cache_board *selected_cache = skateshop_selected_cache_if_loaded();
489
490 if( selected_cache ){
491 gui_helper_action( button_display_string( k_srbind_maccept ), "pick" );
492 }
493
494 /*
495 * Controls
496 * ----------------------
497 */
498
499 if( global_skateshop.interaction_cooldown > 0.0f ){
500 global_skateshop.interaction_cooldown -= vg.time_delta;
501 return;
502 }
503
504 if( button_down( k_srbind_mleft ) ){
505 if( global_skateshop.selected_registry_id > 0 ){
506 global_skateshop.selected_registry_id --;
507 moved = 1;
508 }
509 }
510
511 if( button_down( k_srbind_mright ) ){
512 if( global_skateshop.selected_registry_id+1 <
513 global_skateshop.registry_count )
514 {
515 global_skateshop.selected_registry_id ++;
516 moved = 1;
517 }
518 }
519
520 if( moved ){
521 global_skateshop.interaction_cooldown = 0.125f;
522 return;
523 }
524
525 if( selected_cache && button_down( k_srbind_maccept ) ){
526 vg_info( "chose board from skateshop (%u)\n",
527 global_skateshop.selected_registry_id );
528
529 if( localplayer.board_view_slot ){
530 unwatch_cache_board( localplayer.board_view_slot );
531 }
532
533 localplayer.board_view_slot = selected_cache;
534 watch_cache_board( localplayer.board_view_slot );
535
536 global_skateshop_exit();
537 return;
538 }
539
540 if( button_down( k_srbind_mback ) ){
541 global_skateshop_exit();
542 return;
543 }
544 }
545
546 /*
547 * World: render event
548 */
549 VG_STATIC void skateshop_render(void)
550 {
551 if( !global_skateshop.active ) return;
552
553 ent_skateshop *shop = global_skateshop.ptr_ent;
554 world_instance *world = get_active_world();
555
556 u32 slot_count = vg_list_size(global_skateshop.shop_view_slots);
557
558 ent_marker *mark_rack = mdl_arritm( &world->ent_marker,
559 mdl_entity_id_id(shop->id_rack)),
560 *mark_display = mdl_arritm( &world->ent_marker,
561 mdl_entity_id_id(shop->id_display));
562
563 int visibility[ SKATESHOP_VIEW_SLOT_MAX ];
564 SDL_AtomicLock( &global_skateshop.sl_cache_access );
565 for( u32 i=0; i<SKATESHOP_VIEW_SLOT_MAX; i++ ){
566 struct shop_view_slot *slot = &global_skateshop.shop_view_slots[i];
567
568 visibility[i] = 1;
569
570 if( slot->cache_ptr == NULL ) visibility[i] = 0;
571 else if( slot->cache_ptr->state != k_cache_board_state_loaded )
572 visibility[i] = 0;
573 }
574 SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
575
576 /* Render loaded boards in the view slots */
577 for( u32 i=0; i<slot_count; i++ ){
578 struct shop_view_slot *slot = &global_skateshop.shop_view_slots[i];
579 float selected = 0.0f;
580
581 if( !visibility[i] ) goto fade_out;
582
583 mdl_transform xform;
584 transform_identity( &xform );
585
586 xform.co[0] = -((float)i - ((float)slot_count)*0.5f)*0.45f;
587 mdl_transform_mul( &mark_rack->transform, &xform, &xform );
588
589 if( slot->cache_ptr->registry_id ==
590 global_skateshop.selected_registry_id ){
591 selected = 1.0f;
592 }
593
594 float t = slot->view_blend;
595 v3_lerp( xform.co, mark_display->transform.co, t, xform.co );
596 q_nlerp( xform.q, mark_display->transform.q, t, xform.q );
597 v3_lerp( xform.s, mark_display->transform.s, t, xform.s );
598
599 m4x3f mmdl;
600 mdl_transform_m4x3( &xform, mmdl );
601 render_board( &main_camera, world, &slot->cache_ptr->board, mmdl,
602 k_board_shader_entity );
603
604 fade_out:;
605 float rate = 5.0f*vg.time_delta;
606 slot->view_blend = vg_lerpf( slot->view_blend, selected, rate );
607 }
608
609 ent_marker *mark_info = mdl_arritm( &world->ent_marker,
610 mdl_entity_id_id(shop->id_info));
611 m4x3f mtext, mrack;
612 mdl_transform_m4x3( &mark_info->transform, mtext );
613 mdl_transform_m4x3( &mark_rack->transform, mrack );
614
615 #if 0
616 const char *text_title = "Fish - Title";
617 const char *text_author = "by Shaniqua";
618 #endif
619
620 m4x3f mlocal, mmdl;
621 m4x3_identity( mlocal );
622
623 float scale = 0.2f,
624 thickness = 0.03f;
625
626 font3d_bind( &world_global.font, &main_camera );
627 shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
628
629 /* Selection counter
630 * ------------------------------------------------------------------ */
631 m3x3_zero( mlocal );
632 v3_zero( mlocal[3] );
633 mlocal[0][0] = -scale*2.0f;
634 mlocal[1][2] = -scale*2.0f;
635 mlocal[2][1] = -thickness;
636 mlocal[3][2] = -0.7f;
637 m4x3_mul( mrack, mlocal, mmdl );
638
639 if( global_skateshop.registry_count == 0 ){
640 font3d_simple_draw( &world_global.font, 0,
641 "Nothing installed", &main_camera, mmdl );
642 }
643 else{
644 char buf[16];
645 int i=0;
646 i+=highscore_intl( buf+i, global_skateshop.selected_registry_id+1, 3 );
647 buf[i++] = '/';
648 i+=highscore_intl( buf+i, global_skateshop.registry_count, 3 );
649 buf[i++] = '\0';
650
651 font3d_simple_draw( &world_global.font, 0, buf, &main_camera, mmdl );
652 }
653
654 struct cache_board *cache_ptr = skateshop_selected_cache_if_loaded();
655 if( !cache_ptr ) return;
656
657 struct registry_board *reg =
658 &global_skateshop.registry[cache_ptr->registry_id];
659 struct workshop_file_info *info = &reg->workshop;
660
661 /* Skin title
662 * ----------------------------------------------------------------- */
663 m3x3_zero( mlocal );
664 m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
665 mlocal[3][0] = -font3d_string_width( &world_global.font, 0, info->title );
666 mlocal[3][0] *= scale*0.5f;
667 mlocal[3][1] = 0.1f;
668 m4x3_mul( mtext, mlocal, mmdl );
669 font3d_simple_draw( &world_global.font, 0, info->title, &main_camera, mmdl );
670
671 /* Author name
672 * ----------------------------------------------------------------- */
673 scale *= 0.4f;
674 m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
675 mlocal[3][0] = -font3d_string_width( &world_global.font, 0,
676 info->author_name );
677 mlocal[3][0] *= scale*0.5f;
678 mlocal[3][1] = 0.0f;
679 m4x3_mul( mtext, mlocal, mmdl );
680 font3d_simple_draw( &world_global.font, 0,
681 info->author_name, &main_camera, mmdl );
682 }
683
684 /*
685 * Entity logic: entrance event
686 */
687 VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
688 {
689 u32 index = mdl_entity_id_id( call->id );
690 ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, index );
691 vg_info( "skateshop_call\n" );
692
693 if( menu.active ) return;
694
695 if( call->function == k_ent_function_trigger ){
696 if( localplayer.subsystem != k_player_subsystem_walk ){
697 return;
698 }
699
700 vg_info( "Entering skateshop\n" );
701
702 localplayer.immobile = 1;
703 menu.disable_open = 1;
704 global_skateshop.active = 1;
705
706 v3_zero( localplayer.rb.v );
707 v3_zero( localplayer.rb.w );
708 localplayer._walk.move_speed = 0.0f;
709 global_skateshop.ptr_ent = shop;
710
711 skateshop_update_viewpage();
712 workshop_op_item_scan();
713 }
714 }
715
716 /*
717 * Entity logic: exit event
718 */
719 VG_STATIC void global_skateshop_exit(void)
720 {
721 vg_info( "exit skateshop\n" );
722 localplayer.immobile = 0;
723 global_skateshop.active = 0;
724 menu.disable_open = 0;
725 srinput.ignore_input_frames = 2;
726 }
727
728 #endif /* ENT_SKATESHOP_C */