Page MenuHomeWildfire Games

TerritoryManager does not update the blinking territories when recomputing the territories
ClosedPublic

Authored by mimo on Sep 15 2017, 8:51 PM.

Details

Reviewers
leper
Itms
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Commits
rP20268: Add a TerritoryDecayManager component to update territoryMap with the blinking…
Summary

TerritoryManager does not update the blinking territories when recomputed: this is done only by the entities TerritoryDecay components in the next turn. And that is problem for the AI as the TerritoryMap is cloned just after being recomputed, so that the AI is never aware of blinking cells, but could also have other consequences in the simulation as the blinking cells are forbidden in the BuildRestrictions component.
This is fixed in the patch which adds a scripted component to TerritoryDecay to allow for an update in the TerritoryManager component.

Test Plan

Check for example that without the patch the territoryMap sent to the AI in CCmpAIManager never have the blinking bit set for any tile, while it is correct with the patch.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

mimo created this revision.Sep 15 2017, 8:51 PM
Owners added a subscriber: Restricted Owners Package.Sep 15 2017, 8:51 PM
elexis added a subscriber: elexis.Sep 15 2017, 9:11 PM

Sounds a lot like #4681

Vulcan added a subscriber: Vulcan.Sep 15 2017, 9:39 PM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...

http://jenkins-master:8080/job/phabricator/2032/ for more details.

Executing section Default...
Executing section Source...
Executing section JS...

binaries/data/mods/public/simulation/components/TerritoryDecay.js
|  31| »   if·(tileOwner·==·0)
|    | [NORMAL] JSHintBear:
|    | Use '===' to compare with '0'.

binaries/data/mods/public/simulation/components/TerritoryDecay.js
|  34| »   »   return·cmpPlayer.GetPlayerID()·==·0;·//·Gaia·building·on·gaia·ground·->·don't·decay
|    | [NORMAL] JSHintBear:
|    | Use '===' to compare with '0'.
Executing section XML GUI...
Executing section Python...
Executing section Perl...

http://jenkins-master:8080/job/phabricator_lint/524/ for more details.

The loop could be somewhat expensive, though probably not that bad. And if it turns out to be we could still make some sort of DecayManager that gets the list of entities passed to JS and then calls the individual ones there. (Would avoid the C++-JS call overhead, but I assume that that is either not that expensive or there are worse offenders.)

source/simulation2/components/CCmpTerritoryManager.cpp
88 ↗(On Diff #3671)

Nice catch.

548 ↗(On Diff #3671)

Could just static_cast it to ICmpTerritoryDecay* as a few others do, and then inline the call.

Since at least a few other callers of GetEntitiesWithInterface{,Unordered} do assume that the pointer is valid (which I do hope we ensure in the ComponentManager), and you also seem to assume since there is no if (cmpTerritoryDecay) below.

So the whole body of the loop could be static_cast<ICmpTerritoryDecay*>(pair.second)->SetBlinkingState();

mimo updated this revision to Diff 3699.Sep 17 2017, 7:25 PM
mimo edited the test plan for this revision. (Show Details)

Update patch

mimo added a comment.Sep 17 2017, 7:30 PM
In D910#35595, @leper wrote:

The loop could be somewhat expensive, though probably not that bad. And if it turns out to be we could still make some sort of DecayManager that gets the list of entities passed to JS and then calls the individual ones there. (Would avoid the C++-JS call overhead, but I assume that that is either not that expensive or there are worse offenders.)

In fact, to ease future changes, I've added a TerritoryDecayManager instead of extending the TerritoryDecay component.
I also add to change a bit the way the grid is updated in CmpAIManager as it should also be reloaded when blinking changed without territory changes (as when diplomacy changes).

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...

http://jenkins-master:8080/job/phabricator/2044/ for more details.

Executing section Default...
Executing section Source...
Executing section JS...
Executing section XML GUI...
Executing section Python...
Executing section Perl...

http://jenkins-master:8080/job/phabricator_lint/531/ for more details.

Also sounds like it would fix #4787 (according to borg- one can always build a tower near a captured barracks)

mimo added a comment.Oct 7 2017, 10:37 AM

As this patch is needed by the AI, i'm going to commit it. Feel free to raise a concern is needed.
In a following patch, i'll cache the list of TerritoryDecay components in the new TerritoryDecayManager to avoid having to retrieve it each time the blinking states are updated.

This revision was automatically updated to reflect the committed changes.