MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / main

Function main

deps/SDL2/test/testgamecontroller.c:252–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

250}
251
252int
253main(int argc, char *argv[])
254{
255 int i;
256 int nController = 0;
257 int retcode = 0;
258 char guid[64];
259 SDL_GameController *gamecontroller;
260
261 /* Enable standard application logging */
262 SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
263
264 /* Initialize SDL (Note: video is required to start event loop) */
265 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) {
266 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
267 return 1;
268 }
269
270 SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
271
272 /* Print information about the mappings */
273 if (!argv[1]) {
274 SDL_Log("Supported mappings:\n");
275 for (i = 0; i < SDL_GameControllerNumMappings(); ++i) {
276 char *mapping = SDL_GameControllerMappingForIndex(i);
277 if (mapping) {
278 SDL_Log("\t%s\n", mapping);
279 SDL_free(mapping);
280 }
281 }
282 SDL_Log("\n");
283 }
284
285 /* Print information about the controller */
286 for (i = 0; i < SDL_NumJoysticks(); ++i) {
287 const char *name;
288 const char *description;
289
290 SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
291 guid, sizeof (guid));
292
293 if ( SDL_IsGameController(i) )
294 {
295 nController++;
296 name = SDL_GameControllerNameForIndex(i);
297 switch (SDL_GameControllerTypeForIndex(i)) {
298 case SDL_CONTROLLER_TYPE_XBOX360:
299 description = "XBox 360 Controller";
300 break;
301 case SDL_CONTROLLER_TYPE_XBOXONE:
302 description = "XBox One Controller";
303 break;
304 case SDL_CONTROLLER_TYPE_PS3:
305 description = "PS3 Controller";
306 break;
307 case SDL_CONTROLLER_TYPE_PS4:
308 description = "PS4 Controller";
309 break;

Callers

nothing calls this directly

Calls 15

SDL_LogSetPriorityFunction · 0.85
SDL_InitFunction · 0.85
SDL_LogErrorFunction · 0.85
SDL_GetErrorFunction · 0.85
SDL_LogFunction · 0.85
SDL_freeFunction · 0.85
SDL_NumJoysticksFunction · 0.85
SDL_IsGameControllerFunction · 0.85

Tested by

no test coverage detected