import Vector from '../math/Vector'; import Steerable from './Steerable'; /** * A {@code Proximity} defines an area that is used by group behaviors to find and process the owner's neighbors. *

* Typically (but not necessarily) different group behaviors share the same {@code Proximity} for a given owner. This allows you to * combine group behaviors so as to get a more complex behavior also known as emergent behavior. Emergent behavior is behavior * that looks complex and/or purposeful to the observer but is actually derived spontaneously from fairly simple rules. The * lower-level agents following the rules have no idea of the bigger picture; they are only aware of themselves and maybe a few of * their neighbors. A typical example of emergence is flocking behavior which is a combination of three group behaviors: * {@link Separation separation}, {@link Alignment alignment}, and {@link Cohesion cohesion}. The three behaviors are typically * combined through a {@link BlendedSteering blended steering}. This works okay but, because of the limited view distance of a * character, it's possible for an agent to become isolated from its flock. If this happens, it will just sit still and do * nothing. To prevent this from happening, you usually add in the {@link Wander wander} behavior too. This way, all the agents * keep moving all the time. Tweaking the magnitudes of each of the contributing behaviors will give you different effects such as * shoals of fish, loose swirling flocks of birds, or bustling close-knit herds of sheep. *

* Before a steering acceleration can be calculated for a combination of group behaviors, the neighbors must be determined and * processed. This is done by the {@link #findNeighbors} method and its callback argument. *

* Notes: *

* * @param Type of vector, either 2D or 3D, implementing the {@link Vector} interface * * @author davebaol */ interface Proximity> { /** Returns the owner of this proximity. */ getOwner(): Steerable; /** Sets the owner of this proximity. */ setOwner(owner: Steerable): void; /** * Finds the agents that are within the immediate area of the owner. Each of those agents is passed to the * {@link ProximityCallback#reportNeighbor(Steerable) reportNeighbor} method of the specified callback. * @return the number of neighbors found. */ findNeighbors(callback: ProximityCallback): number; } /** * The callback object used by a proximity to report the owner's neighbor. * * @param Type of vector, either 2D or 3D, implementing the {@link Vector} interface * * @author davebaol */ export interface ProximityCallback> { /** * The callback method used to report a neighbor. * @param neighbor the reported neighbor. * @return {@code true} if the given neighbor is valid; {@code false} otherwise. */ reportNeighbor(neighbor: Steerable): boolean; } export default Proximity;