Page MenuHomeWildfire Games

Hide Formation panel if all formations are disabled
ClosedPublic

Authored by elexis on Mar 5 2017, 7:50 AM.

Details

Summary

Currently we have a hardcoded check in the JS GUI to hide the formation panel if and only if the selected unit is not an animal or not a unit.
So if we selected a unit that has no formation available and is not a domestic animal, then we have a panel full of disabled buttons.
If a mod decides to implement animals (dogs? goose https://www.youtube.com/watch?v=inZTfHW2MxA ? starcraft clone?) and decides to give them a formation,
the formation panel will be hidden.

Code should be as versatile as possible.
We don't need this hardcoded animal check at all and can hide the panel if and only if no formations can be selected.

For the same reason one could argue that the test for the Unit class can be removed too.
Using D190 we can measure whether the test helps with performance (functionality wise it is not needed) by
adding the following code to the patched function after the declaration of availableFormation:

let t1 = Engine.GetMicroSeconds();
unitEntStates.some(state => !hasClass(state, "Unit"))
let t2 = Engine.GetMicroSeconds();
availableFormations.some(formation => canMoveSelectionIntoFormation(formation))
warn("unitEntStates " + ("0000000000" + (Engine.GetMicroSeconds() - t2)).slice(-10) + " canMoveSelectionIntoFormation " + ("000000000" + (t2 - t1)).slice(-10));

Then start the game with "unlimited" population and use the "salad bowl <number>" cheat to spawn many units.

Observeration:

WARNING: unitEntStates 0000000859 canMoveSelectionIntoFormation 0000000038
WARNING: unitEntStates 0000000005 canMoveSelectionIntoFormation 0000000042
WARNING: unitEntStates 0000000005 canMoveSelectionIntoFormation 0000000036
WARNING: unitEntStates 0000000005 canMoveSelectionIntoFormation 0000000049
WARNING: unitEntStates 0000000005 canMoveSelectionIntoFormation 0000000025
WARNING: unitEntStates 0000000004 canMoveSelectionIntoFormation 0000000027
WARNING: unitEntStates 0000000005 canMoveSelectionIntoFormation 0000000034
WARNING: unitEntStates 0000000005 canMoveSelectionIntoFormation 0000000035
WARNING: unitEntStates 0000000004 canMoveSelectionIntoFormation 0000000020
WARNING: unitEntStates 0000000004 canMoveSelectionIntoFormation 0000000021
WARNING: unitEntStates 0000000005 canMoveSelectionIntoFormation 0000000030
WARNING: unitEntStates 0000000005 canMoveSelectionIntoFormation 0000000096
WARNING: unitEntStates 0000000004 canMoveSelectionIntoFormation 0000000035
WARNING: unitEntStates 0000000011 canMoveSelectionIntoFormation 0000000061
WARNING: unitEntStates 0000000004 canMoveSelectionIntoFormation 0000000024
WARNING: unitEntStates 0000000005 canMoveSelectionIntoFormation 0000000024
WARNING: unitEntStates 0000000005 canMoveSelectionIntoFormation 0000000028
WARNING: unitEntStates 0000000005 canMoveSelectionIntoFormation 0000000028
WARNING: unitEntStates 0000000958 canMoveSelectionIntoFormation 0000000091
WARNING: unitEntStates 0000000012 canMoveSelectionIntoFormation 0000000047

So the first time we select the units unitEntStates is much much slower (900 microsec), for every following call canMoveSelectionIntoFormation is about 3 to t times slower (10 microsec vs 50 microsec).
Therefore we can keep the Unit check if we are strict about the performance. Code-wise it still seems unneeded.

Test Plan

Read the functions and see functional equivalence, do an ingame test and see that it's hidden for sheep and visible for all military units.
Notice it's now also hidden for women.

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

elexis created this revision.Mar 5 2017, 7:50 AM
Vulcan added a subscriber: Vulcan.Mar 5 2017, 9:02 AM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (302 tests)..............................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (302 tests)..............................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/468/ for more details.

This diff consists of just an unmodified version of ScriptFunctions.cpp?

elexis updated this revision to Diff 736.Mar 8 2017, 1:53 AM

Actually upload the patch

Vulcan added a comment.Mar 8 2017, 2:57 AM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (302 tests)..............................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (302 tests)..............................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/483/ for more details.

elexis added a reviewer: mimo.Mar 17 2017, 4:19 PM
mimo accepted this revision.Mar 17 2017, 8:21 PM

Looks good to me.
Note that the behaviour is not identical in case you select both units and animals, the formations will now be shown while they were masked before. But that seems a better behaviour to me.

This revision is now accepted and ready to land.Mar 17 2017, 8:21 PM
This revision was automatically updated to reflect the committed changes.

Thanks for the review!