Closed ValeTheVioletMote closed 3 years ago
Hey there, thanks for asking your question.
First of all: since May this year I'm working on a new version of Honeycomb (well, not continuously). I wanted to have released an alpha version already, but unfortunately I haven't managed to yet. The main reason for this new version is an improved way to search hexes and it seems that's exactly what your question's about.
I'm not saying the current version of Honeycomb is as fast (or good in general) as it could be, but I'm unable to reproduce the huge wait times you're experiencing. I've made a Fiddle for your 2nd example (using console.time()
and console.timeEnd()`) and on my machine it clocks just under 2 seconds. Again, maybe not as fast as you'd like, but I hope to improve that in the next version. Could you share your code so I can see why it takes so long in your case?
Here's the source of the neighborsOf()
function. The meat of the function is on lines 276-277. First the hexes (coordinates) around the target hex are acquired (up to 6), then they're converted from cube to cartesian coordinates and finally retrieved from the grid. As you mention, the final part (getting the hexes from the grid) might be a bit redundant and I maybe should leave that to you. But apart from that, I don't think there's any redundancy...
Just to let you know: I've released an alpha version with a new API! Please check out the next
branch.
I have a function that effectively does this:
Calling this in a loop a mere 42 times required 74 seconds. I'm confused.. are the calculations not based on the provided hex?
More examples... This is for a grid of 250x150, by the way:
I ended up writing my own version of the neighbors function based off the RedBlobGames article, and my only guess about this slowness is that you must be looping through the entire grid to check if the hex exists each time, possibly without doing hashed checks (e.g.)
Since I'd rather let Honeycomb be the authoritative and easy source for my hex-related calculations, is it possible you could at least expose the raw calculation functions separate from the checks against the grid? Let me handle checking if the particular hex exists, etc.
And if you already do that somewhere, please point me in the right direction and forgive me for wasting time....