I’m working on my first game, and therefore I lack experience with the design of the complex systems, the best way to do things and so. That’s why a seek advice.
First, I’ll try to briefly describe how I handle the tile map now: my map is infinite size (I procedurally generate it), and I divide it in chunks (I’m inspired a lot by minecraft for this game). Each chunk consists in a 2-dimensional array, that currently stores instances or instances of subclasses of the Block class (I know mixing both is a really bad approach, the way I’m doing it). Also, the chunks are stored in a Map <Point,Chunk> (being Point the coordinate of the Chunk) which is a field in the class ChunkManager(for the lack of a better name). Finally, one field of the World class is a ChunkManager.
Then, my problem lies within the Block class. I don’t know which approach will be the best (if there is such thing):
1-Store a byte/short/int/whatever, and then lookup in a Map which Block subclass does it belong to.
2-Store a Block subclass, which would store the light value of the tile, the x and y coordinates, a reference to the ChunkManager and other things.
Now I would probably go with the first, but I wanted to be able to do thing like chunkManager.getBlock(5,6).explode() instead of BlockMap.getBlock(chunkManager.getBlockId(5,6)).explode(chunkManager,5,6). On the other hand, I would like to avoid the duplication of the coordinates (they would be both in the Block subclass instance and in the position of the block in the chunk plus the position of the chunk in the map multiplied by the side of the chunk) and in general storing more information than necessary.
Note: I’m not looking for third party solutions (feel free to recommend them though), I want to implement it myself.
Anyway, what is your view on the problem? Please tell me which option is better, or another if you think those two aren’t right. Thank you for your help and for reading the whole thing.
TL:DR: Should I just store an int for each tile that corresponds to a type of tile, or an instance of the type of tile along with other useful (but duplicated) information, as the coordinates?