-
Notifications
You must be signed in to change notification settings - Fork 103
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
Feature: register new lua function DrawBuildSquare
to show build squares on custom building commands
#1733
base: master
Are you sure you want to change the base?
Feature: register new lua function DrawBuildSquare
to show build squares on custom building commands
#1733
Conversation
I think drawing should not be doing any validity calculations (add another function that checks overlap, buildability or whatnot) and should draw a single blueprint. |
This was a copy of the behvior of So you think that we should have a function returning the state of every square associated with a building position, and another function that displays each of this square ? How would this change help developping scripts that use the building square feature ? |
OK that's quite clear now. I'll work on improving that. |
2c68170
to
fdd3e11
Compare
@sprunk OK I've rewritten the MR to feature a more simple and direct function. Also added some options to allow to edit the colors, I'm thinking about templates which have a specific color for buildings not buildable by the current builder. I explain that in the description. Lemme know if it's overkill. |
|
@GoogleFrog you originally came up with the suggestion to do it like this so maybe you have some thoughts on API design as well. |
I used commands because it avoided declaring the type buildInfo in lua (command is bascally I also thought about the need of displaying arbitrary squares, but there a caveat to that: the buildability and the height of a square depends on the type of building (some are on or under water, walls can be built on any slope ...). So it would be a different interface anyways that needs to define its own height for each square. I didn't know about I see some LUA calls like |
I like the idea to draw arbitrary zones to show that a team member plans to use it, or that a zone should be defended. But visually I think it would make more sense to draw it as a polygon with player color borders and lighter color fill. some extension of the map draw, but as a filled shape instead of a line. |
Well
You can just add an arbitrary color entry there. Like here it's using some "restart" color directly which isn't associated with any command. spring/rts/Game/SelectedUnitsHandler.cpp Line 913 in 24efb38
There is a Lua call to reload cmdcolors. It has a pretty bad interface that I'm unhappy about but that is outside the scope of this PR.
I'm not asking for completely arbitrary squares, just the ability to draw the existing grid for specific buildings. You'd always have to pass a specific unitDefID and then it would draw squares as appropriate for that type. Pass the ID of a floating/underwater building and it will draw squares on/under water accordingly. Pass a wall's ID and it will draw OK for any slope, etc. |
fdd3e11
to
6dc9651
Compare
OK I've replaced all the hardcoded colors with colors from |
Oh also I wanted to put those
|
The discussion looks good. I am not sure what |
rts/Rendering/Units/UnitDrawer.cpp
Outdated
return color.r == 0 && color.g == 0 && color.b == 0 && color.a == 0; | ||
} | ||
|
||
void CUnitDrawerLegacy::AddLuaBuildSquare(const BuildInfo& buildInfo, LuaBuildSquareOptions& opts) { |
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.
Could add a FIXME code comment that this is partially a copypaste of function X from file Y.cpp done due to compilation error Z
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.
I think you meant ParseBuildInfo
, it has been commented
rts/Lua/LuaUnsyncedCtrl.cpp
Outdated
|
||
int unitDefID = lua_toint(L, idx); | ||
float3 pos = {lua_tofloat(L, idx+1), lua_tofloat(L, idx+2), lua_tofloat(L, idx+3)}; | ||
int facing = lua_toint(L, idx+4); |
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.
IIRC there's some sort of facing parser in LuaUtils that makes facing args work both with numbers and things like "south", might want to optionally check it out
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.
No, all functions using facing (including SetBuildFacing
) just parse an int.
33bb1db
to
4230b40
Compare
Looks like
|
This is actually the behavior of the original function The squares are cached, so having Add/Del would complexify the behavior quite much for a limited gain. Especially since one player would only see HIS squares, only while holding the mouse button, and they would (almost) always be on screen. About About custom height, I'm not sure what would be the use case. The current building command resolves height automatically. |
It will introduce some flexibility as in time we can figure out how to update the state smarter than just brute-forcing TestUnitBuildSquare() on every opportunity. For now at least users will be able to control how frequently the state should get brute-forced, unlike how it's done currently in the PR, where it's fixed to be CACHE_VALIDITY_PERIOD Disregard my
ZK has a concept of terrain terraforming, someone might want to draw the grid at the future height of X or even with some custom height shape. |
The current interface in the PR is already good because it lets you specify position as XYZ. So it would be a matter of the renderer not ignoring the Y. Perhaps if that happens then Y could become optional so that specifying |
OK I understand the idea of Add/Del, it would permit for later optimisation. Looking at For terraforming, unfortunately About skipping the |
I've checked how this is implemented in VAO:
So do we want to mimic that implementation, or we should simplify using a map ? I feel like using a map is better because we can trust C++ to do a faster job at updating a map than lua is doing. |
4230b40
to
548253e
Compare
…Square` to show build squares on custom building commands
548253e
to
1b68bee
Compare
OK next iteration. Now have |
By itself is not that expensive (although it's much more than just a lookup in 2D array), but when N constructors queue M buildings it's NxM runs to perform and it becomes very expensive.
This is in line with what I'm saying. Even if implemented naively, the only place something might change is at game frame time. The game runs 30 sim frames per seconds, while rendering frames normally reach 3 digit figures.
Terraforming defines the final state of heightmap, but it's ok if you skip this one.
Unsure how VAO relates to the topic of discussion. But that actually led me to some interesting thought. The way we store the buildable/unbuildable/feature squares is very expensive and redundant. It's enough to store the build-ability data in a 2D value array, possibly a bitmap and use shader to colorize the output according to the chosen colors. |
Ok, I'll have a look today. |
Oh yeah I absolutely hate how the test function takes 3 vector pointers, instead of just returning a struct with a 2D array of states.
I've been trying to understand how threading works, but I didn't get much clues through the code. I just noticed that despite having a very decent laptop, replay speed barely exceeds normal speed on big battles. I suppose this is the cause of unsynchronisations that players seem to complain about. |
…Square` to show build squares on custom building commands
Co-authored-by: sprunk <[email protected]>
Hi, anything else you want me to improve, or we're good to merge ? |
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.
Documentation would be good:
- what happens if you call Add twice with the same args, or if the Y is different? How lenient is duplicate detection?
- do x/z need to be aligned to the grid?
- what is "cache validity"? Just the rate of buildability checks or will the square remove itself?
- does Remove require 100% identical args that were passed to Add to successfully remove? If not, how much leniency is there?
rts/Lua/LuaUnsyncedCtrl.cpp
Outdated
* @number y | ||
* @number z | ||
* @number facing | ||
* @bool[opt] unbuildable |
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.
Seems to be a table 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.
I've tried to fix those comments, I'm still not clear how they work though because they are quite different from LUA annotations.
Some widget so we could test the main use case would be decent too |
Hi I created a small widget to test the new call: |
I've added some checks and fixes to avoid crashing with unexpected arguments. Surprisingly, I've found out that the engine doesn't enforce a building to follow the grid, so |
0524352
to
8081c65
Compare
…Square` to show build squares on custom building commands
8081c65
to
0f2c725
Compare
@sprunk So the current behavior is to never recompute the squares, and keep them in cache when removed according to I'm not sure what would be the best behavior, I'm open to suggestions. We could recompute them regularily once validity is passed despite being still used, we could add another argument for setting a refresh time ... Also I've tested more thoroughly |
Registers
Spring.AddBuildSquare(unitDefId, x, y, z, facing [, opts])
andSpring.RemoveBuildSquare(unitDefId, x, y, z, facing)
which display the usual grid.Options are
unbuildable=false
: show the building as unbuildable (orange) instead of buildable (green) even if there is no detected conflict.defaultColor={0,0,0,0}
: replace all the hardcoded color with this given color (then it will be overriden by next colors)buildableColor={0,0,0,0}
: change the color for buildable (green)unbuildableColor={0,0,0,0}
: change the color for unbuildable (orange)featureColor={0,0,0,0}
: change the color for feature (orange)illegalColor={0,0,0,0}
: change the color for illegal (red)Mostly forking
CUnitDrawerLegacy::ShowUnitBuildSquare
.My first MR on that project, so please lemme know best practices.