Wrapper instead of porting Love2D

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Mud
Citizen
Posts: 98
Joined: Fri Nov 05, 2010 4:54 am

Re: Wrapper instead of porting Love2D

Post by Mud »

SiENcE wrote:Yes thats exactly my Idea 2. I'm fiddling with it, but i cant get it working.
I sketched it out. We need to track the number of draw calls for a particular prop, and make sure we have an instance for each. So we create a lookup table to associate a prop with all instances of it.

Code: Select all

__prop_instances = {}
When we create the first instance of a prop, we add that to the list:

Code: Select all

__prop_instances[prop] = {index=1; prop}
When we need a new instance of a prop, we clone it and add it to that prop's instance list.

The index is used for rendering. Before our rendering pass, we reset it to 1. After we render a prop, we increment the index. If we need to render a prop but the index is higher than the number of available instances, we clone a new instance and add it to the list.

The code:

Changes to main loop (main.lua):

Code: Select all

love.graphics:___renderinit()
love.draw()
love.graphics:___render()
Changes to moai_love2d_wrapper.lua

Code: Select all

love = {}
love.graphics = {}

local __prop_instances = {}

local function clonePropInstance(prop)
	local copy = MOAIProp2D.new()
	copy:setDeck(prop.gfxQuad)
	layer:insertProp(copy)
	table.insert(__prop_instances[prop], copy)
	return copy
end

function love.graphics.newImage(file)
   local prop = MOAIProp2D.new ()

   prop.texture = MOAITexture.new ()
   prop.texture:load ( file )
   local xtex, ytex = prop.texture:getSize ()

   prop.gfxQuad = MOAIGfxQuad2D.new ()
   prop.gfxQuad:setTexture ( prop.texture )
   prop.gfxQuad:setRect ( xtex/2*-1, ytex/2*-1, xtex/2, ytex/2 )

   prop:setDeck(prop.gfxQuad )

   prop:setLoc ( -1000, -1000 )   --hack to place the gfx ouside the screen
   layer:insertProp ( prop )

   __prop_instances[prop] = {index=1; prop }

   return prop
end

local __renderlist = {}

function love.graphics:___renderinit()
	__renderlist = {}
end

function love.graphics:___render()
	-- new frame; reset instance index
	for _,prop in pairs(__prop_instances) do
		prop.index = 1
	end

	for i,renderitem in ipairs(__renderlist) do
		local prop, x, y = unpack(renderitem)

		-- get an instance of this prop, creating a new one if all existing ones have been used
		local instances = __prop_instances[prop]
		if instances.index > #instances then
			clonePropInstance(prop)
		end
		local renderprop = instances[instances.index]
		instances.index = instances.index + 1

		renderprop:setLoc(prop, x, y)
	end
end

function love.graphics.draw( prop, x, y, r, sx, sy, ox, oy )
	table.insert(__renderlist, {prop, x, y, r, sx, sy, ox, oy })
end

function love.graphics.setBackgroundColor() end
function love.graphics.setColor() end
function love.graphics.newImageFont() end
function love.graphics.quad() end
function love.graphics.setFont() end
function love.graphics.print() end

love.audio = {}
function love.audio.play() end
function love.audio.newSource() end

love.filesystem = {}
function love.filesystem.load() end
Last edited by Mud on Wed Feb 08, 2012 10:12 pm, edited 3 times in total.
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Wrapper instead of porting Love2D

Post by SiENcE »

Nice. I add your patch and push it to github.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Wrapper instead of porting Love2D

Post by bartbes »

Would it not make more sense to put the __renderinit code in clear and __render in present?
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Wrapper instead of porting Love2D

Post by SiENcE »

@Mud:
Do you know why images are only changing thier y location and not the x?

@bartbes:

can u share the code of your idea?

thx
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Wrapper instead of porting Love2D

Post by SiENcE »

I created an github project fro lovemoai.

https://github.com/SiENcE/lovemoai

Help is welcome :-) !
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Wrapper instead of porting Love2D

Post by molul »

I wish I could help you, but my programming skills are not enough. However I can encourage you all. GO LÖVERS! (lol)
User avatar
Mud
Citizen
Posts: 98
Joined: Fri Nov 05, 2010 4:54 am

Re: Wrapper instead of porting Love2D

Post by Mud »

SiENcE wrote:@Mud: Do you know why images are only changing thier y location and not the x?
This line renderprop:setLoc(prop, x, y) should be renderprop:setLoc(x,y)
User avatar
tsturzl
Party member
Posts: 161
Joined: Fri Apr 08, 2011 3:24 am

Re: Wrapper instead of porting Love2D

Post by tsturzl »

I definitely agree with this. As of now it looks like and iOS port of Love2D would require a full rewrite anyhow due to license limitations of the libraries being used. This would basically kill the android love project however. I'd say this is the best way to do it regardless, because if a new phone platform comes out, you don't have to maintain or write another port.
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Wrapper instead of porting Love2D

Post by SiENcE »

@Mud: thanks ... i overlocked this :)

Yes, but you can only support a subset of love. Maybe Moai is the wrong choice...but i want to see what we can achive. Next is maybe a CoronaSDK wrapper or somthing else.
sclark39
Prole
Posts: 5
Joined: Wed Jan 02, 2013 4:36 pm

Re: Wrapper instead of porting Love2D

Post by sclark39 »

I've been exploring how to port a love project to MOAI and found this project to be pretty useful, despite the small subset of love that it supports. There were a bunch of issues with the implementation as it was, so I forked the project and made some changes. Now you can run the love project in love or MOAI with an identical feature set (except that the clouds have a small outline for some reason, not sure why that is, i think it's due to how MOAI is handling png's), including audio support (if you use the moai-untz host).

SiENcE has already pulled some of my changes into his codebase, and I imagine will do the same with the rest. I probably will not continue working on this past what I have already done, but felt it was still worthwhile to share my work in case it helps others.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 230 guests