Syncaidius / MoltenEngine

A spare-time C# .NET 8 game engine project. Cross-platform, multi-threaded.
MIT License
301 stars 20 forks source link

.NET 7 Generic Math Operators #70

Closed Syncaidius closed 10 months ago

Syncaidius commented 2 years ago

Once .NET 7 release around November, look into the use of generic math operators to clean up math type generation. Currently it uses some overly-complex text-template (.tt) files to output a large amount of codebase for vector and quaternion types.

See for details: https://devblogs.microsoft.com/dotnet/dotnet-7-generic-math/

IceReaper commented 2 years ago

Any reason to not already port to .net7 then? Its unlikely this project gets released before .net7 anway?

Syncaidius commented 2 years ago

@IceReaper The main reason is stability. Previews tend to have bugs or unfinished features. Although preview 7 is the last one before release in November, other dependencies, such as Silk.NET will also need time to catch up and support it.

Since this would be a quality-of-life change, it makes more sense to prioritize critical systems such as rendering, audio and UI for now. But, if anything comes up along the way that must have generic math, then this will definitely get pushed up in priority.

Syncaidius commented 2 years ago

After looking into this further, generic math will not work well for Molten's vector types, as it would still need at least one generic type per vector size (Vector2, 3, and 4) and a separate set for integer and floating-point vectors, which still adds up to a not-so-small amount of types.

The lack of struct inheritance also means that, unless everyone is expected to type something like Vector2F<float> or Vector2I<int> everywhere, it would also need non-generic versions of each vector size.

For now at least, it seems better to stick with template-generated vector types.

Syncaidius commented 1 year ago

The first step towards generic math usage has been made by implementing IVector on all vector types. Also includes ISignedVector and IUnsignedVector.