|
|
@ -6,7 +6,7 @@ const Etyp = @import("EntitySystemTypes.zig");
|
|
|
|
const EntityIDs: std.TailQueue(u32) = init: {
|
|
|
|
const EntityIDs: std.TailQueue(u32) = init: {
|
|
|
|
var temp = std.TailQueue(u32);
|
|
|
|
var temp = std.TailQueue(u32);
|
|
|
|
var i = 0;
|
|
|
|
var i = 0;
|
|
|
|
while(i < Etyp.MAXEntitys){
|
|
|
|
while (i < Etyp.MAXEntitys) {
|
|
|
|
temp.append(i);
|
|
|
|
temp.append(i);
|
|
|
|
i += 1;
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -19,8 +19,7 @@ const Signatures: [Etyp.MAXEntitys]Etyp.Signature = undefined;
|
|
|
|
//Entity System
|
|
|
|
//Entity System
|
|
|
|
|
|
|
|
|
|
|
|
pub fn CreateEntity() !Etyp.entity {
|
|
|
|
pub fn CreateEntity() !Etyp.entity {
|
|
|
|
if(EntityAmount >= Etyp.MAXEntitys)
|
|
|
|
if (EntityAmount >= Etyp.MAXEntitys) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return error{};
|
|
|
|
return error{};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EntityAmount += 1;
|
|
|
|
EntityAmount += 1;
|
|
|
@ -41,31 +40,8 @@ pub fn GetSignature(entity: Etyp.entity) Etyp.signature {
|
|
|
|
return Signatures[entity];
|
|
|
|
return Signatures[entity];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const ComponentArray = struct {
|
|
|
|
//Component Manager
|
|
|
|
Components: [Etyp.MAXEntitys]type,
|
|
|
|
|
|
|
|
Entity2Array: [usize]EntityIDs,
|
|
|
|
|
|
|
|
Array2Entity: [EntityIDs]usize,
|
|
|
|
|
|
|
|
sizeM: usize,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn AddComponent(self: ComponentArray, entity: Etyp.entity, comp: type) void{
|
|
|
|
pub fn RegisterComponent() 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: Etyp.entity) void{
|
|
|
|
|
|
|
|
var remidx: usize = self.Entity2Array[entity];
|
|
|
|
|
|
|
|
var lastidx: usize = self.sizeM-1;
|
|
|
|
|
|
|
|
self.Components[remidx] = self.Components[lastidx];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var lastentity: Etyp.entity = self.Array2Entity[lastidx];
|
|
|
|
|
|
|
|
self.Entity2Array[lastentity] = remidx;
|
|
|
|
|
|
|
|
self.Array2Entity[remidx] = lastentity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.Entity2Array[entity] = null;
|
|
|
|
|
|
|
|
self.Array2Entity[lastentity] = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.sizeM -= 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|