Closed trsh closed 4 years ago
P.S. in your code I got lot's of undefined
for let current_r = queue[pos];
. Have no idea how that effects stuff when going down the pipe :)
Ah, sorry about that! As a "game jam" type project, some of my code here is messy and undocumented. It works similarly to your function, but it does it by trying to minimize allocations. Here's the explanation of how that function works:
This is adapted from a breadth first search (BFS). With BFS, the queue will be all elements in queue[queue_out ... queue.length-1]. Pushing onto the queue adds an element to the end, increasing queue.length. Popping from the queue removes an element from the beginning by increasing queue_out.
To add variety, I do a random search instead of a breadth first search. I continue to queue[queue_out ... queue.length-1] as the frontier elements to be searched, but at each step I pick a random element to pop instead of the earliest one. I do this by swapping queue[pos] and queue[queue_out].
Yes, you are correct, there is a bug in the code. Instead of the for loop having queue_out < mesh.numRegions
it should be queue_out < queue.length
.
Ok. Will try to get my head around it. Thanks for the explanation :)
Hi! I could not make sense of some of function you wrote, so i did my version. What it does, is, for example takes mountain 1 and assign distances on its neighbors, than for next mountain etc. When all mountains are iterated, it goes trough again, but assigns neighbor neighbors, etc., until all is assigned. In simple words it kind of radiates the fields out for the seed 1 by 1. What do you think? Seems to work, but results are different.