clean boardshop idea
[carveJwlIkooP6JGAAIwe30JlM.git] / menu.h
1 #ifndef MENU_H
2 #define MENU_H
3
4 #include "common.h"
5 #include "model.h"
6 #include "world_render.h"
7 #include "player.h"
8 #include "conf.h"
9
10 #include "shaders/model_menu.h"
11 #include "vg_steam_friends.h"
12
13 VG_STATIC mdl_context menu_model;
14 VG_STATIC mdl_array_ptr menu_markers;
15 VG_STATIC glmesh menu_glmesh;
16 VG_STATIC m4x3f menu_mdl_mtx;
17 VG_STATIC float menu_opacity = 0.0f;
18 VG_STATIC float menu_input_cooldown = 0.0f;
19 VG_STATIC float menu_fov_target = 97.0f,
20 menu_smooth_fov = 97.0f;
21 VG_STATIC v2f menu_extra_angles;
22 VG_STATIC v3f menu_camera_pos;
23 VG_STATIC v2f menu_camera_angles;
24
25 VG_STATIC int cl_menu = 0,
26 cl_menu_go_away = 0;
27
28 VG_STATIC int menu_enabled(void){ return cl_menu; }
29
30 VG_STATIC const char *playermodels[] = { "ch_new", "ch_jordan", "ch_outlaw" };
31
32 GLuint tex_menu;
33
34 VG_STATIC struct input_binding input_menu_h,
35 input_menu_v,
36 input_menu_press,
37 input_menu_back,
38 input_menu_toggle,
39 input_menu_toggle_kbm;
40
41 VG_STATIC void menu_btn_quit( int event );
42 VG_STATIC void menu_btn_skater( int event );
43 VG_STATIC void menu_btn_blur( int event );
44 VG_STATIC void menu_btn_fuckoff( int event );
45 VG_STATIC void menu_btn_reset( int event );
46 VG_STATIC void menu_btn_map( int event );
47 VG_STATIC void menu_btn_settings( int event );
48 VG_STATIC void menu_btn_invert_y( int event );
49
50 VG_STATIC mdl_mesh *menu_mesh_fov_slider,
51 *menu_mesh_vol_slider,
52 *menu_mesh_res_slider;
53
54 VG_STATIC ent_marker
55 *menu_mark_fov_min,
56 *menu_mark_fov_max,
57 *menu_mark_vol_min,
58 *menu_mark_vol_max,
59 *menu_mark_res_min,
60 *menu_mark_res_max;
61
62 struct{
63 /* state */
64 int loc;
65 u32 page;
66
67 /* map browser */
68 struct menu_map_file{
69 char name[ 64 ];
70 }
71 maps_list[ 16 ];
72
73 int selected_map,
74 map_count;
75 }
76 VG_STATIC game_menu;
77
78 enum menu_page{
79 k_menu_page_main = 0x1,
80 k_menu_page_skater = 0x2,
81 k_menu_page_quit = 0x4,
82 k_menu_page_settings = 0x8,
83 k_menu_page_map = 0x10
84 };
85
86 struct menu_btn_userdata{
87 int i;
88 void *ptr_generic;
89 };
90
91 VG_STATIC int menu_settings_if( struct menu_btn_userdata ud )
92 {
93 if( game_menu.page & k_menu_page_settings ){
94 int *ptr = ud.ptr_generic;
95 return *ptr;
96 }
97 else
98 return 0;
99 }
100
101 VG_STATIC int menu_vis( struct menu_btn_userdata ud )
102 {
103 if( ud.i & game_menu.page )
104 return 1;
105 else
106 return 0;
107 }
108
109 VG_STATIC int menu_controller( struct menu_btn_userdata ud )
110 {
111 if( (game_menu.page & (k_menu_page_main|k_menu_page_settings))
112 && (ud.i == steam_display_controller) )
113 return 1;
114 return 0;
115 }
116
117 VG_STATIC int menu_controller_inf( struct menu_btn_userdata ud )
118 {
119 if( (game_menu.page & k_menu_page_settings)
120 && (ud.i == steam_display_controller) )
121 return 1;
122 return 0;
123 }
124
125 struct menu_button
126 {
127 const char *name;
128
129 int (*fn_visibility)( struct menu_btn_userdata ud );
130 struct menu_btn_userdata user;
131
132 void (*fn_press)( int event );
133
134 const char *ll,
135 *lu,
136 *lr,
137 *ld;
138
139 mdl_mesh *mesh;
140 float falpha, fsize;
141 }
142 VG_STATIC menu_buttons[] =
143 {
144 {
145 "text_quit", menu_vis, {.i=k_menu_page_main|k_menu_page_quit},
146 .fn_press = menu_btn_quit,
147 .ld="text_reset", .lr="text_settings", /*.ll="text_map"*/
148 },
149 {
150 "text_quitty", menu_vis, {.i=k_menu_page_quit}
151 },
152 {
153 "text_yes", menu_vis, {.i=k_menu_page_quit},
154 .fn_press = menu_btn_fuckoff
155 },
156 {
157 "text_reset", menu_vis, {.i=k_menu_page_main},
158 .fn_press = menu_btn_reset,
159 .lu="text_quit", .ld="text_skater", /*.ll="text_map",*/ .lr="text_settings"
160 },
161 {
162 "text_skater", menu_vis, {.i=k_menu_page_main|k_menu_page_skater},
163 .fn_press = menu_btn_skater,
164 .lu="text_reset", /*.ll="text_map",*/ .lr="text_settings"
165 },
166 /*
167 {
168 "text_map", menu_vis, {.i=k_menu_page_main},
169 .fn_press = menu_btn_map,
170 .lr="text_reset"
171 },
172 */
173 {
174 "text_settings", menu_vis, {.i=k_menu_page_main|k_menu_page_settings},
175 .fn_press = menu_btn_settings,
176 .ll="text_reset"
177 },
178 {
179 "skater_left", menu_vis, {k_menu_page_skater}
180 },
181 {
182 "skater_right", menu_vis, {k_menu_page_skater}
183 },
184
185 {
186 "fov_slider", menu_vis, {k_menu_page_settings},
187 .ld="text_invert_y"
188 },
189 { "fov_info", menu_vis, {k_menu_page_settings} },
190
191 {
192 "vol_slider", menu_vis, {k_menu_page_settings},
193 .lu="res_slider"
194 },
195 { "vol_info", menu_vis, {k_menu_page_settings} },
196
197 {
198 "text_invert_y", menu_vis, {k_menu_page_settings},
199 .fn_press = menu_btn_invert_y,
200 .lu = "fov_slider", .ld="text_blur"
201 },
202 {
203 "text_invert_y_check", menu_settings_if, {.ptr_generic=&cl_invert_y}
204 },
205 {
206 "text_blur", menu_vis, {k_menu_page_settings},
207 .fn_press = menu_btn_blur,
208 .lu="text_invert_y", .ld="res_slider"
209 },
210 {
211 "text_blur_check", menu_settings_if, {.ptr_generic=&cl_blur}
212 },
213 {
214 "res_slider", menu_vis, {k_menu_page_settings},
215 .ld = "vol_slider", .lu = "text_blur"
216 },
217 {
218 "res_info", menu_vis, {k_menu_page_settings},
219 },
220 { "ctr_xbox", menu_controller_inf, {k_steam_controller_type_xbox}},
221 { "ctr_xbox_text", menu_controller_inf, {k_steam_controller_type_xbox}},
222 { "ctr_steam", menu_controller_inf, {k_steam_controller_type_steam}},
223 { "ctr_steam_text", menu_controller_inf, {k_steam_controller_type_steam}},
224 { "ctr_deck", menu_controller_inf, {k_steam_controller_type_steam_deck}},
225 { "ctr_deck_text", menu_controller_inf, {k_steam_controller_type_steam_deck}},
226 { "ctr_ps", menu_controller_inf, {k_steam_controller_type_playstation}},
227 { "ctr_ps_text", menu_controller_inf, {k_steam_controller_type_playstation}},
228 { "ctr_kbm", menu_controller_inf, {k_steam_controller_type_keyboard}},
229 { "ctr_kbm_text", menu_controller_inf, {k_steam_controller_type_keyboard}},
230 {
231 "text_paused", menu_vis, {k_menu_page_main}
232 },
233 };
234
235 VG_STATIC int menu_get_loc( const char *loc )
236 {
237 for( int i=0; i<vg_list_size(menu_buttons); i++ )
238 if( !strcmp( menu_buttons[i].name, loc ) )
239 return i;
240
241 assert(0);
242 return 0;
243 }
244
245 VG_STATIC void menu_btn_reset( int event )
246 {
247 localplayer_cmd_respawn( 0, NULL );
248 cl_menu_go_away = 1;
249 game_menu.page = 0;
250 }
251
252 VG_STATIC void menu_btn_fuckoff( int event )
253 {
254 vg.window_should_close = 1;
255 }
256
257 VG_STATIC void menu_btn_quit( int event )
258 {
259 game_menu.page = k_menu_page_quit;
260 game_menu.loc = menu_get_loc( "text_yes" );
261 }
262
263 VG_STATIC void menu_btn_settings( int event )
264 {
265 game_menu.page = k_menu_page_settings;
266 game_menu.loc = menu_get_loc( "fov_slider" );
267 }
268
269 VG_STATIC void menu_btn_skater( int event )
270 {
271 game_menu.page = k_menu_page_skater;
272 }
273
274 VG_STATIC void menu_btn_blur( int event )
275 {
276 cl_blur ^= 0x1;
277 }
278
279 VG_STATIC void menu_btn_invert_y( int event )
280 {
281 cl_invert_y ^= 0x1;
282 }
283
284 VG_STATIC void menu_btn_map( int event )
285 {
286 game_menu.page = k_menu_page_map;
287 game_menu.map_count = 0;
288 game_menu.selected_map = 0;
289
290 tinydir_dir dir;
291 tinydir_open( &dir, "maps" );
292
293 while( dir.has_next ){
294 tinydir_file file;
295 tinydir_readfile( &dir, &file );
296
297 if( file.is_reg ){
298 struct menu_map_file *mf = &game_menu.maps_list[ game_menu.map_count ];
299
300 vg_strncpy( file.name, mf->name,
301 vg_list_size(game_menu.maps_list[0].name),
302 k_strncpy_always_add_null );
303
304 game_menu.map_count ++;
305 if( game_menu.map_count == vg_list_size(game_menu.maps_list) )
306 break;
307 }
308
309 tinydir_next( &dir );
310 }
311
312 tinydir_close(&dir);
313 }
314
315 VG_STATIC void menu_crap_ui(void)
316 {
317 if( cl_menu && (game_menu.page == k_menu_page_map) ){
318 ui_rect box;
319 box[0] = vg.window_x/2 - 150;
320 box[1] = vg.window_y/2 - 300;
321 box[2] = 300;
322 box[3] = 600;
323
324 ui_fill_rect( box, 0xa0000000 );
325
326 if( game_menu.map_count == 0 ){
327 ui_text( (ui_rect){ vg.window_x/2, box[1]+8, 0,0 }, "No maps found", 1,
328 k_text_align_center );
329 }
330 else{
331 ui_rect_pad( box, 4 );
332 box[3] = 16;
333
334 for( int i=0; i<game_menu.map_count; i++ ){
335 struct menu_map_file *mf = &game_menu.maps_list[ i ];
336
337 ui_fill_rect( box, game_menu.selected_map == i? 0xa0ffffff:
338 0xa0808080 );
339 ui_text( (ui_rect){ vg.window_x/2, box[1]+2, 0,0 },
340 mf->name, 1, k_text_align_center );
341 box[1] += 16+4;
342 }
343 }
344 }
345 }
346
347 VG_STATIC void steam_on_game_overlay( CallbackMsg_t *msg )
348 {
349 GameOverlayActivated_t *inf = (GameOverlayActivated_t *)msg->m_pubParam;
350 vg_info( "Steam game overlay activated; pausing\n" );
351
352 if( inf->m_bActive ){
353 cl_menu = 1;
354 game_menu.page = k_menu_page_main;
355 game_menu.loc = menu_get_loc( "text_skater" );
356 }
357 }
358
359 VG_STATIC void menu_init(void)
360 {
361 vg_create_unnamed_input( &input_menu_h, k_input_type_axis );
362 vg_create_unnamed_input( &input_menu_v, k_input_type_axis );
363 vg_create_unnamed_input( &input_menu_back, k_input_type_button );
364 vg_create_unnamed_input( &input_menu_press, k_input_type_button );
365 vg_create_unnamed_input( &input_menu_toggle, k_input_type_button );
366 vg_create_unnamed_input( &input_menu_toggle_kbm, k_input_type_button );
367
368 vg_apply_bind_str( &input_menu_h, "", "gp-ls-h" );
369 vg_apply_bind_str( &input_menu_h, "+", "right" );
370 vg_apply_bind_str( &input_menu_h, "-", "left" );
371 vg_apply_bind_str( &input_menu_v, "", "-gp-ls-v" );
372 vg_apply_bind_str( &input_menu_v, "+", "up" );
373 vg_apply_bind_str( &input_menu_v, "-", "down" );
374 vg_apply_bind_str( &input_menu_press, "", "gp-a" );
375 vg_apply_bind_str( &input_menu_press, "", "\2enter" );
376 vg_apply_bind_str( &input_menu_back, "", "gp-b" );
377 vg_apply_bind_str( &input_menu_back, "", "\2escape" );
378 vg_apply_bind_str( &input_menu_toggle_kbm, "", "\2escape" );
379 vg_apply_bind_str( &input_menu_toggle, "", "\2gp-menu" );
380
381 vg_linear_clear( vg_mem.scratch );
382
383 mdl_open( &menu_model, "models/rs_menu.mdl", vg_mem.rtmemory );
384 mdl_load_metadata_block( &menu_model, vg_mem.rtmemory );
385 mdl_load_array( &menu_model, &menu_markers, "ent_marker", vg_mem.rtmemory );
386 //mdl_invert_uv_coordinates( &menu_model );
387 mdl_async_load_glmesh( &menu_model, &menu_glmesh );
388 mdl_close( &menu_model );
389
390 vg_tex2d_load_qoi_async_file( "textures/menu.qoi",
391 VG_TEX2D_CLAMP|VG_TEX2D_NEAREST,
392 &tex_menu );
393
394
395 for( int i=0; i<vg_list_size(menu_buttons); i++ ){
396 struct menu_button *btn = &menu_buttons[i];
397 btn->mesh = mdl_find_mesh( &menu_model, btn->name );
398
399 if( !btn->mesh ){
400 vg_info( "info: %s\n", btn->name );
401 vg_fatal_error( "Menu programming error" );
402 }
403 }
404
405 menu_mark_fov_max =
406 ent_find_marker( &menu_model, &menu_markers, "fov_slider_max" );
407 menu_mark_fov_min =
408 ent_find_marker( &menu_model, &menu_markers, "fov_slider_min" );
409 menu_mark_vol_max =
410 ent_find_marker( &menu_model, &menu_markers, "vol_slider_max" );
411 menu_mark_vol_min =
412 ent_find_marker( &menu_model, &menu_markers, "vol_slider_min" );
413 menu_mark_res_max =
414 ent_find_marker( &menu_model, &menu_markers, "res_slider_max" );
415 menu_mark_res_min =
416 ent_find_marker( &menu_model, &menu_markers, "res_slider_min" );
417
418 menu_mesh_fov_slider = mdl_find_mesh( &menu_model, "fov_slider" );
419 menu_mesh_vol_slider = mdl_find_mesh( &menu_model, "vol_slider" );
420 menu_mesh_res_slider = mdl_find_mesh( &menu_model, "res_slider" );
421
422 shader_model_menu_register();
423
424 #ifdef SR_NETWORKED
425 steam_register_callback( k_iGameOverlayActivated, steam_on_game_overlay );
426 #endif
427 }
428
429 VG_STATIC void menu_run_directional(void)
430 {
431 struct menu_button *btn = &menu_buttons[ game_menu.loc ];
432
433 if( vg_input_button_down( &input_menu_press ) ){
434 if( btn->fn_press ){
435 audio_lock();
436 audio_oneshot( &audio_ui[0], 1.0f, 0.0f );
437 audio_unlock();
438
439 btn->fn_press( 1 );
440 return;
441 }
442 }
443
444 if( menu_input_cooldown <= 0.0f ){
445 v2f dir = { input_menu_h.axis.value,
446 -input_menu_v.axis.value };
447
448 if( v2_length2( dir ) > 0.8f*0.8f ){
449 const char *link = NULL;
450
451 if( fabsf(dir[0]) > fabsf(dir[1]) ){
452 if( dir[0] > 0.0f ) link = btn->lr;
453 else link = btn->ll;
454 }
455 else{
456 if( dir[1] > 0.0f ) link = btn->ld;
457 else link = btn->lu;
458 }
459
460 if( link ){
461 game_menu.loc = menu_get_loc( link );
462 menu_input_cooldown = 0.25f;
463 }
464 }
465 }
466 }
467
468 VG_STATIC int menu_page_should_backout(void)
469 {
470 return vg_input_button_down( &input_menu_back );
471 }
472
473 VG_STATIC void menu_close(void)
474 {
475 cl_menu_go_away = 1;
476 game_menu.page = 0;
477 game_menu.loc = menu_get_loc( "text_skater" );
478 }
479
480 VG_STATIC void menu_page_main(void)
481 {
482 if( menu_page_should_backout() )
483 {
484 menu_close();
485 return;
486 }
487
488 menu_fov_target = 112.0f;
489 menu_run_directional();
490 }
491
492 VG_STATIC void menu_page_map(void)
493 {
494 if( menu_page_should_backout() ){
495 game_menu.page = k_menu_page_main;
496 game_menu.loc = menu_get_loc( "text_map" );
497 }
498
499 if( game_menu.map_count > 0 ){
500 float v = input_menu_v.axis.value;
501 if( (fabsf(v) > 0.7f) && (menu_input_cooldown <= 0.0f) ){
502 audio_lock();
503 audio_oneshot( &audio_rewind[4], 1.0f, 0.0f );
504 audio_unlock();
505
506 if( v > 0.0f ){
507 game_menu.selected_map --;
508
509 if( game_menu.selected_map < 0 )
510 game_menu.selected_map = game_menu.map_count-1;
511
512 menu_input_cooldown = 0.25f;
513 }
514 else{
515 game_menu.selected_map ++;
516
517 if( game_menu.selected_map >= game_menu.map_count )
518 game_menu.selected_map = 0;
519
520 menu_input_cooldown = 0.25f;
521 }
522 }
523
524 if( vg_input_button_down( &input_menu_press ) ){
525 #if 0
526 /* load map */
527 char temp[256];
528 strcpy( temp, "maps/" );
529 strcat( temp, game_menu.maps_list[game_menu.selected_map].name );
530
531 world_change_world( 1, (const char *[]){ temp } );
532 menu_close();
533 #endif
534 }
535 }
536
537 menu_fov_target = 80.0f;
538 }
539
540 VG_STATIC void menu_page_quit(void)
541 {
542 if( menu_page_should_backout() ){
543 game_menu.page = k_menu_page_main;
544 game_menu.loc = menu_get_loc( "text_quit" );
545 }
546
547 menu_fov_target = 90.0f;
548 menu_run_directional();
549 }
550
551 void temp_update_playermodel(void);
552 VG_STATIC void menu_page_skater(void)
553 {
554 float h = input_menu_h.axis.value;
555 menu_fov_target = 97.0f;
556
557 if( menu_page_should_backout() ){
558 game_menu.page = k_menu_page_main;
559 game_menu.loc = menu_get_loc( "text_skater" );
560 return;
561 }
562
563 if( (fabsf(h) > 0.7f) && (menu_input_cooldown <= 0.0f) ){
564 audio_lock();
565 audio_oneshot( &audio_rewind[4], 1.0f, 0.0f );
566 audio_unlock();
567
568 vg_info( "%f\n", h );
569
570 if( h < 0.0f ){
571 cl_playermdl_id --;
572 if( cl_playermdl_id < 0 )
573 cl_playermdl_id = 2;
574
575 int li = menu_get_loc( "skater_left" );
576
577 menu_buttons[li].fsize = 0.4f;
578 menu_buttons[li].falpha = 1.0f;
579
580 menu_input_cooldown = 0.25f;
581 }
582 else{
583 cl_playermdl_id ++;
584 if( cl_playermdl_id > 2 )
585 cl_playermdl_id = 0;
586
587 int ri = menu_get_loc( "skater_right" );
588
589 menu_buttons[ri].fsize = 0.4f;
590 menu_buttons[ri].falpha = 1.0f;
591
592 menu_input_cooldown = 0.25f;
593 }
594
595 temp_update_playermodel();
596 }
597 }
598
599 VG_STATIC void menu_slider( float *value, int set_value,
600 mdl_mesh *slider, v3f co_min, v3f co_max )
601 {
602 if( set_value ){
603 float h = input_menu_h.axis.value;
604 if( fabsf(h) > 0.04f )
605 *value += h * vg.time_frame_delta;
606 *value = vg_clampf( *value, 0.0f, 1.0f );
607 }
608
609 v3_lerp( co_min, co_max, *value, slider->transform.co );
610 }
611
612 VG_STATIC void menu_page_settings(void)
613 {
614 menu_run_directional();
615
616 int fov_select = game_menu.loc == menu_get_loc( "fov_slider" );
617 menu_slider( &cl_fov, fov_select,
618 menu_mesh_fov_slider, menu_mark_fov_min->transform.co,
619 menu_mark_fov_max->transform.co );
620
621 if( fov_select )
622 menu_fov_target = vg_lerpf( 97.0f, 135.0f, cl_fov ) * 0.8f;
623
624 menu_slider( &vg_audio.external_global_volume,
625 (game_menu.loc == menu_get_loc( "vol_slider" )),
626 menu_mesh_vol_slider, menu_mark_vol_min->transform.co,
627 menu_mark_vol_max->transform.co );
628
629 menu_slider( &gpipeline.view_render_scale,
630 (game_menu.loc == menu_get_loc( "res_slider" )),
631 menu_mesh_res_slider, menu_mark_res_min->transform.co,
632 menu_mark_res_max->transform.co );
633
634 if( menu_page_should_backout() ){
635 game_menu.page = k_menu_page_main;
636 game_menu.loc = menu_get_loc( "text_settings" );
637 return;
638 }
639 }
640
641 VG_STATIC void menu_update(void)
642 {
643 vg_input_update( 1, &input_menu_h );
644 vg_input_update( 1, &input_menu_v );
645 vg_input_update( 1, &input_menu_back );
646 vg_input_update( 1, &input_menu_press );
647 vg_input_update( 1, &input_menu_toggle );
648 vg_input_update( 1, &input_menu_toggle_kbm );
649 return;
650
651 int toggle_gp = vg_input_button_down( &input_menu_toggle ),
652 toggle_kb = vg_input_button_down( &input_menu_toggle_kbm ),
653 wait_for_a_sec = 0;
654
655 if( toggle_gp || toggle_kb ){
656 if( cl_menu ){
657 if( toggle_gp ){
658 menu_close();
659 }
660 }
661 else{
662 if( toggle_kb )
663 wait_for_a_sec = 1;
664
665 cl_menu = 1;
666 game_menu.page = 1;
667 }
668 }
669
670 if( !wait_for_a_sec && cl_menu ){
671 if( game_menu.page == k_menu_page_main )
672 menu_page_main();
673 else if( game_menu.page == k_menu_page_skater )
674 menu_page_skater();
675 else if( game_menu.page == k_menu_page_quit )
676 menu_page_quit();
677 else if( game_menu.page == k_menu_page_settings )
678 menu_page_settings();
679 else if( game_menu.page == k_menu_page_map )
680 menu_page_map();
681 }
682
683 struct menu_button *btn = &menu_buttons[ game_menu.loc ];
684
685 /* Base */
686 {
687 player_instance *player = &localplayer;
688 struct player_avatar *av = player->playeravatar;
689
690 v3f center_rough;
691 if( player->subsystem == k_player_subsystem_dead ){
692 m4x3_mulv( av->sk.final_mtx[av->id_hip], (v3f){0.0f,0.9f,0.0f},
693 center_rough );
694 }
695 else{
696 m4x3_mulv( av->sk.final_mtx[av->id_head], (v3f){0.0f,1.5f,0.0f},
697 center_rough );
698 }
699
700 v3f cam_offset;
701 float cam_rot;
702 if( player->subsystem == k_player_subsystem_walk ){
703 v3_muls( player->rb.to_world[2], 1.0f, cam_offset );
704 cam_rot = 0.0f;
705 }
706 else{
707 v3_muls( player->rb.to_world[0], -1.0f, cam_offset );
708 cam_rot = -VG_PIf*0.5f;
709 }
710
711
712 v3f lookdir;
713 m3x3_mulv( player->invbasis, cam_offset, lookdir );
714 lookdir[1] = 0.0f;
715 v3_normalize( lookdir );
716
717 m3x3_mulv( player->basis, lookdir, cam_offset );
718 v3_muladds( center_rough, cam_offset, 2.0f, menu_camera_pos );
719
720 menu_camera_angles[1] = 0.0f;
721 menu_camera_angles[0] = -atan2f( lookdir[0], lookdir[2] );
722
723 /* setup model matrix */
724 v4f qmenu_mdl;
725 q_axis_angle( qmenu_mdl, (v3f){0.0f,1.0f,0.0f}, -menu_camera_angles[0] );
726 q_m3x3( qmenu_mdl, menu_mdl_mtx );
727 v3_add( center_rough, (v3f){0.0f,-0.5f,0.0f}, menu_mdl_mtx[3] );
728 m3x3_mul( player->basis, menu_mdl_mtx, menu_mdl_mtx );
729
730 menu_smooth_fov = vg_lerpf( menu_smooth_fov, menu_fov_target,
731 vg.time_frame_delta * 8.2f );
732 }
733
734 /* Extra */
735 {
736 v3f delta;
737 v3_sub( btn->mesh->transform.co, (v3f){ 0.0f,1.5f,-1.5f }, delta );
738 v3_normalize( delta );
739
740 float y = atan2f( delta[0], delta[2] ),
741 p = -sinf(delta[1]),
742 dt = vg.time_frame_delta;
743
744 menu_extra_angles[0] = vg_lerpf( menu_extra_angles[0], y, dt );
745 menu_extra_angles[1] = vg_lerpf( menu_extra_angles[1], p, dt );
746
747 v2_muladds( menu_camera_angles, menu_extra_angles, 0.8f,
748 menu_camera_angles );
749 menu_camera_angles[0] = fmodf( menu_camera_angles[0], VG_TAUf );
750 }
751
752 float dt = vg.time_frame_delta * 6.0f;
753 menu_opacity = vg_lerpf( menu_opacity, cl_menu&&!cl_menu_go_away, dt );
754
755 if( menu_opacity <= 0.01f ){
756 cl_menu = 0;
757 cl_menu_go_away = 0;
758 }
759
760 vg.time_rate = 1.0-(double)menu_opacity;
761
762 if( cl_menu ){
763 menu_input_cooldown -= vg.time_frame_delta;
764 }
765 }
766
767 /* https://iquilezles.org/articles/functions/ */
768 float expSustainedImpulse( float x, float f, float k )
769 {
770 float s = fmaxf(x-f,0.0f);
771 return fminf( x*x/(f*f), 1.0f+(2.0f/f)*s*expf(-k*s));
772 }
773
774 VG_STATIC void menu_render_bg(void)
775 {
776 glEnable(GL_BLEND);
777 glDisable(GL_DEPTH_TEST);
778 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
779 glBlendEquation(GL_FUNC_ADD);
780
781 shader_blitcolour_use();
782 shader_blitcolour_uColour( (v4f){ 0.1f, 0.1f, 0.3f, menu_opacity*0.5f } );
783 render_fsquad();
784 }
785
786 VG_STATIC void menu_render_fg( camera *cam )
787 {
788 glEnable( GL_DEPTH_TEST );
789 glDisable( GL_BLEND );
790
791 m4x3f mtx;
792
793 shader_model_menu_use();
794 shader_model_menu_uColour( (v4f){ 1.0f,1.0f,1.0f,1.0f} );
795 shader_model_menu_uTexMain( 1 );
796
797 glActiveTexture( GL_TEXTURE1 );
798 glBindTexture( GL_TEXTURE_2D, tex_menu );
799
800 shader_model_menu_uPv( cam->mtx.pv );
801 shader_model_menu_uPvmPrev( cam->mtx_prev.pv );
802 mesh_bind( &menu_glmesh );
803
804 for( int i=0; i<vg_list_size(menu_buttons); i++ ){
805 struct menu_button *btn = &menu_buttons[i];
806 float talpha = i==game_menu.loc? 1.0f: 0.0f,
807 tsize0 = btn->fn_visibility( btn->user )? 1.0f: 0.0f,
808 tsize1 = i==game_menu.loc? 0.07f: 0.0f,
809 tsize = tsize0+tsize1;
810
811 btn->falpha = vg_lerpf( btn->falpha, talpha, vg.time_frame_delta * 14.0f);
812 btn->fsize = vg_lerpf( btn->fsize, tsize, vg.time_frame_delta * 7.0f );
813
814 /* Colour */
815 v4f vselected = {0.95f*1.3f,0.45f*1.3f,0.095f*1.3f, 1.0f},
816 vnormal = {1.0f,1.0f,1.0f, 1.0f},
817 vcurrent;
818
819 v4_lerp( vnormal, vselected, btn->falpha, vcurrent );
820 shader_model_menu_uColour( vcurrent );
821
822 /* Create matrix */
823 m4x3f mtx_size;
824 mdl_transform_m4x3( &btn->mesh->transform, mtx );
825 m4x3_mul( menu_mdl_mtx, mtx, mtx );
826 m4x3_identity( mtx_size );
827 m3x3_scalef( mtx_size, expSustainedImpulse( btn->fsize, 0.5f, 8.7f) );
828 m4x3_mul( mtx, mtx_size, mtx );
829 shader_model_menu_uMdl( mtx );
830
831 for( int j=0; j<btn->mesh->submesh_count; j++ ){
832 mdl_submesh *sm =
833 mdl_arritm( &menu_model.submeshs, btn->mesh->submesh_start+j );
834 mdl_draw_submesh( sm );
835 }
836 }
837
838 /*
839 for( int i=0; i<menu_model->node_count; i++ )
840 {
841 mdl_node *pnode = mdl_node_from_id( menu_model, i );
842
843 for( int j=0; j<pnode->submesh_count; j++ )
844 {
845 mdl_submesh *sm =
846 mdl_submesh_from_id( menu_model, pnode->submesh_start+j );
847
848 mdl_node_transform( pnode, mtx );
849 m4x3_mul( menu_mdl_mtx, mtx, mtx );
850 shader_menu_uMdl( mtx );
851
852 mdl_draw_submesh( sm );
853 }
854 }
855 */
856 }
857
858 #endif /* MENU_H */