Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-07-21 22:03:26 +0000
committerStijn Buys <ingar@osirion.org>2008-07-21 22:03:26 +0000
commit980c5c41dc8e88ab3e7a5751348a92a0662a2ea4 (patch)
tree638fc130c94973038b76b50c1fd68a74c2dcdd9f /src/client
parent5a4bcd856787af106807b0b18fba8e4e2fae63ef (diff)
prepare keybinds for modifier keys, fix for the camera clipping issue
Diffstat (limited to 'src/client')
-rw-r--r--src/client/input.cc22
-rw-r--r--src/client/key.cc77
-rw-r--r--src/client/key.h27
-rw-r--r--src/client/keyboard.cc211
-rw-r--r--src/client/keyboard.h3
-rw-r--r--src/client/targets.cc10
-rw-r--r--src/client/video.cc10
7 files changed, 238 insertions, 122 deletions
diff --git a/src/client/input.cc b/src/client/input.cc
index 8075058..5e75f0a 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -418,7 +418,7 @@ void frame(float seconds)
// FIXME console key is always captured
// FIXME ESC should escape to gui
- if ((key->sym() == SDLK_ESCAPE) || (key->bind().compare("ui_console") == 0)) {
+ if ((key->sym() == SDLK_ESCAPE) || (key->bind(Key::None).compare("ui_console") == 0)) {
console()->toggle();
local_direction = 0.0f;
local_pitch = 0.0f;
@@ -444,34 +444,36 @@ void frame(float seconds)
targets::select_target(targets::hover());
} else {
- char c = key->bind().c_str()[0];
+ // FIXME modifier
+ char c = key->bind(Key::None).c_str()[0];
if (c == '+' || c == '-') {
// action bind
- action_press(key->bind());
+ action_press(key->bind(Key::None));
} else if (c) {
// normal bind
- core::cmd() << key->bind() << "\n";
+ core::cmd() << key->bind(Key::None) << "\n";
}
}
} else if (core::application()->connected()) {
-
- char c = key->bind().c_str()[0];
+ // FIXME modifier
+
+ char c = key->bind(Key::None).c_str()[0];
if (c && c != '+' && c != '-') {
// normal bind
- core::cmd() << key->bind() << "\n";
+ core::cmd() << key->bind(Key::None) << "\n";
}
}
} else {
if (core::application()->connected() && core::localcontrol() && !console()->visible() && !chat::visible()) {
-
- char c = key->bind().c_str()[0];
+ // FIXME modifier (note: mmmmm, modifier could be released by now)
+ char c = key->bind(Key::None).c_str()[0];
if (c == '+' || c == '-') {
// action bind
- action_release(key->bind());
+ action_release(key->bind(Key::None));
}
}
}
diff --git a/src/client/key.cc b/src/client/key.cc
index 066f6ef..9b0c942 100644
--- a/src/client/key.cc
+++ b/src/client/key.cc
@@ -4,6 +4,7 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include "auxiliary/functions.h"
#include "client/key.h"
namespace client {
@@ -16,14 +17,86 @@ Key::Key(const char *name, unsigned int keysym, char ascii, const char *bind)
key_name.assign(name);
+ clear();
+
if (bind)
key_bind.assign(bind);
- else
- key_bind.clear();
}
Key::~Key()
{
}
+std::string const & Key::bind(Modifier mod) const
+{
+ switch (mod) {
+ case None:
+ return key_bind;
+ break;
+ case Shift:
+ return key_bind_shift;
+ break;
+ case Ctrl:
+ return key_bind_ctrl;
+ break;
+ case Alt:
+ break;
+ }
+
+ return key_bind_alt;
+}
+
+void Key::clear()
+{
+ key_bind.clear();
+ key_bind_shift.clear();
+ key_bind_ctrl.clear();
+ key_bind_alt.clear();
+}
+
+void Key::clear(Modifier mod)
+{
+ switch (mod) {
+ case None:
+ key_bind.clear();
+ break;
+ case Shift:
+ key_bind_shift.clear();
+ break;
+ case Ctrl:
+ key_bind_ctrl.clear();
+ break;
+ case Alt:
+ key_bind_alt.clear();
+ break;
+ }
+}
+
+void Key::assign(Modifier mod, const char *bind)
+{
+ if (!bind) {
+ clear(mod);
+ return;
+ }
+
+ switch (mod) {
+ case None:
+ key_bind.assign(bind);
+ aux::trim(key_bind);
+ break;
+ case Shift:
+ key_bind_shift.assign(bind);
+ aux::trim(key_bind_shift);
+ break;
+ case Ctrl:
+ key_bind_ctrl.assign(bind);
+ aux::trim(key_bind_ctrl);
+ break;
+ case Alt:
+ key_bind_alt.assign(bind);
+ aux::trim(key_bind_alt);
+ break;
+ }
+}
+
}
diff --git a/src/client/key.h b/src/client/key.h
index ece7669..344e1fa 100644
--- a/src/client/key.h
+++ b/src/client/key.h
@@ -14,27 +14,44 @@ namespace client {
class Key
{
public:
+ /// define a new key
Key(const char *name, unsigned int keysym, char ascii=0, const char *bind=0);
~Key();
+
+ /// key modifiers
+ enum Modifier { None=0, Shift=1, Ctrl=2, Alt=3 };
+
+ /// clear all binds
+ void clear();
+
+ /// set the bind for a specific modifier
+ void assign(Modifier mod, const char *bind);
+
+ /// clear the bind for a specific modifier
+ void clear(Modifier mod);
+
+ /// return the bind for a specific modifier
+ std::string const & bind(Modifier mod) const;
inline float & pressed() { return key_pressed; }
inline std::string const & name() const { return key_name; }
- inline std::string & bind() { return key_bind; }
-
inline char ascii() const { return key_ascii; }
inline unsigned int sym() const { return key_sym; }
private:
+ std::string key_name;
unsigned int key_sym;
char key_ascii;
- std::string key_name;
- std::string key_bind;
-
float key_pressed;
+
+ std::string key_bind;
+ std::string key_bind_shift;
+ std::string key_bind_ctrl;
+ std::string key_bind_alt;
};
} // namespace client
diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc
index 8295fce..170fbd1 100644
--- a/src/client/keyboard.cc
+++ b/src/client/keyboard.cc
@@ -15,7 +15,8 @@
#include "filesystem/filesystem.h"
#include "sys/sys.h"
-namespace client {
+namespace client
+{
/*
Notes:
@@ -29,25 +30,25 @@ Keyboard::Keyboard()
add_key("backspace", SDLK_BACKSPACE);
add_key("tab", SDLK_TAB);
- add_key("clear", SDLK_CLEAR);
- add_key("enter", SDLK_RETURN);
- add_key("pause", SDLK_PAUSE);
- add_key("esc", SDLK_ESCAPE);
- add_key("space", SDLK_SPACE, ' ', "ui_control");
- add_key("!", SDLK_EXCLAIM, '!');
- add_key("\"", SDLK_QUOTEDBL, '"');
- add_key("#", SDLK_HASH, '#');
- add_key("$", SDLK_DOLLAR, '$');
- add_key("&", SDLK_AMPERSAND, '&');
- add_key("'", SDLK_QUOTE, '\'');
+ add_key("clear", SDLK_CLEAR);
+ add_key("enter", SDLK_RETURN);
+ add_key("pause", SDLK_PAUSE);
+ add_key("esc", SDLK_ESCAPE);
+ add_key("space", SDLK_SPACE, ' ', "ui_control");
+ add_key("!", SDLK_EXCLAIM, '!');
+ add_key("\"", SDLK_QUOTEDBL, '"');
+ add_key("#", SDLK_HASH, '#');
+ add_key("$", SDLK_DOLLAR, '$');
+ add_key("&", SDLK_AMPERSAND, '&');
+ add_key("'", SDLK_QUOTE, '\'');
add_key("(", SDLK_LEFTPAREN, '(');
- add_key(")", SDLK_RIGHTPAREN, ')');
- add_key("*", SDLK_ASTERISK, '*');
- add_key("+", SDLK_PLUS, '+');
- add_key(",", SDLK_COMMA, ',');
- add_key("-", SDLK_MINUS, '-');
- add_key(".", SDLK_PERIOD, '.');
- add_key("/", SDLK_SLASH, '/');
+ add_key(")", SDLK_RIGHTPAREN, ')');
+ add_key("*", SDLK_ASTERISK, '*');
+ add_key("+", SDLK_PLUS, '+');
+ add_key(",", SDLK_COMMA, ',');
+ add_key("-", SDLK_MINUS, '-');
+ add_key(".", SDLK_PERIOD, '.');
+ add_key("/", SDLK_SLASH, '/');
add_key("0", SDLK_0, '0');
add_key("1", SDLK_1, '1');
@@ -61,18 +62,18 @@ Keyboard::Keyboard()
add_key("9", SDLK_9, '9');
add_key(":", SDLK_COLON, ':');
- add_key(";", SDLK_SEMICOLON, ';');
- add_key("<", SDLK_LESS, '<');
- add_key("=", SDLK_EQUALS, '=');
- add_key(">", SDLK_GREATER, '>');
- add_key("?", SDLK_QUESTION, '?');
- add_key("@", SDLK_AT, '@');
- add_key("[", SDLK_LEFTBRACKET, '[');
- add_key("\\", SDLK_BACKSLASH, '\\');
- add_key("]", SDLK_RIGHTBRACKET, ']');
- add_key("^", SDLK_CARET, '^');
- add_key("_", SDLK_UNDERSCORE, '_');
- add_key("`", SDLK_BACKQUOTE, '`', "ui_console");
+ add_key(";", SDLK_SEMICOLON, ';');
+ add_key("<", SDLK_LESS, '<');
+ add_key("=", SDLK_EQUALS, '=');
+ add_key(">", SDLK_GREATER, '>');
+ add_key("?", SDLK_QUESTION, '?');
+ add_key("@", SDLK_AT, '@');
+ add_key("[", SDLK_LEFTBRACKET, '[');
+ add_key("\\", SDLK_BACKSLASH, '\\');
+ add_key("]", SDLK_RIGHTBRACKET, ']');
+ add_key("^", SDLK_CARET, '^');
+ add_key("_", SDLK_UNDERSCORE, '_');
+ add_key("`", SDLK_BACKQUOTE, '`', "ui_console");
add_key("a", SDLK_a, 'a');
add_key("b", SDLK_b, 'b');
@@ -112,7 +113,7 @@ Keyboard::Keyboard()
add_key("kp7", SDLK_KP7);
add_key("kp8", SDLK_KP8, 0, "+down");
add_key("kp9", SDLK_KP9);
-
+
add_key("kpperiod", SDLK_KP_PERIOD, '.');
add_key("kpdiv", SDLK_KP_DIVIDE, '/', "+rollleft");
add_key("kpmul", SDLK_KP_MULTIPLY, '*', "+rollright");
@@ -120,7 +121,7 @@ Keyboard::Keyboard()
add_key("kpplus", SDLK_KP_PLUS, '+', "+thrust");
add_key("kpenter", SDLK_KP_ENTER, '\n');
add_key("kpequal", SDLK_KP_EQUALS, '=');
-
+
add_key("up", SDLK_UP, 0, "+camup");
add_key("down", SDLK_DOWN, 0, "+camdown");
add_key("right", SDLK_RIGHT, 0, "+camright");
@@ -147,7 +148,7 @@ Keyboard::Keyboard()
add_key("f13", SDLK_F13);
add_key("f14", SDLK_F14);
add_key("f15", SDLK_F15);
-
+
add_key("numlock", SDLK_NUMLOCK);
add_key("capslock", SDLK_CAPSLOCK);
add_key("scrollock", SDLK_SCROLLOCK);
@@ -170,7 +171,7 @@ Keyboard::Keyboard()
add_key("help", SDLK_HELP);
add_key("print", SDLK_PRINT, 0, "screenshot");
add_key("sysrq", SDLK_SYSREQ);
- add_key("breal", SDLK_BREAK);
+ add_key("break", SDLK_BREAK);
add_key("menu", SDLK_MENU);
add_key("power", SDLK_POWER);
add_key("euro", SDLK_EURO);
@@ -186,8 +187,8 @@ Keyboard::Keyboard()
Keyboard::~Keyboard()
{
- for(iterator it = begin(); it != end(); it++)
- delete (*it).second;
+ for (iterator it = begin(); it != end(); it++)
+ delete(*it).second;
keys.clear();
}
@@ -211,8 +212,8 @@ void Keyboard::save_binds()
iterator it;
for (it = begin(); it != end(); it++) {
Key *key = (*it).second;
- if (key->bind().size()) {
- ofs << "bind " << key->name() << " " << key->bind() << std::endl;
+ if (key->bind(Key::None).size()) {
+ ofs << "bind " << key->name() << " " << key->bind(Key::None) << std::endl;
}
/*
} else {
@@ -241,7 +242,7 @@ void Keyboard::load_binds()
if (line[0] && line[0] != '#' && line[0] != ';')
core::cmd() << line << '\n';
}
-
+
// execute commands in the buffer
core::CommandBuffer::exec();
}
@@ -251,7 +252,7 @@ Key * Keyboard::release(unsigned int sym)
if (!key) {
return 0;
}
-
+
key->pressed() = 0;
return key;
}
@@ -262,7 +263,7 @@ Key * Keyboard::press(unsigned int sym)
if (!key) {
return 0;
}
-
+
if (!key->pressed())
key->pressed() = core::application()->time();
@@ -293,8 +294,7 @@ void Keyboard::bind(std::string const &name, const std::string str)
{
Key *key = find(name);
if (key) {
- key->bind().assign(str);
- aux::trim(key->bind());
+ key->assign(Key::None, str.c_str());
} else {
con_print << "Key '" << name << "' not found." << std::endl;
}
@@ -304,12 +304,20 @@ void Keyboard::unbind(std::string const &name)
{
Key *key = find(name);
if (key) {
- key->bind().clear();
+ key->clear(Key::None);
} else {
con_print << "Key '" << name << "' not found." << std::endl;
}
}
+void Keyboard::unbindall()
+{
+ for (iterator it = begin(); it != end(); it++) {
+ Key *key = (*it).second;
+ key->clear();
+ }
+}
+
void Keyboard::add_key(const char *name, const unsigned int keysym, const char ascii, const char *bind)
{
keys[keysym] = new Key(name, keysym, ascii, bind);
@@ -318,7 +326,7 @@ void Keyboard::add_key(const char *name, const unsigned int keysym, const char a
void Keyboard::list_keys()
{
for (iterator it = begin(); it != end(); it++) {
- con_print << " " << aux::pad_left((*it).second->name(), 6) << " " << (*it).second->bind() << std::endl;
+ con_print << " " << aux::pad_left((*it).second->name(), 6) << " " << (*it).second->bind(Key::None) << std::endl;
}
con_print << keys.size() << " keys" << std::endl;
}
@@ -327,36 +335,49 @@ void Keyboard::list_binds()
{
size_t n =0;
for (iterator it = begin(); it != end(); it++) {
- if ((*it).second->bind().size()) {
- con_print << " " << aux::pad_left((*it).second->name(), 6) << " " << (*it).second->bind() << std::endl;
+ if ((*it).second->bind(Key::None).size()) {
+ con_print << " " << aux::pad_left((*it).second->name(), 6) << " " << (*it).second->bind(Key::None) << std::endl;
n++;
}
+ if ((*it).second->bind(Key::Shift).size()) {
+ con_print << " shift+" << aux::pad_left((*it).second->name(), 6) << " " << (*it).second->bind(Key::Shift) << std::endl;
+ n++;
+ }
+ if ((*it).second->bind(Key::Ctrl).size()) {
+ con_print << " ctrl+" << aux::pad_left((*it).second->name(), 6) << " " << (*it).second->bind(Key::Ctrl) << std::endl;
+ n++;
+ }
+ if ((*it).second->bind(Key::Alt).size()) {
+ con_print << " alt+" << aux::pad_left((*it).second->name(), 6) << " " << (*it).second->bind(Key::Alt) << std::endl;
+ n++;
+ }
+
}
con_print << n << " binds" << std::endl;
}
void setkeyboardmode(bool input)
{
-/* if(input)
- SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL);
- else
- SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL);
-*/
+ /* if(input)
+ SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL);
+ else
+ SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL);
+ */
}
unsigned int translate_keysym(const SDL_keysym &keysym)
{
-
+
int key = keysym.sym;
- bool shift = false;
+ bool shift = false;
bool numlock = false;
-
+
// keypad keys
if (keysym.mod & KMOD_NUM) {
numlock = true;
- switch(key) {
+ switch (key) {
case SDLK_KP0:
return '0';
break;
@@ -389,39 +410,39 @@ unsigned int translate_keysym(const SDL_keysym &keysym)
break;
}
} else {
- switch(key) {
- case SDLK_KP0:
- return SDLK_INSERT;
- break;
- case SDLK_KP1:
- return SDLK_END;
- break;
- case SDLK_KP2:
- return SDLK_DOWN;
- break;
- case SDLK_KP3:
- return SDLK_PAGEDOWN;
- break;
- case SDLK_KP4:
- return SDLK_LEFT;
- break;
- case SDLK_KP6:
- return SDLK_RIGHT;
- break;
- case SDLK_KP7:
- return SDLK_HOME;
- break;
- case SDLK_KP8:
- return SDLK_UP;
- break;
- case SDLK_KP9:
- return SDLK_PAGEUP;
- break;
+ switch (key) {
+ case SDLK_KP0:
+ return SDLK_INSERT;
+ break;
+ case SDLK_KP1:
+ return SDLK_END;
+ break;
+ case SDLK_KP2:
+ return SDLK_DOWN;
+ break;
+ case SDLK_KP3:
+ return SDLK_PAGEDOWN;
+ break;
+ case SDLK_KP4:
+ return SDLK_LEFT;
+ break;
+ case SDLK_KP6:
+ return SDLK_RIGHT;
+ break;
+ case SDLK_KP7:
+ return SDLK_HOME;
+ break;
+ case SDLK_KP8:
+ return SDLK_UP;
+ break;
+ case SDLK_KP9:
+ return SDLK_PAGEUP;
+ break;
}
}
// special keys
- switch(key) {
+ switch (key) {
case SDLK_ESCAPE:
return SDLK_ESCAPE;
break;
@@ -431,19 +452,19 @@ unsigned int translate_keysym(const SDL_keysym &keysym)
case SDLK_KP_PERIOD:
return '.';
break;
- case SDLK_KP_DIVIDE:
+ case SDLK_KP_DIVIDE:
return '/';
break;
- case SDLK_KP_MULTIPLY:
+ case SDLK_KP_MULTIPLY:
return '*';
break;
- case SDLK_KP_MINUS:
+ case SDLK_KP_MINUS:
return '-';
break;
- case SDLK_KP_PLUS:
+ case SDLK_KP_PLUS:
return '+';
break;
- case SDLK_KP_EQUALS:
+ case SDLK_KP_EQUALS:
return '=';
break;
}
@@ -461,7 +482,7 @@ unsigned int translate_keysym(const SDL_keysym &keysym)
if ((key >= 'a' && key <= 'z')) {
key = key + 'A' - 'a';
return key;
- }
+ }
switch (key) {
case '`':
@@ -503,7 +524,7 @@ unsigned int translate_keysym(const SDL_keysym &keysym)
case '=':
key = '+';
break;
- // second row
+ // second row
case '[':
key = '{';
break;
@@ -513,14 +534,14 @@ unsigned int translate_keysym(const SDL_keysym &keysym)
case '|':
key = '\\';
break;
- // third row
+ // third row
case ';':
key = ':';
break;
case '\'':
key = '"';
break;
- // fourth row
+ // fourth row
case ',':
key = '<';
break;
diff --git a/src/client/keyboard.h b/src/client/keyboard.h
index fb9efaf..8275b1a 100644
--- a/src/client/keyboard.h
+++ b/src/client/keyboard.h
@@ -34,6 +34,9 @@ public:
/// clear the string bound to a key
void unbind(std::string const &name);
+ /// celar all key binds
+ void unbindall();
+
/// list keyboard key names
void list_keys();
diff --git a/src/client/targets.cc b/src/client/targets.cc
index 1264cbb..9dd508b 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -273,14 +273,14 @@ void draw()
float z = -1;
// mouse cursor location in 3d world space
- float x = (float)(input::mouse_x - video::width /2) / (float)video::width * render::Camera::aspect();
- float y = (float)(input::mouse_y - video::height /2) / (float)video::height;
+ float x = (float)(input::mouse_x - video::width /2) / (float)video::width;
+ float y = (float)(input::mouse_y - video::height /2) / (float)video::height / render::Camera::aspect();
- Vector3f cursor = render::Camera::eye() + render::Camera::axis().forward() * (render::frustum_front + 0.001);
+ Vector3f cursor = render::Camera::eye() + render::Camera::axis().forward() * (render::Camera::frustum_front() + 0.001);
cursor -= render::Camera::axis().left() * x;
cursor -= render::Camera::axis().up() * y;
- math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::frustum_front +0.01f));
+ math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::Camera::frustum_front() +0.01f));
for (std::map<unsigned int, core::Entity *>::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
core::Entity *entity = (*it).second;
@@ -327,7 +327,7 @@ void draw()
// find the intersection of the line [ eye - target ] in the frustum front plane
Vector3f const &plane_normal = render::Camera::axis().forward();
- Vector3f const &plane_point = render::Camera::eye() + render::Camera::axis().forward() * (render::frustum_front + 0.001);
+ Vector3f const &plane_point = render::Camera::eye() + render::Camera::axis().forward() * (render::Camera::frustum_front() + 0.001);
float d = (plane_normal.x * plane_point.x + plane_normal.y * plane_point.y + plane_normal.z * plane_point.z);
float t = d - plane_normal.x * render::Camera::eye().x
diff --git a/src/client/video.cc b/src/client/video.cc
index 3566481..56514a9 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -41,12 +41,12 @@ core::Cvar *r_fullscreen;
void reset()
{
- // recalculate the video aspect
- render::Camera::set_aspect((float) width / (float) height);
-
- // settup our viewport.
+ // setup our viewport.
gl::viewport(0, 0, width, height );
+ // recalculate the video aspect
+ render::Camera::set_aspect(width, height);
+
// reset the view
view::reset();
}
@@ -110,7 +110,7 @@ bool init()
}
con_print << " video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl;
- render::Camera::set_aspect((float) width / (float) height);
+ render::Camera::set_aspect(width, height);
(*r_width) = width;
(*r_height) = height;