Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3238 in orxonox.OLD for orxonox/branches/buerli/src/command_node.cc


Ignore:
Timestamp:
Dec 20, 2004, 2:42:54 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches: updated branches: buerli, nico, sound. And moved bezierTrack to old.bezierTrack. Conflicts resolved in a usefull order.
Conflics mostly resolved in favor of trunk
merge.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/buerli/src/command_node.cc

    r2707 r3238  
    1111   ### File Specific:
    1212   main-programmer: Christian Meyer
    13    co-programmer: ...
     13   co-programmer: Patrick Boenzli
    1414*/
    1515
     
    2020#include "world_entity.h"
    2121#include "game_loader.h"
     22#include "world.h"
    2223
    2324#include <stdio.h>
     
    3334CommandNode::CommandNode (int ID)
    3435{
    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;
    3942}
    4043
     
    4548CommandNode::CommandNode (char* filename = DEFAULT_KEYBIND_FILE)
    4649{
    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);
    5257}
    5358
     
    5863{
    5964  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
     78void 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
     86void 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*/
     100void CommandNode::addToWorld(World* world)
     101{
     102  this->world = world;
     103}
     104
    62105
    63106/**
     
    65108   \param filename: The path and name of the file to load the bindings from
    66109*/
    67 void CommandNode::load_bindings (char* filename)
     110void CommandNode::loadBindings (char* filename)
    68111{
    69112  FILE* stream;
     
    82125  // create parser
    83126  IniParser parser (filename);
    84   if( parser.get_section ("Bindings") == -1)
     127  if( parser.getSection ("Bindings") == -1)
    85128    {
    86129      printf("Could not find key bindings in %s\n", filename);
     
    96139  int* index;
    97140 
    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);
    101144      switch( index[0])
    102145        {
    103146        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);
    105148          strcpy (aliases->keys[index[1]], valuebuf);
    106149          break;
    107150        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);
    109152          strcpy (aliases->buttons[index[1]], valuebuf);
    110153          break;
     
    123166void CommandNode::bind (WorldEntity* entity)
    124167{
    125   bound->add (entity, LIST_ADD_NEXT, true);
     168  bound->add (entity);
    126169}
    127170
     
    132175void CommandNode::unbind (WorldEntity* entity)
    133176{
    134   bound->remove (entity, LIST_FIND_FW);
    135 }
    136 
    137 int* CommandNode::name_to_index (char* name)
     177  bound->remove (entity);
     178}
     179
     180int* CommandNode::nameToIndex (char* name)
    138181{
    139182  coord[0] = -1;
    140183  coord[1] = -1;
    141184  int c;
    142   if( (c = keyname_to_SDLK (name)) != -1)
     185  if( (c = keynameToSDLK (name)) != -1)
    143186    {
    144187      coord[1] = c;
    145188      coord[0] = 0;
    146189    }
    147   if( (c = buttonname_to_SDLB (name)) != -1)
     190  if( (c = buttonnameToSDLB (name)) != -1)
    148191    {
    149192      coord[1] = c;
     
    158201void CommandNode::process ()
    159202{
    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
     210void CommandNode::processLocal ()
    165211{
    166212  SDL_Event event;
    167213  Command cmd;
    168  
    169214  while( SDL_PollEvent (&event))
    170215    {
     
    175220          strcpy (cmd.cmd, aliases->keys[event.key.keysym.sym]);
    176221          cmd.bUp = false;
    177           if( strlen (cmd.cmd) > 0) relay (&cmd);
     222          if( strlen (cmd.cmd) > 0) relay(&cmd);
    178223          break;
    179224        case SDL_KEYUP:
    180225          strcpy( cmd.cmd, aliases->keys[event.key.keysym.sym]);
    181226          cmd.bUp = true;
    182           if( strlen (cmd.cmd) > 0) relay (&cmd);
     227          if( strlen (cmd.cmd) > 0) relay(&cmd);
    183228          break;
    184229        case SDL_MOUSEMOTION:
     
    192237          strcpy( cmd.cmd, aliases->buttons[event.button.button]);
    193238          cmd.bUp = true;
    194           if( strlen (cmd.cmd) > 0) relay (&cmd);
     239          if( strlen (cmd.cmd) > 0) relay(&cmd);
    195240          break;
    196241        case SDL_MOUSEBUTTONDOWN:
    197242          strcpy( cmd.cmd, aliases->buttons[event.button.button]);
    198243          cmd.bUp = false;
    199           if( strlen (cmd.cmd) > 0) relay (&cmd);
     244          if( strlen (cmd.cmd) > 0) relay(&cmd);
    200245          break;
    201246        case SDL_JOYAXISMOTION:
     
    207252        default:
    208253          Orxonox *orx = Orxonox::getInstance();
    209           orx->event_handler (&event);
    210          
     254          orx->eventHandler(&event);
    211255          break;
    212256        }
     
    214258}
    215259
    216 void CommandNode::process_network ()
    217 {
    218 
    219 }
     260
     261void CommandNode::processNetwork ()
     262{
     263
     264}
     265
    220266
    221267void CommandNode::relay (Command* cmd)
    222268{
    223   //printf("CommandNode|relay()\n");
    224   List<WorldEntity>* plist = bound;
    225  
     269
    226270  Orxonox *orx = Orxonox::getInstance();
    227   if( orx->system_command (cmd)) return;
     271  if( orx->systemCommand (cmd)) return;
     272
    228273  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
    238288
    239289/**
     
    241291   \param ID: the new ID to use
    242292*/
    243 void CommandNode::set_netID (int ID)
     293void CommandNode::setNetID (int ID)
    244294{
    245295  netID = ID;
    246296}
    247297
    248 void CommandNode::send_over_network (Command* cmd)
    249 {
    250 }
     298void CommandNode::sendOverNetwork (Command* cmd)
     299{
     300}
Note: See TracChangeset for help on using the changeset viewer.