Page MenuHomeWildfire Games

Slight cleanup of Commands.js
ClosedPublic

Authored by temple on Dec 9 2017, 11:41 PM.

Details

Summary

After the Barter cleanup of rP20598, we no longer need cmpPlayerManager or playerEnt.

Test Plan

Includes a few other simplifications as well.

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

temple created this revision.Dec 9 2017, 11:41 PM
temple retitled this revision from Slightly cleanup of Commands.js to Slight cleanup of Commands.js.
elexis added a subscriber: elexis.Dec 9 2017, 11:52 PM
elexis added inline comments.
binaries/data/mods/public/simulation/helpers/Commands.js
7 ↗(On Diff #4681)

Do we use INVALID_PLAYER in about every ownershipchange event and not a single itme in JS?
Damn, so many -1 comparisons.

10 ↗(On Diff #4681)

I do recall someone liking that we save components getter calls here but also that this is a bad design pattern everywhere else. Maybe it's a good exception or this one should be removed too.

445 ↗(On Diff #4681)

meh, should have noticed

743 ↗(On Diff #4681)

(Good Change if its indeed the same playerID in any case)

Vulcan added a subscriber: Vulcan.Dec 10 2017, 2:29 AM

Successful build - Chance fights ever on the side of the prudent.

Updating workspaces...
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...
elexis accepted this revision.Dec 10 2017, 5:01 AM

Thanks

binaries/data/mods/public/simulation/helpers/Commands.js
7 ↗(On Diff #4681)

That < 0 is a bit unclean. If it's a common case that we get -1 then we should test against that.
If we get arbitrary numbers commonly, we might just as well rely on the condition below.

That an observer sends a simulation command should be as impossible as it can get.
A funny client may still send broken commands, but we don't have to optimize partially for that.

10 ↗(On Diff #4681)

Ok I'm not becoming friends with this data.cmpPlayer variable, but I fully agree with not deleting it in this diff. The more I appreciate that the data.cmpPlayerManager is removed. Either we do cache components everywhere where possible or nowhere IMO.

Also I'm adding 2 newlines, so that in case we ever add a second property, we will only have to change one character on that line and so that all objects I ever added have one line per property (code symmetry).

In fact we can add the controlAllUnits property here as well.
In fact I don't like the controlAllUnits cache either.
But I'm not going to rip it out now.

445 ↗(On Diff #4681)

(so this optimization goes contrary to what I would wish, but I dont mind)

700 ↗(On Diff #4681)

good

743 ↗(On Diff #4681)

(In particular accessing component variables directly is discouraged)

This revision is now accepted and ready to land.Dec 10 2017, 5:01 AM
This revision was automatically updated to reflect the committed changes.
temple added inline comments.Dec 10 2017, 5:22 AM
binaries/data/mods/public/simulation/helpers/Commands.js
7 ↗(On Diff #4681)

It's kinda weird in PlayerManager.GetPlayerByID, where it says:

	// All players at or below ID 0 get gaia-level data. (Observers for example)
	if (id <= 0)
		return this.playerEntities[0];

So it seemed like maybe there was some potential for observers to control gaia? That's why I played it safe and kept the player < 0 check. But I never actually tested if observers could do commands.

temple added inline comments.Dec 10 2017, 6:29 AM
binaries/data/mods/public/simulation/helpers/Commands.js
7 ↗(On Diff #4681)

Tested, seems they can't, so okay.