add sdl2 directive checks

This commit is contained in:
theredbluecube2@gmail.com 2025-12-07 13:54:01 +03:00
parent 92a3b6e20a
commit df951db538

View File

@ -7,7 +7,9 @@
#include <ncurses.h> #include <ncurses.h>
#include <ctime> #include <ctime>
#include <unistd.h> #include <unistd.h>
#ifdef WITH_SDL2
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#endif
#include "Board.h" #include "Board.h"
#ifndef _WIN32 #ifndef _WIN32
#include <signal.h> #include <signal.h>
@ -21,7 +23,9 @@ void handleSIGWINCH(int sig)
#define MAX_TIME 60 #define MAX_TIME 60
#ifdef WITH_SDL2
SDL_GameController *controller; SDL_GameController *controller;
#endif
void startGame(Board &board) void startGame(Board &board)
{ {
@ -163,6 +167,7 @@ void startGame(Board &board)
} }
c = getch(); c = getch();
#ifdef WITH_SDL2
if (c == ERR) if (c == ERR)
{ {
if (controller != nullptr) if (controller != nullptr)
@ -270,6 +275,7 @@ void startGame(Board &board)
} }
} }
} }
#endif
if (!(c == ERR)) if (!(c == ERR))
{ {
@ -438,6 +444,7 @@ void startGame(Board &board)
} }
} }
#ifdef WITH_SDL2
SDL_GameController *findController() SDL_GameController *findController()
{ {
for (int i = 0; i < SDL_NumJoysticks(); i++) for (int i = 0; i < SDL_NumJoysticks(); i++)
@ -450,6 +457,7 @@ SDL_GameController *findController()
return nullptr; return nullptr;
} }
#endif
int main() int main()
{ {
@ -466,6 +474,7 @@ int main()
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
#endif #endif
#ifdef WITH_SDL2
bool controllerSupport; bool controllerSupport;
if (SDL_Init(SDL_INIT_GAMECONTROLLER) < 0) if (SDL_Init(SDL_INIT_GAMECONTROLLER) < 0)
@ -481,6 +490,7 @@ int main()
controller = findController(); controller = findController();
if (controller != nullptr) if (controller != nullptr)
controllerSupport = false; // no controller for you controllerSupport = false; // no controller for you
#endif
start_color(); start_color();
init_pair(1, COLOR_BLUE, COLOR_BLACK); init_pair(1, COLOR_BLUE, COLOR_BLACK);