-#include "player_animation.h"
-#include "player_audio.h"
-
-/*
- * -----------------------------------------------------------------------------
- * Events
- * -----------------------------------------------------------------------------
- */
-
-VG_STATIC void player_init(void) /* 1 */
-{
- rb_init( &player.phys.rb );
- rb_init( &player.collide_front );
- rb_init( &player.collide_back );
-
- vg_convar_push( (struct vg_convar){
- .name = "cl_playermdl_id",
- .data = &cl_playermdl_id,
- .data_type = k_convar_dtype_i32,
- .opt_i32 = { .min=0, .max=2, .clamp=1 },
- .persistent = 1
- });
-
- vg_convar_push( (struct vg_convar){
- .name = "walk_speed",
- .data = &k_walkspeed,
- .data_type = k_convar_dtype_f32,
- .opt_f32 = { .clamp = 0 },
- .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 = "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_function_push( (struct vg_cmd){
- .name = "reset",
- .function = reset_player
- });
-
- 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 );
- }
- }
-}
-
-/* Deal with input etc */
-VG_STATIC void player_update_pre(void)
-{
- struct player_phys *phys = &player.phys;
-
- if( player.rewinding )
- {
- return;
- }
-
- if( vg_get_button_down( "reset" ) )
- {
- if( player.is_dead )
- {
- reset_player( 0, NULL );
- audio_lock();
- audio_play_oneshot( &audio_ui[0], 1.0f );
- audio_unlock();
- }
- else
- {
- 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( !phys->on_board )
- {
- player.angles[0] = atan2f( -phys->rb.forward[2],
- -phys->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
- {
- /* cant do that */
- audio_lock();
- audio_play_oneshot( &audio_rewind[4], 1.0f );
- audio_unlock();
- }
- }
- }
-
- if( vg_get_button_down( "switchmode" ) )
- {
- phys->on_board ^= 0x1;
-
- audio_lock();
- if( phys->on_board )
- {
- v3_muladds( phys->rb.v, phys->rb.forward, 0.2f, phys->rb.v );
- audio_play_oneshot( &audio_lands[6], 1.0f );
- }
- else
- {
- audio_play_oneshot( &audio_lands[5], 1.0f );
- }
-
- audio_unlock();
- }
-}
-
-VG_STATIC void player_update_fixed(void) /* 2 */
-{
- if( player.rewinding )
- return;
-
- if( player.death_tick_allowance )
- player.death_tick_allowance --;
-
- struct player_phys *phys = &player.phys;
-
- 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();
- }