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

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
204

One too much?

Freagarach added inline comments.
binaries/data/mods/public/simulation/components/Capturable.js
47

with

56

capture points?

59

multiplied

60

s/,/.

180–181

Perhaps "best player" could be elaborated ;)

229–230

Comment on top?

246

Comment necessary?

249

Delete?

338

Comment on top?

356–358

(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

Not really

246

Someone might be wondering why we remove a timer.

356–358

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

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

57

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

60

Ah yeah,,,

136

let?

151

let?

214

let

Stan added inline comments.Jun 21 2020, 11:00 PM
binaries/data/mods/public/simulation/components/Capturable.js
183
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

In fact you do

183

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
47

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.

70

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

191

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
70

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?

191

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.