-
Notifications
You must be signed in to change notification settings - Fork 136
New REMOVE_RANGE command for range removal #2156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ead of by cmdid/tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking nice.
Co-authored-by: sprunk <spr.ng@o2.pl>
Co-authored-by: sprunk <spr.ng@o2.pl>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great.
Ended up implementing tag mode too, it's a bit verbose and who knows if someone needs it, but actually when not providing params it doesn't matter if ALT is used since it defaults to whole queue anyways, otherwise yes, ALT is indexes, no ALT is tags. If start/end tag are provided, but not found, then it won't do anything. Let me know if you think it's too much can always remove, but felt its incomplete otherwise, besides, we were not considering the case where no ALT, but no params too. In that case it works just like with ALT. Anyways I think maybe I'll try with a simple FindTagIndex function, and use that one instead, maybe not so efficient but likely doesn't matter that much here. Also later can be used in other places too. Tried to make the implementation of finding both ends efficient, since the queue can have 100k+ items, but looks a bit overboard tbh XD. |
Another consideration, indexes here are c++ based, so first is 0, last is queue.size()-1. Should we maybe use lua-like indexes instead? |
Good point, should use Lua 1-based.
Great. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, perhaps it's a good moment to undraft.
Co-authored-by: sprunk <spr.ng@o2.pl>
Co-authored-by: sprunk <spr.ng@o2.pl>
Co-authored-by: sprunk <spr.ng@o2.pl>
Co-authored-by: sprunk <spr.ng@o2.pl>
…e sense. Co-authored-by: sprunk <spr.ng@o2.pl>
It's name also applies only to the second loop.
22f9218
to
9cc92ba
Compare
I'm fairly sure that giving two CMD_WAIT commands works as a flush (they immediately cancel each other out and the unit seems to react a bit faster than when inserting a CMD_STOP). Perhaps check whether it helps in this case and if yes, what exactly happens inside that makes it work. |
Ok, I just realized there's #2172 addressing my documentation concern, I removed my previous comments on this post. (note: is this up to 2nd or up to 20th? unsure if theres a typo or not |
Oh yeah, right that's why I wrote 2th originally, but then corrected to 2nd... good catch. Fixed now. |
As noted here, this might be making the REMOVE cmd api a bit too overloaded, and it could be better to create a separate command instead, like CMD_REMOVE_RANGE for example. Wondering what other ppl here think. |
Splitting sounds good. I wouldn't do |
Personally, don't see that path, since then we'd have 3 commands with overlapping uses, ie, Also keep in mind we added the tag option for range just because REMOVE already supported that and otherwise would be incomplete, but don't think that's going to have much use, so if creating CMD_RANGE we could just not add tag support, and wait to see if it's smth needed later on. I much prefer The other way we end with 4 commands each with different modifiers and behaviour. Option A)
Option B)
I think (B) much better and we don't pollute the command list so much. Also CMD names much nicer imo. |
Tag is important for polishing because it avoids latency-based race condition when given from unsynced.
Yes, but that is fine. We can deprecate it and encourage people to use the dedicated ones. There's got to be like 20 uses of cmd.remove total across the whole ecosystem.
As far as I understand, having complex commands that do everything and change parameter meaning based on modifiers is why @rhys-vdw suggested the split-off in the first place. If we're using an opportunity to have primitive commands then we shouldn't do the bare minimum, in fact I maybe we could even have 7+ commands (existing remove, by tag, by tag range, by index, by index range, by cmdid all, by cmdid single) where none of them take any modifier that modifies the meaning of parameters (only ctrl to choose which queue the removal applies to). Pollution is going to exist either way because there's just so many ways to remove (equivalently, meanings that parameters can have), your method just moves it to modifier options which I think is worse (especially while #1063 exists). |
Well sorry, but I don't see it at all, it's as bad to have too many options as too many commands (pollutes the command space, documentation and code too), I'll do the CMD_REMOVE_RANGE and we can see. Also it's not like doing it the way you want is saving any options, since those would still need 1 option in general, just like CMD_REMOVE_RANGE. |
Implemented CMD_REMOVE_RANGE and changed PR description and title accordingly. |
The remaining minor changes for regular remove could be in a separate PR since they seem uncontroversial. |
Actually they are controversial XD. If left here would require a bit of a refactor. That's because in some places the cpp code just does uses the REMOVE command to remove a command with a specific tag from the queue, and it shouldnt send the CmdDone there probably. Wanted to say that but you beat me to it. |
13ef0ca
to
e3a93a8
Compare
I disagree with this because the options don't map to keystrokes in this case. I see no reason to use the options argument which has already been flagged as kind of outdated cruft. I actually think it makes more sense to move away from Even when the command does relate to inputs, the use of this pattern has resulted in difficulties remapping inputs such a shift to queue or shift to place a line of buildings. These operations are still not rebindindable because of When adding unit orders to a factory queue, it makes more sense to check for keybindings and send a different quantity e.g. send Basically everything can be expressed with primitives and parameters, so why muddy things with options that everyone seems to agree are confusing and limiting? I think @sprunk and I are on the same page here:
Even the queue selection could be passed as a param, but any movement away from using options is a good choice IMO. Obviously I'm new to the codebase so feel free to point out what I'm missing here, but a 1:1 list of clearly named command IDs to command functionalities feels like both the ideal and obvious way to do things. |
The options are not really flagged as outdated cruft, just their names. If we do go that path of deprecating options, or changing names, then it could be the case but it's not. So I think we should stick to current standards of how things work, instead of creating a new ad-hoc standard that might not even be final. Keep in mind this PR's scope is not creating a new command option standard.
The problem is not the option names, don't think those correspond to the actual keys since they do not. The problem is not about the options that you can't rebind, the problem is the engine ui code is creating those commands in custom parts of the code, but they need to be refactored into actions that ppl will be able to bind. The options can be used all the same so believe me those are really not a problem. (I'm working on fixing those too, and the option 'names' themselves are not a problem)
As said, I think we should stick to current standards since it's not the scope of this PR to create a new command interface/standard. I agree maybe for tag/id we could use a parameter, although I think it's a bit awkward, since I believe the common way will be to use index with it, and tag is kind of an extra option, but we already have varargs, so either it has to be the first param or need to provide a nil in some situations, so it would end like one of these:
For example, to remove all but the first element with altqueue would be:
If tag would be a parameter then it could be even worse:
Solving the awkward naming of options is going to be tricky, but could be done by specifying per command maps, where we map the options to their bit codes internally, for example: CMD_REMOVE_RANGE_OPTIONS = {
'ctrl' => 'altqueue',
'alt' => 'byTag',
shift' => 'append',
} Then ppl could use as This could even be declared from c++ in some way like |
Ok, removed the tag option, since that seems to be controversial, also lua method to GetIndexFromTag or so could make it uneeded, so maybe better to create that one afterwards. Don't really see creating lots of commands with ugly names, and also don't see creating lots of similarly named methods, I think that also makes the api ugly and confusing to use, not just having options. Regarding options themselves, above I described a mechanism to make them look on-point from lua, maybe some day we can do that or smth in that direction, personally doesn't bother me too much, since there's more pressing issues tbh. I don't want to set a new command standard here, just implement a simple Range command. Currently commands have simple names and sometimes several options, that's how it works now pretty much. Trying to come up with a new standard in every PR is a bad idea imo, and when one is implemented, everything should be changed swiftly, otherwise we'd just have several standards coexist and later before one is implemented I'm sure the goals will move again and there'll be a new standard and so on. I'd be willing to maybe make this a lua method, instead of (or in addition to) a command, that would save some network bytes, but wouldn't be usable from widgets. Other than that I think the feature is |
So the new API is just
That makes a lot of sense to me. I'm still confused what the index of a tag would be. Is it
I'm not going to continue this conversation here, and I don't want to block your PR. I didn't think the suggestion would be controversial! So I hope to find time to write up my thoughts in a more structured way for ppl to think about and have a more productive conversation. |
Yes, I'll add a PR afterwards with GetCommandTagIndex or smth like that, so we can have the tag version "for free".
Was noted elsewhere, but the tag for a command is a unique id identifying it in it's queue. So when you know the tag of a command you can query or address it directly through that. |
Work done
Work yet to be done in this PR
Related issues
Also see following "precursor" prs:
Remarks
REMOVE_RANGE specs
callins: After successful execution, it will call UnitCmdDone.
Examples:
spGiveOrderToUnit(unitID, CMD.REMOVE, nil, {'meta', 'ctrl'}) -- delete everything
spGiveOrderToUnit(unitID, CMD.REMOVE, 2, {'meta', 'ctrl', 'alt'}) -- delete all but the 1st element
spGiveOrderToUnit(unitID, CMD.REMOVE, {1, 20}, {'meta', 'ctrl', 'alt'}) -- delete from 1st to 2th
spGiveOrderToUnit(unitID, CMD.REMOVE, {startTag, endTag}, {'meta', 'ctrl'}) -- delete from position of startTag, to endTag