Render::Render() : Widget(NULL, "Render") { assert(_instance == NULL); _instance = this; _childEventSender = NULL; _viewport = Rect(Point(0, 0), Application::instance()->windowSettings().size); _fpsTimer.setIntervalMsec(500); _fps = 1.0f; _frames = 0; setEventMask(ET_AllEvents); setVisible(true); _mapDialog = new MapDialog(this); _gameDialog = new GameDialog(this); _simulation = new Simulation(this, "Simulation"); _settingsDialog = new SettingsDialog(this); _console = new Console(this); Settings::instance()->registerSetting<bool>("FPS", true); BindingManager *b = BindingManager::instance(); b->registerKey("Console", KeyBinding(SDLK_BACKQUOTE)); b->registerKey("ToggleFPS", KeyBinding(SDLK_F1)); b->registerKey("Quit", KeyBinding(SDLK_F4)); }
void Simulation::joystickButtonUpEvent(JoystickButtonUpEvent* e) { if (_initializing || _menu->visible()) return; if (_simulationType == Simulation_Game) { BindingManager *b = BindingManager::instance(); if (b->findJoystickButton("Fire").button() == e->event().button) { _player->setFiring(false); } } }
void Render::keyboardDownEvent(KeyboardDownEvent *e) { BindingManager *b = BindingManager::instance(); int keysym = e->event().keysym.sym; if (b->findKey("ToggleFPS").check(keysym)) { e->stop(); _fpsLabel->setVisible(!_fpsLabel->visible()); } else if (b->findKey("Quit").check(keysym)) { e->stop(); Application::instance()->quit(0); } else if (b->findKey("Console").check(keysym)) { e->stop(); if (!_console->visible()) { _consoleSaveEvents.clear(); WidgetChildren *c = children(); for (WidgetChildrenIterator it = c->begin(); it != c->end(); ++it) { _consoleSaveEvents.push_back((*it)->eventMask()); if (*it != _console) (*it)->disableInput(); } _console->show(); } else { WidgetChildren *c = children(); int i = 0; for (WidgetChildrenIterator it = c->begin(); it != c->end(); ++it, ++i) (*it)->setEventMask(_consoleSaveEvents[i]); _console->hide(); } } }
void Simulation::joystickAxisMotionEvent(JoystickAxisMotionEvent* e) { if (_initializing || _menu->visible()) return; float value = e->event().value; if (abs(e->event().value) < 1500) value = 0; value /= 32768.0f; BindingManager *b = BindingManager::instance(); if (b->findJoystickAxis("Roll").axis() == e->event().axis) { if (b->findJoystickAxis("Roll").inverted()) value = -value; Vector3D angularControl = _player->angularControl(); angularControl.z = value * _player->maximumAngularControl().z; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findJoystickAxis("Pitch").axis() == e->event().axis) { if (b->findJoystickAxis("Pitch").inverted()) value = -value; Vector3D angularControl = _player->angularControl(); angularControl.x = value * _player->maximumAngularControl().x; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findJoystickAxis("Yaw").axis() == e->event().axis) { if (b->findJoystickAxis("Yaw").inverted()) value = -value; Vector3D angularControl = _player->angularControl(); angularControl.y = value * _player->maximumAngularControl().y; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findJoystickAxis("Acceleration").axis() == e->event().axis) { if (b->findJoystickAxis("Pitch").inverted()) value = -value; _player->setControl(value * _player->maximumAccelerationControl(), _player->angularControl()); } }
void Frigid::checkBindings() { BindingManager *bm = BindingManager::instance(); for (uint32 i = 0; i < bm->getBindingCount(); ++i) { Binding b = bm->getBinding(i); bool key = Input::isKeyDown(b.key); bool modifiers = true; for (int j = 0; j < b.modifiers.size(); ++j) { if (!Input::isKeyDown(b.modifiers[j])) { modifiers = false; break; } } if (key && modifiers) { doCommand(b.cmd); return; } } }
void CodeEditor::checkBindings() { BindingManager *bm = BindingManager::instance(); //Make it so if other keys are pressed ignore it. for (uint32 i = 0; i < bm->getBindingCount(); ++i) { Binding b = bm->getBinding(i); bool key = Input::isKeyDown(b.key); bool modifiers = true; for (int j = 0; j < b.modifiers.size(); ++j) { if (!Input::isKeyDown(b.modifiers[j])) { modifiers = false; break; } } if (key && modifiers) { doCommand(b.cmd); return; } } }
void Simulation::keyboardDownEvent(KeyboardDownEvent* e) { if (_initializing) return; BindingManager *b = BindingManager::instance(); int keysym = e->event().keysym.sym; if (b->findKey("RollNegative").check(keysym)) { Vector3D angularControl = _player->angularControl(); angularControl.z = -_player->maximumAngularControl().z; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findKey("RollPositive").check(keysym)) { Vector3D angularControl = _player->angularControl(); angularControl.z = _player->maximumAngularControl().z; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findKey("PitchNegative").check(keysym)) { Vector3D angularControl = _player->angularControl(); angularControl.x = -_player->maximumAngularControl().x; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findKey("PitchPositive").check(keysym)) { Vector3D angularControl = _player->angularControl(); angularControl.x = _player->maximumAngularControl().x; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findKey("YawNegative").check(keysym)) { Vector3D angularControl = _player->angularControl(); angularControl.y = -_player->maximumAngularControl().y; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findKey("YawPositive").check(keysym)) { Vector3D angularControl = _player->angularControl(); angularControl.y = _player->maximumAngularControl().y; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findKey("Accelerate").check(keysym)) { _player->setControl( _player->maximumAccelerationControl(), _player->angularControl()); } else if (b->findKey("Decelerate").check(keysym)) { _player->setControl(-_player->maximumAccelerationControl(), _player->angularControl()); } else if (b->findKey("ViewYNegative").check(keysym)) { _outsideViewAnglesAcc.y = -30.0f; } else if (b->findKey("ViewYPositive").check(keysym)) { _outsideViewAnglesAcc.y = 30.0f; } else if (b->findKey("ViewXNegative").check(keysym)) { _outsideViewAnglesAcc.x = -30.0f; } else if (b->findKey("ViewXPositive").check(keysym)) { _outsideViewAnglesAcc.x = 30.0f; } else if (b->findKey("Fog").check(keysym)) { _fog = !_fog; if (_fog) displayMessage(_("Fog: on")); else displayMessage(_("Fog: off")); } else if (b->findKey("Hud").check(keysym)) { if (_hudMode == Hud_Full) { displayMessage(_("HUD: minimal")); _hudMode = Hud_Minimal; } else if (_hudMode == Hud_Minimal) { displayMessage(_("HUD: off")); _hudMode = Hud_None; } else if (_hudMode == Hud_None) { displayMessage(_("HUD: full")); _hudMode = Hud_Full; } } else if (b->findKey("View").check(keysym)) { if (_viewMode == View_Cockpit) { displayMessage(_("View: outside")); _viewMode = View_Outside; } else if (_viewMode == View_Outside) { displayMessage(_("View: cockpit")); _viewMode = View_Cockpit; } } else if (b->findKey("GameMenu").check(keysym)) { _menu->show(); _updateTimer.setEnabled(false); e->stop(); } if (_simulationType == Simulation_Game) { if (b->findKey("Fire").check(keysym)) { _player->setFiring(true); } } }
Simulation::Simulation(Widget* pParent, const string &pName) : Widget(pParent, pName.empty() ? genericName("Simulation") : pName, 1000) { enableInput(); _map = new Map(&_fractal, name() + "_Map"); _map->setScale(Vector3D(20.0f, 800.0f, 20.0f)); _player = new Player(_map); _player->setTeam(Player::Team_Blue); _player->setControlType(Player::Control_AngularVelocity); _player->setAI(false); _player->setFrameVisible(false); _hudMode = Hud_Full; _updateTimer.setIntervalMsec(5); _messageTimer.setIntervalMsec(50); BindingManager *b = BindingManager::instance(); b->registerKey("RollNegative", KeyBinding(SDLK_KP4)); b->registerKey("RollPositive", KeyBinding(SDLK_KP6)); b->registerKey("PitchNegative", KeyBinding(SDLK_KP8)); b->registerKey("PitchPositive", KeyBinding(SDLK_KP2)); b->registerKey("YawNegative", KeyBinding(SDLK_KP1)); b->registerKey("YawPositive", KeyBinding(SDLK_KP3)); b->registerKey("Accelerate", KeyBinding(SDLK_KP_PLUS)); b->registerKey("Decelerate", KeyBinding(SDLK_KP_MINUS)); b->registerKey("ViewYNegative", KeyBinding(SDLK_1)); b->registerKey("ViewYPositive", KeyBinding(SDLK_4)); b->registerKey("ViewXNegative", KeyBinding(SDLK_2)); b->registerKey("ViewXPositive", KeyBinding(SDLK_3)); b->registerKey("ViewZoomIn", KeyBinding(SDLK_5)); b->registerKey("ViewZoomOut", KeyBinding(SDLK_6)); b->registerKey("Fog", KeyBinding(SDLK_f)); b->registerKey("Hud", KeyBinding(SDLK_h)); b->registerKey("View", KeyBinding(SDLK_v)); b->registerKey("GameMenu", KeyBinding(SDLK_ESCAPE)); b->registerKey("Fire", KeyBinding(SDLK_SPACE)); b->registerJoystickAxis("Roll", JoystickAxisBinding(0)); b->registerJoystickAxis("Pitch", JoystickAxisBinding(1)); b->registerJoystickAxis("Yaw", JoystickAxisBinding(3)); b->registerJoystickAxis("Acceleration", JoystickAxisBinding(2)); b->registerJoystickButton("Fire", JoystickButtonBinding(0)); Settings *s = Settings::instance(); s->registerSetting<string>("PlayerName", _player->name()); s->registerSetting<int>("DisplayQuality", Quality_Medium); s->registerSetting<float>("FOV", 45.0f); }
void Simulation::keyboardUpEvent(KeyboardUpEvent* e) { if (_initializing || _menu->visible()) return; BindingManager *b = BindingManager::instance(); int keysym = e->event().keysym.sym; if (b->findKey("RollNegative").check(keysym) || b->findKey("RollPositive").check(keysym)) { Vector3D angularControl = _player->angularControl(); angularControl.z = 0.0f; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findKey("PitchNegative").check(keysym) || b->findKey("PitchPositive").check(keysym)) { Vector3D angularControl = _player->angularControl(); angularControl.x = 0.0f; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findKey("YawNegative").check(keysym) || b->findKey("YawPositive").check(keysym)) { Vector3D angularControl = _player->angularControl(); angularControl.y = 0.0f; _player->setControl(_player->accelerationControl(), angularControl); } else if (b->findKey("Accelerate").check(keysym) || b->findKey("Decelerate").check(keysym)) { _player->setControl(0.0f, _player->angularControl()); } else if (b->findKey("ViewZoomIn").check(keysym)) { _outsideViewZoom -= 1.0f; } else if (b->findKey("ViewZoomOut").check(keysym)) { _outsideViewZoom += 1.0f; } else if (b->findKey("ViewYNegative").check(keysym) || b->findKey("ViewYPositive").check(keysym)) { _outsideViewAnglesAcc.y = 0.0f; } else if (b->findKey("ViewXNegative").check(keysym) || b->findKey("ViewXPositive").check(keysym)) { _outsideViewAnglesAcc.x = 0.0f; } if (_simulationType == Simulation_Game) { if (b->findKey("Fire").check(keysym)) { _player->setFiring(false); } } }