Compare commits
3 commits
50fa2ce19c
...
d77317c816
| Author | SHA1 | Date | |
|---|---|---|---|
| d77317c816 | |||
| 76a23aa4ed | |||
| 9b75772039 |
4 changed files with 32 additions and 20 deletions
|
|
@ -44,7 +44,7 @@ struct Entity
|
||||||
return cast(T*)getComponent(becsID!T);
|
return cast(T*)getComponent(becsID!T);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* getComponent(ushort component_id) const
|
export void* getComponent(ushort component_id) const
|
||||||
{
|
{
|
||||||
EntityManager.EntitiesBlock* block = gEntityManager.getMetaData(&this);
|
EntityManager.EntitiesBlock* block = gEntityManager.getMetaData(&this);
|
||||||
EntityManager.EntityInfo* info = block.type_info;
|
EntityManager.EntityInfo* info = block.type_info;
|
||||||
|
|
@ -54,7 +54,7 @@ struct Entity
|
||||||
return (cast(void*)block + info.deltas[component_id] + block.entityIndex(&this) * gEntityManager.components[component_id].size);
|
return (cast(void*)block + info.deltas[component_id] + block.entityIndex(&this) * gEntityManager.components[component_id].size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasComponent(ushort component_id) const
|
export bool hasComponent(ushort component_id) const
|
||||||
{
|
{
|
||||||
EntityManager.EntitiesBlock* block = gEntityManager.getMetaData(&this);
|
EntityManager.EntitiesBlock* block = gEntityManager.getMetaData(&this);
|
||||||
EntityManager.EntityInfo* info = block.type_info;
|
EntityManager.EntityInfo* info = block.type_info;
|
||||||
|
|
@ -62,7 +62,7 @@ struct Entity
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityMeta getMeta() const
|
export EntityMeta getMeta() const
|
||||||
{
|
{
|
||||||
EntityMeta meta;
|
EntityMeta meta;
|
||||||
meta.block = gEntityManager.getMetaData(&this);
|
meta.block = gEntityManager.getMetaData(&this);
|
||||||
|
|
@ -85,7 +85,7 @@ struct EntityMeta
|
||||||
return cast(T*)getComponent(becsID!T);
|
return cast(T*)getComponent(becsID!T);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* getComponent(ushort component_id) const
|
export void* getComponent(ushort component_id) const
|
||||||
{
|
{
|
||||||
const (EntityManager.EntityInfo)* info = block.type_info;
|
const (EntityManager.EntityInfo)* info = block.type_info;
|
||||||
|
|
||||||
|
|
@ -95,7 +95,7 @@ struct EntityMeta
|
||||||
return (cast(void*)block + info.deltas[component_id] + index * gEntityManager.components[component_id].size);
|
return (cast(void*)block + info.deltas[component_id] + index * gEntityManager.components[component_id].size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasComponent(ushort component_id) const
|
export bool hasComponent(ushort component_id) const
|
||||||
{
|
{
|
||||||
const EntityManager.EntityInfo* info = block.type_info;
|
const EntityManager.EntityInfo* info = block.type_info;
|
||||||
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)return false;
|
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)return false;
|
||||||
|
|
@ -133,7 +133,7 @@ export struct EntityTemplate
|
||||||
/************************************************************************************************************************
|
/************************************************************************************************************************
|
||||||
Get specified component. If component doesn't exist function return null. Returned pointer is valid during EntityTemplate lifetime.
|
Get specified component. If component doesn't exist function return null. Returned pointer is valid during EntityTemplate lifetime.
|
||||||
*/
|
*/
|
||||||
void* getComponent(ushort component_id) const nothrow @nogc
|
export void* getComponent(ushort component_id) const nothrow @nogc
|
||||||
{
|
{
|
||||||
if(component_id >= info.tmpl_deltas.length || info.tmpl_deltas[component_id] == ushort.max)return null;
|
if(component_id >= info.tmpl_deltas.length || info.tmpl_deltas[component_id] == ushort.max)return null;
|
||||||
return cast(void*)(entity_data.ptr + info.tmpl_deltas[component_id]);
|
return cast(void*)(entity_data.ptr + info.tmpl_deltas[component_id]);
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ export ulong defaultHashFunc(T)(auto ref T t) nothrow @nogc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong hash(byte[] array) nothrow @nogc
|
export ulong hash(byte[] array) nothrow @nogc
|
||||||
{
|
{
|
||||||
ulong hash = 0;
|
ulong hash = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ alias SerializeVector = bubel.ecs.vector.Vector!ubyte;
|
||||||
///Global EntityManager used for everything.
|
///Global EntityManager used for everything.
|
||||||
export __gshared EntityManager* gEntityManager = null;
|
export __gshared EntityManager* gEntityManager = null;
|
||||||
|
|
||||||
|
version(D_BetterC) version = NoDRuntime;
|
||||||
|
|
||||||
/************************************************************************************************************************
|
/************************************************************************************************************************
|
||||||
Entity manager is responsible for everything.
|
Entity manager is responsible for everything.
|
||||||
|
|
||||||
|
|
@ -359,7 +361,7 @@ export struct EntityManager
|
||||||
void registerSystem(Sys)(int priority, const(char)[] pass_name)
|
void registerSystem(Sys)(int priority, const(char)[] pass_name)
|
||||||
{
|
{
|
||||||
ushort pass = passes_map.get(pass_name, ushort.max);
|
ushort pass = passes_map.get(pass_name, ushort.max);
|
||||||
version (D_BetterC)
|
version (NoDRuntime)
|
||||||
assert(pass != ushort.max, "Update pass doesn't exist.");
|
assert(pass != ushort.max, "Update pass doesn't exist.");
|
||||||
else
|
else
|
||||||
assert(pass != ushort.max, "Update pass (Name " ~ pass_name ~ ") doesn't exist.");
|
assert(pass != ushort.max, "Update pass (Name " ~ pass_name ~ ") doesn't exist.");
|
||||||
|
|
@ -381,7 +383,7 @@ export struct EntityManager
|
||||||
|
|
||||||
assert(register_state,
|
assert(register_state,
|
||||||
"registerSystem must be called between beginRegister() and endRegister().");
|
"registerSystem must be called between beginRegister() and endRegister().");
|
||||||
version (D_BetterC)
|
version (NoDRuntime)
|
||||||
assert(pass < passes.length, "Update pass doesn't exist.");
|
assert(pass < passes.length, "Update pass doesn't exist.");
|
||||||
else
|
else
|
||||||
assert(pass < passes.length, "Update pass (ID " ~ pass.to!string ~ ") doesn't exist.");
|
assert(pass < passes.length, "Update pass (ID " ~ pass.to!string ~ ") doesn't exist.");
|
||||||
|
|
@ -390,7 +392,7 @@ export struct EntityManager
|
||||||
enum SystemName = fullName!Sys;
|
enum SystemName = fullName!Sys;
|
||||||
//enum SystemName = Sys.stringof;
|
//enum SystemName = Sys.stringof;
|
||||||
|
|
||||||
System system;
|
System system = System();
|
||||||
system.m_pass = pass;
|
system.m_pass = pass;
|
||||||
|
|
||||||
// static if (!(hasMember!(Sys, "system_id")) || !is(typeof(Sys.system_id) == ushort))
|
// static if (!(hasMember!(Sys, "system_id")) || !is(typeof(Sys.system_id) == ushort))
|
||||||
|
|
@ -840,7 +842,7 @@ export struct EntityManager
|
||||||
foreach (iii, comp_info; components_info.req)
|
foreach (iii, comp_info; components_info.req)
|
||||||
{
|
{
|
||||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||||
version (D_BetterC)
|
version (NoDRuntime)
|
||||||
assert(comp != ushort.max,
|
assert(comp != ushort.max,
|
||||||
"Can't register system \"" ~ SystemName
|
"Can't register system \"" ~ SystemName
|
||||||
~ "\" due to non existing component.");
|
~ "\" due to non existing component.");
|
||||||
|
|
@ -852,7 +854,7 @@ export struct EntityManager
|
||||||
foreach (iii, comp_info; components_info.excluded)
|
foreach (iii, comp_info; components_info.excluded)
|
||||||
{
|
{
|
||||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||||
version (D_BetterC)
|
version (NoDRuntime)
|
||||||
assert(comp != ushort.max,
|
assert(comp != ushort.max,
|
||||||
"Can't register system \"" ~ SystemName
|
"Can't register system \"" ~ SystemName
|
||||||
~ "\" due to non existing component.");
|
~ "\" due to non existing component.");
|
||||||
|
|
@ -864,7 +866,7 @@ export struct EntityManager
|
||||||
foreach (iii, comp_info; components_info.optional)
|
foreach (iii, comp_info; components_info.optional)
|
||||||
{
|
{
|
||||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||||
version (D_BetterC)
|
version (NoDRuntime)
|
||||||
assert(comp != ushort.max,
|
assert(comp != ushort.max,
|
||||||
"Can't register system \"" ~ SystemName
|
"Can't register system \"" ~ SystemName
|
||||||
~ "\" due to non existing component.");
|
~ "\" due to non existing component.");
|
||||||
|
|
@ -876,7 +878,7 @@ export struct EntityManager
|
||||||
foreach (iii, comp_info; components_info.readonly)
|
foreach (iii, comp_info; components_info.readonly)
|
||||||
{
|
{
|
||||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||||
version (D_BetterC)
|
version (NoDRuntime)
|
||||||
assert(comp != ushort.max,
|
assert(comp != ushort.max,
|
||||||
"Can't register system \"" ~ SystemName
|
"Can't register system \"" ~ SystemName
|
||||||
~ "\" due to non existing component.");
|
~ "\" due to non existing component.");
|
||||||
|
|
@ -888,7 +890,7 @@ export struct EntityManager
|
||||||
foreach (iii, comp_info; components_info.mutable)
|
foreach (iii, comp_info; components_info.mutable)
|
||||||
{
|
{
|
||||||
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||||
version (D_BetterC)
|
version (NoDRuntime)
|
||||||
assert(comp != ushort.max,
|
assert(comp != ushort.max,
|
||||||
"Can't register system \"" ~ SystemName
|
"Can't register system \"" ~ SystemName
|
||||||
~ "\" due to non existing component.");
|
~ "\" due to non existing component.");
|
||||||
|
|
@ -1198,7 +1200,7 @@ export struct EntityManager
|
||||||
{
|
{
|
||||||
ushort comp = external_dependencies_map.get(cast(const(char)[]) comp_info.type,
|
ushort comp = external_dependencies_map.get(cast(const(char)[]) comp_info.type,
|
||||||
ushort.max);
|
ushort.max);
|
||||||
version (D_BetterC)
|
version (NoDRuntime)
|
||||||
assert(comp != ushort.max,
|
assert(comp != ushort.max,
|
||||||
"Can't register system \"" ~ SystemName
|
"Can't register system \"" ~ SystemName
|
||||||
~ "\" due to non existing dependency.");
|
~ "\" due to non existing dependency.");
|
||||||
|
|
@ -1211,7 +1213,7 @@ export struct EntityManager
|
||||||
foreach (iii, comp_info; components_info.writableDeps)
|
foreach (iii, comp_info; components_info.writableDeps)
|
||||||
{
|
{
|
||||||
ushort comp = external_dependencies_map.get(cast(char[]) comp_info.type, ushort.max);
|
ushort comp = external_dependencies_map.get(cast(char[]) comp_info.type, ushort.max);
|
||||||
version (D_BetterC)
|
version (NoDRuntime)
|
||||||
assert(comp != ushort.max,
|
assert(comp != ushort.max,
|
||||||
"Can't register system \"" ~ SystemName
|
"Can't register system \"" ~ SystemName
|
||||||
~ "\" due to non existing dependency.");
|
~ "\" due to non existing dependency.");
|
||||||
|
|
@ -3355,6 +3357,16 @@ export struct EntityManager
|
||||||
export ~this() nothrow @nogc
|
export ~this() nothrow @nogc
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export void opAssign(ComponentInfo c)
|
||||||
|
{
|
||||||
|
size = c.size;
|
||||||
|
alignment = c.alignment;
|
||||||
|
init_data = c.init_data;
|
||||||
|
destroy_callback = c.destroy_callback;
|
||||||
|
create_callback = c.create_callback;
|
||||||
|
}
|
||||||
|
|
||||||
///Component size
|
///Component size
|
||||||
ushort size;
|
ushort size;
|
||||||
///Component data alignment
|
///Component data alignment
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@ import bubel.ecs.manager;
|
||||||
System contain data required to proper glue EntityManager with Systems.
|
System contain data required to proper glue EntityManager with Systems.
|
||||||
System callbacks:
|
System callbacks:
|
||||||
$(LIST
|
$(LIST
|
||||||
* void onUpdate(EntitesData);
|
* void onUpdate(EntitiesData);
|
||||||
* void onEnable() - called inside system.enable() function
|
* void onEnable() - called inside system.enable() function
|
||||||
* void onDisable() - called inside system.disable() function
|
* void onDisable() - called inside system.disable() function
|
||||||
* bool onBegin() - called inside manager.begin()
|
* bool onBegin() - called inside manager.begin()
|
||||||
* void onEnd() - called inside manager.end()
|
* void onEnd() - called inside manager.end()
|
||||||
* void onCreate() - called after registration inside registerSystem function
|
* void onCreate() - called after registration inside registerSystem function
|
||||||
* void onDestroy() - called during re-registration and inside manager destructor
|
* void onDestroy() - called during re-registration and inside manager destructor
|
||||||
* void onAddEntity(EntitesData) - called for every entity which are assigned to system (by adding new entity or changing its components)
|
* void onAddEntity(EntitiesData) - called for every entity which are assigned to system (by adding new entity or changing its components)
|
||||||
* void onRemoveEntity(EntitiesData) - called for every entity removed from system update process
|
* void onRemoveEntity(EntitiesData) - called for every entity removed from system update process
|
||||||
* void onChangeEntity(EntitiesData) - called for every entity which components are changed but it was previously assigned to system
|
* void onChangeEntity(EntitiesData) - called for every entity which components are changed but it was previously assigned to system
|
||||||
* void handleEvent(Entity*, Event) - called for every event supported by system
|
* void handleEvent(Entity*, Event) - called for every event supported by system
|
||||||
|
|
@ -108,7 +108,7 @@ struct System
|
||||||
package:
|
package:
|
||||||
|
|
||||||
///destory system. Dispose all data
|
///destory system. Dispose all data
|
||||||
void destroy() nothrow @nogc
|
export void destroy() nothrow @nogc
|
||||||
{
|
{
|
||||||
import bubel.ecs.std : Mallocator;
|
import bubel.ecs.std : Mallocator;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue