I'm preparing to slowly add random generation to "On The Roadside" and from earlier ventures into map generation I think a big help would be the ability to visualize each step of the generation.
What I mean is something like this:
So first I thought I could use / abuse coroutines, but I guess "attempt to yield across C-call boundary" is a hint that I can't really use them in LÖVE, or can I?
I have worked with threads before, but now I'm wondering if there is a way to pause a thread until it receives a message from a channel. Basically to emulate the way coroutines can yield and resume.
Any pointers (threading-related or not) are appreciated.
Visualizing map generation
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- zorg
- Party member
- Posts: 3441
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Visualizing map generation
You embed videos by clicking the youtube button in the post editor... or alternatively: [ youtube ] video_id [ /youtube ]rmcode wrote: ↑Wed Apr 19, 2017 12:04 am I'm preparing to slowly add random generation to "On The Roadside" and from earlier ventures into map generation I think a big help would be the ability to visualize each step of the generation.
What I mean is something like this:
https://www.youtube.com/watch?v=NhFLDAfqNp8 (How the eff do you embed youtube videos )
So first I thought I could use / abuse coroutines, but I guess "attempt to yield across C-call boundary" is a hint that I can't really use them in LÖVE, or can I?
I have worked with threads before, but now I'm wondering if there is a way to pause a thread until it receives a message from a channel. Basically to emulate the way coroutines can yield and resume.
Any pointers (threading-related or not) are appreciated.
For the C-call boundary yielding, i thought that was only an issue in PUC lua, and that it worked with luaJIT... maybe i'm wrong.
As for suspending threads, you can call Channel:demand in the thread for it to wait for a message pushed/supplied to that channel.
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.
Re: Visualizing map generation
Code: Select all
[youtube]NhFLDAfqNp8[/youtube]
I don't think I can use Channel:demand to suspend a running loop for example:
As for suspending threads, you can call Channel:demand in the thread for it to wait for a message pushed/supplied to that channel.
Code: Select all
for x = 1, w do
grid[x] = {}
for y = 1, h do
channel:push( 'yield' ) -- Draw the map in some other class
grid[x][y] = 0
channel:demand() -- Continue
end
end
- zorg
- Party member
- Posts: 3441
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Visualizing map generation
It doesn't matter where you have the :demand call, it will halt processing and block until some other thread pushes something into that channel.
I meant like... think of it like this:
channel:push in main thread is kinda like coro.resume()
channel:demand in second thread is kinda like coro.yield()
(you should use separate channels for the two directions though, especially if you also want to pass variables the way yield can)
you do channel:demand() in the second thread to suspend its processing, and it stays like that until you push something into the channel from the main thread. (Also probably shouldn't :demand on the main thread since blocking execution there makes the program unresponsive, for obvious reasons )
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.
Re: Visualizing map generation
This means there's a call to a C function somewhere in the call stack between your yield and resume calls.rmcode wrote:attempt to yield across C-call boundary
It's most likely a "require" in which case it shouldn't be hard to move outside the coroutine, or possibly a "pcall" which could be trickier. Not that many C functions call back into Lua code, although there are some Love functions that take callbacks. I'd look for "require" first.
That said, if your map generation routine has any kind of main loop, you should just be able to move the body of that loop out into a separate function and call it once every time a key is pressed or some time passes or whatever. Probably simpler than coroutines or threads.
Re: Visualizing map generation
the error should print a stack trace that C functions are recognizable in I think. otherwise you can also use the debug library to get one, the source file will be set to 'C' for offending functions.airstruck wrote: ↑Wed Apr 19, 2017 3:14 amThis means there's a call to a C function somewhere in the call stack between your yield and resume calls.rmcode wrote:attempt to yield across C-call boundary
It's most likely a "require" in which case it shouldn't be hard to move outside the coroutine, or possibly a "pcall" which could be trickier. Not that many C functions call back into Lua code, although there are some Love functions that take callbacks. I'd look for "require" first.
That said, if your map generation routine has any kind of main loop, you should just be able to move the body of that loop out into a separate function and call it once every time a key is pressed or some time passes or whatever. Probably simpler than coroutines or threads.
Who is online
Users browsing this forum: Ahrefs [Bot] and 156 guests