bubel-ecs/source/ecs/system.d
Mergul 5dd24b6462 -Systems, Components and Events now must have proper mixin. Mixins are located in ecs.core module. (i.e. mixin ECS.Component)
-Multithreading support:
 *multithreaded update - updateMT(), function generates jobs to execute
 *added dispatch callback function to dispatch generated jobs (setJobDispachFunc)
 *added getID callback for get thread ID by EntityManager
-added Job structure. Job has one function "execute()".
-calling partial info update (required to multithreading)
-multithreaded removeEntity, addCompoenents, removeComponents. Every thread has own data and remove/change lists.
-multithreaded addEntity (WIP)
-fixed issue with duplicating components
-simpler and faster "findBlockWithFreeSpace" function
-CallDataAllocator, allocator for CallDatas (used for Jobs)
-fixed some bugs/issues
2018-10-14 17:00:53 +02:00

94 lines
2.6 KiB
D

module ecs.system;
import ecs.entity;
import ecs.manager;
/************************************************************************************************************************
*System contain data required to proper glue EntityManager with Systems.
*/
struct System
{
/************************************************************************************************************************
*Check if system is enabled.
*/
export bool enabled()
{
return m_enabled;
}
/************************************************************************************************************************
*Enable system. If actually it is enabled function do nothing.
*/
export void enable()
{
if (!m_enabled && m_enable)
(cast(void function(void*))m_enable)(m_system_pointer);
m_enabled = true;
}
/************************************************************************************************************************
*Disable system. If actually it is disabled function do nothing.
*/
export void disable()
{
if (m_enabled && m_disable)
(cast(void function(void*))m_disable)(m_system_pointer);
m_enabled = false;
}
/************************************************************************************************************************
*Get system priority.
*/
export int priority()
{
return m_priority;
}
package:
///should system update and catch events?
bool m_enabled = false;
///system priority
int m_priority;
///pointer to system implementation
void* m_system_pointer;
///system name
const (char)[] name;
///required components
ushort[] m_components;
///absent components
ushort[] m_absent_components;
///optional components
ushort[] m_optional_components;
EntityManager.Job[] jobs;
//void function(ref EntityManager.CallData data) m_update;
void* m_update; ///workaroud for DMD bug with upper line
/*void function(void* system_pointer) m_enable;
void function(void* system_pointer) m_disable;
void function(void* system_pointer) m_create;
void function(void* system_pointer) m_destroy;
void function(void* system_pointer) m_begin;
void function(void* system_pointer) m_end;*/
void* m_enable;
void* m_disable;
void* m_create;
void* m_destroy;
void* m_begin;
void* m_end;
//void function(ref EntityManager.CallData data) m_initialize;
//void function(ref EntityManager.CallData data) m_deinitilize;
void* m_initialize;
void* m_deinitilize;
}