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
Account for terrain height and slope when calculating order location. #7748
Conversation
This is a huge step forward, but I got a crash when building vehicles on "A river runs nearby":
Not reproducible and does not seem to be caused by any of the code touched here so 👍 |
Removed references to #6840, since this doesn't completely fix this. You can verify the self-consistency of the CellContaining changes by putting the following code somewhere that will run once: var m = self.World.Map;
foreach (var c in m.Cells)
{
var cc = m.CellContaining(m.CenterOfCell(c));
if (c != cc)
Console.WriteLine("Mismatch: {0} -> {1} -> {2}", c, m.CenterOfCell(c), cc);
} |
:+0.5: for ingame, can't really judge the code. |
|
@obrakmann added a commit to fix that. |
var p = map.CenterOfCell(uv.ToCPos(map.TileShape)); | ||
var s = worldRenderer.ScreenPxPosition(p); | ||
var dx = Math.Abs(s.X - world.X); | ||
var dy = Math.Abs(s.Y - world.Y); |
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.
In the worst case scenario you're doing all this for all candidates twice. I know it's just integer maths, but it gets called quite often. Is it worth it to remove that redundancy?
Edit: Thinking about it some more, it's probably not worth it.
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.
There is a tradeoff between making the common case efficient and eating the perf in the worst case, or making the common case slower to save on the worst case. I decided that the worst case (clicking on the side of a cliff) is rare enough that this way is better.
In-game this looks good, and I didn't spot any regressions in the older mods, either. The code is mostly above my head and I wouldn't spot a glaring error if it stared me right in the eye. I'll cautiously add my own :+0.5:s to reaperrrs :) |
var dy = Math.Abs(s.Y - world.Y); | ||
|
||
return dx * dx + dy * dy; | ||
}).First().ToCPos(map); |
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.
Why .First()
instead of [0]
?
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.
Enumerables can't be indexed.
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.
Oh right, I wasn't paying attention to the type.
This works fantastic for me so if there are no objections this can be merged (after lunch). 👍 |
Account for terrain height and slope when calculating order location.
Units will now move where you tell them to on TS maps that include slopes (i.e. all except our one debug map). The terrain geometry overlay will now also highlight the mouseover cell to aid in debugging any future problems.