-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathApus.Engine.Controller.pas
104 lines (93 loc) · 2.68 KB
/
Apus.Engine.Controller.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Interface for game controllers: joystick, gamepad etc
//
// Copyright (C) 2021 Ivan Polyacov, Apus Software ([email protected])
// This file is licensed under the terms of BSD-3 license (see license.txt)
// This file is a part of the Apus Game Engine (http://apus-software.com/engine/)
unit Apus.Engine.Controller;
interface
uses Apus.Common;
type
TGameControllerType=(gcUnplugged,
gcUnknown,
gcJoystick,
gcGamepad,
gcWheel);
TConAxisType=(atAxis0,
atAxis1,
atAxis2,
atAxis3,
atAxis4,
atAxis5,
atAxis6,
atAxis7,
atLeftX,
atLeftY,
atRightX,
atRightY);
TConButtonType=(btButton0,
btButton1,
btButton2,
btButton3,
btButton4,
btButton5,
btButton6,
btButton7,
btButton8,
btButton9,
btButton10,
btButton11,
btButton12,
btButton13,
btButton14,
btButton15,
btButtonA,
btButtonB,
btButtonX,
btButtonY,
btButtonBack,
btButtonGuide,
btButtonStart,
btButtonDPadUp,
btButtonDPadDown,
btButtonDPadLeft,
btButtonDPadRight,
btButtonLeftShoulder,
btButtonRightShoulder);
TGameController=record
index:integer;
controllerType:TGameControllerType;
name:String8;
numAxes,numButtons:integer;
buttons:cardinal;
axes:array[TConAxisType] of single; // -1..1 range
function GetButton(btn:TConButtonType):boolean;
end;
PGameController=^TGameController;
var
controllers:array[0..3] of TGameController;
function GetButtonName(btn:TConButtonType):String8;
implementation
uses SysUtils;
{ TGameController }
function TGameController.GetButton(btn:TConButtonType): boolean;
begin
result:=GetBit(buttons,ord(btn));
end;
function GetButtonName(btn: TConButtonType): String8;
const
conButtonNames:array[btButtonA..btButtonRightShoulder] of String8=(
'A','B','X','Y','Back','Guide','Start',
'DPad Up','DPad Down','DPad Left','DPad Right',
'Left Shoulder','Right Shoulder');
begin
if btn in [low(conButtonNames)..high(conButtonNames)] then
result:=conButtonNames[btn]
else
result:=IntToStr(ord(btn));
end;
var
i:integer;
initialization
for i:=0 to high(controllers) do
controllers[i].index:=i;
end.