camera basis
[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 void temp_update_playermodel(void);
455 VG_STATIC void global_skateshop_preupdate(void)
456 {
457 float rate = vg_minf( 1.0f, vg.time_frame_delta * 2.0f );
458 global_skateshop.factive = vg_lerpf( global_skateshop.factive,
459 global_skateshop.active, rate );
460
461 if( !global_skateshop.active ) return;
462
463 world_instance *world = get_active_world();
464
465 ent_skateshop *shop = global_skateshop.ptr_ent;
466
467 /* camera positioning */
468 ent_camera *ref = mdl_arritm( &world->ent_camera,
469 mdl_entity_id_id(shop->id_camera) );
470
471 v3f dir = {0.0f,-1.0f,0.0f};
472 mdl_transform_vector( &ref->transform, dir, dir );
473 m3x3_mulv( localplayer.invbasis, dir, dir );
474 player_vector_angles( localplayer.cam_override_angles, dir, 1.0f, 0.0f );
475
476 v3f lookat;
477 if( shop->type == k_skateshop_type_boardshop ){
478 ent_marker *display = mdl_arritm( &world->ent_marker,
479 mdl_entity_id_id(shop->boards.id_display) );
480
481 v3_sub( display->transform.co, localplayer.rb.co, lookat );
482
483 }
484 else if( shop->type == k_skateshop_type_charshop ){
485 v3_sub( ref->transform.co, localplayer.rb.co, lookat );
486 }
487 else{
488 vg_fatal_error( "Unknown store (%u)\n", shop->type );
489 }
490
491 q_axis_angle( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f},
492 atan2f(lookat[0],lookat[2]) );
493
494 v3_copy( ref->transform.co, localplayer.cam_override_pos );
495 localplayer.cam_override_fov = ref->fov;
496 localplayer.cam_override_strength = global_skateshop.factive;
497
498 /* input */
499 if( shop->type == k_skateshop_type_boardshop ){
500 gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" );
501 gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
502
503 struct cache_board *selected_cache = skateshop_selected_cache_if_loaded();
504
505 if( selected_cache ){
506 gui_helper_action( button_display_string( k_srbind_maccept ), "pick" );
507 }
508
509 /*
510 * Controls
511 * ----------------------
512 */
513
514 if( button_down( k_srbind_mleft ) ){
515 if( global_skateshop.selected_registry_id > 0 ){
516 global_skateshop.selected_registry_id --;
517 }
518 }
519
520 if( button_down( k_srbind_mright ) ){
521 if( global_skateshop.selected_registry_id+1 <
522 global_skateshop.registry_count )
523 {
524 global_skateshop.selected_registry_id ++;
525 }
526 }
527
528 if( selected_cache && button_down( k_srbind_maccept ) ){
529 vg_info( "chose board from skateshop (%u)\n",
530 global_skateshop.selected_registry_id );
531
532 if( localplayer.board_view_slot ){
533 unwatch_cache_board( localplayer.board_view_slot );
534 }
535
536 localplayer.board_view_slot = selected_cache;
537 watch_cache_board( localplayer.board_view_slot );
538
539 global_skateshop_exit();
540 return;
541 }
542 }
543 else if( shop->type == k_skateshop_type_charshop ){
544 gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" );
545 gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
546 gui_helper_action( button_display_string( k_srbind_maccept ), "pick" );
547
548 if( button_down( k_srbind_mleft ) ){
549 if( cl_playermdl_id > 0 ){
550 cl_playermdl_id --;
551 }
552 else{
553 cl_playermdl_id = 2; /* HACK */
554 }
555 temp_update_playermodel(); /* HACK */
556 }
557
558 if( button_down( k_srbind_mright ) ){
559 if( cl_playermdl_id+1 < 3 ){
560 cl_playermdl_id ++;
561 }
562 else{
563 cl_playermdl_id = 0; /* HACK */
564 }
565 temp_update_playermodel(); /* HACK */
566 /*lol*/
567 }
568
569 if( button_down( k_srbind_maccept ) ){
570 global_skateshop_exit();
571 }
572 }
573 else{
574 vg_fatal_error( "Unknown store (%u)\n", shop->type );
575 }
576
577 if( button_down( k_srbind_mback ) ){
578 global_skateshop_exit();
579 return;
580 }
581 }
582
583 VG_STATIC void skateshop_render_boardshop(void)
584 {
585 world_instance *world = get_active_world();
586 ent_skateshop *shop = global_skateshop.ptr_ent;
587
588 u32 slot_count = vg_list_size(global_skateshop.shop_view_slots);
589
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));
594
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];
599
600 visibility[i] = 1;
601
602 if( slot->cache_ptr == NULL ) visibility[i] = 0;
603 else if( slot->cache_ptr->state != k_cache_board_state_loaded )
604 visibility[i] = 0;
605 }
606 SDL_AtomicUnlock( &global_skateshop.sl_cache_access );
607
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;
612
613 if( !visibility[i] ) goto fade_out;
614
615 mdl_transform xform;
616 transform_identity( &xform );
617
618 xform.co[0] = -((float)i - ((float)slot_count)*0.5f)*0.45f;
619 mdl_transform_mul( &mark_rack->transform, &xform, &xform );
620
621 if( slot->cache_ptr->registry_id ==
622 global_skateshop.selected_registry_id ){
623 selected = 1.0f;
624 }
625
626 float t = slot->view_blend;
627 v3_lerp( xform.co, mark_display->transform.co, t, xform.co );
628 q_nlerp( xform.q, mark_display->transform.q, t, xform.q );
629 v3_lerp( xform.s, mark_display->transform.s, t, xform.s );
630
631 m4x3f mmdl;
632 mdl_transform_m4x3( &xform, mmdl );
633 render_board( &main_camera, world, &slot->cache_ptr->board, mmdl,
634 k_board_shader_entity );
635
636 fade_out:;
637 float rate = 5.0f*vg.time_delta;
638 slot->view_blend = vg_lerpf( slot->view_blend, selected, rate );
639 }
640
641 ent_marker *mark_info = mdl_arritm( &world->ent_marker,
642 mdl_entity_id_id(shop->boards.id_info));
643 m4x3f mtext, mrack;
644 mdl_transform_m4x3( &mark_info->transform, mtext );
645 mdl_transform_m4x3( &mark_rack->transform, mrack );
646
647 #if 0
648 const char *text_title = "Fish - Title";
649 const char *text_author = "by Shaniqua";
650 #endif
651
652 m4x3f mlocal, mmdl;
653 m4x3_identity( mlocal );
654
655 float scale = 0.2f,
656 thickness = 0.03f;
657
658 font3d_bind( &world_global.font, &main_camera );
659 shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
660
661 /* Selection counter
662 * ------------------------------------------------------------------ */
663 m3x3_zero( mlocal );
664 v3_zero( mlocal[3] );
665 mlocal[0][0] = -scale*2.0f;
666 mlocal[1][2] = -scale*2.0f;
667 mlocal[2][1] = -thickness;
668 mlocal[3][2] = -0.7f;
669 m4x3_mul( mrack, mlocal, mmdl );
670
671 if( global_skateshop.registry_count == 0 ){
672 font3d_simple_draw( &world_global.font, 0,
673 "Nothing installed", &main_camera, mmdl );
674 }
675 else{
676 char buf[16];
677 int i=0;
678 i+=highscore_intl( buf+i, global_skateshop.selected_registry_id+1, 3 );
679 buf[i++] = '/';
680 i+=highscore_intl( buf+i, global_skateshop.registry_count, 3 );
681 buf[i++] = '\0';
682
683 font3d_simple_draw( &world_global.font, 0, buf, &main_camera, mmdl );
684 }
685
686 struct cache_board *cache_ptr = skateshop_selected_cache_if_loaded();
687 if( !cache_ptr ) return;
688
689 struct registry_board *reg =
690 &global_skateshop.registry[cache_ptr->registry_id];
691 struct workshop_file_info *info = &reg->workshop;
692
693 /* Skin title
694 * ----------------------------------------------------------------- */
695 m3x3_zero( mlocal );
696 m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
697 mlocal[3][0] = -font3d_string_width( &world_global.font, 0, info->title );
698 mlocal[3][0] *= scale*0.5f;
699 mlocal[3][1] = 0.1f;
700 m4x3_mul( mtext, mlocal, mmdl );
701 font3d_simple_draw( &world_global.font, 0, info->title, &main_camera, mmdl );
702
703 /* Author name
704 * ----------------------------------------------------------------- */
705 scale *= 0.4f;
706 m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
707 mlocal[3][0] = -font3d_string_width( &world_global.font, 0,
708 info->author_name );
709 mlocal[3][0] *= scale*0.5f;
710 mlocal[3][1] = 0.0f;
711 m4x3_mul( mtext, mlocal, mmdl );
712 font3d_simple_draw( &world_global.font, 0,
713 info->author_name, &main_camera, mmdl );
714 }
715
716 VG_STATIC void skateshop_render_charshop(void)
717 {
718 }
719
720 /*
721 * World: render event
722 */
723 VG_STATIC void skateshop_render(void)
724 {
725 if( !global_skateshop.active ) return;
726
727 ent_skateshop *shop = global_skateshop.ptr_ent;
728
729 if( shop->type == k_skateshop_type_boardshop ){
730 skateshop_render_boardshop();
731 }
732 else if( shop->type == k_skateshop_type_charshop ){
733 skateshop_render_charshop();
734 }
735 else{
736 vg_fatal_error( "Unknown store (%u)\n", shop->type );
737 }
738 }
739
740 /*
741 * Entity logic: entrance event
742 */
743 VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
744 {
745 u32 index = mdl_entity_id_id( call->id );
746 ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, index );
747 vg_info( "skateshop_call\n" );
748
749 if( menu.active ) return;
750
751 if( call->function == k_ent_function_trigger ){
752 if( localplayer.subsystem != k_player_subsystem_walk ){
753 return;
754 }
755
756 vg_info( "Entering skateshop\n" );
757
758 localplayer.immobile = 1;
759 menu.disable_open = 1;
760 global_skateshop.active = 1;
761
762 v3_zero( localplayer.rb.v );
763 v3_zero( localplayer.rb.w );
764 localplayer._walk.move_speed = 0.0f;
765 global_skateshop.ptr_ent = shop;
766
767 if( shop->type == k_skateshop_type_boardshop ){
768 skateshop_update_viewpage();
769 workshop_op_item_scan();
770 }
771 }
772 }
773
774 /*
775 * Entity logic: exit event
776 */
777 VG_STATIC void global_skateshop_exit(void)
778 {
779 vg_info( "exit skateshop\n" );
780 localplayer.immobile = 0;
781 global_skateshop.active = 0;
782 menu.disable_open = 0;
783 srinput.ignore_input_frames = 2;
784 }
785
786 #endif /* ENT_SKATESHOP_C */