From 46aba822d0a3024d7177261b18844e130a2ff65a Mon Sep 17 00:00:00 2001 From: Mergul Date: Wed, 6 May 2020 10:55:40 +0200 Subject: [PATCH] Improved documentation and removed some old code --- source/bubel/ecs/id_manager.d | 27 --------------------------- source/bubel/ecs/simple_vector.d | 8 ++++++++ source/bubel/ecs/system.d | 26 +++++++++++++------------- 3 files changed, 21 insertions(+), 40 deletions(-) diff --git a/source/bubel/ecs/id_manager.d b/source/bubel/ecs/id_manager.d index c8eadec..4c3a2c3 100644 --- a/source/bubel/ecs/id_manager.d +++ b/source/bubel/ecs/id_manager.d @@ -17,10 +17,6 @@ struct IDManager */ pragma(inline, false) EntityID getNewID() nothrow @nogc { - //uint current = m_next_id; - //uint next;// = m_ids_array[m_next_id].next_id; -//begin: - //if (current == uint.max)//> m_last_id) int current = m_stack_top.atomicOp!"-="(1) + 1; if(current < 0) { @@ -48,29 +44,11 @@ struct IDManager return id; } - - //current += 1; uint index = m_free_stack[current]; EntityID id; id.id = index; id.counter = m_ids_array[index].counter; - //current = m_ids_array[index].next_id; return id; - - /*next = m_ids_array[current].next_id; - if(cas(&m_next_id,current,next)) - { - EntityID id; - id.id = current; - id.counter = m_ids_array[current].counter; - m_next_id = m_ids_array[current].next_id; - return id; - } - else - { - current = next; - goto begin; - }*/ } /************************************************************************************************************************ @@ -82,9 +60,7 @@ struct IDManager if (data.counter != id.counter) return; data.counter++; - //data.next_id = m_next_id; data.entity = null; - ///m_next_id = id.id; m_stack_top.atomicOp!"+="(1); m_free_stack[m_stack_top] = id.id; @@ -241,13 +217,10 @@ struct IDManager private: Mutex* add_mutex; - //shared uint m_next_id = 0; - //shared uint m_last_id = 0; Data[] m_ids_array = null; uint m_blocks_count = 0; Block[] m_blocks; - //shared int m_stack_top = -1; uint[] m_free_stack = null; align(64) shared uint m_last_id = 0; diff --git a/source/bubel/ecs/simple_vector.d b/source/bubel/ecs/simple_vector.d index 28d4707..1de026e 100644 --- a/source/bubel/ecs/simple_vector.d +++ b/source/bubel/ecs/simple_vector.d @@ -4,11 +4,16 @@ import bubel.ecs.std; //import core.stdc.string; +/************************************************************************************************************************ +Vector for byte data. Simpler than standard template-based implementation designed for better performance. \ +Rellocates 1024 elements at once instead of doubling size. +*/ struct SimpleVector { @disable this(this); + ///Add element to vector void add(ubyte el) nothrow @nogc { while(used >= data.length) @@ -19,6 +24,7 @@ struct SimpleVector data[used++] = el; } + ///Add array of elements to vector void add(ubyte[] el) nothrow @nogc { while(used + el.length >= data.length) @@ -30,6 +36,7 @@ struct SimpleVector used += el.length; } + ///Return vector length size_t length() nothrow @nogc { return used; @@ -55,6 +62,7 @@ struct SimpleVector return used; } + ///set vector length to 0 void clear() nothrow @nogc { used = 0; diff --git a/source/bubel/ecs/system.d b/source/bubel/ecs/system.d index 6452e6c..7343831 100644 --- a/source/bubel/ecs/system.d +++ b/source/bubel/ecs/system.d @@ -14,16 +14,16 @@ System contain data required to proper glue EntityManager with Systems. System callbacks: $(LIST * void onUpdate(EntitesData); - * void onEnable() - * void onDisable(); - * bool onBegin(); - * void onEnd(); - * void onCreate() - * void onDestroy(); - * void onAddEntity(EntitesData); - * void onRemoveEntity(EntitiesData); - * void onChangeEntity(EntitiesData); - * void handleEvent(Entity*, Event); + * void onEnable() - called inside system.enable() function + * void onDisable() - called inside system.disable() function + * bool onBegin() - called inside manager.begin() + * void onEnd() - called inside manager.end() + * void onCreate() - called after registration inside registerSystem function + * 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 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 handleEvent(Entity*, Event) - called for every event supported by system ) */ struct System @@ -66,15 +66,15 @@ struct System } /************************************************************************************************************************ - Get system priority. + Get if system will be executed during current frame. Should be checked after manager.begin(). Its value is setted as result of manager.onBegin() callback. */ - export bool execute() nothrow @nogc + export bool willExecute() nothrow @nogc { return m_execute; } /************************************************************************************************************************ - Get system priority. + Get system id. */ export ushort id() nothrow @nogc {