Index: source/simulation2/components/CCmpRangeManager.cpp =================================================================== --- source/simulation2/components/CCmpRangeManager.cpp +++ source/simulation2/components/CCmpRangeManager.cpp @@ -790,6 +790,7 @@ if (oldPlayerCounts != m_LosPlayerCounts) { + std::vector> errors; for (size_t id = 0; id < m_LosPlayerCounts.size(); ++id) { debug_printf("player %li\n", id); @@ -806,10 +807,16 @@ for (size_t i = 0; i < m_LosPlayerCounts[id].width(); ++i) { for (size_t j = 0; j < m_LosPlayerCounts[id].height(); ++j) + { + if (m_LosPlayerCounts[id].get(i,j) != oldPlayerCounts[id].get(i,j)) + errors.push_back({i, j}); debug_printf("%i ", m_LosPlayerCounts[id].get(i,j)); + } debug_printf("\n"); } } + for (std::pair err : errors) + debug_printf("Error: %i, %i\n", err.first, err.second); debug_warn(L"inconsistent player counts"); } if (oldStateRevealed != m_LosStateRevealed) @@ -2212,11 +2219,11 @@ entity_pos_t dy2 = dy.Square(); while (dy2 + (entity_pos_t::FromInt(i0-1) - x).Square() <= r2) --i0; - while (i0 < xceil && i0 < i1 - 1 && dy2 + (entity_pos_t::FromInt(i0) - x).Square() > r2) + while (i0 < i1 - 1 && i0 < xceil && dy2 + (entity_pos_t::FromInt(i0) - x).Square() > r2) ++i0; while (dy2 + (entity_pos_t::FromInt(i1+1) - x).Square() <= r2) ++i1; - while (i1 > xfloor && i1 - 1 > i0 && dy2 + (entity_pos_t::FromInt(i1) - x).Square() > r2) + while (i1 - 1 > i0 && i1 > xfloor && dy2 + (entity_pos_t::FromInt(i1) - x).Square() > r2) --i1; #if DEBUG_RANGE_MANAGER_BOUNDS @@ -2267,8 +2274,12 @@ i32 j0_from = ((from.Y - visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToInfinity(); i32 j1_from = ((from.Y + visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity(); + if (j1_from <= j0_from) + j1_from = j0_from + 1; i32 j0_to = ((to.Y - visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToInfinity(); i32 j1_to = ((to.Y + visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity(); + if (j1_to <= j0_to) + j1_to = j0_to + 1; i32 j0clamp = std::max(std::min(j0_from, j0_to), 1); i32 j1clamp = std::min(std::max(j1_from, j1_to), m_TerrainVerticesPerSide-2); @@ -2291,26 +2302,36 @@ for (i32 j = j0clamp; j <= j1clamp; ++j) { + if (j == j0_from) + { + i0_from = xfloor_from; + i1_from = xceil_from; + } + if (j == j0_to) + { + i0_to = xfloor_to; + i1_to = xceil_to; + } entity_pos_t dy_from = entity_pos_t::FromInt(j) - y_from; entity_pos_t dy2_from = dy_from.Square(); while (dy2_from + (entity_pos_t::FromInt(i0_from-1) - x_from).Square() <= r2) --i0_from; - while (i0_from < xceil_from && dy2_from + (entity_pos_t::FromInt(i0_from) - x_from).Square() > r2) + while ((j < j0_from || j > j1_from || i0_from < i1_from - 1) && i0_from < xceil_from && dy2_from + (entity_pos_t::FromInt(i0_from) - x_from).Square() > r2) ++i0_from; while (dy2_from + (entity_pos_t::FromInt(i1_from+1) - x_from).Square() <= r2) ++i1_from; - while (i1_from > xfloor_from && dy2_from + (entity_pos_t::FromInt(i1_from) - x_from).Square() > r2) + while ((j < j0_from || j > j1_from || i0_from < i1_from - 1) && i1_from > xfloor_from && dy2_from + (entity_pos_t::FromInt(i1_from) - x_from).Square() > r2) --i1_from; entity_pos_t dy_to = entity_pos_t::FromInt(j) - y_to; entity_pos_t dy2_to = dy_to.Square(); while (dy2_to + (entity_pos_t::FromInt(i0_to-1) - x_to).Square() <= r2) --i0_to; - while (i0_to < xceil_to && dy2_to + (entity_pos_t::FromInt(i0_to) - x_to).Square() > r2) + while ((j < j0_to || j > j1_to || i0_to < i1_to - 1) && i0_to < xceil_to && dy2_to + (entity_pos_t::FromInt(i0_to) - x_to).Square() > r2) ++i0_to; while (dy2_to + (entity_pos_t::FromInt(i1_to+1) - x_to).Square() <= r2) ++i1_to; - while (i1_to > xfloor_to && dy2_to + (entity_pos_t::FromInt(i1_to) - x_to).Square() > r2) + while ((j < j0_to || j > j1_to || i0_to < i1_to - 1) && i1_to > xfloor_to && dy2_to + (entity_pos_t::FromInt(i1_to) - x_to).Square() > r2) --i1_to; #if DEBUG_RANGE_MANAGER_BOUNDS