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

After NotBefore<> support to control initialization order. #19928

Merged
merged 1 commit into from Apr 18, 2022

Conversation

RoosterDragon
Copy link
Member

@RoosterDragon RoosterDragon commented Feb 6, 2022

Requires<T> means that trait of type T will be initialized first, and asserts that at least one exists. The new NotBefore<T> means that trait of type T will be initialized first, but allows no traits.

This allows traits to control initialization order for optional dependencies. They want to be initialized second so they can rely on the dependencies having been initialized. But if the dependencies are optional then to not throw if none are present.

We apply this to Locomotor which was previously using AddFrameEndTask to work around trait order initialization. This improves the user experience as the initialization is applied whilst the loading screen is still visible, rather than the game starting and creating jank by performing initialization on the first tick.


Recommend using the Hide Whitespace option when looking at Locomotor.cs for clarity.

Changelog notes will want to cover:

  • New NotBefore<T> interface to complement Requires<T>.
  • Any traits implementing ICustomMovementLayer should now also tag their TraitInfo with ICustomMovementLayerInfo.

@RoosterDragon
Copy link
Member Author

Updated the tests to ensure the the interfaces/inheritance was tested with After<> as well.

@RoosterDragon
Copy link
Member Author

Moved the new ICustomMomentLayerInfo interface to Mods.Common, which is where the existing ICustomMomentLayer lives.

teinarss
teinarss previously approved these changes Apr 3, 2022
Requires<T> means that trait of type T will be initialized first, and asserts that at least one exists. The new NotBefore<T> means that trait of type T will be initialized first, but allows no traits.

This allows traits to control initialization order for optional dependencies. They want to be initialized second so they can rely on the dependencies having been initialized. But if the dependencies are optional then to not throw if none are present.

We apply this to Locomotor which was previously using AddFrameEndTask to work around trait order initialization. This improves the user experience as the initialization is applied whilst the loading screen is still visible, rather than the game starting and creating jank by performing initialization on the first tick.
@RoosterDragon
Copy link
Member Author

Per some bikeshedding on Discord, have renamed the trait from After<> to NotBefore<>

@RoosterDragon RoosterDragon changed the title After After<> support to control initialization order. After NotBefore<> support to control initialization order. Apr 4, 2022
@pchote pchote merged commit 2583a7a into OpenRA:bleed Apr 18, 2022
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.

None yet

4 participants