-#include "player_animation.h"
-#include "player_audio.h"
-
-/*
- * -----------------------------------------------------------------------------
- * Events
- * -----------------------------------------------------------------------------
- */
-
-VG_STATIC void player_init(void) /* 1 */
-{
- 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++ )
- execute_console_input(default_cfg[i]);
-
- 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 = 0
- });
-
- 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();
-
- /* controls */
-
-}
-
-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 );
- }
- }
-}
-
-/*
- * Free camera movement
- */
-VG_STATIC void player_mouseview(void)
-{
- if( ui_want_mouse() )
- return;
-
- v2_muladds( player.angles, vg.mouse_delta, 0.0025f, player.angles );
-
- if( vg.gamepad_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 );
-}