well yeah i guess
[carveJwlIkooP6JGAAIwe30JlM.git] / menu.h
diff --git a/menu.h b/menu.h
index 7d8bf764441bb5fcfb01363c697759759c82171c..02ab25242a74c75837f862f20eb51fb6a230bf7b 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -8,32 +8,31 @@
 
 #include "shaders/menu.h"
 
-static mdl_header *menu_model;
-static glmesh      menu_glmesh;
-static m4x3f       menu_mdl_mtx;
-static float       menu_opacity = 0.0f;
-static float       menu_input_cooldown = 0.0f;
-static float       menu_fov_target = 97.0f;
-static v2f         menu_extra_angles;
-
-static int         menu_loc = 1,
+VG_STATIC mdl_context menu_model;
+VG_STATIC glmesh      menu_glmesh;
+VG_STATIC m4x3f       menu_mdl_mtx;
+VG_STATIC float       menu_opacity = 0.0f;
+VG_STATIC float       menu_input_cooldown = 0.0f;
+VG_STATIC float       menu_fov_target = 97.0f;
+VG_STATIC v2f         menu_extra_angles;
+
+VG_STATIC int         menu_loc = 1,
                    menu_loc_last = 1;
-static u32         menu_page     = 0;
+VG_STATIC u32         menu_page     = 0;
 
-static int         cl_menu         = 0,
+VG_STATIC int         cl_menu         = 0,
                    cl_menu_go_away = 0;
-static int         cl_playermdl_id = 0;
 
-static const char *playermodels[] = { "ch_new", "ch_jordan", "ch_outlaw" };
+VG_STATIC const char *playermodels[] = { "ch_new", "ch_jordan", "ch_outlaw" };
 
-static void menu_btn_paused( int event );
-static void menu_btn_quit( int event );
-static void menu_btn_skater( int event );
-static void menu_btn_map( int event );
-static void menu_btn_map_a( int event );
-static void menu_btn_map_b( int event );
-static void menu_btn_map_c( int event );
-static void menu_btn_fuckoff( int event );
+VG_STATIC void menu_btn_paused( int event );
+VG_STATIC void menu_btn_quit( int event );
+VG_STATIC void menu_btn_skater( int event );
+VG_STATIC void menu_btn_map( int event );
+VG_STATIC void menu_btn_map_a( int event );
+VG_STATIC void menu_btn_map_b( int event );
+VG_STATIC void menu_btn_map_c( int event );
+VG_STATIC void menu_btn_fuckoff( int event );
 
 struct menu_button
 {
@@ -46,7 +45,7 @@ struct menu_button
 
    float falpha, fsize;
 }
-static menu_buttons[] = 
+VG_STATIC menu_buttons[] = 
 {
 /*0*/{"text_paused",     1, menu_btn_paused },
 /*1*/{"text_quit",       9, menu_btn_quit,    {3,-1,4,2}},
@@ -64,69 +63,63 @@ static menu_buttons[] =
 /*d*/{"text_yes",        8, menu_btn_fuckoff,{-1,-1,-1,-1} },
 };
 
-static void menu_btn_map_a( int event ){}
-static void menu_btn_map_b( int event ){}
-static void menu_btn_map_c( int event ){}
+VG_STATIC void menu_btn_map_a( int event ){}
+VG_STATIC void menu_btn_map_b( int event ){}
+VG_STATIC void menu_btn_map_c( int event ){}
 
-static void menu_btn_paused( int event )
+VG_STATIC void menu_btn_paused( int event )
 {
 
 }
 
-static void menu_btn_fuckoff( int event )
+VG_STATIC void menu_btn_fuckoff( int event )
 {
    glfwSetWindowShouldClose( vg.window, 1 );
 }
 
-static void menu_btn_quit( int event )
+VG_STATIC void menu_btn_quit( int event )
 {
    menu_page = 0x8;
    menu_loc = 0xd;
 }
 
-static void menu_btn_map( int event )
+VG_STATIC void menu_btn_map( int event )
 {
    menu_page = 0x4;
    menu_loc = 7;
 }
 
-static void menu_btn_skater( int event )
+VG_STATIC void menu_btn_skater( int event )
 {
    menu_page = 0x2;
 }
 
