The game I'm building allows users to create their own tile maps essentially, so I want the server to respond with tilemap coordinates if / when a user enters their custom world.
my main issue is storing the data for complex tilemaps.
You can think of tilemaps as arrays. So, you can just use an 2D array of numbers, where each number on the array represent a kind of tile.
If you want to serialize an array, for local storage or for network transmission, you can start by placing the dimensions (unless these are standard), followed by the value of each tile, in binary format, going row by row.
To deserialize, given that you know the dimensions, you can break the stream of tile values into rows. Knowing the number of columns tells you where it should end.
A couple notable alternatives to this approach are:
- Storing the tile values as characters in a string. If you use new line to mark the end of a row, it will be easy to edit and visualize in virtually any text editor.
- Storing the tile values as pixels in an bitmap image. This time you can visualize and perhaps edit with an image editor. Plus, you can seamlessly take advantage of lossless image compression such as the one provided by png. Plus, if you need to upload it to a shader, it is easy to use as a texture. Although, that is not your use case. See the Godot class image.
Now, if your tilemap is sparse, or if it is too large. There might be value in breaking it into chunks, and having a larger structure.
Some solutions: - An array of chunks. Very easy to query. - A quadtree of chunks. Will use less memory for sparse tilemaps. - Just a list of chunks with their coordinates. Easier to transmit.
Speaking of ease of transmit. You might want to have the game request chunks on demand based on the coordinates of the player. And those chunks can be png files. Well, how easy that is depends on your server technology.
If you also need to place other kinds of objects on the map, you may add them to same structure.
As you probably has seen in the documentation, you can use
set_cell to write to tilempas in runtime. See How do I programatically lay tiles with the Godot engine?.