Danielv123 / gridworld

Automatic creation of distributed factorio gridworlds connected using edge_transports
4 stars 0 forks source link

Map merging #32

Closed Danielv123 closed 4 months ago

Danielv123 commented 5 months ago

Resolves #13

As per issue #13 over 2 years ago now, gridworld is designed with the intent for the maps to be able to be merged together and to run as a single instance. This is done by running every map on the same seed but a different position offset. The borders align exactly in terms of world coordinates.

This makes map merging about as simple as it can be. What is implemented in this PR is the following:

  1. Start a new server to perform the map merge
  2. Pre-generate all chunks that are inside the generated instances
  3. For each instance in the cluster, do the following:
    1. Delete all entities
    2. Serialize all tiles and set them in the same location on the target server
    3. Serialize all entities and set them in the same location on the target server

The difficult part is the last step - serializing and deserializing entities. As you might imagine, there are a lot of different entities in factorio, with a lot of different unique properties. Factorio does not provide any method of serializing entities - in the base game you can simply do .clone if you want to do this, but it has no intermediate representation.

The entity serializer as part of this PR aims to serialize and deserialze all properties on factorio entities. This will most likely not be achieved in quite some time, and I expect there to be follow up PRs with additional properties as we discover things that are missing.

Danielv123 commented 4 months ago

This should now merge both entities and tiles without much issue. The entity serializer is not fully featured - that is, there are many properties that are not being merged at the moment. Here are a few of the basics I'd like to get out of the way before merging: