コード例 #1
0
 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);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 public void handleMessage(Message msg, int flags) {
   try {
     lock.lock();
     if (activated == false) return; // return true;
     if (msg.getMsgType() == Behavior.MSG_TYPE_COMMAND) {
       Behavior.CommandMessage cmdMsg = (Behavior.CommandMessage) msg;
       String command = cmdMsg.getCmd();
       // Remove the executor, because anything we do will
       // end the current execution.
       Engine.getExecutor().remove(this);
       if (Log.loggingDebug)
         Log.debug(
             "BaseBehavior.onMessage: command = "
                 + command
                 + "; oid = "
                 + obj.getOid()
                 + "; name "
                 + obj.getName());
       if (command.equals(MSG_CMD_TYPE_GOTO)) {
         GotoCommandMessage gotoMsg = (GotoCommandMessage) msg;
         Point destination = gotoMsg.getDestination();
         mode = MSG_CMD_TYPE_GOTO;
         roamingBehavior = true;
         gotoSetup(destination, gotoMsg.getSpeed());
       } else if (command.equals(MSG_CMD_TYPE_STOP)) {
         followTarget = null;
         pathState.clear();
         obj.getWorldNode().setDir(new MVVector(0, 0, 0));
         obj.updateWorldNode();
         mode = MSG_CMD_TYPE_STOP;
         // If roamingBehavior is set, that means that we
         // used formerly had a roaming behavior, so send
         // an ArrivedEventMessage so that the other
         // behavior starts up again.
         if (roamingBehavior) {
           try {
             Engine.getAgent().sendBroadcast(new ArrivedEventMessage(obj));
           } catch (Exception e) {
             Log.error(
                 "BaseBehavior.onMessage: Error sending ArrivedEventMessage, error was '"
                     + e.getMessage()
                     + "'");
             throw new RuntimeException(e);
           }
         }
       } else if (command.equals(BaseBehavior.MSG_CMD_TYPE_FOLLOW)) {
         FollowCommandMessage followMsg = (FollowCommandMessage) msg;
         mode = MSG_CMD_TYPE_FOLLOW;
         followSetup(followMsg.getTarget(), followMsg.getSpeed());
       }
     } else if (msg.getMsgType() == WorldManagerClient.MSG_TYPE_MOB_PATH_CORRECTION) {
       Engine.getExecutor().remove(this);
       interpolatePath();
       interpolatingPath = false;
     }
     // return true;
   } finally {
     lock.unlock();
   }
 }
コード例 #4
0
 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();
   }
 }
コード例 #5
0
  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;
  }
コード例 #6
0
 public void run() {
   try {
     lock.lock();
     if (activated == false) {
       return;
     }
     try {
       if (mode == MSG_CMD_TYPE_GOTO) {
         gotoUpdate();
       } else if (mode == MSG_CMD_TYPE_FOLLOW) {
         followUpdate();
       } else if (mode == MSG_CMD_TYPE_STOP) {
       } else {
         Log.error("BaseBehavior.run: invalid mode");
       }
     } catch (Exception e) {
       Log.exception("BaseBehavior.run caught exception raised during run for mode = " + mode, e);
       throw new RuntimeException(e);
     }
   } finally {
     lock.unlock();
   }
 }