From 67517585e9b55967f5236ed5ebca77173eb2f2e3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 22 Jul 2008 22:48:21 +0000 Subject: reset keyboard state on r_restart --- src/client/client.cc | 2 ++ src/client/input.cc | 30 ++++++++++++++++++++++++++++++ src/client/input.h | 3 +++ 3 files changed, 35 insertions(+) diff --git a/src/client/client.cc b/src/client/client.cc index 2f60fce..7951577 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -35,6 +35,8 @@ void func_r_restart(std::string const &args) if (!video::init()) { app.quit(1); } + + input::reset(); } //--- public ------------------------------------------------------ diff --git a/src/client/input.cc b/src/client/input.cc index 819ce27..6306fc8 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -453,6 +453,36 @@ void key_released(Key *key) } +void reset() +{ + local_direction = 0.0f; + local_pitch = 0.0f; + local_roll = 0.0f; + if (core::localcontrol()) { + local_thrust = core::localcontrol()->thrust(); + last_control = core::localcontrol()->id(); + } else { + local_thrust = 0; + last_control = 0; + } + mouse_pitch = 0.0f; + mouse_direction = 0.0f; + mouse_x = video::width / 2; + mouse_y = video::height / 2; + render::Camera::reset(); + mouse_control_override = false; + 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; + } + } +} + void frame(float seconds) { /* -- detect localcontrol() changes --------------- */ diff --git a/src/client/input.h b/src/client/input.h index 96192f8..b2b44c8 100644 --- a/src/client/input.h +++ b/src/client/input.h @@ -24,6 +24,9 @@ void shutdown(); /// handle one frame of input events void frame(float seconds); +/// reset input state +void reset(); + extern int mouse_x; extern int mouse_y; -- cgit v1.2.3