InputManager Class Reference

#include <inputmanager.h>

Inherits Mutex.

Inheritance diagram for InputManager:

Inheritance graph
[legend]
Collaboration diagram for InputManager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 InputManager ()
 ~InputManager ()
void addInputAcceptor (InputAcceptor &ia)
 Add input acceptor to input acceptors list mIAVector.
void removeInputAcceptor (InputAcceptor &ia)
 Return input acceptor from input acceptors list.
void checkSDLEvents ()
 Read input from SDL.
void processKeys ()
 Process keys stored in queue mKeys.
void keyDown (SDL_keysym keysym)
 Proces one key.
void WantAllInput (bool wanted=true)
 Send all input to queue for processing and none to netwok.
void setKeyReceiver (int key, InputAcceptor *receiver)
 Set forwaring of one key to input acceptor.
void setNetAcceptor (InputAcceptor *netAcceptor)
 Set acceptor that receive input from keyDown that nobody wants. Note that mNetAcceptor isn't locked so be sure that only one game thread is running when calling this or call this from network thread.

Private Member Functions

 InputManager (const InputManager &im)
 Disable copying inpit manager.

Private Attributes

std::map< int, InputAcceptor * > mIAVector
 list of input wanters
std::queue< SDL_keysym > mKeys
InputAcceptormWantedKeys_mainThread [SDLK_LAST]
InputAcceptormWantedKeys_netThread [SDLK_LAST]
int mAllInputWanters
 Number of components that would like to ket full input.
InputAcceptormNetAcceptor

Detailed Description

Definition at line 16 of file inputmanager.h.


Constructor & Destructor Documentation

InputManager::InputManager  ) 
 

Definition at line 15 of file inputmanager.cpp.

References mAllInputWanters, mNetAcceptor, mWantedKeys_mainThread, mWantedKeys_netThread, and TIN.

InputManager::~InputManager  ) 
 

Definition at line 30 of file inputmanager.cpp.

InputManager::InputManager const InputManager im  )  [private]
 

Disable copying inpit manager.

The InputManager shoudn't be copied. Anyway if you call this private method, the application fails.

Definition at line 35 of file inputmanager.cpp.

References DIE(), and LOGE.

Here is the call graph for this function:


Member Function Documentation

void InputManager::addInputAcceptor InputAcceptor ia  ) 
 

Add input acceptor to input acceptors list mIAVector.

Note that InputAcceptor doesn't need to be registered in list unless it needs to get all input at some point.

Parameters:
ia input acceptor that should be added. Priority of acceptor will be determined by calling ia.getNice() The priority MUST be unique.

Definition at line 41 of file inputmanager.cpp.

References InputAcceptor::getNice(), LOGT, mIAVector, and TIN.

Referenced by Messages::init(), and Console::init().

Here is the call graph for this function:

void InputManager::checkSDLEvents  ) 
 

Read input from SDL.

This may be called from separate thread. When engine is running it will be in thread togehter with network. Check against mWantedKeys_netThread and if position with key is != 0, the key is added to queue mKeys with keys waiting for processing. The key is put into queue also when mWantedAllInput is true.

Definition at line 55 of file inputmanager.cpp.

References Game::endFun(), getAppClient(), ApplicationClient::getGame(), keyDown(), LOGD, and TIN.

Referenced by GameClient::run().

Here is the call graph for this function:

void InputManager::keyDown SDL_keysym  keysym  ) 
 

Proces one key.

If you want to process SDL events on you own and only use this for keys handlidg simply call this when you get new key.

Definition at line 92 of file inputmanager.cpp.

References InputAcceptor::keyDown(), Mutex::lock(), LOGD, LOGE, mAllInputWanters, mKeys, mNetAcceptor, mWantedKeys_netThread, TIN, and Mutex::unlock().

Referenced by checkSDLEvents().

Here is the call graph for this function:

void InputManager::processKeys  ) 
 

Process keys stored in queue mKeys.

This should be called from engine. Check against mWantedKeys_mainThread and calls input acceptors.

