• Home
  • Products
    • Game Engine
      • Base
      • Mathematics
      • Geometry
      • Physics
      • Particles
      • Animation
      • Graphics
      • Game
      • Game UI
    • Windows Forms
      • Docking Windows
      • Text Editor Control
  • Downloads
  • Buy
    • Overview
    • Professional
    • Indie
    • Non-Commercial
  • Support
    • Overview
    • Blog
    • Forum
    • License FAQ
    • Documentation
  • About
    • About Us
      • Services
    • Contact Us
    • Press
    • Legal Terms
      • Imprint (English)
      • Imprint (German)
Select the search type
 
  • Site
  • Web
Search
DigitalRune.com
Login |Register
NEWS News RSS Feed BLOG Blog RSS Feed FORUM News RSS Feed DOCUMENTATION DigitalRune Software on YouTube DigitalRune Software on Twitter
You are here: SupportForum

If you want to contribute to the forum discussions, please Register or Login.

SearchHome
  • 1
  • 2
  • 3
  • 4
  • 5
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineGame.Input - Input eventsGame.Input - Input events
Previous
 
Next
New Post
12/15/2011 10:32 PM
 
Batch
No Ranking

Joined: 12/15/2011
Posts: 3
Game.Input - Input events 

Is there any specific reason why the input manager does not implement an event system for notifying objects of input events?

public delegate void KeyboardInputEvent(Keys p_key, bool p_isHandled);
public event KeyboardInputEvent ThrowPlayer1InputPressed;
public event KeyboardInputEvent ThrowPlayer1InputHeld;
public event KeyboardInputEvent ThrowPlayer1InputReleased;

Create a listener interface which objects should inherit:

public Interface IKeyboardListener{
    public void OnKeyPress(Keys p_key, bool p_isHandled);
    public void OnKeyHeld(Keys p_key, bool p_isHandled);
    public void OnKeyRelease(Keys p_key, bool p_isHandled);
}

And expose a method in the manager to allow an IKeyboardListener to register for these events

public void AddKeyboardListener(IKeyboardListener p_listener, LogicalPlayerIndex p_index){
   switch(p_index){
        case LogicalPlayerIndex.One:
            ThrowPlayer1KeyPress += p_listener.OnKeyPress;
            ThrowPlayer1KeyHeld += p_listener.OnKeyHeld;
            ThrowPlayer1KeyRelease += p_listener.OnKeyRelease;
            break;
    }
}

Input event notification systems tend to be more common nowadays. This prevents having to check for specific input presses each frame, within each object needing to to handle input.

Alternatively, rather than creating events for each input device crossed with each player, and having to manually check if the input "isHandled" parameter,  simply maintain a Dictionary<LogicalPlayerIndex, HashSet<IKeyboardListeners> > and iterate through the HashSets for the specific player index, terminating the iteration whenever the input has been handled (change the interface methods from void the bool and remove the "isHandled" parameter)

 
New Post
12/16/2011 10:14 AM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Game.Input - Input events 

Good question. Our game libraries usually do not provide many events on purpose.
There are specific reasons for avoiding event systems: Multithreading and input routing.

In a multithreaded game the game subsystems (input, graphics, physics, animation, particles, network, AI, ...) should be able to execute in parallel. While these systems are running in parallel, it is not allowed to influence their states from outside (e.g. while the physics simulation is updating another subsystem must not change the rigid body states because that would be a write-write conflict).
Now, if those systems raise events (like keyboard events, collision events, etc.) while they are running, then the event listener can receive the event but is not currently allowed to react on the event. For example, a game object listens to the left mouse button event and wants to move a rigid body in response. When the game object receives the event, it cannot immediately change the physics state because the physics is currently updating.
That means, subsystem events have to be deferrred until  the execution is thread-safe, or the event listeners must only note the occurance of the event and react to it later when it is thread-safe. Both options kind of defeat the purpose of an event system.

Also, the game logic might want to consume the events in a specific order. The window that is currently on top should handle input first. Or while a game object is executing a drag-and-drop operation, it should receive the input before the top-most window.
It is difficult for the input system to push the information in the correct order. But it is easy for game objects to pull informations in a specific, dynamic order - even in parallel.
Further, some game objects might want to react to device input even if this device input was already handled by another game object.

Event-driven architectures work great for desktop application but are limiting for game-loop-driven systems. With our current design it is still possible to add an event system if needed. (After the input manager has finished, simply iterate over the state and raise some events.)

This is a complicated topic, and to summarize:  I don't know how to use an event system without limiting parallelism or introducing multi-threading problems and other headaches. We have settled on the current design after researching and testing parallel game architecture options (double-buffering, pipelining, etc.).

 
New Post
12/16/2011 4:11 PM
 
Batch
No Ranking

Joined: 12/15/2011
Posts: 3
Re: Game.Input - Input events 

Wow.... what a great response. I hadn't thought about the multi-threading aspect, but your reasoning makes perfect sense.

A few years back, I created a small game engine in XNA 3.0 for a software methodology project class. The architecture of my engine is almost identical to the architecture of DigitalRune Engine. The engine provides all of the independent services and the game specific code is the glue between them. I stumbled upon your engine one day when looking for a good third-party GUI system and felt like I stepped forward in time and found something that I could have written in the future. My next (4th) iteration of the engine was supposed to be a complete redesign to make use of multi-threading but it seems that your engine is already leaps and bounds ahead of my own.

 I look forward to working with something written by others who take the time necessary to correctly implement features after carefully considering the benefits and drawbacks. I am currently talking with a few other individuals to develop an indie game for PC/XBOX and will be suggesting the use of the DigitalRune Engine. Thank you for all the hard work and great job!

 
New Post
12/16/2011 5:12 PM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Game.Input - Input events 
Batch wrote:

 The engine provides all of the independent services and the game specific code is the glue between them.

Exactly! I think we have the same sentence in our design documents ;-)

Batch wrote:

I am currently talking with a few other individuals to develop an indie game for PC/XBOX and will be suggesting the use of the DigitalRune Engine. Thank you for all the hard work and great job!

 Thanks.

 
 Page 1 of 1
Previous
 
Next
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineGame.Input - Input eventsGame.Input - Input events


DigitalRune is a trademark of Garstenauer Information Technology OG.

Garstenauer Information Technology OG
Weingartenstrasse 35, 4452 Ternberg
Austria (EUROPE)
office@digitalrune.com

Home Products Downloads Buy Support About Us
Game Engine Particles Windows Forms Professional Blog Services
Base Animation Docking Windows Indie Forum Contact Us
Mathematics Graphics Text Editor Control Non-Commercial License FAQ Press (News)
Geometry Game Documentation Legal Terms
Physics Game UI Imprint
Impressum
Copyright © 2006-2012 Garstenauer Information Technology OG Terms Of UsePrivacy Statement