-changes in gitignore

-changed "absent" to "excluded" everywhere
-added Events support:
 *systems are scanned by handleEvent() function
 *generate system callers for events
 *event sending have (untested) multithreaded support
 *EventInput structure in System has input components for event
This commit is contained in:
Mergul 2018-11-02 15:39:46 +01:00
parent 16a5696840
commit 3bc5ff2423
8 changed files with 689 additions and 310 deletions

View file

@ -10,253 +10,280 @@ import ecs.core;
import core.time;
import std.stdio;
int main()
struct TestEvent
{
mixin ECS.Event;//__gshared ushort event_id;
int a;
}
struct TestEvent
struct TestEvent2
{
mixin ECS.Event;//__gshared ushort event_id;
float a;
}
static struct TestComp
{
mixin ECS.Component;//__gshared ushort component_id;
int a = 1;
ulong b = 2;
static void serializeComponent(SerializeVector output)
{
mixin ECS.Event;//__gshared ushort event_id;
int a;
}
struct TestEvent2
static void deserializeComponent(ubyte[] data)
{
mixin ECS.Event;//__gshared ushort event_id;
float a;
}
}
static struct TestComp2
{
mixin ECS.Component;//__gshared ushort component_id;
int b = 3;
int a = 4;
static void serializeComponent(ref TestComp comp, SerializeVector output)
{
}
static struct TestComp
static void deserializeComponent(ref TestComp comp, ubyte[] data)
{
mixin ECS.Component;//__gshared ushort component_id;
int a = 1;
ulong b = 2;
static void serializeComponent(SerializeVector output)
}
}
static struct TestComp3
{
mixin ECS.Component;//__gshared ushort component_id;
uint gg = 5; //good game
uint bg = 6; //bad game
void serializeComponent(SerializeVector output)
{
}
void deserializeComponent(ubyte[] data)
{
}
}
static struct TestComp4
{
mixin ECS.Component;//__gshared ushort component_id;
uint gg = 7; //good game
uint bg = 8; //bad game
ulong a = 9;
ulong b = 10;
ulong c = 11;
ulong g = 12;
static void serializeComponent(ref TestComp comp, SerializeVector output)
{
}
static void deserializeComponent(ref TestComp comp, ubyte[] data)
{
}
}
struct TestSystem
{
mixin ECS.System!16;//__gshared ushort system_id;
void onCreate()
{
writeln("On Test System create.");
}
void onDestroy()
{
writeln("On Test System destroy.");
}
bool onBegin()
{
//writeln("On Test System begin.");
return true;
}
void onEnd()
{
//writeln("On Test System end.");
}
void initialize(ref Entity entity, ref TestComp comp)
{
}
static struct EntitiesData
{
size_t length;
TestComp[] test;
TestComp2[] test2;
@readonly @optional const(TestComp3)[] test3;
//@excluded TestComp4[] test4;
}
void update(ref Entity entity, ref TestComp test, ref TestComp2 test2)//, TestComp3* test3) //ref TestComp comp)
{
assert(cast(size_t)&test % TestComp.alignof == 0);
assert(cast(size_t)&test2 % TestComp2.alignof == 0);
import std.stdio;
test.a += 1000;
test.b += 2000;
test2.b += 2;
test2.a = 8;
}
void update(EntitiesData data)
{
foreach(i;0..data.length)
{
}
static void deserializeComponent(ubyte[] data)
{
data.test[i].a += 1000;
data.test[i].b += 2000;
data.test2[i].b += 2;
data.test2[i].a = 8;
}
}
static struct TestComp2
void handleEvent(TestEvent event, ref TestComp test, ref TestComp2 test2, TestComp3* test3)
{
mixin ECS.Component;//__gshared ushort component_id;
int b = 3;
int a = 4;
static void serializeComponent(ref TestComp comp, SerializeVector output)
{
}
}
}
struct TestSystemWithHighPriority
{
mixin ECS.System!16;//__gshared ushort system_id;
static void deserializeComponent(ref TestComp comp, ubyte[] data)
{
}
static struct EntitiesData
{
TestComp[] test;
}
static struct TestComp3
void initialize(ref Entity entity, ref TestComp comp)
{
mixin ECS.Component;//__gshared ushort component_id;
uint gg = 5; //good game
uint bg = 6; //bad game
void serializeComponent(SerializeVector output)
{
}
void deserializeComponent(ubyte[] data)
{
}
int o = 1;
}
static struct TestComp4
void update(EntitiesData data)
{
mixin ECS.Component;//__gshared ushort component_id;
uint gg = 7; //good game
uint bg = 8; //bad game
ulong a = 9;
ulong b = 10;
ulong c = 11;
ulong g = 12;
static void serializeComponent(ref TestComp comp, SerializeVector output)
{
}
static void deserializeComponent(ref TestComp comp, ubyte[] data)
{
}
}
struct TestSystem
/*void handleEvent(Event event, ref TestComp comp)
{
mixin ECS.System!16;//__gshared ushort system_id;
void onCreate()
{
writeln("On Test System create.");
}
void onDestroy()
{
writeln("On Test System destroy.");
}
bool onBegin()
{
//writeln("On Test System begin.");
return true;
}
void onEnd()
{
//writeln("On Test System end.");
}
void initialize(ref Entity entity, ref TestComp comp)
{
}
static struct EntitiesData
{
size_t length;
TestComp[] test;
TestComp2[] test2;
@readonly @optional const(TestComp3)[] test3;
//@absent TestComp4[] test4;
}
void update(ref Entity entity, ref TestComp test, ref TestComp2 test2)//, TestComp3* test3) //ref TestComp comp)
{
assert(cast(size_t)&test % TestComp.alignof == 0);
assert(cast(size_t)&test2 % TestComp2.alignof == 0);
import std.stdio;
test.a += 1000;
test.b += 2000;
test2.b += 2;
test2.a = 8;
}
void update(EntitiesData data)
{
foreach(i;0..data.length)
{
data.test[i].a += 1000;
data.test[i].b += 2000;
data.test2[i].b += 2;
data.test2[i].a = 8;
}
}
void handleEvent(TestEvent event, ref TestComp test, ref TestComp2 test2, TestComp3* test3)
{
}
}
struct TestSystemWithHighPriority
{
mixin ECS.System!16;//__gshared ushort system_id;
static struct EntitiesData
{
TestComp[] test;
}
void initialize(ref Entity entity, ref TestComp comp)
{
int o = 1;
}
void update(EntitiesData data)
{
}
/*void handleEvent(Event event, ref TestComp comp)
{
}*/
}
}*/
}
import std.meta;
struct TestSystem2
struct TestSystem2
{
mixin ECS.System!16;//__gshared ushort system_id;
/*enum ExcludedComponents0
{
mixin ECS.System!16;//__gshared ushort system_id;
enum AbsentComponents0
{
TestComp,
TestComp4
}
alias AbsentComponents = AliasSeq!("TestComp", "TestComp4");
string AbsentComponents2;
static struct EntitiesData
{
short length;
const (Entity)[] entity;
TestComp3[] test;
//@absent TestComp[] testt;
}
void onEnable()
{
import std.stdio;
writeln("TestSystem2 enabled");
}
void onDisable()
{
import std.stdio;
writeln("TestSystem2 disabled");
}
void initialize(ref Entity entity, ref TestComp comp)
{
}
void update(ref EntitiesData data)
{
foreach(i;0..data.test.length)
{
data.test[i].gg += 14;
gEM.sendSelfEvent!(TestEvent)(data.entity[i].id, TestEvent());
}
}
void lateUpdate(ref EntitiesData data)
{
foreach(i;0..data.test.length)
{
data.test[i].gg -= 1;
gEM.sendSelfEvent!(TestEvent)(data.entity[i].id, TestEvent());
}
}
/*void handleEvent(Event event, ref TestComp comp)
{
}*/
TestComp,
TestComp4
}
alias ExcludedComponents = AliasSeq!("TestComp", "TestComp4");
string ExcludedComponents2;*/
static struct EntitiesData
{
short length;
const (Entity)[] entity;
TestComp3[] test;
//@excluded TestComp[] testt;
}
static struct EventInput
{
Entity* entity;
TestComp3* test;
//TestComp* tt;
}
void handleEvent(EventInput input, ref TestEvent event)
{
input.test.bg = event.a;
TestEvent2 event2;
event2.a = event.a + 8;
gEM.sendEvent(input.entity.id, event2);
}
void handleEvent(EventInput input, ref TestEvent2 event)
{
input.test.gg = cast(uint)event.a;
}
void onEnable()
{
import std.stdio;
writeln("TestSystem2 enabled");
}
void onDisable()
{
import std.stdio;
writeln("TestSystem2 disabled");
}
void initialize(ref Entity entity, ref TestComp comp)
{
}
void update(EntitiesData data)
{
foreach(i;0..data.test.length)
{
data.test[i].gg += 14;
TestEvent event;
event.a = data.test[i].gg + 4;
gEM.sendEvent(data.entity[i].id, event);//*/
/*TestEvent2 event2;
event2.a = data.test[i].gg + 8;
gEM.sendEvent(data.entity[i].id, event2);//*/
//gEM.sendEvent!(TestEvent)(data.entity[i].id, event);
//gEM.sendSelfEvent!(TestEvent)(data.entity[i].id, TestEvent());
}
}
void lateUpdate(ref EntitiesData data)
{
foreach(i;0..data.test.length)
{
data.test[i].gg -= 1;
//gEM.sendSelfEvent!(TestEvent)(data.entity[i].id, TestEvent());
}
}
/*void handleEvent(Event event, ref TestComp comp)
{
}*/
}
int main()
{
void dispatch(EntityManager.JobGroup jobs)
{
foreach(job;jobs.jobs)