7a5117d2422d56ae0029d19489c25215a8dece48
[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( cl_menu && (game_menu.page == k_menu_page_map) ){
324 ui_rect box;
325 box[0] = vg.window_x/2 - 150;
326 box[1] = vg.window_y/2 - 300;
327 box[2] = 300;
328 box[3] = 600;
329
330 ui_fill_rect( box, 0xa0000000 );
331
332 if( game_menu.map_count == 0 ){
333 ui_text( (ui_rect){ vg.window_x/2, box[1]+8, 0,0 }, "No maps found", 1,
334 k_text_align_center );
335 }
336 else{
337 ui_rect_pad( box, 4 );
338 box[3] = 16;
339
340 for( int i=0; i<game_menu.map_count; i++ ){
341 struct menu_map_file *mf = &game_menu.maps_list[ i ];
342
343 ui_fill_rect( box, game_menu.selected_map == i? 0xa0ffffff:
344 0xa0808080 );
345 ui_text( (ui_rect){ vg.window_x/2, box[1]+2, 0,0 },
346 mf->name, 1, k_text_align_center );
347 box[1] += 16+4;
348 }
349 }
350 }
351 }
352
353 VG_STATIC void steam_on_game_overlay( CallbackMsg_t *msg )
354 {
355 GameOverlayActivated_t *inf = (GameOverlayActivated_t *)msg->m_pubParam;
356 vg_info( "Steam game overlay activated; pausing\n" );
357
358 if( inf->m_bActive ){
359 cl_menu = 1;
360 game_menu.page = k_menu_page_main;
361 game_menu.loc = menu_get_loc( "text_skater" );
362 }
363 }
364
365 VG_STATIC void menu_init(void)
366 {
367 #if 0
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 #endif
381
382 vg_linear_clear( vg_mem.scratch );
383
384 mdl_open( &menu_model, "models/rs_menu.mdl", vg_mem.rtmemory );
385 mdl_load_metadata_block( &menu_model, vg_mem.rtmemory );
386 mdl_load_array( &menu_model, &menu_markers, "ent_marker", vg_mem.rtmemory );
387 //mdl_invert_uv_coordinates( &menu_model );
388 mdl_async_load_glmesh( &menu_model, &menu_glmesh );
389 mdl_close( &menu_model );
390
391 vg_tex2d_load_qoi_async_file( "textures/menu.qoi",
392 VG_TEX2D_CLAMP|VG_TEX2D_NEAREST,
393 &tex_menu );
394
395
396 for( int i=0; i<vg_list_size(menu_buttons); i++ ){
397 struct menu_button *btn = &menu_buttons[i];
398 btn->mesh = mdl_find_mesh( &menu_model, btn->name );
399
400 if( !btn->mesh ){
401 vg_info( "info: %s\n", btn->name );
402 vg_fatal_error( "Menu programming error" );
403 }
404 }
405
406 menu_mark_fov_max =
407 ent_find_marker( &menu_model, &menu_markers, "fov_slider_max" );
408 menu_mark_fov_min =
409 ent_find_marker( &menu_model, &menu_markers, "fov_slider_min" );
410 menu_mark_vol_max =
411 ent_find_marker( &menu_model, &menu_markers, "vol_slider_max" );
412 menu_mark_vol_min =
413 ent_find_marker( &menu_model, &menu_markers, "vol_slider_min" );
414 menu_mark_res_max =
415 ent_find_marker( &menu_model, &menu_markers, "res_slider_max" );
416 menu_mark_res_min =
417 ent_find_marker( &menu_model, &menu_markers, "res_slider_min" );
418
419 menu_mesh_fov_slider = mdl_find_mesh( &menu_model, "fov_slider" );
420 menu_mesh_vol_slider = mdl_find_mesh( &menu_model, "vol_slider" );
421 menu_mesh_res_slider = mdl_find_mesh( &menu_model, "res_slider" );
422
423 shader_model_menu_register();
424
425 #ifdef SR_NETWORKED
426 steam_register_callback( k_iGameOverlayActivated, steam_on_game_overlay );
427 #endif
428 }
429
430 VG_STATIC void menu_run_directional(void)
431 {
432 #if 0
433 struct menu_button *btn = &menu_buttons[ game_menu.loc ];
434
435 if( vg_input_button_down( &input_menu_press ) ){
436 if( btn->fn_press ){
437 audio_lock();
438 audio_oneshot( &audio_ui[0], 1.0f, 0.0f );
439 audio_unlock();
440
441 btn->fn_press( 1 );
442 return;
443 }
444 }
445
446 if( menu_input_cooldown <= 0.0f ){
447 v2f dir = { input_menu_h.axis.value,
448 -input_menu_v.axis.value };
449
450 if( v2_length2( dir ) > 0.8f*0.8f ){
451 const char *link = NULL;
452
453 if( fabsf(dir[0]) > fabsf(dir[1]) ){
454 if( dir[0] > 0.0f ) link = btn->lr;
455 else link = btn->ll;
456 }
457 else{
458 if( dir[1] > 0.0f ) link = btn->ld;
459 else link = btn->lu;
460 }
461
462 if( link ){
463 game_menu.loc = menu_get_loc( link );
464 menu_input_cooldown = 0.25f;
465 }
466 }
467 }
468 #endif
469 }
470
471 VG_STATIC int menu_page_should_backout(void)
472 {
473 return 0;
474 #if 0
475 return vg_input_button_down( &input_menu_back );
476 #endif
477 }
478
479 VG_STATIC void menu_close(void)
480 {
481 cl_menu_go_away = 1;
482 game_menu.page = 0;
483 game_menu.loc = menu_get_loc( "text_skater" );
484 }
485
486 VG_STATIC void menu_page_main(void)
487 {
488 if( menu_page_should_backout() )
489 {
490 menu_close();
491 return;
492 }
493
494 menu_fov_target = 112.0f;
495 menu_run_directional();
496 }
497
498 VG_STATIC void menu_page_map(void)
499 {
500 if( menu_page_should_backout() ){
501 game_menu.page = k_menu_page_main;
502 game_menu.loc = menu_get_loc( "text_map" );
503 }
504
505 if( game_menu.map_count > 0 ){
506 #if 0
507 float v = input_menu_v.axis.value;
508 if( (fabsf(v) > 0.7f) && (menu_input_cooldown <= 0.0f) ){
509 audio_lock();
510 audio_oneshot( &audio_rewind[4], 1.0f, 0.0f );
511 audio_unlock();
512
513 if( v > 0.0f ){
514 game_menu.selected_map --;
515
516 if( game_menu.selected_map < 0 )
517 game_menu.selected_map = game_menu.map_count-1;
518
519 menu_input_cooldown = 0.25f;
520 }
521 else{
522 game_menu.selected_map ++;
523
524 if( game_menu.selected_map >= game_menu.map_count )
525 game_menu.selected_map = 0;
526
527 menu_input_cooldown = 0.25f;
528 }
529 }
530
531 if( vg_input_button_down( &input_menu_press ) ){
532 #if 0
533 /* load map */
534 char temp[256];
535 strcpy( temp, "maps/" );
536 strcat( temp, game_menu.maps_list[game_menu.selected_map].name );
537
538 world_change_world( 1, (const char *[]){ temp } );
539 menu_close();
540 #endif
541 }
542 #endif
543 }
544
545 menu_fov_target = 80.0f;
546 }
547
548 VG_STATIC void menu_page_quit(void)
549 {
550 if( menu_page_should_backout() ){
551 game_menu.page = k_menu_page_main;
552 game_menu.loc = menu_get_loc( "text_quit" );
553 }
554
555 menu_fov_target = 90.0f;
556 menu_run_directional();
557 }
558
559 void temp_update_playermodel(void);
560 VG_STATIC void menu_page_skater(void)
561 {
562 #if 0
563 float h = input_menu_h.axis.value;
564 menu_fov_target = 97.0f;
565
566 if( menu_page_should_backout() ){
567 game_menu.page = k_menu_page_main;
568 game_menu.loc = menu_get_loc( "text_skater" );
569 return;
570 }
571
572 if( (fabsf(h) > 0.7f) && (menu_input_cooldown <= 0.0f) ){
573 audio_lock();
574 audio_oneshot( &audio_rewind[4], 1.0f, 0.0f );
575 audio_unlock();
576
577 vg_info( "%f\n", h );
578
579 if( h < 0.0f ){
580 cl_playermdl_id --;
581 if( cl_playermdl_id < 0 )
582 cl_playermdl_id = 2;
583
584 int li = menu_get_loc( "skater_left" );
585
586 menu_buttons[li].fsize = 0.4f;
587 menu_buttons[li].falpha = 1.0f;
588
589 menu_input_cooldown = 0.25f;
590 }
591 else{
592 cl_playermdl_id ++;
593 if( cl_playermdl_id > 2 )
594 cl_playermdl_id = 0;
595
596 int ri = menu_get_loc( "skater_right" );
597
598 menu_buttons[ri].fsize = 0.4f;
599 menu_buttons[ri].falpha = 1.0f;
600
601 menu_input_cooldown = 0.25f;
602 }
603
604 temp_update_playermodel();
605 }
606 #endif
607 }
608
609 VG_STATIC void menu_slider( float *value, int set_value,
610 mdl_mesh *slider, v3f co_min, v3f co_max )
611 {
612 #if 0
613 if( set_value ){
614 float h = input_menu_h.axis.value;
615 if( fabsf(h) > 0.04f )
616 *value += h * vg.time_frame_delta;
617 *value = vg_clampf( *value, 0.0f, 1.0f );
618 }
619
620 v3_lerp( co_min, co_max, *value, slider->transform.co );
621 #endif
622 }
623
624 VG_STATIC void menu_page_settings(void)
625 {
626 menu_run_directional();
627
628 int fov_select = game_menu.loc == menu_get_loc( "fov_slider" );
629 menu_slider( &cl_fov, fov_select,
630 menu_mesh_fov_slider, menu_mark_fov_min->transform.co,
631 menu_mark_fov_max->transform.co );
632
633 if( fov_select )
634 menu_fov_target = vg_lerpf( 97.0f, 135.0f, cl_fov ) * 0.8f;
635
636 menu_slider( &vg_audio.external_global_volume,
637 (game_menu.loc == menu_get_loc( "vol_slider" )),
638 menu_mesh_vol_slider, menu_mark_vol_min->transform.co,
639 menu_mark_vol_max->transform.co );
640
641 menu_slider( &gpipeline.view_render_scale,
642 (game_menu.loc == menu_get_loc( "res_slider" )),
643 menu_mesh_res_slider, menu_mark_res_min->transform.co,
644 menu_mark_res_max->transform.co );
645
646 if( menu_page_should_backout() ){
647 game_menu.page = k_menu_page_main;
648 game_menu.loc = menu_get_loc( "text_settings" );
649 return;
650 }
651 }
652
653 VG_STATIC void menu_update(void)
654 {
655 #if 0
656 vg_input_update( 1, &input_menu_h );
657 vg_input_update( 1, &input_menu_v );
658 vg_input_update( 1, &input_menu_back );
659 vg_input_update( 1, &input_menu_press );
660 vg_input_update( 1, &input_menu_toggle );
661 vg_input_update( 1, &input_menu_toggle_kbm );
662 #endif
663 return;
664
665
666 #if 0
667 int toggle_gp = vg_input_button_down( &input_menu_toggle ),
668 toggle_kb = vg_input_button_down( &input_menu_toggle_kbm ),
669 wait_for_a_sec = 0;
670
671 if( toggle_gp || toggle_kb ){
672 if( cl_menu ){
673 if( toggle_gp ){
674 menu_close();
675 }
676 }
677 else{
678 if( toggle_kb )
679 wait_for_a_sec = 1;
680
681 cl_menu = 1;
682 game_menu.page = 1;
683 }
684 }
685
686 if( !wait_for_a_sec && cl_menu ){
687 if( game_menu.page == k_menu_page_main )
688 menu_page_main();
689 else if( game_menu.page == k_menu_page_skater )
690 menu_page_skater();
691 else if( game_menu.page == k_menu_page_quit )
692 menu_page_quit();
693 else if( game_menu.page == k_menu_page_settings )
694 menu_page_settings();
695 else if( game_menu.page == k_menu_page_map )
696 menu_page_map();
697 }
698
699 struct menu_button *btn = &menu_buttons[ game_menu.loc ];
700
701 /* Base */
702 {
703 player_instance *player = &localplayer;
704 struct player_avatar *av = player->playeravatar;
705
706 v3f center_rough;
707 if( player->subsystem == k_player_subsystem_dead ){
708 m4x3_mulv( av->sk.final_mtx[av->id_hip], (v3f){0.0f,0.9f,0.0f},
709 center_rough );
710 }
711 else{
712 m4x3_mulv( av->sk.final_mtx[av->id_head], (v3f){0.0f,1.5f,0.0f},
713 center_rough );
714 }
715
716 v3f cam_offset;
717 float cam_rot;
718 if( player->subsystem == k_player_subsystem_walk ){
719 v3_muls( player->rb.to_world[2], 1.0f, cam_offset );
720 cam_rot = 0.0f;
721 }
722 else{
723 v3_muls( player->rb.to_world[0], -1.0f, cam_offset );
724 cam_rot = -VG_PIf*0.5f;
725 }
726
727
728 v3f lookdir;
729 m3x3_mulv( player->invbasis, cam_offset, lookdir );
730 lookdir[1] = 0.0f;
731 v3_normalize( lookdir );
732
733 m3x3_mulv( player->basis, lookdir, cam_offset );
734 v3_muladds( center_rough, cam_offset, 2.0f, menu_camera_pos );
735
736 menu_camera_angles[1] = 0.0f;
737 menu_camera_angles[0] = -atan2f( lookdir[0], lookdir[2] );
738
739 /* setup model matrix */
740 v4f qmenu_mdl;
741 q_axis_angle( qmenu_mdl, (v3f){0.0f,1.0f,0.0f}, -menu_camera_angles[0] );
742 q_m3x3( qmenu_mdl, menu_mdl_mtx );
743 v3_add( center_rough, (v3f){0.0f,-0.5f,0.0f}, menu_mdl_mtx[3] );
744 m3x3_mul( player->basis, menu_mdl_mtx, menu_mdl_mtx );
745
746 menu_smooth_fov = vg_lerpf( menu_smooth_fov, menu_fov_target,
747 vg.time_frame_delta * 8.2f );
748 }
749
750 /* Extra */
751 {
752 v3f delta;
753 v3_sub( btn->mesh->transform.co, (v3f){ 0.0f,1.5f,-1.5f }, delta );
754 v3_normalize( delta );
755
756 float y = atan2f( delta[0], delta[2] ),
757 p = -sinf(delta[1]),
758 dt = vg.time_frame_delta;
759
760 menu_extra_angles[0] = vg_lerpf( menu_extra_angles[0], y, dt );
761 menu_extra_angles[1] = vg_lerpf( menu_extra_angles[1], p, dt );
762
763 v2_muladds( menu_camera_angles, menu_extra_angles, 0.8f,
764 menu_camera_angles );
765 menu_camera_angles[0] = fmodf( menu_camera_angles[0], VG_TAUf );
766 }
767
768 float dt = vg.time_frame_delta * 6.0f;
769 menu_opacity = vg_lerpf( menu_opacity, cl_menu&&!cl_menu_go_away, dt );
770
771 if( menu_opacity <= 0.01f ){
772 cl_menu = 0;
773 cl_menu_go_away = 0;
774 }
775
776 vg.time_rate = 1.0-(double)menu_opacity;
777
778 if( cl_menu ){
779 menu_input_cooldown -= vg.time_frame_delta;
780 }
781 #endif
782 }
783
784 /* https://iquilezles.org/articles/functions/ */
785 float expSustainedImpulse( float x, float f, float k )
786 {
787 float s = fmaxf(x-f,0.0f);
788 return fminf( x*x/(f*f), 1.0f+(2.0f/f)*s*expf(-k*s));
789 }
790
791 VG_STATIC void menu_render_bg(void)
792 {
793 glEnable(GL_BLEND);
794 glDisable(GL_DEPTH_TEST);
795 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
796 glBlendEquation(GL_FUNC_ADD);
797
798 shader_blitcolour_use();
799 shader_blitcolour_uColour( (v4f){ 0.1f, 0.1f, 0.3f, menu_opacity*0.5f } );
800 render_fsquad();
801 }
802
803 VG_STATIC void menu_render_fg( camera *cam )
804 {
805 glEnable( GL_DEPTH_TEST );
806 glDisable( GL_BLEND );
807
808 m4x3f mtx;
809
810 shader_model_menu_use();
811 shader_model_menu_uColour( (v4f){ 1.0f,1.0f,1.0f,1.0f} );
812 shader_model_menu_uTexMain( 1 );
813
814 glActiveTexture( GL_TEXTURE1 );
815 glBindTexture( GL_TEXTURE_2D, tex_menu );
816
817 shader_model_menu_uPv( cam->mtx.pv );
818 shader_model_menu_uPvmPrev( cam->mtx_prev.pv );
819 mesh_bind( &menu_glmesh );
820
821 for( int i=0; i<vg_list_size(menu_buttons); i++ ){
822 struct menu_button *btn = &menu_buttons[i];
823 float talpha = i==game_menu.loc? 1.0f: 0.0f,
824 tsize0 = btn->fn_visibility( btn->user )? 1.0f: 0.0f,
825 tsize1 = i==game_menu.loc? 0.07f: 0.0f,
826 tsize = tsize0+tsize1;
827
828 btn->falpha = vg_lerpf( btn->falpha, talpha, vg.time_frame_delta * 14.0f);
829 btn->fsize = vg_lerpf( btn->fsize, tsize, vg.time_frame_delta * 7.0f );
830
831 /* Colour */
832 v4f vselected = {0.95f*1.3f,0.45f*1.3f,0.095f*1.3f, 1.0f},
833 vnormal = {1.0f,1.0f,1.0f, 1.0f},
834 vcurrent;
835
836 v4_lerp( vnormal, vselected, btn->falpha, vcurrent );
837 shader_model_menu_uColour( vcurrent );
838
839 /* Create matrix */
840 m4x3f mtx_size;
841 mdl_transform_m4x3( &btn->mesh->transform, mtx );
842 m4x3_mul( menu_mdl_mtx, mtx, mtx );
843 m4x3_identity( mtx_size );
844 m3x3_scalef( mtx_size, expSustainedImpulse( btn->fsize, 0.5f, 8.7f) );
845 m4x3_mul( mtx, mtx_size, mtx );
846 shader_model_menu_uMdl( mtx );
847
848 for( int j=0; j<btn->mesh->submesh_count; j++ ){
849 mdl_submesh *sm =
850 mdl_arritm( &menu_model.submeshs, btn->mesh->submesh_start+j );
851 mdl_draw_submesh( sm );
852 }
853 }
854
855 /*
856 for( int i=0; i<menu_model->node_count; i++ )
857 {
858 mdl_node *pnode = mdl_node_from_id( menu_model, i );
859
860 for( int j=0; j<pnode->submesh_count; j++ )
861 {
862 mdl_submesh *sm =
863 mdl_submesh_from_id( menu_model, pnode->submesh_start+j );
864
865 mdl_node_transform( pnode, mtx );
866 m4x3_mul( menu_mdl_mtx, mtx, mtx );
867 shader_menu_uMdl( mtx );
868
869 mdl_draw_submesh( sm );
870 }
871 }
872 */
873 }
874
875 #endif /* MENU_H */