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