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
Fix terrain positions for targets not being serialized for Orders #21021
Conversation
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.
untested.
this couldn't break i.e. with FrameEndTask being executed?
what would the average length of the array be? soldiers one? larger units multiple? buildings more? |
See #20216 (comment), the average length will be one as we usually only send |
No I don't believe the use of (or lack of) FrameEndTask would affect this scenario. |
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.
we should probably create a testcase scenario. Or perhaps add a unit test?
… array in a way that roundtrips. Previously, a 0 length array would not roundtrip and would deserialize as a center position instead.
d99e6af
to
07d5cb9
Compare
Can't easily add a unit test as I'd need a world/actor or some other hard to create object. But if we add an extra method for testing then the following test will fail on bleed, but pass with the PR changes. Since // OrderTest.cs
[TestCase(TestName = "Order target persists over serialization")]
public void SerializeTerrain()
{
var o = new Order("Test", null, Target.FromTestPositions(new WPos(1, 2, 3), new[] { new WPos(4, 5, 6), new WPos(7, 8, 9) }), false);
var o2 = Order.Deserialize(null, new BinaryReader(new MemoryStream(o.Serialize())));
Assert.That(o2.Target.Positions, Is.EqualTo(o.Target.Positions));
}
//Order.cs
public static Target FromTestPositions(WPos centerPosition, WPos[] terrainPositions)
{
return new Target(centerPosition, terrainPositions);
} |
Could this be done with reflection as a more acceptable (IMO) level of hackery? |
This one scenario is an edge case we barely care about. The scenarios we really do care about are the things used all the time like actors, frozen actors, cells - i.e. all the Target.From* methods that currently lack tests. They would be much higher value but would require somehow making the code testable and that's a whole different can of worms. But if somebody solved that then this edge case can be tested without hacks. It'd be nice to merge this as a small fix as-is since @abcdefg30 went to the effort of authoring it - but I'd prefer to defer dealing with the worms until we get more value out of the effort for it. |
Takeover of #20216, see for more details.
Ensure we serialize terrain positions for a target correctly. Resolves my comment from original PR by using -1 as a magic number rather than 0 which conflicts with a 0-length array.