Changeset 3238 in orxonox.OLD for orxonox/branches/buerli/src/command_node.cc
- Timestamp:
- Dec 20, 2004, 2:42:54 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/buerli/src/command_node.cc
r2707 r3238 11 11 ### File Specific: 12 12 main-programmer: Christian Meyer 13 co-programmer: ...13 co-programmer: Patrick Boenzli 14 14 */ 15 15 … … 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<WorldEntity>(); 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<WorldEntity>(); 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 } 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 */ 77 78 void CommandNode::reset() 79 { 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 62 105 63 106 /** … … 65 108 \param filename: The path and name of the file to load the bindings from 66 109 */ 67 void CommandNode::load _bindings (char* filename)110 void CommandNode::loadBindings (char* filename) 68 111 { 69 112 FILE* stream; … … 82 125 // create parser 83 126 IniParser parser (filename); 84 if( parser.get _section ("Bindings") == -1)127 if( parser.getSection ("Bindings") == -1) 85 128 { 86 129 printf("Could not find key bindings in %s\n", filename); … … 96 139 int* index; 97 140 98 while( parser.next _var (namebuf, valuebuf) != -1)99 { 100 index = name _to_index (namebuf);141 while( parser.nextVar (namebuf, valuebuf) != -1) 142 { 143 index = nameToIndex (namebuf); 101 144 switch( index[0]) 102 145 { 103 146 case 0: 104 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); 105 148 strcpy (aliases->keys[index[1]], valuebuf); 106 149 break; 107 150 case 1: 108 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); 109 152 strcpy (aliases->buttons[index[1]], valuebuf); 110 153 break; … … 123 166 void CommandNode::bind (WorldEntity* entity) 124 167 { 125 bound->add (entity , LIST_ADD_NEXT, true);168 bound->add (entity); 126 169 } 127 170 … … 132 175 void CommandNode::unbind (WorldEntity* entity) 133 176 { 134 bound->remove (entity , LIST_FIND_FW);135 } 136 137 int* CommandNode::name _to_index (char* name)177 bound->remove (entity); 178 } 179 180 int* CommandNode::nameToIndex (char* name) 138 181 { 139 182 coord[0] = -1; 140 183 coord[1] = -1; 141 184 int c; 142 if( (c = keyname _to_SDLK (name)) != -1)185 if( (c = keynameToSDLK (name)) != -1) 143 186 { 144 187 coord[1] = c; 145 188 coord[0] = 0; 146 189 } 147 if( (c = buttonname _to_SDLB (name)) != -1)190 if( (c = buttonnameToSDLB (name)) != -1) 148 191 { 149 192 coord[1] = c; … … 158 201 void CommandNode::process () 159 202 { 160 if( bLocalInput) process_local (); 161 else process_network (); 162 } 163 164 void CommandNode::process_local () 203 if( this->bEnabled) 204 { 205 if( bLocalInput) processLocal (); 206 else processNetwork (); 207 } 208 } 209 210 void CommandNode::processLocal () 165 211 { 166 212 SDL_Event event; 167 213 Command cmd; 168 169 214 while( SDL_PollEvent (&event)) 170 215 { … … 175 220 strcpy (cmd.cmd, aliases->keys[event.key.keysym.sym]); 176 221 cmd.bUp = false; 177 if( strlen (cmd.cmd) > 0) relay 222 if( strlen (cmd.cmd) > 0) relay(&cmd); 178 223 break; 179 224 case SDL_KEYUP: 180 225 strcpy( cmd.cmd, aliases->keys[event.key.keysym.sym]); 181 226 cmd.bUp = true; 182 if( strlen (cmd.cmd) > 0) relay 227 if( strlen (cmd.cmd) > 0) relay(&cmd); 183 228 break; 184 229 case SDL_MOUSEMOTION: … … 192 237 strcpy( cmd.cmd, aliases->buttons[event.button.button]); 193 238 cmd.bUp = true; 194 if( strlen (cmd.cmd) > 0) relay 239 if( strlen (cmd.cmd) > 0) relay(&cmd); 195 240 break; 196 241 case SDL_MOUSEBUTTONDOWN: 197 242 strcpy( cmd.cmd, aliases->buttons[event.button.button]); 198 243 cmd.bUp = false; 199 if( strlen (cmd.cmd) > 0) relay 244 if( strlen (cmd.cmd) > 0) relay(&cmd); 200 245 break; 201 246 case SDL_JOYAXISMOTION: … … 207 252 default: 208 253 Orxonox *orx = Orxonox::getInstance(); 209 orx->event_handler (&event); 210 254 orx->eventHandler(&event); 211 255 break; 212 256 } … … 214 258 } 215 259 216 void CommandNode::process_network () 217 { 218 219 } 260 261 void CommandNode::processNetwork () 262 { 263 264 } 265 220 266 221 267 void CommandNode::relay (Command* cmd) 222 268 { 223 //printf("CommandNode|relay()\n"); 224 List<WorldEntity>* plist = bound; 225 269 226 270 Orxonox *orx = Orxonox::getInstance(); 227 if( orx->system_command (cmd)) return; 271 if( orx->systemCommand (cmd)) return; 272 228 273 GameLoader* gl = GameLoader::getInstance(); 229 if(gl->worldCommand(cmd)) return; 230 231 if( bLocalInput) send_over_network (cmd); 232 233 while( (plist = plist->get_next()) != NULL) 234 { 235 plist->get_object()->command (cmd); 236 } 237 } 274 if( gl->worldCommand(cmd)) return; 275 276 if( bLocalInput) sendOverNetwork (cmd); 277 278 if( this->world->command(cmd)) return; 279 280 WorldEntity* entity = bound->enumerate(); 281 while( entity != NULL) 282 { 283 entity->command (cmd); 284 entity = bound->nextElement(); 285 } 286 } 287 238 288 239 289 /** … … 241 291 \param ID: the new ID to use 242 292 */ 243 void CommandNode::set _netID (int ID)293 void CommandNode::setNetID (int ID) 244 294 { 245 295 netID = ID; 246 296 } 247 297 248 void CommandNode::send _over_network (Command* cmd)249 { 250 } 298 void CommandNode::sendOverNetwork (Command* cmd) 299 { 300 }
Note: See TracChangeset
for help on using the changeset viewer.