-
Notifications
You must be signed in to change notification settings - Fork 20
World
Simon edited this page Jul 21, 2023
·
11 revisions
The core of Fleks is the World
which is the container for entities, components, systems and families. It is the object that you
need to update your systems.
To create a world simply call:
val world = configureWorld {}
A world without any system doesn't make sense and that's why there is a lambda argument for the configureWorld
DSL function
to configure it accordingly:
- Use
entityCapacity
to set the expected maximum amount of entities. The default value is 512. The purpose of this property is to initialize internal collections and arrays with a proper size for your game to avoid a lot ofArray.copy
calls in the background which are slow. - Use
injectables
to register injectables to your world that can be accessed anywhere within a Fleks context or from outside via aWorld
instance. - Use
families
to registerFamilyHook
s to your world. - Use
systems
to add a system to your world. The order in which they are added is the order in which they are called when callingworld.update
. - Use
onAddEntity
/onRemoveEntity
to registerEntityHook
s.
Here is an example that creates a world for 1000 entities with one injectable, two FamilyHooks, two EntityHooks and two systems:
val w = configureWorld(entityCapacity = 1000) {
injectables {
add(b2dWorld)
}
families {
val moveFamily = family { all(MoveComponent) }
onAdd(moveFamily) {entity ->
}
onRemove(moveFamily) {entity ->
}
}
systems {
add(MoveSystem())
add(PhysicSystem())
}
onAddEntity { entity ->
}
onRemoveEntity { entity ->
}
}