X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=main.c;h=9bfa794c51a1e0b1ad55668aa8ca29b1877fc366;hb=47941822dae18a018c985847b052e70214a3ccc6;hp=bbb4c321f310f8e297409801e3c3605c1874b2ae;hpb=15beb60ade240af4e00b0d204f7e89a4d35dca36;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/main.c b/main.c index bbb4c32..9bfa794 100644 --- a/main.c +++ b/main.c @@ -18,8 +18,14 @@ * */ -#define SR_NETWORKED #define VG_3D +#define VG_STATIC static + +//#define VG_MINIMAL_TEST +#ifndef VG_MINIMAL_TEST + +#define SR_NETWORKED + #include "common.h" #include "steam.h" #include "render.h" @@ -29,21 +35,20 @@ #include "network.h" #include "menu.h" -static int cl_ui = 1, - cl_menu = 0; +static int cl_ui = 1; int main( int argc, char *argv[] ) { + vg_prealloc_quota( 128*1024*1024 ); vg_enter( argc, argv, "Voyager Game Engine" ); } -static void highscores_save_at_exit(void*_) +VG_STATIC void highscores_save_at_exit(void*_) { highscores_serialize_all(); - highscores_free(); } -void vg_preload(void) +VG_STATIC void vg_preload(void) { vg_convar_push( (struct vg_convar){ .name = "cl_ui", @@ -74,106 +79,85 @@ vg_info(" ' ' '--' [] '----- '----- ' ' '---' " vg_loader_highwater( network_init, network_end, NULL ); } -void vg_load(void) +VG_STATIC 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( render_init, NULL, NULL ); + vg_loader_highwater( menu_init, NULL, NULL ); + vg_loader_highwater( world_init, NULL, NULL ); vg_loader_highwater( player_init, NULL, NULL ); - if( !vg_bake_shaders() ) - vg_fatal_exit_loop( "Did not load all shaders" ); - + vg_bake_shaders(); vg_loader_highwater( audio_init, audio_free, NULL ); - /* FInal step */ - world_load(); + /* 'systems' are completely loaded now */ + world_load( "models/mp_dev.mdl" ); vg_console_load_autos(); } -static void vg_start(void) +VG_STATIC void vg_start(void) { - player_load_model( "ch_jordan" ); reset_player( 1, (const char *[]){ "start" } ); } -static void draw_origin_axis(void) +VG_STATIC void draw_origin_axis(void) { vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 1.0f, 0.0f, 0.0f }, 0xffff0000 ); vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 1.0f, 0.0f }, 0xff00ff00 ); vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 0.0f, 1.0f }, 0xff0000ff ); } -void vg_update( int loaded ) +VG_STATIC void vg_update( int loaded ) { steam_update(); if( loaded ) { - if( vg_get_button_down( "menu" ) ) - { - cl_menu = !cl_menu; - } - draw_origin_axis(); network_update(); - if( !cl_menu ) - { - player_update_pre(); - world_update( player.phys.rb.co ); - } - - menu_update( cl_menu ); + player_update_pre(); + world_update( player.phys.rb.co ); } } -static void vg_update_fixed( int loaded ) +VG_STATIC void vg_update_fixed( int loaded ) { - if( loaded && !cl_menu ) + if( loaded ) { player_update_fixed(); } } -static void vg_update_post( int loaded ) +VG_STATIC void vg_update_post( int loaded ) { - if( loaded && !cl_menu ) + if( loaded ) { player_update_post(); + menu_update(); } } -static void vg_framebuffer_resize( int w, int h ) +VG_STATIC void vg_framebuffer_resize( int w, int h ) { render_fb_resize(); - gate_fb_resize(); water_fb_resize(); } -static void render_main_game(void) +VG_STATIC void render_main_game(void) { - v3f *active_cam_inv = NULL, - *active_cam = NULL; - m4x4f world_4x4; + m4x3_expand( camera_mtx_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; - } + static float fov = 97.0f; - m4x3_expand( active_cam_inv, world_4x4 ); + float fov_target = 108.0f; + if( player.phys.on_board ) + fov_target = 125.0f; - static float fov = 97.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 ); + if( cl_menu ) + fov_target = menu_fov_target; + + fov = vg_lerpf( fov, fov_target, vg.frame_delta * 2.0f ); gpipeline.fov = freecam? 60.0f: fov; /* 120 */ m4x4_projection( vg.pv, gpipeline.fov, @@ -189,18 +173,21 @@ static void render_main_game(void) int draw_solid = player.is_dead | freecam; - render_world( vg.pv, active_cam ); + render_world( vg.pv, camera_mtx ); if( draw_solid ) - draw_player( active_cam ); + draw_player( camera_mtx ); - render_water_texture( active_cam ); + render_water_texture( camera_mtx ); glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - render_water_surface( vg.pv, active_cam ); - render_world_gates( vg.pv, player.phys.rb.co, active_cam ); + render_water_surface( vg.pv, camera_mtx ); + render_world_gates( vg.pv, player.phys.rb.co, camera_mtx ); if( cl_menu ) + { + glClear( GL_DEPTH_BUFFER_BIT ); menu_render( vg.pv ); + } /* Copy the RGB of what we have into the background buffer */ glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); @@ -223,9 +210,9 @@ static void render_main_game(void) { m4x4_projection( vg.pv, gpipeline.fov, (float)vg.window_x / (float)vg.window_y, - 0.01f, 600.0f ); + 0.05f, 60.0f ); m4x4_mul( vg.pv, world_4x4, vg.pv ); - draw_player( active_cam ); + draw_player( camera_mtx ); } /* Draw back in the background @@ -246,7 +233,7 @@ static void render_main_game(void) render_fsquad(); } -void vg_render(void) +VG_STATIC void vg_render(void) { glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glViewport( 0,0, vg.window_x, vg.window_y ); @@ -265,7 +252,7 @@ void vg_render(void) glViewport( 0,0, vg.window_x, vg.window_y ); } -void vg_ui(void) +VG_STATIC void vg_ui(void) { #if 0 if( cl_menu ) @@ -348,7 +335,7 @@ void vg_ui(void) } #if 0 -static void run_light_widget( struct light_widget *lw ) +VG_STATIC void run_light_widget( struct light_widget *lw ) { struct ui_checkbox c1 = { .data=&lw->enabled }; @@ -367,32 +354,104 @@ static void run_light_widget( struct light_widget *lw ) } #endif -static void run_debug_info(void) +VG_STATIC void run_debug_info(void) { char buf[40]; snprintf( buf, 40, "%.2fm/s", v3_length( player.phys.rb.v ) ); - gui_text( (ui_px [2]){ 0, 0 }, buf, 1, k_text_align_left ); + ui_text( (ui_px [2]){ 0, 0 }, buf, 1, k_text_align_left ); snprintf( buf, 40, "%.2f %.2f %.2f m/s", player.phys.a[0], player.phys.a[1], player.phys.a[2] ); - gui_text( (ui_px [2]){ 0, 20 }, buf, 1, k_text_align_left ); + ui_text( (ui_px [2]){ 0, 20 }, buf, 1, k_text_align_left ); snprintf( buf, 40, "pos %.2f %.2f %.2f", player.phys.rb.co[0], player.phys.rb.co[1], player.phys.rb.co[2] ); - gui_text( (ui_px [2]){ 0, 40 }, buf, 1, k_text_align_left ); + ui_text( (ui_px [2]){ 0, 40 }, buf, 1, k_text_align_left ); if( vg.gamepad_ready ) { for( int i=0; i<6; i++ ) { snprintf( buf, 40, "%.2f", vg.gamepad.axes[i] ); - gui_text( (ui_px [2]){ 0, (i+3)*20 }, buf, 1, k_text_align_left ); + ui_text( (ui_px [2]){ 0, (i+3)*20 }, buf, 1, k_text_align_left ); } } else { - gui_text( (ui_px [2]){ 0, 60 }, + ui_text( (ui_px [2]){ 0, 60 }, "Gamepad not ready", 1, k_text_align_left ); } } + +#else + +#define VG_TIMESTEP_FIXED (1.0/60.0) +#define VG_3D +#define VG_FRAMEBUFFER_RESIZE 1 +#include "vg/vg.h" + +int main( int argc, char *argv[] ) +{ + vg_prealloc_quota( 512*1024*1024 ); + vg_enter( argc, argv, "Voyager Game Engine" ); +} + +VG_STATIC void vg_preload(void) +{ +vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" ); +vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" ); +vg_info(" | \\ / | +-- / +----- +---' | / | \n" ); +vg_info(" | \\ / | | / | | \\ | / | \n" ); +vg_info(" | \\/ | | / | | \\ | / | \n" ); +vg_info(" ' ' '--' [] '----- '----- ' ' '---' " + "SOFTWARE\n" ); +} + +VG_STATIC void vg_load(void) +{ + vg_bake_shaders(); + vg_console_load_autos(); +} + +VG_STATIC void vg_start(void) +{ +} + +VG_STATIC void vg_update( int loaded ) +{ +} + +VG_STATIC void vg_update_fixed( int loaded ) +{ +} + +VG_STATIC void vg_update_post( int loaded ) +{ +} + +VG_STATIC void vg_framebuffer_resize( int w, int h ) +{ +} + +VG_STATIC void vg_render(void) +{ + glBindFramebuffer( GL_FRAMEBUFFER, 0 ); + glViewport( 0,0, vg.window_x, vg.window_y ); + glDisable( GL_DEPTH_TEST ); + + glClearColor( 0.11f, 0.35f, 0.37f, 1.0f ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); + + /* Other shite */ + glDisable(GL_BLEND); + glDisable( GL_DEPTH_TEST ); + vg_lines_drawall( (float *)vg.pv ); + glViewport( 0,0, vg.window_x, vg.window_y ); +} + +VG_STATIC void vg_ui(void) +{ +} + +#endif