modals
[carveJwlIkooP6JGAAIwe30JlM.git] / input.h
diff --git a/input.h b/input.h
index 6f19634f606e4dde10fd52754dbcaf9d3804cd66..6548eef2c9d163d00a7c99a4b0ef60fcd3b8aef2 100644 (file)
--- a/input.h
+++ b/input.h
@@ -47,6 +47,7 @@ struct {
    float axis_states[ k_sraxis_max ][2];
    v2f joystick_states[ k_srjoystick_max ][2];
    u8 button_states[ k_srbind_max ][2];
+   u32 ignore_input_frames;
 }
 static srinput;
 
@@ -113,7 +114,7 @@ static const char *button_display_string( enum sr_bind button )
    };
 
    const char *keyboard_table[ k_srbind_max ] = {
-    [k_srbind_jump]   = KEYBOARD_GLYPH( "A" ),
+    [k_srbind_jump]   = "\xa1",
     [k_srbind_push]   = KEYBOARD_GLYPH( "W" ),
     [k_srbind_trick0] = "\x99",
     [k_srbind_trick1] = "\x9a",
@@ -156,30 +157,34 @@ static const char *axis_display_string( enum sr_axis axis )
       return keyboard_table[ axis ];
 }
 
-static const char *joystick_display_string( enum sr_joystick joystick )
+static const char *joystick_display_string( enum sr_joystick joystick, 
+                                            u32 axis )
 {
-   const char *controller_table[ k_srjoystick_max ] = {
-    [k_srjoystick_steer] = "\x88",
-    [k_srjoystick_grab]  = "\x8e",
-    [k_srjoystick_look]  = "\x8e"
+   const char *controller_table[ k_srjoystick_max ][3] = {
+    [k_srjoystick_steer] = {"\x88","\x89","\x8a"},
+    [k_srjoystick_grab]  = {"\x8c","\x8d","\x8e"},
+    [k_srjoystick_look]  = {"\x8c","\x8d","\x8e"}
    };
 
-   const char *keyboard_table[ k_srjoystick_max ] = {
-    [k_srjoystick_steer] = KEYBOARD_GLYPH( "\x93" )KEYBOARD_GLYPH( "\x95" ),
-    [k_srjoystick_grab]  = "\xa4",
-    [k_srjoystick_look]  = "\xa4"
+   const char *keyboard_table[ k_srjoystick_max ][3] = {
+    [k_srjoystick_steer] = {KEYBOARD_GLYPH("A")KEYBOARD_GLYPH("D"), /*h*/
+                            KEYBOARD_GLYPH("W")KEYBOARD_GLYPH("S"), /*v*/
+                              
+                            KEYBOARD_GLYPH("A")KEYBOARD_GLYPH("D") /*hv*/
+                            KEYBOARD_GLYPH("W")KEYBOARD_GLYPH("S"), },
+    [k_srjoystick_grab]  = {"\xa4","\xa4","\xa4"},
+    [k_srjoystick_look]  = {"\xa4","\xa4","\xa4"}
    };
 
    if( vg_input.display_input_method == k_input_method_controller )
-      return controller_table[ joystick ];
-   else
-      return keyboard_table[ joystick ];
+      return controller_table[ joystick ][axis];
+   else  return keyboard_table[ joystick ][axis];
 }
 
 static int buttons_filter_fixed(void)
 {
-   if( vg_console.enabled )
-      return 1;
+   if( srinput.ignore_input_frames ) return 1;
+   if( vg_ui.wants_mouse ) return 1;
 
    if( vg.engine_stage == k_engine_stage_update_fixed )
       if( vg.fixed_iterations > 0 )
@@ -191,8 +196,7 @@ static int buttons_filter_fixed(void)
 /* Rising edge of button */
 static int button_down( enum sr_bind button )
 {
-   if( buttons_filter_fixed() )
-      return 0;
+   if( buttons_filter_fixed() ) return 0;
    
    if(  srinput.button_states[ button ][0] && 
        !srinput.button_states[ button ][1] )
@@ -204,8 +208,7 @@ static int button_down( enum sr_bind button )
 /* Falling edge of button */
 static int button_up( enum sr_bind button )
 {
-   if( buttons_filter_fixed() )
-      return 0;
+   if( buttons_filter_fixed() ) return 0;
    
    if( !srinput.button_states[ button ][0] && 
         srinput.button_states[ button ][1] )
@@ -217,15 +220,13 @@ static int button_up( enum sr_bind button )
 /* State of button */
 static int button_press( enum sr_bind button )
 {
-   if( vg_console.enabled )
-      return 0;
-
+   if( vg_ui.wants_mouse ) return 0;
    return srinput.button_states[ button ][0];
 }
 
 static void joystick_state( enum sr_joystick joystick, v2f state )
 {
-   if( vg_console.enabled )
+   if( vg_ui.wants_mouse )
       v2_zero( state );
    else
       v2_copy( srinput.joystick_states[ joystick ][0], state );
@@ -233,7 +234,7 @@ static void joystick_state( enum sr_joystick joystick, v2f state )
 
 static float axis_state( enum sr_axis axis )
 {
-   if( vg_console.enabled ) return 0.0f;
+   if( vg_ui.wants_mouse ) return 0.0f;
    else return srinput.axis_states[axis][0];
 }
 
@@ -244,6 +245,9 @@ static void setbtn( enum sr_bind button, u8 value )
 
 static void skaterift_preupdate_inputs(void)
 {
+   if( srinput.ignore_input_frames )
+      srinput.ignore_input_frames --;
+
    for( u32 i=0; i<k_srbind_max; i++ ){
       srinput.button_states[i][1] = srinput.button_states[i][0];
       srinput.button_states[i][0] = 0;
@@ -305,7 +309,7 @@ static void skaterift_preupdate_inputs(void)
    if( vg_getkey( SDLK_RIGHT ) )
       srinput.axis_states[ k_sraxis_mbrowse_h ][0] += 1.0f;
 
-   if( vg_input.active_controller_index != -1 ){
+   if( vg_input.active_controller_index >= 0 ){
       struct vg_controller *controller = 
          &vg_input.controllers[vg_input.active_controller_index];
 
@@ -324,7 +328,8 @@ static void skaterift_preupdate_inputs(void)
       setbtn( k_srbind_mdown,  buttons[ SDL_CONTROLLER_BUTTON_DPAD_DOWN ] );
       setbtn( k_srbind_mback,  buttons[ SDL_CONTROLLER_BUTTON_B ] );
       setbtn( k_srbind_maccept,buttons[ SDL_CONTROLLER_BUTTON_A ] );
-      setbtn( k_srbind_mopen,  buttons[ SDL_CONTROLLER_BUTTON_GUIDE ] );
+      setbtn( k_srbind_mopen,  buttons[ SDL_CONTROLLER_BUTTON_START ] );
+      setbtn( k_srbind_mback,  buttons[ SDL_CONTROLLER_BUTTON_START ] );
 
       float *axis = controller->axises;
 
@@ -351,8 +356,8 @@ static void skaterift_preupdate_inputs(void)
 
       if( lh >  sensitivity ) setbtn( k_srbind_mright, 1 );
       if( lh < -sensitivity ) setbtn( k_srbind_mleft, 1 );
-      if( lv >  sensitivity ) setbtn( k_srbind_mup, 1 );
-      if( lv < -sensitivity ) setbtn( k_srbind_mdown, 1 );
+      if( lv >  sensitivity ) setbtn( k_srbind_mdown, 1 );
+      if( lv < -sensitivity ) setbtn( k_srbind_mup, 1 );
    }
 
    srinput.axis_states[ k_sraxis_grab ][0] =