diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/input.cc | 72 | ||||
-rw-r--r-- | src/client/key.cc | 1 | ||||
-rw-r--r-- | src/client/key.h | 16 | ||||
-rw-r--r-- | src/client/keyboard.cc | 15 |
4 files changed, 53 insertions, 51 deletions
diff --git a/src/client/input.cc b/src/client/input.cc index b5d4c0d..f1d9464 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -58,10 +58,12 @@ float mouse_direction = 0; bool mouse_deadzone = false; // true if the mouse has control +float mouse_control_override_time = 0; bool mouse_control_override = false; bool mouse_control = false; const float thruster_offset = 0.05f; +const float mouse_timeout = 0.200f; // 200 ms mouse timout int mouse_position_x() { return mouse_x; @@ -232,10 +234,10 @@ void init() input_mousecontrol = core::Cvar::get("input_mousecontrol", 1.0f, core::Cvar::Archive); input_mousecontrol->set_info("[bool] enable or disable mouse control"); - input_keydelay = core::Cvar::get("input_keydelay", 250.0f, core::Cvar::Archive); + input_keydelay = core::Cvar::get("input_keydelay", 150.0f, core::Cvar::Archive); input_keydelay->set_info("[int] keyboard delay time-out in milliseconds"); - input_keyrepeat = core::Cvar::get("input_keyrepeat", 30.0f, core::Cvar::Archive); + input_keyrepeat = core::Cvar::get("input_keyrepeat", 15.0f, core::Cvar::Archive); input_keyrepeat->set_info("[int] keyboard repeat time-out in milliseconds"); core::Func *func = 0; @@ -308,7 +310,7 @@ void shutdown() } -void action_press(std::string const &action) +void action_press(Key const *key, std::string const &action) { /* -- thruster ------------------------------------ */ if (action.compare("+thrustup") == 0) { @@ -321,6 +323,7 @@ void action_press(std::string const &action) /* -- mouse control ------------------------------- */ } else if (action.compare("+control") == 0) { mouse_control_override = true; + mouse_control_override_time = key->pressed(); /* -- directional control ------------------------- */ } else if (action.compare("+left") == 0) { @@ -357,7 +360,7 @@ void action_press(std::string const &action) con_warn << "Unknown action " << action << std::endl; } -void action_release(std::string const &action) +void action_release(Key *key, std::string const &action) { /* -- thruster ------------------------------------ */ if (action.compare("+thrustup") == 0) { @@ -369,6 +372,7 @@ void action_release(std::string const &action) /* -- mouse control ------------------------------- */ } else if (action.compare("+control") == 0) { mouse_control_override = false; + mouse_control_override_time = 0; if (!input_mousecontrol->value()) { local_direction = 0.0f; local_pitch = 0.0f; @@ -464,22 +468,14 @@ void key_pressed(Key *key) } else if (core::application()->connected() && core::localcontrol()) { - if ((render::Camera::mode() == render::Camera::Free) && (key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover()) { - // hovering target selected - targets::select_target(targets::hover()); - - } else { - char c = key->bind(convert_SDL_modifier(keyboard_modifiers)).c_str()[0]; - if (c == '+') { - // action bind - action_press(key->bind(convert_SDL_modifier(keyboard_modifiers))); - - } else if (c) { - // normal bind - core::cmd() << key->bind(convert_SDL_modifier(keyboard_modifiers)) << "\n"; - } + char c = key->bind(convert_SDL_modifier(keyboard_modifiers)).c_str()[0]; + if (c == '+') { + // action bind + action_press(key, key->bind(convert_SDL_modifier(keyboard_modifiers))); + } else if (c) { + // normal bind + core::cmd() << key->bind(convert_SDL_modifier(keyboard_modifiers)) << "\n"; } - } else if (core::application()->connected()) { char c = key->bind(convert_SDL_modifier(keyboard_modifiers)).c_str()[0]; @@ -495,7 +491,7 @@ void key_released(Key *key) { if (core::application()->connected() && core::localcontrol() && !console()->visible() && !chat::visible()) { - if ((render::Camera::mode() != render::Camera::Free) && (key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover()) { + if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover() && (key->waspressed() <= mouse_timeout) ) { // hovering target selected targets::select_target(targets::hover()); } @@ -505,22 +501,22 @@ void key_released(Key *key) c = key->bind(Key::None).c_str()[0]; if (c == '+') { // action bind - action_release(key->bind(Key::None)); + action_release(key, key->bind(Key::None)); } c = key->bind(Key::Shift).c_str()[0]; if (c == '+') { // action bind - action_release(key->bind(Key::Shift)); + action_release(key, key->bind(Key::Shift)); } c = key->bind(Key::Ctrl).c_str()[0]; if (c == '+') { // action bind - action_release(key->bind(Key::Ctrl)); + action_release(key, key->bind(Key::Ctrl)); } c = key->bind(Key::Alt).c_str()[0]; if (c == '+') { // action bind - action_release(key->bind(Key::Alt)); + action_release(key, key->bind(Key::Alt)); } } } @@ -543,14 +539,16 @@ void reset() mouse_y = video::height / 2; render::Camera::reset(); mouse_control_override = false; + mouse_control_override_time = 0; targets::reset(); render::reset(); for (Keyboard::iterator it = keyboard->begin(); it != keyboard->end(); it++) { Key *key = (*it).second; if (key) { - key->pressed() = 0; - key->lastpressed() = 0; + key->key_pressed = 0; + key->key_lastpressed = 0; + key->key_waspressed = 0; } } } @@ -630,23 +628,18 @@ void frame(float seconds) } /* -- handle key repeat --------------------------- */ - float delay = 250.0f; // key delay time-out in milliseconds + float delay = 150.0f; // key delay time-out in milliseconds if (input_keydelay) { delay = input_keydelay->value(); math::clamp(delay, 50.0f, 500.0f); } - float repeat = 30.0f; // key repeat time-out in milliseconds + float repeat = 10.0f; // key repeat time-out in milliseconds if (input_keyrepeat) { repeat = input_keyrepeat->value(); math::clamp(repeat, 10.0f, 250.0f); } - - if (repeat > delay) { - float tmp = repeat; - repeat = delay; - delay = tmp; - } + if (input_keydelay) (*input_keydelay) = delay; if (input_keyrepeat) @@ -660,9 +653,9 @@ void frame(float seconds) if (key && key->sym() < 512 && key->pressed()) { while ((key->pressed()+delay < core::application()->time()) && (key->lastpressed()+repeat < core::application()->time())) { if (key->lastpressed() > key->pressed()) - key->lastpressed() += repeat; + key->key_lastpressed += repeat; else - key->lastpressed() += delay; + key->key_lastpressed += delay; key_pressed(key); } } @@ -671,11 +664,12 @@ void frame(float seconds) /* -- process mouse movement ----------------------*/ mouse_control = false; mouse_deadzone = false; - key->lastpressed() += repeat; + if (core::application()->connected() && core::localcontrol()) { - mouse_control = !console()->visible() && ((input_mousecontrol->value() > 0) || mouse_control_override); - core::localcontrol()->set_autolevel(!mouse_control); + mouse_control = !console()->visible() && ((input_mousecontrol->value() > 0) + || (mouse_control_override && (mouse_control_override_time + mouse_timeout < core::application()->time()))); + //core::localcontrol()->set_autolevel(!mouse_control); if (mouse_control) { // the mouse will not react if it is in the deadzone diff --git a/src/client/key.cc b/src/client/key.cc index 27d280f..c2da4a7 100644 --- a/src/client/key.cc +++ b/src/client/key.cc @@ -15,6 +15,7 @@ Key::Key(const char *name, int keysym, char ascii, const char *bind) key_ascii = ascii; key_pressed = 0; key_lastpressed = 0; + key_waspressed = 0; key_name.assign(name); diff --git a/src/client/key.h b/src/client/key.h index d1a8e96..06e0587 100644 --- a/src/client/key.h +++ b/src/client/key.h @@ -41,10 +41,13 @@ public: std::string const & bind(Modifier mod) const; /// first time the key was pressed since previous release - inline float & pressed() { return key_pressed; } + inline float pressed() const { return key_pressed; } - /// last time the key was pressed - inline float & lastpressed() { return key_lastpressed; } + /// last time the key was pressed (includes repeats) + inline float lastpressed() const { return key_lastpressed; } + + /// time the key was pressed when it is released + inline float waspressed() const { return key_waspressed; } inline std::string const & name() const { return key_name; } @@ -52,14 +55,15 @@ public: inline int sym() const { return key_sym; } + float key_pressed; + float key_lastpressed; + float key_waspressed; + private: std::string key_name; int key_sym; char key_ascii; - float key_pressed; - float key_lastpressed; - std::string key_bind; std::string key_bind_shift; std::string key_bind_ctrl; diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc index 791e6df..420d1bb 100644 --- a/src/client/keyboard.cc +++ b/src/client/keyboard.cc @@ -296,8 +296,10 @@ Key * Keyboard::release(unsigned int sym) return 0; } - key->pressed() = 0; - key->lastpressed() = 0; + key->key_waspressed = (core::application()->time() - key->pressed()); + key->key_pressed = 0; + key->key_lastpressed = 0; + return key; } @@ -313,10 +315,11 @@ Key * Keyboard::press(unsigned int sym) Key * Keyboard::press(Key *key) { - if (!key->pressed()) - key->pressed() = core::application()->time(); - key->lastpressed() = core::application()->time(); - + if (key->pressed() == 0) { + key->key_pressed = core::application()->time(); + key->key_waspressed = 0; + } + key->key_lastpressed = core::application()->time(); return key; } |