I've shown a map generator and viewer previous time. It was very buggy with glitches and all that. I've now built an improved version of this.
The improvements include:
- A fixed (but expandable!) map size.
- No more graphical glitches.
- More efficiƫnt code (it doesn't render stuff which is offscreen).
Well, I didn't get there without problems. The first thing I've tried was a fixed 2-dimensional array which contained the items. While this was quite sufficient on a small scale, as soon as I hit over a certain size of the map, the lag became almost unbearable. So I resorted back to the old method of only containing a list of items which were actually generated.
This has several advantages. Firstly, it is more efficient if you have less than 100.000 items on the map. Secondly, you can have multiple items at one location.
Further improvements could be that you keep up 2 lists. One of the total items on the map, and one of the items nearby your current viewing position. You check the smaller list every time, but the big total list gets checked once every second or so. This could be an improvement, but I'm not exactly sure if this would work properly.
Here's a video of the application:
Download location of the source: here
Till the next time!
Roberto 'dirtbag007' Moretti