+/*
+ * Copyright (C) Mount0 Software, Harry Godden - All Rights Reserved
+ */
+
#include "common.h"
/* Resources */
/* 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 */
-#include "road.h"
+//#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 "terrain.h"
-#include "character.h"
+//#include "ik.h"
+#include "audio.h"
+//#include "terrain.h"
+//#include "character.h"
#include "ragdoll.h"
#include "rigidbody.h"
#include "render.h"
-#include "gate.h"
-#include "water.h"
#include "world.h"
#include "player.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();
- terrain_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,
vg_init( argc, argv, "Voyager Game Engine" );
}
-#if 0
-rigidbody mr_box = {
- .bbx = {{ -1.0f, -0.25f, -0.25f }, { 1.0f, 0.25f, 0.25f }}
-};
-
-rigidbody mrs_box = {
- .bbx = {{ -0.5f, -0.25f, -0.25f }, { 0.5f, 0.25f, 0.25f }}
-};
-
-#endif
-
static int playermodel( int argc, char const *argv[] )
{
if( argc < 1 ) return 0;
void vg_start(void)
{
+ steam_init();
+
vg_convar_push( (struct vg_convar){
- .name = "freecam",
+ .name = "fc",
.data = &freecam,
.data_type = k_convar_dtype_i32,
.opt_i32 = { .min=0, .max=1, .clamp=1 },
.persistent = 1
});
+ vg_convar_push( (struct vg_convar){
+ .name = "fcs",
+ .data = &fc_speed,
+ .data_type = k_convar_dtype_f32,
+ .opt_f32 = { .clamp = 0 },
+ .persistent = 1
+ });
+
+ 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_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
+ });
+
vg_convar_push( (struct vg_convar){
.name = "walk_speed",
.data = &k_walkspeed,
.persistent = 1
});
+ vg_convar_push( (struct vg_convar){
+ .name = "run_speed",
+ .data = &k_runspeed,
+ .data_type = k_convar_dtype_f32,
+ .opt_f32 = { .clamp = 0 },
+ .persistent = 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
+ });
+
+ vg_convar_push( (struct vg_convar){
+ .name = "dt",
+ .data = &ktimestep,
+ .data_type = k_convar_dtype_f32,
+ .opt_f32 = { .clamp = 0 },
+ .persistent = 0
+ });
+
vg_convar_push( (struct vg_convar){
.name = "debugcam",
.data = &sv_debugcam,
});
vg_tex2d_init( texture_list, vg_list_size( texture_list ) );
+
+ init_other();
- render_init();
- gate_init();
- terrain_init();
- character_init();
+ /*
+ * 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.
+ */
- character_load( &player.mdl, "ch_default" );
- character_init_ragdoll( &player.mdl );
+ if( sv_scene == 0 )
+ {
+ character_load( &player.mdl, "ch_new" );
+ character_init_ragdoll( &player.mdl );
- world_load();
+ world_load();
- reset_player( 1, (const char *[]){ "tutorial" } );
- player_transform_update();
+ reset_player( 1, (const char *[]){ "start" } );
+ rb_init( &player.rb );
+
+ network_init();
+ }
+ else if( sv_scene == 1 )
+ {
+ physics_test_start();
+ }
+ else if( sv_scene == 2 )
+ {
+ anim_test_start();
+ }
+}
+
+void vg_free(void)
+{
+ network_end();
+ vg_tex2d_free( texture_list, vg_list_size(texture_list) );
+ /* TODO: THE REST OF THE GOD DAMN FREEING STUFF */
+ steam_end();
}
void vg_update(void)
{
- player_update();
+ steam_update();
+
+ if( sv_scene == 0 )
+ {
+ 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();
+ }
}
static void vg_framebuffer_resize( int w, int h )
water_fb_resize();
}
-void vg_render(void)
+static void draw_origin_axis(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 );
+ 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 );
+}
- float speed = freecam? 0.0f: v3_length( player.v );
+static void render_main_game(void)
+{
+ float speed = freecam? 0.0f: v3_length( player.rb.v );
v3f shake = { vg_randf()-0.5f, vg_randf()-0.5f, vg_randf()-0.5f };
v3_muls( shake, speed*0.01f, shake );
- if( player.is_dead )
- {
-#if 0
- v3f delta;
- v3_sub( player.mdl.ragdoll[k_chpart_head].co, player.follow, delta );
- v3_normalize(delta);
-
- v3f follow_pos;
- v3_muladds( player.mdl.ragdoll[k_chpart_head].co, delta,
- -1.5f, follow_pos );
- v3_lerp( player.follow, follow_pos, 0.1f, player.follow );
- v3_negate( player.follow, final );
-
-
- float yaw = atan2f( delta[0], -delta[2] );
- float pitch = asinf( delta[1] );
- m4x3_rotate_x( world_matrix, -pitch );
- m4x3_rotate_y( world_matrix, yaw );
-#endif
- }
- else
- {
- }
-
m4x4f world_4x4;
m4x3_expand( player.camera_inverse, world_4x4 );
- gpipeline.fov = freecam? 60.0f: 120.0f; /* 120 */
+ gpipeline.fov = freecam? 60.0f: 125.0f; /* 120 */
m4x4_projection( vg_pv, gpipeline.fov,
(float)vg_window_x / (float)vg_window_y,
- 0.025f, 1000.0f );
+ 0.02f, 2100.0f );
m4x4_mul( vg_pv, world_4x4, vg_pv );
- 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 );
-
glEnable( GL_DEPTH_TEST );
/*
* Draw world
*/
+ int draw_solid = player.is_dead | freecam;
+
render_world( vg_pv, player.camera );
+ if( draw_solid )
+ draw_player();
render_water_texture( player.camera );
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- render_water_surface( vg_pv );
-
- vg_tex2d_bind( &tex_water, 1 );
-
- for( int i=0; i<world.gate_count; i++ )
- {
- render_gate( &world.gates[i], player.camera );
- }
+ render_water_surface( vg_pv, player.camera );
+ vg_tex2d_bind( &tex_water, 1 ); /*TODO: ?*/
+ render_world_gates( vg_pv, player.camera );
/* Copy the RGB of what we have into the background buffer */
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
else
glClear( GL_COLOR_BUFFER_BIT );
+
+ if( !draw_solid )
+ {
+ m4x4_projection( vg_pv, gpipeline.fov,
+ (float)vg_window_x / (float)vg_window_y,
+ 0.01f, 600.0f );
+ m4x4_mul( vg_pv, world_4x4, vg_pv );
+ draw_player();
+ }
- draw_player();
-
- /* Draw back in the background */
+ /* 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);
/* Other shite */
glDisable( GL_DEPTH_TEST );
vg_lines_drawall( (float *)vg_pv );
+ glViewport( 0,0, vg_window_x, vg_window_y );
+}
- /* Debugger camera */
-#if 0
- glViewport( 0,0, 800, 800 );
- glClearColor( 0.1f, 0.0f, 0.2f, 1.0f );
- glClear( GL_DEPTH_BUFFER_BIT );
-
- m4x3_identity( world_matrix );
-
- v3f debugcam;
- v3_negate( player.co, debugcam );
- debugcam[2] -= 2.0f;
- debugcam[1] -= 0.7f;
+void vg_render(void)
+{
+ glBindFramebuffer( GL_FRAMEBUFFER, 0 );
+ glViewport( 0,0, vg_window_x, vg_window_y );
- m4x3_translate( world_matrix, debugcam );
- m4x3_expand( world_matrix, world_4x4 );
+ 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 );
- m4x4_projection( vg_pv,
- 100.0f,
- (float)128.0f / (float)128.0f,
- 0.1f, 1000.0f );
- m4x4_mul( vg_pv, world_4x4, vg_pv );
+#ifndef SR_NETWORK_TEST
+ draw_origin_axis();
- if(sv_debugcam)
+ if( sv_scene == 0 )
{
- glEnable( GL_DEPTH_TEST );
- draw_player();
+ render_main_game();
+ }
+ else if( sv_scene == 1 )
+ {
+ physics_test_render();
+ }
+ else if( sv_scene == 2 )
+ {
+ anim_test_render( &tex_characters );
}
#endif
+}
- glDisable( GL_DEPTH_TEST );
- vg_lines_drawall( (float *)vg_pv );
+static void run_light_widget( struct light_widget *lw )
+{
+ struct ui_checkbox c1 = { .data=&lw->enabled };
- glViewport( 0,0, vg_window_x, vg_window_y );
+ 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 );
+ }
}
-void vg_ui(void)
+static void run_debug_info(void)
{
- char buf[20];
-
- snprintf( buf, 20, "%.2fm/s", v3_length( player.v ) );
+ char buf[40];
+
+ 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, 20, "%.2f %.2f %.2f m/s",
+ 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, 20, "pos %.2f %.2f %.2f",
- player.co[0], player.co[1], player.co[2] );
+ 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, 20, "%.2f", vg_gamepad.axes[i] );
+ snprintf( buf, 40, "%.2f", vg_gamepad.axes[i] );
gui_text( (ui_px [2]){ 0, (i+3)*20 }, buf, 1, k_text_align_left );
}
}
}
}
-void vg_free(void){}
+void vg_ui(void)
+{
+ if( lightedit )
+ {
+ ui_global_ctx.cursor[0] = 10;
+ ui_global_ctx.cursor[1] = 10;
+ ui_global_ctx.cursor[2] = 200;
+ ui_global_ctx.cursor[3] = 20;
+
+ struct ub_world_lighting *wl = &gpipeline.ub_world_lighting;
+ struct ui_slider_vector
+ s5 = { .min=0.0f, .max=2.0f, .len=3, .data=wl->g_ambient_colour };
+
+ struct ui_slider
+ s8 = { .min=0.0f, .max=2.0f, .data = &gpipeline.shadow_spread },
+ s9 = { .min=0.0f, .max=25.0f, .data = &gpipeline.shadow_length };
+
+ 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;
+ struct ui_checkbox c1 = {.data = &wl->g_light_preview};
+ ui_checkbox( &ui_global_ctx, &c1 );
+
+ render_update_lighting_ub();
+ }
+
+ //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
+ if( cl_ui )
+ {
+ render_world_routes_ui();
+ }
+ //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+
+#if 0
+ static double last_b_press = 0.0;
+
+ double localtime = vg_time - last_b_press;
+
+ world_routes_ui_updatetime( 0, localtime );
+ world_routes_ui_draw( 0, (v4f){ 1.0f,0.0f,1.0f,1.0f}, 9.0f );
+
+ if( glfwGetKey(vg_window,GLFW_KEY_B) )
+ world_routes_ui_notch( 0, localtime );
+
+ 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 );
+ }
+
+ static double last_m_press;
+ if( vg_time-last_m_press > 1.0 )
+ if( glfwGetKey( vg_window, GLFW_KEY_M) )
+ {
+ 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 );
+ }
+#endif
+}