Changeset 4369 in orxonox.OLD for orxonox/trunk/src/util/event/key_mapper.cc
- Timestamp:
- May 28, 2005, 4:18:58 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/event/key_mapper.cc
r4367 r4369 40 40 // delete what has to be deleted here 41 41 } 42 43 44 /** 45 \brief loads new key bindings from a file 46 \param filename: The path and name of the file to load the bindings from 47 */ 48 void KeyMapper::loadKeyBindings (const char* fileName) 49 { 50 FILE* stream; 51 52 PRINTF(4)("Loading key bindings from %s\n", fileName); 53 54 // remove old bindings if present 55 if( this->keyAliases != NULL) 56 { 57 free (this->keyAliases); 58 this->keyAliases = NULL; 59 } 60 61 // create parser 62 IniParser parser(fileName); 63 if( parser.getSection (CONFIG_SECTION_PLAYER "1") == -1) 64 { 65 PRINTF(1)("Could not find key bindings " CONFIG_SECTION_PLAYER"1 in %s\n", fileName); 66 return; 67 } 68 // allocate empty lookup table 69 this->keyAliases = (KeyBindings*) calloc (1, sizeof (KeyBindings)); 70 71 char namebuf[256]; 72 char valuebuf[256]; 73 memset (namebuf, 0, 256); 74 memset (valuebuf, 0, 256); 75 int* index; 76 77 while( parser.nextVar (namebuf, valuebuf) != -1) 78 { 79 //index = nameToIndex (valuebuf); 80 int c; 81 if( (c = keynameToSDLK (valuebuf)) != -1) 82 { 83 index[1] = c; index[0] = 0; 84 } 85 if( (c = buttonnameToSDLB (valuebuf)) != -1) 86 { 87 index[1] = c; index[0] = 1; 88 } 89 90 switch( index[0]) 91 { 92 case 0: 93 PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf); 94 strcpy (this->keyAliases->keys[index[1]], namebuf); 95 break; 96 case 1: 97 PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf); 98 strcpy (this->keyAliases->buttons[index[1]], namebuf); 99 break; 100 default: 101 break; 102 } 103 memset (namebuf, 0, 256); 104 memset (valuebuf, 0, 256); 105 } 106 107 108 // PARSE MISC SECTION 109 if( parser.getSection (CONFIG_SECTION_MISC_KEYS) == -1) 110 { 111 PRINTF(1)("Could not find key bindings in %s\n", fileName); 112 return; 113 } 114 115 while( parser.nextVar (namebuf, valuebuf) != -1) 116 { 117 //index = nameToIndex (valuebuf); 118 int c; 119 if( (c = keynameToSDLK (valuebuf)) != -1) 120 { 121 index[1] = c; index[0] = 0; 122 } 123 if( (c = buttonnameToSDLB (valuebuf)) != -1) 124 { 125 index[1] = c; index[0] = 1; 126 } 127 128 129 switch( index[0]) 130 { 131 case 0: 132 PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf); 133 strcpy (keyAliases->keys[index[1]], namebuf); 134 break; 135 case 1: 136 PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf); 137 strcpy (keyAliases->buttons[index[1]], namebuf); 138 break; 139 default: 140 break; 141 } 142 memset (namebuf, 0, 256); 143 memset (valuebuf, 0, 256); 144 } 145 }
Note: See TracChangeset
for help on using the changeset viewer.