Visualizing map generation

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Visualizing map generation

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.
Last edited by rmcode on Wed Apr 19, 2017 12:17 am, edited 3 times in total.

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

Re: Visualizing map generation

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:

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.
You embed videos by clicking the youtube button in the post editor... or alternatively: [ youtube ] video_id [ /youtube ]

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.

rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Visualizing map generation

zorg wrote:
Wed Apr 19, 2017 12:09 am
You embed videos by clicking the youtube button in the post editor... or alternatively: [ youtube ] video_id [ /youtube ]

Code: Select all

[youtube]NhFLDAfqNp8[/youtube]
did the trick ... the youtube button added the tags, but I tried it with the full URL.

As for suspending threads, you can call Channel:demand in the thread for it to wait for a message pushed/supplied to that channel.
I don't think I can use Channel:demand to suspend a running loop for example:

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: 3055
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Visualizing map generation

rmcode wrote:
Wed Apr 19, 2017 12:16 am
I don't think I can use Channel:demand to suspend a running loop for example:
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.

airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Visualizing map generation

rmcode wrote:attempt to yield across C-call boundary
This means there's a call to a C function somewhere in the call stack between your yield and resume calls.

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.

s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Visualizing map generation

airstruck wrote:
Wed Apr 19, 2017 3:14 am
rmcode wrote:attempt to yield across C-call boundary
This means there's a call to a C function somewhere in the call stack between your yield and resume calls.

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.
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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
baby:hurt(me)
end

Who is online

Users browsing this forum: No registered users and 39 guests