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.
This commit is contained in:
		
							parent
							
								
									e44a1e32fa
								
							
						
					
					
						commit
						4a8b0f30c8
					
				
					 3 changed files with 29 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -34,7 +34,7 @@
 | 
			
		|||
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
bool EventThread::keyStates[] = { false };
 | 
			
		||||
uint8_t EventThread::keyStates[] = { false };
 | 
			
		||||
 | 
			
		||||
EventThread::JoyState EventThread::joyState =
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue