git repos / blockattack-game

blame: source/code/gamecontroller.cpp

normal view · raw

826cf176 sago007 2016-03-12 10:53 1
/*
826cf176 sago007 2016-03-12 10:53 2
===========================================================================
826cf176 sago007 2016-03-12 10:53 3
blockattack - Block Attack - Rise of the Blocks
826cf176 sago007 2016-03-12 10:53 4
Copyright (C) 2005-2016 Poul Sander
826cf176 sago007 2016-03-12 10:53 5
826cf176 sago007 2016-03-12 10:53 6
This program is free software: you can redistribute it and/or modify
826cf176 sago007 2016-03-12 10:53 7
it under the terms of the GNU General Public License as published by
826cf176 sago007 2016-03-12 10:53 8
the Free Software Foundation, either version 2 of the License, or
826cf176 sago007 2016-03-12 10:53 9
(at your option) any later version.
826cf176 sago007 2016-03-12 10:53 10
826cf176 sago007 2016-03-12 10:53 11
This program is distributed in the hope that it will be useful,
826cf176 sago007 2016-03-12 10:53 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
826cf176 sago007 2016-03-12 10:53 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
826cf176 sago007 2016-03-12 10:53 14
GNU General Public License for more details.
826cf176 sago007 2016-03-12 10:53 15
826cf176 sago007 2016-03-12 10:53 16
You should have received a copy of the GNU General Public License
826cf176 sago007 2016-03-12 10:53 17
along with this program.  If not, see http://www.gnu.org/licenses/
826cf176 sago007 2016-03-12 10:53 18
826cf176 sago007 2016-03-12 10:53 19
Source information and contacts persons can be found at
826cf176 sago007 2016-03-12 10:53 20
http://www.blockattack.net
826cf176 sago007 2016-03-12 10:53 21
===========================================================================
826cf176 sago007 2016-03-12 10:53 22
*/
826cf176 sago007 2016-03-12 10:53 23
826cf176 sago007 2016-03-12 10:53 24
#include "gamecontroller.h"
826cf176 sago007 2016-03-12 10:53 25
#include "SDL_gamecontroller.h"
c74066db Poul Sander 2022-02-16 12:14 26
#include "platform_folders.h"
75ea368b sago007 2016-04-16 14:37 27
#include "common.h"
826cf176 sago007 2016-03-12 10:53 28
#include <iostream>
a077dceb sago007 2016-03-19 19:19 29
#include <map>
75ea368b sago007 2016-04-16 14:37 30
#include <SDL2/SDL_joystick.h>
826cf176 sago007 2016-03-12 10:53 31
2cb68251 sago007 2016-03-14 18:01 32
static bool verbose = false;
2cb68251 sago007 2016-03-14 18:01 33
a077dceb sago007 2016-03-19 19:19 34
struct ControllerStatus {
a077dceb sago007 2016-03-19 19:19 35
	std::map<int, bool> AxisInDeadZone;
f2dac7e4 sago007 2016-04-09 19:24 36
	int player = 1;
a077dceb sago007 2016-03-19 19:19 37
};
a077dceb sago007 2016-03-19 19:19 38
a077dceb sago007 2016-03-19 19:19 39
static std::map<SDL_JoystickID, ControllerStatus> controllerStatusMap;
bf4572f8 sago007 2018-04-10 22:25 40
static std::map<std::string, int> gamecontrollers_assigned;
bf4572f8 sago007 2018-04-10 22:25 41
static std::vector<std::string> supportedControllers;
8c5c4f5a Poul Sander 2020-06-27 13:06 42
static std::vector<SDL_GameController*> controllersOpened;
a077dceb sago007 2016-03-19 19:19 43
a077dceb sago007 2016-03-19 19:19 44
2cb68251 sago007 2016-03-14 18:01 45
void GameControllerSetVerbose(bool value) {
2cb68251 sago007 2016-03-14 18:01 46
	verbose = value;
2cb68251 sago007 2016-03-14 18:01 47
}
2cb68251 sago007 2016-03-14 18:01 48
a35ab74b sago007 2016-04-02 10:26 49
static const char* GameControllerGetName(SDL_GameController* gamecontroller) {
2cb68251 sago007 2016-03-14 18:01 50
	const char* result = SDL_GameControllerName(gamecontroller);
2cb68251 sago007 2016-03-14 18:01 51
	if (!result) {
2cb68251 sago007 2016-03-14 18:01 52
		result = "Unnamed";
2cb68251 sago007 2016-03-14 18:01 53
	}
2cb68251 sago007 2016-03-14 18:01 54
	return result;
2cb68251 sago007 2016-03-14 18:01 55
}
2cb68251 sago007 2016-03-14 18:01 56
75ea368b sago007 2016-04-16 14:37 57
static std::string GetGuidAsHex(const SDL_JoystickGUID& guid) {
75ea368b sago007 2016-04-16 14:37 58
	std::string ret;
75ea368b sago007 2016-04-16 14:37 59
	char buffer[3];
016b3bf0 Poul Sander 2023-11-15 17:58 60
	for (size_t j = 0; j < sizeof(guid.data); j++) {
75ea368b sago007 2016-04-16 14:37 61
		snprintf(buffer, sizeof(buffer), "%02X", guid.data[j]);
75ea368b sago007 2016-04-16 14:37 62
		ret += buffer;
75ea368b sago007 2016-04-16 14:37 63
	}
75ea368b sago007 2016-04-16 14:37 64
	return ret;
75ea368b sago007 2016-04-16 14:37 65
}
75ea368b sago007 2016-04-16 14:37 66
75ea368b sago007 2016-04-16 14:37 67
75ea368b sago007 2016-04-16 14:37 68
static int GetNextPlayerByGui(const SDL_JoystickGUID& guid) {
75ea368b sago007 2016-04-16 14:37 69
	Config::getInstance()->setDefault("gc_AllToOnePlayer", "0");
75ea368b sago007 2016-04-16 14:37 70
	int fixedPlayer = Config::getInstance()->getInt("gc_AllToOnePlayer");
75ea368b sago007 2016-04-16 14:37 71
	if (fixedPlayer > 0 && fixedPlayer <= 2) {
75ea368b sago007 2016-04-16 14:37 72
		return fixedPlayer;
75ea368b sago007 2016-04-16 14:37 73
	}
75ea368b sago007 2016-04-16 14:37 74
	std::string guidAsHex= GetGuidAsHex(guid);
75ea368b sago007 2016-04-16 14:37 75
	std::string configName = "gc_assign_"+guidAsHex;
75ea368b sago007 2016-04-16 14:37 76
	Config::getInstance()->setDefault(configName, "1");
75ea368b sago007 2016-04-16 14:37 77
	int player = Config::getInstance()->getInt(configName) + gamecontrollers_assigned[guidAsHex];
75ea368b sago007 2016-04-16 14:37 78
	gamecontrollers_assigned[guidAsHex]++; //Next controller with same guid should be assigned to different player.
092bdebe sago007 2017-03-19 14:39 79
75ea368b sago007 2016-04-16 14:37 80
	if (player%2==0) {
75ea368b sago007 2016-04-16 14:37 81
		return 2;  //Even number means player 2
75ea368b sago007 2016-04-16 14:37 82
	}
75ea368b sago007 2016-04-16 14:37 83
	return 1;
75ea368b sago007 2016-04-16 14:37 84
}
75ea368b sago007 2016-04-16 14:37 85
8c5c4f5a Poul Sander 2020-06-27 13:06 86
void UnInitGameControllers() {
8c5c4f5a Poul Sander 2020-06-27 13:06 87
	if (controllersOpened.empty()) {
8c5c4f5a Poul Sander 2020-06-27 13:06 88
		return;
8c5c4f5a Poul Sander 2020-06-27 13:06 89
	}
8c5c4f5a Poul Sander 2020-06-27 13:06 90
	for (SDL_GameController* t : controllersOpened) {
8c5c4f5a Poul Sander 2020-06-27 13:06 91
		SDL_GameControllerClose(t);
8c5c4f5a Poul Sander 2020-06-27 13:06 92
	}
8c5c4f5a Poul Sander 2020-06-27 13:06 93
	controllersOpened.clear();
8c5c4f5a Poul Sander 2020-06-27 13:06 94
	controllerStatusMap.clear();
8c5c4f5a Poul Sander 2020-06-27 13:06 95
	gamecontrollers_assigned.clear();
8c5c4f5a Poul Sander 2020-06-27 13:06 96
	supportedControllers.clear();
8c5c4f5a Poul Sander 2020-06-27 13:06 97
}
8c5c4f5a Poul Sander 2020-06-27 13:06 98
826cf176 sago007 2016-03-12 10:53 99
void InitGameControllers() {
2cb68251 sago007 2016-03-14 18:01 100
	std::string configFile = sago::getConfigHome()+"/blockattack/gamecontrollerdb.txt";
2cb68251 sago007 2016-03-14 18:01 101
	int errorCode = SDL_GameControllerAddMappingsFromFile(configFile.c_str());
2cb68251 sago007 2016-03-14 18:01 102
	if (errorCode == -1 && verbose) {
161a010c sago007 2016-05-06 14:00 103
		std::cerr << "Could not load mapping file: " << configFile << "\n";
2cb68251 sago007 2016-03-14 18:01 104
	}
2cb68251 sago007 2016-03-14 18:01 105
	if (verbose) {
161a010c sago007 2016-05-06 14:00 106
		std::cout << "Number of Game controllers: " << SDL_NumJoysticks() << "\n";
2cb68251 sago007 2016-03-14 18:01 107
	}
c7f2082f sago007 2016-03-13 11:48 108
	SDL_GameController* controller = nullptr;
826cf176 sago007 2016-03-12 10:53 109
	for (int i = 0; i < SDL_NumJoysticks(); ++i) {
826cf176 sago007 2016-03-12 10:53 110
		if (SDL_IsGameController(i)) {
826cf176 sago007 2016-03-12 10:53 111
			controller = SDL_GameControllerOpen(i);
092bdebe sago007 2017-03-19 14:39 112
			SDL_Joystick* j = SDL_GameControllerGetJoystick(controller);
f2dac7e4 sago007 2016-04-09 19:24 113
			SDL_JoystickID instanceId = SDL_JoystickInstanceID(j);
75ea368b sago007 2016-04-16 14:37 114
			SDL_JoystickGUID guid = SDL_JoystickGetGUID(j);
75ea368b sago007 2016-04-16 14:37 115
			int assingToPlayer = GetNextPlayerByGui(guid);
75ea368b sago007 2016-04-16 14:37 116
			controllerStatusMap[instanceId].player = assingToPlayer;
bf4572f8 sago007 2018-04-10 22:25 117
			supportedControllers.push_back(GameControllerGetName(controller));
8c5c4f5a Poul Sander 2020-06-27 13:06 118
			controllersOpened.push_back(controller);
2cb68251 sago007 2016-03-14 18:01 119
			if (verbose) {
161a010c sago007 2016-05-06 14:00 120
				std::cout << "Supported game controller detected: " << GameControllerGetName(controller) << ", mapping: " << SDL_GameControllerMapping(controller) <<  "\n";
161a010c sago007 2016-05-06 14:00 121
				std::cout << "Assigned to player: " << controllerStatusMap[instanceId].player << "\n";
2cb68251 sago007 2016-03-14 18:01 122
			}
826cf176 sago007 2016-03-12 10:53 123
		}
826cf176 sago007 2016-03-12 10:53 124
	}
826cf176 sago007 2016-03-12 10:53 125
}
ce5aa7d3 sago007 2016-03-13 11:44 126
bf4572f8 sago007 2018-04-10 22:25 127
const std::vector<std::string>& GetSupportedControllerNames() {
bf4572f8 sago007 2018-04-10 22:25 128
	return supportedControllers;
bf4572f8 sago007 2018-04-10 22:25 129
}
bf4572f8 sago007 2018-04-10 22:25 130
016b3bf0 Poul Sander 2023-11-15 17:58 131
void GameControllerCheckDeadZone(const SDL_Event& event) {
a077dceb sago007 2016-03-19 19:19 132
	if (event.type != SDL_CONTROLLERAXISMOTION) {
a077dceb sago007 2016-03-19 19:19 133
		return;  //assert?
a077dceb sago007 2016-03-19 19:19 134
	}
a077dceb sago007 2016-03-19 19:19 135
	int value = event.caxis.value;
a077dceb sago007 2016-03-19 19:19 136
	if (value > -deadZoneLimit && value < deadZoneLimit) {
a077dceb sago007 2016-03-19 19:19 137
		controllerStatusMap[event.caxis.which].AxisInDeadZone[event.caxis.axis] = true;
a077dceb sago007 2016-03-19 19:19 138
	}
a077dceb sago007 2016-03-19 19:19 139
}
a077dceb sago007 2016-03-19 19:19 140
016b3bf0 Poul Sander 2023-11-15 17:58 141
bool GameControllerIsInDeadZone(SDL_JoystickID id, int axis) {
a077dceb sago007 2016-03-19 19:19 142
	return controllerStatusMap[id].AxisInDeadZone[axis];
a077dceb sago007 2016-03-19 19:19 143
}
a077dceb sago007 2016-03-19 19:19 144
016b3bf0 Poul Sander 2023-11-15 17:58 145
void GameControllerSetIsInDeadZone(SDL_JoystickID id, int axis, bool value) {
a077dceb sago007 2016-03-19 19:19 146
	controllerStatusMap[id].AxisInDeadZone[axis] = value;
a077dceb sago007 2016-03-19 19:19 147
}
a077dceb sago007 2016-03-19 19:19 148
016b3bf0 Poul Sander 2023-11-15 17:58 149
static bool GameControllerExtSkipThisPlayer(int playerNumber, const SDL_Event& event) {
f2dac7e4 sago007 2016-04-09 19:24 150
f2dac7e4 sago007 2016-04-09 19:24 151
	if (event.type == SDL_CONTROLLERBUTTONDOWN) {
f2dac7e4 sago007 2016-04-09 19:24 152
		ControllerStatus& cs = controllerStatusMap[event.cbutton.which];
f2dac7e4 sago007 2016-04-09 19:24 153
		if (cs.player == playerNumber) {
f2dac7e4 sago007 2016-04-09 19:24 154
			return false;
f2dac7e4 sago007 2016-04-09 19:24 155
		}
f2dac7e4 sago007 2016-04-09 19:24 156
	}
f2dac7e4 sago007 2016-04-09 19:24 157
	if (event.type == SDL_CONTROLLERAXISMOTION ) {
f2dac7e4 sago007 2016-04-09 19:24 158
		ControllerStatus& cs = controllerStatusMap[event.caxis.which];
f2dac7e4 sago007 2016-04-09 19:24 159
		if (cs.player == playerNumber) {
f2dac7e4 sago007 2016-04-09 19:24 160
			return false;
f2dac7e4 sago007 2016-04-09 19:24 161
		}
f2dac7e4 sago007 2016-04-09 19:24 162
	}
f2dac7e4 sago007 2016-04-09 19:24 163
	return true;
f2dac7e4 sago007 2016-04-09 19:24 164
}
f2dac7e4 sago007 2016-04-09 19:24 165
db84be96 sago007 2020-06-27 22:07 166
016b3bf0 Poul Sander 2023-11-15 17:58 167
bool GameControllerIsConnectionEvent(const SDL_Event& event) {
db84be96 sago007 2020-06-27 22:07 168
	if ( event.type == SDL_CONTROLLERDEVICEADDED
db84be96 sago007 2020-06-27 22:07 169
	        || event.type == SDL_CONTROLLERDEVICEREMOVED
db84be96 sago007 2020-06-27 22:07 170
	        || event.type == SDL_CONTROLLERDEVICEREMAPPED ) {
db84be96 sago007 2020-06-27 22:07 171
		return true;
db84be96 sago007 2020-06-27 22:07 172
	}
db84be96 sago007 2020-06-27 22:07 173
	return false;
db84be96 sago007 2020-06-27 22:07 174
}
db84be96 sago007 2020-06-27 22:07 175
fbc58f22 Poul Sander 2022-01-30 15:59 176
ce5aa7d3 sago007 2016-03-13 11:44 177
016b3bf0 Poul Sander 2023-11-15 17:58 178
bool GameControllerExtIsPlayerDownEvent(int playerNumber, const SDL_Event& event) {
016b3bf0 Poul Sander 2023-11-15 17:58 179
	if (GameControllerExtSkipThisPlayer(playerNumber, event)) {
ce5aa7d3 sago007 2016-03-13 11:44 180
		return false;
ce5aa7d3 sago007 2016-03-13 11:44 181
	}
016b3bf0 Poul Sander 2023-11-15 17:58 182
	return GameControllerIsDownEvent(event);
f73e7c50 sago007 2020-07-04 08:03 183
}
f73e7c50 sago007 2020-07-04 08:03 184
016b3bf0 Poul Sander 2023-11-15 17:58 185
bool GameControllerIsControllerDirectionEvent(const SDL_Event& event, SDL_GameControllerButton dpad_direction, SDL_GameControllerAxis axis, float axis_mod = 1.0f) {
ce5aa7d3 sago007 2016-03-13 11:44 186
	if (event.type == SDL_CONTROLLERBUTTONDOWN) {
fbc58f22 Poul Sander 2022-01-30 15:59 187
		if (event.cbutton.button == dpad_direction ) {
ce5aa7d3 sago007 2016-03-13 11:44 188
			return true;
ce5aa7d3 sago007 2016-03-13 11:44 189
		}
ce5aa7d3 sago007 2016-03-13 11:44 190
	}
fbc58f22 Poul Sander 2022-01-30 15:59 191
	if (event.type == SDL_CONTROLLERAXISMOTION  && event.caxis.axis == axis ) {
a35ab74b sago007 2016-04-02 10:26 192
		const SDL_ControllerAxisEvent& a = event.caxis;
016b3bf0 Poul Sander 2023-11-15 17:58 193
		GameControllerCheckDeadZone(event);
016b3bf0 Poul Sander 2023-11-15 17:58 194
		if (GameControllerIsInDeadZone(a.which, a.axis)) {
fbc58f22 Poul Sander 2022-01-30 15:59 195
			if (event.caxis.value * axis_mod > deadZoneLimit) {
016b3bf0 Poul Sander 2023-11-15 17:58 196
				GameControllerSetIsInDeadZone(a.which,a.axis,false);
a077dceb sago007 2016-03-19 19:19 197
				return true;
a077dceb sago007 2016-03-19 19:19 198
			}
a077dceb sago007 2016-03-19 19:19 199
		}
a077dceb sago007 2016-03-19 19:19 200
	}
ce5aa7d3 sago007 2016-03-13 11:44 201
	return false;
ce5aa7d3 sago007 2016-03-13 11:44 202
}
ce5aa7d3 sago007 2016-03-13 11:44 203
016b3bf0 Poul Sander 2023-11-15 17:58 204
bool GameControllerIsDownEvent(const SDL_Event& event) {
016b3bf0 Poul Sander 2023-11-15 17:58 205
	return GameControllerIsControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_DOWN, SDL_CONTROLLER_AXIS_LEFTY);
