Compare commits
7 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0002852303 | |||
| 6e45e7b053 | |||
| 59db920a2e | |||
| bbb8144f34 | |||
| 24ef63d505 | |||
| 70a5388820 | |||
| 0d08b8532a |
14 changed files with 2309 additions and 567 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -12,4 +12,8 @@
|
|||
!compile_wasm.py
|
||||
!compile_android.py
|
||||
!.gitlab-ci.yml
|
||||
!LICENSE
|
||||
!LICENSE
|
||||
!c-api
|
||||
!c-api/*.h
|
||||
!c-api/*.d
|
||||
!c-api/*.c
|
||||
|
|
@ -56,7 +56,7 @@ coverage_test_dmd:
|
|||
- mkdir reports
|
||||
- binaries/dmd_unittest_cov
|
||||
after_script:
|
||||
- bash <(curl -s https://codecov.io/bash) -s reports -t 1a0c0169-a721-4085-8252-fed4755dcd8c
|
||||
- bash <(curl -s https://codecov.io/bash) -s reports -t df87b1d8-85f4-4584-96e3-1315d27ec2c5
|
||||
|
||||
wasm:
|
||||
stage: build_wasm
|
||||
|
|
|
|||
207
c-api/becs.h
Normal file
207
c-api/becs.h
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
#ifndef __BECS__
|
||||
#define __BECS__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdalign.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct BECSSystem
|
||||
{
|
||||
|
||||
}BECSSystem;
|
||||
|
||||
typedef struct BECSArray
|
||||
{
|
||||
size_t size;
|
||||
void* ptr;
|
||||
}BECSArray;
|
||||
|
||||
typedef struct EntityID
|
||||
{
|
||||
///Index to entity in IDManager.
|
||||
uint32_t id;
|
||||
///Counter required for reusing ID.
|
||||
uint32_t counter;
|
||||
}EntityID;
|
||||
|
||||
typedef struct Entity
|
||||
{
|
||||
///Entity ID.
|
||||
EntityID id;
|
||||
}Entity;
|
||||
|
||||
typedef struct ComponentRef
|
||||
{
|
||||
///pointer to component
|
||||
void* ptr;
|
||||
///component index
|
||||
uint16_t id;
|
||||
}ComponentRef;
|
||||
|
||||
typedef ComponentRef EventRef;
|
||||
|
||||
typedef struct BECSComponentInfo
|
||||
{
|
||||
///Component size
|
||||
uint16_t size;
|
||||
///Component data alignment
|
||||
uint16_t alignment;
|
||||
///Initialization data
|
||||
BECSArray init_data;
|
||||
///Pointer to component destroy callback
|
||||
void* destroy_callback;
|
||||
///Pointer to component create callback
|
||||
void* create_callback;
|
||||
//void* create_callback;
|
||||
}BECSComponentInfo;
|
||||
|
||||
typedef struct BECSEventRegisterInfo
|
||||
{
|
||||
///Component size
|
||||
uint16_t size;
|
||||
///Component data alignment
|
||||
uint16_t alignment;
|
||||
}BECSEventRegisterInfo;
|
||||
|
||||
typedef struct EntityTemplate
|
||||
{
|
||||
/*///Entity components data
|
||||
BECSArray entity_data;
|
||||
///Pointer to entity type info.
|
||||
void* info;*/
|
||||
}EntityTemplate;
|
||||
|
||||
enum BECSSystemComponentAttribute
|
||||
{
|
||||
required = 0,
|
||||
optional = 1,
|
||||
excluded = 2
|
||||
};
|
||||
|
||||
enum BECSSystemComponentAccess
|
||||
{
|
||||
writable = 0,
|
||||
readonly = 1
|
||||
};
|
||||
|
||||
typedef struct BECSSystemComponentInfo
|
||||
{
|
||||
uint16_t id;
|
||||
enum BECSSystemComponentAttribute attribute;
|
||||
enum BECSSystemComponentAccess access;
|
||||
}BECSSystemComponentInfo;
|
||||
|
||||
///C-API structure conatin only subset of real data which can be accessed directly. Component arrays can be retrived using function calls.
|
||||
typedef struct BECSListenerCallData
|
||||
{
|
||||
uint32_t count;
|
||||
void* context;
|
||||
}BECSListenerCallData;
|
||||
|
||||
///C-API structure conatin only subset of real data which can be accessed directly. Component arrays can be retrived using function calls.
|
||||
typedef struct BECSSystemCallData
|
||||
{
|
||||
uint32_t count;
|
||||
uint32_t thread_id;
|
||||
uint32_t job_id;
|
||||
void* context;
|
||||
}BECSSystemCallData;
|
||||
|
||||
///C-API structure conatin only subset of real data which can be accessed directly. Component arrays can be retrived using function calls.
|
||||
typedef struct BECSEventCallData
|
||||
{
|
||||
Entity* entity;
|
||||
void* event;
|
||||
void* context;
|
||||
}BECSEventCallData;
|
||||
|
||||
typedef struct BECSEventCallback
|
||||
{
|
||||
uint16_t id;
|
||||
void (*callback)(BECSEventCallData* data);
|
||||
}BECSEventCallback;
|
||||
|
||||
typedef struct BECSSystemRegisterInfo
|
||||
{
|
||||
uint32_t pass_id;
|
||||
int32_t priority;
|
||||
uint32_t max_jobs;
|
||||
|
||||
size_t components_count;
|
||||
BECSSystemComponentInfo* components;
|
||||
|
||||
size_t event_handlers_count;
|
||||
BECSEventCallback* event_handlers;
|
||||
|
||||
size_t system_size;
|
||||
void* init_data;
|
||||
|
||||
void (*on_update)(BECSSystemCallData* call_data);
|
||||
void (*on_create)(void* system_pointer);
|
||||
void (*on_destroy)(void* system_pointer);
|
||||
void (*on_enable)(void* system_pointer);
|
||||
void (*on_disable)(void* system_pointer);
|
||||
char (*on_begin)(void* system_pointer);
|
||||
void (*on_end)(void* system_pointer);
|
||||
void (*on_add_entity)(BECSListenerCallData*);
|
||||
void (*on_remove_entity)(BECSListenerCallData*);
|
||||
void (*on_change_entity)(BECSListenerCallData*);
|
||||
void (*filter_entity)(void* system_pointer, void* info);
|
||||
}BECSSystemRegisterInfo;
|
||||
|
||||
void becsInitialize();
|
||||
void becsDestroy();
|
||||
|
||||
void becsBeginRegister();
|
||||
void becsEndRegister();
|
||||
|
||||
void becsBegin();
|
||||
void becsEnd();
|
||||
void becsCommit();
|
||||
|
||||
void becsUpdate(uint16_t pass_id);
|
||||
void becsUpdateMT(uint16_t pass_id);
|
||||
|
||||
uint16_t becsRegisterComponent(const char* name, BECSComponentInfo info);
|
||||
uint16_t becsRegisterEvent(const char* name, BECSEventRegisterInfo info);
|
||||
uint16_t becsRegisterSystem(const char* name, BECSSystemRegisterInfo info);
|
||||
uint16_t becsRegisterPass(const char* name);
|
||||
|
||||
Entity* becsAddEntity(EntityTemplate* template);
|
||||
Entity* becsAddEntityCopy(EntityID id);
|
||||
void becsRemoveEntity(EntityID id);
|
||||
|
||||
Entity* becsGetEntity(EntityID id);
|
||||
|
||||
void becsAddComponents(const EntityID entity_id, size_t length, ComponentRef* comps);
|
||||
void becsRemoveComponents(const EntityID entity_id, size_t length, uint16_t* comps);
|
||||
|
||||
EntityTemplate* becsAllocateTemplate(uint32_t count, uint16_t* components);
|
||||
EntityTemplate* becsAllocateTemplateFromEntity(EntityID id, uint8_t fill_default);
|
||||
EntityTemplate* becsAllocateTemplateCopy(EntityTemplate* tmpl);
|
||||
EntityTemplate* becsAllocateTemplateFromTemplate(EntityTemplate* tmpl, size_t new_count, uint16_t* components, size_t remove_count, uint16_t* remove_components);
|
||||
void becsFreeTemplate(EntityTemplate* tmpl);
|
||||
|
||||
void* becsEntityGetComponent(Entity* entity, uint16_t component_id);
|
||||
|
||||
void* becsSystemCallDataGetComponentArray(BECSSystemCallData* data, uint16_t component_id);
|
||||
Entity* becsSystemCallDataGetEntitiesArray(BECSSystemCallData* data);
|
||||
|
||||
void* becsListenerCallDataGetComponentArray(BECSListenerCallData* data, uint16_t component_id);
|
||||
Entity* becsListenerCallDataGetEntitiesArray(BECSListenerCallData* data);
|
||||
|
||||
void becsCallEntitiesFunction(uint16_t system_id, void (*on_update)(BECSSystemCallData* call_data), void* context);
|
||||
|
||||
void becsSendEvent(EntityID id, EventRef event);
|
||||
|
||||
#define BECS_REGISTER_COMPONENT(comp) \
|
||||
({ \
|
||||
void* mem_ptr = malloc(sizeof(comp)); \
|
||||
memcpy(mem_ptr, &comp, sizeof(comp)); \
|
||||
becsRegisterComponent(#comp, (BECSComponentInfo){sizeof(comp), alignof(comp), (BECSArray){sizeof(comp), mem_ptr}, 0, 0}); \
|
||||
})
|
||||
|
||||
//BECSComponentInfo(sizeof(comp), 4, 0, 0, 0));
|
||||
|
||||
#endif //__BECS__
|
||||
306
c-api/manager.d
Normal file
306
c-api/manager.d
Normal file
|
|
@ -0,0 +1,306 @@
|
|||
module manager;
|
||||
|
||||
import bubel.ecs.manager;
|
||||
import bubel.ecs.entity;
|
||||
import bubel.ecs.events;
|
||||
import bubel.ecs.system;
|
||||
import bubel.ecs.std;
|
||||
|
||||
import core.stdc.string;
|
||||
|
||||
extern (C):
|
||||
/*
|
||||
struct BECSComponentInfo
|
||||
{
|
||||
///Component size
|
||||
ushort size;
|
||||
///Component data alignment
|
||||
ushort alignment;
|
||||
///Initialization data
|
||||
ubyte[] init_data;
|
||||
///Pointer to component destroy callback
|
||||
void* destroy_callback;
|
||||
///Pointer to component create callback
|
||||
void* create_callback;
|
||||
//void* create_callback;
|
||||
}*/
|
||||
|
||||
alias BECSComponentInfo = EntityManager.ComponentInfo;
|
||||
// alias BECSEventCallData = EntityManager.EventCallData;
|
||||
|
||||
enum BECSSystemComponentAttribute
|
||||
{
|
||||
required = 0,
|
||||
optional = 1,
|
||||
excluded = 2
|
||||
}
|
||||
|
||||
enum BECSSystemComponentAccess
|
||||
{
|
||||
writable = 0,
|
||||
readonly = 1
|
||||
}
|
||||
|
||||
struct BECSSystemComponentInfo
|
||||
{
|
||||
ushort id;
|
||||
BECSSystemComponentAttribute attribute;
|
||||
BECSSystemComponentAccess access;
|
||||
}
|
||||
|
||||
struct BECSEventCallback
|
||||
{
|
||||
ushort id;
|
||||
void function(EntityManager.EventCallData* data) callback;
|
||||
}
|
||||
|
||||
struct BECSSystemRegisterInfo
|
||||
{
|
||||
uint pass_id;
|
||||
int priority;
|
||||
uint max_jobs;
|
||||
|
||||
BECSSystemComponentInfo[] components;
|
||||
BECSEventCallback[] event_handlers;
|
||||
|
||||
byte[] init_data;
|
||||
|
||||
void function(EntityManager.SystemCallData* call_data) on_update;
|
||||
void function(void* system_pointer) on_create;
|
||||
void function(void* system_pointer) on_destroy;
|
||||
void function(void* system_pointer) on_enable;
|
||||
void function(void* system_pointer) on_disable;
|
||||
bool function(void* system_pointer) on_begin;
|
||||
void function(void* system_pointer) on_end;
|
||||
void function(EntityManager.ListenerCallData*) on_add_entity;
|
||||
void function(EntityManager.ListenerCallData*) on_remove_entity;
|
||||
void function(EntityManager.ListenerCallData*) on_change_entity;
|
||||
void function(void* system_pointer, EntityManager.EntityInfo* info) filter_entity;
|
||||
}
|
||||
|
||||
alias BECSEventRegisterInfo = EntityManager.EventRegisterInfo;
|
||||
|
||||
void becsInitialize()
|
||||
{
|
||||
EntityManager.initialize();
|
||||
}
|
||||
|
||||
void becsDestroy()
|
||||
{
|
||||
EntityManager.destroy();
|
||||
}
|
||||
|
||||
void becsBeginRegister()
|
||||
{
|
||||
gEntityManager.beginRegister();
|
||||
}
|
||||
|
||||
void becsEndRegister()
|
||||
{
|
||||
gEntityManager.endRegister();
|
||||
}
|
||||
|
||||
void becsBegin()
|
||||
{
|
||||
gEntityManager.begin();
|
||||
}
|
||||
|
||||
void becsEnd()
|
||||
{
|
||||
gEntityManager.end();
|
||||
}
|
||||
|
||||
void becsCommit()
|
||||
{
|
||||
gEntityManager.commit();
|
||||
}
|
||||
|
||||
void becsUpdate(ushort pass_id)
|
||||
{
|
||||
gEntityManager.update(pass_id);
|
||||
}
|
||||
|
||||
void becsUpdateMT(ushort pass_id)
|
||||
{
|
||||
gEntityManager.update(pass_id);
|
||||
}
|
||||
|
||||
ushort becsRegisterPass(const (char)* name)
|
||||
{
|
||||
return gEntityManager.registerPass(name[0 .. strlen(name)]);
|
||||
}
|
||||
|
||||
ushort becsRegisterComponent(const(char)* name, BECSComponentInfo info)
|
||||
{
|
||||
return gEntityManager.registerComponent(name[0 .. strlen(name)], info);
|
||||
}
|
||||
|
||||
ushort becsRegisterEvent(const(char)* name, BECSEventRegisterInfo info)
|
||||
{
|
||||
return gEntityManager.registerEvent(name[0 .. strlen(name)], info);
|
||||
}
|
||||
|
||||
ushort becsRegisterSystem(const(char)* name, BECSSystemRegisterInfo info)
|
||||
{
|
||||
System system;
|
||||
|
||||
if(info.init_data.length)
|
||||
{
|
||||
system.m_system_pointer = malloc(info.init_data.length);
|
||||
memcpy(system.m_system_pointer, info.init_data.ptr, info.init_data.length);
|
||||
}
|
||||
|
||||
if(info.event_handlers.length)
|
||||
{
|
||||
system.m_event_callers = Mallocator.makeArray!(System.EventCaller)(info.event_handlers.length);
|
||||
foreach(i, BECSEventCallback callback; info.event_handlers)
|
||||
{
|
||||
system.m_event_callers[i].id = callback.id;
|
||||
system.m_event_callers[i].callback = callback.callback;
|
||||
}
|
||||
}
|
||||
|
||||
system.m_update = info.on_update;
|
||||
system.m_create = info.on_create;
|
||||
system.m_destroy = info.on_destroy;
|
||||
system.m_enable = info.on_enable;
|
||||
system.m_disable = info.on_disable;
|
||||
system.m_begin = info.on_begin;
|
||||
system.m_end = info.on_end;
|
||||
system.m_add_entity = info.on_add_entity;
|
||||
system.m_remove_entity = info.on_remove_entity;
|
||||
system.m_change_entity = info.on_change_entity;
|
||||
system.m_filter_entity = info.filter_entity;
|
||||
|
||||
if(info.components.length)
|
||||
{
|
||||
uint req;
|
||||
uint opt;
|
||||
foreach(comp; info.components)
|
||||
{
|
||||
if(comp.attribute == BECSSystemComponentAttribute.required)req++;
|
||||
else if(comp.attribute == BECSSystemComponentAttribute.optional)opt++;
|
||||
}
|
||||
if(req)system.m_components = Mallocator.makeArray!ushort(req);
|
||||
if(opt)system.m_optional_components = Mallocator.makeArray!ushort(opt);
|
||||
req = 0;
|
||||
opt = 0;
|
||||
foreach(comp; info.components)
|
||||
{
|
||||
if(comp.attribute == BECSSystemComponentAttribute.required)
|
||||
{
|
||||
system.m_components[req++] = comp.id;
|
||||
}
|
||||
else if(comp.attribute == BECSSystemComponentAttribute.optional)
|
||||
{
|
||||
system.m_optional_components[opt++] = comp.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
system.m_empty = true;
|
||||
}
|
||||
return gEntityManager.registerSystem(name[0 .. strlen(name)], system);
|
||||
}
|
||||
|
||||
EntityTemplate* becsAllocateTemplate(uint count, ushort* components)
|
||||
{
|
||||
return gEntityManager.allocateTemplate(components[0 .. count]);
|
||||
}
|
||||
|
||||
EntityTemplate* becsAllocateTemplateFromEntity(EntityID id, bool fill_default)
|
||||
{
|
||||
return gEntityManager.allocateTemplate(id, fill_default);
|
||||
}
|
||||
|
||||
EntityTemplate* becsAllocateTemplateCopy(EntityTemplate* tmpl)
|
||||
{
|
||||
return gEntityManager.allocateTemplate(tmpl);
|
||||
}
|
||||
|
||||
EntityTemplate* becsAllocateTemplateFromTemplate(EntityTemplate* tmpl, size_t new_count, ushort* components, size_t remove_count, ushort* remove_components)
|
||||
{
|
||||
return gEntityManager.allocateTemplate(tmpl, components[0 .. new_count], remove_components[0 .. remove_count]);
|
||||
}
|
||||
|
||||
void becsFreeTemplate(EntityTemplate* tmpl)
|
||||
{
|
||||
gEntityManager.freeTemplate(tmpl);
|
||||
}
|
||||
|
||||
Entity* becsAddEntity(EntityTemplate* tmpl)
|
||||
{
|
||||
return gEntityManager.addEntity(tmpl);
|
||||
}
|
||||
|
||||
Entity* becsAddEntityCopy(EntityID id)
|
||||
{
|
||||
return gEntityManager.addEntityCopy(id);
|
||||
}
|
||||
|
||||
void becsRemoveEntity(EntityID id)
|
||||
{
|
||||
gEntityManager.removeEntity(id);
|
||||
}
|
||||
|
||||
Entity* becsGetEntity(EntityID id)
|
||||
{
|
||||
return gEntityManager.getEntity(id);
|
||||
}
|
||||
|
||||
void* becsEntityGetComponent(Entity* entity, ushort component_id)
|
||||
{
|
||||
return entity.getComponent(component_id);
|
||||
}
|
||||
|
||||
void* becsSystemCallDataGetComponentArray(EntityManager.SystemCallData* data, ushort component_id)
|
||||
{
|
||||
if(data.info.deltas.length <= component_id || data.info.deltas[component_id] == 0)return null;
|
||||
return cast(void*)data.block + data.info.deltas[component_id];
|
||||
}
|
||||
|
||||
Entity* becsSystemCallDataGetEntitiesArray(EntityManager.SystemCallData* data)
|
||||
{
|
||||
return cast(Entity*)data.block.dataBegin();
|
||||
}
|
||||
|
||||
void* becsListenerCallDataGetComponentArray(EntityManager.ListenerCallData* data, ushort component_id)
|
||||
{
|
||||
if(data.info.deltas.length <= component_id || data.info.deltas[component_id] == 0)return null;
|
||||
return cast(void*)data.block + data.info.deltas[component_id];
|
||||
}
|
||||
|
||||
Entity* becsListenerCallDataGetEntitiesArray(EntityManager.ListenerCallData* data)
|
||||
{
|
||||
return cast(Entity*)data.block.dataBegin();
|
||||
}
|
||||
|
||||
void becsCallEntitiesFunction(ushort system_id, void function(EntityManager.SystemCallData*) callback, void* context)
|
||||
{
|
||||
System* system = gEntityManager.getSystem(system_id);
|
||||
|
||||
if (!system.m_any_system_caller)
|
||||
return;
|
||||
|
||||
foreach (info; system.m_any_system_caller.infos)
|
||||
{
|
||||
EntityManager.CallData data = EntityManager.CallData(system.id, system, info, context, cast(void*)callback);
|
||||
data.update();
|
||||
}
|
||||
}
|
||||
|
||||
void becsAddComponents(const EntityID entity_id, ComponentRef[] comps)
|
||||
{
|
||||
gEntityManager.addComponents(entity_id, comps);
|
||||
}
|
||||
|
||||
void becsRemoveComponents(const EntityID entity_id, ushort[] comps)
|
||||
{
|
||||
gEntityManager.removeComponents(entity_id, comps);
|
||||
}
|
||||
|
||||
void becsSendEvent(EntityID id, EventRef event)
|
||||
{
|
||||
gEntityManager.sendEvent(id, event);
|
||||
}
|
||||
7
c-api/meson.build
Normal file
7
c-api/meson.build
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
src += files(
|
||||
'manager.d'
|
||||
)
|
||||
|
||||
c_src = files(
|
||||
'test.c'
|
||||
)
|
||||
1051
c-api/test.c
Normal file
1051
c-api/test.c
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -75,7 +75,7 @@ for arg in sys.argv[1:]:
|
|||
elif(arg == '-opt'):
|
||||
shared_flags += '-O3 '
|
||||
ldc_flags += '-release -enable-inlining '
|
||||
emc_flags += '--llvm-lto 3 -s SIMD=1 '
|
||||
emc_flags += '--llvm-lto 3 '
|
||||
elif(arg == '-quiet'):
|
||||
emc_flags += "-Wl,--no-check-features "
|
||||
elif(arg == '--clean'):
|
||||
|
|
|
|||
36
meson.build
36
meson.build
|
|
@ -1,15 +1,17 @@
|
|||
project('decs', 'd', version : '0.5.0')
|
||||
project('decs', 'd', version : '0.1.0')
|
||||
|
||||
# Options
|
||||
betterC_opt = get_option('betterC')
|
||||
BuildDemos_opt = get_option('BuildDemos')
|
||||
BuildTests_opt = get_option('BuildTests')
|
||||
LTO_otp = get_option('LTO')
|
||||
C_API_opt = get_option('C-API')
|
||||
|
||||
summary('betterC enabled', betterC_opt)
|
||||
summary('build demos', BuildDemos_opt)
|
||||
summary('build tests', BuildTests_opt)
|
||||
summary('LTO enabled', LTO_otp)
|
||||
summary('C-API enabled', C_API_opt)
|
||||
|
||||
meson_minimum_version = '>=0.57.1'
|
||||
assert(meson.version().version_compare(meson_minimum_version), 'Newer verson of meson required, current version: @0@, required: @1@'.format(meson.version(), meson_minimum_version))
|
||||
|
|
@ -18,7 +20,14 @@ assert(meson.version().version_compare(meson_minimum_version), 'Newer verson of
|
|||
src = files()
|
||||
subdir('source')
|
||||
|
||||
inc = include_directories('source/')
|
||||
inc = [include_directories('source/')]
|
||||
|
||||
#C API files
|
||||
if C_API_opt
|
||||
c_src = files()
|
||||
subdir('c-api')
|
||||
inc += include_directories('c-api/')
|
||||
endif
|
||||
|
||||
# Arguments
|
||||
args = []
|
||||
|
|
@ -49,6 +58,11 @@ if betterC_opt
|
|||
endif
|
||||
endif
|
||||
|
||||
if comp_id == 'gcc'
|
||||
args+='-pthread'
|
||||
link_args+='-pthread'
|
||||
endif
|
||||
|
||||
add_project_arguments(args, language : 'd')
|
||||
add_project_link_arguments(link_args, language : 'd')
|
||||
|
||||
|
|
@ -69,6 +83,24 @@ decs_dep = declare_dependency(
|
|||
# Tests
|
||||
if BuildTests_opt
|
||||
subdir('tests')
|
||||
|
||||
executable('d-api-tests',
|
||||
['tests/tests.d'],
|
||||
include_directories : [inc],
|
||||
d_args : args,
|
||||
link_args : link_args,
|
||||
dependencies : decs_dep,
|
||||
)
|
||||
|
||||
if C_API_opt
|
||||
add_languages('c')
|
||||
executable('c-api-tests',
|
||||
['c-api/test.c'],
|
||||
include_directories : [inc],
|
||||
dependencies : decs_dep,
|
||||
)
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
# Demos
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@ option('betterC', type: 'boolean', value: false)
|
|||
option('BuildDemos', type: 'boolean', value: false)
|
||||
option('BuildTests', type: 'boolean', value: false)
|
||||
option('LTO', type: 'boolean', value: false)
|
||||
option('C-API', type: 'boolean', value: false)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import bubel.ecs.traits : becsID;
|
|||
|
||||
import std.algorithm.comparison : max;
|
||||
|
||||
alias EventRef = ComponentRef;
|
||||
|
||||
package struct EventManager
|
||||
{
|
||||
|
||||
|
|
@ -30,12 +32,17 @@ package struct EventManager
|
|||
}
|
||||
|
||||
export void sendEvent(Ev)(EntityID id, Ev event, uint thread_id = 0) nothrow @nogc
|
||||
{
|
||||
sendEvent(id, EventRef(&event, becsID!Ev), thread_id);
|
||||
}
|
||||
|
||||
export void sendEvent(EntityID id, EventRef event, uint thread_id = 0) nothrow @nogc
|
||||
{
|
||||
uint block_id = current_index + thread_id;
|
||||
|
||||
EventData* data = &events[becsID!Ev];
|
||||
EventData* data = &events[event.component_id];
|
||||
EventBlock* block = data.blocks[block_id];
|
||||
//EntityManager.EventInfo* info = &manager.events[Ev.event_id];
|
||||
EntityManager.EventInfo* info = &manager.events[event.component_id];
|
||||
//event.entity_id = id;
|
||||
|
||||
if (block is null)
|
||||
|
|
@ -61,10 +68,11 @@ package struct EventManager
|
|||
data.blocks[block_id] = block;
|
||||
}
|
||||
|
||||
uint size = Ev.sizeof + EntityID.sizeof;
|
||||
uint size = info.size + EntityID.sizeof;
|
||||
void* ptr = cast(void*) block + data.data_offset + block.count * size;
|
||||
*cast(EntityID*)ptr = id;
|
||||
*cast(Ev*)(ptr + EntityID.sizeof) = event;
|
||||
memcpy(ptr + EntityID.sizeof, event.ptr, info.size);
|
||||
//*cast(Ev*)(ptr + EntityID.sizeof) = event;
|
||||
//Ev* event_array = cast(Ev*)(cast(void*) block + data.data_offset);
|
||||
//event_array[block.count] = event;
|
||||
block.count++;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -89,7 +89,7 @@ struct System
|
|||
return cast(const(char)[]) m_name;
|
||||
}
|
||||
|
||||
package:
|
||||
//package:
|
||||
|
||||
void destroy()
|
||||
{
|
||||
|
|
@ -170,7 +170,7 @@ package:
|
|||
|
||||
//void function(ref EntityManager.CallData data) m_update;
|
||||
void* m_update; ///workaroud for DMD bug with upper line
|
||||
void delegate() m_update_delegate;
|
||||
//void delegate() m_update_delegate;
|
||||
|
||||
//void function(void* system_pointer) m_enable;
|
||||
//void function(void* system_pointer) m_disable;
|
||||
|
|
@ -198,6 +198,6 @@ package:
|
|||
|
||||
//void function(ref EntityManager.CallData data) m_initialize;
|
||||
//void function(ref EntityManager.CallData data) m_deinitilize;
|
||||
void* m_initialize;
|
||||
void* m_deinitilize;
|
||||
// void* m_initialize;
|
||||
// void* m_deinitilize;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -650,6 +650,8 @@ unittest
|
|||
|
||||
void onAddEntity(EntitiesData data)
|
||||
{
|
||||
foreach(i; 0..data.length)
|
||||
data.long_[i] += 1;
|
||||
add++;
|
||||
assert(add_order == 1);
|
||||
add_order++;
|
||||
|
|
|
|||
|
|
@ -283,13 +283,13 @@ struct ChangeTestSystem
|
|||
|
||||
bool onBegin()
|
||||
{
|
||||
////writeln("On Test System begin.");
|
||||
// writeln("On Test System begin.");
|
||||
return true;
|
||||
}
|
||||
|
||||
void onEnd()
|
||||
{
|
||||
////writeln("On Test System end.");
|
||||
// writeln("On Test System end.");
|
||||
}
|
||||
|
||||
void initialize(ref Entity entity, ref TestComp comp)
|
||||
|
|
@ -307,10 +307,10 @@ struct ChangeTestSystem
|
|||
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
foreach (i; 0 .. data.length)
|
||||
/*foreach (i; 0 .. data.length)
|
||||
{
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -318,6 +318,8 @@ struct TestSystem
|
|||
{
|
||||
mixin ECS.System!16; //__gshared ushort system_id;
|
||||
|
||||
uint print = 1;
|
||||
|
||||
void onCreate()
|
||||
{
|
||||
//writeln("On Test System create.");
|
||||
|
|
@ -343,13 +345,14 @@ struct TestSystem
|
|||
|
||||
bool onBegin()
|
||||
{
|
||||
////writeln("On Test System begin.");
|
||||
if(print)printf("On Test System begin.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
void onEnd()
|
||||
{
|
||||
////writeln("On Test System end.");
|
||||
if(print)printf("On Test System end.\n");
|
||||
print = 0;
|
||||
}
|
||||
|
||||
void initialize(ref Entity entity, ref TestComp comp)
|
||||
|
|
@ -406,7 +409,7 @@ struct TestSystemWithHighPriority
|
|||
|
||||
void initialize(ref Entity entity, ref TestComp comp)
|
||||
{
|
||||
int o = 1;
|
||||
|
||||
}
|
||||
|
||||
void onUpdate(EntitiesData data)
|
||||
|
|
@ -844,6 +847,7 @@ else:
|
|||
//dur = (MonoTime.currTime - time).total!"usecs";
|
||||
//writeln("Entities adding: ", dur, " usecs");
|
||||
printf("Entities adding: %f usecs\n", cast(float)(Time.getUSecTime() - time));
|
||||
Mallocator.dispose(idss);
|
||||
time = Time.getUSecTime();
|
||||
|
||||
uint blocks = 0;
|
||||
|
|
@ -1021,8 +1025,6 @@ else:
|
|||
gEntityManager.freeTemplate(copy_default_tempalte);
|
||||
EntityManager.destroy();
|
||||
|
||||
Mallocator.dispose(idss);
|
||||
|
||||
printf("end\n"); //*/
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue