Closed egordorichev closed 7 years ago
I've been wondering, why is the world stored in memory as a linear array rather than just making it two dimensional so blocks can be accessed directly with their x and y?
Because to alloc 2d array you need to call new width times. But when you use 1d array, you need only one alloc call.
And in the new system I plan to use the same technic, but splited into chunks. But will help you, we always can make a array wrapper.
A 2d array in java is done like this:
int[][] data = new int[height][width]
Yes, it is. But if you look deeper, you will find, that java does this (c++ code):
int **data = new int *[width];
for (int i = 0; i < width; i++) {
data[i] = new int[height];
}
So here is the development plan:
Also, will we need infinite worlds?
Apparently terraria doesn't have an infinite world because they keep the entire map in memory so that they can make trees grow and stuff so we don't really need one but I think that we could have one if we wanted.
Instead of keeping all of the map in memory we could just increase a time variable on each chunk that isn't loaded and when the chunk gets loaded it updates everything that changes with time like trees.
Ok, sure. Also, we should flip the y-axis of the game logic. When we moved to libgdx, we inverted the drawing y-axis, but not the logic one. So now, the world 0:0 should be at bottom right for simplicity of calculations.
According to the, https://github.com/egordorichev/LastTry/pull/40 we must impove save system for the world. Added to todo list https://trello.com/c/SG1TeEc6/26-make-world-file-size-smaller-a-ton.
Probably, we should implement chunks system. If we will use chunks method, will we need to create infinite worlds?