fbc58f22 Poul Sander 2022-01-30 15:59 206
}
fbc58f22 Poul Sander 2022-01-30 15:59 207
016b3bf0 Poul Sander 2023-11-15 17:58 208
bool GameControllerIsUpEvent(const SDL_Event& event) {
016b3bf0 Poul Sander 2023-11-15 17:58 209
	return GameControllerIsControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_UP, SDL_CONTROLLER_AXIS_LEFTY, -1.0f);
fbc58f22 Poul Sander 2022-01-30 15:59 210
}
fbc58f22 Poul Sander 2022-01-30 15:59 211
016b3bf0 Poul Sander 2023-11-15 17:58 212
bool GameControllerIsLeftEvent(const SDL_Event& event) {
016b3bf0 Poul Sander 2023-11-15 17:58 213
	return GameControllerIsControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDL_CONTROLLER_AXIS_LEFTX, -1.0f);
fbc58f22 Poul Sander 2022-01-30 15:59 214
}
fbc58f22 Poul Sander 2022-01-30 15:59 215
016b3bf0 Poul Sander 2023-11-15 17:58 216
bool GameControllerIsRightEvent(const SDL_Event& event) {
016b3bf0 Poul Sander 2023-11-15 17:58 217
	return GameControllerIsControllerDirectionEvent(event, SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDL_CONTROLLER_AXIS_LEFTX);
fbc58f22 Poul Sander 2022-01-30 15:59 218
}
fbc58f22 Poul Sander 2022-01-30 15:59 219
016b3bf0 Poul Sander 2023-11-15 17:58 220
bool GameControllerExtIsPlayerUpEvent(int playerNumber, const SDL_Event& event) {
016b3bf0 Poul Sander 2023-11-15 17:58 221
	if (GameControllerExtSkipThisPlayer(playerNumber, event)) {
ce5aa7d3 sago007 2016-03-13 11:44 222
		return false;
ce5aa7d3 sago007 2016-03-13 11:44 223
	}
016b3bf0 Poul Sander 2023-11-15 17:58 224
	return GameControllerIsUpEvent(event);
f73e7c50 sago007 2020-07-04 08:03 225
}
f73e7c50 sago007 2020-07-04 08:03 226
016b3bf0 Poul Sander 2023-11-15 17:58 227
bool GameControllerExtIsPlayerLeftEvent(int playerNumber, const SDL_Event& event) {
016b3bf0 Poul Sander 2023-11-15 17:58 228
	if (GameControllerExtSkipThisPlayer(playerNumber, event)) {
ce5aa7d3 sago007 2016-03-13 11:44 229
		return false;
ce5aa7d3 sago007 2016-03-13 11:44 230
	}
016b3bf0 Poul Sander 2023-11-15 17:58 231
	return GameControllerIsLeftEvent(event);
f73e7c50 sago007 2020-07-04 08:03 232
}
f73e7c50 sago007 2020-07-04 08:03 233
016b3bf0 Poul Sander 2023-11-15 17:58 234
bool GameControllerExtIsPlayerRightEvent(int playerNumber, const SDL_Event& event) {
016b3bf0 Poul Sander 2023-11-15 17:58 235
	if (GameControllerExtSkipThisPlayer(playerNumber, event)) {
f73e7c50 sago007 2020-07-04 08:03 236
		return false;
f73e7c50 sago007 2020-07-04 08:03 237
	}
016b3bf0 Poul Sander 2023-11-15 17:58 238
	return GameControllerIsRightEvent(event);
f73e7c50 sago007 2020-07-04 08:03 239
}
f73e7c50 sago007 2020-07-04 08:03 240
016b3bf0 Poul Sander 2023-11-15 17:58 241
bool GameControllerExtIsPlayerSwitchEvent(int playerNumber, const SDL_Event& event) {
016b3bf0 Poul Sander 2023-11-15 17:58 242
	if (GameControllerExtSkipThisPlayer(playerNumber, event)) {
ce5aa7d3 sago007 2016-03-13 11:44 243
		return false;
ce5aa7d3 sago007 2016-03-13 11:44 244
	}
ce5aa7d3 sago007 2016-03-13 11:44 245
	if (event.type == SDL_CONTROLLERBUTTONDOWN) {
ce5aa7d3 sago007 2016-03-13 11:44 246
		if (event.cbutton.button == SDL_CONTROLLER_BUTTON_A || event.cbutton.button == SDL_CONTROLLER_BUTTON_B ) {
ce5aa7d3 sago007 2016-03-13 11:44 247
			return true;
ce5aa7d3 sago007 2016-03-13 11:44 248
		}
ce5aa7d3 sago007 2016-03-13 11:44 249
	}
ce5aa7d3 sago007 2016-03-13 11:44 250
	return false;
ce5aa7d3 sago007 2016-03-13 11:44 251
}
ce5aa7d3 sago007 2016-03-13 11:44 252
016b3bf0 Poul Sander 2023-11-15 17:58 253
bool GameControllerExtIsPlayerPushEvent(int playerNumber, const SDL_Event& event) {
016b3bf0 Poul Sander 2023-11-15 17:58 254
	if (GameControllerExtSkipThisPlayer(playerNumber, event)) {
ce5aa7d3 sago007 2016-03-13 11:44 255
		return false;
ce5aa7d3 sago007 2016-03-13 11:44 256
	}
ce5aa7d3 sago007 2016-03-13 11:44 257
	if (event.type == SDL_CONTROLLERBUTTONDOWN) {
ce5aa7d3 sago007 2016-03-13 11:44 258
		if (event.cbutton.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER || event.cbutton.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER ) {
ce5aa7d3 sago007 2016-03-13 11:44 259
			return true;
ce5aa7d3 sago007 2016-03-13 11:44 260
		}
ce5aa7d3 sago007 2016-03-13 11:44 261
	}
3ee31498 sago007 2018-06-30 11:56 262
	if (event.type == SDL_CONTROLLERAXISMOTION  && (event.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT || event.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT ) ) {
016b3bf0 Poul Sander 2023-11-15 17:58 263
		GameControllerCheckDeadZone(event);
3ee31498 sago007 2018-06-30 11:56 264
		const SDL_ControllerAxisEvent& a = event.caxis;
016b3bf0 Poul Sander 2023-11-15 17:58 265
		if (GameControllerIsInDeadZone(a.which, a.axis)) {
3ee31498 sago007 2018-06-30 11:56 266
			if (event.caxis.value > deadZoneLimit) {
016b3bf0 Poul Sander 2023-11-15 17:58 267
				GameControllerSetIsInDeadZone(a.which,a.axis,false);
3ee31498 sago007 2018-06-30 11:56 268
				return true;
3ee31498 sago007 2018-06-30 11:56 269
			}
3ee31498 sago007 2018-06-30 11:56 270
		}
3ee31498 sago007 2018-06-30 11:56 271
	}
ce5aa7d3 sago007 2016-03-13 11:44 272
	return false;
66e1a55c Poul Sander 2018-12-23 16:25 273
}
1970-01-01 00:00 274