Definition at line 134 of file inputmanager.cpp.

References InputAcceptor::keyDown(), Mutex::lock(), LOGE, LOGT, mAllInputWanters, mIAVector, mKeys, mWantedKeys_mainThread, TIN, and Mutex::unlock().

Referenced by GameClient::run().

Here is the call graph for this function:

void InputManager::removeInputAcceptor InputAcceptor ia  ) 
 

Return input acceptor from input acceptors list.

Parameters:
ia input acceptor that should be removed.

Definition at line 48 of file inputmanager.cpp.

References InputAcceptor::getNice(), mIAVector, and TIN.

Referenced by Messages::clean(), and Console::clean().

Here is the call graph for this function:

void InputManager::setKeyReceiver int  key,
InputAcceptor receiver
 

Set forwaring of one key to input acceptor.

Note that the acceptor doesn't need to be rigistered by add InputAcceptor. This will cause forwarding one key to input acceptor. InputAcceptor may call this function more times to receive more keys. Note that this function should be called only when you are sure that the game is only in one thread since it modify mWantedKeys_mainThread and mWantedKeys_netThread.

Parameters:
key key to forward. Use keys from SDL (like SDLK_e,..)
receiver input acceptor that want to receive this key. by setting to NULL you may cancel forwading keys.

Definition at line 196 of file inputmanager.cpp.

References mWantedKeys_mainThread, and mWantedKeys_netThread.

Referenced by Messages::clean(), Console::clean(), Messages::init(), and Console::init().

void InputManager::setNetAcceptor InputAcceptor netAcceptor  ) 
 

Set acceptor that receive input from keyDown that nobody wants. Note that mNetAcceptor isn't locked so be sure that only one game thread is running when calling this or call this from network thread.

Parameters:
netAcceptor network acceptor. May be 0.

Definition at line 203 of file inputmanager.cpp.

References mNetAcceptor.

void InputManager::WantAllInput bool  wanted = true  ) 
 

Send all input to queue for processing and none to netwok.

Component that wants all input may set this to true and then all input will go to queue. It also must be in mIAVector if it wants to get the input. mAllInputWanters will automaticly set to 0 when some key will pass all components in mIAVector and noone will want it.

Parameters:
wanted You may set to false if you want to be polite and decrease mAllInputWanters. Note that you may lost one key for network network if you will not be polite.

Definition at line 182 of file inputmanager.cpp.

References Mutex::lock(), mAllInputWanters, and Mutex::unlock().

Referenced by Messages::keyDown(), and Console::keyDown().

Here is the call graph for this function:


Member Data Documentation

int InputManager::mAllInputWanters [private]
 

Number of components that would like to ket full input.

Definition at line 134 of file inputmanager.h.

Referenced by InputManager(), keyDown(), processKeys(), and WantAllInput().

std::map<int,InputAcceptor*> InputManager::mIAVector [private]
 

list of input wanters

Definition at line 118 of file inputmanager.h.

Referenced by addInputAcceptor(), processKeys(), and removeInputAcceptor().

std::queue<SDL_keysym> InputManager::mKeys [private]
 

list of pressed keys that are waiting for processing. This variable must be locked

Definition at line 124 of file inputmanager.h.

Referenced by keyDown(), and processKeys().

InputAcceptor* InputManager::mNetAcceptor [private]
 

Definition at line 136 of file inputmanager.h.

Referenced by InputManager(), keyDown(), and setNetAcceptor().

InputAcceptor* InputManager::mWantedKeys_mainThread[SDLK_LAST] [private]
 

Definition at line 127 of file inputmanager.h.

Referenced by InputManager(), processKeys(), and setKeyReceiver().

InputAcceptor* InputManager::mWantedKeys_netThread[SDLK_LAST] [private]
 

Definition at line 129 of file inputmanager.h.

Referenced by InputManager(), keyDown(), and setKeyReceiver().


The documentation for this class was generated from the following files:
Generated on Wed Apr 12 14:17:53 2006 for bjs by  doxygen 1.4.5