[2066] | 1 | /*! |
---|
| 2 | \file command_node.h |
---|
| 3 | \brief Parses keyboard, mouse and remote input |
---|
| 4 | |
---|
| 5 | Contains methods to parse remote and local input and handles sending of input to remote CommandNodes |
---|
| 6 | */ |
---|
| 7 | |
---|
[3224] | 8 | #ifndef _COMMAND_NODE_H |
---|
| 9 | #define _COMMAND_NODE_H |
---|
[2066] | 10 | |
---|
| 11 | |
---|
[3608] | 12 | #include "comincl.h" |
---|
| 13 | |
---|
| 14 | template<class T> class tList; |
---|
[2100] | 15 | class WorldEntity; |
---|
[3216] | 16 | class World; |
---|
[4332] | 17 | class PNode; |
---|
[2100] | 18 | |
---|
[2066] | 19 | #define N_STD_KEYS SDLK_LAST |
---|
| 20 | #define N_BUTTONS 6 |
---|
[4178] | 21 | #define DEFAULT_KEYBIND_FILE "~/.orxonox/orxonox.conf" |
---|
[2066] | 22 | |
---|
[2096] | 23 | //! Key aliasing structure |
---|
| 24 | /** |
---|
[2816] | 25 | This structure contains the key aliasing information, e.g. the command strings that |
---|
| 26 | have been bound to the keys. |
---|
[2096] | 27 | */ |
---|
[2066] | 28 | typedef struct |
---|
| 29 | { |
---|
[2816] | 30 | char keys[N_STD_KEYS][CMD_LENGHT]; |
---|
| 31 | char buttons[N_BUTTONS][CMD_LENGHT]; |
---|
[2066] | 32 | } KeyBindings; |
---|
| 33 | |
---|
[2096] | 34 | //! Command Node |
---|
| 35 | /** |
---|
[2816] | 36 | This class gathers all incoming SDL_Events and processes them. Keyboard, mouse and joystick input is |
---|
| 37 | captured and translated into command messages which are passed down to the bound WorldEntities (via WorldEntity::command()). |
---|
| 38 | Other SDL_Events are passed to Orxonox::event_handler() to deal with them. If the CommandNode has been created |
---|
| 39 | with bLocalInput set to false, it will query the network class for incoming commands that match his netID and pass |
---|
| 40 | them on to it's WorldEntities. |
---|
[2096] | 41 | */ |
---|
[2066] | 42 | class CommandNode { |
---|
| 43 | private: |
---|
[2816] | 44 | bool bLocalInput; //!< Identifies the CommandNode that processes local input |
---|
[3213] | 45 | bool bEnabled; |
---|
[2816] | 46 | int netID; //!< Unique identifier that is used to determine between remote CommandNodes |
---|
| 47 | KeyBindings* aliases; |
---|
[4332] | 48 | tList<PNode>* bound; //!< List of WorldEntites that recieve commands from this CommandNode |
---|
[2816] | 49 | Sint32 coord[2]; |
---|
[3216] | 50 | World* world; |
---|
[2816] | 51 | |
---|
| 52 | |
---|
| 53 | void relay (Command* cmd); |
---|
[3225] | 54 | int* nameToIndex (char* name); |
---|
| 55 | void processLocal (); |
---|
| 56 | void processNetwork (); |
---|
| 57 | void sendOverNetwork (Command* cmd); |
---|
[2816] | 58 | |
---|
[2066] | 59 | public: |
---|
| 60 | CommandNode (int ID); |
---|
| 61 | CommandNode (char* filename); |
---|
| 62 | ~CommandNode (); |
---|
[2816] | 63 | |
---|
[3225] | 64 | void reset (); |
---|
| 65 | void enable (bool bEnabled); |
---|
[3236] | 66 | void loadBindings (char* filename); |
---|
[4332] | 67 | void bind (PNode* entity); |
---|
| 68 | void unbind (PNode* entity); |
---|
[3225] | 69 | void addToWorld (World* world); |
---|
[2066] | 70 | void process (); |
---|
[2096] | 71 | |
---|
[3225] | 72 | void setNetID (int ID); |
---|
[2066] | 73 | }; |
---|
| 74 | |
---|
[3224] | 75 | #endif /* _COMMAND_NODE_H */ |
---|