From f030154fe727e25a2afe1f78b3998c2d2dba95e4 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 18 Aug 2009 09:24:15 +0000 Subject: astyle cleanup, corrects not loading of material textures --- src/client/input.cc | 119 +++++++++++++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 56 deletions(-) (limited to 'src/client/input.cc') diff --git a/src/client/input.cc b/src/client/input.cc index 8b49604..790af91 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -82,15 +82,18 @@ float joystick_lastmoved = 0; const float thruster_offset = 0.05f; -int mouse_position_x() { +int mouse_position_x() +{ return mouse_x; } -int mouse_position_y() { +int mouse_position_y() +{ return mouse_y; } -Key *last_key_pressed() { +Key *last_key_pressed() +{ return last_key; } @@ -130,6 +133,9 @@ void func_ui_control(std::string const &args) render::Camera::set_direction(0.0f); render::Camera::set_pitch(0.0f); } + + con_debug << "mouse control is " << ((input_mousecontrol->value()) ? "on" : "off") << std::endl; + audio::play("ui/control"); } @@ -193,7 +199,7 @@ void func_list_binds(std::string const &args) aux::to_lowercase(keyname); keyboard->bind(keyname, ""); } else { - keyboard->list_binds(); + keyboard->list_binds(); } } else { con_warn << "Keyboard handler not installed!" << std::endl; @@ -207,8 +213,8 @@ void func_bind(std::string const &args) std::string keyname; if (argstr >> keyname) { aux::to_lowercase(keyname); - if (args.size() > keyname.size()+1) { - keyboard->bind(keyname, args.substr(keyname.size()+1)); + if (args.size() > keyname.size() + 1) { + keyboard->bind(keyname, args.substr(keyname.size() + 1)); } else { keyboard->bind(keyname, ""); } @@ -249,7 +255,7 @@ void init() keyboard = new Keyboard(); - SDL_ShowCursor(SDL_DISABLE); + SDL_ShowCursor(SDL_DISABLE); SDL_WM_GrabInput(SDL_GRAB_ON); // SDL_EnableUNICODE(1); @@ -268,7 +274,7 @@ void init() input_mousedelay->set_info("[int] mouse click time-out in milliseconds"); core::Func *func = 0; - func = core::Func::add("ui_control",func_ui_control); + func = core::Func::add("ui_control", func_ui_control); func->set_info("toggle mouse control"); func = core::Func::add("list_joystick", func_list_joystick); @@ -280,7 +286,7 @@ void init() func = core::Func::add("list_keys", func_list_keys); func->set_info("list key names"); - func = core::Func::add("list_binds",func_list_binds); + func = core::Func::add("list_binds", func_list_binds); func->set_info("list keyb binds"); func = core::Func::add("bind", (core::FuncPtr) func_bind); @@ -319,17 +325,17 @@ void shutdown() core::Func::remove("unbindall"); core::Func::remove("screenshot"); - + core::Func::remove("ui_control"); core::Func::remove("ui_view"); - + if (keyboard) { keyboard->save_binds(); delete keyboard; keyboard = 0; } - SDL_ShowCursor(SDL_ENABLE); + SDL_ShowCursor(SDL_ENABLE); SDL_WM_GrabInput(SDL_GRAB_OFF); // SDL_DisableUNICODE(0); @@ -340,11 +346,11 @@ void action_press(Key const *key, std::string const &action) /* -- 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) { @@ -384,7 +390,7 @@ void action_press(Key const *key, std::string const &action) local_afterburner = -1.0f; /* -- camera control ------------------------------ */ - + } else if (action.compare("+zoomin") == 0) { render::Camera::set_zoom(-0.1f); @@ -392,16 +398,16 @@ void action_press(Key const *key, std::string const &action) 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) ); + 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)); + 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)); + 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)); + render::Camera::set_pitch(-math::min(key->pressed() - core::application()->time(), 1.0f)); } else con_warn << "Unknown action " << action << std::endl; } @@ -410,23 +416,23 @@ void action_release(Key *key, std::string const &action) { /* -- 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))) { + + 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); } @@ -463,7 +469,7 @@ void action_release(Key *key, std::string const &action) } else if (action.compare("+reverse") == 0) { local_afterburner = 0.0f; - /* -- camera control ------------------------------ */ + /* -- camera control ------------------------------ */ } else if (action.compare("+camleft") == 0) { render::Camera::set_direction(0.0f); @@ -478,12 +484,13 @@ void action_release(Key *key, std::string const &action) } } -Key::Modifier modifier() { - if ((keyboard_modifiers & Key::Shift) > 0 ) +Key::Modifier modifier() +{ + if ((keyboard_modifiers & Key::Shift) > 0) return Key::Shift; - else if ((keyboard_modifiers & Key::Ctrl) > 0 ) + else if ((keyboard_modifiers & Key::Ctrl) > 0) return Key::Ctrl; - else if ((keyboard_modifiers & Key::Alt) > 0 ) + else if ((keyboard_modifiers & Key::Alt) > 0) return Key::Alt; else return Key::None; @@ -514,7 +521,7 @@ void key_pressed(Key *key) 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; @@ -525,7 +532,7 @@ void key_pressed(Key *key) if (c == '@') { // target bind if (targets::current_id()) - core::cmd() << key->bind(modifier()) << " " << targets::current_id() <<"\n"; + core::cmd() << key->bind(modifier()) << " " << targets::current_id() << "\n"; } else if (c == '+') { // action bind action_press(key, key->bind(modifier())); @@ -550,13 +557,13 @@ void key_released(Key *key) if (core::application()->connected() && core::localcontrol()) { - // FIXME mouse release selection should be handled inside the hud - if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover() && (key->waspressed() <= (input_mousedelay->value()/1000.0f) ) ) { + // FIXME mouse release selection should be handled inside the hud + 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]; @@ -585,7 +592,7 @@ void key_released(Key *key) void axis_event(int axis, int value) { // value is in range -32768 to 32767 - switch(axis) { + switch (axis) { case 0: // direction if (value >= 0) { local_direction = (float) value / 32767.0f; @@ -702,7 +709,7 @@ void frame() video::resize(event.resize.w, event.resize.h); break; - case SDL_MOUSEMOTION: + case SDL_MOUSEMOTION: mouse_x = event.motion.x; mouse_y = event.motion.y; mouse_moved = true; @@ -750,8 +757,8 @@ void frame() core::application()->shutdown(); return; break; - } - + } + if (key) { if (pressed) { key_pressed(key); @@ -772,7 +779,7 @@ void frame() delay = input_keydelay->value(); math::clamp(delay, 50.0f, 500.0f); } - + float repeat = 35.0f; // key repeat time-out in milliseconds if (input_keyrepeat) { repeat = input_keyrepeat->value(); @@ -783,14 +790,14 @@ void frame() (*input_keydelay) = delay; if (input_keyrepeat) (*input_keyrepeat) = repeat; - + repeat /= 1000.0f; delay /= 1000.0f; - + for (Keyboard::iterator it = keyboard->begin(); it != keyboard->end(); it++) { key = (*it).second; - if (key && (key->sym() < 512) && key->pressed()) { - if ((key->pressed()+delay < core::application()->time()) && (key->lastpressed()+repeat < core::application()->time())) { + if (key && (key->sym() < 512) && key->pressed()) { + if ((key->pressed() + delay < core::application()->time()) && (key->lastpressed() + repeat < core::application()->time())) { key->key_lastpressed = core::application()->time(); key_pressed(key); } @@ -803,7 +810,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; @@ -817,30 +824,30 @@ void frame() // direction int l = mouse_x - (render::State::width() >> 1); - - if (abs(l) < ( deadzone_size >> 1 )) { + + if (abs(l) < (deadzone_size >> 1)) { // dead zone mouse_direction = 0; } else { l = (mouse_x - deadzone_size) - ((render::State::width() - deadzone_size) >> 1); - mouse_direction = float (-l) / (float) ((render::State::width() - deadzone_size) >> 1); + mouse_direction = float(-l) / (float)((render::State::width() - deadzone_size) >> 1); mouse_deadzone = false; } // pitch int h = mouse_y - (render::State::height() >> 1); - if (abs(h) < ( deadzone_size >> 1 )) { + if (abs(h) < (deadzone_size >> 1)) { // dead zone mouse_pitch = 0; } else { h = (mouse_y - deadzone_size) - ((render::State::height() - deadzone_size) >> 1); - mouse_pitch = float (-h) / (float) ((render::State::height() - deadzone_size) >> 1); + mouse_pitch = float(-h) / (float)((render::State::height() - deadzone_size) >> 1); mouse_deadzone = false; } if ((render::Camera::mode() == render::Camera::Track) || (render::Camera::mode() == render::Camera::Cockpit)) { - + //local_direction = mouse_direction * math::absf(mouse_direction); //local_pitch = mouse_pitch * math::absf(mouse_pitch); local_direction = mouse_direction; @@ -848,10 +855,10 @@ void frame() } else if (render::Camera::mode() == render::Camera::Free) { // squared values to smoothen camera movement - render::Camera::set_direction( -mouse_direction * math::absf(mouse_direction)); + render::Camera::set_direction(-mouse_direction * math::absf(mouse_direction)); render::Camera::set_pitch(-mouse_pitch * math::absf(mouse_pitch)); } - + } math::clamp(local_direction, -1.0f, 1.0f); @@ -866,7 +873,7 @@ void frame() core::localcontrol()->set_thrust(local_thrust); core::localcontrol()->set_direction(local_direction); - core::localcontrol()->set_pitch(local_pitch / render::State::aspect() ); + core::localcontrol()->set_pitch(local_pitch / render::State::aspect()); core::localcontrol()->set_roll(local_roll); core::localcontrol()->set_strafe(local_strafe); core::localcontrol()->set_afterburner(local_afterburner); -- cgit v1.2.3