diff --git a/README.md b/README.md index bdf9bdb3..464be166 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,10 @@ mkxp-z provides limited support for some WinAPI functions that would normally br ## Nonstandard RGSS extensions +### Kernel + +* `load_data` now has a second optional `Boolean` argument which, if set to true, returns the contents of the file as a string (rather than trying to load it with Marshal first). + ### Input * The `Input.press?` family of functions accepts three additional button constants: `::MOUSELEFT`, `::MOUSEMIDDLE` and `::MOUSERIGHT` for the respective mouse buttons. It will now also accept [SDL scancodes](https://wiki.libsdl.org/SDL_Scancode?highlight=%28%5CbCategoryEnum%5Cb%29%7C%28CategoryKeyboard%29) in the form of symbols corresponding to each scancode (e.g. `SDL_SCANCODE_RETURN` would be requested through `Input.press?/trigger?/repeat? :RETURN`) @@ -149,6 +153,8 @@ mkxp-z provides limited support for some WinAPI functions that would normally br * `game_title` returns the game's title as set in its ini. * `power_state` returns a hash with the system power state information. Its members are `:discharging` (Boolean), `:percent` (int/nil), and `:seconds` (int/nil) * `show_settings` displays the keybinding menu. +* `nproc` returns the amount of logical cores available to the system. +* `memory` returns the total amount of RAM detected by the system in megabytes. ### Discord diff --git a/binding/binding-mri.cpp b/binding/binding-mri.cpp index af607037..5313452e 100644 --- a/binding/binding-mri.cpp +++ b/binding/binding-mri.cpp @@ -45,6 +45,7 @@ #include #include +#include #ifdef __WIN32__ #define NULL_IO "NUL" @@ -107,6 +108,8 @@ RB_METHOD(mkxpUserLanguage); RB_METHOD(mkxpGameTitle); RB_METHOD(mkxpPowerState); RB_METHOD(mkxpSettingsMenu); +RB_METHOD(mkxpCpuCount); +RB_METHOD(mkxpSystemMemory); RB_METHOD(mriRgssMain); RB_METHOD(mriRgssStop); @@ -186,6 +189,8 @@ static void mriBindingInit() _rb_define_module_function(mod, "user_language", mkxpUserLanguage); _rb_define_module_function(mod, "game_title", mkxpGameTitle); _rb_define_module_function(mod, "power_state", mkxpPowerState); + _rb_define_module_function(mod, "nproc", mkxpCpuCount); + _rb_define_module_function(mod, "memory", mkxpSystemMemory); /* Load global constants */ rb_gv_set("MKXP", Qtrue); @@ -344,6 +349,20 @@ RB_METHOD(mkxpSettingsMenu) return Qnil; } +RB_METHOD(mkxpCpuCount) +{ + RB_UNUSED_PARAM; + + return INT2NUM(SDL_GetCPUCount()); +} + +RB_METHOD(mkxpSystemMemory) +{ + RB_UNUSED_PARAM; + + return INT2NUM(SDL_GetSystemRAM()); +} + static VALUE rgssMainCb(VALUE block) { rb_funcall2(block, rb_intern("call"), 0, 0); @@ -476,7 +495,7 @@ static void runCustomScript(const std::string &filename) newStringUTF8(filename.c_str(), filename.size()), NULL); } -VALUE kernelLoadDataInt(const char *filename, bool rubyExc); +VALUE kernelLoadDataInt(const char *filename, bool rubyExc, bool raw); struct BacktraceData { @@ -511,7 +530,7 @@ static void runRMXPScripts(BacktraceData &btData) * still go wrong */ try { - scriptArray = kernelLoadDataInt(scriptPack.c_str(), false); + scriptArray = kernelLoadDataInt(scriptPack.c_str(), false, false); } catch (const Exception &e) { diff --git a/binding/filesystem-binding.cpp b/binding/filesystem-binding.cpp index 38896e19..4c833075 100644 --- a/binding/filesystem-binding.cpp +++ b/binding/filesystem-binding.cpp @@ -145,17 +145,24 @@ RB_METHOD(fileIntPos) } VALUE -kernelLoadDataInt(const char *filename, bool rubyExc) +kernelLoadDataInt(const char *filename, bool rubyExc, bool raw) { rb_gc_start(); VALUE port = fileIntForPath(filename, rubyExc); - - VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal")); + VALUE result; + if (!raw) + { + VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal")); - // FIXME need to catch exceptions here with begin rescue - VALUE data = fileIntRead(0, 0, port); - VALUE result = rb_funcall2(marsh, rb_intern("load"), 1, &data); + // FIXME need to catch exceptions here with begin rescue + VALUE data = fileIntRead(0, 0, port); + result = rb_funcall2(marsh, rb_intern("load"), 1, &data); + } + else + { + result = fileIntRead(0, 0, port); + } rb_funcall2(port, rb_intern("close"), 0, NULL); @@ -167,7 +174,8 @@ RB_METHOD(kernelLoadData) RB_UNUSED_PARAM; VALUE filename; - rb_get_args(argc, argv, "S", &filename RB_ARG_END); + bool raw = false; + rb_get_args(argc, argv, "S|b", &filename, &raw RB_ARG_END); // Until a faster method for getting RGSSAD data is // written (could just copy RMXP, keeping stuff in @@ -186,7 +194,7 @@ RB_METHOD(kernelLoadData) rb_funcall(f, rb_intern("close"), 0); return ret; } - return kernelLoadDataInt(RSTRING_PTR(filename), true); + return kernelLoadDataInt(RSTRING_PTR(filename), true, raw); } RB_METHOD(kernelSaveData) diff --git a/src/eventthread.cpp b/src/eventthread.cpp index d27e8738..4002ca78 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -389,8 +389,16 @@ void EventThread::process(RGSSThreadData &rtData) joystickConnected = true; hap = SDL_HapticOpenFromJoystick(js); + Debug() << (hap ? "true" : "false"); if (hap && (SDL_HapticQuery(hap) & SDL_HAPTIC_SINE)) + { hapt = hap; + Debug() << "Haptic device initialized"; + } + else + { + Debug() << "No haptic support found"; + } break;