Norbert's Game Engine v200
Loading...
Searching...
No Matches
eGamepad Class Reference

#include <Gamepad.hpp>

Inheritance diagram for eGamepad:
eBase

Public Member Functions

bool IsConnected (ulong port)
 
eDeadzoneStick DeadzoneCorrection ()
 
void Vibration (ulong port, int leftmotorspeed, int rightmotorspeed)
 
bool GetButtonPressed (uint button)
 
bool GetButtonDown (uint button)
 
bool GetButtonReleased (uint button)
 
sshort GetButtons ()
 
short GetThumbLX ()
 
short GetThumbLY ()
 
short GetThumbRX ()
 
short GetThumbRY ()
 
eGamepadLayout LoadLayout (eString layout)
 
- Public Member Functions inherited from eBase
template<typename T >
T * Cast (eBase *obj)
 Cast class to base.
 

Detailed Description

Gamepad class

Definition at line 45 of file Gamepad.hpp.

Member Function Documentation

◆ DeadzoneCorrection()

eDeadzoneStick eGamepad::DeadzoneCorrection ( )

Definition at line 17 of file Gamepad.cpp.

18{
19 real6 LX = mState.Gamepad.sThumbLX;
20 real6 LY = mState.Gamepad.sThumbLY;
21
22 real6 magnitude = sqrt(LX * LX + LY * LY);
23 real6 normalizedLX = 0.0;
24 real6 normalizedLY = 0.0;
25
26 if (magnitude > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
27 {
28 magnitude = max(0, magnitude - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE);
29 real6 normalizedMagnitude = magnitude / (32767.0 - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE);
30 normalizedLX = LX / 32767.0;
31 normalizedLY = LY / 32767.0;
32 }
33
34 real6 RX = mState.Gamepad.sThumbRX;
35 real6 RY = mState.Gamepad.sThumbRY;
36
37 real6 Rmagnitude = sqrt(RX * RX + RY * RY);
38 real6 normalizedRX = 0.0;
39 real6 normalizedRY = 0.0;
40
41 if (Rmagnitude > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
42 {
43 Rmagnitude = max(0, Rmagnitude - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE);
44 real6 RnormalizedMagnitude = Rmagnitude / (32767.0 - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE);
45 normalizedRX = RX / 32767.0;
46 normalizedRY = RY / 32767.0;
47 }
48
49 return { normalizedLX, normalizedLY, normalizedRX, normalizedRY };
50}

◆ GetButtonDown()

bool eGamepad::GetButtonDown ( uint button)

Definition at line 90 of file Gamepad.cpp.

91{
92 return (mState.Gamepad.wButtons & button);
93}

◆ GetButtonPressed()

bool eGamepad::GetButtonPressed ( uint button)

Definition at line 59 of file Gamepad.cpp.

60{
61 bool isDown = false;
62 int location = 0;
63 for (int i = 0; i < mButtonPressed.size(); i++)
64 {
65 if (mButtonPressed[i] == button)
66 {
67 location = i;
68 isDown = true;
69 break;
70 }
71 }
72
73 if (isDown)
74 {
75 if (GetButtonReleased(button))
76 mButtonPressed.erase(mButtonPressed.begin() + location);
77 return false;
78 }
79 else
80 {
81 if (GetButtonDown(button))
82 {
83 mButtonPressed.push_back(button);
84 return true;
85 }
86 }
87 return false;
88}

◆ GetButtonReleased()

bool eGamepad::GetButtonReleased ( uint button)

Definition at line 95 of file Gamepad.cpp.

96{
97 return !(mState.Gamepad.wButtons & button);
98}

◆ GetButtons()

sshort eGamepad::GetButtons ( )

Definition at line 100 of file Gamepad.cpp.

101{
102 return mState.Gamepad.wButtons;
103}

◆ GetThumbLX()

short eGamepad::GetThumbLX ( )

Definition at line 105 of file Gamepad.cpp.

106{
107 return mState.Gamepad.sThumbLX;
108}

◆ GetThumbLY()

short eGamepad::GetThumbLY ( )

Definition at line 110 of file Gamepad.cpp.

111{
112 return mState.Gamepad.sThumbLY;
113}

◆ GetThumbRX()

short eGamepad::GetThumbRX ( )

Definition at line 115 of file Gamepad.cpp.

116{
117 return mState.Gamepad.sThumbRX;
118}

◆ GetThumbRY()

short eGamepad::GetThumbRY ( )

Definition at line 120 of file Gamepad.cpp.

121{
122 return mState.Gamepad.sThumbRY;
123}

◆ IsConnected()

bool eGamepad::IsConnected ( ulong port)

Definition at line 9 of file Gamepad.cpp.

10{
11 ulong result = XInputGetState(port, &mState);
12 if (result == ERROR_SUCCESS)
13 return true;
14 return false;
15}

◆ LoadLayout()

eGamepadLayout eGamepad::LoadLayout ( eString layout)

Definition at line 125 of file Gamepad.cpp.

126{
127 strg filePath = "gamepad.rd";
128
129 if (!EDR::FileExists(filePath.c_str()))
130 {
131 eConsole::PrintLog("WARNING::eGamepad::LoadLayout", "File 'gamepad.rd' could not be found!");
132 return {};
133 }
134
135 eGamepadLayout rtVl;
136 rtVl.A = (uint)EDR::GetIntG(filePath, "A", layout.GetStrg());
137 rtVl.B = (uint)EDR::GetIntG(filePath, "B", layout.GetStrg());
138 rtVl.X = (uint)EDR::GetIntG(filePath, "X", layout.GetStrg());
139 rtVl.Y = (uint)EDR::GetIntG(filePath, "Y", layout.GetStrg());
140 rtVl.DPad_up = (uint)EDR::GetIntG(filePath, "DPad_up", layout.GetStrg());
141 rtVl.DPad_down = (uint)EDR::GetIntG(filePath, "DPad_down", layout.GetStrg());
142 rtVl.DPad_left = (uint)EDR::GetIntG(filePath, "DPad_left", layout.GetStrg());
143 rtVl.DPad_right = (uint)EDR::GetIntG(filePath, "DPad_right", layout.GetStrg());
144 rtVl.LBShoulder = (uint)EDR::GetIntG(filePath, "LBShoulder", layout.GetStrg());
145 rtVl.RBShoulder = (uint)EDR::GetIntG(filePath, "RBShoulder", layout.GetStrg());
146 rtVl.LSThumbstick = (uint)EDR::GetIntG(filePath, "LSThumbstick", layout.GetStrg());
147 rtVl.RSThumbstick = (uint)EDR::GetIntG(filePath, "RSThumbstick", layout.GetStrg());
148 rtVl.Start = (uint)EDR::GetIntG(filePath, "Start", layout.GetStrg());
149 rtVl.Back = (uint)EDR::GetIntG(filePath, "Back", layout.GetStrg());
150 return rtVl;
151}
static void PrintLog(eString head, eString msg)
Print a log.
Definition Console.cpp:22
const strg & GetStrg() const
Return text as std::string.
Definition String.cpp:70
int GetIntG(strg file, strg token, strg group, const bool binary=false)
For reading in a group.
Definition EDR.cpp:716

◆ Vibration()

void eGamepad::Vibration ( ulong port,
int leftmotorspeed,
int rightmotorspeed )

Definition at line 52 of file Gamepad.cpp.

53{
54 mVibration.wLeftMotorSpeed = leftmotorspeed;
55 mVibration.wRightMotorSpeed = rightmotorspeed;
56 XInputSetState(port, &mVibration);
57}

The documentation for this class was generated from the following files: