using System; using FarseerPhysics.Dynamics; namespace FarseerPhysics.Controllers { [Flags] public enum ControllerType { GravityController = (1 << 0), VelocityLimitController = (1 << 1), AbstractForceController = (1 << 2), BuoyancyController = (1 << 3), } public struct ControllerFilter { public ControllerType ControllerFlags; /// /// Ignores the controller. The controller has no effect on this body. /// /// The controller type. public void IgnoreController(ControllerType controller) { ControllerFlags |= controller; } /// /// Restore the controller. The controller affects this body. /// /// The controller type. public void RestoreController(ControllerType controller) { ControllerFlags &= ~controller; } /// /// Determines whether this body ignores the the specified controller. /// /// The controller type. /// /// true if the body has the specified flag; otherwise, false. /// public bool IsControllerIgnored(ControllerType controller) { return (ControllerFlags & controller) == controller; } } public abstract class Controller : FilterData { public bool Enabled; public World World; private ControllerType _type; public Controller(ControllerType controllerType) { _type = controllerType; } public override bool IsActiveOn(Body body) { if (body.ControllerFilter.IsControllerIgnored(_type)) return false; return base.IsActiveOn(body); } public abstract void Update(float dt); } }