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

Clean up version flags #1047

Merged
merged 19 commits into from
Feb 23, 2023
Merged

Clean up version flags #1047

merged 19 commits into from
Feb 23, 2023

Conversation

Jacky720
Copy link
Contributor

Description

  • This PR removes the UndertaleData.GMS2_2_2_302, UndertaleData.GMS2_3, UndertaleData.GMS2_3_1, GMS2_3_2, GMS2022_1, GMS2022_2, GM2022_3, and GM2022_5 booleans in favor of creating an UndertaleGeneralInfo.GMSVersions enum, as well as UndertaleGeneralInfo.GMS2Version using said enum. Closes GMS2 flag spam #1045.
  • Additionally, UndertaleData.IsVersionAtLeast() has been updated to accept these newer versions, and UndertaleData.SetGMS2Version() has been added to easily change the value of GMS2Version.
  • All existing references to the previous booleans have been changed to use the above functions, as well as several checks for reader.undertaleData.GeneralInfo.Major >= 2 being simplified to the existing UndertaleData.IsGameMaker2() function.
  • Finally, UndertaleGeneralInfo.ToString() has been updated to read from GMS2Version and thus display a more accurate version in the title bar, helping with Display proper GM version in the window title #929:
    image

Caveats

  • Breaks any external references to the booleans that are not part of the project or that I missed.
  • The version displayed is inaccurate for GM2022.6, as well as versions between GMS2.0 and GMS2.2.2.302 due to the limited nature of the pre-existing flags and infrequency of changes to the data.win format. This may be fixed by adding special clarification (e.g. "GMS2.0-2.2.0") to the display.

Notes

N/A

@Grossley Grossley closed this Jul 12, 2022
@Grossley Grossley reopened this Jul 12, 2022
@github-actions
Copy link

github-actions bot commented Jul 19, 2022

@Jacky720
Copy link
Contributor Author

@Miepee You said you had comments on this? Just want to bump it.

Copy link
Contributor

@Miepee Miepee left a comment

Choose a reason for hiding this comment

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

Haven't checked the actual replacements yet, only the new approach.

UndertaleModLib/Models/UndertaleGeneralInfo.cs Outdated Show resolved Hide resolved
UndertaleModLib/Models/UndertaleGeneralInfo.cs Outdated Show resolved Hide resolved
return DisplayName + " (GMS " + Major + "." + Minor + "." + Release + "." + Build + ", bytecode " + BytecodeVersion + ")";
if (Major == 2)
return DisplayName + " (" + Enum.GetName(typeof(GMSVersions), GMS2Version).Replace("_", ".") + ", bytecode " + BytecodeVersion + ")";
else
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's just my preference. Keeping all returns on the same level.

/// <param name="minor">The minor version.</param>
/// <param name="release">The release version.</param>
/// <param name="build">The build version.</param>
public void SetGMS2Version(uint major, uint minor = 0, uint release = 0, uint build = 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this this error in any way when invalid major is given, instead of just doing nothing silently?
Also, why is this done with a major/minor/release/build approach? I'd personally like if enums were still used for this, for safety, but I assume that created too much boilerplate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UndertaleGeneralInfo.GMSVersions.GMS2_2_2_302 qualifies as too much boilerplate, IMO.

Most invalid versions are actually just versions that don't have any distinguishing characteristics in the data file, but I see what you mean about major versions in particular. I can add a throw there.

Copy link
Contributor

Choose a reason for hiding this comment

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

UndertaleGeneralInfo.GMSVersions.GMS2_2_2_302 qualifies as too much boilerplate, IMO.

AFAIK, you don't have give the full name like that, GMSVersions.GMS2_2_2_302 should be valid too, but may need some specific usings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added error: "Attempted to set a version of GameMaker {major} using SetGMS2Version". Not going to resolve this in case it's still possible to get in those usings and make it pretty.

UndertaleModLib/UndertaleData.cs Outdated Show resolved Hide resolved
UndertaleModLib/UndertaleData.cs Outdated Show resolved Hide resolved
@Jacky720
Copy link
Contributor Author

Jacky720 commented Sep 8, 2022

To-do:

  • Resolve all these suggestions.
  • Confirm that more recent commits haven't broken anything.
  • Realize I can move the reader.AllChunkNames.Contains("SEQN") check into GeneralInfo
  • and do away with reader.GMS2_3. (there are some more references)
  • Add 2022.8 support.
  • Say, are there any other new-ish chunks that can be used for version identification since 2.3? When was FEDS added? (added 2.3.6, FEDS, 2.2.1, TGIN, and 2022.8, FEAT)

UndertaleModLib/UndertaleData.cs Outdated Show resolved Hide resolved
@@ -495,19 +468,24 @@ private bool TestGMS1Version(uint stableBuild, uint betaBuild, bool allowGMS2 =
/// <param name="release">The release version.</param>
/// <param name="build">The build version.</param>
/// <returns>Whether the version of the data file is the same or higher than a specified version.</returns>
public bool IsVersionAtLeast(uint major, uint minor, uint release, uint build)
public bool IsVersionAtLeast(uint major, uint minor = 0, uint release = 0, uint build = 0)
Copy link
Member

Choose a reason for hiding this comment

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

This method shouldn't be used within (de)compiler, because compared to the boolean check (GMS2_3), it's expensive.

UndertaleModLib/UndertaleData.cs Outdated Show resolved Hide resolved
Comment on lines -297 to -300
/// <summary>
/// Whether the data file is from version GMS2.3
/// </summary>
public bool GMS2_3 = false;
Copy link
Member

@VladiStep VladiStep Feb 12, 2023

Choose a reason for hiding this comment

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

You should revert this field removal, and update the description so it's clear that only this field is kept because of performance.
(see my commentary at IsVersionAtLeast())

@VladiStep
Copy link
Member

I suggest instead of setting CompileContext.GMS2_3 on its creation, you should:

  1. Make the variable static.
  2. Set it in either GeneralInfo.Unserialize() or UndertaleChunkFORM.Unserialize().

@@ -120,7 +117,7 @@ public class UndertaleChunkEXTN : UndertaleListChunk<UndertaleExtension>

internal override void UnserializeChunk(UndertaleReader reader)
{
if (reader.undertaleData.GMS2_3)
if (reader.undertaleData.IsVersionAtLeast(2, 3) && !reader.undertaleData.IsVersionAtLeast(2022, 6))
Copy link
Member

Choose a reason for hiding this comment

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

Is a 2022.6 check necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. That code block is to set the version to 2022.6, so if the versions n has already been set higher it would be redundant.

@@ -339,7 +336,7 @@ internal override void SerializeChunk(UndertaleWriter writer)

internal override void UnserializeChunk(UndertaleReader reader)
{
if (reader.undertaleData.GeneralInfo?.BytecodeVersion >= 17)
if (!reader.undertaleData.IsVersionAtLeast(2022, 2) && reader.undertaleData.GeneralInfo?.BytecodeVersion >= 17)
Copy link
Member

Choose a reason for hiding this comment

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

(the same question as above)

@VladiStep
Copy link
Member

Everything seems fine.
Just make sure that there are no scripts that you've missed.

@Jacky720
Copy link
Contributor Author

Rebasing to update the change from #1048...

@Grossley Grossley merged commit 417dc35 into UnderminersTeam:master Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GMS2 flag spam
4 participants