SFML community forums

Help => Window => Topic started by: fuerchter on December 16, 2012, 02:53:33 pm

Title: Writing a config file/converting string to sf::Event?
Post by: fuerchter on December 16, 2012, 02:53:33 pm
Hi there
I hope this hasn't been asked before, I didn't search that thoroughly yet, so forgive me if it has :S

I currently have a config.cfg file from which I read strings like "Up", "Down", "Left", "Right" etc... corresponding to the buttons pressed.
Now I want those strings to be converted to a sf::Event so I can actually react to those inputs.

To make where I'm trying to go a bit more clear: I want the user to be able to change the config file to inputs like maybe replace "Up" with "Joystick1Button1" so the Up input in my game/menu would be replaced with a button on the Joystick or whatever the user enters into the config.

I would be glad if anyone could help me with this ;)
greetings
Title: Re: Writing a config file/converting string to sf::Event?
Post by: Nexus on December 16, 2012, 06:48:05 pm
SFML doesn't provide serialization, so you have to implement it yourself.

To convert between key/mouse names and the corresponding enumerator, you can use the InputNames (http://www.bromeon.ch/libraries/thor/v2.0/doc/_input_names_8hpp.html) feature of the Thor library. Example:
thor::toKeyboardKey("Escape") == sf::Keyboard::Escape
Title: Re: Writing a config file/converting string to sf::Event?
Post by: fuerchter on December 17, 2012, 12:01:33 am
Does it work with Gamepad input aswell?

//EDIT:
well, should probably read the page first lol it doesn't look like it though?

it wouldn't be that hard to write my own wrapper for that though right?
Title: Re: Writing a config file/converting string to sf::Event?
Post by: Nexus on December 17, 2012, 08:53:59 am
There are no enumerators for the joystick buttons in SFML, they are represented as numbers.

SFML has enumerators for the joystick axes, for which I could actually provide a mapping in Thor, too...
Title: Re: Writing a config file/converting string to sf::Event?
Post by: fuerchter on December 17, 2012, 09:26:02 am
I wouldn't mind that ^^

Thanks for the help! ;) In case you actually wrote that for Thor pls notify me I'll probably go on without a gamepad in the meantime.
Title: Re: Writing a config file/converting string to sf::Event?
Post by: Nexus on December 17, 2012, 10:54:14 am
Okay, I'll implement it towards the end of the week and notify you :)

Oh, and I try to do it before Friday, otherwise it's too late :D
Title: Re: Writing a config file/converting string to sf::Event?
Post by: fuerchter on December 17, 2012, 06:18:38 pm
hm, I do also have problems with cmake etc. ^^ i can't get your library working, cmake just says it won't accept the sfml path i entered :S
Title: Re: Writing a config file/converting string to sf::Event?
Post by: Nexus on December 17, 2012, 09:30:08 pm
1. Download the latest SFML and Thor versions from GitHub.
2. Install SFML according to the CMake tutorial.
3. Install Thor according to the installation tutorial.

Make sure you follow both tutorials step by step, almost all problems have resulted from people who do not read carefully.
Title: Re: Writing a config file/converting string to sf::Event?
Post by: fuerchter on December 17, 2012, 09:33:43 pm
well, i have a folder with sfml properly built (i think) but cmake won't accept it :S any special folder structure/filenames i should look out for?
Title: Re: Writing a config file/converting string to sf::Event?
Post by: Laurent on December 17, 2012, 10:43:03 pm
Quote
cmake won't accept it
Maybe you could be more precise about your errors?
Title: Re: Writing a config file/converting string to sf::Event?
Post by: Nexus on December 17, 2012, 11:10:02 pm
i have a folder with sfml properly built (i think)
Have you installed it, i.e. built the INSTALL project or typed make install?

If everything is correct, in your installed SFML folder there should be at least the directories "include" and "lib".
Title: Re: Writing a config file/converting string to sf::Event?
Post by: fuerchter on December 17, 2012, 11:37:04 pm
here is the error i get from cmake:

CMake Warning at CMakeLists.txt:86 (find_package):
  By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "SFML", but
  CMake did not find one.

  Could not find a package configuration file provided by "SFML" (requested
  version 2) with any of the following names:

    SFMLConfig.cmake
    sfml-config.cmake

  Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
  "SFML_DIR" to a directory containing one of the above files.  If "SFML"
  provides a separate development package or SDK, be sure it has been
  installed.


CMake Error at CMakeLists.txt:92 (message):
  SFML directory not found.  Set SFMLDIR to SFML's top-level path (containing
  "include" and "lib" directories).


Configuring incomplete, errors occurred!

