* =============================================================================
*
* Copyright . . . -----, ,----- ,---. .---.
- * 2021-2022 |\ /| | / | | | | /|
+ * 2021-2023 |\ /| | / | | | | /|
* | \ / | +-- / +----- +---' | / |
* | \ / | | / | | \ | / |
* | \/ | | / | | \ | / |
* ' ' '--' [] '----- '----- ' ' '---' SOFTWARE
*
* =============================================================================
- *
- * register: shader register & init scheduling
- * init: initialization
- * update: logic
- * render: graphics
- * free: resource free
- *
*/
-#define VG_3D
-#define VG_STATIC static
-//#define VG_STATIC
-
-//#define VG_MINIMAL_TEST
-#ifndef VG_MINIMAL_TEST
-
#define SR_NETWORKED
-
#include "common.h"
+#include "conf.h"
#include "steam.h"
#include "render.h"
#include "audio.h"
#include "network.h"
#include "menu.h"
-static int cl_ui = 1;
+static int cl_ui = 1,
+ cl_view_id = 0,
+ cl_light_edit = 0;
int main( int argc, char *argv[] )
{
vg_mem.use_libc_malloc = 0;
vg_set_mem_quota( 128*1024*1024 );
vg_enter( argc, argv, "Voyager Game Engine" );
+
+ return 0;
}
-VG_STATIC void highscores_save_at_exit(void*_)
+VG_STATIC void highscores_save_at_exit(void)
{
highscores_serialize_all();
}
+VG_STATIC void vg_launch_opt(void)
+{
+
+}
+
VG_STATIC void vg_preload(void)
{
+ g_conf_init();
- vg_convar_push( (struct vg_convar){
+ vg_var_push( (struct vg_var){
.name = "cl_ui",
.data = &cl_ui,
- .data_type = k_convar_dtype_i32,
+ .data_type = k_var_dtype_i32,
.opt_i32 = { .min=0, .max=1, .clamp=1 },
- .persistent = 1
+ .persistent = 0
+ });
+
+ vg_var_push( (struct vg_var){
+ .name = "cl_view_id",
+ .data = &cl_view_id,
+ .data_type = k_var_dtype_i32,
+ .opt_i32 = { .min=0, .max=1, .clamp=1 },
+ .persistent = 0
+ });
+
+ vg_var_push( (struct vg_var){
+ .name = "ledit",
+ .data = &cl_light_edit,
+ .data_type = k_var_dtype_i32,
+ .opt_i32 = { .min=0, .max=1, .clamp=1 },
+ .persistent = 0
});
vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" );
if( !highscores_read() )
highscores_create_db();
- vg_loader_highwater( NULL, highscores_save_at_exit, NULL );
-
- //vg_sleep_ms(200);
+ vg_loader_step( NULL, highscores_save_at_exit );
steam_init();
- vg_loader_highwater( NULL, steam_end, NULL );
- vg_loader_highwater( network_init, network_end, NULL );
+ vg_loader_step( NULL, steam_end );
+ vg_loader_step( network_init, network_end );
}
VG_STATIC void vg_load(void)
{
- 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 );
+ vg_loader_step( render_init, NULL );
+ vg_loader_step( menu_init, NULL );
+ vg_loader_step( world_init, NULL );
+ vg_loader_step( player_init, NULL );
vg_bake_shaders();
- vg_loader_highwater( audio_init, audio_free, NULL );
+ vg_loader_step( audio_init, audio_free );
world_audio_init();
/* 'systems' are completely loaded now */
- strcpy( world.world_name, "models/mp_dev.mdl" );
+ strcpy( world.world_name, "maps/mp_mtzero.mdl" );
+ //strcpy( world.world_name, "maps/mp_gridmap.mdl" );
world_load();
vg_console_load_autos();
}
vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 0.0f, 1.0f }, 0xff0000ff );
}
-VG_STATIC void vg_update( int loaded )
+VG_STATIC void vg_update(void)
{
steam_update();
- if( loaded )
+ if( vg.is_loaded )
{
draw_origin_axis();
network_update();
}
}
-VG_STATIC void vg_update_fixed( int loaded )
+VG_STATIC void vg_update_fixed(void)
{
- if( loaded )
+ if( vg.is_loaded )
{
player_update_fixed();
}
}
-VG_STATIC void vg_update_post( int loaded )
+VG_STATIC void vg_update_post(void)
{
- if( loaded )
+ if( vg.is_loaded )
{
player_update_post();
menu_update();
VG_STATIC void vg_framebuffer_resize( int w, int h )
{
render_fb_resize();
- water_fb_resize();
}
-VG_STATIC void render_main_game(void)
+VG_STATIC void present_view_with_post_processing(void)
{
- m4x4f world_4x4;
- m4x3_expand( camera_mtx_inverse, world_4x4 );
+ glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- static float fov = 97.0f;
+ glEnable(GL_BLEND);
+ glDisable(GL_DEPTH_TEST);
+ glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA);
+ glBlendEquation(GL_FUNC_ADD);
- float fov_target = 108.0f;
- if( player.phys.on_board )
- fov_target = 125.0f;
+ if( cl_blur )
+ {
+ shader_blitblur_use();
+ shader_blitblur_uTexMain( 0 );
+ shader_blitblur_uTexMotion( 1 );
+ shader_blitblur_uBlurStrength(cl_blur_strength / (vg.frame_delta*60.0f));
+
+ v2f menu_blurring;
+ v2_muls( (v2f){ 0.04f, 0.001f }, menu_opacity, menu_blurring );
+ shader_blitblur_uOverrideDir( menu_blurring );
+
+ if( cl_view_id == 0 )
+ render_fb_bind_texture( gpipeline.fb_main, 0, 0 );
+ else if( cl_view_id == 1 )
+ render_fb_bind_texture( gpipeline.fb_main, 1, 0 );
+ else
+ render_fb_bind_texture( gpipeline.fb_main, 0, 0 );
+
+ render_fb_bind_texture( gpipeline.fb_main, 1, 1 );
+ }
+ else
+ {
+ shader_blit_use();
+ shader_blit_uTexMain( 0 );
+ render_fb_bind_texture( gpipeline.fb_main, 0, 0 );
+ }
- if( cl_menu )
- fov_target = menu_fov_target;
+ render_fsquad();
+}
- fov = vg_lerpf( fov, fov_target, vg.frame_delta * 2.0f );
+VG_STATIC void render_player_transparent(void)
+{
+ static camera small_cam; /* DOES NOT NEED TO BE STATIC BUT MINGW
+ SAIS OTHERWISE */
+
+ m4x3_copy( main_camera.transform, small_cam.transform );
+
+ small_cam.fov = main_camera.fov;
+ small_cam.nearz = 0.05f;
+ small_cam.farz = 60.0f;
+
+ camera_update_view( &small_cam );
+ camera_update_projection( &small_cam );
+ camera_finalize( &small_cam );
- gpipeline.fov = freecam? 60.0f: fov; /* 120 */
- m4x4_projection( vg.pv, gpipeline.fov,
- (float)vg.window_x / (float)vg.window_y,
- 0.1f, 2100.0f );
+ /* Draw player to window buffer and blend background ontop */
- m4x4_mul( vg.pv, world_4x4, vg.pv );
+ glBindFramebuffer( GL_FRAMEBUFFER, 0 );
+ draw_player( &small_cam );
+}
+
+VG_STATIC void render_scene(void)
+{
+ render_fb_bind( gpipeline.fb_main );
+ glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
+
+ /* Draw world */
glEnable( GL_DEPTH_TEST );
-
- /*
- * Draw world
- */
- int draw_solid = player.is_dead | freecam;
- render_world( vg.pv, camera_mtx );
+ render_world( &main_camera );
- if( draw_solid )
- draw_player( camera_mtx );
+ int player_transparent = !(player.is_dead || freecam),
+ player_draw = !cl_menu;
- render_water_texture( camera_mtx );
+ if( !player_transparent && player_draw )
+ draw_player( &main_camera );
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- render_water_surface( vg.pv, camera_mtx );
- render_world_gates( vg.pv, player.phys.rb.co, camera_mtx );
+ render_water_texture( &main_camera );
+ render_fb_bind( gpipeline.fb_main );
+ render_water_surface( &main_camera );
+ render_world_gates( &main_camera );
+
+ if( player_transparent && player_draw )
+ render_player_transparent();
+}
+VG_STATIC void render_menu(void)
+{
+ glClear( GL_DEPTH_BUFFER_BIT );
+ menu_render( &main_camera );
+}
+
+VG_STATIC void render_main_game(void)
+{
+ static float fov = 60.0f;
+ float fov_target = vg_lerpf( 90.0f, 110.0f, cl_fov );
+ if( player.phys.on_board )
+ fov_target = vg_lerpf( 97.0f, 135.0f, cl_fov );
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 );
- glBindFramebuffer( GL_DRAW_FRAMEBUFFER, gpipeline.fb_background );
- glBlitFramebuffer( 0,0, vg.window_x, vg.window_y,
- 0,0, vg.window_x, vg.window_y,
- GL_COLOR_BUFFER_BIT,
- GL_LINEAR );
-
- /* Clear out the colour buffer, but keep depth */
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
+ fov_target = menu_fov_target;
+ fov = vg_lerpf( fov, fov_target, vg.frame_delta * 2.0f );
+ fov = freecam? 60.0f: fov;
- if( !player.is_dead )
- glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
- else
- glClear( GL_COLOR_BUFFER_BIT );
-
- if( !draw_solid )
+ main_camera.fov = fov;
+ main_camera.nearz = 0.1f;
+ main_camera.farz = 2100.0f;
+
+ camera_update_view( &main_camera );
+ camera_update_projection( &main_camera );
+ camera_finalize( &main_camera );
+
+ /* ========== Begin Frame ========== */
+
+ render_scene();
+ present_view_with_post_processing();
+
+ if( cl_menu )
{
- m4x4_projection( vg.pv, gpipeline.fov,
- (float)vg.window_x / (float)vg.window_y,
- 0.05f, 60.0f );
- m4x4_mul( vg.pv, world_4x4, vg.pv );
- draw_player( camera_mtx );
+ render_menu();
+ render_player_transparent();
}
- /* Draw back in the background
- *
- * TODO: need to disable alpha write in the terrain shader so this works
- * again.
- */
- glEnable(GL_BLEND);
- glDisable(GL_DEPTH_TEST);
- glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA);
- glBlendEquation(GL_FUNC_ADD);
-
- shader_blit_use();
- shader_blit_uTexMain( 0 );
- glActiveTexture(GL_TEXTURE0);
- glBindTexture( GL_TEXTURE_2D, gpipeline.rgb_background );
-
- render_fsquad();
+ /* =========== End Frame =========== */
}
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 );
+ glClearColor( 1.0f, 0.0f, 0.0f, 0.0f );
+ glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
render_main_game();
-
/* Other shite */
glDisable(GL_BLEND);
glDisable( GL_DEPTH_TEST );
- vg_lines_drawall( (float *)vg.pv );
+ vg_lines_drawall( (float *)main_camera.mtx.pv );
glViewport( 0,0, vg.window_x, vg.window_y );
}
+VG_STATIC void run_light_widget( struct light_widget *lw );
VG_STATIC 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 )
+ menu_crap_ui();
+
+ if( cl_light_edit )
{
- ui_global_ctx.cursor[0] = 10;
- ui_global_ctx.cursor[1] = 10;
- ui_global_ctx.cursor[2] = 200;
- ui_global_ctx.cursor[3] = 20;
+ vg_uictx.cursor[0] = 10;
+ vg_uictx.cursor[1] = 10;
+ vg_uictx.cursor[2] = 200;
+ vg_uictx.cursor[3] = 20;
struct ub_world_lighting *wl = &gpipeline.ub_world_lighting;
struct ui_slider_vector
for( int i=0; i<3; i++ )
run_light_widget( &gpipeline.widgets[i] );
-
- gui_text( ui_global_ctx.cursor, "Ambient", 1, 0 );
- ui_global_ctx.cursor[1] += 16;
- ui_slider_vector( &ui_global_ctx, &s5 );
-
- gui_text( ui_global_ctx.cursor, "Shadows", 1, 0 );
- ui_global_ctx.cursor[1] += 16;
- ui_slider( &ui_global_ctx, &s8 );
- ui_slider( &ui_global_ctx, &s9 );
-
- gui_text( ui_global_ctx.cursor, "Misc", 1, 0 );
- ui_global_ctx.cursor[1] += 16;
+
+ ui_text( vg_uictx.cursor, "Ambient", 1, 0 );
+ vg_uictx.cursor[1] += 16;
+ ui_slider_vector( &s5 );
+
+ ui_text( vg_uictx.cursor, "Shadows", 1, 0 );
+ vg_uictx.cursor[1] += 16;
+ ui_slider( &s8 );
+ ui_slider( &s9 );
+
+ ui_text( vg_uictx.cursor, "Misc", 1, 0 );
+ vg_uictx.cursor[1] += 16;
struct ui_checkbox c1 = {.data = &wl->g_light_preview};
- ui_checkbox( &ui_global_ctx, &c1 );
+ ui_checkbox( &c1 );
render_update_lighting_ub();
}
-#endif
//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
if( cl_ui )
//glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
audio_debug_soundscapes();
+ render_view_framebuffer_ui();
+ player_physics_gui();
}
-#if 0
VG_STATIC void run_light_widget( struct light_widget *lw )
{
struct ui_checkbox c1 = { .data=&lw->enabled };
- ui_checkbox( &ui_global_ctx, &c1 );
+ ui_checkbox( &c1 );
if( lw->enabled )
{
colour = { .min=0.0f, .max=2.0f, .len=3, .data=lw->colour },
dir = { .min=-VG_PIf, .max=VG_PIf, .len=2, .data=lw->dir };
- ui_slider_vector( &ui_global_ctx, &colour );
- ui_global_ctx.cursor[1] += 4;
- ui_slider_vector( &ui_global_ctx, &dir );
+ ui_slider_vector( &colour );
+ vg_uictx.cursor[1] += 4;
+ ui_slider_vector( &dir );
}
}
-#endif
VG_STATIC void run_debug_info(void)
{
player.phys.rb.co[0], player.phys.rb.co[1], player.phys.rb.co[2] );
ui_text( (ui_px [2]){ 0, 40 }, buf, 1, k_text_align_left );
- if( vg.gamepad_ready )
+ if( vg_input.controller_handle )
{
- for( int i=0; i<6; i++ )
+ for( int i=0; i<vg_list_size(vg_input.controller_axises); i++ )
{
- snprintf( buf, 40, "%.2f", vg.gamepad.axes[i] );
+ snprintf( buf, 40, "%.2f", vg_input.controller_axises[i] );
ui_text( (ui_px [2]){ 0, (i+3)*20 }, buf, 1, k_text_align_left );
}
}
"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