WorldType

World identifier type-tag, used to isolate static data when creating different worlds in the same process

  • Represented as a user structure without data with a marker interface IWorldType

Example:

public struct MainWorldType : IWorldType { }
public struct MiniGameWorldType : IWorldType { }

World

Library entry point responsible for accessing, creating, initializing, operating, and destroying world data

  • Represented as a static class World<T> parameterized by IWorldType

Since the type-identifier IWorldType defines access to a specific world
There are three ways to work with the framework:


The first way is as is via full address (very inconvenient):

public struct WT : IWorldType { }

World<WT>.Create(WorldConfig.Default());
World<WT>.CalculateEntitiesCount();

var entity = World<WT>.Entity.New<Position>();

The second way is a little more convenient, use static imports or static aliases (you’ll have to write in each file)

using static FFS.Libraries.StaticEcs.World<WT>;

public struct WT : IWorldType { }

Create(WorldConfig.Default());
CalculateEntitiesCount();

var entity = Entity.New<Position>();

The third way is the most convenient, use type-aliases in the root namespace (no need to write in every file)

This is the method that will be used everywhere in the examples

public struct WT : IWorldType { }

public abstract class World : World<WT> { }

World.Create(WorldConfig.Default());
World.CalculateEntitiesCount();

var entity = World.Entity.New<Position>();

Basic operations:

// Defining the world ID
public struct WT : IWorldType { }

// Register types - aliases
public abstract class World : World<WT> { }

// Creating a world with a default configuration
World.Create(WorldConfig.Default());
// Or a custom one
World.Create(new() {
            // Base capacity for entities when creating a world
            baseEntitiesCapacity = 4096,                        
            // Base size of all component types (number of component types)
            BaseComponentTypesCount = 64                        
            // Base size of all varieties of tag types (number of tag types)
            BaseTagTypesCount = 64,                             
            // Operation mode of multithreaded processing 
            // (Disabled - no threads are created, MaxThreadsCount - maximum available number of threads is created, CustomThreadsCount - specified number of threads)
            ParallelQueryType = ParallelQueryType.Disabled,
            // Number of threads at ParallelQueryType.CustomThreadsCount
            CustomThreadCount = 4,
            // Strict Query default mode of operation, optionally in the Queries section
            DefaultQueryModeStrict = true
        });

World.Entity.    // Entity access for MainWorldType (world ID)
World.Context.   // Access to context for MainWorldType (world ID)
World.Components.// Access to components for MainWorldType (world ID)
World.Tags.      // Access to tags for MainWorldType (world ID)

// Initialization of the world
World.Initialize();

// Destroying and deleting the world's data
World.Destroy();

// true if the world is initialized
bool initialized = World.IsInitialized();

// the number of active entities in the world
int entitiesCount = World.CalculateEntitiesCount();

// current capacity for entities
int entitiesCapacity = World.CalculateEntitiesCapacity();