Page 2 of 3
Re: Wrapper instead of porting Love2D
Posted: Wed Feb 08, 2012 10:08 pm
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.
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
Re: Wrapper instead of porting Love2D
Posted: Wed Feb 08, 2012 10:09 pm
by SiENcE
Nice. I add your patch and push it to github.
Re: Wrapper instead of porting Love2D
Posted: Thu Feb 09, 2012 7:24 am
by bartbes
Would it not make more sense to put the __renderinit code in clear and __render in present?
Re: Wrapper instead of porting Love2D
Posted: Thu Feb 09, 2012 10:56 am
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
Re: Wrapper instead of porting Love2D
Posted: Fri Feb 10, 2012 11:30 am
by SiENcE
I created an github project fro lovemoai.
https://github.com/SiENcE/lovemoai
Help is welcome :-) !
Re: Wrapper instead of porting Love2D
Posted: Fri Feb 10, 2012 1:07 pm
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)
Re: Wrapper instead of porting Love2D
Posted: Mon Feb 13, 2012 5:26 pm
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)
Re: Wrapper instead of porting Love2D
Posted: Mon Feb 13, 2012 5:26 pm
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.
Re: Wrapper instead of porting Love2D
Posted: Mon Feb 13, 2012 11:02 pm
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.
Re: Wrapper instead of porting Love2D
Posted: Wed Jan 02, 2013 4:41 pm
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.