GuyInGrey / AptitudeEngine

A 2D based, new technology using, game engine in C#.
https://guyingrey.github.io/
MIT License
0 stars 0 forks source link

Deprecate OpenTK Dependency Externally #16

Closed dresswithpockets closed 7 years ago

dresswithpockets commented 7 years ago

what?

Create types that replace, wrap around, derive from, or are compatible with the OpenTK types that inhabit AptitudeEngine.

why?

We use OpenTK a lot. Everything including the GameWindow context and it's events is OpenTK. Which means that there is a high likely hood that the developer thats using AptitudeEngine may also have to reference OpenTK to use some of those types.

how?

12 actually touches on this issue and is technically a step in the direction this issue is intended to be taking.

Enums are castable.

Two enums of the same sub type can be casted between eachother, so implementing an enum in AptitudeEngine like this:

public enum VSyncMode
{
    Off = 0,
    On = 1,
    Adaptive = 2
}

would immediately be castable to OpenTK's VSyncMode like so:

OpenTK.VSyncMode someTkVsync = (OpenTK.VSyncMode)VSyncMode.Off;

Structs are implicitly castable when overriden

We actually do this already because of #2 in Vector2's implicit cast overrides to OpenTK's Vector2 seen here:

public static implicit operator OpenTK.Vector2(Vector2 vec)
    => new OpenTK.Vector2(vec.X, vec.Y);

Classes are inheritable

Our version of, say, GraphicsMode can just derive from OpenTK.Graphics.GraphicsMode with a few hiding variables when needed like so:

public class GraphicsMode : OpenTK.Graphics.GraphicsMode
{
    public static new readonly GraphicsMode Default
            = (GraphicsMode)OpenTK.Graphics.GraphicsMode.Default;
}
dresswithpockets commented 7 years ago

Simply inheriting from the OpenTK alternative wont work, as downcasting is not implementable.

A conversion actually needs to be implemented between reference types.

dresswithpockets commented 7 years ago

Completed with merge https://github.com/PhoenixGameDevelopmentTeam/AptitudeEngine/commit/eaa49280434a76fc4c770c85a3e957ce710688e0.