Changeset 3238 in orxonox.OLD for orxonox/branches/nico/src/command_node.cc
- Timestamp:
- Dec 20, 2004, 2:42:54 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/nico/src/command_node.cc
r2816 r3238 20 20 #include "world_entity.h" 21 21 #include "game_loader.h" 22 #include "world.h" 22 23 23 24 #include <stdio.h> … … 33 34 CommandNode::CommandNode (int ID) 34 35 { 35 bound = new List(); 36 aliases = NULL; 37 netID = ID; 38 bLocalInput = false; 36 this->bound = new tList<WorldEntity>(); 37 this->aliases = NULL; 38 this->netID = ID; 39 this->bLocalInput = false; 40 this->bEnabled = true; 41 this->world = NULL; 39 42 } 40 43 … … 45 48 CommandNode::CommandNode (char* filename = DEFAULT_KEYBIND_FILE) 46 49 { 47 aliases = NULL; 48 bLocalInput = true; 49 netID = 0; 50 bound = new List(); 51 load_bindings (filename); 50 this->aliases = NULL; 51 this->bLocalInput = true; 52 this->netID = 0; 53 this->bound = new tList<WorldEntity>(); 54 this->bEnabled = true; 55 this->world = NULL; 56 this->loadBindings (filename); 52 57 } 53 58 … … 58 63 { 59 64 if( aliases != NULL) free (aliases); 60 if( bound != NULL) delete bound; 61 } 62 65 if( bound != NULL) delete bound; /* \todo should this delete bound? dangerous FIX */ 66 } 67 68 69 /** 70 \brief this resets the command node 71 72 deleting all data contained in the command node to fill it up again 73 74 \todo coppling to different game-entities 75 \todo reset/destroy has to be redesigned 76 */ 63 77 64 78 void CommandNode::reset() 65 79 { 66 this->bound->clear(); 67 } 80 this->bound->destroy(); 81 //this->bound = NULL; /* \todo this produces a NULLpointer error.. FIX */ 82 this->bEnabled = false; 83 this->world = NULL; 84 } 85 86 void CommandNode::enable(bool bEnabled) 87 { 88 this->bEnabled = bEnabled; 89 } 90 91 92 /** 93 \brief adds Node to a GameWorld 94 95 this is usefull, if you want to catch events in a world class. usualy 96 this is done automaticaly via GameLoader. Reset it via 97 CommandNode::reset() 98 99 */ 100 void CommandNode::addToWorld(World* world) 101 { 102 this->world = world; 103 } 104 68 105 69 106 /** … … 71 108 \param filename: The path and name of the file to load the bindings from 72 109 */ 73 void CommandNode::load _bindings (char* filename)110 void CommandNode::loadBindings (char* filename) 74 111 { 75 112 FILE* stream; … … 88 125 // create parser 89 126 IniParser parser (filename); 90 if( parser.get _section ("Bindings") == -1)127 if( parser.getSection ("Bindings") == -1) 91 128 { 92 129 printf("Could not find key bindings in %s\n", filename); … … 102 139 int* index; 103 140 104 while( parser.next _var (namebuf, valuebuf) != -1)105 { 106 index = name _to_index (namebuf);141 while( parser.nextVar (namebuf, valuebuf) != -1) 142 { 143 index = nameToIndex (namebuf); 107 144 switch( index[0]) 108 145 { 109 146 case 0: 110 printf("Key binding %d(%s) set to %s\n", index[1], SDLK _to_keyname( index[1]), valuebuf);147 printf("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), valuebuf); 111 148 strcpy (aliases->keys[index[1]], valuebuf); 112 149 break; 113 150 case 1: 114 printf("Button binding %d(%s) set to %s\n", index[1], SDLB _to_buttonname( index[1]), valuebuf);151 printf("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), valuebuf); 115 152 strcpy (aliases->buttons[index[1]], valuebuf); 116 153 break; … … 141 178 } 142 179 143 int* CommandNode::name _to_index (char* name)180 int* CommandNode::nameToIndex (char* name) 144 181 { 145 182 coord[0] = -1; 146 183 coord[1] = -1; 147 184 int c; 148 if( (c = keyname _to_SDLK (name)) != -1)185 if( (c = keynameToSDLK (name)) != -1) 149 186 { 150 187 coord[1] = c; 151 188 coord[0] = 0; 152 189 } 153 if( (c = buttonname _to_SDLB (name)) != -1)190 if( (c = buttonnameToSDLB (name)) != -1) 154 191 { 155 192 coord[1] = c; … … 164 201 void CommandNode::process () 165 202 { 166 if( bLocalInput) process_local (); 167 else process_network (); 168 } 169 170 void CommandNode::process_local () 203 if( this->bEnabled) 204 { 205 if( bLocalInput) processLocal (); 206 else processNetwork (); 207 } 208 } 209 210 void CommandNode::processLocal () 171 211 { 172 212 SDL_Event event; 173 213 Command cmd; 174 175 214 while( SDL_PollEvent (&event)) 176 215 { … … 181 220 strcpy (cmd.cmd, aliases->keys[event.key.keysym.sym]); 182 221 cmd.bUp = false; 183 if( strlen (cmd.cmd) > 0) relay 222 if( strlen (cmd.cmd) > 0) relay(&cmd); 184 223 break; 185 224 case SDL_KEYUP: 186 225 strcpy( cmd.cmd, aliases->keys[event.key.keysym.sym]); 187 226 cmd.bUp = true; 188 if( strlen (cmd.cmd) > 0) relay 227 if( strlen (cmd.cmd) > 0) relay(&cmd); 189 228 break; 190 229 case SDL_MOUSEMOTION: … … 198 237 strcpy( cmd.cmd, aliases->buttons[event.button.button]); 199 238 cmd.bUp = true; 200 if( strlen (cmd.cmd) > 0) relay 239 if( strlen (cmd.cmd) > 0) relay(&cmd); 201 240 break; 202 241 case SDL_MOUSEBUTTONDOWN: 203 242 strcpy( cmd.cmd, aliases->buttons[event.button.button]); 204 243 cmd.bUp = false; 205 if( strlen (cmd.cmd) > 0) relay 244 if( strlen (cmd.cmd) > 0) relay(&cmd); 206 245 break; 207 246 case SDL_JOYAXISMOTION: … … 213 252 default: 214 253 Orxonox *orx = Orxonox::getInstance(); 215 orx->event_handler (&event); 216 254 orx->eventHandler(&event); 217 255 break; 218 256 } … … 221 259 222 260 223 void CommandNode::process _network ()261 void CommandNode::processNetwork () 224 262 { 225 263 … … 229 267 void CommandNode::relay (Command* cmd) 230 268 { 231 269 232 270 Orxonox *orx = Orxonox::getInstance(); 233 if( orx->system_command (cmd)) return; 271 if( orx->systemCommand (cmd)) return; 272 234 273 GameLoader* gl = GameLoader::getInstance(); 235 if(gl->worldCommand(cmd)) return; 236 237 if( bLocalInput) send_over_network (cmd); 238 274 if( gl->worldCommand(cmd)) return; 275 276 if( bLocalInput) sendOverNetwork (cmd); 277 278 if( this->world->command(cmd)) return; 279 239 280 WorldEntity* entity = bound->enumerate(); 240 while( 281 while( entity != NULL) 241 282 { 242 283 entity->command (cmd); … … 250 291 \param ID: the new ID to use 251 292 */ 252 void CommandNode::set _netID (int ID)293 void CommandNode::setNetID (int ID) 253 294 { 254 295 netID = ID; 255 296 } 256 297 257 void CommandNode::send _over_network (Command* cmd)258 { 259 } 298 void CommandNode::sendOverNetwork (Command* cmd) 299 { 300 }
Note: See TracChangeset
for help on using the changeset viewer.