as far as sfml goes i used cmake and then i opened the project file "ALL_BUILD.vcxproj" that cmake created and built it. the include folder that was created in the process wasn't in the sfml main folder but i pasted it there afterwards.

//EDIT:
sorry if i come across as stupid :S i never used cmake bevore
Title: Re: Writing a config file/converting string to sf::Event?
Post by: Nexus on December 19, 2012, 09:54:42 am
As stated, read the tutorials carefully. For example, you have to build the INSTALL, not the ALL_BUILD project.

I pushed the conversion functions for sf::Joystick::Axis.
Title: Re: Writing a config file/converting string to sf::Event?
Post by: fuerchter on December 19, 2012, 12:11:41 pm
even if I compiled it with the install project file it won't make a difference

now i copied the findsfml.cmake into the cmake module folder but it still doesn't go much further
Could NOT find SFML (missing:  SFML_AUDIO_LIBRARY SFML_GRAPHICS_LIBRARY SFML_WINDOW_LIBRARY SFML_SYSTEM_LIBRARY)
CMake Error at CMakeLists.txt:92 (message):
  SFML directory not found.  Set SFMLDIR to SFML's top-level path (containing
  "include" and "lib" directories).
Title: Re: Writing a config file/converting string to sf::Event?
Post by: Nexus on December 19, 2012, 01:36:45 pm
Why do you use an older Thor version? I told you to get the latest versions of SFML and Thor from GitHub.

Please read our advice in the forum and the tutorial carefully. We are really trying to help, but it is annoying if you give up at the first issue, especially when it results from not reading things. If there is a problem, try again and make sure you follow the instructions correctly. I know this needs some patience, but you would lose less time than with waiting for answers. And we don't waste our time by explaining the same things again and again.
Title: Re: Writing a config file/converting string to sf::Event?
Post by: eXpl0it3r on December 19, 2012, 02:08:57 pm
I've quickly recorded a video and showed how to build SFML and Thor with Visual Studio 2010 (it's the same process for any other Visual Studio version).
It's really not hard once you get used to it and you can make it even easier by utilizing the command line. ;)

(Watch in 720p to actually see what's going on :D)
http://www.youtube.com/watch?v=nSMjXycPhs4

I'm not sure though how long I'll keep that video up, since it's better to read and understand the official tutorials, rather than possibly outdated YouTube videos... ;)
Title: Re: Writing a config file/converting string to sf::Event?
Post by: fuerchter on December 19, 2012, 02:52:52 pm
first of all, why are you getting angry at me? i stated that i never worked with cmake before

secondly i'm sorry, but i just read past the note about the install project file (in the sfml tutorial it just says "You're now ready to compile SFML. Of course, how to do it depends on what makefiles/projects you've generated. If you created a project/solution/workspace, open it with your IDE and compile like any other project.", i didn't see on your site that it say INSTALL)

besides that i'd admit too that i didn't see you saying the github project but just the latest version (and on the website in the downloads section it represents 1.1 as latest version, granted there are github links again... >.<)

i got it to work now, but could you please have a bit more patience with someone who has never gone through this kind of build process before

//EDIT:
the string/key methods all work nicely thanks for the help guys ;)
Title: Re: Writing a config file/converting string to sf::Event?
Post by: Nexus on December 19, 2012, 03:39:57 pm
I've quickly recorded a video and showed how to build SFML and Thor with Visual Studio 2010
Thanks a lot :)


first of all, why are you getting angry at me? i stated that i never worked with cmake before
I am not angry, but I expect some initiative from users, instead of just "it doesn't work, please help". This includes at least reading the tutorials, for some reason Laurent and I write them. If you still have questions, you can of course ask here, but please try to first solve the most obvious mistakes on your own.

Apart from that, many people have already had exactly the same problem, so using the forum search can often lead to quick solutions. Consider this an advice, not a blame ;)


i didn't see on your site that it say INSTALL
Quote from: Thor Installation Tutorial (http://www.bromeon.ch/libraries/thor/v2.0/tutorial-installation.html)
IMPORTANT: Do not only compile SFML, but also install it. That means, you have to build the install target. You do that as follows:
  • Visual Studio solutions: Compile the INSTALL project.
  • NMake: Execute nmake install in the VS command line.
  • Make: Type make install in the terminal.
  • MinGW: Type mingw32-make install in the command line.
I don't know how I can make it more explicit. Maybe I should add a flashing pop-up :D
Title: Re: Writing a config file/converting string to sf::Event?
Post by: fuerchter on December 19, 2012, 04:38:14 pm
the thing is, i honestly tried installing it with the help of the tutorials but i just felt lost in all the variables and stuff that i didn't understand, it kind of seemed beyond my reach