/*
- * Copyright (C) Mount0 Software, Harry Godden - All Rights Reserved
+ * =============================================================================
+ *
+ * Copyright . . . -----, ,----- ,---. .---.
+ * 2021-2022 |\ /| | / | | | | /|
+ * | \ / | +-- / +----- +---' | / |
+ * | \ / | | / | | \ | / |
+ * | \/ | | / | | \ | / |
+ * ' ' '--' [] '----- '----- ' ' '---' SOFTWARE
+ *
+ * =============================================================================
+ *
+ * register: shader register & init scheduling
+ * init: initialization
+ * update: logic
+ * render: graphics
+ * free: resource free
+ *
*/
+#define SR_NETWORKED
+#define VG_3D
#include "common.h"
-
-/* Resources */
-vg_tex2d tex_norwey = { .path = "textures/norway_foliage.qoi" };
-vg_tex2d tex_grid = { .path = "textures/grid.qoi" };
-vg_tex2d tex_sky = { .path = "textures/sky.qoi" };
-vg_tex2d tex_gradients = { .path = "textures/gradients.qoi",
- .flags = VG_TEXTURE_CLAMP };
-vg_tex2d tex_cement = { .path = "textures/cement512.qoi" };
-vg_tex2d tex_water = { .path = "textures/water.qoi" };
-
-/* Convars */
-static int debugview = 0;
-static int sv_debugcam = 0;
-static int lightedit = 0;
-static int sv_scene = 0;
-static int cl_ui = 1;
-
-/* Components */
-//#define SR_NETWORKED
-
-/* uncomment this to run the game without any graphics being drawn */
-//#define SR_NETWORK_TEST
-
#include "steam.h"
-#include "network.h"
-
-#include "model.h"
-//#include "road.h"
-#include "scene.h"
-//#include "ik.h"
-#include "audio.h"
-//#include "terrain.h"
-//#include "character.h"
-#include "ragdoll.h"
-#include "rigidbody.h"
#include "render.h"
+#include "audio.h"
#include "world.h"
#include "player.h"
-#include "shaders/blit.h"
-#include "shaders/standard.h"
-#include "shaders/unlit.h"
-
-#include "physics_test.h"
-#include "anim_test.h"
-
-#include "gate.h"
-#include "water.h"
-
-void vg_register(void)
-{
- shader_blit_register();
- shader_standard_register();
- shader_vblend_register();
- shader_unlit_register();
-
- world_register();
- character_register();
- water_register();
- gate_register();
-}
-
-static void init_other(void)
-{
- player_init();
- render_init();
- gate_init();
- world_init();
- character_init();
- audio_init();
-}
-
-vg_tex2d *texture_list[] =
-{
- &tex_norwey,
- &tex_gradients,
- &tex_grid,
- &tex_sky,
- &tex_cement,
- &tex_water,
- &tex_water_surf
-};
+static int cl_ui = 1;
int main( int argc, char *argv[] )
{
- vg_init( argc, argv, "Voyager Game Engine" );
+ vg_enter( argc, argv, "Voyager Game Engine" );
}
-static int playermodel( int argc, char const *argv[] )
+static void highscores_save_at_exit(void*_)
{
- if( argc < 1 ) return 0;
-
- glmesh old_mesh = player.mdl.mesh;
-
- if( character_load( &player.mdl, argv[0] ) )
- mesh_free( &old_mesh );
-
- return 1;
+ highscores_serialize_all();
+ highscores_free();
}
-void vg_start(void)
+int vg_preload(void)
{
- steam_init();
-
vg_convar_push( (struct vg_convar){
- .name = "fc",
- .data = &freecam,
+ .name = "cl_ui",
+ .data = &cl_ui,
.data_type = k_convar_dtype_i32,
.opt_i32 = { .min=0, .max=1, .clamp=1 },
.persistent = 1
});
- vg_convar_push( (struct vg_convar){
- .name = "grid",
- .data = &walk_grid_iterations,
- .data_type = k_convar_dtype_i32,
- .opt_i32 = { .min=0, .max=1, .clamp=0 },
- .persistent = 1
- });
+vg_info(" Copyright . . . -----, ,----- ,---. .---. " );
+vg_info(" 2021-2022 |\\ /| | / | | | | /| " );
+vg_info(" | \\ / | +-- / +----- +---' | / | " );
+vg_info(" | \\ / | | / | | \\ | / | " );
+vg_info(" | \\/ | | / | | \\ | / | " );
+vg_info(" ' ' '--' [] '----- '----- ' ' '---' "
+ "SOFTWARE" );
- vg_convar_push( (struct vg_convar){
- .name = "fcs",
- .data = &fc_speed,
- .data_type = k_convar_dtype_f32,
- .opt_f32 = { .clamp = 0 },
- .persistent = 1
- });
+ highscores_init( 2000, 50 );
+ if( !vg_loader_highwater( highscores_save_at_exit, NULL ) ) return 0;
- vg_convar_push( (struct vg_convar){
- .name = "ledit",
- .data = &lightedit,
- .data_type = k_convar_dtype_i32,
- .opt_i32 = { .min=0, .max=1, .clamp=1 },
- .persistent = 1
- });
+ vg_sleep_ms(200);
- vg_convar_push( (struct vg_convar){
- .name = "cl_ui",
- .data = &cl_ui,
- .data_type = k_convar_dtype_i32,
- .opt_i32 = { .min=0, .max=1, .clamp=1 },
- .persistent = 1
- });
+ if( !steam_init() ) return 0;
+ if( !vg_loader_highwater( steam_end, NULL ) ) return 0;
- vg_convar_push( (struct vg_convar){
- .name = "walk_speed",
- .data = &k_walkspeed,
- .data_type = k_convar_dtype_f32,
- .opt_f32 = { .clamp = 0 },
- .persistent = 1
- });
+ if( !network_init() ) return 0;
+ if( !vg_loader_highwater( network_end, NULL ) ) return 0;
- vg_convar_push( (struct vg_convar){
- .name = "run_speed",
- .data = &k_runspeed,
- .data_type = k_convar_dtype_f32,
- .opt_f32 = { .clamp = 0 },
- .persistent = 1
- });
+ return 1;
+}
- vg_convar_push( (struct vg_convar){
- .name = "walk_accel",
- .data = &k_walk_accel,
- .data_type = k_convar_dtype_f32,
- .opt_f32 = { .clamp = 0 },
- .persistent = 1
- });
+int vg_load(void)
+{
+ if( !render_init() ) return 0;
+ if( !vg_loader_highwater( render_free, NULL ) ) return 0;
- vg_convar_push( (struct vg_convar){
- .name = "dt",
- .data = &ktimestep,
- .data_type = k_convar_dtype_f32,
- .opt_f32 = { .clamp = 0 },
- .persistent = 0
- });
+ if( !world_init() ) return 0;
- vg_convar_push( (struct vg_convar){
- .name = "debugcam",
- .data = &sv_debugcam,
- .data_type = k_convar_dtype_i32,
- .opt_i32 = { .min=0, .max=1, .clamp=0 },
- .persistent = 1
- });
+ if( !player_init() ) return 0;
+ if( !vg_loader_highwater( player_model_free, NULL ) ) return 0;
- vg_convar_push( (struct vg_convar){
- .name = "debugview",
- .data = &debugview,
- .data_type = k_convar_dtype_i32,
- .opt_i32 = { .min=0, .max=1, .clamp=0 },
- .persistent = 1
- });
- vg_function_push( (struct vg_cmd){
- .name = "reset",
- .function = reset_player
- });
- vg_tex2d_init( texture_list, vg_list_size( texture_list ) );
-
- init_other();
+ if( !vg_bake_shaders() ) return 0;
- /*
- * If we're in physics test mode we dont need to load anything else, this
- * parameter is dev only. TODO: dev only cvars that don't ship with the game
- * when building in release mode.
- */
- if( sv_scene == 0 )
- {
- character_load( &player.mdl, "ch_new" );
- character_init_ragdoll( &player.mdl );
+ if( !audio_init() ) return 0;
+ if( !vg_loader_highwater( audio_free, NULL ) ) return 0;
- world_load();
+ /* FInal step */
+ world_load();
+ vg_console_load_autos();
- reset_player( 1, (const char *[]){ "start" } );
- rb_init( &player.rb );
+ return 1;
+}
- network_init();
- }
- else if( sv_scene == 1 )
- {
- physics_test_start();
- }
- else if( sv_scene == 2 )
- {
- anim_test_start();
- }
+static void vg_start(void)
+{
+ player_load_model( "ch_new" );
+ reset_player( 1, (const char *[]){ "start" } );
}
-void vg_free(void)
+static void draw_origin_axis(void)
{
- network_end();
- vg_tex2d_free( texture_list, vg_list_size(texture_list) );
- /* TODO: THE REST OF THE GOD DAMN FREEING STUFF */
- steam_end();
+ 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(void)
+void vg_update( int loaded )
{
steam_update();
- if( sv_scene == 0 )
+ if( loaded )
{
+ draw_origin_axis();
network_update();
player_update();
- world_update();
- //traffic_visualize( world.traffic, world.traffic_count );
- //
- /* TEMP */
- if( glfwGetKey( vg_window, GLFW_KEY_J ))
- {
- v3_copy( player.camera_pos, world.mr_ball.co );
- }
- }
- else if( sv_scene == 1 )
- {
- physics_test_update();
- }
- else if( sv_scene == 2 )
- {
- anim_test_update();
+ world_update( player.phys.rb.co );
}
}
water_fb_resize();
}
-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 );
-}
-
static void render_main_game(void)
{
- float speed = freecam? 0.0f: v3_length( player.rb.v );
+ /* TODO Breakup this & Gen */
+#if 0
+ float speed = freecam? 0.0f: v3_length( player.phys.rb.v );
v3f shake = { vg_randf()-0.5f, vg_randf()-0.5f, vg_randf()-0.5f };
v3_muls( shake, speed*0.01f, shake );
+#endif
m4x4f world_4x4;
m4x3_expand( player.camera_inverse, world_4x4 );
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
render_water_surface( vg_pv, player.camera );
- vg_tex2d_bind( &tex_water, 1 ); /*TODO: ?*/
- render_world_gates( vg_pv, player.camera );
+ render_world_gates( vg_pv, player.phys.rb.co, player.camera );
/* Copy the RGB of what we have into the background buffer */
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
glBindTexture( GL_TEXTURE_2D, gpipeline.rgb_background );
render_fsquad();
- glDisable(GL_BLEND);
-
- /* Other shite */
- glDisable( GL_DEPTH_TEST );
- vg_lines_drawall( (float *)vg_pv );
- glViewport( 0,0, vg_window_x, vg_window_y );
}
-void vg_render(void)
+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 );
-#ifndef SR_NETWORK_TEST
- draw_origin_axis();
-
- if( sv_scene == 0 )
- {
- render_main_game();
- }
- else if( sv_scene == 1 )
- {
- physics_test_render();
- }
- else if( sv_scene == 2 )
- {
- anim_test_render( &tex_characters );
- }
-#endif
-}
-
-static void run_light_widget( struct light_widget *lw )
-{
- struct ui_checkbox c1 = { .data=&lw->enabled };
-
- ui_checkbox( &ui_global_ctx, &c1 );
-
- if( lw->enabled )
- {
- struct ui_slider_vector
- 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 );
- }
-}
-
-static void run_debug_info(void)
-{
- char buf[40];
+ render_main_game();
- snprintf( buf, 40, "%.2fm/s", v3_length( player.rb.v ) );
- gui_text( (ui_px [2]){ 0, 0 }, buf, 1, k_text_align_left );
- snprintf( buf, 40, "%.2f %.2f %.2f m/s",
- player.a[0], player.a[1], player.a[2] );
- gui_text( (ui_px [2]){ 0, 20 }, buf, 1, k_text_align_left );
-
- snprintf( buf, 40, "pos %.2f %.2f %.2f",
- player.rb.co[0], player.rb.co[1], player.rb.co[2] );
- gui_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 );
- }
- }
- else
- {
- gui_text( (ui_px [2]){ 0, 60 },
- "Gamepad not ready", 1, k_text_align_left );
- }
+ /* Other shite */
+ glDisable(GL_BLEND);
+ glDisable( GL_DEPTH_TEST );
+ vg_lines_drawall( (float *)vg_pv );
+ glViewport( 0,0, vg_window_x, vg_window_y );
}
void vg_ui(void)
{
+#if 0
if( lightedit )
{
ui_global_ctx.cursor[0] = 10;
render_update_lighting_ub();
}
+#endif
//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
if( cl_ui )
render_world_routes_ui();
}
//glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+
+ audio_debug_soundscapes();
+}
+
+void vg_free(void)
+{
+}
#if 0
- static double last_b_press = 0.0;
+static void run_light_widget( struct light_widget *lw )
+{
+ struct ui_checkbox c1 = { .data=&lw->enabled };
- double localtime = vg_time - last_b_press;
+ ui_checkbox( &ui_global_ctx, &c1 );
+
+ if( lw->enabled )
+ {
+ struct ui_slider_vector
+ colour = { .min=0.0f, .max=2.0f, .len=3, .data=lw->colour },
+ dir = { .min=-VG_PIf, .max=VG_PIf, .len=2, .data=lw->dir };
- world_routes_ui_updatetime( 0, localtime );
- world_routes_ui_draw( 0, (v4f){ 1.0f,0.0f,1.0f,1.0f}, 9.0f );
+ ui_slider_vector( &ui_global_ctx, &colour );
+ ui_global_ctx.cursor[1] += 4;
+ ui_slider_vector( &ui_global_ctx, &dir );
+ }
+}
+#endif
- if( glfwGetKey(vg_window,GLFW_KEY_B) )
- world_routes_ui_notch( 0, localtime );
+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 );
+
+ 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 );
- if( vg_time-last_b_press > 1.0 )
- if( glfwGetKey(vg_window,GLFW_KEY_N) )
- {
- last_b_press = vg_time;
- world_routes_ui_newseg( 0 );
- }
+ 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 );
- static double last_m_press;
- if( vg_time-last_m_press > 1.0 )
- if( glfwGetKey( vg_window, GLFW_KEY_M) )
+ if( vg.gamepad_ready )
+ {
+ for( int i=0; i<6; i++ )
{
- last_m_press = vg_time;
-
- vg_info( "start: %u\n",world.routes.routes[0].ui.segment_count );
- for( int i=0; i<world.routes.routes[0].ui.segment_count; i++ )
- world_routes_ui_popfirst(0);
-
- vg_info( "new: %u\n",world.routes.routes[0].ui.segment_count );
+ snprintf( buf, 40, "%.2f", vg.gamepad.axes[i] );
+ gui_text( (ui_px [2]){ 0, (i+3)*20 }, buf, 1, k_text_align_left );
}
-#endif
+ }
+ else
+ {
+ gui_text( (ui_px [2]){ 0, 60 },
+ "Gamepad not ready", 1, k_text_align_left );
+ }
}