-
Notifications
You must be signed in to change notification settings - Fork 39
Adding game controlers as input method #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
080e48b
c64cb72
af29b3c
f168c1c
5ca406c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ void SDLRenderingWindow::initialize(Poco::Util::Application& app) | |
// Observe user configuration changes (set via the settings window) | ||
_userConfig->propertyChanged += Poco::delegate(this, &SDLRenderingWindow::OnConfigurationPropertyChanged); | ||
_userConfig->propertyRemoved += Poco::delegate(this, &SDLRenderingWindow::OnConfigurationPropertyRemoved); | ||
|
||
_controller = FindController(); | ||
} | ||
|
||
void SDLRenderingWindow::uninitialize() | ||
|
@@ -48,6 +50,12 @@ void SDLRenderingWindow::uninitialize() | |
DestroySDLWindow(); | ||
_renderingWindow = nullptr; | ||
} | ||
|
||
if (_controller) | ||
{ | ||
SDL_GameControllerClose(_controller); | ||
_controller = nullptr; | ||
} | ||
} | ||
|
||
void SDLRenderingWindow::GetDrawableSize(int& width, int& height) const | ||
|
@@ -196,7 +204,7 @@ void SDLRenderingWindow::NextDisplay() | |
|
||
void SDLRenderingWindow::CreateSDLWindow() | ||
{ | ||
SDL_InitSubSystem(SDL_INIT_VIDEO); | ||
SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER); | ||
|
||
int width{_config->getInt("width", 800)}; | ||
int height{_config->getInt("height", 600)}; | ||
|
@@ -307,7 +315,7 @@ void SDLRenderingWindow::DestroySDLWindow() | |
SDL_DestroyWindow(_renderingWindow); | ||
_renderingWindow = nullptr; | ||
|
||
SDL_QuitSubSystem(SDL_INIT_VIDEO); | ||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER); | ||
} | ||
|
||
void SDLRenderingWindow::DumpOpenGLInfo() | ||
|
@@ -461,3 +469,69 @@ void SDLRenderingWindow::OnConfigurationPropertyRemoved(const std::string& key) | |
UpdateWindowTitle(); | ||
} | ||
} | ||
|
||
SDL_GameController* SDLRenderingWindow::FindController() { | ||
//Check for joysticks | ||
if( SDL_NumJoysticks() < 1 ) | ||
{ | ||
poco_debug(_logger, "No joysticks connected"); | ||
return nullptr; | ||
} | ||
|
||
//For simplicity, we’ll only be setting up and tracking a single | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want, you could also add a setting and an option in the settings dialog to let the user select a specific controller. Then select the stored one automatically on startup, e.g. via its name or device path (which should map to the port it is connected to). If you're not into Dear ImGui, I can also add this stuff at a later time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't knew about Dear ImGui before I had a look at this project. Adding features to the GUI is a bit over my head at the moment (my available time is scrace). Actually I'm not even into C++ but this doesn't hinder me to tinker around :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, no problem! I've got the same time issue, but I'll try my best to spend a bit of it on projectM every week 😀 Thanks again for the contribution! |
||
//controller at a time | ||
for (int i = 0; i < SDL_NumJoysticks(); i++) { | ||
if (SDL_IsGameController(i)) { | ||
poco_debug(_logger, "Adding first controller"); | ||
return SDL_GameControllerOpen(i); | ||
} | ||
else { | ||
poco_debug(_logger, "Connected joystick is not a SDL game controller"); | ||
} | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
void SDLRenderingWindow::ControllerAdd(const int id ) | ||
{ | ||
if (!_controller) | ||
{ | ||
if (SDL_IsGameController(id)) { | ||
_controller = SDL_GameControllerOpen(id); | ||
poco_debug(_logger, "Controller added!"); | ||
} | ||
else { | ||
poco_debug(_logger, "Connected joystick is not a SDL game controller"); | ||
} | ||
} | ||
} | ||
|
||
void SDLRenderingWindow::ControllerRemove(const int id ) | ||
{ | ||
if (_controller && id == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(_controller))) | ||
{ | ||
SDL_GameControllerClose(_controller); | ||
poco_debug(_logger, "Controller removed!"); | ||
_controller = FindController(); | ||
} | ||
} | ||
|
||
bool SDLRenderingWindow::ControllerIsOurs(const int id ) | ||
{ | ||
int instance = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(_controller)); | ||
|
||
if (!_controller ) | ||
{ | ||
poco_debug(_logger, "No controller initialized"); | ||
return false; | ||
} | ||
|
||
if (id != instance) | ||
{ | ||
poco_debug_f2(_logger, "Use controller %?d instead of %?d. Currently only one controller is supported", instance, id); | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -102,11 +102,6 @@ projectM.aspectCorrectionEnabled = true | |||||||
# For detailed information on how to configure logging, please refer to the POCO documentation: | ||||||||
# https://docs.pocoproject.org/current/Poco.Util.LoggingConfigurator.html | ||||||||
|
||||||||
# Set log level to debug for all components | ||||||||
#logging.loggers.root.level = debug | ||||||||
|
||||||||
|
||||||||
|
||||||||
### Logging configuration | ||||||||
|
||||||||
# Verbose log format, includes process/thread ID, source etc. | ||||||||
|
@@ -145,9 +140,13 @@ logging.channels.async.class = AsyncChannel | |||||||
logging.channels.async.channel = split | ||||||||
|
||||||||
# Default logging settings. | ||||||||
logging.loggers.root.level = information | ||||||||
logging.loggers.root.channel = async | ||||||||
|
||||||||
# Set log level to debug for all components | ||||||||
#logging.loggers.root.level = debug | ||||||||
logging.loggers.root.level = information | ||||||||
|
||||||||
|
||||||||
Comment on lines
+145
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should remove this addition here before merging, was probably a leftover from testing.
Suggested change
|
||||||||
# You can configure log levels, channels etc. for each message source (logger) individually. | ||||||||
# See https://docs.pocoproject.org/current/Poco.Util.LoggingConfigurator.html for details. | ||||||||
# Example: | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functionality was not reimplemented when rewriting the renderer, as it doesn't really fit the structure well and was quite cumbersome to use anyway. No need to add controls for something that doesn't work.