public Corral(Point size, WorldObject toTrack) { subject = toTrack; bounds = new BoxCollider(size); AddComponent(bounds); bounds.CollisionStart += TriggerEvents; bounds.CollisionEnd += TriggerEvents; }
private static bool CircularComponentCheck(WorldObject root, HashSet<WorldObject> log) { // check if the root is in the log, if it is, that means that we have a loop if (log.Contains(root)) return false; // otherwise add the root, and perform a recursive call on all of the components. log.Add(root); foreach(WorldObject wo in root.GetComponents()) { // if any fail, then stop checking. if (!CircularComponentCheck(wo, log)) return false; } // if none failed, then it checks out return true; }
protected virtual void OnOwnerChanged(WorldObject owner) { if (OwnerChanged != null) OwnerChanged(this, new WorldObjectEventArgs(owner)); Layer = owner == null ? null : owner.Layer; }
public void RemoveComponent(WorldObject component) { if (_components.Contains(component)) { _components.Remove(component); OnComponentRemoved(component); } }
public void AddComponent(WorldObject component) { _components.Add(component); if (component.Owner != this) component.Owner = this; OnComponentAdded(component); if (!CircularComponentCheck(RootObject)) throw new InvalidComponentsException("An invalid component configuration was detected. Make sure you do not have duplicate components or a circular arrangement of components."); }
public static bool CircularComponentCheck(WorldObject root) { return CircularComponentCheck(root, new HashSet<WorldObject>()); }
public WorldObjectEventArgs(WorldObject worldObject) { WorldObject = worldObject; }
public WorldObject(WorldObject owner) { Initialize(owner, Vector2.Zero); }
public void Remove(WorldObject worldObject) { WorldObjects.Remove(worldObject); OnWorldObjectRemoved(worldObject); }
public void Add(WorldObject worldObject) { WorldObjects.Add(worldObject); OnWorldObjectAdded(worldObject); }
private void UnsubscribeFromManagers(WorldObject worldObject) { if (worldObject is ICollidable) CollisionManager.AddCollidable(worldObject as ICollidable); else if (worldObject is IDrawManageable) DrawManager.Remove(worldObject as IDrawManageable); // unsubscribe the components recursively foreach (WorldObject wo in worldObject.GetComponents()) { UnsubscribeFromManagers(wo); } }
private void SubscribeToManagers(WorldObject worldObject) { if (worldObject is ICollidable) CollisionManager.AddCollidable(worldObject as ICollidable); else if (worldObject is IDrawManageable) DrawManager.AddDrawable(worldObject as IDrawManageable); // subscribe components recursively foreach (WorldObject wo in worldObject.GetComponents()) { SubscribeToManagers(wo); } }
private void OnWorldObjectRemoved(WorldObject worldObject) { if (WorldObjectRemoved != null) WorldObjectRemoved(this, new WorldObjectEventArgs(worldObject)); // remove the worldObject from the Managers UnsubscribeFromManagers(worldObject); }
private void OnWorldObjectAdded(WorldObject worldObject) { if (WorldObjectAdded != null) WorldObjectAdded(this, new WorldObjectEventArgs(worldObject)); // set the layer worldObject.Layer = this; // hook up events worldObject.UpdateOrderChanged += worldObject_UpdateOrderChanged; // refresh the update order SortUpdateOrder(); // add the worldObject to the Managers SubscribeToManagers(worldObject); }
private void Initialize(WorldObject owner = null, Vector2? position = null, params WorldObject[] components) { Owner = owner; _components = new List<WorldObject>(components); BasePosition = position ?? Vector2.Zero; BaseScale = new Vector2(1, 1); BaseRotation = 0; Enabled = true; UpdateOrder = 0; }
private void OnComponentRemoved(WorldObject component) { if (ComponentRemoved != null) ComponentRemoved(this, new WorldObjectEventArgs(component)); }
protected override void OnOwnerChanged(WorldObject owner) { base.OnOwnerChanged(owner); _baseObject = RootObject; }
public WorldObject(WorldObject owner = null, Vector2? position = null, params WorldObject[] components) { Initialize(owner, position ?? null, components); }
public Body() { _baseObject = RootObject; }