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.cc198
1 files changed, 76 insertions, 122 deletions
diff --git a/src/client/input.cc b/src/client/input.cc
index 775f03a..f8d76f2 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -29,9 +29,10 @@ namespace input
//--- local variables ---------------------------------------------
+// keyboard instance
Keyboard *keyboard = 0;
-
-//bool free_control = true;
+// keyboard modifiers shift, ctrl, alt etc
+int keyboard_modifiers = 0;
// local controls
@@ -377,6 +378,73 @@ void action_release(std::string const &action)
}
}
+void key_pressed(Key *key)
+{
+
+ if ((key->sym() == SDLK_ESCAPE) || (key->bind(Key::None).compare("ui_console") == 0)) {
+ console()->toggle();
+ local_direction = 0.0f;
+ local_pitch = 0.0f;
+ local_roll = 0.0f;
+
+ render::Camera::set_direction(0.0f);
+ render::Camera::set_pitch(0.0f);
+
+ } else if (console()->visible()) {
+ // send key events to the console
+ if (key->sym() < 512)
+ console()->keypressed(translate_keysym(key->sym(), keyboard_modifiers));
+
+ } else if (chat::visible()) {
+ // send key events to the chat box
+ if (key->sym() < 512)
+ chat::keypressed(translate_keysym(key->sym(), keyboard_modifiers));
+
+ } else if (core::application()->connected() && core::localcontrol()) {
+
+ if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover()) {
+ // hovering target selected
+ targets::select_target(targets::hover());
+
+ } else {
+ // FIXME modifiers
+ char c = key->bind(Key::None).c_str()[0];
+ if (c == '+') {
+ // action bind
+ action_press(key->bind(Key::None));
+
+ } else if (c) {
+ // normal bind
+ core::cmd() << key->bind(Key::None) << "\n";
+ }
+ }
+
+ } else if (core::application()->connected()) {
+ // FIXME modifiers
+
+ char c = key->bind(Key::None).c_str()[0];
+ if (c && c != '+') {
+ // normal bind
+ core::cmd() << key->bind(Key::None) << "\n";
+ }
+ }
+
+}
+
+void key_released(Key *key)
+{
+ if (core::application()->connected() && core::localcontrol() && !console()->visible() && !chat::visible()) {
+
+ // FIXME modifiers
+ char c = key->bind(Key::None).c_str()[0];
+ if (c == '+') {
+ // action bind
+ action_release(key->bind(Key::None));
+ }
+ }
+}
+
+
void frame(float seconds)
{
if (core::localcontrol() && (last_control != core::localcontrol()->id())) {
@@ -423,11 +491,13 @@ void frame(float seconds)
break;
case SDL_KEYDOWN:
+ keyboard_modifiers = event.key.keysym.mod;
key = keyboard->press(event.key.keysym.sym);
pressed = true;
break;
case SDL_KEYUP:
+ keyboard_modifiers = event.key.keysym.mod;
key = keyboard->release(event.key.keysym.sym);
pressed = false;
break;
@@ -439,74 +509,10 @@ void frame(float seconds)
}
if (key) {
- if (pressed) {
-/*
- if (keysym.mod & KMOD_NUM) numlock = true else numlock = false;
- if (keysym.mod & KMOD_CAPS) capslock = true; else capslock = false;
- if ((keysym.mod & KMOD_LSHIFT) || (keysym.mod & KMOD_RSHIFT)) capslock != capslock;
-*/
- // FIXME console key is always captured
- // FIXME ESC should escape to gui
-
- if ((key->sym() == SDLK_ESCAPE) || (key->bind(Key::None).compare("ui_console") == 0)) {
- console()->toggle();
- local_direction = 0.0f;
- local_pitch = 0.0f;
- local_roll = 0.0f;
-
- render::Camera::set_direction(0.0f);
- render::Camera::set_pitch(0.0f);
-
- } else if (console()->visible()) {
- // send key events to the console
- if (event.type == SDL_KEYDOWN)
- console()->keypressed(translate_keysym(event.key.keysym));
-
- } else if (chat::visible()) {
- // send key events to the chat box
- if (event.type == SDL_KEYDOWN)
- chat::keypressed(translate_keysym(event.key.keysym));
-
- } else if (core::application()->connected() && core::localcontrol()) {
-
- if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover()) {
- // hovering target selected
- targets::select_target(targets::hover());
-
- } else {
- // FIXME modifier
- char c = key->bind(Key::None).c_str()[0];
- if (c == '+') {
- // action bind
- action_press(key->bind(Key::None));
-
- } else if (c) {
- // normal bind
- core::cmd() << key->bind(Key::None) << "\n";
- }
- }
-
- } else if (core::application()->connected()) {
- // FIXME modifier
-
- char c = key->bind(Key::None).c_str()[0];
- if (c && c != '+') {
- // normal bind
- core::cmd() << key->bind(Key::None) << "\n";
- }
- }
-
- } else {
-
- if (core::application()->connected() && core::localcontrol() && !console()->visible() && !chat::visible()) {
- // FIXME modifier (note: mmmmm, modifier could be released by now)
- char c = key->bind(Key::None).c_str()[0];
- if (c == '+') {
- // action bind
- action_release(key->bind(Key::None));
- }
- }
- }
+ if (pressed)
+ key_pressed(key);
+ else
+ key_released(key);
}
}
@@ -555,58 +561,6 @@ void frame(float seconds)
render::Camera::set_direction( -mouse_direction * math::absf(mouse_direction));
render::Camera::set_pitch(-mouse_pitch * math::absf(mouse_pitch));
}
-
- } else {
- /*
- const float MIN_DELTA = 10e-10;
- const float ANGLE_DELTA = 0.01f;
-
- math::Axis target_axis; // FIXME
- float cosangle;
- const math::Axis & entity_axis= core::localcontrol()->axis();
-
- // auto-level: pitch
- local_pitch = 0;
-
- // project target_axis.up() into the plane with axis->left() normal
- math::Vector3f n = entity_axis.left();
- math::Vector3f p = target_axis.up();
- float u = p[0]*n[0] + p[1]*n[1] + p[2]*n[2] / (-n[0]*n[0] - n[1]*n[1] - n[2] * n[2]);
- p = target_axis.up() + u * n;
-
- float side = entity_axis.forward().x * p.x +
- entity_axis.forward().y * p.y +
- entity_axis.forward().z * p.z;
-
- if ((fabs(side) - MIN_DELTA > 0)) {
-
- cosangle = math::dotproduct(p, entity_axis.up());
- if (fabs(cosangle) + ANGLE_DELTA < 1 ) {
- local_pitch = -3 * math::sgnf(side) * (1-cosangle);
- }
- }
-
- // auto-level: roll
- local_roll = 0;
-
- // project target_axis.up() into the plane with axis.forward() normal
- n = entity_axis.forward();
- p = target_axis.up();
- u = p[0]*n[0] + p[1]*n[1] + p[2]*n[2] / (-n[0]*n[0] - n[1]*n[1] - n[2] * n[2]);
- p = target_axis.up() + u * n;
-
- side = entity_axis.left().x * p.x +
- entity_axis.left().y * p.y +
- entity_axis.left().z * p.z;
-
- if ((fabs(side) - MIN_DELTA > 0)) {
-
- cosangle = math::dotproduct(p, entity_axis.up());
- if (fabs(cosangle) + ANGLE_DELTA < 1 ) {
- local_roll = 3 * math::sgnf(side) * (1-cosangle);
- }
- }
- */
}