131 void GameVegaConfig::initKeyMap()
134 key_map[
"space"] =
' ';
137 key_map[
"function-1"] =
WSK_F1;
138 key_map[
"function-2"] =
WSK_F2;
139 key_map[
"function-3"] =
WSK_F3;
140 key_map[
"function-4"] =
WSK_F4;
141 key_map[
"function-5"] =
WSK_F5;
142 key_map[
"function-6"] =
WSK_F6;
143 key_map[
"function-7"] =
WSK_F7;
144 key_map[
"function-8"] =
WSK_F8;
145 key_map[
"function-9"] =
WSK_F9;
146 key_map[
"function-10"] =
WSK_F10;
147 key_map[
"function-11"] =
WSK_F11;
148 key_map[
"function-12"] =
WSK_F12;
149 key_map[
"function-13"] =
WSK_F13;
150 key_map[
"function-14"] =
WSK_F14;
151 key_map[
"function-15"] =
WSK_F15;
152 key_map[
"keypad-insert"] =
WSK_KP0;
163 key_map[
"less-than"] =
'<';
164 key_map[
"greater-than"] =
'>';
182 key_map[
"cursor-up"] =
WSK_UP;
188 key_map[
"cursor-end"] =
WSK_END;
209 using namespace CockpitKeys;
215 std::string s = composition.
data;
216 while ( s.length() ) {
217 std::string::size_type where = s.find(
" " );
218 std::string t = s.substr( 0, where );
219 if (where != std::string::npos)
220 s = s.substr( where+1 );
223 where = t.find(
"(" );
225 if (where != string::npos) {
226 args = t.substr( where+1 );
227 std::string::size_type paren = args.find(
")" );
228 if (paren != string::npos)
229 args = args.substr( 0, paren );
230 t = t.substr( 0, where );
234 (*i).second( args, k );
244 void GameVegaConfig::initCommandMap()
250 void GameVegaConfig::doBindings(
configNode *node )
252 vector< easyDomNode* >::const_iterator siter;
253 for (siter = node->
subnodes.begin(); siter != node->
subnodes.end(); siter++) {
255 if ( (cnode)->Name() ==
"bind" )
257 else if ( ( (cnode)->Name() ==
"axis" ) )
260 cout<<
"Unknown tag: "<<(cnode)->Name()<<endl;
266 void GameVegaConfig::doAxis(
configNode *node )
269 string myjoystick = node->
attr_value(
"joystick" );
271 string invertstr = node->
attr_value(
"inverse" );
272 string mouse_str = node->
attr_value(
"mouse" );
273 if ( name.empty() || ( mouse_str.empty() && myjoystick.empty() ) || axis.empty() ) {
274 cout<<
"no correct axis desription given "<<endl;
277 int joy_nr = atoi( myjoystick.c_str() );
278 if ( !mouse_str.empty() )
280 int axis_nr = atoi( axis.c_str() );
284 bool inverse =
false;
285 if ( !invertstr.empty() )
288 axis_joy[0] = joy_nr;
291 }
else if (name ==
"y") {
292 axis_joy[1] = joy_nr;
295 }
else if (name ==
"z") {
296 axis_joy[2] = joy_nr;
299 }
else if (name ==
"throttle") {
300 axis_joy[3] = joy_nr;
303 }
else if (name ==
"hatswitch") {
305 string margin_str = node->
attr_value(
"margin" );
306 if ( nr_str.empty() || margin_str.empty() ) {
307 cout<<
"you have to assign a number and a margin to the hatswitch"<<endl;
310 int nr = atoi( nr_str.c_str() );
312 float margin = atof( margin_str.c_str() );
313 hatswitch_margin[nr] = margin;
315 hatswitch_axis[nr] = axis_nr;
316 hatswitch_joystick[nr] = joy_nr;
318 vector< easyDomNode* >::const_iterator siter;
321 for (siter = node->
subnodes.begin(); siter != node->
subnodes.end(); siter++) {
323 checkHatswitch( nr, cnode );
326 cout<<
"unknown axis "<<name<<endl;
333 void GameVegaConfig::checkHatswitch(
int nr,
configNode *node )
335 if (node->
Name() !=
"hatswitch") {
336 cout<<
"not a hatswitch node "<<endl;
340 float val = atof( strval.c_str() );
341 if (val > 1.0 || val < -1.0) {
342 cout<<
"only hatswitch values from -1.0 to 1.0 allowed"<<endl;
345 hatswitch[nr][hs_value_index] = val;
346 cout<<
"setting hatswitch nr "<<nr<<
" "<<hs_value_index<<
" = "<<val<<endl;
352 void GameVegaConfig::checkBind(
configNode *node )
354 if (node->
Name() !=
"bind") {
355 cout<<
"not a bind node "<<endl;
358 std::string tmp = node->
attr_value(
"modifier" );
361 string cmdstr = node->
attr_value(
"command" );
362 string player_bound = node->
attr_value(
"player" );
363 if ( player_bound.empty() )
366 if (handler == NULL) {
367 cout<<
"No such command: "<<cmdstr<<endl;
370 string player_str = node->
attr_value(
"player" );
371 string joy_str = node->
attr_value(
"joystick" );
372 string mouse_str = node->
attr_value(
"mouse" );
374 string additional_data = node->
attr_value(
"data" );
375 string buttonstr = node->
attr_value(
"button" );
376 string hat_str = node->
attr_value(
"hatswitch" );
377 string dighswitch = node->
attr_value(
"digital-hatswitch" );
378 string direction = node->
attr_value(
"direction" );
379 if ( !player_str.empty() ) {
380 if ( !joy_str.empty() ) {
381 int jn = atoi( joy_str.c_str() );
384 }
else if ( !mouse_str.empty() ) {
388 if ( !keystr.empty() ) {
391 if (keystr.length() == 1) {
394 int glut_key = key_map[keystr];
396 cout<<
"No such special key: "<<keystr<<endl;
401 }
else if ( !buttonstr.empty() ) {
403 int button_nr = atoi( buttonstr.c_str() );
404 if ( joy_str.empty() && mouse_str.empty() ) {
406 if ( hat_str.empty() ) {
407 cout<<
"you got to give a analogue hatswitch number"<<endl;
410 int hatswitch_nr = atoi( hat_str.c_str() );
417 if ( mouse_str.empty() )
418 joystick_nr = atoi( joy_str.c_str() );
421 if (
joystick[joystick_nr]->isAvailable() ) {
429 static bool first =
true;
431 cout<<
"\nrefusing to bind command to joystick (joy-nr too high)"<<endl;
436 }
else if ( !( dighswitch.empty() || direction.empty() || ( mouse_str.empty() && joy_str.empty() ) ) ) {
438 if ( dighswitch.empty() || direction.empty() || ( mouse_str.empty() && joy_str.empty() ) ) {
439 cout<<
"you have to specify joystick,digital-hatswitch,direction"<<endl;
442 int hsw_nr = atoi( dighswitch.c_str() );
445 if ( mouse_str.empty() )
446 joy_nr = atoi( joy_str.c_str() );
449 if ( !(
joystick[joy_nr]->isAvailable() && hsw_nr <
joystick[joy_nr]->nr_of_hats) ) {
450 cout<<
"refusing to bind digital hatswitch: no such hatswitch"<<endl;
454 if (direction ==
"center") {
456 }
else if (direction ==
"up") {
458 }
else if (direction ==
"right") {
460 }
else if (direction ==
"left") {
462 }
else if (direction ==
"down") {
464 }
else if (direction ==
"rightup") {
466 }
else if (direction ==
"rightdown") {
468 }
else if (direction ==
"leftup") {
470 }
else if (direction ==
"leftdown") {
473 cout<<
"no valid direction string"<<endl;
477 cout<<
"Bound joy "<<joy_nr<<
" hatswitch "<<hsw_nr<<
" dir_index "<<dir_index<<
" to command "<<cmdstr<<endl;
488 void GameVegaConfig::bindKeys()
490 doBindings( bindings );
498 commandMap[
"NoPositionalKey"] =
mute;
499 commandMap[
"DopplerInc"] =
incdop;
501 commandMap[
"DopplerDec"] =
decdop;
502 commandMap[
"VolumeInc"] =
VolUp;
503 commandMap[
"VolumeDec"] =
VolDown;
580 commandMap[
"BlinkLeftKey"] = FireKeyboard::BlinkLeftKey;
581 commandMap[
"BlinkRightKey"] = FireKeyboard::BlinkRightKey;
582 commandMap[
"HeadlightKey"] = FireKeyboard::HeadlightKey;
583 commandMap[
"SirenKey"] = FireKeyboard::SirenKey;
708 commandMap[
"Cockpit::MapKey"] =
MapKey;