Closed dudeawsomeness1 closed 4 years ago
Help people to help you. Which example ? Which platform ?
If you're talking about the samples, on Windows you have to launch it from VS an look at the output window. I don't know about other platforms, haven't tried.
I used the "Usage" example from the main page of this repository with SFML, the project is 64-bit and I'm on Windows 10 64-bit. The samples work
#include <SFML/Graphics.hpp>
#include <iostream>
#include <gainput/gainput.h>
#define WIN_WIDTH 1280
#define WIN_HEIGHT 720
using namespace std;
enum Button
{
ButtonConfirm
};
int main() {
sf::RenderWindow window(sf::VideoMode(WIN_WIDTH, WIN_HEIGHT), "Gainput Key Finder");
gainput::InputManager manager;
manager.SetDisplaySize(WIN_WIDTH, WIN_HEIGHT);
const gainput::DeviceId keyboardId = manager.CreateDevice<gainput::InputDeviceKeyboard>();
//const gainput::DeviceId mouseId = manager.CreateDevice<gainput::InputDeviceMouse>();
//const gainput::DeviceId padId = manager.CreateDevice<gainput::InputDevicePad>();
//const gainput::DeviceId touchId = manager.CreateDevice<gainput::InputDeviceTouch>();
gainput::InputMap map(manager);
map.MapBool(ButtonConfirm, keyboardId, gainput::KeyReturn);
//map.MapBool(ButtonConfirm, mouseId, gainput::MouseButtonLeft);
//map.MapBool(ButtonConfirm, padId, gainput::PadButtonA);
//map.MapBool(ButtonConfirm, touchId, gainput::Touch0Down);
/*bool old_val = false, new_val = false;
gainput::MappedInputListener listen;
listen.OnUserButtonBool(ButtonConfirm, old_val, new_val);
map.AddListener(&listen);*/
sf::Color clearColor(255, 0, 0);
while (window.isOpen()) {
sf::Event e;
while (window.pollEvent(e)) {
if (e.type == sf::Event::Closed) window.close();
}
manager.Update();
if (map.GetBoolWasDown(ButtonConfirm)) {
clearColor = sf::Color(0, 255, 0);
}
else {
//clearColor = sf::Color(255, 0, 0);
}
window.clear(clearColor);
window.display();
}
return 0;
}
while (window.pollEvent(e)) { if (e.type == sf::Event::Closed) window.close(); }
It erased the event queue and nothing left for the library to process.
while (window.pollEvent(e)) { if (e.type == sf::Event::Closed) window.close(); }
It erased the event queue and nothing left for the library to process.
I don't see how the SFML polling loop has anything to do with the gainput stuff. Can you explain?
I tried to use SFML with Gainput too, you can't do that, unless you modify SFML quite a lot. SFML isn't meant to share the input consumption with another lib.
The loop while (window.pollEvent(e)) will consume (i.e. read and remove from event queue) all the awaiting window events, which where needed by Gainput to do its own business (on windows, keyboard events, mouse movements and clicks are retrieved as window messages : https://docs.microsoft.com/en-us/windows/win32/learnwin32/window-messages). Since SFML need to poll those events to handle window resize or window close, the inputs (keyboard, mouse, etc) are consumed as well.
My personal conclusion, as I didn't want to modify SFML, was that SFML isn't designed to be mixed with other input libraries. With SFML, only use SFML input features.
Darn, I want to implement game pad controls for my game but last I checked it wasn't possible with SFML, unless I am wrong?
I haven't tested it, but as far as I know SFML works fine with gamepads detected by windows, using the joystick API (https://www.sfml-dev.org/tutorials/2.5/window-inputs.php#joystick). Googling a bit seems to bring up people using xbox 360 controller via this API, so I guess you should be fine, theoretically.
I have the given example up and running but it does nothing