void CoarseConvFeaturizerUnitTypes::featurize_invfow()

in featurizers/coarse_conv_featurizer_units.cpp [207:259]


void CoarseConvFeaturizerUnitTypes::featurize_invfow(
    Feature& feature,
    Reduced* rframe,
    int32_t perspective,
    TilesInfo& tinfo,
    FogOfWar& fow) const {
  auto urframe = reinterpret_cast<ReducedUnitTypes*>(rframe);
  assert(urframe != nullptr);

  for (auto& u : urframe->units[perspective]) {
    auto range = tc::BW::data::SightRange[u.type] / tc::BW::XYPixelsPerWalktile;
    auto isFlyer = tc::BW::data::IsFlyer[u.type];
    // XXX Cannot account for lifted units right now since unit flags are not
    // part of the reduced frame data.
    fow.revealSightAt(tinfo, u.x, u.y, range, isFlyer,
        0 /* Don't care about frame numbers */);
  }

  // Pool into feature bins. Every bin for which we have at least 50% build tile
  // visibility will be marked as visible
  assert(resX % 4 == 0);
  assert(resY % 4 == 0);
  assert(strideX % 4 == 0);
  assert(strideY % 4 == 0);
  int32_t nBinY = feature.size();
  int32_t nBinX = feature[0].size();
  int32_t startTileX = 0;
  for (int32_t x = 0; x < nBinX; x++) {
    int32_t endTileX = std::min(tinfo.mapTileWidth, unsigned(startTileX + resX/4));
    int32_t startTileY = 0;
    for (int32_t y = 0; y < nBinY; y++) {
      int32_t endTileY = std::min(tinfo.mapTileHeight, unsigned(startTileY + resY/4));

      int32_t countvis = 0;
      for (int32_t tx = startTileX; tx < endTileX; tx++) {
        for (int32_t ty = startTileY; ty < endTileY; ty++) {
          auto& tt = tinfo.tiles[TilesInfo::tilesWidth * ty + tx];
          if (tt.visible) {
            countvis++;
          } else {
            countvis--;
          }
        }
      }
      if (countvis > 0) {
        feature[y][x][0] = 1;
      }

      startTileY += strideY/4;
    }
    startTileX += strideX/4;
  }
}