stuff
[carveJwlIkooP6JGAAIwe30JlM.git] / main.c
diff --git a/main.c b/main.c
index 8b2f5615193d5eb146719b4993bddc2c5ca16237..175f12efe879a4af4a8244c231bf57fd3f47117a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -17,9 +17,17 @@ vg_tex2d tex_water = { .path = "textures/water.qoi" };
 static int debugview = 0;
 static int sv_debugcam = 0;
 static int lightedit = 0;
-static int sv_scene = 1;
+static int sv_scene = 0;
 
 /* 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 "road.h"
 #include "scene.h"
 #include "ik.h"
@@ -38,9 +46,7 @@ static int sv_scene = 1;
 #include "shaders/standard.h"
 #include "shaders/unlit.h"
 
-#ifndef VG_RELEASE
 #include "physics_test.h"
-#endif
 
 void vg_register(void)
 {
@@ -57,6 +63,7 @@ void vg_register(void)
 
 static void init_other(void)
 {
+   player_init();
    render_init();
    gate_init();
    world_init();
@@ -77,7 +84,7 @@ vg_tex2d *texture_list[] =
 
 int main( int argc, char *argv[] )
 { 
-   vg_init( argc, argv, "CARBE" ); 
+   vg_init( argc, argv, "Voyager Game Engine" ); 
 }
 
 static int playermodel( int argc, char const *argv[] )
@@ -94,13 +101,7 @@ static int playermodel( int argc, char const *argv[] )
 
 void vg_start(void)
 {
-   vg_convar_push( (struct vg_convar){
-      .name = "scene",
-      .data = &sv_scene,
-      .data_type = k_convar_dtype_i32,
-      .opt_i32 = { .min=0, .max=1, .clamp=1 },
-      .persistent = 1
-   });
+   steam_init();
 
    vg_convar_push( (struct vg_convar){
       .name = "fc",
@@ -182,6 +183,8 @@ void vg_start(void)
 
       reset_player( 1, (const char *[]){ "start" } );
       rb_init( &player.rb );
+
+      network_init();
    }
    else
    {
@@ -191,13 +194,19 @@ void vg_start(void)
 
 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)
 {
+   steam_update();
+
    if( sv_scene == 0 )
    {
+      network_update();
       player_update();
       world_update();
       //traffic_visualize( world.traffic, world.traffic_count );
@@ -240,7 +249,7 @@ static void render_main_game(void)
    gpipeline.fov = freecam? 60.0f: 135.0f; /* 120 */
    m4x4_projection( vg_pv, gpipeline.fov, 
          (float)vg_window_x / (float)vg_window_y, 
-         0.1f, 2100.0f );
+         0.02f, 2100.0f );
 
    m4x4_mul( vg_pv, world_4x4, vg_pv );
 
@@ -249,20 +258,15 @@ static void render_main_game(void)
    /* 
     * Draw world
     */
-
+   
    render_world( vg_pv, player.camera );
    render_water_texture( player.camera );
 
    glBindFramebuffer( GL_FRAMEBUFFER, 0 );
    render_water_surface( vg_pv, player.camera );
 
-   vg_tex2d_bind( &tex_water, 1 );
-
-   for( int i=0; i<world.gate_count; i++ )
-   {
-      render_gate( &world.gates[i], 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 );
@@ -285,7 +289,7 @@ static void render_main_game(void)
    {
       m4x4_projection( vg_pv, gpipeline.fov, 
             (float)vg_window_x / (float)vg_window_y, 
-            0.01f, 100.0f );
+            0.04f, 600.0f );
       m4x4_mul( vg_pv, world_4x4, vg_pv );
    }
    draw_player();
@@ -323,6 +327,7 @@ void vg_render(void)
    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 )
@@ -333,6 +338,7 @@ void vg_render(void)
    {
       physics_test_render();
    }
+#endif
 }
 
 static void run_light_widget( struct light_widget *lw )
@@ -353,27 +359,26 @@ static void run_light_widget( struct light_widget *lw )
    }
 }
 
-void vg_ui(void)
+static void run_debug_info(void)
 {
-   char buf[20];
-
-#if 0
-   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 );
       }
    }
@@ -382,8 +387,10 @@ void vg_ui(void)
       gui_text( (ui_px [2]){ 0, 60 }, 
             "Gamepad not ready", 1, k_text_align_left );
    }
-#endif
-   
+}
+
+void vg_ui(void)
+{
    if( lightedit )
    {
       ui_global_ctx.cursor[0] = 10;