diff --git a/source/ecs/block_allocator.d b/source/ecs/block_allocator.d index 29b1fb3..d2272dd 100644 --- a/source/ecs/block_allocator.d +++ b/source/ecs/block_allocator.d @@ -12,7 +12,7 @@ struct BlockAllocator//(uint block_size, uint blocks_in_allocation) void* next_block = null; - void* getBlock() + void* getBlock() nothrow @nogc { if (next_block is null) allocBlock(); @@ -21,13 +21,13 @@ struct BlockAllocator//(uint block_size, uint blocks_in_allocation) return ret; } - void freeBlock(void* block) + void freeBlock(void* block) nothrow @nogc { *cast(void**)block = next_block; next_block = block; } - private void allocBlock() + private void allocBlock() nothrow @nogc { next_block = cast(void*) AlignedMallocator.instance.alignedAllocate( block_size * blocks_in_allocation, block_size); diff --git a/source/ecs/core.d b/source/ecs/core.d index 3095dbb..8f34fc0 100644 --- a/source/ecs/core.d +++ b/source/ecs/core.d @@ -10,7 +10,7 @@ static struct ECS __gshared ushort system_id; EntityManager.Job[] _ecs_jobs; - void __ecsInitialize() + void __ecsInitialize() nothrow @nogc { import std.experimental.allocator.mallocator; import std.experimental.allocator; diff --git a/source/ecs/entity.d b/source/ecs/entity.d index 854385a..3757d80 100644 --- a/source/ecs/entity.d +++ b/source/ecs/entity.d @@ -24,7 +24,7 @@ struct Entity /************************************************************************************************************************ *Update pointer to it in IDManager */ - void updateID() + void updateID() nothrow @nogc { EntityManager.instance.id_manager.update(this); } @@ -60,7 +60,7 @@ export struct EntityTemplate /************************************************************************************************************************ *Get specified component. If component doesn't exist function return null. */ - T* getComponent(T)() + T* getComponent(T)() nothrow @nogc { if(T.component_id >= info.tmpl_deltas.length)return null; return cast(T*)(entity_data.ptr + info.tmpl_deltas[T.component_id]); diff --git a/source/ecs/events.d b/source/ecs/events.d index ef81b6c..a6f6d36 100644 --- a/source/ecs/events.d +++ b/source/ecs/events.d @@ -70,13 +70,13 @@ struct EventManager block.index = cast(ushort)(aligned_index + Ev.sizeof); }*/ - void initialize(EntityManager m) + void initialize(EntityManager m) nothrow @nogc { allocator = BlockAllocator(events_block_size, events_blocks_in_allocation); manager = m; } - void sendEvent(Ev)(EntityID id, Ev event, uint thread_id = 0) + void sendEvent(Ev)(EntityID id, Ev event, uint thread_id = 0) nothrow @nogc { uint block_id = current_index+thread_id; @@ -110,7 +110,7 @@ struct EventManager block.count++; } - void swapCurrent() + void swapCurrent() nothrow @nogc { uint threads_count = cast(uint)manager.threads.length; if(current_index == 0)current_index = threads_count; @@ -136,7 +136,7 @@ struct EventManager } } - void clearEvents() + void clearEvents() nothrow @nogc { uint threads_count = cast(uint)manager.threads.length; foreach(ref event;events) @@ -173,7 +173,7 @@ struct EventManager process_events.current_block = null;*/ } - void allocateData(uint threads_count) + void allocateData(uint threads_count) nothrow @nogc { if(events) { diff --git a/source/ecs/hash_map.d b/source/ecs/hash_map.d index 2a62201..da317d2 100755 --- a/source/ecs/hash_map.d +++ b/source/ecs/hash_map.d @@ -11,7 +11,7 @@ private enum HASH_EMPTY = 0; private enum HASH_DELETED = 0x1; private enum HASH_FILLED_MARK = ulong(1) << 8 * ulong.sizeof - 1; -export ulong defaultHashFunc(T)(auto ref T t) { +export ulong defaultHashFunc(T)(auto ref T t) nothrow @nogc { static if (isIntegral!(T)) { return hashInt(t); } else { diff --git a/source/ecs/id_manager.d b/source/ecs/id_manager.d index 1e8ebad..07566d3 100644 --- a/source/ecs/id_manager.d +++ b/source/ecs/id_manager.d @@ -18,7 +18,7 @@ struct IDManager /************************************************************************************************************************ *Get new ID. */ - pragma(inline, false) EntityID getNewID() + pragma(inline, false) EntityID getNewID() nothrow @nogc { //uint current = m_next_id; //uint next;// = m_ids_array[m_next_id].next_id; @@ -35,13 +35,13 @@ begin: uint block_id = local_id >> 16; if (block_id >= m_blocks_count) { - add_mutex.lock(); + add_mutex.lock_nothrow(); if(block_id >= m_blocks_count) { m_blocks[m_blocks_count].alloc(); m_blocks_count++; } - add_mutex.unlock(); + add_mutex.unlock_nothrow(); } } @@ -79,7 +79,7 @@ begin: /************************************************************************************************************************ *Release ID. */ - void releaseID(EntityID id) + void releaseID(EntityID id) nothrow @nogc { Data* data = &m_ids_array[id.id]; if (data.counter != id.counter) @@ -96,7 +96,7 @@ begin: /************************************************************************************************************************ *Update pointer to entity. The purpose of this function is to ensure that pointer to entity is always correct. */ - void update(ref Entity entity) + void update(ref Entity entity) nothrow @nogc { if (entity.id.id >= cast(uint) m_ids_array.length) { @@ -112,7 +112,7 @@ begin: /************************************************************************************************************************ *Returns pointer to entity. */ - export Entity* getEntityPointer(EntityID id) + export Entity* getEntityPointer(EntityID id) nothrow @nogc { if (id.id >= m_ids_array.length) { @@ -137,13 +137,13 @@ begin: /************************************************************************************************************************ *Check if entity with specified ID exist. */ - export bool isExist(EntityID id) + export bool isExist(EntityID id) nothrow @nogc { Data* data = &m_ids_array[id.id]; return data.counter == id.counter; } - void initialize() + void initialize() nothrow @nogc { m_ids_array = Mallocator.instance.makeArray!Data(65536); m_free_stack = Mallocator.instance.makeArray!uint(65536); @@ -154,7 +154,7 @@ begin: add_mutex = Mallocator.instance.make!Mutex(); } - void optimize() + void optimize() nothrow @nogc { if(m_stack_top < -1)m_stack_top = -1; if(m_last_id > m_ids_array.length) @@ -183,13 +183,13 @@ begin: private static struct Block { - void alloc() + void alloc() nothrow @nogc { assert(data is null); data = Mallocator.instance.makeArray!Data(65536); } - void free() + void free() nothrow @nogc { assert(data !is null); Mallocator.instance.dispose(data); diff --git a/source/ecs/manager.d b/source/ecs/manager.d index 1215c5b..b8932f3 100644 --- a/source/ecs/manager.d +++ b/source/ecs/manager.d @@ -55,7 +55,7 @@ class EntityManager /************************************************************************************************************************ *Begin registering process. Every register function should be called between beginRegister() and endRegister(). */ - void beginRegister() + void beginRegister() nothrow @nogc { assert(!register_state, "beginRegister() can't be called twice before endRegister();"); register_state = true; @@ -730,12 +730,12 @@ class EntityManager Sys.system_id = system.id; } - System* getSystem(ushort id) + System* getSystem(ushort id) nothrow @nogc { return &systems[id]; } - Sys* getSystem(Sys)() + Sys* getSystem(Sys)() nothrow @nogc { return cast(Sys*) systems[Sys.system_id].m_system_pointer; } @@ -765,9 +765,10 @@ class EntityManager && is(ReturnType!(Comp.onDestroy) == void) && Parameters!(Comp.onDestroy).length == 0) { - static void callDestroy(void* pointer) + static void callDestroy(void* pointer) nothrow @nogc + { - (cast(Comp*) pointer).onDestroy(); + (cast(void delegate() nothrow @nogc)&(cast(Comp*) pointer).onDestroy)(); } info.destroy_callback = &callDestroy; @@ -832,7 +833,7 @@ class EntityManager /************************************************************************************************************************ *Same as "void update(int pass = 0)" but use pass name instead of id. */ - void update(const(char)[] pass_name) + void update(const(char)[] pass_name) nothrow @nogc { ushort pass = passes_map.get(pass_name, ushort.max); assert(pass != ushort.max); @@ -842,7 +843,7 @@ class EntityManager /************************************************************************************************************************ *Update systems. Should be called only between begin() and end(). */ - export void update(ushort pass = 0) + export void update(ushort pass = 0) nothrow @nogc { assert(!register_state); assert(pass < passes.length); @@ -863,14 +864,14 @@ class EntityManager /************************************************************************************************************************ *Same as "void updateMT(int pass = 0)" but use pass name instead of id. */ - void updateMT(const(char)[] pass_name) + void updateMT(const(char)[] pass_name) nothrow @nogc { ushort pass = passes_map.get(pass_name, ushort.max); assert(pass != ushort.max); updateMT(pass); } - void updateMT(ushort pass = 0) + void updateMT(ushort pass = 0) nothrow @nogc { assert(!register_state); assert(pass < passes.length); @@ -994,22 +995,22 @@ class EntityManager nextJob(); caller.job_group.jobs = sys.jobs[0 .. job_id]; - m_dispatch_jobs(caller.job_group); //sys.jobs[0 .. job_id]); + (cast(void delegate(JobGroup) nothrow @nogc)m_dispatch_jobs)(caller.job_group); //sys.jobs[0 .. job_id]); } } } - void setJobDispachFunc(void delegate(JobGroup) func) + void setJobDispachFunc(void delegate(JobGroup) func) nothrow @nogc { m_dispatch_jobs = func; } - static void alignNum(ref ushort num, ushort alignment) + static void alignNum(ref ushort num, ushort alignment) nothrow @nogc { num = cast(ushort)((num + alignment - 1) & (-cast(int) alignment)); //num += alignment - (num & (alignment - 1)); } - extern (C) static int compareUShorts(const void* a, const void* b) + extern (C) static int compareUShorts(const void* a, const void* b) nothrow @nogc { ushort _a = *cast(ushort*) a; ushort _b = *cast(ushort*) b; @@ -1132,7 +1133,7 @@ class EntityManager return info; } - export void addSystemCaller(ref EntityInfo entity, uint system_id) + export void addSystemCaller(ref EntityInfo entity, uint system_id) nothrow @nogc { System* system = &systems[system_id]; @@ -1176,7 +1177,7 @@ class EntityManager *params: *id = ID of entity */ - export Entity* getEntity(EntityID id) + export Entity* getEntity(EntityID id) nothrow @nogc { return cast(Entity*) id_manager.getEntityPointer(id); } @@ -1188,7 +1189,7 @@ class EntityManager *entity_id = ID of entity *del_ids = array of components IDs */ - export void removeComponents(EntityID entity_id, ushort[] del_ids) + export void removeComponents(EntityID entity_id, ushort[] del_ids) nothrow @nogc { ThreadData* data = &threads[thread_id]; uint num = cast(uint) del_ids.length; @@ -1414,7 +1415,7 @@ class EntityManager *entity_id = ID of entity to remove *tmpl = pointer entity template allocated by EntityManager. */ - void addComponents(Components...)(const EntityID entity_id, Components comps) + void addComponents(Components...)(const EntityID entity_id, Components comps) nothrow @nogc { const uint num = Components.length; Entity* entity = id_manager.getEntityPointer(entity_id); @@ -1505,7 +1506,7 @@ class EntityManager /************************************************************************************************************************ *Return block with free space for selected EntityInfo. */ - private EntitiesBlock* findBlockWithFreeSpace(EntityInfo* info) + private EntitiesBlock* findBlockWithFreeSpace(EntityInfo* info) nothrow @nogc { EntitiesBlock* block = info.last_block; @@ -1585,7 +1586,7 @@ class EntityManager threads[thread_id].entities_to_remove.add(id); } - private void __removeEntity(EntityID id) + private void __removeEntity(EntityID id) nothrow @nogc { //get entity and block meta data pointers Entity* entity = id_manager.getEntityPointer(id); @@ -1598,7 +1599,7 @@ class EntityManager } private void removeEntityNoID(Entity* entity, EntitiesBlock* block, - bool call_destructors = false) + bool call_destructors = false) nothrow @nogc { //pos is Entity number in block void* data_begin = block.dataBegin(); @@ -1662,7 +1663,7 @@ class EntityManager *params: *pointer = pointer to any data of entity (i.e. component data pointer) */ - export EntitiesBlock* getMetaData(const void* pointer) + export EntitiesBlock* getMetaData(const void* pointer) nothrow @nogc { return cast(EntitiesBlock*)(cast(size_t) pointer & (~cast(size_t)(page_size - 1))); } @@ -1726,7 +1727,7 @@ class EntityManager } } - private void removeEntities() + private void removeEntities() nothrow @nogc { foreach (i, ref thread; threads) { @@ -1738,7 +1739,7 @@ class EntityManager } } - void updateEvents() + void updateEvents() nothrow @nogc { bool empty = true; //uint index = event_manager. @@ -1775,7 +1776,7 @@ class EntityManager foreach(caller; events[i].callers) { call_data.system_pointer = caller.system.m_system_pointer; - (cast(void function(ref EventCallData))caller.callback)(call_data); + (cast(void function(ref EventCallData) nothrow @nogc)caller.callback)(call_data); } event_pointer += events[i].size; } @@ -1834,21 +1835,21 @@ class EntityManager //event_manager.clearEvents(); } - private void getThreadID() + private void getThreadID() nothrow @nogc { if (m_thread_id_func) - thread_id = m_thread_id_func(); + thread_id = (cast(uint delegate() nothrow @nogc)m_thread_id_func)(); else thread_id = 0; } - void sendEvent(Ev)(EntityID id, Ev event) + void sendEvent(Ev)(EntityID id, Ev event) nothrow @nogc { event_manager.sendEvent(id, event, thread_id); } /*private */ - void generateDependencies() + void generateDependencies() nothrow @nogc { foreach (pass_id, pass; passes) { @@ -2009,7 +2010,7 @@ class EntityManager ///Initialization data ubyte[] init_data; ///Pointer to component destroy callback - void function(void* pointer) destroy_callback; + void function(void* pointer) nothrow @nogc destroy_callback; } struct EventCaller @@ -2040,7 +2041,7 @@ class EntityManager struct EntityInfo { ///Returns number of blocks - uint blocksCount() + uint blocksCount() nothrow @nogc { if (last_block) return last_block.id + 1; @@ -2049,7 +2050,7 @@ class EntityManager } ///Returns number of non empty blocks - uint nonEmptyBlocksCount() + uint nonEmptyBlocksCount() nothrow @nogc { EntitiesBlock* block = last_block; while (1) @@ -2094,7 +2095,7 @@ class EntityManager struct EntitiesBlock { ///return distance (in bytes) from begin of block to data - uint dataDelta() + uint dataDelta() nothrow @nogc { ushort dif = EntitiesBlock.sizeof; alignNum(dif, type_info.alignment); @@ -2102,7 +2103,7 @@ class EntityManager } ///return pointer to first element in block - export void* dataBegin() + export void* dataBegin() nothrow @nogc { ushort dif = EntitiesBlock.sizeof; return cast(void*)&this + dif; @@ -2134,7 +2135,7 @@ class EntityManager */ struct CallData { - void update() + void update() nothrow @nogc { (cast(SytemFuncType) system.m_update)(this); } @@ -2160,7 +2161,7 @@ class EntityManager { CallData[] callers; - void execute() + void execute() nothrow @nogc { EntityManager.instance.getThreadID(); foreach (ref caller; callers) @@ -2181,7 +2182,7 @@ class EntityManager struct SystemCaller { - ~this() + ~this() nothrow @nogc { if (dependencies) { @@ -2209,7 +2210,7 @@ class EntityManager struct UpdatePass { - ~this() + ~this() nothrow @nogc { assert(name); if (name) @@ -2230,7 +2231,7 @@ class EntityManager //Vector!(SystemCaller*) system_callers; - alias SytemFuncType = void function(ref EntityManager.CallData data); + alias SytemFuncType = void function(ref EntityManager.CallData data) nothrow @nogc; //alias sendSelfEvent = instance.event_manager.sendSelfEvent; @@ -2278,7 +2279,7 @@ class EntityManager Vector!(Block*) blocks; uint id; - void clear() + void clear() nothrow @nogc { if (blocks.length > 0) foreach (block; blocks[0 .. id + 1]) @@ -2289,7 +2290,7 @@ class EntityManager //blocks.clear(); } - CallData[] getCallData(uint num) + CallData[] getCallData(uint num) nothrow @nogc { if (blocks.length == 0) { diff --git a/source/ecs/string_intern.d b/source/ecs/string_intern.d index 49dc21b..ed7820e 100644 --- a/source/ecs/string_intern.d +++ b/source/ecs/string_intern.d @@ -9,6 +9,7 @@ import std.traits : Parameters; private __gshared static HashMap!(const(char)[], StringIntern) gStringInterns; struct StringIntern { + private const(char)* strPtr; this(const(char)[] fromStr) { diff --git a/source/ecs/system.d b/source/ecs/system.d index 9c61591..d21e75a 100644 --- a/source/ecs/system.d +++ b/source/ecs/system.d @@ -12,7 +12,7 @@ struct System /************************************************************************************************************************ *Check if system is enabled. */ - export bool enabled() + export bool enabled() nothrow @nogc { return m_enabled; } @@ -20,27 +20,27 @@ struct System /************************************************************************************************************************ *Enable system. If actually it is enabled function do nothing. */ - export void enable() + export void enable() nothrow @nogc { if (!m_enabled && m_enable) - (cast(void function(void*))m_enable)(m_system_pointer); + (cast(void function(void*) nothrow @nogc)m_enable)(m_system_pointer); m_enabled = true; } /************************************************************************************************************************ *Disable system. If actually it is disabled function do nothing. */ - export void disable() + export void disable() nothrow @nogc { if (m_enabled && m_disable) - (cast(void function(void*))m_disable)(m_system_pointer); + (cast(void function(void*) nothrow @nogc)m_disable)(m_system_pointer); m_enabled = false; } /************************************************************************************************************************ *Get system priority. */ - export int priority() + export int priority() nothrow @nogc { return m_priority; } @@ -48,7 +48,7 @@ struct System /************************************************************************************************************************ *Get system priority. */ - export bool execute() + export bool execute() nothrow @nogc { return m_execute; } @@ -56,7 +56,7 @@ struct System /************************************************************************************************************************ *Get system priority. */ - export ushort id() + export ushort id() nothrow @nogc { return m_id; } diff --git a/tests/tests.d b/tests/tests.d index 7f9f72b..1d48f4b 100644 --- a/tests/tests.d +++ b/tests/tests.d @@ -284,7 +284,7 @@ struct TestSystem2 int main() { - void dispatch(EntityManager.JobGroup jobs) + void dispatch(EntityManager.JobGroup jobs) nothrow @nogc { foreach(job;jobs.jobs) {