Farvardin's game (was: moving multiple objects with mouse)

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
farvardin
Party member
Posts: 167
Joined: Sat Jun 28, 2008 6:46 pm

Farvardin's game (was: moving multiple objects with mouse)

Post by farvardin »

hello,

I'd like to try to implement this board game with löve:

http://anamnese.online.fr/site2/index.p ... anon#toc13

There are several pawns in it, I've managed to adapt the 2nd tutorial to move one pawn with mouse ( http://love.sourceforge.net/?page=tutorial&id=2 ), but can't think how to make all of them movable.

Code: Select all

if button == love.mouse_left then
		local width = pawn1:getWidth() / 2
		local height = pawn1:getHeight() / 2
Do I have to make a loop for every pawn? Won't it slow down the performance?
And how could I perform this loop?s
Last edited by farvardin on Fri Jul 04, 2008 4:58 am, edited 2 times in total.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: moving multiple objects with mouse

Post by rude »

I didn't understand the board game, but I made this demo for you. ^^

There are some comments and stuff inside, but I did it very quickly, so please forgive any spelling errors etc.
Attachments
mousemov.love
(2.56 KiB) Downloaded 411 times
User avatar
farvardin
Party member
Posts: 167
Joined: Sat Jun 28, 2008 6:46 pm

Re: moving multiple objects with mouse

Post by farvardin »

Thank you veeeeery much for this example rude! It's very kind of you.

I've adapted it for my project, and it's working well, but I'm a bit worried by the cpu load, it's getting more than 100% and get the fan to start...
Is it normal or could it be optimised?
I'm also getting a "flash" when resizing the window, because it's loading the default windows size first (800x600 I think).

I've uploaded the sample with this message.

(new attachment on the next page)
Last edited by farvardin on Thu Jul 03, 2008 6:48 pm, edited 4 times in total.
User avatar
cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

Re: moving multiple objects with mouse

Post by cag »

I wouldn't think that's normal at all. My Tetris demo was doing completely fine... and it had a helluva more graphics operations than a couple of texture blasts...
Aha, found the problem!

Your call to love.graphics.setMode() was making the rendering engine completely inefficient. My suggestion is to take out that line and add this to your game.conf:

Code: Select all

width = 850
height = 400
EDIT: Haven't tried this yet, but you might also be able to do the same thing changing # FSAA buffers to 2. That's a wild guess, though, and the method above is MUCH preferred, as it stops the initial window flash-thingy.
User avatar
Merkoth
Party member
Posts: 186
Joined: Mon Feb 04, 2008 11:43 pm
Location: Buenos Aires, Argentina

Re: moving multiple objects with mouse

Post by Merkoth »

farvardin wrote:Thank you veeeeery much for this example rude! It's very kind of you.

I've adapted it for my project, and it's working well, but I'm a bit worried by the cpu load, it's getting more than 100% and get the fan to start...
Is it normal or could it be optimised?
I'm also getting a "flash" when resizing the window, because it's loading the default windows size first (800x600 I think).

I've uploaded the sample with this message.
Regarding CPU usage:
It's normal, I'm afraid. You can try putting this somewhere at the end of your update() callback:

Code: Select all

love.timer.sleep( 10 )
This will put your game to sleep each frame for about ten milisecs, hopefully giving some air to your CPU.

Regarding window resizing, you can avoid that by defining which resolution to use in your game.conf file:

Code: Select all

width = 1024
height = 768
You should change those values as you see fit, of course :)

Hope this helps n_n
User avatar
cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

Re: moving multiple objects with mouse

Post by cag »

Merkoth wrote: Regarding CPU usage:
It's normal, I'm afraid. You can try putting this somewhere at the end of your update() callback:

Code: Select all

love.timer.sleep( 10 )
This will put your game to sleep each frame for about ten milisecs, hopefully giving some air to your CPU.
I've done some individual testing with Love on that regard already. I expected the sleep() to give room to the CPU as well, but as it stands, Love already has some sort of cpu-letting mechanism hard-coded into it, so my tests indicated that adding sleep either matched or actually (!) hindered performance, and that Love works fine without all that sleeping-mabobers. That's nice though, hiding all that gritty detail from new programmers...
Course, if it's different on other OS's/systems, then it's different, and I'm wrong. :)
User avatar
Merkoth
Party member
Posts: 186
Joined: Mon Feb 04, 2008 11:43 pm
Location: Buenos Aires, Argentina

Re: moving multiple objects with mouse

Post by Merkoth »

Well, in my (old, even pre 0.3.0) tests it used to work (Under Ubuntu)... But to be honest, I'm not really sure what was going on. In fact, one of the bugs fixed in 0.3.1 is the sleep() function which was causing trouble on Linux (surprisingly, 0.2.1 worked fine) so I'm kinda confused right now, hehe.

I'm currently on Windows (LÖVE 0.3.1), and lovetris uses almost no CPU time so colour me puzzled n_nU

EDIT: Sorry for repeating what you said before, I completely missed your post.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: moving multiple objects with mouse

Post by rude »

Merkoth wrote:But to be honest, I'm not really sure what was going on. In fact, one of the bugs fixed in 0.3.1 is the sleep() function which was causing trouble on Linux (surprisingly, 0.2.1 worked fine) so I'm kinda confused right now, hehe.
love.timer.sleep was dll-exported in 0.3.0 (not before), which caused a conflict with sleep in unistd.h. The function ended up referring to the latter one, and thus sleeping for 1000 times too long. :x
cag wrote:Love already has some sort of cpu-letting mechanism hard-coded into it, so my tests indicated that adding sleep either matched or actually (!) hindered performance, and that Love works fine without all that sleeping-mabobers. That's nice though, hiding all that gritty detail from new programmers...Course, if it's different on other OS's/systems, then it's different, and I'm wrong.
This is ... not completely true. LÖVE tries to get "vertical sync" if possible, and if it does, the FPS will be capped at 60FPS (edit: or your monitor refresh rate) and the CPU spared from horror. In my experience, vertical sync (as implemented by SDL) works most often on Windows with nVidia drivers, but is *supposed* to work everywhere. Of course, any feeble requests of vsync can be ignored by the graphics driver (it is usually a setting in the control panel), so yes it depends on the host system.

About flickering: I didn't notice any flickering, but if you like to set the display mode in Lua instead of the config file (nothing wrong with that), set the display_auto config option to false. See this page for an example. (Should probably have the same example at the page love.graphics.setMode(), *ahem*).
User avatar
cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

Re: moving multiple objects with mouse

Post by cag »

Ah, that makes sense, since I didn't find any sort of sleep/thread semaphore/foobar mechanism for this phenomenon while snooping through the source. I guess that it's probably better to suffer the imperceivable cpu hit adding sleep than to risk maxing out other systems...

I suppose that there really isn't much to do about it, except sleep and use dt properly... bummer, since I'm the kind who likes to do things by frames. ;)
User avatar
farvardin
Party member
Posts: 167
Joined: Sat Jun 28, 2008 6:46 pm

Re: moving multiple objects with mouse

Post by farvardin »

hello,

you were right, the slowness problem was caused by "love.graphics.setMode(850, 400, false, false, 1 )". I've used the game.conf and it"'s working well, without any heavy cpu load.

Now I'm looking inside the lovetris code for finding a way to "snap" the mouse or keyboard mouvements...
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], glass2d and 77 guests