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.
love.event.wait(timeout)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: love.event.wait(timeout)
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).
-
- Prole
- Posts: 4
- Joined: Wed Dec 16, 2015 4:40 pm
Re: love.event.wait(timeout)
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.
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.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: love.event.wait(timeout)
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 True 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.
-
- Prole
- Posts: 4
- Joined: Wed Dec 16, 2015 4:40 pm
Re: love.event.wait(timeout)
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.
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: love.event.wait(timeout)
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.
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot] and 12 guests