chaos caused by async
[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 #include "submodules/tinydir/tinydir.h"
13
14 VG_STATIC mdl_context menu_model;
15 VG_STATIC mdl_array_ptr menu_markers;
16 VG_STATIC glmesh menu_glmesh;
17 VG_STATIC m4x3f menu_mdl_mtx;
18 VG_STATIC float menu_opacity = 0.0f;
19 VG_STATIC float menu_input_cooldown = 0.0f;
20 VG_STATIC float menu_fov_target = 97.0f,
21 menu_smooth_fov = 97.0f;
22 VG_STATIC v2f menu_extra_angles;
23 VG_STATIC v3f menu_camera_pos;
24 VG_STATIC v2f menu_camera_angles;
25
26 VG_STATIC int cl_menu = 0,
27 cl_menu_go_away = 0;
28
29 VG_STATIC int menu_enabled(void){ return cl_menu; }
30
31 VG_STATIC const char *playermodels[] = { "ch_new", "ch_jordan", "ch_outlaw" };
32
33 GLuint tex_menu;
34
35 VG_STATIC struct input_binding input_menu_h,
36 input_menu_v,
37 input_menu_press,
38 input_menu_back,
39 input_menu_toggle,
40 input_menu_toggle_kbm;
41
42 VG_STATIC void menu_btn_quit( int event );
43 VG_STATIC void menu_btn_skater( int event );
44 VG_STATIC void menu_btn_blur( int event );
45 VG_STATIC void menu_btn_fuckoff( int event );
46 VG_STATIC void menu_btn_reset( int event );
47 VG_STATIC void menu_btn_map( int event );
48 VG_STATIC void menu_btn_settings( int event );
49 VG_STATIC void menu_btn_invert_y( int event );
50
51 VG_STATIC mdl_mesh *menu_mesh_fov_slider,
52 *menu_mesh_vol_slider,
53 *menu_mesh_res_slider;
54
55 VG_STATIC ent_marker
56 *menu_mark_fov_min,
57 *menu_mark_fov_max,
58 *menu_mark_vol_min,
59 *menu_mark_vol_max,
60 *menu_mark_res_min,
61 *menu_mark_res_max;
62
63 struct{
64 /* state */
65 int loc;
66 u32 page;
67
68 /* map browser */
69 struct menu_map_file{
70 char name[ 64 ];
71 }
72 maps_list[ 16 ];
73
74 int selected_map,
75 map_count;
76 }
77 VG_STATIC game_menu;
78
79 enum menu_page{
80 k_menu_page_main = 0x1,
81 k_menu_page_skater = 0x2,
82 k_menu_page_quit = 0x4,
83 k_menu_page_settings = 0x8,
84 k_menu_page_map = 0x10
85 };
86
87 struct menu_btn_userdata{
88 int i;
89 void *ptr_generic;
90 };
91
92 VG_STATIC int menu_settings_if( struct menu_btn_userdata ud )
93 {
94 if( game_menu.page & k_menu_page_settings ){
95 int *ptr = ud.ptr_generic;
96 return *ptr;
97 }
98 else
99 return 0;
100 }
101
102 VG_STATIC int menu_vis( struct menu_btn_userdata ud )
103 {
104 if( ud.i & game_menu.page )
105 return 1;
106 else
107 return 0;
108 }
109
110 VG_STATIC int menu_controller( struct menu_btn_userdata ud )
111 {
112 if( (game_menu.page & (k_menu_page_main|k_menu_page_settings))
113 && (ud.i == steam_display_controller) )
114 return 1;
115 return 0;
116 }
117
118 VG_STATIC int menu_controller_inf( struct menu_btn_userdata ud )
119 {
120 if( (game_menu.page & k_menu_page_settings)
121 && (ud.i == steam_display_controller) )
122 return 1;
123 return 0;
124 }
125
126 struct menu_button
127 {
128 const char *name;
129
130 int (*fn_visibility)( struct menu_btn_userdata ud );
131 struct menu_btn_userdata user;
132
133 void (*fn_press)( int event );
134
135 const char *ll,
136 *lu,
137 *lr,
138 *ld;
139
140 mdl_mesh *mesh;
141 float falpha, fsize;
142 }
143 VG_STATIC menu_buttons[] =
144 {
145 {
146 "text_quit", menu_vis, {.i=k_menu_page_main|k_menu_page_quit},
147 .fn_press = menu_btn_quit,
148 .ld="text_reset", .lr="text_settings", /*.ll="text_map"*/
149 },
150 {
151 "text_quitty", menu_vis, {.i=k_menu_page_quit}
152 },
153 {
154 "text_yes", menu_vis, {.i=k_menu_page_quit},
155 .fn_press = menu_btn_fuckoff
156 },
157 {
158 "text_reset", menu_vis, {.i=k_menu_page_main},
159 .fn_press = menu_btn_reset,
160 .lu="text_quit", .ld="text_skater", /*.ll="text_map",*/ .lr="text_settings"
161 },
162 {
163 "text_skater", menu_vis, {.i=k_menu_page_main|k_menu_page_skater},
164 .fn_press = menu_btn_skater,
165 .lu="text_reset", /*.ll="text_map",*/ .lr="text_settings"
166 },
167 /*
168 {
169 "text_map", menu_vis, {.i=k_menu_page_main},
170 .fn_press = menu_btn_map,
171 .lr="text_reset"
172 },
173 */
174 {
175 "text_settings", menu_vis, {.i=k_menu_page_main|k_menu_page_settings},
176 .fn_press = menu_btn_settings,
177 .ll="text_reset"
178 },
179 {
180 "skater_left", menu_vis, {k_menu_page_skater}
181 },
182 {
183 "skater_right", menu_vis, {k_menu_page_skater}
184 },
185
186 {
187 "fov_slider", menu_vis, {k_menu_page_settings},
188 .ld="text_invert_y"
189 },
190 { "fov_info", menu_vis, {k_menu_page_settings} },
191
192 {
193 "vol_slider", menu_vis, {k_menu_page_settings},
194 .lu="res_slider"
195 },
196 { "vol_info", menu_vis, {k_menu_page_settings} },
197
198 {
199 "text_invert_y", menu_vis, {k_menu_page_settings},
200 .fn_press = menu_btn_invert_y,
201 .lu = "fov_slider", .ld="text_blur"
202 },
203 {
204 "text_invert_y_check", menu_settings_if, {.ptr_generic=&cl_invert_y}
205 },
206 {
207 "text_blur", menu_vis, {k_menu_page_settings},
208 .fn_press = menu_btn_blur,
209 .lu="text_invert_y", .ld="res_slider"
210 },
211 {
212 "text_blur_check", menu_settings_if, {.ptr_generic=&cl_blur}
213 },
214 {
215 "res_slider", menu_vis, {k_menu_page_settings},
216 .ld = "vol_slider", .lu = "text_blur"
217 },
218 {
219 "res_info", menu_vis, {k_menu_page_settings},
220 },
221 { "ctr_xbox", menu_controller_inf, {k_steam_controller_type_xbox}},
222 { "ctr_xbox_text", menu_controller_inf, {k_steam_controller_type_xbox}},
223 { "ctr_steam", menu_controller_inf, {k_steam_controller_type_steam}},
224 { "ctr_steam_text", menu_controller_inf, {k_steam_controller_type_steam}},
225 { "ctr_deck", menu_controller_inf, {k_steam_controller_type_steam_deck}},
226 { "ctr_deck_text", menu_controller_inf, {k_steam_controller_type_steam_deck}},
227 { "ctr_ps", menu_controller_inf, {k_steam_controller_type_playstation}},
228 { "ctr_ps_text", menu_controller_inf, {k_steam_controller_type_playstation}},
229 { "ctr_kbm", menu_controller_inf, {k_steam_controller_type_keyboard}},
230 { "ctr_kbm_text", menu_controller_inf, {k_steam_controller_type_keyboard}},
231 {
232 "text_paused", menu_vis, {k_menu_page_main}
233 },
234 };
235
236 VG_STATIC int menu_get_loc( const char *loc )
237 {
238 for( int i=0; i<vg_list_size(menu_buttons); i++ )
239 if( !strcmp( menu_buttons[i].name, loc ) )
240 return i;
241
242 assert(0);
243 return 0;
244 }
245
246 VG_STATIC void menu_btn_reset( int event )
247 {
248 localplayer_cmd_respawn( 0, NULL );
249 cl_menu_go_away = 1;
250 game_menu.page = 0;
251 }
252
253 VG_STATIC void menu_btn_fuckoff( int event )
254 {
255 vg.window_should_close = 1;
256 }
257
258 VG_STATIC void menu_btn_quit( int event )
259 {
260 game_menu.page = k_menu_page_quit;
261 game_menu.loc = menu_get_loc( "text_yes" );
262 }
263
264 VG_STATIC void menu_btn_settings( int event )
265 {
266 game_menu.page = k_menu_page_settings;
267 game_menu.loc = menu_get_loc( "fov_slider" );
268 }
269
270 VG_STATIC void menu_btn_skater( int event )
271 {
272 game_menu.page = k_menu_page_skater;
273 }
274
275 VG_STATIC void menu_btn_blur( int event )
276 {
277 cl_blur ^= 0x1;
278 }
279
280 VG_STATIC void menu_btn_invert_y( int event )
281 {
282 cl_invert_y ^= 0x1;
283 }
284
285 VG_STATIC void menu_btn_map( int event )
286 {
287 game_menu.page = k_menu_page_map;
288 game_menu.map_count = 0;
289 game_menu.selected_map = 0;
290
291 tinydir_dir dir;
292 tinydir_open( &dir, "maps" );
293
294 while( dir.has_next ){
295 tinydir_file file;
296 tinydir_readfile( &dir, &file );
297
298 if( file.is_reg ){
299 struct menu_map_file *mf = &game_menu.maps_list[ game_menu.map_count ];
300
301 vg_strncpy( file.name, mf->name,
302 vg_list_size(game_menu.maps_list[0].name)-1 );
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
650 int toggle_gp = vg_input_button_down( &input_menu_toggle ),
651 toggle_kb = vg_input_button_down( &input_menu_toggle_kbm ),
652 wait_for_a_sec = 0;
653
654 if( toggle_gp || toggle_kb ){
655 if( cl_menu ){
656 if( toggle_gp ){
657 menu_close();
658 }
659 }
660 else{
661 if( toggle_kb )
662 wait_for_a_sec = 1;
663
664 cl_menu = 1;
665 game_menu.page = 1;
666 }
667 }
668
669 if( !wait_for_a_sec && cl_menu ){
670 if( game_menu.page == k_menu_page_main )
671 menu_page_main();
672 else if( game_menu.page == k_menu_page_skater )
673 menu_page_skater();
674 else if( game_menu.page == k_menu_page_quit )
675 menu_page_quit();
676 else if( game_menu.page == k_menu_page_settings )
677 menu_page_settings();
678 else if( game_menu.page == k_menu_page_map )
679 menu_page_map();
680 }
681
682 struct menu_button *btn = &menu_buttons[ game_menu.loc ];
683
684 /* Base */
685 {
686 player_instance *player = &localplayer;
687 struct player_avatar *av = player->playeravatar;
688
689 v3f center_rough;
690 if( player->subsystem == k_player_subsystem_dead ){
691 m4x3_mulv( av->sk.final_mtx[av->id_hip], (v3f){0.0f,0.9f,0.0f},
692 center_rough );
693 }
694 else{
695 m4x3_mulv( av->sk.final_mtx[av->id_head], (v3f){0.0f,1.5f,0.0f},
696 center_rough );
697 }
698
699 v3f cam_offset;
700 float cam_rot;
701 if( player->subsystem == k_player_subsystem_walk ){
702 v3_muls( player->rb.to_world[2], 1.0f, cam_offset );
703 cam_rot = 0.0f;
704 }
705 else{
706 v3_muls( player->rb.to_world[0], -1.0f, cam_offset );
707 cam_rot = -VG_PIf*0.5f;
708 }
709
710
711 v3f lookdir;
712 m3x3_mulv( player->invbasis, cam_offset, lookdir );
713 lookdir[1] = 0.0f;
714 v3_normalize( lookdir );
715
716 m3x3_mulv( player->basis, lookdir, cam_offset );
717 v3_muladds( center_rough, cam_offset, 2.0f, menu_camera_pos );
718
719 menu_camera_angles[1] = 0.0f;
720 menu_camera_angles[0] = -atan2f( lookdir[0], lookdir[2] );
721
722 /* setup model matrix */
723 v4f qmenu_mdl;
724 q_axis_angle( qmenu_mdl, (v3f){0.0f,1.0f,0.0f}, -menu_camera_angles[0] );
725 q_m3x3( qmenu_mdl, menu_mdl_mtx );
726 v3_add( center_rough, (v3f){0.0f,-0.5f,0.0f}, menu_mdl_mtx[3] );
727 m3x3_mul( player->basis, menu_mdl_mtx, menu_mdl_mtx );
728
729 menu_smooth_fov = vg_lerpf( menu_smooth_fov, menu_fov_target,
730 vg.time_frame_delta * 8.2f );
731 }
732
733 /* Extra */
734 {
735 v3f delta;
736 v3_sub( btn->mesh->transform.co, (v3f){ 0.0f,1.5f,-1.5f }, delta );
737 v3_normalize( delta );
738
739 float y = atan2f( delta[0], delta[2] ),
740 p = -sinf(delta[1]),
741 dt = vg.time_frame_delta;
742
743 menu_extra_angles[0] = vg_lerpf( menu_extra_angles[0], y, dt );
744 menu_extra_angles[1] = vg_lerpf( menu_extra_angles[1], p, dt );
745
746 v2_muladds( menu_camera_angles, menu_extra_angles, 0.8f,
747 menu_camera_angles );
748 menu_camera_angles[0] = fmodf( menu_camera_angles[0], VG_TAUf );
749 }
750
751 float dt = vg.time_frame_delta * 6.0f;
752 menu_opacity = vg_lerpf( menu_opacity, cl_menu&&!cl_menu_go_away, dt );
753
754 if( menu_opacity <= 0.01f ){
755 cl_menu = 0;
756 cl_menu_go_away = 0;
757 }
758
759 vg.time_rate = 1.0-(double)menu_opacity;
760
761 if( cl_menu ){
762 menu_input_cooldown -= vg.time_frame_delta;
763 }
764 }
765
766 /* https://iquilezles.org/articles/functions/ */
767 float expSustainedImpulse( float x, float f, float k )
768 {
769 float s = fmaxf(x-f,0.0f);
770 return fminf( x*x/(f*f), 1.0f+(2.0f/f)*s*expf(-k*s));
771 }
772
773 VG_STATIC void menu_render_bg(void)
774 {
775 glEnable(GL_BLEND);
776 glDisable(GL_DEPTH_TEST);
777 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
778 glBlendEquation(GL_FUNC_ADD);
779
780 shader_blitcolour_use();
781 shader_blitcolour_uColour( (v4f){ 0.1f, 0.1f, 0.3f, menu_opacity*0.5f } );
782 render_fsquad();
783 }
784
785 VG_STATIC void menu_render_fg( camera *cam )
786 {
787 glEnable( GL_DEPTH_TEST );
788 glDisable( GL_BLEND );
789
790 m4x3f mtx;
791
792 shader_model_menu_use();
793 shader_model_menu_uColour( (v4f){ 1.0f,1.0f,1.0f,1.0f} );
794 shader_model_menu_uTexMain( 1 );
795
796 glActiveTexture( GL_TEXTURE1 );
797 glBindTexture( GL_TEXTURE_2D, tex_menu );
798
799 shader_model_menu_uPv( cam->mtx.pv );
800 shader_model_menu_uPvmPrev( cam->mtx_prev.pv );
801 mesh_bind( &menu_glmesh );
802
803 for( int i=0; i<vg_list_size(menu_buttons); i++ ){
804 struct menu_button *btn = &menu_buttons[i];
805 float talpha = i==game_menu.loc? 1.0f: 0.0f,
806 tsize0 = btn->fn_visibility( btn->user )? 1.0f: 0.0f,
807 tsize1 = i==game_menu.loc? 0.07f: 0.0f,
808 tsize = tsize0+tsize1;
809
810 btn->falpha = vg_lerpf( btn->falpha, talpha, vg.time_frame_delta * 14.0f);
811 btn->fsize = vg_lerpf( btn->fsize, tsize, vg.time_frame_delta * 7.0f );
812
813 /* Colour */
814 v4f vselected = {0.95f*1.3f,0.45f*1.3f,0.095f*1.3f, 1.0f},
815 vnormal = {1.0f,1.0f,1.0f, 1.0f},
816 vcurrent;
817
818 v4_lerp( vnormal, vselected, btn->falpha, vcurrent );
819 shader_model_menu_uColour( vcurrent );
820
821 /* Create matrix */
822 m4x3f mtx_size;
823 mdl_transform_m4x3( &btn->mesh->transform, mtx );
824 m4x3_mul( menu_mdl_mtx, mtx, mtx );
825 m4x3_identity( mtx_size );
826 m3x3_scalef( mtx_size, expSustainedImpulse( btn->fsize, 0.5f, 8.7f) );
827 m4x3_mul( mtx, mtx_size, mtx );
828 shader_model_menu_uMdl( mtx );
829
830 for( int j=0; j<btn->mesh->submesh_count; j++ ){
831 mdl_submesh *sm =
832 mdl_arritm( &menu_model.submeshs, btn->mesh->submesh_start+j );
833 mdl_draw_submesh( sm );
834 }
835 }
836
837 /*
838 for( int i=0; i<menu_model->node_count; i++ )
839 {
840 mdl_node *pnode = mdl_node_from_id( menu_model, i );
841
842 for( int j=0; j<pnode->submesh_count; j++ )
843 {
844 mdl_submesh *sm =
845 mdl_submesh_from_id( menu_model, pnode->submesh_start+j );
846
847 mdl_node_transform( pnode, mtx );
848 m4x3_mul( menu_mdl_mtx, mtx, mtx );
849 shader_menu_uMdl( mtx );
850
851 mdl_draw_submesh( sm );
852 }
853 }
854 */
855 }
856
857 #endif /* MENU_H */