Should input be fired as events?

This is a discussion on Should input be fired as events? within the Game Programming forums, part of the General Programming Boards category; I've just finished (almost thoroughly tested) my event manager - it's a heavy adaption of the event system presented by ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Should input be fired as events?

    I've just finished (almost thoroughly tested) my event manager - it's a heavy adaption of the event system presented by Mike McShaffry in Game Coding Complete 2nd (the only similarities are the double-buffered processing queue and the fact that I read the chapter from beginning to end countless times).

    Anyway, I was thinking. Is it a good idea to have user input go through this system? I'm thinking it might make things go groovy since input tends to come in hard and fast (right?), then again it won't be queued, just fired ASAP unlike most game events.

    Is this question answerable or is it one of those times where I should try two/three different approaches and decide which is best based on benchmarking etc?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    I've never really even thought of handling input through events. I just check for key presses and mouse movement each frame and that's it.

    What's the advantage of an event system for this? (actually, I'm not even sure if I know exactly what kind of events you're talking about. the only events I know are GUI events.)
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  3. #3
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    With games running 60+ fps, checking key/mouse/joystick states once per frame is pretty effective. Unless you think the user is going to be pressing the keys for less than .0167 seconds... If your game doesn't run that fast, you'd better hope your input system is running on a different thread.
    Don't quote me on that... ...seriously

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    I believe that people refrain from using Win32's input notifications for a reason, opting for the faster asynchronous calls to the keyboard and mouse. As such, you would only be reinventing the wheel by running it through your system as opposed to just using the win32 model.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    I have the same book but could not for the life of me figure out why he did input that way. I see nothing wrong with polled input as long as your game is running reasonably well. It well may die at 5 to 7 FPS but then so will the rendering so there isn't much point to accepting input when the game is barely running.

    For mouse and keyboard I poll, store the results, and respond in the same frame.

    If you are using a message based system and I assume you are then you can poll, respond to the device state via storing messages, and then route the messages to the appropriate handlers. I never found much use for buffered input via DirectInput.
    Last edited by VirtualAce; 04-11-2007 at 03:47 AM.

  6. #6
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    OK, thanks for the thoughts all.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 01:59 AM
  2. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-29-2007, 11:16 PM
  3. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  4. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 12:22 AM
  5. Help with Input Checking
    By Derek in forum C Programming
    Replies: 7
    Last Post: 06-17-2003, 03:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21