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.cc72
1 files changed, 33 insertions, 39 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