Cubitect / cubiomes

C library that mimics the Minecraft biome generation.
MIT License
556 stars 98 forks source link

>MC_1_13 getSpawn() can be simplified to remove the 1024x iteration. #81

Closed Nel-S closed 1 year ago

Nel-S commented 1 year ago

Currently the code is set up to call findServerSpawn() 1024 times, each with a slightly different value of j and k. However, j and k start out as 0, and after each iteration they have u and v added to them... which are also 0, meaning the exact same call is made each time (and the sign-swapping does nothing to change that since -0 = 0). Thus, in its current form, the 1024x iteration loop can be removed entirely, speeding up any relevant programs by... well, 1024 times.

Cubitect commented 1 year ago

Thanks for pointing this out, but this was actually a bug which was introduced some time ago while adding support for 1.18. It should be a spiral iterator and the v-value should start with -1. Also, 1024 is just an upper limit, the loop terminates very quickly for most seeds and the accuracy isn't as affected as much as you may think. So the impact in speed and accuracy from the bug was actually surprisingly limited.

Additionally to fixing this, I have taken the opportunity to introduce support for an approximation of the surface height and use it with getSpawn(), so the accuracy should be improved now. However, it still is far from perfect.