#3826 closed enhancement (fixed)
[PATCH] Improve FindIdleUnits of GUIInterface
Reported by: | elexis | Owned by: | Stephen Imhoff |
---|---|---|---|
Priority: | Nice to Have | Milestone: | Alpha 21 |
Component: | UI & Simulation | Keywords: | |
Cc: | Patch: |
Description
hasIdleWorker
of session.js
(see r17674) calls the GuiInterface.js
function FindIdleUnits
for every type of g_WorkerTypes
. Instead it should rather support the passing of the whole array.
FindIdleUnits
itself should not loop twice over playerEntities
but only once.
Attachments (1)
Change History (10)
comment:1 by , 8 years ago
Keywords: | review added |
---|---|
Summary: | Improve FindIdleUnits of GUIInterface → [PATCH] Improve FindIdleUnits of GUIInterface |
comment:2 by , 8 years ago
Owner: | set to |
---|
comment:3 by , 8 years ago
comment:4 by , 8 years ago
sanderd17 - you're right about the `array.some` being lucky. I just hadn't seen `array.findIndex` yet.
comment:5 by , 8 years ago
I don't know if it's possible to use the MatchesClassList helper, but as that one also supports AND, OR and even NOT operations on class combinations, it might result in more versatile code. http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/globalscripts/Templates.js#L47
comment:6 by , 8 years ago
if(
->if (
- L1719 early return
if (!idleUnits.length)\n return;
or similar - L1678 -> if its not an array make it an array. always push the element (reduces the code slightly)
by , 8 years ago
Attachment: | patch.patch added |
---|
comment:7 by , 8 years ago
L1719's change is a little more involved; it needs to reset the cursor, as no idle units were found. There's also an included TODO about "nobody found" notifications should be added. Changed, but I can reverse it.
MatchesClassList is interesting, but unfortunately I don't think I can use it. I'm using findIndex specifically to get the sorting bucket to put a given unit in, which MatchesClassList won't/can't give me. I could use a modified version of the helper, I guess, but it'd need some pretty wide changes to return the information I need.
comment:9 by , 8 years ago
Keywords: | simple review removed |
---|---|
Milestone: | Backlog → Alpha 21 |
A first review on code style (not yet on functionality): input.js
currIdleClassIndex == 0
) than a negative (currIdleClassIndex != 0
). So you could swap the two around. Though I doubt that selector is needed, as AFAICS, when the index is 0, the slice and concat operation will do no work.if (...) return;
, and proceed with the other case on a lower indentation level.GuiInterface.js
for..each..in
should be avoided in favour offor..of
when possible.array.some
is quite ugly code.