-
Notifications
You must be signed in to change notification settings - Fork 464
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
[blueprint] Support new commandline syntax and semantics #1849
Conversation
note that unit tests will fail until #1846 is merged |
- make depth and name parameters optional - allow depth to be negative to indicate top-down instead of the previous hard-coded bottom-up - add --cursor for specifying start position (game cursor is not needed if this param is specified)
(though "and" instead of "&&" seems to work in gcc!)
latest develop merged. tests should pass now |
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 so far - I like the single path for command processing, and the use of Lua getopt. Still haven't played around with this in fortress mode, but from static review it looks good.
|
||
static struct_identity _identity; | ||
}; | ||
static const struct_field_info blueprint_options_fields[] = { |
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.
This is an interesting approach that I felt like I should comment on. This looks good for type-safety! Long-term, I think we should generate type definitions like these with codegen somehow instead of manually, since there could be failures down the road if these field definitions aren't kept in sync with the structure definition. (using offsetof()
to calculate offsets should help guard against most issues... but as a counterpoint, I'm not sure if the field definitions need to be ordered by offset, so rearranging fields could potentially have unintended consequences, for example).
Am I correct in assuming that you didn't define this in PluginStatics.cpp because the objects in question are short-lived and can't exist if the plugin is unloaded? (I was playing around with this and opts
tended to end up at the same stack address every time!) I think this is safe, as long as you're sure that no Lua code retains references to opts
(hopefully the garbage collector doesn't...).
In the interests of avoiding duplication, you could also consider a macro like FLD()
, but the existing definition would admittedly be difficult to include.
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.
+1 for generating the struct_field_info
. As far as I could tell, this is the first time a marshal-able type has been manually defined in DFHack, so I guess the need for a generator just never came up before.
You are correct as to why I didn't put this in PluginStatics
. The stack-allocated options struct doesn't live beyond the blueprint
command execution so I figured I'd keep all the definitions together in the blueprint.cpp
file instead of gaining a consistent identity object, but splitting the object definitions into PluginStatics
.
Yeah, I manually expanded the #defines that are used in the generated struct_field_info
s when I was figuring out how to do this. Not using the existing (but inaccessible) macros felt dirty, but copying the macros into blueprint.cpp
felt somehow dirtier : p I didn't really want to get into refactoring DataStatics*
in this PR, but that might be the way to go longer term.
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 from a static review! I got sucked into details (e.g. documentation formatting) a bit, but those are minor things. Will try to test in more detail this weekend; let me know if you have any areas of concern in mind.
Need to update the unit tests after deleting do_gui. I'll get that tomorrow |
done |
and factor out active cursor detection
plugins/blueprint.cpp
Outdated
@@ -755,16 +756,12 @@ command_result blueprint(color_ostream &out, vector<string> ¶meters) | |||
DFCoord start(options.start); | |||
if (options.start.x == -30000) |
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.
Just noticed that df::coord
has an isValid()
method that does this too. I don't know how widely it's used - I know there are a lot of hardcoded checks for -30000
too - but if you end up making other changes, this could be something to use as well.
(This PR is still on my list. Hopefully tomorrow!)
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 really good! A couple minor things I noticed from testing; not sure if you've already fixed them elsewhere.
#1842
This is the first stage of the blueprint plugin overhaul.
Depends on #1846 for support for negative depths and #1841 for the MapCache change (though the MapCache commits are included in this PR as well to avoid future merge conflicts)
The
blueprint gui
command has a soft dependency on DFHack/scripts#281. You'll be able to run theblueprint gui
command, but it won't do anything until thegui/blueprint
script has something in it.User visible changes to blueprint:
depth
andname
parameters are now optional (defaulting to1
andblueprint
if not specified)depth
can now be negative to indicate that we should iterate through the levels top-down instead of the previous hard-coded bottom-up--cursor
option for specifying start position (game cursor is not needed if this option is specified)I tried to touch the original logic as little as possible, but I did add bounds checking for the input and clipping of the translation area at the map edge.
All docs are updated as well.
question:
I kept the lua functions that the blueprint plugin previously exported (
dig()
,place()
,build()
, andquery()
) though personally I'm not convinced they add any value over just runningblueprint
viarun_command
. In fact, the new implementations of these functions are just a wrapper aroundrun_command
. I don't see any callers in the repo, but I kept the functions for the sake of backward compatibility.I should note, though, that I'm planning on changing the semantics of the phases in the future, including splitting the current
query
phase intoconfig
androoms
, so I don't think perfect backward compatibility will be feasible. Should I keep those functions or just remove them?