mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-28 20:55:44 +00:00
Reduce water-crossing analysis overhead (#8784)
This commit is contained in:
@@ -147,10 +147,15 @@ auto UnitIdsRequiringWaterCrossing(
|
||||
const LandRegions &landRegions,
|
||||
const APDCache &apdCache,
|
||||
const BattalionTypeGetter &battalionTypeGetter) -> vector<UnitId> {
|
||||
const GameState *state = gameState.Get();
|
||||
const auto *units = state->units();
|
||||
const HexMap *map = state->hex_map();
|
||||
|
||||
std::vector<const net::eagle0::shardok::storage::fb::Unit *> unitsToCheck{};
|
||||
unitsToCheck.reserve(units->size());
|
||||
std::array<int8_t, 9> startingPositionIndices{};
|
||||
startingPositionIndices.fill(-1);
|
||||
for (const auto *unit : *gameState->units()) {
|
||||
for (const auto *unit : *units) {
|
||||
if (unit->player_id() != pid) continue;
|
||||
|
||||
if (unit->status() == net::eagle0::shardok::storage::fb::UnitStatus_NORMAL_UNIT) {
|
||||
@@ -160,8 +165,7 @@ auto UnitIdsRequiringWaterCrossing(
|
||||
} else if (unit->status() == net::eagle0::shardok::storage::fb::UnitStatus_RESERVE_UNIT) {
|
||||
if (startingPositionIndices[unit->starting_position_index()] == -1) {
|
||||
startingPositionIndices[unit->starting_position_index()] = 0;
|
||||
const auto *startingPositions = gameState->hex_map()
|
||||
->attacker_starting_positions()
|
||||
const auto *startingPositions = map->attacker_starting_positions()
|
||||
->Get(unit->starting_position_index())
|
||||
->positions();
|
||||
for (const Coords *position : *startingPositions) {
|
||||
@@ -179,7 +183,6 @@ auto UnitIdsRequiringWaterCrossing(
|
||||
}
|
||||
if (unitsToCheck.empty()) return {};
|
||||
|
||||
const HexMap *map = gameState->hex_map();
|
||||
MapId mapId = ActionPointDistancesCache::GetMapId(map);
|
||||
const bool staticRegionsCanProveDisconnection = !HasTraversableRegionBoundaryModifier(map);
|
||||
|
||||
@@ -218,6 +221,7 @@ auto UnitIdsRequiringWaterCrossing(
|
||||
};
|
||||
|
||||
vector<UnitId> unitIdsToReturn{};
|
||||
unitIdsToReturn.reserve(unitsToCheck.size());
|
||||
|
||||
// The static region pass above removed every unit that is definitely able to reach every
|
||||
// destination without water. Resolve full APDs only for the inconclusive units.
|
||||
@@ -245,8 +249,7 @@ auto UnitIdsRequiringWaterCrossing(
|
||||
if (startingPositionIndices[unit->starting_position_index()] == -1) {
|
||||
startingPositionIndices[unit->starting_position_index()] = 0;
|
||||
const auto *distances = distancesFor(battType);
|
||||
const auto *startingPositions = gameState->hex_map()
|
||||
->attacker_starting_positions()
|
||||
const auto *startingPositions = map->attacker_starting_positions()
|
||||
->Get(unit->starting_position_index())
|
||||
->positions();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user