コード例 #1
0
  /** The main method of the game map processor. */
  @SuppressWarnings("nls")
  @Override
  public void run() {
    while (running) {
      while (pauseLoop) {
        try {
          synchronized (unchecked) {
            unchecked.wait();
          }
        } catch (final InterruptedException e) {
          LOGGER.debug("Unexpected wakeup during pause.", e);
        }
      }
      performInsideCheck();

      if (processUnchecked()) {
        continue;
      }

      if (workloadCheck()) {
        continue;
      }

      try {
        synchronized (unchecked) {
          unchecked.wait();
        }
      } catch (final InterruptedException e) {
        LOGGER.debug("Unexpected wake up of the map processor", e);
      }
    }
  }
コード例 #2
0
  /**
   * Process the unchecked tiles that are still needed to be done.
   *
   * @return <code>true</code> in case a tile was handled.
   */
  private boolean processUnchecked() {
    long key;
    synchronized (unchecked) {
      final int size = unchecked.size();
      if (size == 0) {
        return false;
      }
      key = unchecked.removeAt(size - 1);
    }

    final MapTile tile = parent.getMapAt(key);

    // no tile found, lets quit here
    if (tile == null) {
      return true;
    }

    // clipping check
    if (checkClipping(tile, key)) {
      return true;
    }

    // obstruction check
    if (checkObstruction(tile, key)) {
      return true;
    }

    // hidden check
    if (checkHidden(tile, key)) {
      return true;
    }

    return true;
  }
コード例 #3
0
 /**
  * Add a key of a map location to the processor that contains a location on the map that was yet
  * unchecked.
  *
  * @param key the key of the location that needs to be checked
  */
 public void reportUnchecked(final long key) {
   synchronized (unchecked) {
     if (unchecked.contains(key)) {
       unchecked.add(key);
     }
     unchecked.notify();
   }
   fullCheckNeeded = true;
 }
コード例 #4
0
 public Position(
     Portfolio portfolio,
     String assetName,
     TFloatArrayList price,
     TLongArrayList priceTimeMillSec,
     TIntArrayList quantity,
     TLongArrayList quantityTimeMillSec) {
   this(
       portfolio,
       assetName,
       price.toArray(),
       priceTimeMillSec.toArray(),
       quantity.toArray(),
       quantityTimeMillSec.toArray());
 }
コード例 #5
0
  /**
   * Add all tiles in the visible perspective below one location to the list of unchecked tiles
   * again.
   *
   * @param searchLoc the location the search starts add. This location is not added to the list of
   *     unchecked tiles
   * @param limit the limit the Z coordinate is not going below
   */
  private void addAllBelow(final Location searchLoc, final int limit) {
    int currX = searchLoc.getScX();
    int currY = searchLoc.getScY();
    int currZ = searchLoc.getScZ();

    while (currZ >= limit) {
      currX += MapDisplayManager.TILE_PERSPECTIVE_OFFSET;
      currY -= MapDisplayManager.TILE_PERSPECTIVE_OFFSET;
      currZ--;
      final long foundKey = Location.getKey(currX, currY, currZ);
      synchronized (unchecked) {
        if (!unchecked.contains(foundKey)) {
          unchecked.add(foundKey);
        }
      }
    }
  }
コード例 #6
0
  /**
   * Perform a check if the player character is inside a building. In case the inside status differs
   * for any level from the state before the check, all tiles are added to the list of tiles that
   * need to be checked once more.
   */
  private void performInsideCheck() {
    if (!checkInside) {
      return;
    }

    checkInside = false;

    final Location playerLoc = World.getPlayer().getLocation();
    final int currX = playerLoc.getScX();
    final int currY = playerLoc.getScY();
    int currZ = playerLoc.getScZ();
    boolean nowOutside = false;
    boolean isInside = false;

    for (int i = 0; i < 2; ++i) {
      currZ++;
      if (isInside || (parent.isMapAt(currX, currY, currZ))) {
        if (!insideStates[i]) {
          insideStates[i] = true;
          synchronized (unchecked) {
            unchecked.add(Location.getKey(currX, currY, currZ));
          }
        }
        isInside = true;
      } else {
        if (insideStates[i]) {
          insideStates[i] = false;
          nowOutside = true;
        }
      }
    }

    /*
     * If one of the values turned from inside to outside, all tiles are
     * added to the list to be checked again.
     */
    if (nowOutside) {
      synchronized (unchecked) {
        unchecked.clear();
        parent.processTiles(this);
      }
    }

    World.getWeather().setOutside(!isInside);
  }
