Browse Source

Simplified an internal Variant constructor to be more intuitive to use.

--HG--
branch : minor
Alex Szpakowski 7 years ago
parent
commit
b838d0de54

+ 4 - 4
src/common/Variant.cpp

@@ -85,10 +85,10 @@ Variant::Variant(love::Type *udatatype, void *userdata)
 {
 {
 	if (udatatype != nullptr)
 	if (udatatype != nullptr)
 	{
 	{
-		Proxy *p = (Proxy *) userdata;
-		data.userdata = p->object;
-		if (p->object)
-			p->object->retain();
+		love::Object *o = (love::Object *) userdata;
+		data.userdata = o;
+		if (o != nullptr)
+			o->retain();
 	}
 	}
 	else
 	else
 		data.userdata = userdata;
 		data.userdata = userdata;

+ 27 - 36
src/modules/event/sdl/Event.cpp

@@ -383,12 +383,10 @@ Message *Event::convert(const SDL_Event &e)
 			}
 			}
 			else
 			else
 			{
 			{
-				Proxy proxy;
-				proxy.object = new love::filesystem::DroppedFile(e.drop.file);
-				proxy.type = &love::filesystem::DroppedFile::type;
-				vargs.emplace_back(proxy.type, &proxy);
+				auto *file = new love::filesystem::DroppedFile(e.drop.file);
+				vargs.emplace_back(&love::filesystem::DroppedFile::type, file);
 				msg = new Message("filedropped", vargs);
 				msg = new Message("filedropped", vargs);
-				proxy.object->release();
+				file->release();
 			}
 			}
 		}
 		}
 		SDL_free(e.drop.file);
 		SDL_free(e.drop.file);
@@ -418,7 +416,8 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
 	std::vector<Variant> vargs;
 	std::vector<Variant> vargs;
 	vargs.reserve(4);
 	vargs.reserve(4);
 
 
-	Proxy proxy;
+	love::Type *joysticktype = &love::joystick::Joystick::type;
+	love::joystick::Joystick *stick = nullptr;
 	love::joystick::Joystick::Hat hat;
 	love::joystick::Joystick::Hat hat;
 	love::joystick::Joystick::GamepadButton padbutton;
 	love::joystick::Joystick::GamepadButton padbutton;
 	love::joystick::Joystick::GamepadAxis padaxis;
 	love::joystick::Joystick::GamepadAxis padaxis;
