Skip to content
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

Coordinated spawns hotfixes #229

Merged
merged 24 commits into from
Jul 6, 2021
Merged

Coordinated spawns hotfixes #229

merged 24 commits into from
Jul 6, 2021

Conversation

Metious
Copy link
Member

@Metious Metious commented Jul 5, 2021

Changes made in this pull request

  • Fixed a bug where the savedSpawns Deserializer was failing.
  • Added two new public JsonConverter classes (QuaternionConverter/Vector3Converter) for simplified serializations.
  • Redesigned SpawnInfo into a struct, implementing IEquatable<SpawnInfo>, custom Equals, GetHashCode methods and operator overloads for == and != respectively.
  • Fixes an issue where EntitySpawner.SpawnAsync was using TechType.ToString() rather than TechType.AsString().

Builds by @tobeyStraitjacket

5555948 v2.10.0.3: Equals(object obj) & GetHashCode()

  • This build features an implementation as initially intended by @Metious which overrides Equals(object obj) & GetHashCode() to provide a value-based equality comparison for all properties of SpawnInfo.
  • As it overrides Equals and GetHashCode to provide value-based equality comparison, this is a breaking change for anyone who previously relied on Equals or GetHashCode (particularly a problem in the case of HashSet), but it solves the problem where List.Contains is returning false for deserialized SpawnInfo instances. However, it also means that we cannot later change the implementation of Equals or GetHashCode without another breaking change for consumers.

Subnautica

Stable v2.10.0.3
Experimental v2.10.0.3

Below Zero

Stable v2.10.0.3
Experimental v2.10.0.3

96cdaa3 v2.10.0.5: IEquatable<SpawnInfo> Equals(SpawnInfo other)

  • This build does not override Equals(object obj) or GetHashCode, but instead implements IEquatable<SpawnInfo> and Equals(SpawnInfo other) to provide a value-based equality comparison for all properties of SpawnInfo.
  • List.Contains should defer toEquals(SpawnInfo) for comparison since we implement IEquatable<SpawnInfo>, and the issue @Metious was trying to solve should be resolved.
  • This should make for a less egregious backwards-incompatible change, as Equals(object obj) and GetHashCode still operate the same, it is only Equals(SpawnInfo other) that has been changed. Still, the issue remains that if we change this in future, it will have implications for consumers, so it must be approached with caution.

Subnautica

Stable v2.10.0.5
Experimental v2.10.0.5

Below Zero

Stable v2.10.0.5
Experimental v2.10.0.5

b9802ce v2.10.0.6: SpawnInfo redesigned as a struct

  • This build combines the logic of both 2.10.0.3 and 2.10.0.5, and on top of that, also redesigns SpawnInfo as a struct rather than a class.
  • @Metious assures me that nobody outside of himself and the RotA team are making any use of the SpawnInfo API, so a backwards-incompatible change that fixes the design of the API is preferable, should this prove to be true.

Subnautica

Stable v2.10.0.6
Experimental v2.10.0.6

Below Zero

Stable v2.10.0.6
Experimental v2.10.0.6

Builds by @Metious ca7018a

SMLHelper_BZ.STABLE.zip
SMLHelper_BZ.STABLE.zip

@Metious
Copy link
Member Author

Metious commented Jul 5, 2021

Calling for a fast merge/publish as this bug was game breaking.

@PrimeSonic PrimeSonic requested review from toebeann and MrPurple6411 and removed request for toebeann July 5, 2021 21:23
Copy link
Contributor

@toebeann toebeann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have suggested changes in comments, I also intend to work on GetHashCode() implementation before this goes through as I believe there will be issues with SpawnInfo if we introduce an Equals method that is not inline with the GetHashCode method - particularly if someone ever wants to make a HashSet of SpawnInfo instances.
Simply deferring to base.GetHashCode() when you have modified the logic of Equals will get the compiler to "shut up", but it will also cause problems down the road.

SMLHelper/Handlers/CoordinatedSpawnsHandler.cs Outdated Show resolved Hide resolved
SMLHelper/Handlers/CoordinatedSpawnsHandler.cs Outdated Show resolved Hide resolved
SMLHelper/Handlers/CoordinatedSpawnsHandler.cs Outdated Show resolved Hide resolved
SMLHelper/Json/Converters/QuaternionConverter.cs Outdated Show resolved Hide resolved
SMLHelper/Json/Converters/Vector3Converter.cs Show resolved Hide resolved
SMLHelper/Json/Converters/Vector3Converter.cs Outdated Show resolved Hide resolved
SMLHelper/Json/Converters/QuaternionConverter.cs Outdated Show resolved Hide resolved
SMLHelper/Json/Converters/Vector3Converter.cs Outdated Show resolved Hide resolved
SMLHelper/MonoBehaviours/EntitySpawner.cs Outdated Show resolved Hide resolved
@toebeann toebeann requested a review from PrimeSonic July 6, 2021 07:39
… the expected default. Since the API was being redesigned, also took care of the fact the property names were violating property naming rules.
@Metious
Copy link
Member Author

Metious commented Jul 6, 2021

Tested SMLHelper 2.10.0.6 and i can confirm that the potential bugs were fixed and everything works just fine.

Copy link
Contributor

@toebeann toebeann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v2.10.0.6 appears to be bug free after testing from @Metious. Issues that were game-breaking are resolved, and no breaking changes for their 2.9.7 build of mods utilising the API.

@toebeann toebeann merged commit 670610d into SubnauticaModding:dev Jul 6, 2021
@Metious Metious deleted the CoordinatedSpawnsHotfix branch July 6, 2021 14:16
@toebeann toebeann mentioned this pull request Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants