107 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
107 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
108 for j:= 0 to Pred(ControllerNumControllers) do |
108 for j:= 0 to Pred(ControllerNumControllers) do |
109 begin |
109 begin |
110 for i:= 0 to Pred(ControllerNumAxes[j]) do |
110 for i:= 0 to Pred(ControllerNumAxes[j]) do |
111 begin |
111 begin |
112 if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0; |
112 if ControllerAxes[j][i] > 20000 then |
113 if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0; |
113 tkbdn[k + 0]:= 1 |
|
114 else |
|
115 tkbdn[k + 0]:= 0; |
|
116 if ControllerAxes[j][i] < -20000 then |
|
117 tkbdn[k + 1]:= 1 |
|
118 else |
|
119 tkbdn[k + 1]:= 0; |
114 inc(k, 2); |
120 inc(k, 2); |
115 end; |
121 end; |
116 for i:= 0 to Pred(ControllerNumHats[j]) do |
122 for i:= 0 to Pred(ControllerNumHats[j]) do |
117 begin |
123 begin |
118 tkbdn[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP; |
124 tkbdn[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP; |
130 {$ENDIF} |
136 {$ENDIF} |
131 |
137 |
132 // ctrl/cmd + q to close engine and frontend |
138 // ctrl/cmd + q to close engine and frontend |
133 {$IFDEF DARWIN} |
139 {$IFDEF DARWIN} |
134 if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then |
140 if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then |
135 {$ELSE} |
141 {$ELSE} |
136 if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then |
142 if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then |
137 {$ENDIF} |
143 {$ENDIF} |
138 begin |
144 begin |
139 if tkbdn[KeyNameToCode('q')] = 1 then ParseCommand ('halt', true) |
145 if tkbdn[KeyNameToCode('q')] = 1 then ParseCommand ('halt', true) |
140 end; |
146 end; |
141 |
147 |
142 // now process strokes |
148 // now process strokes |
143 for i:= 0 to cKeyMaxIndex do |
149 for i:= 0 to cKeyMaxIndex do |
144 if CurrentBinds[i][0] <> #0 then |
150 if CurrentBinds[i][0] <> #0 then |
145 begin |
151 begin |
146 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; |
152 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; |
147 if (tkbd[i] = 0) and (tkbdn[i] <> 0) then |
153 if (tkbd[i] = 0) and (tkbdn[i] <> 0) then |
148 begin |
154 begin |
149 ParseCommand(CurrentBinds[i], Trusted); |
155 ParseCommand(CurrentBinds[i], Trusted); |
150 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then ParseCommand('gencmd R', true) |
156 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
151 end |
157 ParseCommand('gencmd R', true) |
152 else if (CurrentBinds[i][1] = '+') |
158 end |
153 and (tkbdn[i] = 0) |
159 else if (CurrentBinds[i][1] = '+') and (tkbdn[i] = 0) and (tkbd[i] <> 0) then |
154 and (tkbd[i] <> 0) then |
160 begin |
155 begin |
161 s:= CurrentBinds[i]; |
156 s:= CurrentBinds[i]; |
162 s[1]:= '-'; |
157 s[1]:= '-'; |
163 ParseCommand(s, Trusted); |
158 ParseCommand(s, Trusted); |
164 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
159 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then ParseCommand('gencmd R', true) |
165 ParseCommand('gencmd R', true) |
160 end; |
166 end; |
161 tkbd[i]:= tkbdn[i] |
167 tkbd[i]:= tkbdn[i] |
162 end |
168 end |
163 end; |
169 end; |
164 |
170 |
165 procedure ResetKbd; |
171 procedure ResetKbd; |
203 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
209 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
204 for j:= 0 to Pred(ControllerNumControllers) do |
210 for j:= 0 to Pred(ControllerNumControllers) do |
205 begin |
211 begin |
206 for i:= 0 to Pred(ControllerNumAxes[j]) do |
212 for i:= 0 to Pred(ControllerNumAxes[j]) do |
207 begin |
213 begin |
208 if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0; |
214 if ControllerAxes[j][i] > 20000 then |
209 if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0; |
215 tkbdn[k + 0]:= 1 |
|
216 else |
|
217 tkbdn[k + 0]:= 0; |
|
218 if ControllerAxes[j][i] < -20000 then |
|
219 tkbdn[k + 1]:= 1 |
|
220 else |
|
221 tkbdn[k + 1]:= 0; |
210 inc(k, 2); |
222 inc(k, 2); |
211 end; |
223 end; |
212 for i:= 0 to Pred(ControllerNumHats[j]) do |
224 for i:= 0 to Pred(ControllerNumHats[j]) do |
213 begin |
225 begin |
214 tkbdn[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP; |
226 tkbdn[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP; |
246 //writeln(stdout,IntToStr(i) + ': ' + s); |
258 //writeln(stdout,IntToStr(i) + ': ' + s); |
247 if s = 'unknown key' then KeyNames[i]:= '' |
259 if s = 'unknown key' then KeyNames[i]:= '' |
248 else |
260 else |
249 begin |
261 begin |
250 for t:= 1 to Length(s) do |
262 for t:= 1 to Length(s) do |
251 if s[t] = ' ' then s[t]:= '_'; |
263 if s[t] = ' ' then |
|
264 s[t]:= '_'; |
252 KeyNames[i]:= s |
265 KeyNames[i]:= s |
253 end; |
266 end; |
254 end; |
267 end; |
255 |
268 |
256 //for i:= 0 to cKeyMaxIndex do writeln(stdout,IntToStr(i) + ': ' + KeyNames[i]); |
269 //for i:= 0 to cKeyMaxIndex do writeln(stdout,IntToStr(i) + ': ' + KeyNames[i]); |
402 exit; // joystick subsystem disabled on iPhone |
415 exit; // joystick subsystem disabled on iPhone |
403 {$ENDIF} |
416 {$ENDIF} |
404 |
417 |
405 SDL_InitSubSystem(SDL_INIT_JOYSTICK); |
418 SDL_InitSubSystem(SDL_INIT_JOYSTICK); |
406 ControllerNumControllers:= SDL_NumJoysticks(); |
419 ControllerNumControllers:= SDL_NumJoysticks(); |
407 if ControllerNumControllers > 6 then ControllerNumControllers:= 6; |
420 |
|
421 if ControllerNumControllers > 6 then |
|
422 ControllerNumControllers:= 6; |
408 |
423 |
409 WriteLnToConsole('Number of game controllers: ' + IntToStr(ControllerNumControllers)); |
424 WriteLnToConsole('Number of game controllers: ' + IntToStr(ControllerNumControllers)); |
410 |
425 |
411 if ControllerNumControllers > 0 then |
426 if ControllerNumControllers > 0 then |
412 begin |
427 begin |
426 //WriteLnToConsole('* Number of balls: ' + IntToStr(ControllerNumBalls[j])); |
441 //WriteLnToConsole('* Number of balls: ' + IntToStr(ControllerNumBalls[j])); |
427 WriteLnToConsole('* Number of hats: ' + IntToStr(ControllerNumHats[j])); |
442 WriteLnToConsole('* Number of hats: ' + IntToStr(ControllerNumHats[j])); |
428 WriteLnToConsole('* Number of buttons: ' + IntToStr(ControllerNumButtons[j])); |
443 WriteLnToConsole('* Number of buttons: ' + IntToStr(ControllerNumButtons[j])); |
429 ControllerEnabled:= 1; |
444 ControllerEnabled:= 1; |
430 |
445 |
431 if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20; |
446 if ControllerNumAxes[j] > 20 then |
|
447 ControllerNumAxes[j]:= 20; |
432 //if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
448 //if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
433 if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20; |
449 |
434 if ControllerNumButtons[j] > 20 then ControllerNumButtons[j]:= 20; |
450 if ControllerNumHats[j] > 20 then |
|
451 ControllerNumHats[j]:= 20; |
|
452 |
|
453 if ControllerNumButtons[j] > 20 then |
|
454 ControllerNumButtons[j]:= 20; |
435 |
455 |
436 // reset all buttons/axes |
456 // reset all buttons/axes |
437 for i:= 0 to pred(ControllerNumAxes[j]) do |
457 for i:= 0 to pred(ControllerNumAxes[j]) do |
438 ControllerAxes[j][i]:= 0; |
458 ControllerAxes[j][i]:= 0; |
439 (*for i:= 0 to pred(ControllerNumBalls[j]) do |
459 (*for i:= 0 to pred(ControllerNumBalls[j]) do |
472 ControllerHats[joy][hat]:= value; |
492 ControllerHats[joy][hat]:= value; |
473 end; |
493 end; |
474 |
494 |
475 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
495 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
476 begin |
496 begin |
477 if pressed then ControllerButtons[joy][button]:= 1 |
497 if pressed then |
478 else ControllerButtons[joy][button]:= 0; |
498 ControllerButtons[joy][button]:= 1 |
|
499 else |
|
500 ControllerButtons[joy][button]:= 0; |
479 end; |
501 end; |
480 |
502 |
481 procedure initModule; |
503 procedure initModule; |
482 begin |
504 begin |
483 wheelUp:= false; |
505 wheelUp:= false; |