Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Writing a config file/converting string to sf::Event?  (Read 8046 times)

0 Members and 2 Guests are viewing this topic.

fuerchter

  • Newbie
  • *
  • Posts: 14
    • View Profile
Writing a config file/converting string to sf::Event?
« 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Writing a config file/converting string to sf::Event?
« Reply #1 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 feature of the Thor library. Example:
thor::toKeyboardKey("Escape") == sf::Keyboard::Escape
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

fuerchter

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Writing a config file/converting string to sf::Event?
« Reply #2 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?
« Last Edit: December 17, 2012, 12:03:28 am by fuerchter »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Writing a config file/converting string to sf::Event?
« Reply #3 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...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

fuerchter

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Writing a config file/converting string to sf::Event?
« Reply #4 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Writing a config file/converting string to sf::Event?
« Reply #5 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
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

fuerchter

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Writing a config file/converting string to sf::Event?
« Reply #6 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Writing a config file/converting string to sf::Event?
« Reply #7 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

fuerchter

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Writing a config file/converting string to sf::Event?
« Reply #8 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Writing a config file/converting string to sf::Event?
« Reply #9 on: December 17, 2012, 10:43:03 pm »
Quote
cmake won't accept it
Maybe you could be more precise about your errors?
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Writing a config file/converting string to sf::Event?
« Reply #10 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".
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

fuerchter

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Writing a config file/converting string to sf::Event?
« Reply #11 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
« Last Edit: December 17, 2012, 11:39:11 pm by fuerchter »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Writing a config file/converting string to sf::Event?
« Reply #12 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

fuerchter

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Writing a config file/converting string to sf::Event?
« Reply #13 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).
« Last Edit: December 19, 2012, 12:29:02 pm by fuerchter »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Writing a config file/converting string to sf::Event?
« Reply #14 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.
« Last Edit: December 19, 2012, 01:39:01 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: