challenge effects
[carveJwlIkooP6JGAAIwe30JlM.git] / player.c
index da097071804d7a6e18d5faaef5a1c56c59451bb7..f5176eb21e69701b0f45aa887d1a8d7a4736d216 100644 (file)
--- a/player.c
+++ b/player.c
@@ -4,6 +4,10 @@
 #include "player.h"
 #include "camera.h"
 #include "player_model.h"
+#include "input.h"
+#include "world.h"
+#include "audio.h"
+#include "player_replay.h"
 
 VG_STATIC int localplayer_cmd_respawn( int argc, const char *argv[] )
 {
@@ -32,6 +36,17 @@ VG_STATIC void player_init(void)
    }
 
    vg_console_reg_cmd( "respawn", localplayer_cmd_respawn, NULL );
+   VG_VAR_F32( k_cam_damp );
+   VG_VAR_F32( k_cam_spring );
+   VG_VAR_F32( k_cam_punch );
+   VG_VAR_F32( k_cam_shake_strength );
+   VG_VAR_F32( k_cam_shake_trackspeed );
+   VG_VAR_I32( k_player_debug_info, flags=VG_VAR_PERSISTENT );
+
+   vg_console_reg_var( "cinema", &k_cinema, k_var_dtype_f32, 0 );
+   vg_console_reg_var( "cinema_fixed", &k_cinema_fixed, k_var_dtype_i32, 0 );
+   vg_console_reg_var( "invert_y", &k_invert_y, 
+                        k_var_dtype_i32, VG_VAR_PERSISTENT );
 }
 
 PLAYER_API
@@ -44,8 +59,8 @@ void player__debugtext( int size, const char *fmt, ... )
    vsnprintf( buffer, 1024, fmt, args );
    va_end( args );
 
-   ui_text( vg_uictx.cursor, buffer, size, k_text_align_right );
-       vg_uictx.cursor[1] += 14*size;
+   ui_text( g_player_debugger, buffer, size, k_ui_align_left, 0 );
+   g_player_debugger[1] += size*16;
 }
 
 /*
@@ -58,84 +73,12 @@ void player__create( player_instance *inst )
    assert( only_once == 0 );
    only_once ++;
 
-   inst->input_js1h = vg_create_named_input( "steer-h", k_input_type_axis );
-   inst->input_js1v = vg_create_named_input( "steer-v", k_input_type_axis );
-   inst->input_grab = vg_create_named_input( "grab",    k_input_type_axis_norm);
-   inst->input_js2h = vg_create_named_input( "grab-h",  k_input_type_axis );
-   inst->input_js2v = vg_create_named_input( "grab-v",  k_input_type_axis );
-   inst->input_jump = vg_create_named_input( "jump",    k_input_type_button );
-   inst->input_push = vg_create_named_input( "push",    k_input_type_button );
-   inst->input_walk = vg_create_named_input( "walk",    k_input_type_button );
-   inst->input_walkh= vg_create_named_input( "walk-h",  k_input_type_axis );
-   inst->input_walkv= vg_create_named_input( "walk-v",  k_input_type_axis );
-   inst->input_use  = vg_create_named_input( "use",     k_input_type_button );
-   inst->input_reset= vg_create_named_input( "reset",   k_input_type_button );
-   inst->input_camera=vg_create_named_input( "camera",  k_input_type_button );
-   inst->input_trick0=vg_create_named_input( "trick0",  k_input_type_button );
-   inst->input_trick1=vg_create_named_input( "trick1",  k_input_type_button );
-   inst->input_trick2=vg_create_named_input( "trick2",  k_input_type_button );
-
-   const char *default_cfg[] = 
-   {
-      "bind  steer-h gp-ls-h",
-      "bind -steer-h a",
-      "bind +steer-h d",
-
-      "bind  steer-v gp-ls-v",
-      "bind -steer-v w",
-      "bind +steer-v s",
-
-      "bind  grab gp-rt",
-      "bind +grab shift",
-      "bind  grab-h gp-rs-h",
-      "bind  grab-v gp-rs-v",
-
-      "bind jump space",
-      "bind jump gp-a",
-
-      "bind trick0 mouse1",
-      "bind trick0 gp-a",
-      "bind trick1 mouse2",
-      "bind trick1 gp-b",
-      "bind trick2 gp-x",     /* keyboard: m0 + m1 */
-
-      "bind push gp-b",
-      "bind push w",
-
-      "bind walk shift",
-      "bind walk gp-ls",
-      
-      "bind  walk-h  gp-ls-h",
-      "bind  walk-v -gp-ls-v",
-      "bind +walk-h d",
-      "bind -walk-h a",
-      "bind +walk-v w",
-      "bind -walk-v s",
-
-      "bind reset gp-lb",
-      "bind reset r",
-
-      "bind use gp-y",
-      "bind use e",
-      "bind camera c",
-      "bind camera gp-rb"
-   };
-
-   for( int i=0; i<vg_list_size(default_cfg); i++ )
-      vg_execute_console_input(default_cfg[i]);
-
    v3_zero( inst->rb.co );
    v3_zero( inst->rb.w );
    v3_zero( inst->rb.v );
    q_identity( inst->rb.q );
    m4x3_identity( inst->rb.to_world );
    m4x3_identity( inst->rb.to_local );
