Page MenuHomeWildfire Games

Cleanup of Capturable
ClosedPublic

Authored by bb on Jun 20 2020, 11:12 PM.

Details

Summary

Cleanup of Capturable

var => let
periods, caps
JSdocs where useful
don't get the hitpoints twice

Test Plan

Let the bots run

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

bb created this revision.Jun 20 2020, 11:12 PM
Stan added a subscriber: Stan.Jun 20 2020, 11:18 PM
Stan added inline comments.
binaries/data/mods/public/simulation/components/Capturable.js
205 ↗(On Diff #12403)

One too much?

Freagarach added inline comments.
binaries/data/mods/public/simulation/components/Capturable.js
47 ↗(On Diff #12403)

with

56 ↗(On Diff #12403)

capture points?

59 ↗(On Diff #12403)

multiplied

60 ↗(On Diff #12403)

s/,/.

182 ↗(On Diff #12403)

Perhaps "best player" could be elaborated ;)

230 ↗(On Diff #12403)

Comment on top?

246 ↗(On Diff #12403)

Comment necessary?

249 ↗(On Diff #12403)

Delete?

337 ↗(On Diff #12403)

Comment on top?

355–356 ↗(On Diff #12403)

(Seems like one sentence?)

bb updated this revision to Diff 12407.Jun 21 2020, 5:19 PM
bb marked 8 inline comments as done.
bb added inline comments.
binaries/data/mods/public/simulation/components/Capturable.js
60 ↗(On Diff #12403)

Not really

246 ↗(On Diff #12403)

Someone might be wondering why we remove a timer.

355–356 ↗(On Diff #12403)

Not really, but can make it into one more clear sentence

bb edited the summary of this revision. (Show Details)Jun 21 2020, 5:46 PM
Freagarach added inline comments.Jun 21 2020, 7:16 PM
binaries/data/mods/public/simulation/components/Capturable.js
16 ↗(On Diff #12407)

Comment seems outdated (also recalculated onValueModification). Is it needed?

57 ↗(On Diff #12407)

capturing? Do you "attack" an entity of your ally when taking capture points?

136 ↗(On Diff #12407)

let?

151 ↗(On Diff #12407)

let?

214 ↗(On Diff #12407)

let

60 ↗(On Diff #12403)

Ah yeah,,,

Stan added inline comments.Jun 21 2020, 11:00 PM
binaries/data/mods/public/simulation/components/Capturable.js
183 ↗(On Diff #12407)
Maybe it could be this.cp.filter(cp => cp >= this.cp[bestPlayer]).length
bb updated this revision to Diff 12430.Jun 22 2020, 11:01 PM
bb marked 5 inline comments as done and an inline comment as not done.

Note that I deliberately avoided the cmpOwnership.GetOwner calls, the need a slightly more subtle care

bb added inline comments.Jun 23 2020, 2:47 PM
binaries/data/mods/public/simulation/components/Capturable.js
57 ↗(On Diff #12407)

In fact you do

183 ↗(On Diff #12407)

How? we want to find the index of cp with greatest value, maybe you mean
this.cp.reduce((bestPlayer, playerCp, player, cp) => playerCp > cp[bestPlayer] ? player : bestPlayer, 0)

bb updated this revision to Diff 12436.Jun 23 2020, 6:42 PM

Let the bots run!!

Build failure - The Moirai have given mortals hearts that can endure.

Linter detected issues:
Executing section Source...
Executing section JS...
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
|  19|  19| 	this.cp = [];
|  20|  20| };
|  21|  21| 
|  22|    |-//// Interface functions ////
|    |  22|+// // Interface functions ////
|  23|  23| 
|  24|  24| /**
|  25|  25|  * Returns the current capture points array.
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
| 159| 159| 	return sourceEnemyCp > 0;
| 160| 160| };
| 161| 161| 
| 162|    |-//// Private functions ////
|    | 162|+// // Private functions ////
| 163| 163| 
| 164| 164| /**
| 165| 165|  * This has to be called whenever the capture points are changed.
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
| 301| 301| 		this.CheckTimer();
| 302| 302| };
| 303| 303| 
| 304|    |-//// Message Listeners ////
|    | 304|+// // Message Listeners ////
| 305| 305| 
| 306| 306| Capturable.prototype.OnValueModification = function(msg)
| 307| 307| {
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/2510/display/redirect

wraitii added inline comments.
binaries/data/mods/public/simulation/components/Capturable.js
46 ↗(On Diff #12436)

I'd prefer you explicated that this is one value per player, and if one must pass the player? Or just pass one value for all players.

69 ↗(On Diff #12436)

I'm coming up with bonusMultiplier *= 0.1 + 0.9 * hitpoints / cmpHealth.GetMaxHitpoints() when I do the factoring?

185 ↗(On Diff #12436)

Have you profiled this to be faster? I would call it less readable.

bb marked an inline comment as done.Jul 21 2020, 8:17 PM
bb added inline comments.
binaries/data/mods/public/simulation/components/Capturable.js
69 ↗(On Diff #12436)

bonusMultiplier *= cmpHealth.GetMaxHitpoints() / (0.1 * cmpHealth.GetMaxHitpoints() + 0.9 * cmpHealth.GetHitpoints())
cancelling cmpHealth.GetMaxHitpoints() up and downstairs gives
bonusMultiplier *= 1 / (0.1+ 0.9 * cmpHealth.GetHitpoints()/ cmpHealth.GetMaxHitpoints())
Gives:
bonusMultiplier /= 0.1+ 0.9 * cmpHealth.GetHitpoints()/ cmpHealth.GetMaxHitpoints()

Where is my mistake?

185 ↗(On Diff #12436)

I did now: the proposed code gives a 4-5x improvement

bb updated this revision to Diff 12838.Jul 21 2020, 8:18 PM

comment

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

Linter detected issues:
Executing section Source...
Executing section JS...
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
|  19|  19| 	this.cp = [];
|  20|  20| };
|  21|  21| 
|  22|    |-//// Interface functions ////
|    |  22|+// // Interface functions ////
|  23|  23| 
|  24|  24| /**
|  25|  25|  * Returns the current capture points array.
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
| 159| 159| 	return sourceEnemyCp > 0;
| 160| 160| };
| 161| 161| 
| 162|    |-//// Private functions ////
|    | 162|+// // Private functions ////
| 163| 163| 
| 164| 164| /**
| 165| 165|  * This has to be called whenever the capture points are changed.
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/components/Capturable.js
| 301| 301| 		this.CheckTimer();
| 302| 302| };
| 303| 303| 
| 304|    |-//// Message Listeners ////
|    | 304|+// // Message Listeners ////
| 305| 305| 
| 306| 306| Capturable.prototype.OnValueModification = function(msg)
| 307| 307| {
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/2742/display/redirect

This revision was not accepted when it landed; it landed in state Needs Review.Jul 23 2020, 3:47 PM
Closed by commit rP23875: Cleanup of Capturable component (authored by bb). · Explain Why
This revision was automatically updated to reflect the committed changes.