@@ -428,12 +427,11 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
 	{
 	{
 	case SDL_JOYBUTTONDOWN:
 	case SDL_JOYBUTTONDOWN:
 	case SDL_JOYBUTTONUP:
 	case SDL_JOYBUTTONUP:
-		proxy.type = &love::joystick::Joystick::type;
-		proxy.object = joymodule->getJoystickFromID(e.jbutton.which);
-		if (!proxy.object)
+		stick = joymodule->getJoystickFromID(e.jbutton.which);
+		if (!stick)
 			break;
 			break;
 
 
-		vargs.emplace_back(proxy.type, (void *) &proxy);
+		vargs.emplace_back(joysticktype, stick);
 		vargs.emplace_back((double)(e.jbutton.button+1));
 		vargs.emplace_back((double)(e.jbutton.button+1));
 		msg = new Message((e.type == SDL_JOYBUTTONDOWN) ?
 		msg = new Message((e.type == SDL_JOYBUTTONDOWN) ?
 						  "joystickpressed" : "joystickreleased",
 						  "joystickpressed" : "joystickreleased",
@@ -441,12 +439,11 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
 		break;
 		break;
 	case SDL_JOYAXISMOTION:
 	case SDL_JOYAXISMOTION:
 		{
 		{
-			proxy.type = &love::joystick::Joystick::type;
-			proxy.object = joymodule->getJoystickFromID(e.jaxis.which);
-			if (!proxy.object)
+			stick = joymodule->getJoystickFromID(e.jaxis.which);
+			if (!stick)
 				break;
 				break;
 
 
-			vargs.emplace_back(proxy.type, (void *) &proxy);
+			vargs.emplace_back(joysticktype, stick);
 			vargs.emplace_back((double)(e.jaxis.axis+1));
 			vargs.emplace_back((double)(e.jaxis.axis+1));
 			float value = joystick::Joystick::clampval(e.jaxis.value / 32768.0f);
 			float value = joystick::Joystick::clampval(e.jaxis.value / 32768.0f);
 			vargs.emplace_back((double) value);
 			vargs.emplace_back((double) value);
@@ -457,12 +454,11 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
 		if (!joystick::sdl::Joystick::getConstant(e.jhat.value, hat) || !joystick::Joystick::getConstant(hat, txt))
 		if (!joystick::sdl::Joystick::getConstant(e.jhat.value, hat) || !joystick::Joystick::getConstant(hat, txt))
 			break;
 			break;
 
 
-		proxy.type = &love::joystick::Joystick::type;
-		proxy.object = joymodule->getJoystickFromID(e.jhat.which);
-		if (!proxy.object)
+		stick = joymodule->getJoystickFromID(e.jhat.which);
+		if (!stick)
 			break;
 			break;
 
 
-		vargs.emplace_back(proxy.type, (void *) &proxy);
+		vargs.emplace_back(joysticktype, stick);
 		vargs.emplace_back((double)(e.jhat.hat+1));
 		vargs.emplace_back((double)(e.jhat.hat+1));
 		vargs.emplace_back(txt, strlen(txt));
 		vargs.emplace_back(txt, strlen(txt));
 		msg = new Message("joystickhat", vargs);
 		msg = new Message("joystickhat", vargs);
@@ -475,12 +471,11 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
 		if (!joystick::Joystick::getConstant(padbutton, txt))
 		if (!joystick::Joystick::getConstant(padbutton, txt))
 			break;
 			break;
 
 
-		proxy.type = &love::joystick::Joystick::type;
-		proxy.object = joymodule->getJoystickFromID(e.cbutton.which);
-		if (!proxy.object)
+		stick = joymodule->getJoystickFromID(e.cbutton.which);
+		if (!stick)
 			break;
 			break;
 
 
-		vargs.emplace_back(proxy.type, (void *) &proxy);
+		vargs.emplace_back(joysticktype, stick);
 		vargs.emplace_back(txt, strlen(txt));
 		vargs.emplace_back(txt, strlen(txt));
 		msg = new Message(e.type == SDL_CONTROLLERBUTTONDOWN ?
 		msg = new Message(e.type == SDL_CONTROLLERBUTTONDOWN ?
 						  "gamepadpressed" : "gamepadreleased", vargs);
 						  "gamepadpressed" : "gamepadreleased", vargs);
@@ -491,13 +486,11 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
 			if (!joystick::Joystick::getConstant(padaxis, txt))
 			if (!joystick::Joystick::getConstant(padaxis, txt))
 				break;
 				break;
 
 
-			proxy.type = &love::joystick::Joystick::type;
-			proxy.object = joymodule->getJoystickFromID(e.caxis.which);
-			if (!proxy.object)
+			stick = joymodule->getJoystickFromID(e.caxis.which);
+			if (!stick)
 				break;
 				break;
 
 
-			vargs.emplace_back(proxy.type, (void *) &proxy);
-
+			vargs.emplace_back(joysticktype, stick);
 			vargs.emplace_back(txt, strlen(txt));
 			vargs.emplace_back(txt, strlen(txt));
 			float value = joystick::Joystick::clampval(e.caxis.value / 32768.0f);
 			float value = joystick::Joystick::clampval(e.caxis.value / 32768.0f);
 			vargs.emplace_back((double) value);
 			vargs.emplace_back((double) value);
@@ -506,22 +499,20 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
 		break;
 		break;
 	case SDL_JOYDEVICEADDED:
 	case SDL_JOYDEVICEADDED:
 		// jdevice.which is the joystick device index.
 		// jdevice.which is the joystick device index.
-		proxy.object = joymodule->addJoystick(e.jdevice.which);
-		proxy.type = &love::joystick::Joystick::type;
-		if (proxy.object)
+		stick = joymodule->addJoystick(e.jdevice.which);
+		if (stick)
 		{
 		{
-			vargs.emplace_back(proxy.type, (void *) &proxy);
+			vargs.emplace_back(joysticktype, stick);
 			msg = new Message("joystickadded", vargs);
 			msg = new Message("joystickadded", vargs);
 		}
 		}
 		break;
 		break;
 	case SDL_JOYDEVICEREMOVED:
 	case SDL_JOYDEVICEREMOVED:
 		// jdevice.which is the joystick instance ID now.
 		// jdevice.which is the joystick instance ID now.
-		proxy.object = joymodule->getJoystickFromID(e.jdevice.which);
-		proxy.type = &love::joystick::Joystick::type;
-		if (proxy.object)
+		stick = joymodule->getJoystickFromID(e.jdevice.which);
+		if (stick)
 		{
 		{
-			joymodule->removeJoystick((joystick::Joystick *) proxy.object);
-			vargs.emplace_back(proxy.type, (void *) &proxy);
+			joymodule->removeJoystick(stick);
+			vargs.emplace_back(joysticktype, stick);
 			msg = new Message("joystickremoved", vargs);
 			msg = new Message("joystickremoved", vargs);
 		}
 		}
 		break;
 		break;

+ 1 - 4
src/modules/graphics/wrap_Graphics.cpp

@@ -487,11 +487,8 @@ static void screenshotChannelCallback(const Graphics::ScreenshotInfo *info, love
 
 
 	if (channel != nullptr)
 	if (channel != nullptr)
 	{
 	{
-		Proxy p;
-		p.type = &love::image::ImageData::type;
-		p.object = i;
 		if (i != nullptr)
 		if (i != nullptr)
-			channel->push(Variant(p.type, &p));
+			channel->push(Variant(&love::image::ImageData::type, i));
 
 
 		channel->release();
 		channel->release();
 	}
 	}

+ 1 - 5
src/modules/thread/LuaThread.cpp

@@ -110,12 +110,8 @@ void LuaThread::onError()
 	if (!eventmodule)
 	if (!eventmodule)
 		return;
 		return;
 
 
-	Proxy p;
-	p.type = &LuaThread::type;
-	p.object = this;
-
 	std::vector<Variant> vargs = {
 	std::vector<Variant> vargs = {
-		Variant(p.type, &p),
+		Variant(&LuaThread::type, this),
 		Variant(error.c_str(), error.length())
 		Variant(error.c_str(), error.length())
 	};
 	};