Best method for infinite terrain generation

Bingdom

Googledom
Currently im using tiles for the graphics and ds_grids for the collision detection and data storage, but i noticed that ds_grids do not like going negative, what's the best way of countering it, and ensuring that the world will be infinite? Would just mirroring the world using abs(x) be the best choice? How will i do the infinite generation and chunking system and will be rendering correctly after zooming?

Thanks for reading :)
 
M

Misty

Guest
Mod is your friend you offset the relative xy by a value like 9000 and so the mod never goes negative.
 

Bingdom

Googledom
True, i did just notice that my data structure is divided by 32 compared to coordinates, so going -9000 will take a long time. :)
 
Instead of storing everything in a grid using direct coordinates, I would suggest storing multiple grids in a ds_map, having the key as the "chunk coordinates", for example, if this was your map:

Code:
----------------------
| -1,-1| -1,0 | -1,1 |
----------------------
| 0,-1 | 0,0  | 0,1  |
----------------------
| 1,-1 | 1,0  | 1,1  |
----------------------
... Your keys would be the string values of the coordinates, eg: "-1:-1", and each key in the map would hold a grid with the appropriate values. You'd then just have to access the data in the grids relatively instead of absolutely. This is basically how I'm planning my chunking system to work.
 

Bingdom

Googledom
Hmm, interesting. I was planning on making my chunk sizes according to my view size. So that it would be easier for weaker devices to load chunks on a limited smaller view. But that could lead to chunks merging into each other and that would be hard to figure out (i think). Thanks guys for the help :)
 
A

AnimusRex

Guest
Hey Bingdom; I'd refer you to these series of tutorials, at least to build more knowledge on the topic, even if his system isn't what you end up using, I found it very helpful;

 

Bingdom

Googledom
That's for that, i will go though it and hopefully help me learn how to read/write individual different chunks.
 
Top