|
|
@ -8,12 +8,55 @@ pub const MAXEntitys: u32 = 1000;
|
|
|
|
pub const MAXComponents: u32 = 32;
|
|
|
|
pub const MAXComponents: u32 = 32;
|
|
|
|
|
|
|
|
|
|
|
|
//Id Types
|
|
|
|
//Id Types
|
|
|
|
pub const entity = usize;
|
|
|
|
pub const Entity = usize;
|
|
|
|
|
|
|
|
|
|
|
|
pub const component = usize;
|
|
|
|
pub const Component = usize;
|
|
|
|
|
|
|
|
|
|
|
|
pub const Signature = std.bit_set.IntegerBitSet(MAXComponents);
|
|
|
|
pub const Signature = std.bit_set.IntegerBitSet(MAXComponents);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Component array type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ComponentArray = struct {
|
|
|
|
|
|
|
|
Components: [MAXEntitys]type,
|
|
|
|
|
|
|
|
Entity2Array: [usize]Entity,
|
|
|
|
|
|
|
|
Array2Entity: [Entity]usize,
|
|
|
|
|
|
|
|
sizeM: usize,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn AddComponent(self: ComponentArray, entity: Entity, comp: type) void {
|
|
|
|
|
|
|
|
var newidx: usize = self.sizeM;
|
|
|
|
|
|
|
|
self.Entity2Array[entity] = newidx;
|
|
|
|
|
|
|
|
self.Entity2Array[newidx] = entity;
|
|
|
|
|
|
|
|
self.Components[newidx] = comp;
|
|
|
|
|
|
|
|
self.sizeM += 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn Removedata(self: ComponentArray, entity: Entity) void {
|
|
|
|
|
|
|
|
var remidx: usize = self.Entity2Array[entity];
|
|
|
|
|
|
|
|
var lastidx: usize = self.sizeM - 1;
|
|
|
|
|
|
|
|
self.Components[remidx] = self.Components[lastidx];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var lastentity: entity = self.Array2Entity[lastidx];
|
|
|
|
|
|
|
|
self.Entity2Array[lastentity] = remidx;
|
|
|
|
|
|
|
|
self.Array2Entity[remidx] = lastentity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.Entity2Array[entity] = null;
|
|
|
|
|
|
|
|
self.Array2Entity[lastentity] = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.sizeM -= 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn GetData(self: ComponentArray, entity: Entity) type {
|
|
|
|
|
|
|
|
return self.Components[self.Entity2Array[entity]];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn EntityDestroyed(self: ComponentArray, entity: Entity) void {
|
|
|
|
|
|
|
|
for(self.Array2Entity) |val|{
|
|
|
|
|
|
|
|
if(val == entity){
|
|
|
|
|
|
|
|
self.Removedata(entity);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Components
|
|
|
|
//Components
|
|
|
|
|
|
|
|
|
|
|
|
pub const Transform = struct {
|
|
|
|
pub const Transform = struct {
|
|
|
|