-code foramtted with dfmt
This commit is contained in:
parent
280d7b8ec4
commit
d118adc028
2 changed files with 128 additions and 106 deletions
|
|
@ -86,7 +86,8 @@ class EntityManager
|
||||||
|
|
||||||
foreach (ref info; &entities_infos.byValue)
|
foreach (ref info; &entities_infos.byValue)
|
||||||
{
|
{
|
||||||
if(info.systems)Mallocator.instance.dispose(info.systems);
|
if (info.systems)
|
||||||
|
Mallocator.instance.dispose(info.systems);
|
||||||
info.systems = Mallocator.instance.makeArray!bool(systems.length);
|
info.systems = Mallocator.instance.makeArray!bool(systems.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,8 +140,10 @@ class EntityManager
|
||||||
Mallocator.instance.dispose(info.callers);
|
Mallocator.instance.dispose(info.callers);
|
||||||
}
|
}
|
||||||
|
|
||||||
ushort[] event_callers = (cast(ushort*)alloca(ushort.sizeof * events.length))[0..events.length];
|
ushort[] event_callers = (cast(ushort*) alloca(ushort.sizeof * events.length))[0
|
||||||
foreach(ref caller; event_callers)caller = 0;
|
.. events.length];
|
||||||
|
foreach (ref caller; event_callers)
|
||||||
|
caller = 0;
|
||||||
|
|
||||||
foreach (ref system; systems)
|
foreach (ref system; systems)
|
||||||
{
|
{
|
||||||
|
|
@ -155,7 +158,8 @@ class EntityManager
|
||||||
info.callers = Mallocator.instance.makeArray!(EventCaller)(event_callers[i]);
|
info.callers = Mallocator.instance.makeArray!(EventCaller)(event_callers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(ref caller; event_callers)caller = 0;
|
foreach (ref caller; event_callers)
|
||||||
|
caller = 0;
|
||||||
|
|
||||||
foreach (ref system; systems)
|
foreach (ref system; systems)
|
||||||
{
|
{
|
||||||
|
|
@ -640,8 +644,8 @@ class EntityManager
|
||||||
|
|
||||||
//pragma(msg,genFillInputData);
|
//pragma(msg,genFillInputData);
|
||||||
|
|
||||||
static void fillInputData(ref Sys.EntitiesData input_data, EntityInfo* info, EntitiesBlock* block,
|
static void fillInputData(ref Sys.EntitiesData input_data, EntityInfo* info,
|
||||||
uint offset, uint entities_count, System* system)
|
EntitiesBlock* block, uint offset, uint entities_count, System* system)
|
||||||
{
|
{
|
||||||
mixin(genFillInputData());
|
mixin(genFillInputData());
|
||||||
}
|
}
|
||||||
|
|
@ -845,8 +849,7 @@ class EntityManager
|
||||||
}
|
}
|
||||||
|
|
||||||
static if (hasMember!(Comp, "onCreate") && isFunction!(Comp.onCreate)
|
static if (hasMember!(Comp, "onCreate") && isFunction!(Comp.onCreate)
|
||||||
&& is(ReturnType!(Comp.onCreate) == void)
|
&& is(ReturnType!(Comp.onCreate) == void) && Parameters!(Comp.onCreate).length == 0)
|
||||||
&& Parameters!(Comp.onCreate).length == 0)
|
|
||||||
{
|
{
|
||||||
static void callCreate(void* pointer) nothrow @nogc
|
static void callCreate(void* pointer) nothrow @nogc
|
||||||
{
|
{
|
||||||
|
|
@ -1210,7 +1213,8 @@ class EntityManager
|
||||||
//if(system.m_entity_added || system.m_entity_removed)info.systems[system.id] = true;
|
//if(system.m_entity_added || system.m_entity_removed)info.systems[system.id] = true;
|
||||||
if (system.m_update is null)
|
if (system.m_update is null)
|
||||||
{
|
{
|
||||||
if(system.m_entity_added || system.m_entity_removed)connectListenerToEntityInfo(*info,cast(uint)i);
|
if (system.m_entity_added || system.m_entity_removed)
|
||||||
|
connectListenerToEntityInfo(*info, cast(uint) i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
addSystemCaller(*info, cast(uint) i);
|
addSystemCaller(*info, cast(uint) i);
|
||||||
|
|
@ -1236,8 +1240,10 @@ class EntityManager
|
||||||
info.remove_listeners = null;
|
info.remove_listeners = null;
|
||||||
}
|
}
|
||||||
//allocate local data
|
//allocate local data
|
||||||
ushort[] tmp_add = (cast(ushort*)alloca(systems.length*ushort.sizeof))[0..systems.length];
|
ushort[] tmp_add = (cast(ushort*) alloca(systems.length * ushort.sizeof))[0
|
||||||
ushort[] tmp_rem = (cast(ushort*)alloca(systems.length*ushort.sizeof))[0..systems.length];
|
.. systems.length];
|
||||||
|
ushort[] tmp_rem = (cast(ushort*) alloca(systems.length * ushort.sizeof))[0
|
||||||
|
.. systems.length];
|
||||||
int add_len = 0;
|
int add_len = 0;
|
||||||
int rem_len = 0;
|
int rem_len = 0;
|
||||||
//assign listeners to lists
|
//assign listeners to lists
|
||||||
|
|
@ -1253,7 +1259,8 @@ class EntityManager
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < add_len; j++)
|
for (j = 0; j < add_len; j++)
|
||||||
{
|
{
|
||||||
if(systems[i].priority > systems[tmp_add[j]].priority)break;
|
if (systems[i].priority > systems[tmp_add[j]].priority)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
add_len++;
|
add_len++;
|
||||||
//move elements after new listener
|
//move elements after new listener
|
||||||
|
|
@ -1271,7 +1278,8 @@ class EntityManager
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < rem_len; j++)
|
for (j = 0; j < rem_len; j++)
|
||||||
{
|
{
|
||||||
if(systems[i].priority > systems[tmp_rem[j]].priority)break;
|
if (systems[i].priority > systems[tmp_rem[j]].priority)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
rem_len++;
|
rem_len++;
|
||||||
//move elements after new listener
|
//move elements after new listener
|
||||||
|
|
@ -1472,7 +1480,8 @@ class EntityManager
|
||||||
{
|
{
|
||||||
if (!info.systems[listener])
|
if (!info.systems[listener])
|
||||||
{
|
{
|
||||||
callAddEntityListener(&systems[listener],new_info,new_block,new_block.entities_count,new_block.entities_count+1);
|
callAddEntityListener(&systems[listener], new_info, new_block,
|
||||||
|
new_block.entities_count, new_block.entities_count + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1645,7 +1654,8 @@ class EntityManager
|
||||||
{
|
{
|
||||||
if (!info.systems[listener])
|
if (!info.systems[listener])
|
||||||
{
|
{
|
||||||
callAddEntityListener(&systems[listener],new_info,new_block,new_block.entities_count,new_block.entities_count+1);
|
callAddEntityListener(&systems[listener], new_info, new_block,
|
||||||
|
new_block.entities_count, new_block.entities_count + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1738,8 +1748,8 @@ class EntityManager
|
||||||
|
|
||||||
if (components[comp].create_callback)
|
if (components[comp].create_callback)
|
||||||
{
|
{
|
||||||
components[comp].create_callback(cast(
|
components[comp].create_callback(
|
||||||
void*) block + info.deltas[comp] + id * components[comp].size);
|
cast(void*) block + info.deltas[comp] + id * components[comp].size);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1984,7 +1994,8 @@ class EntityManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callAddEntityListener(System* system, EntityInfo* info, EntitiesBlock* block, int begin, int end) @nogc nothrow
|
private void callAddEntityListener(System* system, EntityInfo* info,
|
||||||
|
EntitiesBlock* block, int begin, int end) @nogc nothrow
|
||||||
{
|
{
|
||||||
ListenerCallData data;
|
ListenerCallData data;
|
||||||
data.system = system;
|
data.system = system;
|
||||||
|
|
@ -1994,7 +2005,8 @@ class EntityManager
|
||||||
(cast(void function(ref ListenerCallData) nothrow @nogc) system.m_entity_added)(data);
|
(cast(void function(ref ListenerCallData) nothrow @nogc) system.m_entity_added)(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callRemoveEntityListeners(EntityInfo* info, EntitiesBlock* block, int begin, int end) @nogc nothrow
|
private void callRemoveEntityListeners(EntityInfo* info, EntitiesBlock* block, int begin,
|
||||||
|
int end) @nogc nothrow
|
||||||
{
|
{
|
||||||
foreach (listener; info.remove_listeners)
|
foreach (listener; info.remove_listeners)
|
||||||
{
|
{
|
||||||
|
|
@ -2003,7 +2015,8 @@ class EntityManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callRemoveEntityListener(System* system, EntityInfo* info, EntitiesBlock* block, int begin, int end) @nogc nothrow
|
private void callRemoveEntityListener(System* system, EntityInfo* info,
|
||||||
|
EntitiesBlock* block, int begin, int end) @nogc nothrow
|
||||||
{
|
{
|
||||||
ListenerCallData data;
|
ListenerCallData data;
|
||||||
data.system = system;
|
data.system = system;
|
||||||
|
|
@ -2057,14 +2070,18 @@ class EntityManager
|
||||||
{
|
{
|
||||||
event_manager.swapCurrent();
|
event_manager.swapCurrent();
|
||||||
uint current_index;
|
uint current_index;
|
||||||
if(event_manager.current_index == 0)current_index = cast(uint)threads.length;
|
if (event_manager.current_index == 0)
|
||||||
else current_index = 0;
|
current_index = cast(uint) threads.length;
|
||||||
|
else
|
||||||
|
current_index = 0;
|
||||||
foreach (i, event; event_manager.events)
|
foreach (i, event; event_manager.events)
|
||||||
{
|
{
|
||||||
foreach(first_block;event.first_blocks[current_index .. current_index + threads.length])
|
foreach (first_block; event.first_blocks[current_index
|
||||||
|
.. current_index + threads.length])
|
||||||
{
|
{
|
||||||
EventManager.EventBlock* block = first_block;
|
EventManager.EventBlock* block = first_block;
|
||||||
if(block)empty = false;
|
if (block)
|
||||||
|
empty = false;
|
||||||
while (block)
|
while (block)
|
||||||
{
|
{
|
||||||
EventCallData call_data;
|
EventCallData call_data;
|
||||||
|
|
@ -2077,14 +2094,18 @@ class EntityManager
|
||||||
call_data.block = getMetaData(entity);
|
call_data.block = getMetaData(entity);
|
||||||
|
|
||||||
static if (EntityID.sizeof == 8)
|
static if (EntityID.sizeof == 8)
|
||||||
call_data.id = cast(ushort)((cast(void*)entity - call_data.block.dataBegin()) >> 3);
|
call_data.id = cast(ushort)(
|
||||||
|
(cast(void*) entity - call_data.block.dataBegin()) >> 3);
|
||||||
else
|
else
|
||||||
call_data.id = cast(ushort)((cast(void*)entity - call_data.block.dataBegin()) / EntityID.sizeof);
|
call_data.id = cast(ushort)(
|
||||||
|
(cast(void*) entity - call_data.block.dataBegin()) / EntityID
|
||||||
|
.sizeof);
|
||||||
|
|
||||||
foreach (caller; events[i].callers)
|
foreach (caller; events[i].callers)
|
||||||
{
|
{
|
||||||
call_data.system_pointer = caller.system.m_system_pointer;
|
call_data.system_pointer = caller.system.m_system_pointer;
|
||||||
(cast(void function(ref EventCallData) nothrow @nogc)caller.callback)(call_data);
|
(cast(void function(ref EventCallData) nothrow @nogc) caller
|
||||||
|
.callback)(call_data);
|
||||||
}
|
}
|
||||||
event_pointer += events[i].size;
|
event_pointer += events[i].size;
|
||||||
}
|
}
|
||||||
|
|
@ -2092,7 +2113,8 @@ class EntityManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(empty)break;
|
if (empty)
|
||||||
|
break;
|
||||||
empty = true;
|
empty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue