From 4a8b0f30c8dfc59deb3a4b30ae6a845121e3f701 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Mon, 20 Oct 2014 10:27:01 +0200 Subject: [PATCH] MRI: Add 'System.raw_key_states' to query full keyboard state Returns a byte array with all key states (0 = released, 1 = pressed) indexed via SDL_SCANCODE_* enums. --- binding-mri/binding-mri.cpp | 42 ++++++++++++++++++++++++------------- src/eventthread.cpp | 2 +- src/eventthread.h | 2 +- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index 6fccdd5..e8c957a 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -76,8 +76,9 @@ void fileIntBindingInit(); RB_METHOD(mriPrint); RB_METHOD(mriP); -RB_METHOD(mriDataDirectory); +RB_METHOD(mkxpDataDirectory); RB_METHOD(mkxpPuts); +RB_METHOD(mkxpRawKeyStates); RB_METHOD(mriRgssMain); RB_METHOD(mriRgssStop); @@ -139,8 +140,9 @@ static void mriBindingInit() assert(!"unreachable"); VALUE mod = rb_define_module("System"); - _rb_define_module_function(mod, "data_directory", mriDataDirectory); + _rb_define_module_function(mod, "data_directory", mkxpDataDirectory); _rb_define_module_function(mod, "puts", mkxpPuts); + _rb_define_module_function(mod, "raw_key_states", mkxpRawKeyStates); rb_gv_set("MKXP", Qtrue); } @@ -151,18 +153,6 @@ showMsg(const std::string &msg) shState->eThread().showMessageBox(msg.c_str()); } -RB_METHOD(mkxpPuts) -{ - RB_UNUSED_PARAM; - - const char *str; - rb_get_args(argc, argv, "z", &str RB_ARG_END); - - Debug() << str; - - return Qnil; -} - static void printP(int argc, VALUE *argv, const char *convMethod, const char *sep) { @@ -199,7 +189,7 @@ RB_METHOD(mriP) return Qnil; } -RB_METHOD(mriDataDirectory) +RB_METHOD(mkxpDataDirectory) { RB_UNUSED_PARAM; @@ -216,6 +206,28 @@ RB_METHOD(mriDataDirectory) return pathStr; } +RB_METHOD(mkxpPuts) +{ + RB_UNUSED_PARAM; + + const char *str; + rb_get_args(argc, argv, "z", &str RB_ARG_END); + + Debug() << str; + + return Qnil; +} + +RB_METHOD(mkxpRawKeyStates) +{ + RB_UNUSED_PARAM; + + VALUE str = rb_str_new(0, sizeof(EventThread::keyStates)); + memcpy(RSTRING_PTR(str), EventThread::keyStates, sizeof(EventThread::keyStates)); + + return str; +} + static VALUE rgssMainCb(VALUE block) { rb_funcall2(block, rb_intern("call"), 0, 0); diff --git a/src/eventthread.cpp b/src/eventthread.cpp index 6678772..6000dad 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -34,7 +34,7 @@ #include -bool EventThread::keyStates[] = { false }; +uint8_t EventThread::keyStates[] = { false }; EventThread::JoyState EventThread::joyState = { diff --git a/src/eventthread.h b/src/eventthread.h index ec5e8bb..15d4f63 100644 --- a/src/eventthread.h +++ b/src/eventthread.h @@ -42,7 +42,7 @@ struct SDL_Window; class EventThread { public: - static bool keyStates[SDL_NUM_SCANCODES]; + static uint8_t keyStates[SDL_NUM_SCANCODES]; struct JoyState {