public void Init(EcsSystems systems) { var world = systems.GetWorld(worldName); _filter = world.Filter <T> ().End(); _pool = world.GetPool <T> (); }
internal static void BlockAllClick(EcsFilter <ClickEvent> events, int buttonNumer) { for (var i = 0; i < events.GetEntitiesCount(); i++) { events.Get1[i].IsBlocked = true; } }
/// <summary> /// Immediately removes all entities in given filter. /// Use it carefully! /// </summary> public static void Clear <T> (this EcsFilter <T> filter) where T : struct { foreach (var idx in filter) { filter.GetEntity(idx).Destroy(); } }
public void Init(EcsSystems systems) { var worldConstraints = systems.GetWorld(PhysicsWorldNames.Constraints); springsBodyBody = worldConstraints.Filter <SpringBodyBody>().End(); springsBodySpace = worldConstraints.Filter <SpringBodySpace>().End(); }
/// <summary> /// Mark all entities in a filter with RemoveEntityComponent. /// </summary> public static void MarkRemove(this EcsFilter filter) { foreach (var idx in filter) { filter.GetEntity(idx).Get <RemoveEntityComponent>(); } }
public bool IsCompatible(EcsFilter filter) { if (BitsCount > 0 && filter.IncludeMask.BitsCount <= BitsCount) { int i = filter.IncludeMask.BitsCount - 1; var maxJ = BitsCount - 1; for (; i >= 0; i--) { var j = maxJ; var bit = filter.IncludeMask.Bits[i]; for (; j >= 0; j--) { if (Bits[j] == bit) { break; } } if (j == -1) { break; } } if (i == -1) { return(!IsIntersects(filter.ExcludeMask)); } } return(false); }
void IEcsWorldDebugListener.OnFilterCreated(EcsFilter filter) { var go = new GameObject(); go.transform.SetParent(_filtersRoot); go.hideFlags = HideFlags.NotEditable; var observer = go.AddComponent <EcsFilterObserver> (); observer.World = this; observer.Filter = filter; // included components. var goName = $"Inc<{filter.IncludedTypes[0].Name}"; for (var i = 1; i < filter.IncludedTypes.Length; i++) { goName += $",{filter.IncludedTypes[i].Name}"; } goName += ">"; // excluded components. if (filter.ExcludedTypes != null) { goName += $".Exc<{filter.ExcludedTypes[0].Name}"; for (var i = 1; i < filter.ExcludedTypes.Length; i++) { goName += $",{filter.ExcludedTypes[i].Name}"; } goName += ">"; } go.name = goName; }
private void ForEachTrigger <T>(EcsFilter <T> filter) where T : struct, ITriggerEvent { foreach (var index in filter) { ref var hannpend = ref filter.Get1(index); Log($"Trigger event {typeof(T).Name}", hannpend.colliderOwner, hannpend.collisionWith); }
private static void CreateOrDestroyEntities(EcsWorld world, EcsFilter filter, int count, Action <EcsWorld> createEntity) { IEcsGroup group = world.Filter(filter); if (group.CalculateCount() == count) { return; } IEcsEntity[] entities = group.ToEntityArray(); for (int i = entities.Length; i < count; i++) { createEntity(world); } for (int i = count; i < entities.Length; i++) { IEcsEntity entity = entities[i]; BroadphaseRefComponent brRef = entity.GetComponent <BroadphaseRefComponent>(); CharacterComponent character = entity.GetComponent <CharacterComponent>(); Object.Destroy(character.Ref.gameObject); foreach (SAPChunk chunk in brRef.Chunks) { BroadphaseHelper.RemoveFormChunk(chunk, entity.Id); } entity.Destroy(); } }
/// <summary> /// You better don't use this extensions in real projects, 'cause it can strike on performance /// </summary> public static T2 GetSecondComponent <T1, T2>( this EcsFilter <T1, T2> filter, Func <T1, bool> limits1 = null, Func <T2, bool> limits2 = null) where T1 : class, new() where T2 : class, new() { if (limits1 == null) { limits1 = x => true; } if (limits2 == null) { limits2 = x => true; } for (int i = 0; i < filter.EntitiesCount; i++) { var component1 = filter.Components1 != null ? filter.Components1[i] : null; var component2 = filter.Components2 != null ? filter.Components2[i] : null; if (!limits1(component1) || !limits2(component2)) { continue; } return(component2); } return(null); }
public void Init(EcsSystems systems) { var world = systems.GetWorld(); boundingCircles = world.Filter <BoundingCircle>().End(); meshes = world.Filter <Mesh>().Inc <Pose>().End(); }
public static bool AllEntitiesEquals <T>(this EcsFilter filter) where T : struct { for (int i = 0; i < filter.GetEntitiesCount() - 1; i++) { ref var currentEntity = ref filter.GetEntity(i).Get <T>(); ref var nextEntity = ref filter.GetEntity(i + 1).Get <T>();
/// <summary> /// simple clear filter /// </summary> /// <param name="filter"></param> public static void ClearSimple(this EcsFilter filter) { foreach (int i in filter) { ref EcsEntity entity = ref filter.GetEntity(i); entity.Destroy(); }
public static EcsFilter <T1, T2> Out <T1, T2>(this EcsFilter <T1, T2> filter, out T1[] get1, out T2[] get2, out EcsEntity[] entities) where T1 : class where T2 : class { get1 = filter.Get1; get2 = filter.Get2; entities = filter.Entities; return(filter); }
public void Init(EcsSystems systems) { var world = systems.GetWorld(); shapes = world.Filter <Shape>().Inc <BoundingBox>().End(); shapesPool = world.GetPool <Shape>(); boundingBoxes = world.GetPool <BoundingBox>(); }
public void Init(EcsSystems systems) { var world = systems.GetWorld(); circles = world.Filter <RigidBody>().Inc <Circle>().Inc <BoundingBox>().End(); meshes = world.Filter <RigidBody>().Inc <Mesh>().Inc <BoundingBox>().End(); grabberElasticityCoefficient = 40f; }
void IEcsSystem.Initialize(EcsWorld world) { _world = world; Debug.LogFormat("{0} => initialize", GetType().Name); _world.SubscribeToEvent <ControlEvent> (OnControlEntity); _controlObjects = _world.GetFilter <ControlComponent> (); _controlComponentId = _world.GetComponentIndex <ControlComponent> (); }
public static void HandleEvents <T>(this EcsFilter <T> filter, EcsWorld _world, Action <T> action) where T : class, new() { foreach (var idx in filter) { action(filter.Components1[idx]); _world.RemoveEntity(filter.Entities[idx]); } }
void IEcsSystem.Initialize(EcsWorld world) { _world = world; Debug.LogFormat("{0} => initialize", GetType().Name); _destroyObjects = _world.GetFilter <DestroyComponent> (); _destroyComponentId = _world.GetComponentIndex <DestroyComponent> (); _world.OnComponentDetach += OnComponentDetach; _world.SubscribeToEvent <DestroyEvent> (OnDestroyEntity); }
public void Init(EcsSystems systems) { var worldEvents = systems.GetWorld(PhysicsWorldNames.Events); var physicsData = systems.GetShared <PhysicsData>(); contacts = worldEvents.Filter <Contact <TagA, TagB> >().End(); contactsPool = worldEvents.GetPool <Contact <TagA, TagB> >(); RegisterSolver(worldEvents, physicsData.ContactSolversMatrix); }
void IEcsSystem.Initialize(EcsWorld world) { _world = world; Debug.LogFormat("{0} => initialize", GetType().Name); _goObjects = _world.GetFilter <GameObjectComponent, SnakeComponent> (); _controlComponentId = _world.GetComponentIndex <ControlComponent> (); _goComponentId = _world.GetComponentIndex <GameObjectComponent> (); _snakeComponentId = _world.GetComponentIndex <SnakeComponent> (); }
public static void AllDestroy(this EcsFilter f) { var ecsEntities = f.Entities; foreach (var i in f) { ecsEntities[i].Destroy(); } }
public static void CleanFilter(this EcsFilter filter) { var world = filter.GetWorld(); for (var i = 0; i < filter.EntitiesCount; i++) { world.RemoveEntity(filter.Entities[i]); } }
void IEcsSystem.Initialize(EcsWorld world) { _world = world; Debug.LogFormat("{0} => initialize", GetType().Name); _colliderComponentId = _world.GetComponentIndex <ColliderComponent> (); _snakeComponentId = _world.GetComponentIndex <SnakeComponent> (); _collisionObjects = _world.GetFilter <ColliderComponent, DestroyComponent> (); _snakeObjects = _world.GetFilter <ColliderComponent, SnakeComponent> (); }
public static void AllUnset <T>(this EcsFilter f) where T : class { var e = f.Entities; foreach (var i in f) { e[i].Unset <T>(); } }
public void Init(EcsSystems systems) { var worldEvents = systems.GetWorld(PhysicsWorldNames.Events); var physicsData = systems.GetShared <PhysicsData>(); possibleContacts = worldEvents.Filter <PossibleContact <ShapeA, ShapeB> >().End(); possibleContactsPool = worldEvents.GetPool <PossibleContact <ShapeA, ShapeB> >(); contactSolversMatrix = physicsData.ContactSolversMatrix; RegisterTester(worldEvents, physicsData.ContactTestersMatrix); }
public static List <EcsEntity> ToEntitieNumbersList <T>(this EcsFilter <T> filter) where T : class, new() { var result = new List <EcsEntity>(); foreach (var idx in filter) { result.Add(filter.Entities[idx]); } return(result); }
public static List <T> ToEntitiesList <T>(this EcsFilter <T> filter) where T : class, new() { var result = new List <T>(); foreach (var idx in filter) { result.Add(filter.Components1[idx]); } return(result); }
internal static bool IsBlockedClick(EcsFilter <ClickEvent> events, int buttonNumer) { var isBlock = false; for (var i = 0; i < events.GetEntitiesCount(); i++) { isBlock = isBlock || (events.Get1[i].ButtonNumber == buttonNumer && events.Get1[i].IsBlocked); } return(isBlock); }
internal static bool IsPressClick(EcsFilter <ClickEvent> events, int buttonNumer) { var isPress = false; for (var i = 0; i < events.GetEntitiesCount(); i++) { isPress = isPress || events.Get1[i].ButtonNumber == buttonNumer; } return(isPress); }