Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5014 in orxonox.OLD for orxonox/trunk/src/lib/event/key_mapper.cc


Ignore:
Timestamp:
Aug 14, 2005, 4:29:29 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: implemented a new kind of ini-parser
this parser first reads the file, and then one can search through without accessing the file anymore

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/event/key_mapper.cc

    r4866 r5014  
    121121void KeyMapper::loadKeyBindings(IniParser* iniParser)
    122122{
    123   if( iniParser->getSection (CONFIG_SECTION_PLAYER "1") == -1)
     123  if( !iniParser->getSection (CONFIG_SECTION_PLAYER "1"))
    124124  {
    125125    PRINTF(1)("Could not find key bindings " CONFIG_SECTION_PLAYER"1\n");
    126126    return;
    127127  }
    128   // allocate empty lookup table
    129 
    130   char namebuf[256];
    131   char valuebuf[256];
    132   memset (namebuf, 0, 256);
    133   memset (valuebuf, 0, 256);
    134128  int* index;
    135129
    136   while( iniParser->nextVar (namebuf, valuebuf) != -1)
    137   {
    138     PRINTF(3)("Keys: Parsing %s, %s now.\n", namebuf, valuebuf);
    139     index = nameToIndex (valuebuf);
    140     this->mapKeys(namebuf, index[1]);
    141 
    142       /*
    143     switch( index[0])
    144     {
    145     case 0:
    146     this->mapKeys(namebuf, index[1]);
    147     break;
    148     case 1:
    149     this->mapKeys(namebuf, index[1]);
    150     break;
    151     default:
    152     break;
    153   }
    154       */
    155     memset (namebuf, 0, 256);
    156     memset (valuebuf, 0, 256);
     130  while(iniParser->nextVar())
     131  {
     132    PRINTF(3)("Keys: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue());
     133    index = nameToIndex (iniParser->getCurrentValue());
     134    this->mapKeys(iniParser->getCurrentName(), index[1]);
    157135  }
    158136
    159137
    160138  // PARSE MISC SECTION
    161   if( iniParser->getSection (CONFIG_SECTION_MISC_KEYS) == -1)
    162   {
    163     PRINTF(1)("Could not find key bindings\n");
     139  if( !iniParser->getSection (CONFIG_SECTION_MISC_KEYS))
     140  {
     141    PRINTF(1)("Could not find key bindings" CONFIG_SECTION_MISC_KEYS "\n");
    164142    return;
    165143  }
    166144
    167   while( iniParser->nextVar (namebuf, valuebuf) != -1)
    168   {
    169     PRINTF(3)("MISC: Parsing %s, %s now.\n", namebuf, valuebuf);
    170     index = nameToIndex (valuebuf);
    171     this->mapKeys(namebuf, index[1]);
    172       /*
    173     switch( index[0])
    174     {
    175     case 0:
    176     this->mapKeys(namebuf, index[1]);
    177     break;
    178     case 1:
    179     this->mapKeys(namebuf, index[1]);
    180     break;
    181     default:
    182     break;
    183   }
    184       */
    185     memset (namebuf, 0, 256);
    186     memset (valuebuf, 0, 256);
     145  while( iniParser->nextVar())
     146  {
     147    PRINTF(3)("MISC: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue());
     148    index = nameToIndex (iniParser->getCurrentValue());
     149    this->mapKeys(iniParser->getCurrentName(), index[1]);
    187150  }
    188151}
     
    192155 * @param the name of the button
    193156*/
    194 int* KeyMapper::nameToIndex (char* name)
     157int* KeyMapper::nameToIndex (const char* name)
    195158{
    196159  coord[0] = -1;
     
    216179 * @param id of the key
    217180*/
    218 void KeyMapper::mapKeys(char* name, int keyID)
     181void KeyMapper::mapKeys(const char* name, int keyID)
    219182{
    220183  for(int i = 0; map[i].pValue != NULL; ++i )
Note: See TracChangeset for help on using the changeset viewer.