The loading is a simulation of a chunk loader for infinite 2d terrain. I have purposefully slowed it down so you can see it load using my "stochastic priority queue". I am currently using this infinite voronoi code to break up an infinite world into non-square cells.
Here are some details on the construction:
- It uses an infinite grid of square tiles.
- Each tile has a seed computed by hashing its x,y coordinate.
- The seed is used to roll a random point inside the tile.
- Then I compute the polygon for each tile by constructing a voronoi diagram using the points for a 5x5 tile area surrounding it
- I use fortune's algorithm and throw away a lot of the work (keeping only one polygon)
- A 5x5 area is the smallest area I found that guarantees that the central tile's polygon is the same as it would be in an infinite grid
The chunk loader prioritizes chunks by their proximity to the center of the screen. Since these priorities change pretty often I couldn't use a regular priority queue/heap. I settled on each thread picking a small number of possible chunks from a list and loading whichever has the highest priority currently.
It's not very efficient, but I was sort of testing the multithreaded chunk loader and I uploaded it because it looked cool.
Source code: github.com/gpergrossi/java-vo...
I am aware of some rare geometry bugs and the fact that I have over-complicated my implementation of fortune's algorithm, which is related to the bugs.
18 июн 2017