public static void RenameGameobject(this ent entity, Transform tr) { if (tr != null) { var name = tr.name; var index = tr.name.LastIndexOf(':'); if (index > -1) { name = tr.name.Remove(0, index + 1); } var id = entity.id; name = name.Trim(); fstr.Clear(); fstr.Append($"{id.ToString().PadLeft(4, '0')}: "); if (Framework.Settings.DebugNames) { fstr.Append("[ "); for (int j = 0; j < entities[entity.id].componentsAmount; j++) { var storage = Storage.All[entities[entity.id].componentsIds[j]]; var lex = j < entities[entity.id].componentsAmount - 1 ? " " : ""; fstr.Append($"{storage.GetComponentType().Name.Remove(0, 9)}{lex}"); } fstr.Append(" ]: "); } fstr.Append(name); tr.name = fstr.ToString(); } }
internal static void Initialize(int id, bool isPooled = false, bool isNested = false) { if (id >= lengthTotal) { var l = id << 1; HelperArray.ResizeInt(ref Generations, l, Framework.Settings.SizeGenerations); // Array.Resize(ref Transforms, l); entities = (CacheEntity *)UnmanagedMemory.ReAlloc(entities, sizeEntityCache * l); for (int i = lengthTotal; i < l; i++) { entities[i] = new CacheEntity(5); } lengthTotal = l; } entities[id].componentsAmount = 0; var ptrCache = &entities[id]; // ptrCache->age = age; ptrCache->isNested = isNested; ptrCache->isPooled = isPooled; // todo: need to refactor in future // ptrCache->isDirty = true; // ptrCache->isAlive = true; ent e = new ent(); e.id = id; // e.age = age; // alive.Add(e); }
public static ent Create() { int id; // byte age = 0; if (ent.entStack.Count > 0) { var pop = ent.entStack.Peek(); id = pop.id; // unchecked // { // age = (byte) (pop.age); // } } else { id = ++ent.lastID; } ent entity = new ent(); entity.id = id; // entity.age = age; Initialize(id); // EntityOperations.Set(entity, -1, EntityOperations.Action.Activate); return(entity); }
/// Use when an entity contains an observer and you want to stop the observer without releasing entity. public static void StopObserver(this ent entity) { if (entity.exist) { entity.ComponentObserver().length = 0; } }
internal void Create(out ent entity, bool isPooled = false) { if (ent.Released.length > 0) { ref var pop = ref ent.Released.source[--ent.Released.length]; entity.id = pop.id; entity.age = pop.age; }
/// Use when an entity is an observer and you want to release this entity. public static void ReleaseObserver(this ent entity) { if (entity.exist) { entity.ComponentObserver().length = 0; entity.Release(); } }
internal static void DebugCheckLimits(int len, ent entity) { if (len == EcsTags.Capacity) { LayerKernel.Debugger.Log(LogType.TAGS_LIMIT_REACHED, entity, EcsTags.Capacity); throw new ArgumentException(); } }
static void DebugCheckActive <T>(ent entity) { #if UNITY_EDITOR if (!entity.exist) { LayerKernel.Debugger.Log(LogType.NOT_ACTIVE, entity, typeof(T).Name); } #endif }
static void DebugCheckNull(ent entity, Type type) { if (entity.id != 0) { return; } LayerKernel.Debugger.Log(LogType.NULL_ENTITY, entity, type.Name); throw new ArgumentException(); }
static void DebugDestroyed(ent entity) { #if UNITY_EDITOR if (!entity.exist) { LayerKernel.Debugger.Log(LogType.DESTROYED, entity, entity.transform); } #endif }
internal void BootstrapCreated(Layer layer, ModelComposer model) { Layer = layer; if (!entity.exist) { entity = layer.Entity.CreateForActor(this, model, prefabReferenceName != string.Empty); } #if UNITY_EDITOR _entity = entity.id; #endif Setup(); HandleEnable(); }
internal void BootstrapCreated(Layer layer, ModelComposer model) { Layer = layer; if (!entity.exist) { entity = layer.Entity.CreateForActor(this, model, isPooled); } #if UNITY_EDITOR _entity = entity.id; #endif Setup(); HandleEnable(); }
//===============================// // Launch methods //===============================// // used when actor is created in session. internal void BootstrapCreated(Layer layer) { Layer = layer; if (!entity.exist) { entity = layer.Entity.CreateForActor(this, (ScriptableBuild)null, prefabReferenceName != string.Empty); } #if UNITY_EDITOR _entity = entity.id; #endif Setup(); HandleEnable(); }
public bool OverlapComponents(ent entity) { int match = 0; for (int i = 0; i < ComponentsIds.length; i++) { if (entity.Has(ComponentsIds[i])) { match++; } } return(ComponentsIds.length == match); }
//===============================// // Launch methods //===============================// // used when actor is created in session. internal void BootstrapCreated(Layer layer) { Layer = layer; if (!entity.exist) { entity = layer.Entity.CreateForActor(this, (ScriptableBuild)null, isPooled); } #if UNITY_EDITOR _entity = entity.id; #endif Setup(); HandleEnable(); }
public static void RenameGameobject(this ent entity) { if (!LayerKernel.Settings.DebugNames) { return; } var tr = ProcessorEcs.EntitiesManaged[entity.id].transform; if (tr != null) { var name = tr.name; var index = tr.name.LastIndexOf(':'); if (index > -1) { name = tr.name.Remove(0, index + 1); } var id = entity.id; name = name.Trim(); fstr.Clear(); fstr.Append($"{id.ToString().PadLeft(4, '0')}: "); fstr.Append("[ "); var ptr = ProcessorEcs.Entities.Get <EntityMeta>(entity.id); for (var j = 0; j < ptr->componentsAmount; j++) { var storage = Storage.All[ptr->components[j]]; var lex = j < ptr->componentsAmount - 1 ? " " : ""; fstr.Append($"{storage.GetComponentType().Name.Remove(0, 9)}{lex}"); } fstr.Append(" ]: "); fstr.Append(name); tr.name = fstr.ToString(); } }
public void Launch() { // int id; // // if (ent.entStack.length > 0) // { // ref var pop = ref ent.entStack.source[--ent.entStack.length]; // id = pop.id; // // unchecked // // { // // age = (byte) (pop.age); // // } // } // else // id = ++ent.lastID; // // entity.id = id; // // entity.age = age; entity = Entity.Create(); #if UNITY_EDITOR _entity = entity.id; #endif // Entity.Initialize(id, isPooled); // Entity.Transforms[id] = transform; // if (isActiveAndEnabled) { // debug.log("setup"); Setup(); // EntityOperations.Set(entity, -1, EntityOperations.Action.Activate); } }
public string Get(int id) { lastEntity = id; return($"Entity with ID [{id}] recieved "); }
static void DebugNoComponent <T>(ent entity) { var generation = Storage <T> .Generation; var mask = Storage <T> .ComponentMask; ref var _managed = ref entity.managed;
public static void ValueChange <TSource, TProp>(this TSource source, Func <TSource, TProp> propertySelector, Action <TProp> callback, ref ent e) { var w = new Wrap <TSource, TProp>(); w.source = source; w.prop = propertySelector; w.callback = callback; #if UNITY_EDITOR if (Comparers.storage.TryGetValue(typeof(TProp).GetHashCode(), out object comparer)) { w.comparer = comparer as IEqualityComparer <TProp>; } else { Debug.LogError($"Comparer for {typeof(TProp)} not found."); } #else w.comparer = Comparers.storage[typeof(TProp).GetHashCode()] as IEqualityComparer <TProp>; #endif var cObserver = default(ComponentObserver); if (!e.exist) { e = Entity.Create(); cObserver = e.Set <ComponentObserver>(); } else { cObserver = e.ComponentObserver(); } #if ACTORS_COMPONENTS_STRUCTS if (cObserver.wrappers == null) { cObserver.wrappers = new IWrap[2]; } Debug.Log(cObserver.wrappers.Length); #endif if (cObserver.length >= cObserver.wrappers.Length) { Array.Resize(ref cObserver.wrappers, cObserver.length << 1); } cObserver.wrappers[cObserver.length++] = w; }