コード例 #7
0
 /** This method starts or resumes the map processor. */
 @Override
 public synchronized void start() {
   pauseLoop = false;
   if (running) {
     synchronized (unchecked) {
       unchecked.notify();
     }
   } else {
     running = true;
     super.start();
   }
 }
コード例 #8
0
ファイル: QuartzJobStore.java プロジェクト: piyush76/EMS
  /**
   * Selects a customerId from among customers that (have a positive preferred weighting) and (have
   * pending tasks), picking according to their preferred weightings. If there are no such
   * customers, this method returns -1.
   */
  private long getPreferredCustomerId() {
    int preferredCount = m_preferredWeightsByCustomer.size();
    if (preferredCount <= 0) {
      return -1L;
    }
    final TLongArrayList custIds = new TLongArrayList(preferredCount);
    final TDoubleArrayList weights = new TDoubleArrayList(preferredCount);
    m_preferredWeightsByCustomer.forEachKey(
        new TLongProcedure() {
          public boolean execute(long value) {
            if (m_taskCountsByCustomer.get(value) > 0) {
              custIds.add(value);
              weights.add((double) m_preferredWeightsByCustomer.get(value));
            }
            return true;
          }
        });

    if (custIds.isEmpty()) {
      return -1L;
    }
    return custIds.get(WeightedRandom.selectRandomBucket(weights.toArray()));
  }
コード例 #9
0
  /**
   * Add all tiles surrounding this location and the tile above to the list of unchecked tiles.
   *
   * @param searchLoc the location of the start of the search.
   */
  private void addAllNeighbours(final Location searchLoc) {
    for (int x = -1; x < 2; x++) {
      for (int y = -1; y < 2; y++) {
        if ((x == 0) && (y == 0)) {
          continue;
        }
        final long foundKey =
            Location.getKey(searchLoc.getScX() + x, searchLoc.getScY() + y, searchLoc.getScZ());
        synchronized (unchecked) {
          if (!unchecked.contains(foundKey)) {
            unchecked.add(foundKey);
          }
        }
      }
    }

    final long foundKey =
        Location.getKey(searchLoc.getScX(), searchLoc.getScY(), searchLoc.getScZ() + 1);
    synchronized (unchecked) {
      if (!unchecked.contains(foundKey)) {
        unchecked.add(foundKey);
      }
    }
  }
