コード例 #1
0
 private void packCoordinates(LandTile tile, int index) {
   // lat and lon rounded to 2 decimal places
   int packedLatLon = 0;
   int roundedLat = Math.round(tile.getLatitude() * 100);
   int roundedLon = Math.round(tile.getLongitude() * 100);
   // pack lat onto first 16 bits, lon onto next 16 bits
   packedLatLon |= (roundedLat << 0);
   packedLatLon |= (roundedLon << 16);
   PACKED_TILE_COORDINATES[index] = packedLatLon;
 }
コード例 #2
0
  private void packRatings(LandTile tile, int index) {
    // 3 bytes to store 12 crop ratings
    byte packedRating1 = 0;
    byte packedRating2 = 0;
    byte packedRating3 = 0;

    for (int i = 0; i < 4; i++) {
      packedRating1 |= (tile.getCropRatings()[i].ordinal() << (6 - 2 * i));
      packedRating2 |= (tile.getCropRatings()[i + 4].ordinal() << (6 - 2 * i));
      packedRating3 |= (tile.getCropRatings()[i + 8].ordinal() << (6 - 2 * i));
    }

    int realIndex = index * 3;
    PACKED_CROP_RATINGS[realIndex] = packedRating1;
    PACKED_CROP_RATINGS[realIndex + 1] = packedRating2;
    PACKED_CROP_RATINGS[realIndex + 2] = packedRating3;
  }