Little cleanup of gamesetup.
initSPtips function moved into g_MiscControls object.
Details
- Reviewers
elexis
.
Diff Detail
- Repository
- rP 0 A.D. Public Repository
- Lint
Lint Skipped - Unit
Unit Tests Skipped - Build Status
Buildable 6394 Build 10596: Vulcan Build Jenkins
Event Timeline
Successful build - Chance fights ever on the side of the prudent.
Linter detected issues: Executing section Default... Executing section Source... Executing section JS... | | [NORMAL] ESLintBear (indent): | | Expected indentation of 1 tab but found 2. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 62| 62| var g_RomanNumbers = [undefined, "I", "II", "III", "IV", "V", "VI", "VII", "VIII"]; | 63| 63| | 64| 64| var g_PlayerTeamList = prepareForDropdown([{ | 65| |- "label": translateWithContext("team", "None"), | | 65|+ "label": translateWithContext("team", "None"), | 66| 66| "id": -1 | 67| 67| }].concat( | 68| 68| Array(g_MaxTeams).fill(0).map((v, i) => ({ | | [NORMAL] ESLintBear (indent): | | Expected indentation of 1 tab but found 2. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 63| 63| | 64| 64| var g_PlayerTeamList = prepareForDropdown([{ | 65| 65| "label": translateWithContext("team", "None"), | 66| |- "id": -1 | | 66|+ "id": -1 | 67| 67| }].concat( | 68| 68| Array(g_MaxTeams).fill(0).map((v, i) => ({ | 69| 69| "label": i + 1, | | [NORMAL] ESLintBear (indent): | | Expected indentation of 0 tabs but found 1. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 64| 64| var g_PlayerTeamList = prepareForDropdown([{ | 65| 65| "label": translateWithContext("team", "None"), | 66| 66| "id": -1 | 67| |- }].concat( | | 67|+}].concat( | 68| 68| Array(g_MaxTeams).fill(0).map((v, i) => ({ | 69| 69| "label": i + 1, | 70| 70| "id": i | | [NORMAL] ESLintBear (indent): | | Expected indentation of 1 tab but found 2. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 65| 65| "label": translateWithContext("team", "None"), | 66| 66| "id": -1 | 67| 67| }].concat( | 68| |- Array(g_MaxTeams).fill(0).map((v, i) => ({ | | 68|+ Array(g_MaxTeams).fill(0).map((v, i) => ({ | 69| 69| "label": i + 1, | 70| 70| "id": i | 71| 71| })) | | [NORMAL] ESLintBear (indent): | | Expected indentation of 2 tabs but found 3. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 66| 66| "id": -1 | 67| 67| }].concat( | 68| 68| Array(g_MaxTeams).fill(0).map((v, i) => ({ | 69| |- "label": i + 1, | | 69|+ "label": i + 1, | 70| 70| "id": i | 71| 71| })) | 72| 72| ) | | [NORMAL] ESLintBear (indent): | | Expected indentation of 2 tabs but found 3. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 67| 67| }].concat( | 68| 68| Array(g_MaxTeams).fill(0).map((v, i) => ({ | 69| 69| "label": i + 1, | 70| |- "id": i | | 70|+ "id": i | 71| 71| })) | 72| 72| ) | 73| 73| ); | | [NORMAL] ESLintBear (indent): | | Expected indentation of 1 tab but found 2. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 68| 68| Array(g_MaxTeams).fill(0).map((v, i) => ({ | 69| 69| "label": i + 1, | 70| 70| "id": i | 71| |- })) | | 71|+ })) | 72| 72| ) | 73| 73| ); | 74| 74| | | [NORMAL] ESLintBear (indent): | | Expected indentation of 0 tabs but found 1. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 69| 69| "label": i + 1, | 70| 70| "id": i | 71| 71| })) | 72| |- ) | | 72|+) | 73| 73| ); | 74| 74| | 75| 75| /** | | [NORMAL] ESLintBear (indent): | | Expected indentation of 1 tab but found 2. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 78| 78| var g_RelicCountList = Object.keys(g_CivData).map((civ, i) => i + 1); | 79| 79| | 80| 80| var g_PlayerCivList = g_CivData && prepareForDropdown([{ | 81| |- "name": translateWithContext("civilization", "Random"), | | 81|+ "name": translateWithContext("civilization", "Random"), | 82| 82| "tooltip": translate("Picks one civilization at random when the game starts."), | 83| 83| "color": g_ColorRandom, | 84| 84| "code": "random" | | [NORMAL] ESLintBear (indent): | | Expected indentation of 1 tab but found 2. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 79| 79| | 80| 80| var g_PlayerCivList = g_CivData && prepareForDropdown([{ | 81| 81| "name": translateWithContext("civilization", "Random"), | 82| |- "tooltip": translate("Picks one civilization at random when the game starts."), | | 82|+ "tooltip": translate("Picks one civilization at random when the game starts."), | 83| 83| "color": g_ColorRandom, | 84| 84| "code": "random" | 85| 85| }].concat( | | [NORMAL] ESLintBear (indent): | | Expected indentation of 1 tab but found 2. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 80| 80| var g_PlayerCivList = g_CivData && prepareForDropdown([{ | 81| 81| "name": translateWithContext("civilization", "Random"), | 82| 82| "tooltip": translate("Picks one civilization at random when the game starts."), | 83| |- "color": g_ColorRandom, | | 83|+ "color": g_ColorRandom, | 84| 84| "code": "random" | 85| 85| }].concat( | 86| 86| Object.keys(g_CivData).filter( | | [NORMAL] ESLintBear (indent): | | Expected indentation of 1 tab but found 2. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 81| 81| "name": translateWithContext("civilization", "Random"), | 82| 82| "tooltip": translate("Picks one civilization at random when the game starts."), | 83| 83| "color": g_ColorRandom, | 84| |- "code": "random" | | 84|+ "code": "random" | 85| 85| }].concat( | 86| 86| Object.keys(g_CivData).filter( | 87| 87| civ => g_CivData[civ].SelectableInGameSetup | | [NORMAL] ESLintBear (indent): | | Expected indentation of 0 tabs but found 1. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 82| 82| "tooltip": translate("Picks one civilization at random when the game starts."), | 83| 83| "color": g_ColorRandom, | 84| 84| "code": "random" | 85| |- }].concat( | | 85|+}].concat( | 86| 86| Object.keys(g_CivData).filter( | 87| 87| civ => g_CivData[civ].SelectableInGameSetup | 88| 88| ).map(civ => ({ | | [NORMAL] ESLintBear (indent): | | Expected indentation of 1 tab but found 2. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 83| 83| "color": g_ColorRandom, | 84| 84| "code": "random" | 85| 85| }].concat( | 86| |- Object.keys(g_CivData).filter( | | 86|+ Object.keys(g_CivData).filter( | 87| 87| civ => g_CivData[civ].SelectableInGameSetup | 88| 88| ).map(civ => ({ | 89| 89| "name": g_CivData[civ].Name, | | [NORMAL] ESLintBear (indent): | | Expected indentation of 2 tabs but found 3. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 84| 84| "code": "random" | 85| 85| }].concat( | 86| 86| Object.keys(g_CivData).filter( | 87| |- civ => g_CivData[civ].SelectableInGameSetup | | 87|+ civ => g_CivData[civ].SelectableInGameSetup | 88| 88| ).map(civ => ({ | 89| 89| "name": g_CivData[civ].Name, | 90| 90| "tooltip": g_CivData[civ].History, | | [NORMAL] ESLintBear (indent): | | Expected indentation of 1 tab but found 2. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 85| 85| }].concat( | 86| 86| Object.keys(g_CivData).filter( | 87| 87| civ => g_CivData[civ].SelectableInGameSetup | 88| |- ).map(civ => ({ | | 88|+ ).map(civ => ({ | 89| 89| "name": g_CivData[civ].Name, | 90| 90| "tooltip": g_CivData[civ].History, | 91| 91| "color": g_ColorRegular, | | [NORMAL] ESLintBear (indent): | | Expected indentation of 2 tabs but found 3. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 86| 86| Object.keys(g_CivData).filter( | 87| 87| civ => g_CivData[civ].SelectableInGameSetup | 88| 88| ).map(civ => ({ | 89| |- "name": g_CivData[civ].Name, | | 89|+ "name": g_CivData[civ].Name, | 90| 90| "tooltip": g_CivData[civ].History, | 91| 91| "color": g_ColorRegular, | 92| 92| "code": civ | | [NORMAL] ESLintBear (indent): | | Expected indentation of 2 tabs but found 3. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 87| 87| civ => g_CivData[civ].SelectableInGameSetup | 88| 88| ).map(civ => ({ | 89| 89| "name": g_CivData[civ].Name, | 90| |- "tooltip": g_CivData[civ].History, | | 90|+ "tooltip": g_CivData[civ].History, | 91| 91| "color": g_ColorRegular, | 92| 92| "code": civ | 93| 93| })).sort(sortNameIgnoreCase) | | [NORMAL] ESLintBear (indent): | | Expected indentation of 2 tabs but found 3. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 88| 88| ).map(civ => ({ | 89| 89| "name": g_CivData[civ].Name, | 90| 90| "tooltip": g_CivData[civ].History, | 91| |- "color": g_ColorRegular, | | 91|+ "color": g_ColorRegular, | 92| 92| "code": civ | 93| 93| })).sort(sortNameIgnoreCase) | 94| 94| ) | | [NORMAL] ESLintBear (indent): | | Expected indentation of 2 tabs but found 3. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 89| 89| "name": g_CivData[civ].Name, | 90| 90| "tooltip": g_CivData[civ].History, | 91| 91| "color": g_ColorRegular, | 92| |- "code": civ | | 92|+ "code": civ | 93| 93| })).sort(sortNameIgnoreCase) | 94| 94| ) | 95| 95| ); | | [NORMAL] ESLintBear (indent): | | Expected indentation of 1 tab but found 2. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 90| 90| "tooltip": g_CivData[civ].History, | 91| 91| "color": g_ColorRegular, | 92| 92| "code": civ | 93| |- })).sort(sortNameIgnoreCase) | | 93|+ })).sort(sortNameIgnoreCase) | 94| 94| ) | 95| 95| ); | 96| 96| | | [NORMAL] ESLintBear (indent): | | Expected indentation of 0 tabs but found 1. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | 91| 91| "color": g_ColorRegular, | 92| 92| "code": civ | 93| 93| })).sort(sortNameIgnoreCase) | 94| |- ) | | 94|+) | 95| 95| ); | 96| 96| | 97| 97| /** | | [NORMAL] ESLintBear (no-trailing-spaces): | | Trailing spaces not allowed. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js |1239|1239| offset = -Math.min(slideSpeed * dt, maxOffset); |1240|1240| } |1241|1241| |1242| |- updateSettingsPanelPosition(offset); | |1242|+ updateSettingsPanelPosition(offset); |1243|1243| } |1244|1244| |1245|1245| /** | | [NORMAL] ESLintBear (curly): | | Unnecessary { after 'if' condition. |----| | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js | |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/gamesetup/gamesetup.js |1757|1757| let biomeList; |1758|1758| |1759|1759| if (g_GameAttributes.mapType == "random" && g_GameAttributes.settings.SupportedBiomes) |1760| |- { | |1760|+ |1761|1761| if (typeof g_GameAttributes.settings.SupportedBiomes == "string") |1762|1762| biomeList = g_Settings.Biomes.filter(biome => biome.Id.startsWith(g_GameAttributes.settings.SupportedBiomes)); |1763|1763| else |1764|1764| biomeList = g_Settings.Biomes.filter( |1765|1765| biome => g_GameAttributes.settings.SupportedBiomes.indexOf(biome.Id) != -1); |1766| |- } | |1766|+ |1767|1767| |1768|1768| g_BiomeList = biomeList && prepareForDropdown( |1769|1769| [{ binaries/data/mods/public/gui/gamesetup/gamesetup.js |2001| » while·(g_IsNetworked) | | [NORMAL] ESLintBear (no-unmodified-loop-condition): | | 'g_IsNetworked' is not modified in this loop.
Link to build: https://jenkins.wildfiregames.com/job/differential/743/display/redirect
binaries/data/mods/public/gui/gamesetup/gamesetup.js | ||
---|---|---|
1076 | Due to updateGUIObjects i think. ^^ |
binaries/data/mods/public/gui/gamesetup/gamesetup.js | ||
---|---|---|
1076 | Exactly, with this the lines will be read from the file and translated every time some setting changes, so I guess this will reduce performance a bit here and there, especially in the case more tips would be added. When the file was added there was some notion of generalizing it so it would contain all sp tips (if more were to be added in future), this did not pass due to some translation problem. refs #4406 A way of making sure performance is not affected would be to create a miscConst global, containing the constant expressions, however that might be harder to maintain. Added a patch below testing says it actually saves a couple of ms on every updateGUIObjects call, time went down from 25-26ms to 22-23ms on changing 1 setting. Not sure if it is worth the effort though... | |
1439–1443 | As updateGameAttributes (which call updateGUIObjects) is called right after (k some other functions too) initSPTipes this doesn't change anything really, so good |
In my gamesetup branch from last year I found this:
+ "caption": () => Engine.GetGUIObjectByName("aiTips").caption || Engine.TranslateLines(Engine.ReadFile("gui/gamesetup/ai.txt"))
I suppose no matter how slow it is, its essential to not trigger HDD I/O if there is no use for that.
The translate calls are semi-cached on the C++ side (still some concatenation etc.), so that's much less harmful.
For the checked thing, it seems correct as well to always set it to true, since it doesnt matter if its checked if its hidden.
So what I had was needlessly complex:
+ "checked": () => Engine.ConfigDB_GetValue("user", "gui.gamesetup.enabletips") == "true",
So I would recommend to commit perhaps the hybrid of the first line posted above and Polakritys patch, and bb makes a separate revision proposal for the performance const split thing.
binaries/data/mods/public/gui/gamesetup/gamesetup.js | ||
---|---|---|
1076 | bb the patch looks good to me, it is a performance improvement without sacrificing the JS and OOP pattern. A disadvantage of this const splitting is that assignments of GUI Object properties becomes fragmented, and it was an important objective of the gamesetup rewrites to remove any sort of fragmentation. Perhaps one could make the constant properties self-deleting? Sounds ugly too, because it can't refer to itself but'd have to refer to the global. So if its 22 vs 25ms now, it might become 30ms in the future, and that function might be called 10 times in a row, then we're at 300ms already (assuming your numbers to be representative). So perhaps the patch can be done in such a way that keeps fragmentation at 0 while gaining the performance advantage otherwise allowed? To anticipate future changes, perhaps one could consider the dedicated server and the model where g_IsController can change during the course of the gamesetup (granting permissions). (That'd mean startButton won't be const in the future and could become grouped; then. Bit hypothetical.) (Theres also the consideration for mods, but those seem to just benefit equally) Did those "25ms" include the Engine.ReadFile call? Because I could imagine that this may be much more expensive than the rest. Also you can use Engine.GetMicroseconds() for more accuracy. (One should also be able to save a lot of performance by changing the C++ GUI code to not rebuild its text or image when the assigned value is the same as before, but I was never sure if this wasnt used as a feature somewhere) | |
binaries/data/mods/public/gui/gamesetup/gamesetup.xml | ||
127 | Removing this here would be correct if it also wasnt removed in JS at the same time. | |
133 | Seems ok |
binaries/data/mods/public/gui/gamesetup/gamesetup.js | ||
---|---|---|
1076 | The problem with the attached patch is that some of the items in g_MiscControlsConsts are not constant. chatInput -> the hotkey may change at runtime (hotkey dialog, would be reasonable as the gamesetup uses hotkeys) spTips is a special case. Rather than input-processing-output-usingthatas-input-processing-something-else-outputting that etc. So that spTips.hidden is actually a problem, the property is now set in two places intead of only one, but there should only be a single source of truth (https://en.wikipedia.org/wiki/Single_source_of_truth), i.e. only one line that sets this attribute, and it should be easy to find where that line is (all in one hunk). Calling updateGUIObjects each resize sounds a bit laggy however. So it can be tolerated for now, but its really an antipattern code structuring wise. The fragmentation of the different GUI object managers should also be avoided (assinging attributes on const and dynamically in two different objects). So I cant find enough sufficient use cases to split off the const ones. Maybe it will be cleaner to create JS classes for all GUI Object types and insert them, rather than reusing repeated XML defined ones, |
binaries/data/mods/public/gui/gamesetup/gamesetup.js | ||
---|---|---|
1076 | Following experience in #5387, I came to the conclusion that classes are preferable over plain JS object. |
D2483 includes this cleanup (TipsPanel.js) and the performance optimization by bb (in each of the setting classes), but using the class framework.