egordorichev / LastTry

:deciduous_tree: LastTry is open-source game written in Java, using LibGDX library and inspired by Terraria :deciduous_tree:
MIT License
119 stars 17 forks source link

World save/load improvement #41

Closed egordorichev closed 7 years ago

egordorichev commented 7 years ago

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?

Storm-Peter commented 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?

egordorichev commented 7 years ago

Because to alloc 2d array you need to call new width times. But when you use 1d array, you need only one alloc call.

egordorichev commented 7 years ago

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.

Storm-Peter commented 7 years ago

A 2d array in java is done like this:

int[][] data = new int[height][width]

egordorichev commented 7 years ago

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];
}
egordorichev commented 7 years ago

So here is the development plan:

Also, will we need infinite worlds?

Storm-Peter commented 7 years ago

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.

egordorichev commented 7 years ago

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.

egordorichev commented 7 years ago

Done in https://github.com/egordorichev/LastTry/pull/58 .