# HG changeset patch # User koda # Date 1256553560 0 # Node ID c6597b65caea97e9b56d7b8e5ca95212b0984c0b # Parent e7e87e3c67dbf2ffffda5978cd727424e6f6f707 other controls implementation + sdlh revisited (once again) diff -r e7e87e3c67db -r c6597b65caea hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Sun Oct 25 23:52:36 2009 +0000 +++ b/hedgewars/SDLh.pas Mon Oct 26 10:39:20 2009 +0000 @@ -68,7 +68,42 @@ SDL_INIT_JOYSTICK = $00000200; SDL_APPINPUTFOCUS = 2; - + SDL_BUTTON_WHEELDUP = 4; + SDL_BUTTON_WHEELDOWN = 5; + +{*begin sdl_event binding*} + SDL_NOEVENT = 0; + SDL_KEYDOWN = 2; + SDL_KEYUP = 3; +{$IFDEF SDL13} + SDL_WINDOWEVENT = 1; + SDL_TEXTINPUT = 4; + SDL_TEXTEDITING = 5; + SDL_MOUSEMOTION = 6; + SDL_MOUSEBUTTONDOWN = 7; + SDL_MOUSEBUTTONUP = 8; + SDL_MOUSEWHEEL = 9; + SDL_JOYAXISMOTION = 10; + SDL_JOYBALLMOTION = 11; + SDL_JOYHATMOTION = 12; + SDL_JOYBUTTONDOWN = 13; + SDL_JOYBUTTONUP = 14; + SDL_QUITEV = 15; +{$ELSE} + SDL_ACTIVEEVENT = 1; + SDL_MOUSEMOTION = 4; + SDL_MOUSEBUTTONDOWN = 5; + SDL_MOUSEBUTTONUP = 6; + SDL_JOYAXISMOTION = 7; + SDL_JOYBALLMOTION = 8; + SDL_JOYHATMOTION = 9; + SDL_JOYBUTTONDOWN = 10; + SDL_JOYBUTTONUP = 11; + SDL_QUITEV = 12; + SDL_VIDEORESIZE = 16; // TODO: outdated? no longer in SDL 1.3? +{$ENDIF} +{*end sdl_event binding*} + {$IFDEF SDL13} SDL_ASYNCBLIT = $08000000; SDL_ANYFORMAT = $10000000; @@ -95,39 +130,6 @@ SDL_RESIZABLE = $00000010; {$ENDIF} -{*begin sdl_event binding*} - SDL_NOEVENT = 0; - SDL_KEYDOWN = 2; - SDL_KEYUP = 3; - SDL_VIDEORESIZE = 16; // TODO: outdated? no longer in SDL 1.3? - -{$IFDEF SDL13} - SDL_WINDOWEVENT = 1; - SDL_TEXTINPUT = 4; - SDL_TEXTEDITING = 5; - SDL_MOUSEMOTION = 6; - SDL_MOUSEBUTTONDOWN = 7; - SDL_MOUSEBUTTONUP = 8; - SDL_MOUSEWHEEL = 9; //different handling, should create SDL_MouseWheelEvent type - SDL_JOYAXIS = 10; - SDL_JOYHAT = 12; - SDL_JOYBUTTONDOWN = 13; - SDL_JOYBUTTONUP = 14; - SDL_QUITEV = 15; -{$ELSE} - SDL_ACTIVEEVENT = 1; - SDL_MOUSEBUTTONDOWN = 5; - SDL_MOUSEBUTTONUP = 6; - SDL_BUTTON_WHEELDUP = 4; - SDL_BUTTON_WHEELDOWN = 5; - SDL_JOYAXIS = 7; - SDL_JOYHAT = 9; - SDL_JOYBUTTONDOWN = 10; - SDL_JOYBUTTONUP = 11; - SDL_QUITEV = 12; -{$ENDIF} -{*end sdl_event binding*} - {$IFDEF ENDIAN_LITTLE} RMask = $000000FF; @@ -242,14 +244,45 @@ unicode: Word; end; + +{* SDL_event type definition *} + +{$IFDEF SDL13} + TSDL_WindowID = LongInt; + + TSDL_WindowEvent = record +{$ELSE} TSDL_ActiveEvent = record +{$ENDIF} type_: byte; gain: byte; state: byte; +{$IFDEF SDL13} + windowID: TSDL_WindowID; + data1, data2: LongInt; +{$ENDIF} end; +//SDL_TextEditingEvent + SDL_TextInputEvent for sdl13 + + TSDL_MouseMotionEvent = record + type_: byte; + which: byte; + state: byte; +{$IFDEF SDL13} + x, y, xrel, yrel : LongInt; + pressure, pressure_max, pressure_min, + rotation, tilt, cursor: LongInt; +{$ELSE} + x, y, xrel, yrel : word; +{$ENDIF} + end; + TSDL_KeyboardEvent = record type_: Byte; +{$IFDEF SDL13} + windowID: TSDL_WindowID; +{$ENDIF} which: Byte; state: Byte; keysym: TSDL_KeySym; @@ -260,9 +293,115 @@ which, button, state: byte; +{$IFDEF SDL13} + x, y: LongInt; +{$ELSE} x, y: word; +{$ENDIF} end; +{$IFDEF SDL13} + TSDL_MouseWheelEvent = record + type_: Byte; + windowID: TSDL_WindowID; + which: Byte; + x, y: LongInt; + end; +{$ENDIF} + + TSDL_JoyAxisEvent = record + type_: Byte; + which: Byte; + axis: Byte; +{$IFDEF SDL13} + value: LongInt; +{$ELSE} + value: word; +{$ENDIF} + end; + + TSDL_JoyBallEvent = record + type_: Byte; + which: Byte; + ball: Byte; +{$IFDEF SDL13} + xrel, yrel: LongInt; +{$ELSE} + xrel, yrel: word; +{$ENDIF} + end; + + TSDL_JoyHatEvent = record + type_: Byte; + which: Byte; + hat: Byte; + value: Byte; + end; + + TSDL_JoyButtonEvent = record + type_: Byte; + which: Byte; + button: Byte; + state: Byte; + end; + + TSDL_QuitEvent = record + type_: Byte; + end; + +{$IFNDEF SDL13} + TSDL_ResizeEvent = record + type_: Byte; + w, h: LongInt; + end; +{$ENDIF} + + PSDL_Event = ^TSDL_Event; + TSDL_Event = record + case Byte of + SDL_NOEVENT: (type_: byte); +{$IFDEF SDL13} + SDL_WINDOWEVENT: (active: TSDL_WindowEvent); + SDL_KEYDOWN, + SDL_KEYUP: (key: TSDL_KeyboardEvent); + SDL_TEXTEDITING, + SDL_TEXTINPUT: (txtin: byte); + SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent); + SDL_MOUSEBUTTONDOWN, + SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent); + SDL_MOUSEWHEEL: (wheel: TSDL_MouseWheelEvent); + SDL_JOYAXISMOTION: (jaxis: TSDL_JoyAxisEvent); + SDL_JOYHATMOTION: (jhat: TSDL_JoyHatEvent); + SDL_JOYBALLMOTION: (jball: TSDL_JoyBallEvent); + SDL_JOYBUTTONDOWN, + SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent); + SDL_QUITEV: (quit: TSDL_QuitEvent); +{$ELSE} + SDL_ACTIVEEVENT: (active: TSDL_ActiveEvent); + SDL_KEYDOWN, + SDL_KEYUP: (key: TSDL_KeyboardEvent); + SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent); + SDL_MOUSEBUTTONDOWN, + SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent); + SDL_JOYAXISMOTION: (jaxis: TSDL_JoyAxisEvent); + SDL_JOYHATMOTION: (jhat: TSDL_JoyHatEvent); + SDL_JOYBALLMOTION: (jball: TSDL_JoyBallEvent); + SDL_JOYBUTTONDOWN, + SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent); + SDL_QUITEV: (quit: TSDL_QuitEvent); + //SDL_SYSWMEVENT,SDL_EVENT_RESERVEDA,SDL_EVENT_RESERVEDB + //SDL_VIDEORESIZE: (resize: TSDL_ResizeEvent); +{$ENDIF} + end; + + PByteArray = ^TByteArray; + TByteArray = array[0..65535] of Byte; + PLongWordArray = ^TLongWordArray; + TLongWordArray = array[0..16383] of LongWord; + + PSDL_Thread = Pointer; + PSDL_mutex = Pointer; + TSDL_GLattr = ( SDL_GL_RED_SIZE, SDL_GL_GREEN_SIZE, @@ -284,7 +423,6 @@ SDL_GL_CONTEXT_MAJOR_VERSION, SDL_GL_CONTEXT_MINOR_VERSION ); - {$IFDEF SDL13} TSDL_ArrayByteOrder = ( // array component order, low byte -> high byte @@ -296,84 +434,8 @@ SDL_ARRAYORDER_BGRA, SDL_ARRAYORDER_ABGR ); - - TSDL_MouseMotionEvent = record - type_: byte; - which: byte; - state: byte; - x : LongInt; - y : LongInt; - xrel : LongInt; - yrel : LongInt; - end; {$ENDIF} - TSDL_QuitEvent = record - type_: Byte; - end; - TSDL_ResizeEvent = record - type_: Byte; - w, h: LongInt; - end; - - TSDL_JoyAxisEvent = record - type_: Byte; - which: Byte; - axis: Byte; - value: LongInt; - end; - - TSDL_JoyHatEvent = record - type_: Byte; - which: Byte; - hat: Byte; - value: Byte; - end; - - TSDL_JoyButtonEvent = record - type_: Byte; - which: Byte; - button: Byte; - state: Byte; - end; - - PSDL_Event = ^TSDL_Event; - TSDL_Event = record - case Byte of -{$IFDEF SDL13} - //doublecheck the type of WINDOWEVENT TEXTINPUT - SDL_NOEVENT: (type_: byte); - SDL_WINDOWEVENT: (active: TSDL_ActiveEvent); - SDL_KEYDOWN, - SDL_KEYUP: (key: TSDL_KeyboardEvent); - SDL_TEXTINPUT: (txtin: byte); - SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent); - SDL_MOUSEBUTTONDOWN, - SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent); -{$ELSE} - SDL_NOEVENT: (type_: byte); - SDL_ACTIVEEVENT: (active: TSDL_ActiveEvent); - SDL_KEYDOWN, - SDL_KEYUP: (key: TSDL_KeyboardEvent); - SDL_QUITEV: (quit: TSDL_QuitEvent); - SDL_VIDEORESIZE: (resize: TSDL_ResizeEvent); - SDL_MOUSEBUTTONDOWN, - SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent); -{$ENDIF} - SDL_JOYAXIS: (jaxis: TSDL_JoyAxisEvent); - SDL_JOYHAT: (jhat: TSDL_JoyHatEvent); - SDL_JOYBUTTONDOWN, - SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent); - end; - - PByteArray = ^TByteArray; - TByteArray = array[0..65535] of Byte; - PLongWordArray = ^TLongWordArray; - TLongWordArray = array[0..16383] of LongWord; - - PSDL_Thread = Pointer; - PSDL_mutex = Pointer; - function SDL_Init(flags: Longword): LongInt; cdecl; external SDLLibName; procedure SDL_Quit; cdecl; external SDLLibName; function SDL_VideoDriverName(var namebuf; maxlen: LongInt): PChar; cdecl; external SDLLibName; @@ -453,35 +515,36 @@ // Joystick/Controller support -type PSDLJoystick = ^TSDLJoystick; - TSDLJoystick = record +type PSDL_Joystick = ^TSDL_Joystick; + TSDL_Joystick = record end; -function SDL_NumJoysticks: LongInt; cdecl; external SDLLibName; -function SDL_JoystickName(idx: LongInt): PChar; cdecl; external SDLLibName; -function SDL_JoystickOpen(idx: LongInt): PSDLJoystick; cdecl; external SDLLibName; -function SDL_JoystickOpened(idx: LongInt): LongInt; cdecl; external SDLLibName; -function SDL_JoystickIndex(joy: PSDLJoystick): LongInt; cdecl; external SDLLibName; -function SDL_JoystickNumAxes(joy: PSDLJoystick): LongInt; cdecl; external SDLLibName; -function SDL_JoystickNumBalls(joy: PSDLJoystick): LongInt; cdecl; external SDLLibName; -function SDL_JoystickNumHats(joy: PSDLJoystick): LongInt; cdecl; external SDLLibName; -function SDL_JoystickNumButtons(joy: PSDLJoystick): LongInt; cdecl; external SDLLibName; +const SDL_HAT_CENTERED = $00; + SDL_HAT_UP = $01; + SDL_HAT_RIGHT = $02; + SDL_HAT_DOWN = $04; + SDL_HAT_LEFT = $08; + SDL_HAT_RIGHTUP = SDL_HAT_RIGHT or SDL_HAT_UP; + SDL_HAT_RIGHTDOWN = SDL_HAT_RIGHT or SDL_HAT_DOWN; + SDL_HAT_LEFTUP = SDL_HAT_LEFT or SDL_HAT_UP; + SDL_HAT_LEFTDOWN = SDL_HAT_LEFT or SDL_HAT_DOWN; + +function SDL_NumJoysticks: LongInt; cdecl; external SDLLibName; +function SDL_JoystickName(idx: LongInt): PChar; cdecl; external SDLLibName; +function SDL_JoystickOpen(idx: LongInt): PSDL_Joystick; cdecl; external SDLLibName; +function SDL_JoystickOpened(idx: LongInt): LongInt; cdecl; external SDLLibName; +function SDL_JoystickIndex(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName; +function SDL_JoystickNumAxes(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName; +function SDL_JoystickNumBalls(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName; +function SDL_JoystickNumHats(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName; +function SDL_JoystickNumButtons(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName; procedure SDL_JoystickUpdate; cdecl; external SDLLibName; -function SDL_JoystickEventState(state: LongInt): LongInt; cdecl; external SDLLibName; -function SDL_JoystickGetAxis(joy: PSDLJoystick; axis: LongInt): Word; cdecl; external SDLLibName; -const SDL_HAT_CENTERED = $00; - SDL_HAT_UP = $01; - SDL_HAT_RIGHT = $02; - SDL_HAT_DOWN = $04; - SDL_HAT_LEFT = $08; - SDL_HAT_RIGHTUP = SDL_HAT_RIGHT or SDL_HAT_UP; - SDL_HAT_RIGHTDOWN = SDL_HAT_RIGHT or SDL_HAT_DOWN; - SDL_HAT_LEFTUP = SDL_HAT_LEFT or SDL_HAT_UP; - SDL_HAT_LEFTDOWN = SDL_HAT_LEFT or SDL_HAT_DOWN; -function SDL_JoystickGetBall(joy: PSDLJoystick; ball: LongInt; dx: PInteger; dy: PInteger): Word; cdecl; external SDLLibName; -function SDL_JoystickGetHat(joy: PSDLJoystick; hat: LongInt): Byte; cdecl; external SDLLibName; -function SDL_JoystickGetButton(joy: PSDLJoystick; button: LongInt): Byte; cdecl; external SDLLibName; -procedure SDL_JoystickClose(joy: PSDLJoystick); cdecl; external SDLLibName; +function SDL_JoystickEventState(state: LongInt): LongInt; cdecl; external SDLLibName; +function SDL_JoystickGetAxis(joy: PSDL_Joystick; axis: LongInt): LongInt; cdecl; external SDLLibName; +function SDL_JoystickGetBall(joy: PSDL_Joystick; ball: LongInt; dx: PInteger; dy: PInteger): Word; cdecl; external SDLLibName; +function SDL_JoystickGetHat(joy: PSDL_Joystick; hat: LongInt): Byte; cdecl; external SDLLibName; +function SDL_JoystickGetButton(joy: PSDL_Joystick; button: LongInt): Byte; cdecl; external SDLLibName; +procedure SDL_JoystickClose(joy: PSDL_Joystick); cdecl; external SDLLibName; (* TTF *) diff -r e7e87e3c67db -r c6597b65caea hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Sun Oct 25 23:52:36 2009 +0000 +++ b/hedgewars/hwengine.pas Mon Oct 26 10:39:20 2009 +0000 @@ -163,20 +163,21 @@ var PrevTime, CurrTime: Longword; event: TSDL_Event; -{$IFDEF IPHONEOS} +{$IFDEF TOUCHINPUT} type TDirection = (nodir, left, right); -var x, y: LongInt; - dx, dy, mouseState: LongInt; +var x, y, dx, dy, mouseState: LongInt; + tiltValue: LongInt; direction: TDirection = nodir; - havetrace: boolean = false; + movedbybuttons: boolean = false; {$ENDIF} begin PrevTime:= SDL_GetTicks; repeat while SDL_PollEvent(@event) <> 0 do {$IFDEF TOUCHINPUT} -if direction <> nodir then +if (direction <> nodir) and (movedbybuttons = true) then begin + AddFileLog('* Hedgehog moving *'); uKeys.isWalking:= true; if direction = left then uKeys.leftKey:= true else if direction = right then uKeys.rightKey:= true; @@ -243,17 +244,15 @@ if (x <= 50) and (y <= 50) then begin AddFileLog('Left Arrow Key DOWN -- x: ' + inttostr(x) + ' y: ' + inttostr(y)); - // uKeys.leftKey:= true; - // uKeys.isWalking:= true; direction:= left; + movedbybuttons:= true; end; if (x > 270) and (y <= 50) then begin AddFileLog('Right Arrow Key DOWN -- x: ' + inttostr(x) + ' y: ' + inttostr(y)); - // uKeys.rightKey:= true; - // uKeys.isWalking:= true; direction:= right; + movedbybuttons:= true; end; {* high jump *} @@ -303,40 +302,46 @@ AddFileLog('Arrow Keys UP | Space UP -- x: ' + inttostr(x) + ' y: ' + inttostr(y) ); {$ENDIF} direction:= nodir; + movedbybuttons:= false; uKeys.isAttacking:= false; - end; + end; {$ENDIF} {$IFDEF IPHONEOS} -{* might be masked by above events - SDL_JOYAXIS: begin + SDL_JOYAXISMOTION: begin {* axis 0 = left and right; axis 1 = up and down; axis 2 = back and forth; *} - if (event.jaxis.axis = 0) and (CurrentTeam <> nil) then + +{$IFDEF DEBUGFILE} + AddFileLog('********************************************* accelerometer'); +{$ENDIF} + + tiltValue:= SDL_JoystickGetAxis(uKeys.theJoystick, 0); + + if (CurrentTeam <> nil) then begin - if event.jaxis.value > 1500 then + AddFileLog('Joystick: 0; Axis: 0; Value: ' + inttostr(tiltValue)); + + if tiltValue > 1500 then begin - direction:= right; + uKeys.rightKey:= true; + uKeys.isWalking:= true; end else - if event.jaxis.value <= -1500 then + if tiltValue <= -1500 then begin - direction:= left + uKeys.leftKey:= true; + uKeys.isWalking:= true; end else - if (event.jaxis.value > -1500) and (event.jaxis.value <= 1500) then direction:= nodir; -{$IFDEF DEBUGFILE} - AddFileLog('Joystick value: ' + inttostr(event.jaxis.value)); -{$ENDIF} + if (tiltValue > -1500) and (tiltValue <= 1500) and (movedbybuttons = false) then uKeys.isWalking:= false; end; - end; -*} {$ELSE} SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true; SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELDUP then uKeys.wheelUp:= true; - SDL_JOYAXIS: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); - SDL_JOYHAT: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); + SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); + SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); {$ENDIF} diff -r e7e87e3c67db -r c6597b65caea hedgewars/uKeys.pas --- a/hedgewars/uKeys.pas Sun Oct 25 23:52:36 2009 +0000 +++ b/hedgewars/uKeys.pas Mon Oct 26 10:39:20 2009 +0000 @@ -18,7 +18,7 @@ unit uKeys; interface -uses uConsts; +uses uConsts, SDLh; {$INCLUDE options.inc} type TBinds = array[0..cKeyMaxIndex] of shortstring; @@ -39,7 +39,7 @@ procedure ControllerHatEvent(joy, hat, value: Byte); procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); -var hideAmmoMenu: boolean; +var hideAmmoMenu: boolean; wheelUp: boolean = false; wheelDown: boolean = false; {$IFDEF TOUCHINPUT} @@ -47,24 +47,26 @@ middleClick: boolean = false; rightClick: boolean = false; -upKey: boolean = false; -downKey: boolean = false; -rightKey: boolean = false; -leftKey: boolean = false; + upKey: boolean = false; + downKey: boolean = false; + rightKey: boolean = false; + leftKey: boolean = false; -backspaceKey: boolean = false; -spaceKey: boolean = false; -enterKey: boolean = false; -tabKey: boolean = false; + backspaceKey: boolean = false; + spaceKey: boolean = false; + enterKey: boolean = false; + tabKey: boolean = false; -isAttacking: boolean = false; -isWalking: boolean = false; - + isAttacking: boolean = false; + isWalking: boolean = false; +{$ENDIF} +{$IFDEF IPHONEOS} + theJoystick: PSDL_Joystick; {$ENDIF} ControllerNumControllers: Integer; - ControllerEnabled: Integer; - ControllerNumAxes: array[0..5] of Integer; - //ControllerNumBalls: array[0..5] of Integer; + ControllerEnabled: Integer; + ControllerNumAxes: array[0..5] of Integer; + //ControllerNumBalls: array[0..5] of Integer; ControllerNumHats: array[0..5] of Integer; ControllerNumButtons: array[0..5] of Integer; ControllerAxes: array[0..5] of array[0..19] of Integer; @@ -73,7 +75,7 @@ ControllerButtons: array[0..5] of array[0..19] of Byte; implementation -uses SDLh, uTeams, uConsole, uMisc, uStore; +uses uTeams, uConsole, uMisc, uStore; const KeyNumber = 1024; var tkbd, tkbdn: TKeyboardState; @@ -400,7 +402,7 @@ tkbd[271]:= 1; end; -var Controller: array [0..5] of PSDLJoystick; +var Controller: array [0..5] of PSDL_Joystick; procedure ControllerInit; var i, j: Integer; @@ -456,6 +458,9 @@ end else WriteLnToConsole('Not using any game controller'); +{$IFDEF IPHONEOS} +theJoystick:= Controller[0]; +{$ENDIF} end; procedure ControllerClose;