-
-   inst->rewind_length = 0;
-   inst->rewind_buffer = 
-      vg_linear_alloc( vg_mem.rtmemory, 
-                       sizeof(struct rewind_frame) * PLAYER_REWIND_FRAMES );
-
 }
 
 /* 
@@ -149,15 +92,10 @@ void player__use_avatar( player_instance *player, struct player_avatar *av )
 }
 
 PLAYER_API
-void player__use_model( player_instance *player, struct player_model *mdl )
-{
-   player->playermodel = mdl;
-}
-
-PLAYER_API
-void player__use_board( player_instance *player, struct player_board *mdl )
-{
-   player->playerboard = mdl;
+void player__use_model( player_instance *player, u16 reg_id ){
+   addon_cache_unwatch( k_addon_type_player, player->playermodel_view_slot );
+   player->playermodel_view_slot = 
+      addon_cache_create_viewer( k_addon_type_player, reg_id );
 }
 
 PLAYER_API
@@ -174,79 +112,13 @@ void player__bind( player_instance *player )
  * ----------------------------------------------------------------------------
  */
 
-VG_STATIC void player_save_rewind_frame( player_instance *player )
-{
-   if( player->rewind_length < PLAYER_REWIND_FRAMES ){
-      struct rewind_frame *fr = 
-         &player->rewind_buffer[ player->rewind_length ++ ];
-
-      v2_copy( player->cam.angles, fr->ang );
-      v3_copy( player->cam.pos, fr->pos );
-
-      if( player->rewind_length >= 2 ){
-         player->rewind_total_length += 
-            v3_dist( player->rewind_buffer[player->rewind_length-1].pos,
-                     player->rewind_buffer[player->rewind_length-2].pos );
-      }
-   }
-}
-
 PLAYER_API