-static void menu_init(void)
+VG_STATIC void menu_init(void)
 {
-   menu_model = mdl_load( "models/rs_menu.mdl" );
+   vg_linear_clear( vg_mem.scratch );
 
-   if( !menu_model )
-      vg_fatal_exit_loop( "No menu model" );
+   mdl_open( &menu_model, "models/rs_menu.mdl" );
+   mdl_load_metadata( &menu_model, vg_mem.rtmemory );
+   mdl_load_mesh_data( &menu_model, vg_mem.scratch );
+   mdl_close( &menu_model );
+
+   vg_acquire_thread_sync();
+   mdl_unpack_glmesh( &menu_model, &menu_glmesh );
+   vg_release_thread_sync();
 
    for( int i=0; i<vg_list_size(menu_buttons); i++ )
    {
       struct menu_button *btn = &menu_buttons[i];
-      btn->pnode = mdl_node_from_name( menu_model, btn->name );
+      btn->pnode = mdl_node_from_name( &menu_model, btn->name );
 
       if( !btn->pnode )
          vg_fatal_exit_loop( "Menu programming error" );
    }
 
-   vg_convar_push( (struct vg_convar){
-      .name = "cl_playermdl_id",
-      .data = &cl_playermdl_id,
-      .data_type = k_convar_dtype_i32,
-      .opt_i32 = { .min=0, .max=2, .clamp=1 },
-      .persistent = 1
-   });
-
-   vg_acquire_thread_sync();
-   mdl_unpack_glmesh( menu_model, &menu_glmesh );
-   vg_release_thread_sync();
-
    shader_menu_register();
 }
 
-static void menu_run_directional(void)
+VG_STATIC void menu_run_directional(void)
 {
    struct menu_button *btn = &menu_buttons[ menu_loc ];
 
@@ -174,18 +167,18 @@ static void menu_run_directional(void)
    }
 }
 
-static int menu_page_should_backout(void)
+VG_STATIC int menu_page_should_backout(void)
 {
    return vg_get_button_down( "break" );
 }
 
-static void menu_close(void)
+VG_STATIC void menu_close(void)
 {
    cl_menu_go_away = 1;
    menu_page = 0;
 }
 
-static void menu_page_main(void)
+VG_STATIC void menu_page_main(void)
 {
    if( menu_page_should_backout() )
    {
@@ -197,7 +190,7 @@ static void menu_page_main(void)
    menu_run_directional();
 }
 
-static void menu_page_map(void)
+VG_STATIC void menu_page_map(void)
 {
    if( menu_page_should_backout() )
    {
@@ -209,7 +202,7 @@ static void menu_page_map(void)
    menu_run_directional();
 }
 
-static void menu_page_quit(void)
+VG_STATIC void menu_page_quit(void)
 {
    if( menu_page_should_backout() )
    {
@@ -221,7 +214,7 @@ static void menu_page_quit(void)
    menu_run_directional();
 }
 
-static void menu_page_skater(void)
+VG_STATIC void menu_page_skater(void)
 {
    float h = vg_get_axis( "lookh" );
    menu_fov_target = 97.0f;
@@ -245,7 +238,6 @@ static void menu_page_skater(void)
          menu_buttons[5].falpha = 1.0f;
 
          menu_input_cooldown = 0.25f;
-         player_load_model( playermodels[ cl_playermdl_id ], 1 );
       }
       else
       {
@@ -257,12 +249,11 @@ static void menu_page_skater(void)
          menu_buttons[6].falpha = 1.0f;
 
          menu_input_cooldown = 0.25f;
-         player_load_model( playermodels[ cl_playermdl_id ], 1 );
       }
    }
 }
 
-static void menu_update(void)
+VG_STATIC void menu_update(void)
 {
    if( vg_get_button_down( "menu" ) )
    {
@@ -376,7 +367,7 @@ float expSustainedImpulse( float x, float f, float k )
     return fminf( x*x/(f*f), 1.0f+(2.0f/f)*s*expf(-k*s));
 }
 
-static void menu_render( m4x4f projection )
+VG_STATIC void menu_render( m4x4f projection )
 {
    glEnable(GL_BLEND);
    glDisable(GL_DEPTH_TEST);
@@ -431,7 +422,7 @@ static void menu_render( m4x4f projection )
       for( int j=0; j<btn->pnode->submesh_count; j++ )
       {
          mdl_submesh *sm = 
-            mdl_submesh_from_id( menu_model, btn->pnode->submesh_start+j );
+            &menu_model.submesh_buffer[ btn->pnode->submesh_start+j ];
          mdl_draw_submesh( sm );
       }
    }
@@ -456,9 +447,4 @@ static void menu_render( m4x4f projection )
    */
 }
 
-static void menu_free(void *_)
-{
-   mesh_free( &menu_glmesh );
-}
-
 #endif /* MENU_H */