After NotBefore<> support to control initialization order.

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.
This commit is contained in:
RoosterDragon
2022-02-06 10:19:31 +00:00
committed by Paul Chote
parent 62e7c7a318
commit 2583a7af31
9 changed files with 100 additions and 34 deletions

View File

@@ -322,6 +322,9 @@ namespace OpenRA.Traits
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Not a real interface, but more like a tag.")]
public interface Requires<T> where T : class, ITraitInfoInterface { }
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Not a real interface, but more like a tag.")]
public interface NotBefore<T> where T : class, ITraitInfoInterface { }
public interface IActivityInterface { }
[RequireExplicitImplementation]