projects
/
oweals
/
minetest.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix Android build, but there is a remaining linking issue in guiConfirmRegistration
[oweals/minetest.git]
/
src
/
keycode.cpp
diff --git
a/src/keycode.cpp
b/src/keycode.cpp
index 2e211ad59179fabf4830713869305d8ffb1f8c27..6822875b1bce0017954a77e2542b669161348953 100644
(file)
--- a/
src/keycode.cpp
+++ b/
src/keycode.cpp
@@
-24,6
+24,7
@@
with this program; if not, write to the Free Software Foundation, Inc.,
#include "debug.h"
#include "util/hex.h"
#include "util/string.h"
#include "debug.h"
#include "util/hex.h"
#include "util/string.h"
+#include "util/basic_macros.h"
class UnknownKeycode : public BaseException
{
class UnknownKeycode : public BaseException
{
@@
-242,13
+243,12
@@
static const struct table_key table[] = {
#undef N_
#undef N_
-#define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
struct table_key lookup_keyname(const char *name)
{
struct table_key lookup_keyname(const char *name)
{
- for (
u16 i = 0; i < ARRAYSIZE(table); i++
) {
- if (strcmp(table
[i]
.Name, name) == 0)
- return table
[i]
;
+ for (
const auto &table_key : table
) {
+ if (strcmp(table
_key
.Name, name) == 0)
+ return table
_key
;
}
throw UnknownKeycode(name);
}
throw UnknownKeycode(name);
@@
-256,9
+256,9
@@
struct table_key lookup_keyname(const char *name)
struct table_key lookup_keykey(irr::EKEY_CODE key)
{
struct table_key lookup_keykey(irr::EKEY_CODE key)
{
- for (
u16 i = 0; i < ARRAYSIZE(table); i++
) {
- if (table
[i]
.Key == key)
- return table
[i]
;
+ for (
const auto &table_key : table
) {
+ if (table
_key
.Key == key)
+ return table
_key
;
}
std::ostringstream os;
}
std::ostringstream os;
@@
-268,9
+268,9
@@
struct table_key lookup_keykey(irr::EKEY_CODE key)
struct table_key lookup_keychar(wchar_t Char)
{
struct table_key lookup_keychar(wchar_t Char)
{
- for (
u16 i = 0; i < ARRAYSIZE(table); i++
) {
- if (table
[i]
.Char == Char)
- return table
[i]
;
+ for (
const auto &table_key : table
) {
+ if (table
_key
.Char == Char)
+ return table
_key
;
}
std::ostringstream os;
}
std::ostringstream os;
@@
-278,12
+278,6
@@
struct table_key lookup_keychar(wchar_t Char)
throw UnknownKeycode(os.str().c_str());
}
throw UnknownKeycode(os.str().c_str());
}
-KeyPress::KeyPress() :
- Key(irr::KEY_KEY_CODES_COUNT),
- Char(L'\0'),
- m_name("")
-{}
-
KeyPress::KeyPress(const char *name)
{
if (strlen(name) == 0) {
KeyPress::KeyPress(const char *name)
{
if (strlen(name) == 0) {
@@
-291,7
+285,9
@@
KeyPress::KeyPress(const char *name)
Char = L'\0';
m_name = "";
return;
Char = L'\0';
m_name = "";
return;
- } else if (strlen(name) <= 4) {
+ }
+
+ if (strlen(name) <= 4) {
// Lookup by resulting character
int chars_read = mbtowc(&Char, name, 1);
FATAL_ERROR_IF(chars_read != 1, "Unexpected multibyte character");
// Lookup by resulting character
int chars_read = mbtowc(&Char, name, 1);
FATAL_ERROR_IF(chars_read != 1, "Unexpected multibyte character");
@@
-345,7
+341,7
@@
const char *KeyPress::sym() const
const char *KeyPress::name() const
{
const char *KeyPress::name() const
{
- if (m_name
== ""
)
+ if (m_name
.empty()
)
return "";
const char *ret;
if (valid_kcode(Key))
return "";
const char *ret;
if (valid_kcode(Key))
@@
-357,23
+353,19
@@
const char *KeyPress::name() const
const KeyPress EscapeKey("KEY_ESCAPE");
const KeyPress CancelKey("KEY_CANCEL");
const KeyPress EscapeKey("KEY_ESCAPE");
const KeyPress CancelKey("KEY_CANCEL");
-const KeyPress NumberKey[] = {
- KeyPress("0"), KeyPress("1"), KeyPress("2"), KeyPress("3"), KeyPress("4"),
- KeyPress("5"), KeyPress("6"), KeyPress("7"), KeyPress("8"), KeyPress("9")
-};
/*
Key config
*/
// A simple cache for quicker lookup
/*
Key config
*/
// A simple cache for quicker lookup
-std::map<std::string, KeyPress> g_key_setting_cache;
+std::
unordered_
map<std::string, KeyPress> g_key_setting_cache;
KeyPress getKeySetting(const char *settingname)
{
KeyPress getKeySetting(const char *settingname)
{
- std::map<std::string, KeyPress>::iterator n;
+ std::
unordered_
map<std::string, KeyPress>::iterator n;
n = g_key_setting_cache.find(settingname);
n = g_key_setting_cache.find(settingname);
- if(n != g_key_setting_cache.end())
+ if
(n != g_key_setting_cache.end())
return n->second;
KeyPress k(g_settings->get(settingname).c_str());
return n->second;
KeyPress k(g_settings->get(settingname).c_str());