update overlay to have ps controls too
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_skateshop.c
1 #include "vg/vg_steam_ugc.h"
2 #include "vg/vg_msg.h"
3 #include "vg/vg_tex.h"
4 #include "vg/vg_image.h"
5 #include "vg/vg_loader.h"
6 #include "ent_skateshop.h"
7 #include "world.h"
8 #include "player.h"
9 #include "gui.h"
10 #include "menu.h"
11 #include "steam.h"
12 #include "addon.h"
13 #include "save.h"
14 #include "network.h"
15
16 struct global_skateshop global_skateshop =
17 {
18 .render={.reg_id=0xffffffff,.world_reg=0xffffffff}
19 };
20
21 /*
22 * Checks string equality but does a hash check first
23 */
24 static inline int const_str_eq( u32 hash, const char *str, const char *cmp )
25 {
26 if( hash == vg_strdjb2(cmp) )
27 if( !strcmp( str, cmp ) )
28 return 1;
29 return 0;
30 }
31
32 static void skateshop_update_viewpage(void){
33 u32 page = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
34
35 for( u32 i=0; i<SKATESHOP_VIEW_SLOT_MAX; i++ ){
36 u32 j = SKATESHOP_VIEW_SLOT_MAX-1-i;
37 struct shop_view_slot *slot = &global_skateshop.shop_view_slots[j];
38 addon_cache_unwatch( k_addon_type_board, slot->cache_id );
39 }
40
41 for( u32 i=0; i<SKATESHOP_VIEW_SLOT_MAX; i++ ){
42 struct shop_view_slot *slot = &global_skateshop.shop_view_slots[i];
43 u32 request_id = page*SKATESHOP_VIEW_SLOT_MAX + i;
44 slot->cache_id = addon_cache_create_viewer( k_addon_type_board,
45 request_id );
46 }
47 }
48
49 struct async_preview_load_thread_data{
50 void *data;
51 addon_reg *reg;
52 };
53
54 static void skateshop_async_preview_imageload( void *data, u32 len ){
55 struct async_preview_load_thread_data *inf = data;
56
57 if( inf->data ){
58 glBindTexture( GL_TEXTURE_2D, global_skateshop.tex_preview );
59 glTexSubImage2D( GL_TEXTURE_2D, 0,0,0,
60 WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT,
61 GL_RGB, GL_UNSIGNED_BYTE, inf->data );
62 glGenerateMipmap( GL_TEXTURE_2D );
63 stbi_image_free( inf->data );
64
65 skaterift.rt_textures[k_skaterift_rt_workshop_preview] =
66 global_skateshop.tex_preview;
67 }
68 else {
69 skaterift.rt_textures[k_skaterift_rt_workshop_preview] = vg.tex_missing;
70 }
71
72 SDL_AtomicLock( &addon_system.sl_cache_using_resources );
73 global_skateshop.reg_loaded_preview = inf->reg;
74 SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
75 }
76
77 static void skateshop_update_preview_image_thread(void *_args)
78 {
79 char path_buf[4096];
80 vg_str folder;
81 vg_strnull( &folder, path_buf, sizeof(path_buf) );
82
83 SDL_AtomicLock( &addon_system.sl_cache_using_resources );
84 addon_reg *reg_preview = global_skateshop.reg_preview;
85 SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
86
87 if( !addon_get_content_folder( reg_preview, &folder, 1 ) )
88 {
89 SDL_AtomicLock( &addon_system.sl_cache_using_resources );
90 global_skateshop.reg_loaded_preview = reg_preview;
91 SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
92 return;
93 }
94
95 vg_strcat( &folder, "/preview.jpg" );
96 vg_async_item *call =
97 vg_async_alloc( sizeof(struct async_preview_load_thread_data) );
98 struct async_preview_load_thread_data *inf = call->payload;
99
100 inf->reg = reg_preview;
101
102 if( vg_strgood( &folder ) )
103 {
104 stbi_set_flip_vertically_on_load(1);
105 int x, y, nc;
106 inf->data = stbi_load( folder.buffer, &x, &y, &nc, 3 );
107
108 if( inf->data )
109 {
110 if( (x != WORKSHOP_PREVIEW_WIDTH) || (y != WORKSHOP_PREVIEW_HEIGHT) )
111 {
112 vg_error( "Resolution does not match framebuffer, so we can't"
113 " show it\n" );
114 stbi_image_free( inf->data );
115 inf->data = NULL;
116 }
117 }
118
119 vg_async_dispatch( call, skateshop_async_preview_imageload );
120 }
121 else
122 {
123 vg_error( "Path too long to workshop preview image.\n" );
124
125 SDL_AtomicLock( &addon_system.sl_cache_using_resources );
126 global_skateshop.reg_loaded_preview = reg_preview;
127 SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
128 }
129 }
130
131 void skateshop_world_preview_preupdate(void)
132 {
133 /* try to load preview image if we availible to do. */
134 if( vg_loader_availible() )
135 {
136 SDL_AtomicLock( &addon_system.sl_cache_using_resources );
137 if( global_skateshop.reg_preview != global_skateshop.reg_loaded_preview )
138 {
139 SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
140 vg_loader_start( skateshop_update_preview_image_thread, NULL );
141 }
142 else SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
143 }
144 }
145
146 /*
147 * op/subroutine: k_workshop_op_item_load
148 * -----------------------------------------------------------------------------
149 */
150
151 /*
152 * Regular stuff
153 * -----------------------------------------------------------------------------
154 */
155
156 static void skateshop_init_async(void *_data,u32 size){
157 glGenTextures( 1, &global_skateshop.tex_preview );
158 glBindTexture( GL_TEXTURE_2D, global_skateshop.tex_preview );
159 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
160 WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT,
161 0, GL_RGB, GL_UNSIGNED_BYTE, NULL );
162
163 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
164 GL_LINEAR_MIPMAP_LINEAR );
165 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
166 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
167 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
168
169 skaterift.rt_textures[ k_skaterift_rt_workshop_preview ] = vg.tex_missing;
170 skaterift.rt_textures[ k_skaterift_rt_server_status ] = vg.tex_missing;
171 render_server_status_gui();
172 }
173
174 /*
175 * VG event init
176 */
177 void skateshop_init(void)
178 {
179 vg_async_call( skateshop_init_async, NULL, 0 );
180 }
181
182 static u16 skateshop_selected_cache_id(void){
183 if( addon_count(k_addon_type_board, ADDON_REG_HIDDEN) ){
184 addon_reg *reg = get_addon_from_index(
185 k_addon_type_board, global_skateshop.selected_board_id,
186 ADDON_REG_HIDDEN );
187 return reg->cache_id;
188 }
189 else return 0;
190 }
191
192 static void skateshop_server_helper_update(void){
193 vg_str text;
194 vg_strnull( &text, global_skateshop.helper_toggle->text,
195 sizeof(global_skateshop.helper_toggle->text) );
196
197 if( skaterift.demo_mode ){
198 vg_strcat( &text, "Not availible in demo" );
199 }
200 else {
201 if( network_client.user_intent == k_server_intent_online )
202 vg_strcat( &text, "Disconnect" );
203 else
204 vg_strcat( &text, "Go Online" );
205 }
206 }
207
208 /*
209 * VG event preupdate
210 */
211 void temp_update_playermodel(void);
212 void ent_skateshop_preupdate( ent_focus_context *ctx )
213 {
214 if( !ctx->active )
215 return;
216
217 world_instance *world = ctx->world;
218 ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, ctx->index );
219
220 /* camera positioning */
221 ent_camera *ref = mdl_arritm( &world->ent_camera,
222 mdl_entity_id_id(shop->id_camera) );
223
224 v3f dir = {0.0f,-1.0f,0.0f};
225 mdl_transform_vector( &ref->transform, dir, dir );
226 v3_angles( dir, world_static.focus_cam.angles );
227
228 v3f lookat;
229 if( shop->type == k_skateshop_type_boardshop ||
230 shop->type == k_skateshop_type_worldshop ){
231 ent_marker *display = mdl_arritm( &world->ent_marker,
232 mdl_entity_id_id(shop->boards.id_display) );
233 v3_sub( display->transform.co, localplayer.rb.co, lookat );
234 }
235 else if( shop->type == k_skateshop_type_charshop ){
236 v3_sub( ref->transform.co, localplayer.rb.co, lookat );
237 }
238 else if( shop->type == k_skateshop_type_server ){
239 ent_prop *prop = mdl_arritm( &world->ent_prop,
240 mdl_entity_id_id(shop->server.id_lever) );
241 v3_sub( prop->transform.co, localplayer.rb.co, lookat );
242 }
243 else
244 vg_fatal_error( "Unknown store (%u)\n", shop->type );
245
246 q_axis_angle( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f},
247 atan2f(lookat[0],lookat[2]) );
248
249 v3_copy( ref->transform.co, world_static.focus_cam.pos );
250 world_static.focus_cam.fov = ref->fov;
251
252 /* input */
253 if( shop->type == k_skateshop_type_boardshop ){
254 if( !vg_loader_availible() ) return;
255
256 u16 cache_id = skateshop_selected_cache_id();
257 global_skateshop.helper_pick->greyed = !cache_id;
258
259 /*
260 * Controls
261 * ----------------------
262 */
263 u32 opage = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
264
265 if( button_down( k_srbind_mleft ) ){
266 if( global_skateshop.selected_board_id > 0 ){
267 global_skateshop.selected_board_id --;
268 }
269 }
270
271 u32 valid_count = addon_count( k_addon_type_board, 0 );
272 if( button_down( k_srbind_mright ) ){
273 if( global_skateshop.selected_board_id+1 < valid_count ){
274 global_skateshop.selected_board_id ++;
275 }
276 }
277
278 u32 npage = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
279
280 if( opage != npage ){
281 skateshop_update_viewpage();
282 }
283 else if( cache_id && button_down( k_srbind_maccept )){
284 vg_info( "chose board from skateshop (%u)\n",
285 global_skateshop.selected_board_id );
286
287 addon_cache_unwatch( k_addon_type_board, localplayer.board_view_slot );
288 addon_cache_watch( k_addon_type_board, cache_id );
289 localplayer.board_view_slot = cache_id;
290 network_send_item( k_netmsg_playeritem_board );
291
292 world_entity_exit_modal();
293 world_entity_clear_focus();
294 gui_helper_clear();
295 skaterift_autosave(1);
296 return;
297 }
298 }
299 else if( shop->type == k_skateshop_type_charshop ){
300 if( !vg_loader_availible() ) return;
301
302 int changed = 0;
303 u32 valid_count = addon_count( k_addon_type_player, ADDON_REG_HIDDEN );
304
305 if( button_down( k_srbind_mleft ) ){
306 if( global_skateshop.selected_player_id > 0 ){
307 global_skateshop.selected_player_id --;
308 }
309 else{
310 global_skateshop.selected_player_id = valid_count-1;
311 }
312
313 changed = 1;
314 }
315
316 if( button_down( k_srbind_mright ) ){
317 if( global_skateshop.selected_player_id+1 < valid_count ){
318 global_skateshop.selected_player_id ++;
319 }
320 else{
321 global_skateshop.selected_player_id = 0;
322 }
323
324 changed = 1;
325 }
326
327 if( changed ){
328 addon_reg *addon = get_addon_from_index(
329 k_addon_type_player, global_skateshop.selected_player_id,
330 ADDON_REG_HIDDEN );
331
332 u32 real_id = get_index_from_addon(
333 k_addon_type_player, addon );
334
335 player__use_model( real_id );
336 }
337
338 if( button_down( k_srbind_maccept ) ){
339 network_send_item( k_netmsg_playeritem_player );
340 world_entity_exit_modal();
341 world_entity_clear_focus();
342 gui_helper_clear();
343 }
344 }
345 else if( shop->type == k_skateshop_type_worldshop ){
346 int browseable = 0,
347 loadable = 0;
348
349 u32 valid_count = addon_count( k_addon_type_world, ADDON_REG_HIDDEN );
350
351 if( valid_count && vg_loader_availible() )
352 browseable = 1;
353
354 if( valid_count && vg_loader_availible() )
355 loadable = 1;
356
357 global_skateshop.helper_browse->greyed = !browseable;
358 global_skateshop.helper_pick->greyed = !loadable;
359
360 addon_reg *selected_world = NULL;
361
362 int change = 0;
363 if( browseable ){
364 if( button_down( k_srbind_mleft ) ){
365 if( global_skateshop.selected_world_id > 0 ){
366 global_skateshop.selected_world_id --;
367 change = 1;
368 }
369 }
370
371 if( button_down( k_srbind_mright ) ){
372 if( global_skateshop.selected_world_id+1 < valid_count ){
373 global_skateshop.selected_world_id ++;
374 change = 1;
375 }
376 }
377
378 selected_world = get_addon_from_index( k_addon_type_world,
379 global_skateshop.selected_world_id, ADDON_REG_HIDDEN );
380
381 if( change || (global_skateshop.reg_preview == NULL) ){
382 SDL_AtomicLock( &addon_system.sl_cache_using_resources );
383 global_skateshop.reg_preview = selected_world;
384 SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
385 }
386 }
387
388 if( loadable ){
389 if( button_down( k_srbind_maccept ) ){
390 skaterift_change_world_start( selected_world );
391 }
392 }
393 }
394 else if( shop->type == k_skateshop_type_server ){
395 f64 delta = vg.time_real - network_client.last_intent_change;
396
397 if( (delta > 5.0) && (!skaterift.demo_mode) ){
398 global_skateshop.helper_pick->greyed = 0;
399 if( button_down( k_srbind_maccept ) ){
400 network_client.user_intent = !network_client.user_intent;
401 network_client.last_intent_change = vg.time_real;
402 skateshop_server_helper_update();
403 render_server_status_gui();
404 }
405 }
406 else {
407 global_skateshop.helper_pick->greyed = 1;
408 }
409 }
410 else{
411 vg_fatal_error( "Unknown store (%u)\n", shop->type );
412 }
413
414 if( button_down( k_srbind_mback ) )
415 {
416 if( shop->type == k_skateshop_type_charshop )
417 network_send_item( k_netmsg_playeritem_player );
418
419 world_entity_exit_modal();
420 world_entity_clear_focus();
421 gui_helper_clear();
422 return;
423 }
424 }
425
426 void skateshop_world_preupdate( world_instance *world )
427 {
428 for( u32 i=0; i<mdl_arrcount(&world->ent_skateshop); i++ ){
429 ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, i );
430
431 if( shop->type == k_skateshop_type_server ){
432 f32 a = network_client.user_intent;
433
434 vg_slewf( &network_client.fintent, a, vg.time_frame_delta );
435 a = (vg_smoothstepf( network_client.fintent ) - 0.5f) * (VG_PIf/2.0f);
436
437 ent_prop *lever = mdl_arritm( &world->ent_prop,
438 mdl_entity_id_id(shop->server.id_lever) );
439
440 /* we need parent transforms now? */
441 q_axis_angle( lever->transform.q, (v3f){0,0,1}, a );
442 }
443 }
444 }
445
446 static void skateshop_render_boardshop( ent_skateshop *shop ){
447 world_instance *world = world_current_instance();
448 u32 slot_count = vg_list_size(global_skateshop.shop_view_slots);
449
450 ent_marker *mark_rack = mdl_arritm( &world->ent_marker,
451 mdl_entity_id_id(shop->boards.id_rack)),
452 *mark_display = mdl_arritm( &world->ent_marker,
453 mdl_entity_id_id(shop->boards.id_display));
454
455 SDL_AtomicLock( &addon_system.sl_cache_using_resources );
456 struct addon_cache *cache = &addon_system.cache[k_addon_type_board];
457
458 /* Render loaded boards in the view slots */
459 for( u32 i=0; i<slot_count; i++ ){
460 struct shop_view_slot *slot = &global_skateshop.shop_view_slots[i];
461 float selected = 0.0f;
462
463 if( !slot->cache_id )
464 goto fade_out;
465
466 addon_cache_entry *entry = vg_pool_item( &cache->pool, slot->cache_id );
467
468 if( entry->state != k_addon_cache_state_loaded )
469 goto fade_out;
470
471 struct player_board *board =
472 addon_cache_item( k_addon_type_board, slot->cache_id );
473
474 mdl_transform xform;
475 transform_identity( &xform );
476
477 xform.co[0] = -((float)i - ((float)slot_count)*0.5f)*0.45f;
478 mdl_transform_mul( &mark_rack->transform, &xform, &xform );
479
480
481 if( entry->reg_index == global_skateshop.selected_board_id ){
482 selected = 1.0f;
483 }
484
485 float t = slot->view_blend;
486 v3_lerp( xform.co, mark_display->transform.co, t, xform.co );
487 q_nlerp( xform.q, mark_display->transform.q, t, xform.q );
488 v3_lerp( xform.s, mark_display->transform.s, t, xform.s );
489
490 struct player_board_pose pose = {0};
491 m4x3f mmdl;
492 mdl_transform_m4x3( &xform, mmdl );
493 render_board( &skaterift.cam, world, board, mmdl,
494 &pose, k_board_shader_entity );
495
496 fade_out:;
497 float rate = 5.0f*vg.time_delta;
498 slot->view_blend = vg_lerpf( slot->view_blend, selected, rate );
499 }
500
501 ent_marker *mark_info = mdl_arritm( &world->ent_marker,
502 mdl_entity_id_id(shop->boards.id_info));
503 m4x3f mtext, mrack;
504 mdl_transform_m4x3( &mark_info->transform, mtext );
505 mdl_transform_m4x3( &mark_rack->transform, mrack );
506
507 m4x3f mlocal, mmdl;
508 m4x3_identity( mlocal );
509
510 float scale = 0.2f,
511 thickness = 0.03f;
512
513 font3d_bind( &gui.font, k_font_shader_default, 0, world, &skaterift.cam );
514 shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
515
516 /* Selection counter
517 * ------------------------------------------------------------------ */
518 m3x3_zero( mlocal );
519 v3_zero( mlocal[3] );
520 mlocal[0][0] = -scale*2.0f;
521 mlocal[1][2] = -scale*2.0f;
522 mlocal[2][1] = -thickness;
523 mlocal[3][2] = -0.7f;
524 m4x3_mul( mrack, mlocal, mmdl );
525
526 u32 valid_count = addon_count(k_addon_type_board,0);
527 if( valid_count ){
528 char buf[16];
529 vg_str str;
530 vg_strnull( &str, buf, sizeof(buf) );
531 vg_strcati32( &str, global_skateshop.selected_board_id+1 );
532 vg_strcatch( &str, '/' );
533 vg_strcati32( &str, valid_count );
534 font3d_simple_draw( 0, buf, &skaterift.cam, mmdl );
535 }
536 else{
537 font3d_simple_draw( 0, "Nothing installed", &skaterift.cam, mmdl );
538 }
539
540 u16 cache_id = skateshop_selected_cache_id();
541 struct addon_cache_entry *entry = vg_pool_item( &cache->pool, cache_id );
542 addon_reg *reg = NULL;
543
544 if( entry ) reg = entry->reg_ptr;
545
546 if( !reg ){
547 SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
548 global_skateshop.render.item_title = "";
549 global_skateshop.render.item_desc = "";
550 return;
551 }
552
553 if( global_skateshop.render.reg_id != global_skateshop.selected_board_id ){
554 global_skateshop.render.item_title = "";
555 global_skateshop.render.item_desc = "";
556 vg_msg msg;
557 vg_msg_init( &msg, reg->metadata, reg->metadata_len );
558
559 if( vg_msg_seekframe( &msg, "workshop" ) ){
560 const char *title = vg_msg_getkvstr( &msg, "title" );
561 if( title ) global_skateshop.render.item_title = title;
562
563 const char *dsc = vg_msg_getkvstr( &msg, "author" );
564 if( dsc ) global_skateshop.render.item_desc = dsc;
565 vg_msg_skip_frame( &msg );
566 }
567
568 global_skateshop.render.reg_id = global_skateshop.selected_board_id;
569 }
570
571 /* Skin title
572 * ----------------------------------------------------------------- */
573 m3x3_zero( mlocal );
574 m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
575 mlocal[3][0] = -font3d_string_width( 0, global_skateshop.render.item_title );
576 mlocal[3][0] *= scale*0.5f;
577 mlocal[3][1] = 0.1f;
578 mlocal[3][2] = 0.0f;
579 m4x3_mul( mtext, mlocal, mmdl );
580 font3d_simple_draw( 0, global_skateshop.render.item_title,
581 &skaterift.cam, mmdl );
582
583 /* Author name
584 * ----------------------------------------------------------------- */
585 scale *= 0.4f;
586 m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
587 mlocal[3][0] = -font3d_string_width( 0, global_skateshop.render.item_desc );
588 mlocal[3][0] *= scale*0.5f;
589 mlocal[3][1] = 0.0f;
590 mlocal[3][2] = 0.0f;
591 m4x3_mul( mtext, mlocal, mmdl );
592 font3d_simple_draw( 0, global_skateshop.render.item_desc,
593 &skaterift.cam, mmdl );
594
595 SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
596 }
597
598 static void skateshop_render_charshop( ent_skateshop *shop ){
599 }
600
601 static void skateshop_render_worldshop( ent_skateshop *shop ){
602 world_instance *world = world_current_instance();
603
604 ent_marker *mark_display = mdl_arritm( &world->ent_marker,
605 mdl_entity_id_id(shop->worlds.id_display)),
606 *mark_info = mdl_arritm( &world->ent_marker,
607 mdl_entity_id_id(shop->boards.id_info));
608
609 if( global_skateshop.render.world_reg != global_skateshop.selected_world_id){
610 global_skateshop.render.world_title = "missing: workshop.title";
611
612 addon_reg *reg = get_addon_from_index( k_addon_type_world,
613 global_skateshop.selected_world_id, ADDON_REG_HIDDEN );
614
615 if( !reg )
616 goto none;
617
618 if( reg->alias.workshop_id )
619 {
620 vg_msg msg;
621 vg_msg_init( &msg, reg->metadata, reg->metadata_len );
622
623 global_skateshop.render.world_loc = vg_msg_getkvstr(&msg,"location");
624 global_skateshop.render.world_reg = global_skateshop.selected_world_id;
625
626 if( vg_msg_seekframe( &msg, "workshop" ) )
627 {
628 global_skateshop.render.world_title = vg_msg_getkvstr(&msg,"title");
629 vg_msg_skip_frame( &msg );
630 }
631 else {
632 vg_warn( "No workshop body\n" );
633 }
634 }
635 else {
636 global_skateshop.render.world_title = reg->alias.foldername;
637 }
638 }
639
640 none:;
641
642 /* Text */
643 char buftext[128], bufsubtext[128];
644 vg_str info, subtext;
645 vg_strnull( &info, buftext, 128 );
646 vg_strnull( &subtext, bufsubtext, 128 );
647
648 u32 valid_count = addon_count(k_addon_type_world,ADDON_REG_HIDDEN);
649 if( valid_count )
650 {
651 vg_strcati32( &info, global_skateshop.selected_world_id+1 );
652 vg_strcatch( &info, '/' );
653 vg_strcati32( &info, valid_count );
654 vg_strcatch( &info, ' ' );
655 vg_strcat( &info, global_skateshop.render.world_title );
656
657 if( !vg_loader_availible() )
658 {
659 vg_strcat( &subtext, "Loading..." );
660 }
661 else
662 {
663 addon_reg *reg = get_addon_from_index( k_addon_type_world,
664 global_skateshop.selected_world_id, ADDON_REG_HIDDEN );
665
666 if( reg->alias.workshop_id )
667 vg_strcat( &subtext, "(Workshop) " );
668
669 vg_strcat( &subtext, global_skateshop.render.world_loc );
670 }
671 }
672 else
673 {
674 vg_strcat( &info, "No workshop worlds installed" );
675 }
676
677 m4x3f mtext,mlocal,mtextmdl;
678 mdl_transform_m4x3( &mark_info->transform, mtext );
679
680 font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &skaterift.cam );
681 shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
682
683 float scale = 0.2f, thickness = 0.015f, scale1 = 0.08f;
684 m3x3_zero( mlocal );
685 m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
686 mlocal[3][0] = -font3d_string_width( 0, buftext );
687 mlocal[3][0] *= scale*0.5f;
688 mlocal[3][1] = 0.1f;
689 mlocal[3][2] = 0.0f;
690 m4x3_mul( mtext, mlocal, mtextmdl );
691 font3d_simple_draw( 0, buftext, &skaterift.cam, mtextmdl );
692
693 m3x3_setdiagonalv3( mlocal, (v3f){ scale1, scale1, thickness } );
694 mlocal[3][0] = -font3d_string_width( 0, bufsubtext );
695 mlocal[3][0] *= scale1*0.5f;
696 mlocal[3][1] = -scale1*0.3f;
697 m4x3_mul( mtext, mlocal, mtextmdl );
698 font3d_simple_draw( 0, bufsubtext, &skaterift.cam, mtextmdl );
699 }
700
701 /*
702 * World: render event
703 */
704 void skateshop_render( ent_skateshop *shop )
705 {
706 if( shop->type == k_skateshop_type_boardshop )
707 skateshop_render_boardshop( shop );
708 else if( shop->type == k_skateshop_type_charshop )
709 skateshop_render_charshop( shop );
710 else if( shop->type == k_skateshop_type_worldshop )
711 skateshop_render_worldshop( shop );
712 else if( shop->type == k_skateshop_type_server ){
713 }
714 else
715 vg_fatal_error( "Unknown store (%u)\n", shop->type );
716 }
717
718 void skateshop_render_nonfocused( world_instance *world, vg_camera *cam )
719 {
720 for( u32 j=0; j<mdl_arrcount( &world->ent_skateshop ); j ++ )
721 {
722 ent_skateshop *shop = mdl_arritm(&world->ent_skateshop, j );
723
724 if( shop->type != k_skateshop_type_boardshop ) continue;
725
726 f32 dist2 = v3_dist2( cam->pos, shop->transform.co ),
727 maxdist = 50.0f;
728
729 if( dist2 > maxdist*maxdist ) continue;
730 ent_marker *mark_rack = mdl_arritm( &world->ent_marker,
731 mdl_entity_id_id(shop->boards.id_rack));
732
733 if( !mark_rack )
734 continue;
735
736 u32 slot_count = vg_list_size(global_skateshop.shop_view_slots);
737 for( u32 i=0; i<slot_count; i++ )
738 {
739 struct player_board *board = &localplayer.fallback_board;
740
741 mdl_transform xform;
742 transform_identity( &xform );
743
744 xform.co[0] = -((float)i - ((float)slot_count)*0.5f)*0.45f;
745 mdl_transform_mul( &mark_rack->transform, &xform, &xform );
746
747 struct player_board_pose pose = {0};
748 m4x3f mmdl;
749 mdl_transform_m4x3( &xform, mmdl );
750 render_board( cam, world, board, mmdl, &pose, k_board_shader_entity );
751 }
752 }
753 }
754
755 static void ent_skateshop_helpers_pickable( const char *acceptance )
756 {
757 vg_str text;
758
759 if( gui_new_helper( input_button_list[k_srbind_mback], &text ))
760 vg_strcat( &text, "exit" );
761
762 if( (global_skateshop.helper_pick = gui_new_helper(
763 input_button_list[k_srbind_maccept], &text))){
764 vg_strcat( &text, acceptance );
765 }
766
767 if( (global_skateshop.helper_browse = gui_new_helper(
768 input_axis_list[k_sraxis_mbrowse_h], &text ))){
769 vg_strcat( &text, "browse" );
770 }
771 }
772
773 static void board_scan_thread( void *_args )
774 {
775 addon_mount_content_folder( k_addon_type_board, "boards", ".mdl" );
776 addon_mount_workshop_items();
777 vg_async_call( async_addon_reg_update, NULL, 0 );
778 vg_async_stall();
779
780 /* 04.03.24
781 * REVIEW: This is removed as it *should* be done on the preupdate of the
782 * addon system.
783 *
784 * Verify that it works the same.
785 */
786 #if 0
787 board_processview_thread(NULL);
788 #endif
789 }
790
791 static void world_scan_thread( void *_args )
792 {
793 addon_mount_content_folder( k_addon_type_world, "maps", ".mdl" );
794 addon_mount_workshop_items();
795 vg_async_call( async_addon_reg_update, NULL, 0 );
796 }
797
798 /*
799 * Entity logic: entrance event
800 */
801 entity_call_result ent_skateshop_call( world_instance *world, ent_call *call )
802 {
803 u32 index = mdl_entity_id_id( call->id );
804 ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, index );
805 vg_info( "skateshop_call\n" );
806
807 if( (skaterift.activity != k_skaterift_default) ||
808 !vg_loader_availible() )
809 return k_entity_call_result_invalid;
810
811 if( call->function == k_ent_function_trigger )
812 {
813 if( localplayer.subsystem != k_player_subsystem_walk )
814 return k_entity_call_result_OK;
815
816 vg_info( "Entering skateshop\n" );
817
818 world_entity_set_focus( call->id );
819 world_entity_focus_modal();
820 gui_helper_clear();
821
822 if( shop->type == k_skateshop_type_boardshop )
823 {
824 skateshop_update_viewpage();
825 vg_loader_start( board_scan_thread, NULL );
826 ent_skateshop_helpers_pickable( "pick" );
827 }
828 else if( shop->type == k_skateshop_type_charshop )
829 {
830 ent_skateshop_helpers_pickable( "pick" );
831 }
832 else if( shop->type == k_skateshop_type_worldshop )
833 {
834 ent_skateshop_helpers_pickable( "open rift" );
835 vg_loader_start( world_scan_thread, NULL );
836 }
837 else if( shop->type == k_skateshop_type_server )
838 {
839 vg_str text;
840 global_skateshop.helper_pick = gui_new_helper(
841 input_button_list[k_srbind_maccept], &text);
842 if( gui_new_helper( input_button_list[k_srbind_mback], &text ))
843 vg_strcat( &text, "exit" );
844 skateshop_server_helper_update();
845 }
846 return k_entity_call_result_OK;
847 }
848 else
849 return k_entity_call_result_unhandled;
850 }