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