/** Increases the size of the backing array (if necessary) to accommodate the specified number of additional items. Useful * before adding many items to avoid multiple backing array resizes. * @param additionalCapacity the number of additional items */ public void ensureCapacity (int additionalCapacity) { int newCapacity = size + additionalCapacity; if (items.length < newCapacity) resize(newCapacity); }
@Override public boolean handleMessage (Telegram telegram) { @SuppressWarnings("unchecked") PathFinderRequest<N> pfr = (PathFinderRequest<N>)telegram.extraInfo; pfr.client = telegram.sender; // set the client to be notified once the request has completed pfr.status = PathFinderRequest.SEARCH_NEW; // Reset status pfr.statusChanged = true; // Status has just changed pfr.executionFrames = 0; // Reset execution frames counter requestQueue.store(pfr); return true; }
@Override public boolean acquire () { return acquire(1); }
/** Acquires the semaphore. Also, the first execution of this method retrieves the semaphore by name and stores it locally. * <p> * This method is called when the task is entered. */ @Override public void start () { if (semaphore == null) { semaphore = NonBlockingSemaphoreRepository.getSemaphore(name); } semaphoreAcquired = semaphore.acquire(); super.start(); }
/** Releases the semaphore. * <p> * This method is called when the task exits. */ @Override public void end () { if (semaphoreAcquired) { if (semaphore == null) { semaphore = NonBlockingSemaphoreRepository.getSemaphore(name); } semaphore.release(); semaphoreAcquired = false; } super.end(); }
@Override public Location<T> calculateSlotLocation (Location<T> outLocation, int slotNumber) { super.calculateSlotLocation(outLocation, slotNumber); outLocation.setOrientation(outLocation.getOrientation() + MathUtils.PI); return outLocation; }
@Override public boolean release () { return release(1); }
@Override public NonBlockingSemaphore createSemaphore (String name, int maxResources) { return new SimpleNonBlockingSemaphore(name, maxResources); }
/** Returns the greatest common divisor of the given absolute values. This implementation uses {@link #gcdPositive(int, int)} * and has the same special cases. * * @param args non-negative numbers * @return the greatest common divisor. */ public static int gcdPositive (int... args) { if (args == null || args.length < 2) throw new IllegalArgumentException("gcdPositive requires at least two arguments"); int result = args[0]; int n = args.length; for (int i = 1; i < n; i++) { result = gcdPositive(result, args[i]); } return result; }
/** Returns the least common multiple of the given absolute values. This implementation uses {@link #lcmPositive(int, int)} and * has the same special cases. * * @param args non-negative numbers * @return the least common multiple, never negative. * @throws ArithmeticException if the result cannot be represented as a non-negative {@code int} value. */ public static int lcmPositive (int... args) { if (args == null || args.length < 2) throw new IllegalArgumentException("lcmPositive requires at least two arguments"); int result = args[0]; int n = args.length; for (int i = 1; i < n; i++) { result = lcmPositive(result, args[i]); } return result; }
public static NonBlockingSemaphore addSemaphore (String name, int maxResources) { NonBlockingSemaphore sem = FACTORY.createSemaphore(name, maxResources); REPO.put(name, sem); return sem; }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { return arrive(steering, target.getPosition()); }
public int size () { return requestQueue.size(); } }
public PathFinderQueue (PathFinder<N> pathFinder) { this.pathFinder = pathFinder; this.requestQueue = new CircularBuffer<PathFinderRequest<N>>(16); this.currentRequest = null; this.requestControl = new PathFinderRequestControl<N>(); }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { return reachOrientation(steering, target.getOrientation()); }
/** Creates a {@code RaycastObstacleAvoidance} behavior. * @param owner the owner of this behavior * @param rayConfiguration the ray configuration * @param raycastCollisionDetector the collision detector * @param distanceFromBoundary the minimum distance to a wall (i.e., how far to avoid collision). */ public RaycastObstacleAvoidance (Steerable<T> owner, RayConfiguration<T> rayConfiguration, RaycastCollisionDetector<T> raycastCollisionDetector, float distanceFromBoundary) { super(owner); this.rayConfiguration = rayConfiguration; this.raycastCollisionDetector = raycastCollisionDetector; this.distanceFromBoundary = distanceFromBoundary; this.outputCollision = new Collision<T>(newVector(owner), newVector(owner)); this.minOutputCollision = new Collision<T>(newVector(owner), newVector(owner)); }
/** Creates a {@code RayConfigurationBase} for the given owner and the specified number of rays. * @param owner the owner of this configuration * @param numRays the number of rays used by this configuration */ @SuppressWarnings("unchecked") public RayConfigurationBase (Steerable<T> owner, int numRays) { this.owner = owner; this.rays = new Ray[numRays]; for (int i = 0; i < numRays; i++) this.rays[i] = new Ray<T>(owner.getPosition().cpy().setZero(), owner.getPosition().cpy().setZero()); }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { return face(steering, target.getPosition()); }
/** Adds the given item to the tail of this circular buffer. * @param item the item to add * @return {@code true} if the item has been successfully added to this circular buffer; {@code false} otherwise. */ public boolean store (T item) { if (size == items.length) { if (!resizable) return false; // Resize this queue resize(Math.max(8, (int)(items.length * 1.75f))); } size++; items[tail++] = item; if (tail == items.length) tail = 0; return true; }
/** Utility method that creates a new vector. * <p> * This method is used internally to instantiate vectors of the correct type parameter {@code T}. This technique keeps the API * simple and makes the API easier to use with the GWT backend because avoids the use of reflection. * * @param location the location whose position is used to create the new vector * @return the newly created vector */ protected T newVector (Location<T> location) { return location.getPosition().cpy().setZero(); } }