Page 1 of 2

Love Game Slave Example Source & Performance

Posted: Mon Jun 20, 2011 2:01 pm
by Cylog
Hi everyone!
I was fiddling around with my first project and noticed some slow-downs and a delay when starting the game. It most likely comes from loading the music, fonts etc. so I guessed it would be neat to use threads... the problem is, I have no idea how they work. I tried to understand examples and search the forum but I really didn't find anything useful.

I noticed that the "Default Example" when starting up Love is just snapping up, no load times at all, and it seems pretty heavy. I'd like to view the source code, I dug aroung the Application but I didn't find the LUA Source. Anyone knows where I can get it?

On a short side-note: I noticed "flickers" when playing music in Love, anyone knows why Love does this? And more importantly, how to fix it? (btw, I'm using the newest Love-Version on Mac OS X 10.6.7)

So, thanks in advance.

-Cylog

Re: Love Game Slave Example Source & Performance

Posted: Mon Jun 20, 2011 2:51 pm
by nevon
Post your code and we can see if you're doing something wrong. If you're loading a lot of resources at once in love.load, there can be some startup time, but usually not more than a second or two.

As for the music, are you by any chance using mp3? If so, try ogg/vorbis instead. That's the preferred audio format.

Re: Love Game Slave Example Source & Performance

Posted: Mon Jun 20, 2011 3:01 pm
by TechnoCat
Cylog wrote:so I guessed it would be neat to use threads... the problem is, I have no idea how they work. I tried to understand examples and search the forum but I really didn't find anything useful.
This is pretty old and I'm guessing it still applies: http://love2d.org/forums/viewtopic.php?f=4&t=2138
Cylog wrote:I noticed that the "Default Example" when starting up Love is just snapping up, no load times at all, and it seems pretty heavy. I'd like to view the source code, I dug aroung the Application but I didn't find the LUA Source. Anyone knows where I can get it?
https://bitbucket.org/rude/love/src/104 ... lua#cl-647

Re: Love Game Slave Example Source & Performance

Posted: Mon Jun 20, 2011 6:13 pm
by Cylog
Oh sweet, thanks for the fast reply nevon, TechnoCat. I didn't notice that thread, thanks.
Hm, funny, the Game Slave Demo isn't using Images per se, it seems that it decodes base64 files which are turned into ImageData. Weird. And it's not even using Threads... this should be somewhat inefficient, yet it works so well.
Thanks for the tipp with Ogg/Vorbis, it loads faster now ^^ There are still some "clicks" and flickers, but they seem rare now. I think it'd be better to play the music in a seperate thread, maybe it's interfering with the update() or other functions.

I'll inform you guys if I still encounter problems, thanks a lot ^^

Re: Love Game Slave Example Source & Performance

Posted: Mon Jun 20, 2011 8:39 pm
by bartbes
Cylog wrote:it seems that it decodes base64 files which are turned into ImageData.
Correct, the images are inside of the binaries. (ImageData is nothing more than a decoded image.)
Cylog wrote:And it's not even using Threads...
Because it loads, what? 10 small images? That shouldn't take long. Also, disk i/o.
Cylog wrote:I think it'd be better to play the music in a seperate thread, maybe it's interfering with the update() or other functions.
Music playback is done in a separate thread by the engine.

Re: Love Game Slave Example Source & Performance

Posted: Mon Jun 20, 2011 11:00 pm
by Cylog
bartbes wrote:Because it loads, what? 10 small images? That shouldn't take long. Also, disk i/o.
True, true, didn't think of that. Oh the performance problem makes more sense now. I'm loading a "giant" 1162 × 688 picture on start, so I guess that is the main problem. It probably would be faster to cut it into smaller pieces and load them as the game progresses...

About music playback... you're totally right ^^ I somehow thought that it'd be the programmers choice to get it into threads and stuff, I guess proper music support is only possible by multi-treading.

I tried to include threads into my game anyways, it seems though, that they don't really want to communicate with each other (I mean main() and the thread). I'll post the source here when I wake up, see ya til then ^^

Re: Love Game Slave Example Source & Performance

Posted: Tue Jun 21, 2011 12:04 am
by Ensayia
Cylog wrote:I'm loading a "giant" 1162 × 688 picture...
Be aware that your images will need to be sized to a power of two in each dimension to work properly on all systems (8, 16, 32, 64, 128, 256, 512, etc...)

See the wiki article on PO2 Syndrome for more details.

Re: Love Game Slave Example Source & Performance

Posted: Tue Jun 21, 2011 8:22 am
by Cylog
Ensayia wrote:Be aware that your images will need to be sized to a power of two in each dimension to work properly on all systems (8, 16, 32, 64, 128, 256, 512, etc...)
I heard about that, thanks for reminding me anyways ^^ My game is still in a prototype phase, the image will be cut down to proper dimensions later on.

Alright, I tried to use Threads to send a simple messages back and forth between the Thread and main, but they don't seem to respond or even recieve messages. I'm calling routines.lua from main.lua, it contains most of the code, variables are stored in a seperate file.

main.lua:

Code: Select all

function love.load()
    exspark()
    extload() 
end
routines.lua:

Code: Select all

function exspark()
musicload = love.thread.newThread("musix", "musicload.lua")
musicload:start()
end

function extload()
love.graphics.setBackgroundColor(0,0,0)
end

function eventtimer(dt)
time = time + (timerspeed * dt)
--EVENT 1
if time >= 1500 then
layerdecayactive = true
end
--EVENT 2

if time >= 1400 then
--Thread Message
musicload:send("ping", true)
--Thread Response
response = musicload:receive("response")
if (response) then  -- if communication is working change BackgroundColor to show visible result.
love.graphics.setBackgroundColor(255,255,255)
end
end
end 

function extupdate(dt)
	eventtimer(dt)
end
musicload.lua:

Code: Select all

local this_thread = love.thread.getThread()
local msg = this_thread:receive("ping")
while (true) do
if (msg) then
this_thread:send("response", true)
end
end

Re: Love Game Slave Example Source & Performance

Posted: Tue Jun 21, 2011 9:49 am
by bartbes
You never call expupdate.

Re: Love Game Slave Example Source & Performance

Posted: Tue Jun 21, 2011 12:41 pm
by Cylog
Oh, sorry I forgot to include that. Anyways, I'll just upload the whole .love file. As for the art... it's just a sketch and quickly colored to get a quick impression ^^
Well, there you go. main.lua calls the function exospark() from routines.lua. routines. exospark() creates the thread. The function eventtimer(dt) tries to communicate with the thread.
You can move the picture via arrowkeys, I'm positioning and cutting it later.

The upload attachement isn't working at the moment (at least for me), so I uploaded it to my Dropbox:
http://dl.dropbox.com/u/1185194/show.love