1. rude
  2. love

Commits

Alex Szpakowski  committed 7e921a2 Merge

Merged bartbes/love-experiments/joystickevents into default

  • Participants
  • Parent commits 3b69a4c, 43ac6da
  • Branches default

Comments (1)

Files changed (5)

File src/modules/event/Event.h

View file
 #include "common/Variant.h"
 #include "keyboard/Keyboard.h"
 #include "mouse/Mouse.h"
+#include "joystick/Joystick.h"
 #include "thread/threads.h"
 
 // STL

File src/modules/event/sdl/Event.cpp

View file
 #include "keyboard/Keyboard.h"
 #include "mouse/Mouse.h"
 
+#include <cmath>
+
 namespace love
 {
 namespace event
 	Message *msg = NULL;
 	love::keyboard::Keyboard::Key key;
 	love::mouse::Mouse::Button button;
-	Variant *arg1, *arg2, *arg3;
+	love::joystick::Joystick::Hat hat;
+	Variant *arg1, *arg2, *arg3, *arg4;
 	const char *txt;
 	switch (e.type)
 	{
 		arg1->release();
 		arg2->release();
 		break;
+	case SDL_JOYAXISMOTION:
+		{
+			arg1 = new Variant((double)(e.jaxis.which+1));
+			arg2 = new Variant((double)(e.jaxis.axis+1));
+			float value = e.jaxis.value / 32768.0f;
+			if (fabsf(value) < 0.001f) value = 0.0f;
+			if (value < -0.99f) value = -1.0f;
+			if (value > 0.99f) value = 1.0f;
+			arg3 = new Variant((double) value);
+			msg = new Message("joystickaxis", arg1, arg2, arg3);
+			arg1->release();
+			arg2->release();
+			arg3->release();
+		}
+		break;
+	case SDL_JOYBALLMOTION:
+		arg1 = new Variant((double)(e.jball.which+1));
+		arg2 = new Variant((double)(e.jball.ball+1));
+		arg3 = new Variant((double)e.jball.xrel);
+		arg4 = new Variant((double)e.jball.yrel);
+		msg = new Message("joystickball", arg1, arg2, arg3, arg4);
+		arg1->release();
+		arg2->release();
+		arg3->release();
+		arg4->release();
+		break;
+	case SDL_JOYHATMOTION:
+		if (hats.find(e.jhat.value, hat) && love::joystick::Joystick::getConstant(hat, txt))
+		{
+			arg1 = new Variant((double)(e.jhat.which+1));
+			arg2 = new Variant((double)(e.jhat.hat+1));
+			arg3 = new Variant(txt, strlen(txt));
+			msg = new Message("joystickhat", arg1, arg2, arg3);
+			arg1->release();
+			arg2->release();
+			arg3->release();
+		}
+		break;
 	case SDL_ACTIVEEVENT:
 		arg1 = new Variant(e.active.gain != 0);
 		if (e.active.state & SDL_APPINPUTFOCUS)
 
 EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM> Event::buttons(Event::buttonEntries, sizeof(Event::buttonEntries));
 
+EnumMap<love::joystick::Joystick::Hat, Uint8, love::joystick::Joystick::HAT_MAX_ENUM>::Entry Event::hatEntries[] =
+{
+	{love::joystick::Joystick::HAT_CENTERED, SDL_HAT_CENTERED},
+	{love::joystick::Joystick::HAT_UP, SDL_HAT_UP},
+	{love::joystick::Joystick::HAT_RIGHT, SDL_HAT_RIGHT},
+	{love::joystick::Joystick::HAT_DOWN, SDL_HAT_DOWN},
+	{love::joystick::Joystick::HAT_LEFT, SDL_HAT_LEFT},
+	{love::joystick::Joystick::HAT_RIGHTUP, SDL_HAT_RIGHTUP},
+	{love::joystick::Joystick::HAT_RIGHTDOWN, SDL_HAT_RIGHTDOWN},
+	{love::joystick::Joystick::HAT_LEFTUP, SDL_HAT_LEFTUP},
+	{love::joystick::Joystick::HAT_LEFTDOWN, SDL_HAT_LEFTDOWN},
+};
+
+EnumMap<love::joystick::Joystick::Hat, Uint8, love::joystick::Joystick::HAT_MAX_ENUM> Event::hats(Event::hatEntries, sizeof(Event::hatEntries));
+
 } // sdl
 } // event
 } // love

File src/modules/event/sdl/Event.h

View file
 	static EnumMap<love::keyboard::Keyboard::Key, SDLKey, love::keyboard::Keyboard::KEY_MAX_ENUM> keys;
 	static EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry buttonEntries[];
 	static EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM> buttons;
+	static EnumMap<love::joystick::Joystick::Hat, Uint8, love::joystick::Joystick::HAT_MAX_ENUM>::Entry hatEntries[];
+	static EnumMap<love::joystick::Joystick::Hat, Uint8, love::joystick::Joystick::Joystick::HAT_MAX_ENUM> hats;
 
 }; // System
 

File src/scripts/boot.lua

View file
 		joystickreleased = function (j,b)
 			if love.joystickreleased then love.joystickreleased(j,b) end
 		end,
+		joystickaxis = function (j,a,v)
+			if love.joystickaxis then love.joystickaxis(j,a,v) end
+		end,
+		joystickball = function (j,b,dx,dy)
+			if love.joystickball then love.joystickball(j,b,dx,dy) end
+		end,
+		joystickhat = function(j,h,v)
+			if love.joystickhat then love.joystickhat(j,h,v) end
+		end,
 		focus = function (f)
 			if love.focus then love.focus(f) end
 		end,

File src/scripts/boot.lua.h

View file
 	0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 
 	0x28, 0x6a, 0x2c, 0x62, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a,
+	0x09, 0x09, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x61, 0x78, 0x69, 0x73, 0x20, 0x3d, 0x20, 0x66, 
+	0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x6a, 0x2c, 0x61, 0x2c, 0x76, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 
+	0x6b, 0x61, 0x78, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 
+	0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x61, 0x78, 0x69, 0x73, 0x28, 0x6a, 0x2c, 0x61, 0x2c, 0x76, 0x29, 0x20, 
+	0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a,
+	0x09, 0x09, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x62, 0x61, 0x6c, 0x6c, 0x20, 0x3d, 0x20, 0x66, 
+	0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x6a, 0x2c, 0x62, 0x2c, 0x64, 0x78, 0x2c, 0x64, 0x79, 
+	0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 
+	0x6b, 0x62, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 
+	0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x62, 0x61, 0x6c, 0x6c, 0x28, 0x6a, 0x2c, 0x62, 0x2c, 0x64, 0x78, 0x2c, 
+	0x64, 0x79, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a,
+	0x09, 0x09, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x68, 0x61, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x75, 
+	0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x6a, 0x2c, 0x68, 0x2c, 0x76, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 
+	0x6b, 0x68, 0x61, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79, 
+	0x73, 0x74, 0x69, 0x63, 0x6b, 0x68, 0x61, 0x74, 0x28, 0x6a, 0x2c, 0x68, 0x2c, 0x76, 0x29, 0x20, 0x65, 0x6e, 
+	0x64, 0x0a,
+	0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a,
 	0x09, 0x09, 0x66, 0x6f, 0x63, 0x75, 0x73, 0x20, 0x3d, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 
 	0x20, 0x28, 0x66, 0x29, 0x0a,
 	0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x6f, 0x63, 0x75, 0x73, 0x20, 0x74,