- What do you want to achieve? Keep it simple and clear!
I have recently been working on a game which utilizes the wave function collapse algorithm to procedurally generate a world. A challenge associated with this has been the server client communication along with making sure that all the clients actually generate the same world.
- What is the issue? Include screenshots / videos if possible!
Im mainly writing this post to ask for feedback and/or help with a solution Ive developed. Currently the code is structured into a client script, server script and a module containing all the relevant functions to the algorithm. Initially I made the client employ the algorithm and spawn the chunks to minimize stress on the server, though this has had its problems. At first, having the server only generate a seed (seed is used by all random objects in the module) seemed like a reasonable idea but it has showed some clear problems. For example, if players generated chunks in a different order than other players they could have completely different worlds due to the nature of the WFC algorithm. Another problem was chunk updates, some objects like doors have to be updated across all clients which proved to be challenging since some players didnt even have said chunks loaded yet.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
The model I designed goes roughly as follows: The client loops over all chunks and checks which chunks have to be loaded (within a specified render distance) and then sends a pull request to the server via a remote function. The server contains a list of chunk states stored in a 3D array. Such chunk states will specify the rotation, (position is unnecessary since its already specified by the index) and sub states. Sub states specify the finer states of objects in a chunk (whether a door is open or not, for example). The serve will check if the requested chunk is present in the array, if it is, the chunk state will be returned, if it isnt the server will request the algorithm to generate said chunk state. Ultimately the server will not actually build the chunk (as in spawn in the parts), it will only store and generate chunk states. Once the client is provided with a chunk state, a function will generate the associated chunk.
There are obvious problems with this. Since I plan to have a fairly large amount of players on each server, overloading it could be a huge problem.
PS: I dont need anyone to create an entire system or whatever, its always useful to have some peer feedback, especially in this specific case.