Module specs::saveload [] [src]

Save and load entities from various formats with serde.

WorldSerialize / WorldDeserialize

This module provides two SystemData implementors:

Fetching those makes it very easy to serialize or deserialize components. However, be aware that you cannot fetch storages used in WorldDeserialize with the same system. E.g. type SystemData = (WorldDeserialize<'a, Marker, MyError, (Pos, Vel)>, WriteStorage<'a, Vel>) is not valid since both WorldDeserialize and WriteStorage would fetch the same component storage mutably.

WorldSerialize implements Serialize and WorldDeserialize implements DeserializeSeed, so serializing / deserializing should be very easy.

Markers

Let's start simple. Because you usually don't want to serialize everything, we use markers to say which entities we're interested in. However, these markers aren't just boolean values; we'd like to also have id spaces which allow us to identify entities even though local ids are different. And the allocation of these ids is what MarkerAllocators are responsible for. For an example, see the docs for the Marker trait.

Structs

U64Marker

Basic marker implementation usable for saving and loading

U64MarkerAllocator

Basic marker allocator

WorldDeserialize

Struct which implements DeserializeSeed to allow serializing components from World.

WorldSerialize

This type implements Serialize so that it may be used in generic environment where Serialize implementation is expected. It may be constructed manually with WorldSerialize::new. Or fetched from System as SystemData. Serializes components in tuple T with marker M.

Traits

Marker

This trait should be implemented by a component which is going to be used as marker. This marker should be set to entity that should be serialized. If serialization strategy needs to set marker to some entity then it should use newly allocated marker from Marker::Allocator.

MarkerAllocator

This allocator is used with the Marker trait. It provides method for allocation new Markers. It should also provide a Marker -> Entity mapping. The maintain method can be implemented for cleanup and actualization. See docs for Marker for an example.

SaveLoadComponent

This trait should be implemented in order to allow component to be serializable with SerializeSystem. It is automatically implemented for all Component + DeserializeOwned + Serialize + Copy

Functions

deserialize

Deserialize entities according to markers.

serialize

Serialize components from specified storages via SerializableComponent::save of all marked entities with provided serializer. When the component gets serialized with SerializableComponent::save method the closure passed in ids arguemnt returns None for unmarked Entity. In this case SerializableComponent::save may perform workaround (forget about Entity) or fail. So the function doesn't recursively mark referenced entities. For recursive marking see serialize_recursive

serialize_recursive

Serialize components from specified storages via SerializableComponent::save of all marked entities with provided serializer. When the component gets serialized with SerializableComponent::save method the closure passed in ids argument marks unmarked Entity (the marker of which was requested) and it will get serialized recursively. For serializing without such recursion see serialize function.