inp::InputQueue Class Reference

Input event queue class. More...

#include <inp_queue.hh>

List of all members.

Public Member Functions

void Enable (const bool enableJoystick)
uint KeyQueueCnt (void)
uint JoyQueueCnt (void)
bool DequeueKeyEvent (Keyboard::Event &event)
bool DequeueJoyEvent (Joystick::Event &event)
void Flush (void)
void Tick (void)
bool IfEnabled (void)
void EnqueueKeyEvent (const Keyboard::Event &event)
void EnqueueJoyEvent (const Joystick::Event &event)

Private Member Functions

 InputQueue (void)
 ~InputQueue ()

Private Attributes

bool mEnabled
deque< Keyboard::EventmKeyQueue
deque< Joystick::EventmJoyQueue

Friends

class Global


Detailed Description

Input event queue class.

///
/// Rationale:
/// ----------
/// Input events should be put into a queue and processed synchronously at
/// an appropriate time, rather than asynchronously.  The reason is that an
/// input event shouldn't be processed in the middle of drawing a view,
/// or worse, while processing an inappropriate view (such as an enemy view
/// which would affect the enemy rather than the player).
///
/// Integration:
/// ------------
/// A module's timer-tick callback is supposed to call InputQueue::Tick()
/// in order to feed the input queue.  Engine has no need of input events.
/// Initially, the input queue is disabled.  When a module is ready
/// to respond to input events, the module should call InputQueue::Enable().
///
/// How to use this class:
/// ----------------------
/// - Note: InputQueue is a global (it should be instantiated by a module).
/// - A module's timer-tick handler should call InputQueue::Tick().
///   InputQueue::Tick() polls input devices and enqueues events.
/// - When module is ready, it should call InputQueue::Enable().
/// - Client can call InputQueue::*Events() to query
///   the amount of events in a single queue.
/// - Keyboard and joystick events can be dequeued out of separate queues
///   by calling GetKey() and GetJoy().  The idea is for a client
///   to poll input prior to drawing a frame.
/// - The client is responsible for dropping events if the program runs slowly.
///   Whether older or newer events are processed or discarded is a policy
///   decided by the client.
///
/// Queues and queue sizes:
/// -----------------------
/// Each input device has its own queue.  This helps in the situation
/// where the application is able to keep pace with one input device but
/// another is being enqueued too quickly.  The application can process
/// events in one queue while dropping events in another queue.
///
/// Implementation:
/// ---------------
/// Enqueueing of keyboard and joystick events are similar but asymmetrical.
/// Both Keyboard and Joystick classes use InputQueue to queue events.
/// Keyboard events are pushed out by GLUT to callbacks (async I/O),
/// but joystick events must be dequeued by a timer-tick handler (polling I/O).
/// Polling isn't as bad in this case because the Linux joystick driver
/// internally queues joystick events (InputQueue forms a queue-over-a-queue).
///
/// Other sources of input and InputQueue:
/// --------------------------------------
/// Other sources of input that aren't enqueued in InputQueue (mouse events)
/// should disable themselves if InputQueue is disabled, as a disabled InputQueue
/// is a kind of input control flag.
///
/// 

Constructor & Destructor Documentation

inp::InputQueue::InputQueue ( void   )  [private]

ctor initially disables input queue. When Engine/Module is ready, it should call InputQueue::Enable().

inp::InputQueue::~InputQueue (  )  [private]


Member Function Documentation

void inp::InputQueue::Enable ( const bool  enableJoystick  ) 

Enable the input queue (initially disabled). Tolerates being called more than once. This should be called after a module is ready to respond to input events.

uint inp::InputQueue::KeyQueueCnt ( void   ) 

Returns:
Amount of events in keyboard queue.

uint inp::InputQueue::JoyQueueCnt ( void   ) 

Returns:
Amount of events in joystick queue.

bool inp::InputQueue::DequeueKeyEvent ( Keyboard::Event event  ) 

Dequeue the next keyboard event.

Returns:
False if no more keyboard events.

bool inp::InputQueue::DequeueJoyEvent ( Joystick::Event event  ) 

Dequeue the next joystick event.

Returns:
False if no more joystick events.

void inp::InputQueue::Flush ( void   ) 

Flush all queues.

void inp::InputQueue::Tick ( void   ) 

Pulsed by a timer tick to poll input devices. Must be called by the application's timer handler (to feed the queue).

bool inp::InputQueue::IfEnabled ( void   )  [inline]

void inp::InputQueue::EnqueueKeyEvent ( const Keyboard::Event event  ) 

Enqueue a keyboard event.

void inp::InputQueue::EnqueueJoyEvent ( const Joystick::Event event  ) 

Enqueue a joystick event.


Friends And Related Function Documentation

friend class Global [friend]


Member Data Documentation

bool inp::InputQueue::mEnabled [private]

deque<Keyboard::Event> inp::InputQueue::mKeyQueue [private]

deque<Joystick::Event> inp::InputQueue::mJoyQueue [private]


The documentation for this class was generated from the following files: Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:28 2007