-
-
Notifications
You must be signed in to change notification settings - Fork 93
Extending Arch
Extending Arch is a simple undertaking. So you can easily wrap Arch in new APIs or simply write libraries and frameworks that extend Arch in some way.
For one, there is the fact that Arch is simply bare minimum, the core is clean and small. No unnecessary fuss, just what counts. On the other hand, there are countless exposed properties and the DangerousUtils
.
As an example, almost any repo from Arch.Extended can be used. Most of them hack into Arch somehow. Let's take Arch.Persistence as an example.
public Entity Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
// Read id
var id = reader.ReadInt32();
return DangerousEntityExtensions.CreateEntityStruct(id, WorldId);
}
Arch forbids the creation of Entity
structs by default (to protect the user from stupid actions). But don't worry, the DangerousUtils
provide enough API to work around these problems. So you can simply create a new entity struct to (de)serialize anything or...
// Create archetype
var chunks = new List<Chunk>((int)chunkSize);
var archetype = DangerousArchetypeExtensions.CreateArchetype(types.ToArray());
archetype.SetSize((int)chunkSize);
Even add whole new archetypes directly... And without any problems! Similar methods and abilities exist for all major arch classes. But be careful, you have to know what you are doing and it can get dangerous.