stuff
authorhgn <hgodden00@gmail.com>
Tue, 8 Nov 2022 04:19:46 +0000 (04:19 +0000)
committerhgn <hgodden00@gmail.com>
Tue, 8 Nov 2022 04:19:46 +0000 (04:19 +0000)
menu.h
player.h
player_animation.h
player_physics.h
skaterift.c
steam.h

diff --git a/menu.h b/menu.h
index d5eb90f058269df735649efe2e6cd162d5841a29..f22789e0b1540c932da5c12c4c4c94e2af6cc996 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -28,6 +28,12 @@ VG_STATIC const char *playermodels[] = { "ch_new", "ch_jordan", "ch_outlaw" };
 
 vg_tex2d tex_menu = { .path = "textures/menu.qoi",.flags = VG_TEXTURE_NEAREST };
 
+VG_STATIC struct input_binding input_menu_h,
+                               input_menu_v,
+                               input_menu_press,
+                               input_menu_back,
+                               input_menu_toggle;
+
 VG_STATIC void menu_btn_paused( int event );
 VG_STATIC void menu_btn_quit( int event );
 VG_STATIC void menu_btn_skater( int event );
@@ -120,6 +126,23 @@ VG_STATIC void steam_on_game_overlay( CallbackMsg_t *msg )
 
 VG_STATIC void menu_init(void)
 {
+   vg_create_unnamed_input( &input_menu_h, k_input_type_axis );
+   vg_create_unnamed_input( &input_menu_v, k_input_type_axis );
+   vg_create_unnamed_input( &input_menu_back, k_input_type_button );
+   vg_create_unnamed_input( &input_menu_press, k_input_type_button );
+   vg_create_unnamed_input( &input_menu_toggle, k_input_type_button );
+
+   vg_apply_bind_str( &input_menu_h, "", "gp-ls-h" );
+   vg_apply_bind_str( &input_menu_h, "+", "d" );
+   vg_apply_bind_str( &input_menu_h, "-", "a" );
+   vg_apply_bind_str( &input_menu_v, "", "gp-ls-v" );
+   vg_apply_bind_str( &input_menu_v, "+", "w" );
+   vg_apply_bind_str( &input_menu_v, "-", "s" );
+   vg_apply_bind_str( &input_menu_press, "", "gp-a" );
+   vg_apply_bind_str( &input_menu_back, "", "gp-b" );
+   vg_apply_bind_str( &input_menu_toggle, "", "\2escape" );
+   vg_apply_bind_str( &input_menu_toggle, "", "\2gp-menu" );
+
    vg_linear_clear( vg_mem.scratch );
 
    mdl_open( &menu_model, "models/rs_menu.mdl" );
@@ -154,7 +177,7 @@ VG_STATIC void menu_run_directional(void)
 {
    struct menu_button *btn = &menu_buttons[ menu_loc ];
 
-   if( vg_get_button_down( "jump" ) )
+   if( vg_input_button_down( &input_menu_press ) )
    {
       if( btn->fn_press )
       {
@@ -169,7 +192,8 @@ VG_STATIC void menu_run_directional(void)
 
    if( menu_input_cooldown <= 0.0f )
    {
-      v2f dir = { vg_get_axis( "lookh" ), vg_get_axis( "lookv" ) };
+      v2f dir = { input_menu_h.axis.value,
+                  input_menu_v.axis.value };
 
       if( v2_length2( dir ) > 0.8f*0.8f )
       {
@@ -200,7 +224,7 @@ VG_STATIC void menu_run_directional(void)
 
 VG_STATIC int menu_page_should_backout(void)
 {
-   return vg_get_button_down( "break" );
+   return vg_input_button_down( &input_menu_back );
 }
 
 VG_STATIC void menu_close(void)
@@ -247,7 +271,7 @@ VG_STATIC void menu_page_quit(void)
 
 VG_STATIC void menu_page_skater(void)
 {
-   float h = vg_get_axis( "lookh" );
+   float h = input_menu_h.axis.value;
    menu_fov_target = 97.0f;
 
    if( menu_page_should_backout() )
@@ -290,7 +314,13 @@ VG_STATIC void menu_page_skater(void)
 
 VG_STATIC void menu_update(void)
 {
-   if( vg_get_button_down( "menu" ) )
+   vg_input_update( 1, &input_menu_h );
+   vg_input_update( 1, &input_menu_v );
+   vg_input_update( 1, &input_menu_back );
+   vg_input_update( 1, &input_menu_press );
+   vg_input_update( 1, &input_menu_toggle );
+
+   if( vg_input_button_down( &input_menu_toggle ) )
    {
       if( cl_menu )
       {
index 61a1391261e758f913c77fe5b46bb8b0f45ebaab..1edbc6ba08981fce86b63c8904294429ac6e95e8 100644 (file)
--- a/player.h
+++ b/player.h
@@ -97,6 +97,7 @@ VG_STATIC struct gplayer
                         *input_js2v,
                         *input_jump,
                         *input_push,
+                        *input_walk,
                         *input_walkh,
                         *input_walkv,
                         *input_switch_mode,
@@ -226,7 +227,8 @@ VG_STATIC void player_init(void)                                            /* 1
    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_axis_norm );
+   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 );
@@ -256,8 +258,11 @@ VG_STATIC void player_init(void)                                            /* 1
       "bind jump space",
       "bind jump gp-a",
 
-      "bind  push gp-lt",
-      "bind +push w",
+      "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",
@@ -374,6 +379,37 @@ VG_STATIC void player_mouseview(void)
       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 );
 }
 
index 88fe6690e8039ace9ae538e159c729a36de6487e..9d2c801fd7309340fded8d2aef52dc4f739568ed 100644 (file)
@@ -20,7 +20,8 @@ VG_STATIC void player_animate_offboard(void)
 
       player.ffly  = vg_lerpf( player.ffly, fly, rate*vg.time_delta );
       player.frun  = vg_lerpf( player.frun,
-                               vg_get_axis("walk/push")*0.5f+0.5f, 
+                               player.walk *
+                               (1.0f + player.input_walk->button.value*0.5f),
                                2.0f*vg.time_delta );
    }
 
@@ -224,7 +225,7 @@ VG_STATIC void player_animate(void)
    
    mdl_keyframe air_pose[32];
    {
-      float target = -vg_get_axis("lookh");
+      float target = -player.input_js1h->axis.value;
       player.fairdir = vg_lerpf( player.fairdir, target, 2.4f*vg.time_delta );
       
       float air_frame = (player.fairdir*0.5f+0.5f) * (15.0f/30.0f);
@@ -360,11 +361,13 @@ VG_STATIC void player_animate_camera(void)
    else
    {
       float speed = vg.time_delta * k_look_speed;
+#if 0
       player.angles[0] += vg_get_axis( "lookh" ) * speed;
       player.angles[1] += vg_get_axis( "lookv" ) * speed;
       
       player.angles[1] = vg_clampf( player.angles[1], 
                                        -k_pitch_limit, k_pitch_limit );
+#endif
       
       float s =  sinf(player.angles[0]) * 0.2f,
             c = -cosf(player.angles[0]) * 0.2f;
index 52e4c3080f82aa4dcae6a9e5e4d6a182942d2c86..20ce7f5d2877aca286dd45a70d0ea0fe6a836356 100644 (file)
@@ -161,7 +161,7 @@ VG_STATIC void player_physics_control(void)
    }
 
    static int push_thresh_last = 0;
-   float push = player.input_push->axis.value;
+   float push = player.input_push->button.value;
    int push_thresh = push>0.15f? 1: 0;
    
    if( push_thresh && !push_thresh_last )
@@ -401,10 +401,14 @@ VG_STATIC void player_walk_physics(void)
                    player.input_walkv->axis.value };
       
       if( v2_length2(walk) > 0.001f )
-         v2_normalize( walk );
+         v2_normalize_clamp( walk );
 
-      v2_muls( walk, vg_maxf( player.input_push->axis.value, 0.5f ) *
-                        k_walkspeed * VG_TIMESTEP_FIXED, walk );
+      player.walk = v2_length( walk );
+
+      if( player.input_walk->button.value )
+         v2_muls( walk, 0.5f, walk );
+
+      v2_muls( walk, k_walkspeed * VG_TIMESTEP_FIXED, walk );
 
       v3f walk_apply;
       v3_zero( walk_apply );
@@ -829,6 +833,9 @@ VG_STATIC void player_freecam(void)
    m3x3_mulv( camera_mtx, sidedir, sidedir );
    
    static v3f move_vel = { 0.0f, 0.0f, 0.0f };
+
+   /* TODO */
+#if 0
    if( vg_get_button( "forward" ) )
       v3_muladds( move_vel, lookdir, VG_TIMESTEP_FIXED * movespeed, move_vel );
    if( vg_get_button( "back" ) )
@@ -837,6 +844,7 @@ VG_STATIC void player_freecam(void)
       v3_muladds( move_vel, sidedir, VG_TIMESTEP_FIXED *-movespeed, move_vel );
    if( vg_get_button( "right" ) )
       v3_muladds( move_vel, sidedir, VG_TIMESTEP_FIXED * movespeed, move_vel );
+#endif
 
    v3_muls( move_vel, 0.7f, move_vel );
    v3_add( move_vel, player.camera_pos, player.camera_pos );
index 7c094b0efeb0823e8a2916878b80bbf0da349f3c..21a7981793ba6ccd6149de3a5aaaccb483ecdf0d 100644 (file)
@@ -157,7 +157,7 @@ VG_STATIC void render_main_game(void)
 
    float fov_target = 108.0f;
    if( player.phys.on_board )
-      fov_target = 125.0f;
+      fov_target = 118.0f;
 
    if( cl_menu )
       fov_target = menu_fov_target;
diff --git a/steam.h b/steam.h
index a92c3252e66b1b503b993ecaf1afd32db88798aa..a417622c5a17e246a0fe4e456924dd38dbab448a 100644 (file)
--- a/steam.h
+++ b/steam.h
@@ -240,6 +240,29 @@ VG_STATIC int steam_init(void)
                .function = steam_set_achievemnt_test
        });
 
+   vg_info( "Checking controller type\n" );
+
+   ISteamInput *hInput = SteamAPI_SteamInput();
+   SteamAPI_ISteamInput_Init( hInput, 0 );
+   SteamAPI_ISteamInput_RunFrame( hInput, 0 );
+   InputHandle_t joy0 = SteamAPI_ISteamInput_GetControllerForGamepadIndex( 
+                           hInput, 0 );
+
+   if( joy0 != 0 )
+   {
+      ESteamInputType type = SteamAPI_ISteamInput_GetInputTypeForHandle(
+                           hInput, joy0 );
+
+      if( type == k_ESteamInputType_SteamController )
+         vg.gamepad_use_trackpad_look = 1;
+
+      vg_info( "Type: %d\n", type );
+   }
+   else
+   {
+      vg_warn( "none found\n" );
+   }
+   
 #endif
 
    /* TODO: On username update callback */