/** * Tells the thread there's something to do Note, you can't just call * notifyAll in the event listener because it doesn't have the thread * something something. */ private synchronized void wakeUp() { final String METHOD_NAME = "wake_up()"; getOwner().methodBegin(getClass(), METHOD_NAME); try { notifyAll(); } finally { getOwner().methodEnd(getClass(), METHOD_NAME); } }
PathEnumerator getPathEnumerator() { PATH_ENUMERATOR_LOCK.readLock().lock(); try { getOwner().log(getClass(), "getPathEnumerator()()", LogLevel.DEBUG, "PATH_ENUMERATOR_LOCK read locked."); return pathEnumerator; } finally { PATH_ENUMERATOR_LOCK.readLock().unlock(); getOwner().log(getClass(), "getPathEnumerator()()", LogLevel.DEBUG, "PATH_ENUMERATOR_LOCK read unlocked."); } }
private void setPathEnumerator(PathEnumerator pathEnumerator) { PATH_ENUMERATOR_LOCK.writeLock().lock(); try { getOwner().log(getClass(), "setPathEnumerator(PathEnumerator)", LogLevel.DEBUG, "PATH_ENUMERATOR_LOCK write locked."); this.pathEnumerator = pathEnumerator; } finally { getOwner().log(getClass(), "setPathEnumerator(PathEnumerator)", LogLevel.DEBUG, "PATH_ENUMERATOR_LOCK write unlocked."); PATH_ENUMERATOR_LOCK.writeLock().unlock(); } }
private void pause() { final String METHOD_NAME = "pause()"; getOwner().methodBegin(getClass(), METHOD_NAME); try { getWaitWhenDone().set(true); while (!getWaiting().get() && !getDone().get()) { try { Thread.sleep(100); } catch (InterruptedException ignored) { } } } finally { getOwner().methodEnd(getClass(), METHOD_NAME); } }
@SuppressWarnings("unchecked") private void receiveUpdateMinefields(Packet packet) { // only update information if you know about the minefield Vector<Minefield> newMines = new Vector<>(); for (Minefield mf : (Vector<Minefield>) packet.getObject(0)) { if (getOwner().getLocalPlayer().containsMinefield(mf)) { newMines.add(mf); } } if (newMines.size() > 0) { getGame().resetMinefieldDensity(newMines); } }
/** * Waits until the thread is not paused, and there's indication that it has * something to do */ private synchronized void waitForUnpause() { final String METHOD_NAME = "wait_for_unpause()"; getOwner().methodBegin(getClass(), METHOD_NAME); try { while (!getDone().get() && (getWaitWhenDone().get() || (getEventsToProcess().isEmpty() && getDirtyUnits().isEmpty()))) { getOwner().log(getClass(), METHOD_NAME, "waitWhenDone = " + getWaitWhenDone() + " :: eventsToProcess = " + getEventsToProcess().size() + " :: dirtyUnits = " + getDirtyUnits().size()); getWaiting().set(true); try { wait(); } catch (InterruptedException ignored) { } // System.err.println("checking WAIT conditions"); } getWaiting().set(false); } finally { getOwner().methodEnd(getClass(), METHOD_NAME); } }
/** * receive and process an entity nova network mode change packet * * @param c The packet containing the change. */ private void receiveEntityNovaNetworkModeChange(Packet c) { final String METHOD_NAME = "receiveEntityNovaNetworkModeChange(Packet)"; try { int entityId = c.getIntValue(0); String networkID = c.getObject(1).toString(); Entity e = getGame().getEntity(entityId); if (e != null) { e.setNewRoundNovaNetworkString(networkID); } } catch (Exception ex) { getOwner().log(getClass(), METHOD_NAME, ex); } }
public void run() { final String METHOD_NAME = "run()"; getOwner().methodBegin(getClass(), METHOD_NAME); try { // todo There's probably a better way to handle this than a loop that only exits on an error. //noinspection InfiniteLoopStatement while (!getDone().get()) { if (!getEventsToProcess().isEmpty()) { processGameEvents(); ecmInfo = ComputeECM.computeAllEntitiesECMInfo( getGame().getEntitiesVector()); } else if (!getDirtyUnits().isEmpty()) { Entity entity = getGame().getEntity(getDirtyUnits().pollFirst()); if ((entity != null) && isEntityOnMap(entity)) { unPause(); getOwner().log(getClass(), METHOD_NAME, "recalculating paths for " + entity.getDisplayName()); getPathEnumerator().recalculateMovesFor(entity); getOwner().log(getClass(), METHOD_NAME, "finished recalculating paths for " + entity .getDisplayName()); } } else if (getWaitWhenDone().get()) { waitForUnpause(); // paused for a reason } else { waitForUnpause(); // idling because there's nothing to do } } } finally { getOwner().methodEnd(getClass(), METHOD_NAME); } }
getOwner().methodBegin(getClass(), METHOD_NAME); int numEvents = eventsToProcessIterator.size(); for (int count = 0; count < numEvents; count++) { getOwner().log(getClass(), METHOD_NAME, "Processing event " + (count + 1) + " out of " + numEvents); GameEvent event = eventsToProcessIterator.get(count); if (event == null) { continue; getOwner().log(getClass(), METHOD_NAME, "Processing " + event.toString()); getEventsToProcess().remove(event); if (event instanceof GameEntityChangeEvent) { continue; // no sense in updating a unit if it hasn't moved getOwner().log(getClass(), METHOD_NAME, "Received entity change event for " + changeEvent.getEntity().getDisplayName() getOwner().log(getClass(), METHOD_NAME, "Phase change detected: " + phaseChange.getNewPhase().name()); getOwner().log(getClass(), METHOD_NAME, "Events still to process: " + getEventsToProcess().size()); } finally { GAME_LOCK.unlock(); getOwner().methodEnd(getClass(), METHOD_NAME);
getOwner().methodBegin(getClass(), METHOD_NAME); Entity entity = getGame().getEntity(entityId); if (entity != null) { getOwner().log(getClass(), METHOD_NAME, "recalculating paths for " + entity.getDisplayName()); getPathEnumerator().recalculateMovesFor(entity); getOwner().log(getClass(), METHOD_NAME, "finished recalculating paths for " + entity .getDisplayName()); getOwner().methodEnd(getClass(), METHOD_NAME);
void handlePacket(Packet c) { if (c == null) { getOwner().log(getClass(), "handlePacket(Packet)", LogLevel.WARNING,