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