-#include "player_animation.h"
-#include "player_audio.h"
-
-/*
- * player_physics_<INTERFACE>_<SUB-INTERFACE>
- *
- *
- *
- */
-
-/*
- * -----------------------------------------------------------------------------
- * Events
- * -----------------------------------------------------------------------------
- */
-VG_STATIC int kill_player( int argc, char const *argv[] );
-VG_STATIC int reset_player( int argc, char const *argv[] );
-VG_STATIC void reset_player_poll( int argc, char const *argv[] );
-
-VG_STATIC void player_init(void) /* 1 */
-{
-#if 0
- player.input_js1h = vg_create_named_input( "steer-h", k_input_type_axis );
- player.input_js1v = vg_create_named_input( "steer-v", k_input_type_axis );
- player.input_grab = vg_create_named_input( "grab", k_input_type_axis_norm );
- player.input_js2h = vg_create_named_input( "grab-h", k_input_type_axis );
- player.input_js2v = vg_create_named_input( "grab-v", k_input_type_axis );
- player.input_jump = vg_create_named_input( "jump", k_input_type_button );
- player.input_push = vg_create_named_input( "push", k_input_type_button );
- player.input_walk = vg_create_named_input( "walk", k_input_type_button );
-
- player.input_walkh = vg_create_named_input( "walk-h",
- k_input_type_axis );
- player.input_walkv = vg_create_named_input( "walk-v",
- k_input_type_axis );
-
-
- player.input_switch_mode = vg_create_named_input( "switch-mode",
- k_input_type_button );
- player.input_reset = vg_create_named_input( "reset", 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 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 switch-mode gp-y",
- "bind switch-mode e",
- };
-
- for( int i=0; i<vg_list_size(default_cfg); i++ )
- vg_execute_console_input(default_cfg[i]);
-#endif
-
- rb_init( &player.rb );
-
- VG_VAR_F32( k_walkspeed );
- VG_VAR_F32( k_stopspeed );
- VG_VAR_F32( k_airspeed );
- VG_VAR_F32( k_walk_friction );
- VG_VAR_F32( k_walk_air_accel );
- VG_VAR_F32( k_runspeed );
- VG_VAR_F32( k_walk_accel );
-
- VG_VAR_I32( freecam );
- VG_VAR_I32( cl_thirdperson );
- VG_VAR_F32_PERSISTENT( fc_speed );
-
- /* TODO: NOT PERSISTENT */
- VG_VAR_F32( k_ragdoll_limit_scale );
- VG_VAR_I32( k_ragdoll_div );
- VG_VAR_I32( k_ragdoll_debug_collider );
- VG_VAR_I32( k_ragdoll_debug_constraints );
-
- VG_VAR_F32( k_friction_lat );
-
- VG_VAR_F32( k_cog_spring );
- VG_VAR_F32( k_cog_damp );
-
- VG_VAR_F32( k_cog_mass_ratio );
- VG_VAR_F32( k_downforce );
-
- VG_VAR_F32( k_spring_force );
- VG_VAR_F32( k_spring_dampener );
- VG_VAR_F32( k_spring_angular );
-
- VG_VAR_F32( k_mmthrow_scale );
- VG_VAR_F32( k_mmcollect_lat );
- VG_VAR_F32( k_mmcollect_vert );
- VG_VAR_F32( k_mmdecay );
-
- vg_function_push( (struct vg_cmd){
- .name = "reset",
- .function = reset_player,
- .poll_suggest = reset_player_poll
- });
-
- vg_function_push( (struct vg_cmd){
- .name = "kill",
- .function = kill_player
- });
-
- /* HACK */
- rb_register_cvar();
-
- player.rewind_length = 0;
- player.rewind_buffer =
- vg_linear_alloc( vg_mem.rtmemory,
- sizeof(struct rewind_frame) * PLAYER_REWIND_FRAMES );
-
- player_model_init();
-}
-
-VG_STATIC void player_save_rewind_frame(void)
-{
- if( player.rewind_length < PLAYER_REWIND_FRAMES )
- {
- struct rewind_frame *fr =
- &player.rewind_buffer[ player.rewind_length ++ ];
-
- v2_copy( player.angles, fr->ang );
- v3_copy( player.camera_pos, fr->pos );
-
- player.rewind_incrementer = 0;
-
- if( player.rewind_length > 1 )
- {
- player.rewind_total_length +=
- v3_dist( player.rewind_buffer[player.rewind_length-1].pos,
- player.rewind_buffer[player.rewind_length-2].pos );
- }
- }
-}
-
-
-/* disaster */
-VG_STATIC int menu_enabled(void);
-#include "menu.h"
-
-VG_STATIC void player_do_motion(void);
-/*
- * Free camera movement
- */
-VG_STATIC void player_mouseview(void)
-{
- if( menu_enabled() )
- return;
-
- v2_muladds( player.angles, vg.mouse_delta, 0.0025f, player.angles );
-
- if( vg_input.controller_should_use_trackpad_look )
- {
- static v2f last_input;
- static v2f vel;
- static v2f vel_smooth;
-
- v2f input = { player.input_js2h->axis.value,
- player.input_js2v->axis.value };
-
- if( (v2_length2(last_input) > 0.001f) && (v2_length2(input) > 0.001f) )
- {
- v2_sub( input, last_input, vel );
- v2_muls( vel, 1.0f/vg.time_delta, vel );
- }
- else
- {
- v2_zero( vel );
- }
-
- v2_lerp( vel_smooth, vel, vg.time_delta*8.0f, vel_smooth );
-
- v2_muladds( player.angles, vel_smooth, vg.time_delta, player.angles );
- v2_copy( input, last_input );
- }
- else
- {
- player.angles[0] += player.input_js2h->axis.value * vg.time_delta * 4.0f;
- player.angles[1] += player.input_js2v->axis.value * vg.time_delta * 4.0f;
- }
-
- player.angles[1] = vg_clampf( player.angles[1], -VG_PIf*0.5f, VG_PIf*0.5f );
-}
-
-/* Deal with input etc */
-VG_STATIC void player_update_pre(void)
-{
-
- {
- v3f ra, rb, rx;
- v3_copy( main_camera.pos, ra );
- v3_muladds( ra, main_camera.transform[2], -10.0f, rb );
-
- float t;
- if( spherecast_world( ra, rb, 0.4f, &t, rx ) != -1 )
- {
- m4x3f mtx;
- m3x3_identity( mtx );
- v3_lerp( ra, rb, t, mtx[3] );
-
- debug_sphere( mtx, 0.4f, 0xff00ff00 );
-
- v3f x1;
- v3_muladds( mtx[3], rx, 0.4f, x1 );
- vg_line( mtx[3], x1, 0xffffffff );
- }
- }
-
-#if 0
-
- vg_line_pt3( phys->cog, 0.10f, 0xffffffff );
- vg_line_pt3( phys->cog, 0.09f, 0xffffffff );
- vg_line_pt3( phys->cog, 0.08f, 0xffffffff );
- vg_line( phys->cog, phys->rb.co, 0xff000000 );
-
- v3f spring_end;
- v3f throw_end, p0, p1;
- v3_muladds( phys->rb.co, phys->rb.up, 1.0f, spring_end );
- v3_muladds( spring_end, phys->throw_v, 1.0f, throw_end );
- v3_muladds( spring_end, player.debug_mmcollect_lat, 1.0f, p0 );
- v3_muladds( spring_end, player.debug_mmcollect_vert, 1.0f, p1 );
- vg_line( spring_end, throw_end, VG__RED );
- vg_line( spring_end, p0, VG__GREEN );
- vg_line( spring_end, p1, VG__BLUE );
-#endif
-
- if( player.rewinding )
- return;
-
- if( vg_input_button_down( player.input_reset ) && !menu_enabled() )
- {
- double delta = world.time - world.last_use;
-
- if( (delta <= RESET_MAX_TIME) && (world.last_use != 0.0) )
- {
- player.rewinding = 1;
- player.rewind_sound_wait = 1;
- player.rewind_time = (float)player.rewind_length - 0.0001f;
- player_save_rewind_frame();
- audio_lock();
- audio_play_oneshot( &audio_rewind[0], 1.0f );
- audio_unlock();
-
- /* based on analytical 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.diag_rewind_start = vg.time;
- player.diag_rewind_time = player.rewind_time;
-
- player.is_dead = 0;
- player.death_tick_allowance = 30;
- player_restore_frame();
-
- if( player.controller == k_player_controller_walk )
- {
- player.angles[0] = atan2f( -player.rb.forward[2],
- -player.rb.forward[0] );
- }
-
- player.mdl.shoes[0] = 1;
- player.mdl.shoes[1] = 1;
-
- world_routes_notify_reset();
-
- /* apply 1 frame of movement */
- player_do_motion();
- }
- else
- {
- if( player.is_dead )
- {
- reset_player( 0, NULL );
- }
- else
- {
- /* cant do that */
- audio_lock();
- audio_play_oneshot( &audio_rewind[4], 1.0f );
- audio_unlock();
- }
- }
- }
-
- if( vg_input_button_down( player.input_switch_mode ) && !menu_enabled() )
- {
- audio_lock();
-
-#if 0
- if( phys->controller == k_player_controller_walk )
- {
- phys->controller = k_player_controller_skate;
-
- v3_muladds( phys->rb.v, phys->rb.forward, 0.2f, phys->rb.v );
- audio_play_oneshot( &audio_lands[6], 1.0f );
- }
- else if( phys->controller == k_player_controller_skate )
- {
- phys->controller = k_player_controller_walk;
-
- audio_play_oneshot( &audio_lands[5], 1.0f );
- }
-#endif
-
- audio_unlock();
- }
-
- if( player.controller == k_player_controller_walk )
- player_mouseview();
-}
-
-VG_STATIC void player_update_fixed(void) /* 2 */
-{
- if( player.rewinding )
- return;
-
- if( player.death_tick_allowance )
- player.death_tick_allowance --;
-
- if( player.is_dead )
- {
- player_ragdoll_iter();
- }
- else
- {
- player.rewind_incrementer ++;
-
- if( player.rewind_incrementer > (u32)(0.25/VG_TIMESTEP_FIXED) )
- {
- player_save_rewind_frame();
- }
-
- player_do_motion();
- }
-}
-
-VG_STATIC void player_update_post(void)
-{
-#if 0
- for( int i=0; i<player.prediction_count; i++ )
- {
- struct land_prediction *p = &player.predictions[i];
-
- for( int j=0; j<p->log_length - 1; j ++ )
- vg_line( p->log[j], p->log[j+1], p->colour );
-
- vg_line_cross( p->log[p->log_length-1], p->colour, 0.25f );
-
- v3f p1;
- v3_add( p->log[p->log_length-1], p->n, p1 );
- vg_line( p->log[p->log_length-1], p1, 0xffffffff );
- }
-#endif
-
-#if 0
- if( player.is_dead )
- {
- player_debug_ragdoll();
-
- if( !freecam )
- player_animate_death_cam();
- }
- else
- {
- player_animate();