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

Author Topic: Global input vs event?  (Read 2912 times)

0 Members and 1 Guest are viewing this topic.

freesoul

  • Newbie
  • *
  • Posts: 19
    • View Profile
Global input vs event?
« on: August 13, 2013, 07:37:58 pm »
What is better way to get input of mouse/keyboard for a game? Events, or testing global input?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Global input vs event?
« Reply #1 on: August 13, 2013, 07:55:19 pm »
Please read the tutorials, they explain exactly this kind of stuff :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

freesoul

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Global input vs event?
« Reply #2 on: August 13, 2013, 08:44:00 pm »
In which tutorial can I find which system is better? I could read what does events and what does global input, but I didn't find which I should use
« Last Edit: August 13, 2013, 08:46:33 pm by freesoul »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Global input vs event?
« Reply #3 on: August 13, 2013, 08:47:27 pm »
None is "better". They have different use cases.

Read:
http://www.sfml-dev.org/tutorials/2.1/window-events.php
http://www.sfml-dev.org/tutorials/2.1/window-inputs.php

If you understand what they're doing, then you'll know which one to use where. Besides, it's also explicitly mentioned.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

MorleyDev

  • Full Member
  • ***
  • Posts: 219
  • "It is not enough for code to work."
    • View Profile
    • http://www.morleydev.co.uk/
Re: Global input vs event?
« Reply #4 on: August 13, 2013, 10:57:53 pm »
Although those documentations does not explicitly explain why one would choose one over the other. It doesn't explain why you'd want to query the state of a keyboard as opposed to using events or vice-versa. Admittedly that's a wider discussion in "game coding" but none-the-less, I can see why it'd be a legitimate question what situations one is better than the over.
 
Heck, I'd say
Quote
Sometimes, people try to use the KeyPressed event to implement smooth movement. Doing so will not produce smooth movements, because when you hold a key you only get a few events (remember, the repeat delay). Smooth movements can only be achieved by using real-time keyboard input with sf::Keyboard (see the dedicated tutorial).
is downright misleading. Smooth movement is perfectly possible with events, it's just the way you go about it is different. Not "Can I move? If so, move" but "Apply velocity on press, Remove velocity on release".
« Last Edit: August 13, 2013, 11:01:57 pm by MorleyDev »
UnitTest11 - A unit testing library in C++ written to take advantage of C++11.

All code is guilty until proven innocent, unworthy until tested, and pointless without singular and well-defined purpose.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Global input vs event?
« Reply #5 on: August 13, 2013, 11:08:16 pm »
I would say, the first paragraph is very clear regarding the different use cases:
Quote
This tutorial explains how to access global inputs: keyboard, mouse and joysticks. This must not be confused with events: real-time inputs allow you to query the global state of keyboard, mouse and joysticks at any time ("is this button currently pressed?", "where is the mouse?") while events notify you when something happens ("this button was pressed", "the mouse has moved").

You're right that one cannot know when to use which for a specific game, but some concrete application scenarios are then listed in the respective tutorials.

However I agree that the sentence concerning smooth movements should be clarified.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

MorleyDev

  • Full Member
  • ***
  • Posts: 219
  • "It is not enough for code to work."
    • View Profile
    • http://www.morleydev.co.uk/
Re: Global input vs event?
« Reply #6 on: August 13, 2013, 11:19:51 pm »
I'd say it's explaining the difference in functionality. It's saying how real-time says how things are, and events says when things change. Those tutorials are very good at explaining the difference in functionality, and that's a good thing.

What they aren't is game code design tutorials or discussions on approaches to structuring game code and I believe this is more that freesoul here is asking about: To know the high level design reasons one would choose one over the other. And that's a more complex discussion with a lot more nuance than those tutorials allow/need.
« Last Edit: August 13, 2013, 11:27:11 pm by MorleyDev »
UnitTest11 - A unit testing library in C++ written to take advantage of C++11.

All code is guilty until proven innocent, unworthy until tested, and pointless without singular and well-defined purpose.

 

anything