Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/input.cc')
-rw-r--r--src/client/input.cc400
1 files changed, 206 insertions, 194 deletions
diff --git a/src/client/input.cc b/src/client/input.cc
index 1886967..e8f0725 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -8,6 +8,7 @@
#include "audio/audio.h"
#include "auxiliary/functions.h"
+#include "client/action.h"
#include "client/client.h"
#include "client/input.h"
#include "client/joystick.h"
@@ -134,7 +135,7 @@ void func_ui_control(std::string const &args)
render::Camera::set_pitch(0.0f);
}
- con_debug << "mouse control is " << ((input_mousecontrol->value()) ? "on" : "off") << std::endl;
+ con_print << "mouse control is " << ((input_mousecontrol->value()) ? "on" : "off") << std::endl;
audio::play("ui/control");
}
@@ -341,146 +342,172 @@ void shutdown()
}
-void action_press(Key const *key, std::string const &action)
+void action_press(Key *key)
{
- /* -- thruster ------------------------------------ */
- if (action.compare("+thrustup") == 0) {
- local_thrust += thruster_offset;
-
-
- } else if (action.compare("+thrustdown") == 0) {
- local_thrust -= 2.0f * thruster_offset;
-
- /* -- mouse control ------------------------------- */
- } else if (action.compare("+control") == 0) {
- if (!mouse_control_override) {
- mouse_control_override = true;
- mouse_control_override_time = key->pressed();
- }
-
- /* -- directional control ------------------------- */
- } else if (action.compare("+left") == 0) {
- local_direction = 1.0f;
-
- } else if (action.compare("+right") == 0) {
- local_direction = -1.0f;
-
- } else if (action.compare("+up") == 0) {
- local_pitch = 1.0f;
-
- } else if (action.compare("+down") == 0) {
- local_pitch = -1.0f;
-
- } else if (action.compare("+rollleft") == 0) {
- local_roll = 1.0f;
-
- } else if (action.compare("+rollright") == 0) {
- local_roll = -1.0f;
-
- } else if (action.compare("+strafeleft") == 0) {
- local_strafe = 1.0f;
-
- } else if (action.compare("+straferight") == 0) {
- local_strafe = -1.0f;
-
- } else if (action.compare("+afterburner") == 0) {
- local_afterburner = 1.0f;
-
- } else if (action.compare("+reverse") == 0) {
- local_afterburner = -1.0f;
-
- /* -- camera control ------------------------------ */
-
- } else if (action.compare("+zoomin") == 0) {
- render::Camera::set_zoom(-0.1f);
-
- } else if (action.compare("+zoomout") == 0) {
- render::Camera::set_zoom(+0.1f);
-
- } else if (action.compare("+camleft") == 0) {
- render::Camera::set_direction(math::min(key->pressed() - core::application()->time(), 1.0f));
-
- } else if (action.compare("+camright") == 0) {
- render::Camera::set_direction(-math::min(key->pressed() - core::application()->time(), 1.0f));
-
- } else if (action.compare("+camup") == 0) {
- render::Camera::set_pitch(math::min(key->pressed() - core::application()->time(), 1.0f));
-
- } else if (action.compare("+camdown") == 0) {
- render::Camera::set_pitch(-math::min(key->pressed() - core::application()->time(), 1.0f));
- } else
- con_warn << "Unknown action " << action << std::endl;
+ switch(key->action()->id()) {
+ case Action::None:
+ case Action::Console:
+ return;
+ break;
+
+ /* -- directional control ------------------------- */
+ case Action::Left:
+ local_direction = 1.0f;
+ break;
+ case Action::Right:
+ local_direction = -1.0f;
+ break;
+ case Action::Up:
+ local_pitch = 1.0f;
+ break;
+ case Action::Down:
+ local_pitch = -1.0f;
+ break;
+ case Action::RollLeft:
+ local_roll = 1.0f;
+ break;
+ case Action::RollRight:
+ local_roll = -1.0f;
+ break;
+ case Action::StrafeLeft:
+ local_strafe = 1.0f;
+ break;
+ case Action::StrafeRight:
+ local_strafe = -1.0f;
+ break;
+
+ /* -- thruster ------------------------------------ */
+ case Action::ThrustUp:
+ local_thrust += thruster_offset;
+ break;
+ case Action::ThrustDown:
+ local_thrust -= 2.0f * thruster_offset;
+ break;
+
+ case Action::Afterburner:
+ local_afterburner = 1.0f;
+ break;
+ case Action::Reverse:
+ local_afterburner = -1.0f;
+ break;
+
+ /* -- mouse control ------------------------------- */
+ case Action::Control:
+ if (!mouse_control_override) {
+ mouse_control_override = true;
+ mouse_control_override_time = key->pressed();
+ }
+ break;
+
+ /* -- camera control ------------------------------ */
+
+ case Action::CamLeft:
+ render::Camera::set_direction(math::min(key->pressed() - core::application()->time(), 1.0f));
+ break;
+ case Action::CamRight:
+ render::Camera::set_direction(-math::min(key->pressed() - core::application()->time(), 1.0f));
+ break;
+ case Action::CamUp:
+ render::Camera::set_pitch(math::min(key->pressed() - core::application()->time(), 1.0f));
+ break;
+ case Action::CamDown:
+ render::Camera::set_pitch(-math::min(key->pressed() - core::application()->time(), 1.0f));
+ break;
+ case Action::ZoomIn:
+ render::Camera::set_zoom(-0.1f);
+ break;
+ case Action::ZoomOut:
+ render::Camera::set_zoom(+0.1f);
+ break;
+ }
}
-void action_release(Key *key, std::string const &action)
+void action_release(Key *key)
{
- /* -- thruster ------------------------------------ */
- if (action.compare("+thrustup") == 0) {
-
-
- } else if (action.compare("+thrustdown") == 0) {
-
-
- /* -- mouse control ------------------------------- */
- } else if (action.compare("+control") == 0) {
- if (mouse_control_override) {
- mouse_control_override = false;
- mouse_control_override_time = 0;
-
- if (!input_mousecontrol->value() || (joystick_control && mouse_control &&
- (render::Camera::mode() == render::Camera::Track || render::Camera::mode() == render::Camera::Cockpit))) {
- local_direction = 0.0f;
- local_pitch = 0.0f;
- local_roll = 0.0f;
-
- render::Camera::set_direction(0.0f);
- render::Camera::set_pitch(0.0f);
+ switch(key->action()->id()) {
+
+ case Action::None:
+ case Action::Console:
+ return;
+ break;
+
+ /* -- directional control ------------------------- */
+ case Action::Left:
+ local_direction = 0.0f;
+ break;
+ case Action::Right:
+ local_direction = 0.0f;
+ break;
+ case Action::Up:
+ local_pitch = 0.0f;
+ break;
+ case Action::Down:
+ local_pitch = 0.0f;
+ break;
+ case Action::RollLeft:
+ local_roll = 0.0f;
+ break;
+ case Action::RollRight:
+ local_roll = 0.0f;
+ break;
+ case Action::StrafeLeft:
+ local_strafe = 0.0f;
+ break;
+ case Action::StrafeRight:
+ local_strafe = 0.0f;
+ break;
+
+ /* -- thruster ------------------------------------ */
+ case Action::ThrustUp:
+ //local_thrust += 0;
+ break;
+ case Action::ThrustDown:
+ //local_thrust += 0;
+ break;
+
+ case Action::Afterburner:
+ local_afterburner = 0.0f;
+ break;
+ case Action::Reverse:
+ local_afterburner = 0.0f;
+ break;
+
+ /* -- mouse control ------------------------------- */
+ case Action::Control:
+ if (mouse_control_override) {
+ mouse_control_override = false;
+ mouse_control_override_time = 0;
+
+ if (!input_mousecontrol->value() || (joystick_control && mouse_control &&
+ (render::Camera::mode() == render::Camera::Track || render::Camera::mode() == render::Camera::Cockpit))) {
+ local_direction = 0.0f;
+ local_pitch = 0.0f;
+ local_roll = 0.0f;
+
+ render::Camera::set_direction(0.0f);
+ render::Camera::set_pitch(0.0f);
+ }
}
- }
-
- /* -- directional control ------------------------- */
- } else if (action.compare("+left") == 0) {
- local_direction = 0.0f;
-
- } else if (action.compare("+right") == 0) {
- local_direction = 0.0f;
-
- } else if (action.compare("+up") == 0) {
- local_pitch = 0.0f;
-
- } else if (action.compare("+down") == 0) {
- local_pitch = 0.0f;
-
- } else if (action.compare("+rollleft") == 0) {
- local_roll = 0.0f;
-
- } else if (action.compare("+rollright") == 0) {
- local_roll = 0.0f;
-
- } else if (action.compare("+strafeleft") == 0) {
- local_strafe = 0.0f;
-
- } else if (action.compare("+straferight") == 0) {
- local_strafe = 0.0f;
-
- } else if (action.compare("+afterburner") == 0) {
- local_afterburner = 0.0f;
-
- } else if (action.compare("+reverse") == 0) {
- local_afterburner = 0.0f;
-
+ break;
+
/* -- camera control ------------------------------ */
- } else if (action.compare("+camleft") == 0) {
- render::Camera::set_direction(0.0f);
-
- } else if (action.compare("+camright") == 0) {
- render::Camera::set_direction(0.0f);
-
- } else if (action.compare("+camup") == 0) {
- render::Camera::set_pitch(0.0f);
-
- } else if (action.compare("+camdown") == 0) {
- render::Camera::set_pitch(0.0f);
+
+ case Action::CamLeft:
+ render::Camera::set_direction(0.0f);
+ break;
+ case Action::CamRight:
+ render::Camera::set_direction(0.0f);
+ break;
+ case Action::CamUp:
+ render::Camera::set_pitch(0);
+ break;
+ case Action::CamDown:
+ render::Camera::set_pitch(0);
+ break;
+ case Action::ZoomIn:
+ break;
+ case Action::ZoomOut:
+ break;
}
}
@@ -498,10 +525,7 @@ Key::Modifier modifier()
void key_pressed(Key *key)
{
- // FIXME implement a real 'console key'
-
- if (key->bind(Key::None).compare("ui_console") == 0) {
- // FIXME bah
+ if (key->action() && (key->action()->id() == Action::Console)) {
local_direction = 0.0f;
local_pitch = 0.0f;
local_roll = 0.0f;
@@ -513,40 +537,38 @@ void key_pressed(Key *key)
return;
}
- if (ui::root()->active()) {
- local_direction = 0.0f;
- local_pitch = 0.0f;
- local_roll = 0.0f;
-
- render::Camera::set_direction(0.0f);
- render::Camera::set_pitch(0.0f);
- }
-
if (ui::root()->input_key(true, Keyboard::translate_keysym(key->sym(), keyboard_modifiers), keyboard_modifiers)) {
-
return;
- } else if (!core::localplayer()->view() && core::application()->connected() && core::localcontrol()) {
-
- char c = key->bind(modifier()).c_str()[0];
- if (c == '@') {
- // target bind
- if (targets::current_id())
- core::cmd() << key->bind(modifier()) << " " << targets::current_id() << "\n";
- } else if (c == '+') {
- // action bind
- action_press(key, key->bind(modifier()));
+ } else if (key->bind(modifier()).size() && core::application()->connected()) {
+
+ if (!core::localplayer()->view() && core::localcontrol()) {
+
+ if (key->action()) {
+ action_press(key);
+ return;
+ }
+
+ const char c = key->bind(modifier()).c_str()[0];
+ if (c == '@') {
+ // target bind
+ if (targets::current_id()) {
+ core::cmd() << key->bind(modifier()) << " " << targets::current_id() << "\n";
+ }
+ return;
+ } else if (c) {
+ // normal bind
+ core::cmd() << key->bind(modifier()) << "\n";
+ return;
+ }
+
} else {
- // normal bind
- core::cmd() << key->bind(modifier()) << "\n";
- }
-
- } else if (core::application()->connected()) {
-
- char c = key->bind(modifier()).c_str()[0];
- if (c && c != '+' && c != '@') {
- // normal bind
- core::cmd() << key->bind(modifier()) << "\n";
+ const char c = key->bind(modifier()).c_str()[0];
+ if (c && c != '+' && c != '@') {
+ // normal bind
+ core::cmd() << key->bind(modifier()) << "\n";
+ return;
+ }
}
}
}
@@ -556,35 +578,16 @@ void key_released(Key *key)
ui::root()->input_key(false, Keyboard::translate_keysym(key->sym(), keyboard_modifiers), keyboard_modifiers);
if (core::application()->connected() && core::localcontrol()) {
-
+
// FIXME mouse release selection should be handled inside the hud
+ // note: mouse button can double as an action key
if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover() && (key->waspressed() <= (input_mousedelay->value() / 1000.0f))) {
// hovering target selected
targets::select_target(targets::hover());
}
-
-
- // the release event must still be processed as usual
- char c = 0;
- c = key->bind(Key::None).c_str()[0];
- if (c == '+') {
- // action bind
- action_release(key, key->bind(Key::None));
- }
- c = key->bind(Key::Shift).c_str()[0];
- if (c == '+') {
- // action bind
- action_release(key, key->bind(Key::Shift));
- }
- c = key->bind(Key::Ctrl).c_str()[0];
- if (c == '+') {
- // action bind
- action_release(key, key->bind(Key::Ctrl));
- }
- c = key->bind(Key::Alt).c_str()[0];
- if (c == '+') {
- // action bind
- action_release(key, key->bind(Key::Alt));
+
+ if (key->action()) {
+ action_release(key);
}
}
}
@@ -828,7 +831,7 @@ void frame()
if (core::application()->connected() && core::localcontrol()) {
mouse_control = ui::console()->hidden() && !ui::root()->active() && ((input_mousecontrol->value() > 0) || (mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time())));
-
+
if (mouse_control && joystick_control && ((render::Camera::mode() == render::Camera::Track) || (render::Camera::mode() == render::Camera::Cockpit))) {
if (!(mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()))) {
mouse_control = false;
@@ -895,6 +898,15 @@ void frame()
core::localcontrol()->set_roll(local_roll);
core::localcontrol()->set_strafe(local_strafe);
core::localcontrol()->set_afterburner(local_afterburner);
+
+ } else {
+
+ local_direction = 0.0f;
+ local_pitch = 0.0f;
+ local_roll = 0.0f;
+
+ render::Camera::set_direction(0.0f);
+ render::Camera::set_pitch(0.0f);
}
}