LPR - Walking
[carveJwlIkooP6JGAAIwe30JlM.git] / skaterift.c
index 272cff9ba4df78002bbb512041558270760bdfe2..ab24550521a7779045192bcb0bc1cb614d1f7899 100644 (file)
 #include "render.h"
 #include "audio.h"
 #include "world.h"
+
+#if 0
 #include "player.h"
+#else
+#include "player_interface.h"
+#include "player_device_walk.h"
+#include "player_model.h"
+
+VG_STATIC player_interface localplayer;
+VG_STATIC struct player_device_walk localplayer_walk;
+
+#endif
+
 #include "network.h"
+
+#if 0
 #include "menu.h"
+#endif
 #include "vehicle.h"
 
 static int cl_ui      = 1,
@@ -46,6 +61,58 @@ VG_STATIC void vg_launch_opt(void)
 
 }
 
+VG_STATIC int __respawn( int argc, const char *argv[] )
+{
+   struct respawn_point *rp = NULL, *r;
+
+   if( argc == 1 )
+   {
+      for( int i=0; i<world.spawn_count; i++ )
+      {
+         r = &world.spawns[i];
+         if( !strcmp( r->name, argv[0] ) )
+         {
+            rp = r;
+            break;
+         }
+      }
+
+      if( !rp )
+         vg_warn( "No spawn named '%s'\n", argv[0] );
+   }
+
+   if( !rp )
+   {
+      float min_dist = INFINITY;
+
+      for( int i=0; i<world.spawn_count; i++ )
+      {
+         r = &world.spawns[i];
+         float d = v3_dist2( r->co, localplayer.rb.co );
+         
+         vg_info( "Dist %s : %f\n", r->name, d );
+         if( d < min_dist )
+         {
+            min_dist = d;
+            rp = r;
+         }
+      }
+   }
+
+   if( !rp )
+   {
+      vg_error( "No spawn found\n" );
+
+      if( !world.spawn_count )
+         return 0;
+
+      rp = &world.spawns[0];
+   }
+
+   player_spawn( &localplayer, rp );
+   return 1;
+}
+
 VG_STATIC void vg_preload(void)
 {
    g_conf_init();
@@ -74,6 +141,12 @@ VG_STATIC void vg_preload(void)
       .persistent = 0
    });
 
+   vg_function_push( (struct vg_cmd) {
+      .name = "respawn",
+      .function = __respawn,
+      //.poll_suggest = reset_player_poll
+   });
+
 vg_info(" Copyright  .        . .       -----, ,----- ,---.   .---.  \n" );
 vg_info(" 2021-2022  |\\      /| |           /  |      |    | |    /| \n" );
 vg_info("            | \\    / | +--        /   +----- +---'  |   / | \n" );
@@ -96,10 +169,15 @@ vg_info("            '        ' '--' [] '----- '----- '     ' '---'  "
 VG_STATIC void vg_load(void)
 {
    vg_loader_step( render_init, NULL );
-   vg_loader_step( menu_init, NULL );
+   //vg_loader_step( menu_init, NULL );
    vg_loader_step( world_init, NULL );
-   vg_loader_step( player_init, NULL );
-   vg_loader_step( vehicle_init, NULL );
+   //vg_loader_step( player_init, NULL );
+   //vg_loader_step( vehicle_init, NULL );
+   //
+   vg_loader_step( player_model_init, NULL );
+
+   player_interface_create_player( &localplayer );
+   player_use_device( &localplayer, &player_device_walk, &localplayer_walk );
 
    vg_bake_shaders();
    vg_loader_step( audio_init, audio_free );
@@ -114,7 +192,7 @@ VG_STATIC void vg_load(void)
 
 VG_STATIC void vg_start(void)
 {
-   reset_player( 1, (const char *[]){ "start" } );
+   __respawn( 1, (const char *[]){ "start" } );
 }
 
 VG_STATIC void draw_origin_axis(void)
@@ -133,10 +211,13 @@ VG_STATIC void vg_update(void)
       draw_origin_axis();
       network_update();
       
+#if 0
       if( !gzoomer.inside )
          player_update_pre();
+#endif
 
-      world_update( player.phys.rb.co );
+      player_pre_update( &localplayer );
+      world_update( localplayer.rb.co );
    }
 }
 
@@ -144,10 +225,14 @@ VG_STATIC void vg_update_fixed(void)
 {
    if( vg.is_loaded )
    {
+#if 0
       if( !gzoomer.inside )
          player_update_fixed();
 
       vehicle_update_fixed();
+#endif
+
+      player_update( &localplayer );
    }
 }
 