-void player__pre_update( player_instance *player )
-{
-   if( player->rewinding ){
-      return;
-   }
-
-   if( vg_input_button_down( player->input_reset ) ){
-      double delta = world_global.time - world_global.last_use;
-
-      if( (delta <= RESET_MAX_TIME) && (world_global.last_use != 0.0) ){
-         player->rewinding = 1;
-         player->rewind_sound_wait = 1;
-         player->rewind_time = (double)player->rewind_length - 0.0001;
-         player_save_rewind_frame( player );
-
-         audio_lock();
-         audio_oneshot( &audio_rewind[0], 1.0f, 0.0f );
-         audio_unlock();
-
-         /* based on testing. DONT CHANGE!
-          * 
-          *    time taken: y = (x^(4/5)) * 74.5
-          *    inverse   : x = (2/149)^(4/5) * y^(4/5)
-          */
-
-         float constant = powf( 2.0f/149.0f, 4.0f/5.0f ),
-               curve    = powf( player->rewind_total_length, 4.0f/5.0f );
-         
-         player->rewind_predicted_time = constant * curve;
-         player->rewind_start = vg.time;
-         player->subsystem = player->subsystem_gate;
-         player->rb = player->rb_gate_storage;
-         v3_copy( player->angles_storage, player->angles );
-
-         if( _player_restore[ player->subsystem ] )
-            _player_restore[ player->subsystem ]( player );
-      }
-      else{
-         if( player->subsystem == k_player_subsystem_dead ){
-            localplayer_cmd_respawn( 0, NULL );
-         }
-         else{
-            /* cant do that */
-            audio_lock();
-            audio_oneshot( &audio_rewind[4], 1.0f, 0.0f );
-            audio_unlock();
-         }
-      }
-   }
-
-   if( vg_input_button_down( player->input_camera ) ){
-      if( player->camera_mode == k_cam_firstperson )
-         player->camera_mode = k_cam_thirdperson;
+void player__pre_update( player_instance *player ){
+   if( button_down( k_srbind_camera ) && !player->immobile ){
+      if( player->cam_control.camera_mode == k_cam_firstperson )
+         player->cam_control.camera_mode = k_cam_thirdperson;
       else
-         player->camera_mode = k_cam_firstperson;
+         player->cam_control.camera_mode = k_cam_firstperson;
    }
 
    if( _player_pre_update[ player->subsystem ] )
@@ -254,32 +126,15 @@ void player__pre_update( player_instance *player )
 }
 
 PLAYER_API
-void player__update( player_instance *player )
-{
-   if( player->rewinding )
-      return;
-
+void player__update( player_instance *player ){
    if( _player_update[ player->subsystem ] )
       _player_update[ player->subsystem ]( player );
 }
 
 PLAYER_API
-void player__post_update( player_instance *player )
-{
-   if( player->rewinding )
-      return;
-
+void player__post_update( player_instance *player ){
    if( _player_post_update[ player->subsystem ] )
       _player_post_update[ player->subsystem ]( player );
-
-   if((player->subsystem != k_player_subsystem_dead) && !player->gate_waiting){
-      player->rewind_accum += vg.time_frame_delta;
-
-      if( player->rewind_accum > 0.25f ){
-         player->rewind_accum -= 0.25f;
-         player_save_rewind_frame( player );
-      }
-   }
 }
 
 /*
@@ -288,16 +143,16 @@ void player__post_update( player_instance *player )
 PLAYER_API
 void player__pass_gate( player_instance *player, ent_gate *gate )
 {
-   world_routes_fracture( get_active_world(), gate, 
+   world_routes_fracture( world_current_instance(), gate, 
                           player->rb.co, player->rb.v );
 
    player->gate_waiting = gate;
-   world_routes_activate_entry_gate( get_active_world(), gate );
-
-   m4x3_mulv( gate->transport, player->tpv_lpf, player->tpv_lpf );
-   m3x3_mulv( gate->transport, player->cam_velocity_smooth, 
-                               player->cam_velocity_smooth );
+   world_routes_activate_entry_gate( world_current_instance(), gate );
 
+   struct player_cam_controller *cc = &player->cam_control;
+   m4x3_mulv( gate->transport, cc->tpv_lpf, cc->tpv_lpf );
+   m3x3_mulv( gate->transport, cc->cam_velocity_smooth, 
+                               cc->cam_velocity_smooth );
    m3x3_copy( player->basis, player->basis_gate );
 
    v4f q;
@@ -307,30 +162,21 @@ void player__pass_gate( player_instance *player, ent_gate *gate )
    q_m3x3( player->qbasis, player->basis );
    m3x3_transpose( player->basis, player->invbasis );
 
-   player->subsystem_gate = player->subsystem;
-   player->rb_gate_storage = player->rb;
-   v3_copy( player->angles, player->angles_storage );
-   player->rewind_length = 0;
-   player->rewind_total_length = 0.0f;
-   player->rewind_gate = gate;
-   player->rewind_accum = 0.0f;
-
    m4x3_mulv( gate->transport, player->cam.pos, player->cam.pos );
-   player_save_rewind_frame( player );
-
-   if( gate->type == k_gate_type_nonlocel )
-      world_global.active_world = gate->target;
 
-   world_global.in_volume = 0;
+   if( gate->flags & k_ent_gate_nonlocal )
+      world_set_active_instance( gate->target );
 
    audio_lock();
    audio_oneshot( &audio_gate_pass, 1.0f, 0.0f );
    audio_unlock();
+
+   replay_clear( &skaterift.replay );
 }
 
 VG_STATIC void player_apply_transport_to_cam( m4x3f transport )
 {
-   /* FIXME: Applies to main_camera directly! */
+   /* FIXME: Applies to skaterift.cam directly! */
 
    /* Pre-emptively edit the camera matrices so that the motion vectors 
     * are correct */
@@ -338,13 +184,13 @@ VG_STATIC void player_apply_transport_to_cam( m4x3f transport )
    m4x4f transport_4;
    m4x3_invert_affine( transport, transport_i );
    m4x3_expand( transport_i, transport_4 );
-   m4x4_mul( main_camera.mtx.pv, transport_4, main_camera.mtx.pv );
-   m4x4_mul( main_camera.mtx.v,  transport_4, main_camera.mtx.v );
+   m4x4_mul( skaterift.cam.mtx.pv, transport_4, skaterift.cam.mtx.pv );
+   m4x4_mul( skaterift.cam.mtx.v,  transport_4, skaterift.cam.mtx.v );
 
    /* we want the regular transform here no the inversion */
    m4x3_expand( transport, transport_4 );
-   m4x4_mul( gate_camera.mtx.pv, transport_4, gate_camera.mtx.pv );
-   m4x4_mul( gate_camera.mtx.v,  transport_4, gate_camera.mtx.v );
+   m4x4_mul( world_gates.cam.mtx.pv, transport_4, world_gates.cam.mtx.pv );
+   m4x4_mul( world_gates.cam.mtx.v,  transport_4, world_gates.cam.mtx.v );
 }
 
 __attribute__ ((deprecated))
@@ -362,32 +208,68 @@ VG_STATIC void gate_rotate_angles( ent_gate *gate, v3f angles, v3f d )
    d[0] = atan2f( fwd_dir[2], fwd_dir[0] );
 }
 
-PLAYER_API void player__im_gui( player_instance *player )
-{
-   vg_uictx.cursor[0] = vg.window_x - 200;
-   vg_uictx.cursor[1] = 0;
-   vg_uictx.cursor[2] = 200;
-   vg_uictx.cursor[3] = 200;
-
-   struct ui_vert *b = ui_fill_rect( vg_uictx.cursor, 0x70000000 );
+PLAYER_API void player__im_gui( player_instance *player ){
+   if( !k_player_debug_info ) return;
 
-   vg_uictx.cursor[0] = vg.window_x;
+   ui_rect box = {
+      vg.window_x - 300,
+      0, 
+      300,
+      vg.window_y
+   };
 
+   ui_fill( box, (ui_colour(k_ui_bg)&0x00ffffff)|0x50000000 );
+
+   g_player_debugger[0] = box[0];
+   g_player_debugger[1] = 0;
+   g_player_debugger[2] = 300;
+   g_player_debugger[3] = 32;
+
+   player__debugtext( 2, "instance #%u", world_static.active_instance );
+
+   char buf_hub[96],
+        buf_client[96];
+   if( world_static.addon_client )
+      addon_alias_uid( &world_static.addon_client->alias, buf_client );
+   else
+      strcpy( buf_client, "none" );
+
+   if( world_static.addon_hub )
+      addon_alias_uid( &world_static.addon_hub->alias, buf_hub );
+   else
+      strcpy( buf_hub, "none" );
+
+   player__debugtext( 1, "hub uid: %s", buf_hub );
+   player__debugtext( 1, "client uid: %s", buf_client );
+   player__debugtext( 2, "director" );
+   player__debugtext( 1, "activity: %s", 
+                     (const char *[]){ [k_skaterift_menu]      = "menu",
+                                       [k_skaterift_replay]    = "replay",
+                                       [k_skaterift_ent_focus] = "ent_focus",
+                                       [k_skaterift_default]   = "default" 
+                     } [skaterift.activity] );
+   player__debugtext( 1, "time_rate: %.4f", skaterift.time_rate );
+
+   player__debugtext( 2, "player_instance[%p]", player );
    player__debugtext( 1, "angles: " PRINTF_v3f( player->cam.angles ) );
    player__debugtext( 1, "basis:  " PRINTF_v4f( player->qbasis ) );
 
    if( _player_im_gui[ player->subsystem ] )
       _player_im_gui[ player->subsystem ]( player );
 
-   b[2].co[1] = vg_uictx.cursor[1];
-   b[3].co[1] = vg_uictx.cursor[1];
+   skaterift_replay_debug_info();
 }
 
-PLAYER_API void player__spawn( player_instance *player, 
-                               ent_spawn *rp )
-{
-   v3_copy( rp->transform.co, player->rb.co );
+
+PLAYER_API void player__setpos( player_instance *player, v3f pos ){
+   v3_copy( pos, player->rb.co );
    v3_zero( player->rb.v );
+   rb_update_transform( &player->rb );
+}
+
+PLAYER_API void player__spawn( player_instance *player, ent_spawn *rp ){
+   replay_clear( &skaterift.replay );
+   player__setpos( player, rp->transform.co );
    v3_zero( player->rb.w );
    q_identity( player->rb.q );
    rb_update_transform( &player->rb );
@@ -397,16 +279,36 @@ PLAYER_API void player__spawn( player_instance *player,
    m3x3_identity( player->invbasis );
 
    player->subsystem = k_player_subsystem_walk;
+   player->immobile = 0;
    player->gate_waiting = NULL;
+   world_static.last_use = 0.0;
+   world_static.focused_entity = 0;
+   world_static.challenge_target = NULL;
+   world_static.challenge_timer = 0.0f;
+   world_entity_unfocus();
 
    if( _player_reset[ player->subsystem ] )
       _player_reset[ player->subsystem ]( player, rp );
 }
 
 
-PLAYER_API void player__kill( player_instance *player )
-{
+PLAYER_API void player__kill( player_instance *player ){
    
 }
 
+PLAYER_API void player__begin_holdout( player_instance *player ){
+   memcpy( &player->holdout_pose, &player->pose, sizeof(player->pose) );
+   player->holdout_time = 1.0f;
+}
+
+/* implementation */
+#include "player_common.c"
+#include "player_walk.c"
+#include "player_skate.c"
+#include "player_dead.c"
+#include "player_drive.c"
+#include "player_render.c"
+#include "player_ragdoll.c"
+#include "player_replay.c"
+
 #endif /* PLAYER_C */