コード例 #10
0
 private void readRouteTreeData(
     RouteSubregion routeTree,
     TLongArrayList idTables,
     TLongObjectHashMap<TLongArrayList> restrictions)
     throws IOException {
   routeTree.dataObjects = new ArrayList<RouteDataObject>();
   idTables.clear();
   restrictions.clear();
   List<String> stringTable = null;
   while (true) {
     int t = codedIS.readTag();
     int tag = WireFormat.getTagFieldNumber(t);
     switch (tag) {
       case 0:
         TLongObjectIterator<TLongArrayList> it = restrictions.iterator();
         while (it.hasNext()) {
           it.advance();
           int from = (int) it.key();
           RouteDataObject fromr = routeTree.dataObjects.get(from);
           fromr.restrictions = new long[it.value().size()];
           for (int k = 0; k < fromr.restrictions.length; k++) {
             int to = (int) (it.value().get(k) >> RouteDataObject.RESTRICTION_SHIFT);
             long valto =
                 (idTables.get(to) << RouteDataObject.RESTRICTION_SHIFT)
                     | ((long) it.value().get(k) & RouteDataObject.RESTRICTION_MASK);
             fromr.restrictions[k] = valto;
           }
         }
         for (RouteDataObject o : routeTree.dataObjects) {
           if (o != null) {
             if (o.id < idTables.size()) {
               o.id = idTables.get((int) o.id);
             }
             if (o.names != null && stringTable != null) {
               int[] keys = o.names.keys();
               for (int j = 0; j < keys.length; j++) {
                 o.names.put(keys[j], stringTable.get(o.names.get(keys[j]).charAt(0)));
               }
             }
           }
         }
         return;
       case RouteDataBlock.DATAOBJECTS_FIELD_NUMBER:
         int length = codedIS.readRawVarint32();
         int oldLimit = codedIS.pushLimit(length);
         RouteDataObject obj =
             readRouteDataObject(routeTree.routeReg, routeTree.left, routeTree.top);
         while (obj.id >= routeTree.dataObjects.size()) {
           routeTree.dataObjects.add(null);
         }
         routeTree.dataObjects.set((int) obj.id, obj);
         codedIS.popLimit(oldLimit);
         break;
       case RouteDataBlock.IDTABLE_FIELD_NUMBER:
         long routeId = 0;
         length = codedIS.readRawVarint32();
         oldLimit = codedIS.pushLimit(length);
         idLoop:
         while (true) {
           int ts = codedIS.readTag();
           int tags = WireFormat.getTagFieldNumber(ts);
           switch (tags) {
             case 0:
               break idLoop;
             case IdTable.ROUTEID_FIELD_NUMBER:
               routeId += codedIS.readSInt64();
               idTables.add(routeId);
               break;
             default:
               skipUnknownField(ts);
               break;
           }
         }
         codedIS.popLimit(oldLimit);
         break;
       case RouteDataBlock.RESTRICTIONS_FIELD_NUMBER:
         length = codedIS.readRawVarint32();
         oldLimit = codedIS.pushLimit(length);
         long from = 0;
         long to = 0;
         long type = 0;
         idLoop:
         while (true) {
           int ts = codedIS.readTag();
           int tags = WireFormat.getTagFieldNumber(ts);
           switch (tags) {
             case 0:
               break idLoop;
             case RestrictionData.FROM_FIELD_NUMBER:
               from = codedIS.readInt32();
               break;
             case RestrictionData.TO_FIELD_NUMBER:
               to = codedIS.readInt32();
               break;
             case RestrictionData.TYPE_FIELD_NUMBER:
               type = codedIS.readInt32();
               break;
             default:
               skipUnknownField(ts);
               break;
           }
         }
         if (!restrictions.containsKey(from)) {
           restrictions.put(from, new TLongArrayList());
         }
         restrictions.get(from).add((to << RouteDataObject.RESTRICTION_SHIFT) + type);
         codedIS.popLimit(oldLimit);
         break;
       case RouteDataBlock.STRINGTABLE_FIELD_NUMBER:
         length = codedIS.readRawVarint32();
         oldLimit = codedIS.pushLimit(length);
         stringTable = map.readStringTable();
         //				codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
         codedIS.popLimit(oldLimit);
         break;
       default:
         skipUnknownField(t);
         break;
     }
   }
 }
コード例 #11
0
 /** Stop this thread as soon as possible. */
 public void saveShutdown() {
   running = false;
   synchronized (unchecked) {
     unchecked.notify();
   }
 }
コード例 #12
0
  /**
   * Procedure function that is used to collect data from the map of the game.
   *
   * <p>Do not call this function from any other class.
   */
  @Override
  public boolean execute(final long key, final MapTile tile) {
    unchecked.add(key);

    return true;
  }
コード例 #13
0
 /**
  * Clear the map, that should be done in case all tiles got removed from the map and the current
  * checks need to stop instantly.
  */
 public void clear() {
   synchronized (unchecked) {
     unchecked.clear();
   }
 }
コード例 #14
0
 public Position(
     Portfolio portfolio, String assetName, TIntArrayList quantity, TLongArrayList timeMillSec) {
   this(portfolio, assetName, quantity.toArray(), timeMillSec.toArray());
 }
コード例 #15
0
 public Metric setPositionQuantity(TDoubleArrayList quantityD, TLongArrayList timeMillesc) {
   return setPositionQuantity(quantityD.toArray(), timeMillesc.toArray());
 }
コード例 #16
0
 public Metric setPositionQuantity(TIntArrayList quantity, TLongArrayList timeMillesc) {
   return setPositionQuantity(quantity.toArray(), timeMillesc.toArray());
 }