@@ -155,6 +240,7 @@ VG_STATIC void vg_update_post(void)
 {
    if( vg.is_loaded )
    {
+#if 0
       if( gzoomer.inside )
       {
          vehicle_camera();
@@ -163,8 +249,14 @@ VG_STATIC void vg_update_post(void)
       {
          player_update_post();
       }
+#endif
+
+      player_post_update( &localplayer );
+
+#if 0
       menu_update();
       vehicle_update_post();
+#endif
    }
 }
 
@@ -190,7 +282,8 @@ VG_STATIC void present_view_with_post_processing(void)
       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 );
+      //v2_muls( (v2f){ 0.04f, 0.001f }, menu_opacity, menu_blurring );
+      v2_muls( (v2f){ 0.04f, 0.001f }, 0.0f, menu_blurring );
       shader_blitblur_uOverrideDir( menu_blurring );
 
       if( cl_view_id == 0 )
@@ -230,7 +323,9 @@ VG_STATIC void render_player_transparent(void)
    /* Draw player to window buffer and blend background ontop */
 
    glBindFramebuffer( GL_FRAMEBUFFER, 0 );
+#if 0
    draw_player( &small_cam );
+#endif
 }
 
 VG_STATIC void render_scene(void)
@@ -244,42 +339,60 @@ VG_STATIC void render_scene(void)
 
    render_world( &main_camera );
 
+#if 0
    int player_transparent = !(player.is_dead || freecam),
        player_draw        = !cl_menu;
 
    if( !player_transparent && player_draw )
       draw_player( &main_camera );
+#endif
 
    render_water_texture( &main_camera );
    render_fb_bind( gpipeline.fb_main );
    render_water_surface( &main_camera );
    render_world_gates( &main_camera );
 
+#if 0
    if( player_transparent && player_draw )
       render_player_transparent();
+#endif
 }
 
 VG_STATIC void render_menu(void)
 {
    glClear( GL_DEPTH_BUFFER_BIT );
+#if 0
    menu_render( &main_camera );
+#endif
 }
 
 VG_STATIC void render_main_game(void)
 {
+#if 0
    static float fov = 60.0f;
    float fov_target = vg_lerpf( 90.0f, 110.0f, cl_fov );
-   if( player.phys.on_board )
+
+   if( player.controller == k_player_controller_skate )
       fov_target = vg_lerpf( 97.0f, 135.0f, cl_fov );
+
    if( cl_menu )
       fov_target = menu_fov_target;
    fov = vg_lerpf( fov, fov_target, vg.frame_delta * 2.0f );
    fov = freecam? 60.0f: fov;
 
    main_camera.fov   = fov;
+#endif
+
+   /* copy camera from player.
+    * TODO: blend with camera from menu */
+
+   v3_copy( localplayer.cam.pos, main_camera.pos );
+   v3_copy( localplayer.cam.angles, main_camera.angles );
+   main_camera.fov = localplayer.cam.fov;
    main_camera.nearz = 0.1f;
    main_camera.farz  = 2100.0f;
 
+   camera_update_transform( &main_camera );
    camera_update_view( &main_camera );
    camera_update_projection( &main_camera );
    camera_finalize( &main_camera );
@@ -289,11 +402,13 @@ VG_STATIC void render_main_game(void)
    render_scene();
    present_view_with_post_processing();
 
+#if 0
    if( cl_menu ) 
    {
       render_menu();
       render_player_transparent();
    }
+#endif
 
    /* =========== End Frame =========== */
 }
@@ -320,7 +435,11 @@ VG_STATIC void vg_render(void)
 VG_STATIC void run_light_widget( struct light_widget *lw );
 VG_STATIC void vg_ui(void)
 {
+   player_ui( &localplayer );
+
+#if 0
    menu_crap_ui();
+#endif
 
    if( cl_light_edit )
    {
@@ -366,7 +485,10 @@ VG_STATIC void vg_ui(void)
    
    audio_debug_soundscapes();
    render_view_framebuffer_ui();
+
+#if 0
    player_physics_gui();
+#endif
 }
 
 VG_STATIC void run_light_widget( struct light_widget *lw )
@@ -389,9 +511,10 @@ VG_STATIC void run_light_widget( struct light_widget *lw )
 
 VG_STATIC void run_debug_info(void)
 {
+#if 0
    char buf[40];
    
-   snprintf( buf, 40, "%.2fm/s", v3_length( player.phys.rb.v ) );
+   snprintf( buf, 40, "%.2fm/s", v3_length( player.rb.v ) );
    ui_text( (ui_px [2]){ 0, 0 }, buf, 1, k_text_align_left );
    
    snprintf( buf, 40, "%.2f %.2f %.2f m/s", 
@@ -415,4 +538,5 @@ VG_STATIC void run_debug_info(void)
       ui_text( (ui_px [2]){ 0, 60 }, 
             "Gamepad not ready", 1, k_text_align_left );
    }
+#endif
 }