author | koda |
Sun, 03 Jan 2010 22:58:19 +0000 | |
changeset 2674 | 2fce032f2f95 |
parent 2671 | 7e0f88013fe8 |
child 2678 | 334016e8d895 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uKeys; |
22 |
interface |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
23 |
uses uConsts, SDLh; |
167 | 24 |
|
25 |
type TBinds = array[0..cKeyMaxIndex] of shortstring; |
|
2567 | 26 |
type TKeyboardState = array[0..cKeyMaxIndex] of Byte; |
4 | 27 |
|
2567 | 28 |
function KeyNameToCode(name: string): word; |
4 | 29 |
procedure ProcessKbd; |
30 |
procedure ResetKbd; |
|
948 | 31 |
procedure FreezeEnterKey; |
4 | 32 |
procedure InitKbdKeyTable; |
33 |
||
167 | 34 |
procedure SetBinds(var binds: TBinds); |
35 |
procedure SetDefaultBinds; |
|
36 |
||
2428 | 37 |
procedure ControllerInit; |
38 |
procedure ControllerClose; |
|
39 |
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
|
40 |
procedure ControllerHatEvent(joy, hat, value: Byte); |
|
41 |
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
|
42 |
||
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
43 |
var hideAmmoMenu: boolean; |
2379 | 44 |
wheelUp: boolean = false; |
45 |
wheelDown: boolean = false; |
|
2586
204e6b2885bc
added little/big endian checks, added symbol for touch input, simplified iphoneos definitions
koda
parents:
2581
diff
changeset
|
46 |
{$IFDEF TOUCHINPUT} |
2567 | 47 |
leftClick: boolean = false; |
48 |
middleClick: boolean = false; |
|
49 |
rightClick: boolean = false; |
|
161 | 50 |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
51 |
upKey: boolean = false; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
52 |
downKey: boolean = false; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
53 |
rightKey: boolean = false; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
54 |
leftKey: boolean = false; |
2567 | 55 |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
56 |
backspaceKey: boolean = false; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
57 |
spaceKey: boolean = false; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
58 |
enterKey: boolean = false; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
59 |
tabKey: boolean = false; |
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
60 |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
61 |
isAttacking: boolean = false; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
62 |
isWalking: boolean = false; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
63 |
{$ENDIF} |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
64 |
{$IFDEF IPHONEOS} |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
65 |
theJoystick: PSDL_Joystick; |
2567 | 66 |
{$ENDIF} |
2428 | 67 |
ControllerNumControllers: Integer; |
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
68 |
ControllerEnabled: Integer; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
69 |
ControllerNumAxes: array[0..5] of Integer; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
70 |
//ControllerNumBalls: array[0..5] of Integer; |
2428 | 71 |
ControllerNumHats: array[0..5] of Integer; |
72 |
ControllerNumButtons: array[0..5] of Integer; |
|
73 |
ControllerAxes: array[0..5] of array[0..19] of Integer; |
|
74 |
//ControllerBalls: array[0..5] of array[0..19] of array[0..1] of Integer; |
|
75 |
ControllerHats: array[0..5] of array[0..19] of Byte; |
|
76 |
ControllerButtons: array[0..5] of array[0..19] of Byte; |
|
77 |
||
4 | 78 |
implementation |
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
79 |
uses uTeams, uConsole, uMisc, uStore; |
109 | 80 |
const KeyNumber = 1024; |
167 | 81 |
|
2436 | 82 |
var tkbd, tkbdn: TKeyboardState; |
4 | 83 |
KeyNames: array [0..cKeyMaxIndex] of string[15]; |
167 | 84 |
DefaultBinds, CurrentBinds: TBinds; |
4 | 85 |
|
86 |
function KeyNameToCode(name: string): word; |
|
351 | 87 |
var Result: Word; |
4 | 88 |
begin |
89 |
Result:= cKeyMaxIndex; |
|
351 | 90 |
while (Result > 0) and (KeyNames[Result] <> name) do dec(Result); |
91 |
KeyNameToCode:= Result |
|
4 | 92 |
end; |
93 |
||
94 |
procedure ProcessKbd; |
|
2428 | 95 |
var i, j, k: LongInt; |
2436 | 96 |
s: shortstring; |
4 | 97 |
pkbd: PByteArray; |
167 | 98 |
Trusted: boolean; |
4 | 99 |
begin |
2428 | 100 |
hideAmmoMenu:= false; |
167 | 101 |
Trusted:= (CurrentTeam <> nil) |
351 | 102 |
and (not CurrentTeam^.ExtDriven) |
846 | 103 |
and (CurrentHedgehog^.BotLevel = 0); |
161 | 104 |
|
2428 | 105 |
// move cursor/camera |
106 |
// TODO: Scale on screen dimensions and/or axis value (game controller)? |
|
107 |
movecursor(5 * CursorMovementX, 5 * CursorMovementY); |
|
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2630
diff
changeset
|
108 |
|
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2630
diff
changeset
|
109 |
k:= SDL_GetMouseState(nil, nil); |
2152 | 110 |
{$IFDEF SDL13} |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2630
diff
changeset
|
111 |
pkbd:= SDL_GetKeyboardState(@j); |
2152 | 112 |
{$ELSE} |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2630
diff
changeset
|
113 |
pkbd:= SDL_GetKeyState(@j); |
2152 | 114 |
{$ENDIF} |
2436 | 115 |
|
2579 | 116 |
{$IFNDEF IPHONEOS} |
2436 | 117 |
for i:= 6 to pred(j) do // first 6 will be overwritten |
118 |
tkbdn[i]:= pkbd^[i]; |
|
2579 | 119 |
{$ENDIF} |
2436 | 120 |
|
2379 | 121 |
// mouse buttons |
2152 | 122 |
{$IFDEF DARWIN} |
2436 | 123 |
tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305])); |
124 |
tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4); |
|
2152 | 125 |
{$ELSE} |
2436 | 126 |
tkbdn[1]:= (k and 1); |
127 |
tkbdn[3]:= ((k shr 2) and 1); |
|
2152 | 128 |
{$ENDIF} |
2436 | 129 |
tkbdn[2]:= ((k shr 1) and 1); |
2328 | 130 |
|
2379 | 131 |
// mouse wheels (see event loop in project file) |
2436 | 132 |
tkbdn[4]:= ord(wheelDown); |
133 |
tkbdn[5]:= ord(wheelUp); |
|
2379 | 134 |
wheelUp:= false; |
135 |
wheelDown:= false; |
|
2586
204e6b2885bc
added little/big endian checks, added symbol for touch input, simplified iphoneos definitions
koda
parents:
2581
diff
changeset
|
136 |
{$IFDEF TOUCHINPUT} |
2567 | 137 |
tkbdn[1]:= ord(leftClick); |
138 |
tkbdn[2]:= ord(middleClick); |
|
139 |
tkbdn[3]:= ord(rightClick); |
|
140 |
leftClick:= false; |
|
141 |
middleClick:= false; |
|
142 |
rightClick:= false; |
|
143 |
||
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
144 |
tkbdn[23]:= ord(upKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
145 |
tkbdn[24]:= ord(downKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
146 |
tkbdn[25]:= ord(leftKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
147 |
tkbdn[26]:= ord(rightKey); |
2567 | 148 |
|
2579 | 149 |
tkbdn[ 8]:= ord(backspaceKey); |
2590 | 150 |
tkbdn[ 9]:= ord(tabKey); |
2579 | 151 |
tkbdn[13]:= ord(enterKey); |
2567 | 152 |
tkbdn[32]:= ord(spaceKey); |
153 |
||
154 |
upKey:= false; |
|
155 |
downKey:= false; |
|
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
156 |
if isWalking = false then rightKey:= false; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
157 |
if isWalking = false then leftKey:= false; |
2567 | 158 |
|
2579 | 159 |
if isAttacking = false then spaceKey:= false; |
2590 | 160 |
tabKey:= false; |
2567 | 161 |
enterKey:= false; |
2579 | 162 |
backspaceKey:= false; |
163 |
||
2567 | 164 |
{$ENDIF} |
2152 | 165 |
|
2428 | 166 |
// Controller(s) |
2436 | 167 |
k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
2428 | 168 |
for j:= 0 to Pred(ControllerNumControllers) do |
169 |
begin |
|
170 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
171 |
begin |
|
2436 | 172 |
if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0; |
173 |
if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0; |
|
2428 | 174 |
inc(k, 2); |
175 |
end; |
|
176 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
177 |
begin |
|
2436 | 178 |
tkbdn[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP; |
179 |
tkbdn[k + 1]:= ControllerHats[j][i] and SDL_HAT_RIGHT; |
|
180 |
tkbdn[k + 2]:= ControllerHats[j][i] and SDL_HAT_DOWN; |
|
181 |
tkbdn[k + 3]:= ControllerHats[j][i] and SDL_HAT_LEFT; |
|
2428 | 182 |
inc(k, 4); |
183 |
end; |
|
184 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
185 |
begin |
|
2436 | 186 |
tkbdn[k]:= ControllerButtons[j][i]; |
2428 | 187 |
inc(k, 1); |
188 |
end; |
|
189 |
end; |
|
190 |
||
2379 | 191 |
// now process strokes |
2436 | 192 |
for i:= 0 to cKeyMaxIndex do |
947 | 193 |
if CurrentBinds[i][0] <> #0 then |
194 |
begin |
|
2436 | 195 |
if (i > 3) and (tkbdn[i] <> 0) and not ((CurrentBinds[i] = 'put') or (CurrentBinds[i] = 'ammomenu') or (CurrentBinds[i] = '+cur_u') or (CurrentBinds[i] = '+cur_d') or (CurrentBinds[i] = '+cur_l') or (CurrentBinds[i] = '+cur_r')) then hideAmmoMenu:= true; |
196 |
if (tkbd[i] = 0) and (tkbdn[i] <> 0) then ParseCommand(CurrentBinds[i], Trusted) |
|
947 | 197 |
else if (CurrentBinds[i][1] = '+') |
2436 | 198 |
and (tkbdn[i] = 0) |
948 | 199 |
and (tkbd[i] <> 0) then |
947 | 200 |
begin |
201 |
s:= CurrentBinds[i]; |
|
202 |
s[1]:= '-'; |
|
203 |
ParseCommand(s, Trusted) |
|
204 |
end; |
|
2436 | 205 |
tkbd[i]:= tkbdn[i] |
206 |
end |
|
4 | 207 |
end; |
208 |
||
209 |
procedure ResetKbd; |
|
2590 | 210 |
var i, j, k, t: LongInt; |
4 | 211 |
pkbd: PByteArray; |
212 |
begin |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
213 |
|
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2630
diff
changeset
|
214 |
k:= SDL_GetMouseState(nil, nil); |
2152 | 215 |
{$IFDEF SDL13} |
2436 | 216 |
pkbd:= SDL_GetKeyboardState(@j); |
2152 | 217 |
{$ELSE} |
2436 | 218 |
pkbd:= SDL_GetKeyState(@j); |
2152 | 219 |
{$ENDIF} |
2436 | 220 |
TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(j) + ')', true); |
221 |
||
2579 | 222 |
{$IFNDEF IPHONEOS} |
2436 | 223 |
for i:= 1 to pred(j) do |
224 |
tkbdn[i]:= pkbd^[i]; |
|
2579 | 225 |
{$ENDIF} |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
226 |
|
2436 | 227 |
// mouse buttons |
228 |
{$IFDEF DARWIN} |
|
229 |
tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305])); |
|
230 |
tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4); |
|
231 |
{$ELSE} |
|
232 |
tkbdn[1]:= (k and 1); |
|
233 |
tkbdn[3]:= ((k shr 2) and 1); |
|
234 |
{$ENDIF} |
|
235 |
tkbdn[2]:= ((k shr 1) and 1); |
|
236 |
||
237 |
// mouse wheels (see event loop in project file) |
|
238 |
tkbdn[4]:= ord(wheelDown); |
|
239 |
tkbdn[5]:= ord(wheelUp); |
|
240 |
wheelUp:= false; |
|
241 |
wheelDown:= false; |
|
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2630
diff
changeset
|
242 |
|
2567 | 243 |
{$IFDEF IPHONEOS} |
244 |
tkbdn[1]:= ord(leftClick); |
|
245 |
tkbdn[2]:= ord(middleClick); |
|
246 |
tkbdn[3]:= ord(rightClick); |
|
247 |
leftClick:= false; |
|
248 |
middleClick:= false; |
|
249 |
rightClick:= false; |
|
250 |
||
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
251 |
tkbdn[23]:= ord(upKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
252 |
tkbdn[24]:= ord(downKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
253 |
tkbdn[25]:= ord(leftKey); |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
254 |
tkbdn[26]:= ord(rightKey); |
2567 | 255 |
|
2579 | 256 |
tkbdn[ 8]:= ord(backspaceKey); |
2590 | 257 |
tkbdn[ 9]:= ord(tabKey); |
2579 | 258 |
tkbdn[13]:= ord(enterKey); |
2567 | 259 |
tkbdn[32]:= ord(spaceKey); |
260 |
||
261 |
upKey:= false; |
|
262 |
downKey:= false; |
|
2590 | 263 |
tabKey:= false; |
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
264 |
if isWalking = false then rightKey:= false; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
265 |
if isWalking = false then leftKey:= false; |
2567 | 266 |
|
2579 | 267 |
if isAttacking = false then spaceKey:= false; |
2567 | 268 |
enterKey:= false; |
2579 | 269 |
backspaceKey:= false; |
2567 | 270 |
{$ENDIF} |
2436 | 271 |
|
272 |
// Controller(s) |
|
273 |
k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
|
2428 | 274 |
for j:= 0 to Pred(ControllerNumControllers) do |
275 |
begin |
|
276 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
277 |
begin |
|
2436 | 278 |
if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0; |
279 |
if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0; |
|
2428 | 280 |
inc(k, 2); |
281 |
end; |
|
282 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
283 |
begin |
|
2436 | 284 |
tkbdn[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP; |
285 |
tkbdn[k + 1]:= ControllerHats[j][i] and SDL_HAT_RIGHT; |
|
286 |
tkbdn[k + 2]:= ControllerHats[j][i] and SDL_HAT_DOWN; |
|
287 |
tkbdn[k + 3]:= ControllerHats[j][i] and SDL_HAT_LEFT; |
|
2428 | 288 |
inc(k, 4); |
289 |
end; |
|
290 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
291 |
begin |
|
2436 | 292 |
tkbdn[k]:= ControllerButtons[j][i]; |
2428 | 293 |
inc(k, 1); |
294 |
end; |
|
295 |
end; |
|
2436 | 296 |
|
297 |
for t:= 0 to cKeyMaxIndex do |
|
298 |
tkbd[i]:= tkbdn[i] |
|
4 | 299 |
end; |
300 |
||
301 |
procedure InitKbdKeyTable; |
|
2428 | 302 |
var i, j, k, t: LongInt; |
4 | 303 |
s: string[15]; |
304 |
begin |
|
305 |
KeyNames[1]:= 'mousel'; |
|
306 |
KeyNames[2]:= 'mousem'; |
|
307 |
KeyNames[3]:= 'mouser'; |
|
2379 | 308 |
KeyNames[4]:= 'wheelup'; |
309 |
KeyNames[5]:= 'wheeldown'; |
|
310 |
||
311 |
for i:= 6 to cKeyMaxIndex do |
|
2613 | 312 |
begin |
313 |
s:= string(sdl_getkeyname(i)); |
|
314 |
//writeln(stdout,inttostr(i) + ': ' + s); |
|
315 |
if s = 'unknown key' then KeyNames[i]:= '' |
|
316 |
else begin |
|
317 |
for t:= 1 to Length(s) do |
|
318 |
if s[t] = ' ' then s[t]:= '_'; |
|
319 |
KeyNames[i]:= s |
|
320 |
end; |
|
321 |
end; |
|
322 |
||
323 |
//for i:= 0 to cKeyMaxIndex do writeln(stdout,inttostr(i) + ': ' + KeyNames[i]); |
|
167 | 324 |
|
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2630
diff
changeset
|
325 |
// get the size of keyboard array |
2436 | 326 |
{$IFDEF SDL13} |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2630
diff
changeset
|
327 |
SDL_GetKeyboardState(@k); |
2436 | 328 |
{$ELSE} |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2630
diff
changeset
|
329 |
SDL_GetKeyState(@k); |
2436 | 330 |
{$ENDIF} |
331 |
||
2428 | 332 |
// Controller(s) |
333 |
for j:= 0 to Pred(ControllerNumControllers) do |
|
334 |
begin |
|
335 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
336 |
begin |
|
337 |
keynames[k + 0]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'u'; |
|
338 |
keynames[k + 1]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'd'; |
|
339 |
inc(k, 2); |
|
340 |
end; |
|
341 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
342 |
begin |
|
343 |
keynames[k + 0]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'u'; |
|
344 |
keynames[k + 1]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'r'; |
|
345 |
keynames[k + 2]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'd'; |
|
346 |
keynames[k + 3]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'l'; |
|
347 |
inc(k, 4); |
|
348 |
end; |
|
349 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
350 |
begin |
|
351 |
keynames[k]:= 'j' + inttostr(j) + 'b' + inttostr(i); |
|
352 |
inc(k, 1); |
|
353 |
end; |
|
354 |
end; |
|
2581 | 355 |
|
2586
204e6b2885bc
added little/big endian checks, added symbol for touch input, simplified iphoneos definitions
koda
parents:
2581
diff
changeset
|
356 |
{$IFDEF TOUCHINPUT} |
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
357 |
DefaultBinds[ 1]:= '/put'; |
2579 | 358 |
DefaultBinds[ 3]:= 'ammomenu'; |
359 |
DefaultBinds[ 8]:= 'hjump'; |
|
2590 | 360 |
DefaultBinds[ 9]:= 'switch'; |
2579 | 361 |
DefaultBinds[ 13]:= 'ljump'; |
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
362 |
DefaultBinds[ 23]:= '+up'; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
363 |
DefaultBinds[ 24]:= '+down'; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
364 |
DefaultBinds[ 25]:= '+left'; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2579
diff
changeset
|
365 |
DefaultBinds[ 26]:= '+right'; |
2590 | 366 |
DefaultBinds[ 32]:= '+attack'; |
2579 | 367 |
{$ENDIF} |
2428 | 368 |
|
2379 | 369 |
DefaultBinds[ 27]:= 'quit'; |
370 |
DefaultBinds[ 96]:= 'history'; |
|
371 |
DefaultBinds[127]:= 'rotmask'; |
|
372 |
||
2606
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
373 |
//numpad |
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
374 |
//DefaultBinds[265]:= '+volup'; |
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
375 |
//DefaultBinds[256]:= '+voldown'; |
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
376 |
|
2379 | 377 |
DefaultBinds[KeyNameToCode('0')]:= '+volup'; |
378 |
DefaultBinds[KeyNameToCode('9')]:= '+voldown'; |
|
379 |
DefaultBinds[KeyNameToCode('c')]:= 'capture'; |
|
380 |
DefaultBinds[KeyNameToCode('h')]:= 'findhh'; |
|
381 |
DefaultBinds[KeyNameToCode('p')]:= 'pause'; |
|
382 |
DefaultBinds[KeyNameToCode('s')]:= '+speedup'; |
|
383 |
DefaultBinds[KeyNameToCode('t')]:= 'chat'; |
|
384 |
DefaultBinds[KeyNameToCode('y')]:= 'confirm'; |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
385 |
|
2407
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
386 |
DefaultBinds[KeyNameToCode('mousem')]:= 'zoomreset'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
387 |
DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomout'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
388 |
DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomin'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
389 |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
390 |
DefaultBinds[KeyNameToCode('f12')]:= 'fullscr'; |
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
391 |
|
167 | 392 |
SetDefaultBinds |
4 | 393 |
end; |
394 |
||
167 | 395 |
procedure SetBinds(var binds: TBinds); |
396 |
begin |
|
2606
ed687a8d081f
updated build files for macosx and optimization system
koda
parents:
2599
diff
changeset
|
397 |
CurrentBinds:= binds; |
167 | 398 |
end; |
399 |
||
400 |
procedure SetDefaultBinds; |
|
401 |
begin |
|
402 |
CurrentBinds:= DefaultBinds |
|
403 |
end; |
|
404 |
||
948 | 405 |
procedure FreezeEnterKey; |
406 |
begin |
|
407 |
tkbd[13]:= 1; |
|
2567 | 408 |
tkbd[271]:= 1; |
948 | 409 |
end; |
167 | 410 |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
411 |
var Controller: array [0..5] of PSDL_Joystick; |
2428 | 412 |
|
413 |
procedure ControllerInit; |
|
414 |
var i, j: Integer; |
|
415 |
begin |
|
2674
2fce032f2f95
lupdate + Palewolf's updated spanish translation + other patches of mine
koda
parents:
2671
diff
changeset
|
416 |
SDL_InitSubSystem(SDL_INIT_JOYSTICK); |
2fce032f2f95
lupdate + Palewolf's updated spanish translation + other patches of mine
koda
parents:
2671
diff
changeset
|
417 |
|
2428 | 418 |
ControllerEnabled:= 0; |
2674
2fce032f2f95
lupdate + Palewolf's updated spanish translation + other patches of mine
koda
parents:
2671
diff
changeset
|
419 |
ControllerNumControllers:= SDL_NumJoysticks(); |
2428 | 420 |
|
421 |
if ControllerNumControllers > 6 then ControllerNumControllers:= 6; |
|
422 |
||
423 |
WriteLnToConsole('Number of game controllers: ' + inttostr(ControllerNumControllers)); |
|
424 |
||
425 |
if ControllerNumControllers > 0 then |
|
426 |
begin |
|
427 |
for j:= 0 to pred(ControllerNumControllers) do |
|
428 |
begin |
|
429 |
WriteLnToConsole('Using game controller: ' + SDL_JoystickName(j)); |
|
430 |
Controller[j]:= SDL_JoystickOpen(j); |
|
431 |
if Controller[j] = nil then |
|
432 |
WriteLnToConsole('* Failed to open game controller!') |
|
433 |
else |
|
434 |
begin |
|
435 |
ControllerNumAxes[j]:= SDL_JoystickNumAxes(Controller[j]); |
|
436 |
//ControllerNumBalls[j]:= SDL_JoystickNumBalls(Controller[j]); |
|
437 |
ControllerNumHats[j]:= SDL_JoystickNumHats(Controller[j]); |
|
438 |
ControllerNumButtons[j]:= SDL_JoystickNumButtons(Controller[j]); |
|
439 |
WriteLnToConsole('* Number of axes: ' + inttostr(ControllerNumAxes[j])); |
|
440 |
//WriteLnToConsole('* Number of balls: ' + inttostr(ControllerNumBalls[j])); |
|
441 |
WriteLnToConsole('* Number of hats: ' + inttostr(ControllerNumHats[j])); |
|
442 |
WriteLnToConsole('* Number of buttons: ' + inttostr(ControllerNumButtons[j])); |
|
443 |
ControllerEnabled:= 1; |
|
444 |
||
445 |
if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20; |
|
446 |
//if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
|
447 |
if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20; |
|
448 |
if ControllerNumButtons[j] > 20 then ControllerNumButtons[j]:= 20; |
|
449 |
||
450 |
// reset all buttons/axes |
|
451 |
for i:= 0 to pred(ControllerNumAxes[j]) do |
|
452 |
ControllerAxes[j][i]:= 0; |
|
453 |
(*for i:= 0 to pred(ControllerNumBalls[j]) do |
|
454 |
begin |
|
455 |
ControllerBalls[j][i][0]:= 0; |
|
456 |
ControllerBalls[j][i][1]:= 0; |
|
457 |
end;*) |
|
458 |
for i:= 0 to pred(ControllerNumHats[j]) do |
|
459 |
ControllerHats[j][i]:= SDL_HAT_CENTERED; |
|
460 |
for i:= 0 to pred(ControllerNumButtons[j]) do |
|
461 |
ControllerButtons[j][i]:= 0; |
|
462 |
end; |
|
463 |
end; |
|
464 |
// enable event generation/controller updating |
|
465 |
SDL_JoystickEventState(1); |
|
466 |
end |
|
467 |
else |
|
468 |
WriteLnToConsole('Not using any game controller'); |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
469 |
{$IFDEF IPHONEOS} |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
470 |
theJoystick:= Controller[0]; |
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
471 |
{$ENDIF} |
2428 | 472 |
end; |
473 |
||
474 |
procedure ControllerClose; |
|
475 |
var j: Integer; |
|
476 |
begin |
|
477 |
if ControllerEnabled > 0 then |
|
478 |
for j:= 0 to pred(ControllerNumControllers) do |
|
479 |
SDL_JoystickClose(Controller[j]); |
|
480 |
end; |
|
481 |
||
482 |
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
|
483 |
begin |
|
484 |
ControllerAxes[joy][axis]:= value; |
|
485 |
end; |
|
486 |
||
487 |
procedure ControllerHatEvent(joy, hat, value: Byte); |
|
488 |
begin |
|
489 |
ControllerHats[joy][hat]:= value; |
|
490 |
end; |
|
491 |
||
492 |
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
|
493 |
begin |
|
494 |
if pressed then ControllerButtons[joy][button]:= 1 else ControllerButtons[joy][button]:= 0; |
|
495 |
end; |
|
496 |
||
4 | 497 |
initialization |
498 |
||
499 |
end. |