Demos #10

Merged
Mergul merged 39 commits from Demos into master 2020-05-28 18:48:45 +02:00
3 changed files with 21 additions and 40 deletions
Showing only changes of commit 46aba822d0 - Show all commits

View file

@ -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;

View file

@ -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;

View file

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