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.cc56
1 files changed, 45 insertions, 11 deletions
diff --git a/src/client/input.cc b/src/client/input.cc
index b281b8e..6778e9c 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -4,21 +4,23 @@
the terms and conditions of the GNU General Public License version 2
*/
-#include "auxiliary/functions.h"
+#include "SDL/SDL.h"
+
#include "audio/audio.h"
-#include "core/core.h"
-#include "client/client.h"
-#include "client/input.h"
+#include "auxiliary/functions.h"
#include "client/chat.h"
+#include "client/client.h"
#include "client/console.h"
+#include "client/input.h"
+#include "client/joystick.h"
#include "client/keyboard.h"
#include "client/targets.h"
#include "client/video.h"
-#include "render/camera.h"
+#include "core/core.h"
#include "math/functions.h"
-#include "render/text.h"
+#include "render/camera.h"
#include "render/draw.h"
-#include "SDL/SDL.h"
+#include "render/text.h"
namespace client
{
@@ -36,7 +38,9 @@ namespace input
Keyboard *keyboard = 0;
// keyboard modifiers shift, ctrl, alt etc
int keyboard_modifiers = 0;
-
+// last key pressed
+Key *last_key = 0;
+float last_key_time = 0;
// local controls
float local_direction = 0.0f;
@@ -73,6 +77,10 @@ int mouse_position_y() {
return mouse_y;
}
+Key *last_key_pressed() {
+ return last_key;
+}
+
//--- engine functions --------------------------------------------
void func_screenshot(std::string const & args)
@@ -231,6 +239,8 @@ void init()
SDL_WM_GrabInput(SDL_GRAB_ON);
// SDL_EnableUNICODE(1);
+ Joystick::init();
+
input_mousecontrol = core::Cvar::get("input_mousecontrol", 1.0f, core::Cvar::Archive);
input_mousecontrol->set_info("[bool] enable or disable mouse control");
@@ -285,6 +295,8 @@ void shutdown()
{
con_print << "^BShutting down input..." << std::endl;
+ Joystick::shutdown();
+
core::Func::remove("list_actions");
core::Func::remove("list_keys");
core::Func::remove("list_binds");
@@ -551,6 +563,7 @@ void reset()
key->key_waspressed = 0;
}
}
+ last_key = 0;
}
void frame(float seconds)
@@ -573,11 +586,20 @@ void frame(float seconds)
render::reset();
}
+ /* -- detect joystick changes --------------------- */
+ Joystick::frame();
+
+
/* -- poll SDL keyboard events -------------------- */
SDL_Event event;
Key *key = 0;
bool pressed = false;
+ if (last_key_time + 1.0f < client()->time()) {
+ last_key = 0;
+ last_key_time = 0;
+ }
+
memset(&event, 0, sizeof(SDL_Event));
while (SDL_PollEvent(&event)) {
pressed = false;
@@ -591,7 +613,6 @@ void frame(float seconds)
break;
case SDL_MOUSEBUTTONDOWN:
- // override for gui mouse down
key = keyboard->press(512 + event.button.button);
pressed = true;
break;
@@ -601,6 +622,16 @@ void frame(float seconds)
pressed = false;
break;
+ case SDL_JOYBUTTONDOWN:
+ key = keyboard->press(564 + event.jbutton.button);
+ pressed = true;
+ break;
+
+ case SDL_JOYBUTTONUP:
+ key = keyboard->release(564 + event.jbutton.button);
+ pressed = false;
+ break;
+
case SDL_KEYDOWN:
keyboard_modifiers = event.key.keysym.mod;
key = keyboard->press(event.key.keysym.sym);
@@ -620,10 +651,13 @@ void frame(float seconds)
}
if (key) {
- if (pressed)
+ if (pressed) {
key_pressed(key);
- else
+ last_key = key; // remember the last key that was pressed
+ last_key_time = client()->time();
+ } else {
key_released(key);
+ }
}
}