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