X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=main.c;h=bbb4c321f310f8e297409801e3c3605c1874b2ae;hb=15beb60ade240af4e00b0d204f7e89a4d35dca36;hp=3cee76a8ce99fb5ecd6e0275a3fecff3cbf5e578;hpb=da929c58442de91be106438ebf2f2daabf7f2430;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/main.c b/main.c index 3cee76a..bbb4c32 100644 --- a/main.c +++ b/main.c @@ -26,11 +26,14 @@ #include "audio.h" #include "world.h" #include "player.h" +#include "network.h" +#include "menu.h" -static int cl_ui = 1; +static int cl_ui = 1, + cl_menu = 0; int main( int argc, char *argv[] ) -{ +{ vg_enter( argc, argv, "Voyager Game Engine" ); } @@ -59,19 +62,22 @@ vg_info(" ' ' '--' [] '----- '----- ' ' '---' " "SOFTWARE\n" ); highscores_init( 2000, 50 ); + if( !highscores_read() ) + highscores_create_db(); + vg_loader_highwater( NULL, highscores_save_at_exit, NULL ); vg_sleep_ms(200); steam_init(); vg_loader_highwater( NULL, steam_end, NULL ); - vg_loader_highwater( network_init, network_end, NULL ); } void vg_load(void) { vg_loader_highwater( render_init, render_free, NULL ); + vg_loader_highwater( menu_init, menu_free, NULL ); vg_loader_highwater( world_init, world_free, NULL ); vg_loader_highwater( player_init, NULL, NULL ); @@ -87,7 +93,7 @@ void vg_load(void) static void vg_start(void) { - player_load_model( "ch_new" ); + player_load_model( "ch_jordan" ); reset_player( 1, (const char *[]){ "start" } ); } @@ -104,16 +110,27 @@ void vg_update( int loaded ) if( loaded ) { + if( vg_get_button_down( "menu" ) ) + { + cl_menu = !cl_menu; + } + draw_origin_axis(); network_update(); - player_update_pre(); - world_update( player.phys.rb.co ); + + if( !cl_menu ) + { + player_update_pre(); + world_update( player.phys.rb.co ); + } + + menu_update( cl_menu ); } } static void vg_update_fixed( int loaded ) { - if( loaded ) + if( loaded && !cl_menu ) { player_update_fixed(); } @@ -121,7 +138,7 @@ static void vg_update_fixed( int loaded ) static void vg_update_post( int loaded ) { - if( loaded ) + if( loaded && !cl_menu ) { player_update_post(); } @@ -136,17 +153,32 @@ static void vg_framebuffer_resize( int w, int h ) static void render_main_game(void) { + v3f *active_cam_inv = NULL, + *active_cam = NULL; + m4x4f world_4x4; - m4x3_expand( player.camera_inverse, world_4x4 ); + + if( cl_menu ) + { + active_cam = menu_cam; + active_cam_inv = menu_cam_inv; + } + else + { + active_cam_inv = player.camera_inverse; + active_cam = player.camera; + } + + m4x3_expand( active_cam_inv, world_4x4 ); static float fov = 97.0f; - float fov_target = player.phys.on_board? 125.0f: 108.0f; + float fov_target = (player.phys.on_board&&!cl_menu)? 125.0f: 108.0f; fov = vg_lerpf( fov, fov_target, vg.time_delta * 2.0f ); gpipeline.fov = freecam? 60.0f: fov; /* 120 */ m4x4_projection( vg.pv, gpipeline.fov, (float)vg.window_x / (float)vg.window_y, - 0.02f, 2100.0f ); + 0.1f, 2100.0f ); m4x4_mul( vg.pv, world_4x4, vg.pv ); glEnable( GL_DEPTH_TEST ); @@ -157,15 +189,18 @@ static void render_main_game(void) int draw_solid = player.is_dead | freecam; - render_world( vg.pv, player.camera ); + render_world( vg.pv, active_cam ); if( draw_solid ) - draw_player(); - render_water_texture( player.camera ); + draw_player( active_cam ); + + render_water_texture( active_cam ); glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - render_water_surface( vg.pv, player.camera ); + render_water_surface( vg.pv, active_cam ); + render_world_gates( vg.pv, player.phys.rb.co, active_cam ); - render_world_gates( vg.pv, player.phys.rb.co, player.camera ); + if( cl_menu ) + menu_render( vg.pv ); /* Copy the RGB of what we have into the background buffer */ glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); @@ -190,7 +225,7 @@ static void render_main_game(void) (float)vg.window_x / (float)vg.window_y, 0.01f, 600.0f ); m4x4_mul( vg.pv, world_4x4, vg.pv ); - draw_player(); + draw_player( active_cam ); } /* Draw back in the background @@ -233,6 +268,39 @@ void vg_render(void) void vg_ui(void) { #if 0 + if( cl_menu ) + { + ui_rect menu = + { + vg.window_x / 2 - 150, + vg.window_y / 2 - 50, + 300, + 130 + }; + + ui_fill_rect( &ui_global_ctx, menu, 0xa0000000 ); + + ui_text( &ui_global_ctx, (ui_rect){ menu[0]+menu[2]/2,menu[1]+6, 0, 0 }, + steam_username_at_startup, + 1, k_text_align_center ); + menu[1] += 24; + menu[3] -= 30; + + ui_rect_pad( menu, 8 ); + ui_fill_rect( &ui_global_ctx, menu, 0x90ffffff ); + ui_rect_pad( menu, 2 ); + ui_fill_rect( &ui_global_ctx, menu, 0xa0000000 ); + + menu[1] += 32; + ui_text( &ui_global_ctx, (ui_rect){ menu[0]+menu[2]/2,menu[1], 0, 0 }, + "Exit", 2, k_text_align_center ); + + if( vg_get_button_down( "jump" ) ) + { + glfwSetWindowShouldClose( vg.window, 1 ); + } + } + if( lightedit ) { ui_global_ctx.cursor[0] = 10;