6 #include "world_render.h"
9 #include "shaders/menu.h"
10 #include "vg/vg_steam_friends.h"
12 VG_STATIC mdl_context menu_model
;
13 VG_STATIC glmesh menu_glmesh
;
14 VG_STATIC m4x3f menu_mdl_mtx
;
15 VG_STATIC
float menu_opacity
= 0.0f
;
16 VG_STATIC
float menu_input_cooldown
= 0.0f
;
17 VG_STATIC
float menu_fov_target
= 97.0f
;
18 VG_STATIC v2f menu_extra_angles
;
20 VG_STATIC
int menu_loc
= 0xb,
22 VG_STATIC u32 menu_page
= 0;
24 VG_STATIC
int cl_menu
= 0,
27 VG_STATIC
const char *playermodels
[] = { "ch_new", "ch_jordan", "ch_outlaw" };
29 vg_tex2d tex_menu
= { .path
= "textures/menu.qoi",.flags
= VG_TEXTURE_NEAREST
};
31 VG_STATIC
void menu_btn_paused( int event
);
32 VG_STATIC
void menu_btn_quit( int event
);
33 VG_STATIC
void menu_btn_skater( int event
);
34 VG_STATIC
void menu_btn_map( int event
);
35 VG_STATIC
void menu_btn_map_a( int event
);
36 VG_STATIC
void menu_btn_map_b( int event
);
37 VG_STATIC
void menu_btn_map_c( int event
);
38 VG_STATIC
void menu_btn_fuckoff( int event
);
39 VG_STATIC
void menu_btn_reset( int event
);
46 void (*fn_press
)(int event
);
52 VG_STATIC menu_buttons
[] =
54 /*0*/{"text_paused", 1, menu_btn_paused
},
55 /*1*/{"text_quit", 9, menu_btn_quit
, {3,-1,4,0xb}},
56 /*2*/{"text_skater", 3, menu_btn_skater
, {3,0xb,4,-1}},
57 /*3*/{"text_map", 5, NULL
, {-1,-1,2,-1}},
58 /*4*/{"text_about_game", 1, NULL
, {2,-1,-1,-1}},
59 /*5*/{"skater_left", 2, NULL
, {-1,-1,-1,-1}},
60 /*6*/{"skater_right", 2, NULL
, {-1,-1,-1,-1}},
61 /*7*/{"g_map", 5, NULL
},
62 /*8*/{"g_controls", 1, NULL
},
63 /*9*/{"text_quitty", 8, NULL
},
64 /*a*/{"text_yes", 8, menu_btn_fuckoff
,{-1,-1,-1,-1} },
65 /*b*/{"text_reset", 1, menu_btn_reset
,{3,1,4,2} },
68 VG_STATIC
void menu_btn_map_a( int event
){}
69 VG_STATIC
void menu_btn_map_b( int event
){}
70 VG_STATIC
void menu_btn_map_c( int event
){}
72 VG_STATIC
void menu_btn_paused( int event
)
77 VG_STATIC
void menu_btn_reset( int event
)
86 VG_STATIC
void menu_btn_fuckoff( int event
)
88 glfwSetWindowShouldClose( vg
.window
, 1 );
91 VG_STATIC
void menu_btn_quit( int event
)
97 VG_STATIC
void menu_btn_map( int event
)
103 VG_STATIC
void menu_btn_skater( int event
)
109 VG_STATIC
void steam_on_game_overlay( CallbackMsg_t
*msg
)
111 GameOverlayActivated_t
*inf
= (GameOverlayActivated_t
*)msg
->m_pubParam
;
112 vg_info( "Steam game overlay activated; pausing\n" );
121 VG_STATIC
void menu_init(void)
123 vg_linear_clear( vg_mem
.scratch
);
125 mdl_open( &menu_model
, "models/rs_menu.mdl" );
126 mdl_load_metadata( &menu_model
, vg_mem
.rtmemory
);
127 mdl_load_mesh_data( &menu_model
, vg_mem
.scratch
);
128 mdl_close( &menu_model
);
130 vg_acquire_thread_sync();
132 mdl_unpack_glmesh( &menu_model
, &menu_glmesh
);
133 vg_tex2d_init( (vg_tex2d
*[]){ &tex_menu
}, 1 );
135 vg_release_thread_sync();
137 for( int i
=0; i
<vg_list_size(menu_buttons
); i
++ )
139 struct menu_button
*btn
= &menu_buttons
[i
];
140 btn
->pnode
= mdl_node_from_name( &menu_model
, btn
->name
);
143 vg_fatal_exit_loop( "Menu programming error" );
146 shader_menu_register();
149 steam_register_callback( k_iGameOverlayActivated
, steam_on_game_overlay
);
153 VG_STATIC
void menu_run_directional(void)
155 struct menu_button
*btn
= &menu_buttons
[ menu_loc
];
157 if( vg_get_button_down( "jump" ) )
162 audio_play_oneshot( &audio_ui
[0], 1.0f
);
170 if( menu_input_cooldown
<= 0.0f
)
172 v2f dir
= { vg_get_axis( "lookh" ), vg_get_axis( "lookv" ) };
174 if( v2_length2( dir
) > 0.8f
*0.8f
)
178 if( fabsf(dir
[0]) > fabsf(dir
[1]) )
180 if( dir
[0] > 0.0f
) idir
= 2;
185 if( dir
[1] > 0.0f
) idir
= 3;
189 int link
= btn
->links
[idir
];
193 menu_loc_last
= menu_loc
;
195 menu_input_cooldown
= 0.25f
;
201 VG_STATIC
int menu_page_should_backout(void)
203 return vg_get_button_down( "break" );
206 VG_STATIC
void menu_close(void)
212 VG_STATIC
void menu_page_main(void)
214 if( menu_page_should_backout() )
220 menu_fov_target
= 112.0f
;
221 menu_run_directional();
224 VG_STATIC
void menu_page_map(void)
226 if( menu_page_should_backout() )
232 menu_fov_target
= 80.0f
;
233 menu_run_directional();
236 VG_STATIC
void menu_page_quit(void)
238 if( menu_page_should_backout() )
244 menu_fov_target
= 90.0f
;
245 menu_run_directional();
248 VG_STATIC
void menu_page_skater(void)
250 float h
= vg_get_axis( "lookh" );
251 menu_fov_target
= 97.0f
;
253 if( menu_page_should_backout() )
260 if( (fabsf(h
) > 0.7f
) && (menu_input_cooldown
<= 0.0f
) )
263 audio_play_oneshot( &audio_rewind
[4], 1.0f
);
269 if( cl_playermdl_id
< 0 )
272 menu_buttons
[5].fsize
= 0.4f
;
273 menu_buttons
[5].falpha
= 1.0f
;
275 menu_input_cooldown
= 0.25f
;
280 if( cl_playermdl_id
> 2 )
283 menu_buttons
[6].fsize
= 0.4f
;
284 menu_buttons
[6].falpha
= 1.0f
;
286 menu_input_cooldown
= 0.25f
;
291 VG_STATIC
void menu_update(void)
293 if( vg_get_button_down( "menu" ) )
309 else if( menu_page
== 2 )
311 else if( menu_page
== 4 )
313 else if( menu_page
== 8 )
316 struct menu_button
*btn
= &menu_buttons
[ menu_loc
];
324 v3f
*mtx
= player
.mdl
.sk
.final_mtx
[player
.mdl
.id_head
];
325 m3x3_mulv( mtx
, (v3f
){-1.0f
,0.0f
,0.0f
}, lookdir
);
328 v3_normalize( lookdir
);
334 v3_copy(player
.mdl
.ragdoll
[ player
.mdl
.id_hip
-1 ].rb
.co
, center_rough
);
338 v3_add( player
.camera_pos
, player
.visual_transform
[3], center_rough
);
339 v3_muls( center_rough
, 0.5f
, center_rough
);
342 v3_muladds( center_rough
, lookdir
, 1.5f
, pos
);
343 v3_add( (v3f
){ 0.0f
,0.8f
,0.0f
}, pos
, pos
);
346 angles
[0] = -atan2f( lookdir
[0], lookdir
[2] );
348 /* setup model matrix */
350 q_axis_angle( qmenu_mdl
, (v3f
){0.0f
,1.0f
,0.0f
}, -angles
[0] );
352 q_m3x3( qmenu_mdl
, menu_mdl_mtx
);
353 v3_copy( center_rough
, menu_mdl_mtx
[3] );
359 v3_sub( btn
->pnode
->co
, (v3f
){ 0.0f
,1.5f
,-1.5f
}, delta
);
360 v3_normalize( delta
);
362 float y
= atan2f( delta
[0], delta
[2] ),
366 menu_extra_angles
[0] = vg_lerpf( menu_extra_angles
[0], y
, dt
);
367 menu_extra_angles
[1] = vg_lerpf( menu_extra_angles
[1], p
, dt
);
369 v2_muladds( angles
, menu_extra_angles
, 0.8f
, angles
);
370 angles
[0] = fmodf( angles
[0], VG_TAUf
);
375 camera_angles
[0] = vg_alerpf( camera_angles
[0], angles
[0], menu_opacity
);
376 camera_angles
[1] = vg_lerpf ( camera_angles
[1], angles
[1], menu_opacity
);
377 v3_lerp( camera_pos
, pos
, menu_opacity
, camera_pos
);
381 float dt
= vg
.frame_delta
* 6.0f
;
382 menu_opacity
= vg_lerpf( menu_opacity
, cl_menu
&&!cl_menu_go_away
, dt
);
384 if( menu_opacity
<= 0.01f
)
390 vg
.time_rate
= 1.0-(double)menu_opacity
;
394 menu_input_cooldown
-= vg
.frame_delta
;
398 /* https://iquilezles.org/articles/functions/ */
399 float expSustainedImpulse( float x
, float f
, float k
)
401 float s
= fmaxf(x
-f
,0.0f
);
402 return fminf( x
*x
/(f
*f
), 1.0f
+(2.0f
/f
)*s
*expf(-k
*s
));
405 VG_STATIC
void menu_render( m4x4f projection
)
408 glDisable(GL_DEPTH_TEST
);
409 glBlendFunc( GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
410 glBlendEquation(GL_FUNC_ADD
);
412 shader_fscolour_use();
413 shader_fscolour_uColour( (v4f
){ 0.1f
, 0.1f
, 0.3f
, menu_opacity
*0.5f
} );
416 glEnable( GL_DEPTH_TEST
);
417 glDisable( GL_BLEND
);
422 shader_menu_uColour( (v4f
){ 1.0f
,1.0f
,1.0f
,1.0f
} );
423 shader_menu_uTexMain( 1 );
424 vg_tex2d_bind( &tex_menu
, 1 );
426 shader_menu_uPv( projection
);
427 mesh_bind( &menu_glmesh
);
429 for( int i
=0; i
<vg_list_size(menu_buttons
); i
++ )
431 struct menu_button
*btn
= &menu_buttons
[i
];
432 float talpha
= i
==menu_loc
? 1.0f
: 0.0f
,
433 tsize0
= btn
->areas
& menu_page
? 1.0f
: 0.0f
,
434 tsize1
= i
==menu_loc
? 0.07f
: 0.0f
,
435 tsize
= tsize0
+tsize1
;
437 btn
->falpha
= vg_lerpf( btn
->falpha
, talpha
, vg
.frame_delta
* 14.0f
);
438 btn
->fsize
= vg_lerpf( btn
->fsize
, tsize
, vg
.frame_delta
* 3.0f
);
441 v4f vselected
= {0.95f
*1.3f
,0.45f
*1.3f
,0.095f
*1.3f
, 1.0f
},
442 vnormal
= {1.0f
,1.0f
,1.0f
, 1.0f
},
445 v4_lerp( vnormal
, vselected
, btn
->falpha
, vcurrent
);
446 shader_menu_uColour( vcurrent
);
450 mdl_node_transform( btn
->pnode
, mtx
);
451 m4x3_mul( menu_mdl_mtx
, mtx
, mtx
);
452 m4x3_identity( mtx_size
);
453 m4x3_scale( mtx_size
, expSustainedImpulse( btn
->fsize
, 0.5f
, 8.7f
) );
454 m4x3_mul( mtx
, mtx_size
, mtx
);
455 shader_menu_uMdl( mtx
);
457 for( int j
=0; j
<btn
->pnode
->submesh_count
; j
++ )
460 &menu_model
.submesh_buffer
[ btn
->pnode
->submesh_start
+j
];
461 mdl_draw_submesh( sm
);
466 for( int i=0; i<menu_model->node_count; i++ )
468 mdl_node *pnode = mdl_node_from_id( menu_model, i );
470 for( int j=0; j<pnode->submesh_count; j++ )
473 mdl_submesh_from_id( menu_model, pnode->submesh_start+j );
475 mdl_node_transform( pnode, mtx );
476 m4x3_mul( menu_mdl_mtx, mtx, mtx );
477 shader_menu_uMdl( mtx );
479 mdl_draw_submesh( sm );