love.event.wait(timeout)

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.
Post Reply
Anononymous
Prole
Posts: 4
Joined: Wed Dec 16, 2015 4:40 pm

love.event.wait(timeout)

Post by Anononymous » Fri Mar 04, 2016 10:43 am

I'm trying to build sort of a dungeon crawler where enemies take a turn automatically every second or so. Obviously I can't poll() once a second because the player should be able to move whenever he feels like. I can't wait() either since that can just block the thread. I guess I could use a separate thread that invokes love.event.push() every second (haven't tried that) but I'd much rather pass a timeout value to love.event.wait(). What you say?

P.S. I'm using a custom love.run() of course.

User avatar
slime
Solid Snayke
Posts: 2851
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.event.wait(timeout)

Post by slime » Fri Mar 04, 2016 11:34 am

You don't need to use threads or modify love.run to do an action every second. Check out timer libraries like hump.timer (download).

Anononymous
Prole
Posts: 4
Joined: Wed Dec 16, 2015 4:40 pm

Re: love.event.wait(timeout)

Post by Anononymous » Fri Mar 04, 2016 12:13 pm

I forgot to mention that one of the reasons I want a timeout argument for love.event.wait() is that I want the game to just sleep and not use any resources when it doesn't need to do anything, that is when the OS isn't sending it any events and no animation deadline has been reached. The default love.run() doesn't satisfy this requirement and it looks like hump.timer was designed with the default love.run() in mind.

Also I have a couple of apps in mind where the delay is way more than one second and I just want them to chill in the background without making the fans spin too much.

User avatar
zorg
Party member
Posts: 2717
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: love.event.wait(timeout)

Post by zorg » Fri Mar 04, 2016 8:05 pm

But it does sleep; even with the default love.run, with or without vsync (though without does call lg.present and related more times), there's that love.timer.sleep call near the end. If your code does nothing in the interim, and there are no events from SDL, then having it spin should be acceptable, it won't use up resources that way, unless you coded something wrong.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Anononymous
Prole
Posts: 4
Joined: Wed Dec 16, 2015 4:40 pm

Re: love.event.wait(timeout)

Post by Anononymous » Sat Mar 05, 2016 10:47 am

Unfortunately it's not acceptable for me. My CPU was manufactured 7 or 8 years ago and there's a noticeable difference between a wait() loop and the default poll() loop. I'm guessing on a smartphone the diff should be noticeable too.

User avatar
slime
Solid Snayke
Posts: 2851
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.event.wait(timeout)

Post by slime » Sat Mar 05, 2016 1:14 pm

You could just make it sleep for a few more milliseconds each frame – in fact, wait() just calls sleep(10/1000); poll(); in a loop until there's an event.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests