I really don’t know how do i implement large maps(over worlds), but i split it into smaller maps, like chunks, and update them only… If you know any tutorial or something, please don’t hesitate to share! Thanks in advance!
Sounds like a job for some kind of tree structure.
Top node is the whole world. Break that up into several child nodes: North, South, East, and West for example.
Break each of those child nodes into further nodes.
When you update a node, first check if it needs to be updated, and if so, tell its children to update recursively until you reach a leaf node that needs to be updated.
See also: http://en.wikipedia.org/wiki/Quadtree
How would i do this for infinite terrain?
Not a single player will appreciate infinite terrain.
Make the world big enough and use a tree structure.
I dont realy know what that means… a tree structure?
Click KevinWorkman’s link.
This is how i used to save infinite maps, it breaks the land into 16X16 chunks, its just the basics, no map saving, no nonsense, but don’t copy it and expect it to work, try and learn from it
Update
Well semi infinite xD but it also has a good example of how to add in world generation too
If you don’t know what a tree structure is, then you probably shouldn’t be worrying about creating infinite terrain.
I’m not trying to discourage you, but you really might want to take a step back and start with something smaller- you’ll be more likely to succeed by taking smaller steps instead of trying to bite off more than you should be chewing.
Since you already have split your map into chunks, saving and loading only nearest chunks shouldn’t be that hard to achieve in order to save resources. What I would do is check the closest chunks around the player and test N, NE, E, SE, S, SW, W and NW cases:
This would work for a fixed size map. Also you would have to do some out of bounds checking. As for saving, I would try serializing the unneeded chunks and deserialize the new ones.
Thought for infinite map you should really look into some kind of structure. Or you could store them in an 1D ArrayList this way you could expand it as much as you need, just a wild thought.
Unless your like me and asign a priority to each chunk based on what is on it and over time depsawn the chunks that are 3+ chunks away from the player
I’ve tried several methods of chunk loading in my voxel engine and found this approach to be the best. It allows you to have minimal allocations and you don’t have to worry too much about data becoming invalid because that’s part of the design. If you’re happy with a fixed-size view of the world then this is the way to go.
Well i made something that is working BUT i load all of the chunks and if i have a lot my ram usage goes over 1 Gb… and i dont want that
my world class
and my Chunk class
I was thinking to just have an a 2D array of 3x3 chunks and as the player moves i make the previus chunk = new chunk… and i don’t really know how…