-almost every funtion is marked as @nogc and nothrow (only problem with HashMap)

This commit is contained in:
Mergul 2018-11-02 16:36:38 +01:00
parent fef55bd790
commit 204ce9dc79
10 changed files with 74 additions and 72 deletions

View file

@ -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)
{