Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Dec 20, 2004, 2:42:54 AM (20 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/nico/src/command_node.cc

    r2816 r3238  
    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();
    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();
    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 }
    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*/
    6377
    6478void CommandNode::reset()
    6579{
    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
     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
    68105
    69106/**
     
    71108   \param filename: The path and name of the file to load the bindings from
    72109*/
    73 void CommandNode::load_bindings (char* filename)
     110void CommandNode::loadBindings (char* filename)
    74111{
    75112  FILE* stream;
     
    88125  // create parser
    89126  IniParser parser (filename);
    90   if( parser.get_section ("Bindings") == -1)
     127  if( parser.getSection ("Bindings") == -1)
    91128    {
    92129      printf("Could not find key bindings in %s\n", filename);
     
    102139  int* index;
    103140 
    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);
    107144      switch( index[0])
    108145        {
    109146        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);
    111148          strcpy (aliases->keys[index[1]], valuebuf);
    112149          break;
    113150        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);
    115152          strcpy (aliases->buttons[index[1]], valuebuf);
    116153          break;
     
    141178}
    142179
    143 int* CommandNode::name_to_index (char* name)
     180int* CommandNode::nameToIndex (char* name)
    144181{
    145182  coord[0] = -1;
    146183  coord[1] = -1;
    147184  int c;
    148   if( (c = keyname_to_SDLK (name)) != -1)
     185  if( (c = keynameToSDLK (name)) != -1)
    149186    {
    150187      coord[1] = c;
    151188      coord[0] = 0;
    152189    }
    153   if( (c = buttonname_to_SDLB (name)) != -1)
     190  if( (c = buttonnameToSDLB (name)) != -1)
    154191    {
    155192      coord[1] = c;
     
    164201void CommandNode::process ()
    165202{
    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
     210void CommandNode::processLocal ()
    171211{
    172212  SDL_Event event;
    173213  Command cmd;
    174  
    175214  while( SDL_PollEvent (&event))
    176215    {
     
    181220          strcpy (cmd.cmd, aliases->keys[event.key.keysym.sym]);
    182221          cmd.bUp = false;
    183           if( strlen (cmd.cmd) > 0) relay (&cmd);
     222          if( strlen (cmd.cmd) > 0) relay(&cmd);
    184223          break;
    185224        case SDL_KEYUP:
    186225          strcpy( cmd.cmd, aliases->keys[event.key.keysym.sym]);
    187226          cmd.bUp = true;
    188           if( strlen (cmd.cmd) > 0) relay (&cmd);
     227          if( strlen (cmd.cmd) > 0) relay(&cmd);
    189228          break;
    190229        case SDL_MOUSEMOTION:
     
    198237          strcpy( cmd.cmd, aliases->buttons[event.button.button]);
    199238          cmd.bUp = true;
    200           if( strlen (cmd.cmd) > 0) relay (&cmd);
     239          if( strlen (cmd.cmd) > 0) relay(&cmd);
    201240          break;
    202241        case SDL_MOUSEBUTTONDOWN:
    203242          strcpy( cmd.cmd, aliases->buttons[event.button.button]);
    204243          cmd.bUp = false;
    205           if( strlen (cmd.cmd) > 0) relay (&cmd);
     244          if( strlen (cmd.cmd) > 0) relay(&cmd);
    206245          break;
    207246        case SDL_JOYAXISMOTION:
     
    213252        default:
    214253          Orxonox *orx = Orxonox::getInstance();
    215           orx->event_handler (&event);
    216          
     254          orx->eventHandler(&event);
    217255          break;
    218256        }
     
    221259
    222260
    223 void CommandNode::process_network ()
     261void CommandNode::processNetwork ()
    224262{
    225263
     
    229267void CommandNode::relay (Command* cmd)
    230268{
    231  
     269
    232270  Orxonox *orx = Orxonox::getInstance();
    233   if( orx->system_command (cmd)) return;
     271  if( orx->systemCommand (cmd)) return;
     272
    234273  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
    239280  WorldEntity* entity = bound->enumerate();
    240   while(  entity != NULL)
     281  while( entity != NULL)
    241282    {
    242283      entity->command (cmd);
     
    250291   \param ID: the new ID to use
    251292*/
    252 void CommandNode::set_netID (int ID)
     293void CommandNode::setNetID (int ID)
    253294{
    254295  netID = ID;
    255296}
    256297
    257 void CommandNode::send_over_network (Command* cmd)
    258 {
    259 }
     298void CommandNode::sendOverNetwork (Command* cmd)
     299{
     300}
Note: See TracChangeset for help on using the changeset viewer.