public void handleUpdateWorldNode(long oid, WorldManagerClient.UpdateWorldNodeMessage wnodeMsg) { PerceiverData perceiverData = perceiverDataMap.get(oid); if (perceiverData == null) { if (Log.loggingDebug) Log.debug( "ProximityTracker.handleMessage: ignoring updateWNMsg for oid " + oid + " because PerceptionData for oid not found"); return; } BasicWorldNode bwnode = wnodeMsg.getWorldNode(); if (Log.loggingDebug) Log.debug( "ProximityTracker.handleMessage: UpdateWnode for " + oid + ", loc " + bwnode.getLoc() + ", dir " + bwnode.getDir()); if (perceiverData.wnode != null) { perceiverData.previousLoc = perceiverData.lastLoc; perceiverData.wnode.setDirLocOrient(bwnode); perceiverData.wnode.setInstanceOid(bwnode.getInstanceOid()); perceiverData.lastLoc = perceiverData.wnode.getLoc(); } else Log.error( "ProximityTracker.handleMessage: In UpdateWorldNodeMessage for oid " + oid + ", perceiverData.wnode is null!"); updateEntity(perceiverData); }
public void addTrackedPerceiver( Long perceiverOid, InterpolatedWorldNode wnode, Integer reactionRadius) { lock.lock(); try { if (perceiverDataMap.containsKey(perceiverOid)) { // Don't add the object more than once. Log.error( "ProximityTracker.addTrackedPerceiver: perceiverOid " + perceiverOid + " is already in the set of local objects, for ProximityTracker instance " + this); return; } PerceiverData perceiverData = new PerceiverData(perceiverOid, reactionRadius, wnode); perceiverDataMap.put(perceiverOid, perceiverData); } finally { lock.unlock(); } if (Log.loggingDebug) Log.debug( "ProximityTracker.addTrackedPerceiver: perceiverOid=" + perceiverOid + " reactionRadius=" + reactionRadius + " instanceOid=" + instanceOid); }
protected void performNotification( long perceiverOid, long perceivedOid, boolean inRadius, boolean wasInRadius) { if (Log.loggingDebug) Log.debug( "ProximityTracker.performNotification: perceiverOid " + perceiverOid + ", perceivedOid " + perceivedOid + ", inRadius " + inRadius + ", wasInRadius " + wasInRadius); if (notifyCallback != null) { notifyCallback.notifyReactionRadius(perceivedOid, perceiverOid, inRadius, wasInRadius); notifyCallback.notifyReactionRadius(perceiverOid, perceivedOid, inRadius, wasInRadius); } else { ObjectTracker.NotifyReactionRadiusMessage nmsg = new ObjectTracker.NotifyReactionRadiusMessage( perceivedOid, perceiverOid, inRadius, wasInRadius); Engine.getAgent().sendBroadcast(nmsg); nmsg = new ObjectTracker.NotifyReactionRadiusMessage( perceiverOid, perceivedOid, inRadius, wasInRadius); Engine.getAgent().sendBroadcast(nmsg); } }
protected boolean maybeAddPerceivedObject(PerceptionMessage.ObjectNote objectNote) { ObjectType objType = (ObjectType) objectNote.getObjectType(); long perceivedOid = objectNote.getSubject(); long perceiverOid = objectNote.getTarget(); if (perceivedOid == perceiverOid) return true; boolean callbackNixedIt = false; if (remoteObjectFilter != null) callbackNixedIt = !remoteObjectFilter.objectShouldBeTracked(perceivedOid, objectNote); if (callbackNixedIt || !(objType.isMob())) { // if (Log.loggingDebug) // Log.debug("ProximityTracker.maybeAddPerceivedObject: ignoring oid=" + // perceivedOid // + " objType=" + objType // + " detected by " + perceiverOid // + ", instanceOid=" + instanceOid); return false; } if (Log.loggingDebug) Log.debug( "ProximityTracker.maybeAddPerceivedObject: oid=" + perceivedOid + " objType=" + objType + " detected by " + perceiverOid + ", instanceOid=" + instanceOid); lock.lock(); try { PerceiverData perceiverData = perceiverDataMap.get(perceiverOid); if (perceiverData == null) { Log.error( "ProximityTracker.maybeAddPerceivedObject: got perception msg with perceived obj oid=" + perceivedOid + " for unknown perceiver=" + perceiverOid); return false; } perceiverData.perceivedOids.add(perceivedOid); PerceiverData perceivedData = perceiverDataMap.get(perceivedOid); if (perceivedData != null) testProximity(perceiverData, perceivedData, true, false); } finally { lock.unlock(); } return true; }
public void run() { while (running) { try { update(); } catch (MVRuntimeException e) { Log.exception("ProximityTracker.Updater.run caught MVRuntimeException", e); } catch (Exception e) { Log.exception("ProximityTracker.Updater.run caught exception", e); } try { Thread.sleep(1000); } catch (InterruptedException e) { Log.warn("Updater: " + e); e.printStackTrace(); } } }
public void removeTrackedPerceiver(Long perceiverOid) { lock.lock(); try { // Iterate over perceived objects, removing our // perceiverOid from their oid sets. PerceiverData perceiverData = perceiverDataMap.get(perceiverOid); if (perceiverData != null) { if (Log.loggingDebug) Log.debug( "ProximityTracker.removeTrackedPerceiver: perceiverOid " + perceiverOid + ", inRangeOids count " + perceiverData.inRangeOids.size()); // Iterate over perceived objects, removing our // perceiverOid from their oid sets. for (Long perceivedOid : perceiverData.perceivedOids) { PerceiverData perceivedData = perceiverDataMap.get(perceivedOid); if (perceivedData != null) { perceivedData.perceivedOids.remove(perceiverOid); if (perceivedData.inRangeOids.contains(perceiverOid)) { perceivedData.inRangeOids.remove(perceiverOid); performNotification(perceiverOid, perceivedOid, false, true); } } } perceiverData.perceivedOids.clear(); perceiverData.inRangeOids.clear(); perceiverDataMap.remove(perceiverOid); } else Log.warn( "ProximityTracker.removeTrackedPerceiver: For oid=" + perceiverOid + ", didn't find PerceiverData"); } finally { lock.unlock(); } if (Log.loggingDebug) Log.debug( "ProximityTracker.removeTrackedPerceiver: oid=" + perceiverOid + " instanceOid=" + instanceOid); }
protected void update() { Log.debug("Updater.update: in update"); List<Long> perceiverOids = null; lock.lock(); try { perceiverOids = new ArrayList<Long>(perceiverDataMap.keySet()); } finally { lock.unlock(); } // We loop over the copied perceiverOids causing // interpolation to happen, and capturing the location in // the PerceiverData, so we can later do comparisons // cheaply. Note that underlying map can change while // we're doing so, so we don't raise errors if it happens. for (long perceiverOid : perceiverOids) { PerceiverData perceiverData = perceiverDataMap.get(perceiverOid); if (perceiverData != null) { perceiverData.previousLoc = perceiverData.lastLoc; // long lastInterp = perceiverData.wnode.getLastInterp(); perceiverData.lastLoc = perceiverData.wnode.getLoc(); // if (Log.loggingDebug) // Log.debug("Updater.update: perceiverOid " + perceiverOid + ", // previousLoc " + perceiverData.previousLoc + // ", lastLoc " + perceiverData.lastLoc + ", time since interp // " + (System.currentTimeMillis() - lastInterp)); } } // Now actually do the double loop to check if inRange has // changed for (long perceiverOid : perceiverOids) { PerceiverData perceiverData = perceiverDataMap.get(perceiverOid); if (perceiverData == null) continue; // If the perceiver hasn't moved much, no need to // iterate over it's perceived entities if (perceiverData.previousLoc != null && Point.distanceToSquared(perceiverData.previousLoc, perceiverData.lastLoc) < 100f) continue; ArrayList<Long> perceivedOids = new ArrayList<Long>(perceiverData.perceivedOids); for (long perceivedOid : perceivedOids) { PerceiverData perceivedData = perceiverDataMap.get(perceivedOid); if (perceivedData == null) continue; // Invoke the testProximity method but tell it not // to interpolate, but instead get its location // from the PerceptionData.lastLoc members testProximity(perceiverData, perceivedData, false, false); } } }
public List<Long> getOidsInRadius(long perceiverOid) { lock.lock(); try { PerceiverData perceiverData = perceiverDataMap.get(perceiverOid); if (perceiverData == null) { Log.error( "ProximityTracker.getOidsInRadius: perceptionData for oid " + perceiverOid + " is null"); return new LinkedList<Long>(); } else return new LinkedList<Long>(perceiverData.inRangeOids); } finally { lock.unlock(); } }
protected void removePerceivedObject(long perceiverOid, long perceivedOid) { lock.lock(); try { PerceiverData perceiverData = perceiverDataMap.get(perceiverOid); if (perceiverData == null) { if (Log.loggingDebug) Log.debug( "ProximityTracker.removePerceivedObject: No perceiverData for oid " + perceiverOid); return; } perceiverData.perceivedOids.remove(perceivedOid); if (perceiverData.inRangeOids.contains(perceivedOid)) { performNotification(perceiverOid, perceivedOid, true, false); perceiverData.inRangeOids.remove(perceivedOid); } } finally { lock.unlock(); } }
public void handlePerception(PerceptionMessage perceptionMessage) { long targetOid = perceptionMessage.getTarget(); List<PerceptionMessage.ObjectNote> gain = perceptionMessage.getGainObjects(); List<PerceptionMessage.ObjectNote> lost = perceptionMessage.getLostObjects(); if (Log.loggingDebug) Log.debug( "ProximityTracker.handlePerception: targetOid + " + targetOid + ", instanceOid=" + instanceOid + " " + ((gain == null) ? 0 : gain.size()) + " gain and " + ((lost == null) ? 0 : lost.size()) + " lost"); if (gain != null) for (PerceptionMessage.ObjectNote note : gain) maybeAddPerceivedObject(note); if (lost != null) for (PerceptionMessage.ObjectNote note : lost) maybeRemovePerceivedObject(note.getSubject(), note, targetOid); }
// getPlayer().sendServerInfo("You make progress on the quest " + // getName() + ". You have " + status.currentCount + "/" + status.targetCount + " " + // status.template.getName()); // } // return; // } // else { // Log.debug("CollectionGoalStatus.handleAcquire: no match"); // } // } // } // finally { // lock.unlock(); // } // } public void handleInvUpdate() { if (Log.loggingDebug) if (Log.loggingDebug) Log.debug("CollectionQuestState.handleAcquire: quest=" + getName()); lock.lock(); try { if (getConcluded()) { return; } // MarsMob player = getPlayer(); // Log.debug("CollectionQuestState.handleInvUpdate: player=" + // player.getName() + // ", questState=" + this.getName() + // ", numGoals=" + // goalsStatus.size()); // Iterator<CollectionGoalStatus> iter = goalsStatus.iterator(); // while(iter.hasNext()) { // CollectionGoalStatus status = iter.next(); // int invCount = player.getInvItemCount(status.template); // Log.debug("CollectionQuestState.handleInvUpdate: checking itemTemplate=" + status.template // + ", invCount=" + invCount); // if (getCompleted()) { // Log.debug("CollectionQuestState.handleInvUpdate: completed"); // // the quest was completed prior to getting this item // if (invCount > status.currentCount) { // // we must have just picked up a quest item // // but we dont need it // continue; // } // else if (invCount == status.currentCount) { // // quest is still completed - you can ignore // continue; // } // // // invCount < status.currentCount // // we must have just dropped an item, and // // the quest is no longer complete // setCompleted(false); // status.currentCount = invCount; // // // send a QuestCompleted event to mobs that perceive us // // so that if one of them can accept this quest for // // completion, it can update its state // QuestCompleted completeEvent = // new QuestCompleted(player, getQuest()); // Engine.getMessageServer().sendToPerceivers(player, // completeEvent, // RDPMessageServer.NON_USERS); // // // send a log update // Event questStateInfo = new QuestStateInfo(player, this); // player.sendEvent(questStateInfo); // // // send text message // player.sendServerInfo("Your quest " + getName() + " is no longer // completed. You have " + status.currentCount + "/" + status.targetCount + " " + // status.template.getName()); // continue; // } // // // quest is not completed // Log.debug("CollectionQuestState.handleInvUpdate: not completed"); // // if (invCount < status.currentCount) { // Log.debug("CollectionQuestState.handleInvUpdate: lost item"); // // we lost an item // status.currentCount = invCount; // // // send a log update // Event questStateInfo = new QuestStateInfo(player, this); // player.sendEvent(questStateInfo); // // // send text message // player.sendServerInfo("You lost an item for quest " + getName() + ". // You have " + status.currentCount + "/" + status.targetCount + " " + // status.template.getName()); // continue; // } // else if (invCount == status.currentCount) { // // we didnt get a new quest item // Log.debug("CollectionQuestState.handleInvUpdate: not quest item"); // continue; // } // if (invCount > status.currentCount) { // // we just got a new needed quest item // Log.debug("CollectionQuestState.handleInvUpdate: got new quest item"); // if (invCount > status.targetCount) { // // we have more than we need // status.currentCount = status.targetCount; // } // else { // status.currentCount = invCount; // } // // // send a log update // Event questStateInfo = new QuestStateInfo(player, this); // player.sendEvent(questStateInfo); // // // send text message // player.sendServerInfo("You make progress on the quest " + getName() + ". // You have " + status.currentCount + "/" + status.targetCount + " " + // status.template.getName()); // // // check if completed and handle if it is // // (sending message to user and also notifying // // mobs nearby in case one of them is a quest // // completer) // completeHandler(); // } // } } finally { lock.unlock(); } }