Skip to content

Commit

Permalink
Update FNA guide
Browse files Browse the repository at this point in the history
  • Loading branch information
lithiumtoast committed Dec 5, 2020
1 parent 149f772 commit 39128e8
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 33 deletions.
123 changes: 115 additions & 8 deletions docs/MIGRATION-GUIDE-FNA.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,106 @@ The following types have been deleted in comparision to the XNA API. If you need
- `GameServiceContainer`
- `IGraphicsDeviceManager`
- `IGraphicsDeviceService`

- `ContentExtensions`
- `ContentLoadException`
- `ContentManager`
- `ContentReader`
- `ContentSerializerAttribute`
- `ContentSerializerCollectionItemNameAttribute`
- `ContentSerializerIgnoreAttribute`
- `ContentSerializerRuntimeTypeAttribute`
- `ContentSerializerTypeVersionAttribute`
- `ContentTypeReader`
- `ContentTypeReaderManager`
- `LzxDecoder`
- `ResourceContentManager`
- `AlphaTestEffectReader`
- `ArrayReader`
- `BasicEffectReader`
- `BooleanReader`
- `ByteReader`
- `CharReader`
- `ColorReader`
- `DateTimeReader`
- `DecimalReader`
- `DictionaryReader`
- `DoubleReader`
- `DualTextureEffectReader`
- `EffectMaterialReader`
- `EffectReader`
- `EnumReader`
- `EnvironmentMapEffectReader`
- `ExternalReferenceReader`
- `IndexBufferReader`
- `Int16Reader`
- `Int32Reader`
- `Int64Reader`
- `ListReader`
- `MatrixReader`
- `NullableReader`
- `QuaternionReader`
- `RectanglerReader`
- `RefleciveReader`
- `SByteReader`
- `SingleReader`
- `SkinnedEffectReader`
- `SongReader`
- `SoundEffectReader`
- `SpriteFontReader`
- `StringReader`
- `Texture2DReader`
- `Texture3DReader`
- `TextureCubeReader`
- `TextureReader`
- `TimeSpanReader`
- `UInt16Reader`
- `UInt32Reader`
- `UInt64Reader`
- `Vector2Reader`
- `Vector3Reader`
- `Vector4Reader`
- `VertexBufferReader`
- `VertexDeclarationReader`
- `VideoReader`
- `MatrixConverter`
- `QuaternionConverter`
- `Vector2Converter`
- `Vector3Converter`
- `Vector4Converter`
- `IEffectFog`
- `IEffectLights`
- `IEffectMatrices`
- `AlphaTestEffect`
- `BasicEffect`
- `DualTextureEffect`
- `EffectHelpers`
- `EnvironmentalMapEffect`
- `SkinnedEffect`
- `Alpha8`
- `Bgr565`
- `Bgra4444`
- `Bgra5551`
- `Byte4`
- `HalfSingle`
- `HalfTypeHelper`
- `HalfVector2`
- `HalfVector4`
- `IPackedVector`
- `NormalizedByte2`
- `NormalizedByte4`
- `NormalizedShort2`
- `NormalizedShort4`
- `Rg32`
- `Rgba1010102`
- `Rgba64`
- `Short2`
- `Short4`

### Removed math types: `Point`, `Plane`, `Ray`, `BoundingFrustum`, `BoundingBox`, `BoundingSphere`, `ContainmentType`, `PlaneIntersectionType`, `PlaneIntersectionType`, `Curve`, `CurveKey`, `CurveKeyCollection`, `CurveLoopType`, and `CurveTangent`

These types are removed simply because there names and usages are confusing for developers between contexts, especially between 2D and 3D.

For example, `Point` is a 2D point with signed 32-bit integer components. But where is the 3D point type? What if a developer want to use a point struct with different integer bits signed or unsigned? Similiarly for `BoundingBox` which is a 2D AABB (axis-aligned-bounding-box) using 32-bit floats but where is the 2D equivalent? Sure, there is `Rectangle` but that's using 32-bit signed integer components!
For example, `Point` is a 2D point with signed 32-bit integer components. But where is the 3D point type? What if a developer want to use a point struct with different integer bits signed or unsigned? Similiarly for `BoundingBox` which is a 3D AABB (axis-aligned-bounding-box) using 32-bit floats but where is the 2D equivalent? Sure, there is `Rectangle` but that's using 32-bit signed integer components!

What's worse is that down-stream developers for middleware feel the effects of these bad descisions with the XNA API when designing and implementing their own API. For example, what if developers want to use the name `BoundingBox` for their 2D engine but it is already taken? Sure, they could use a different namespace, but this makes things more complex than they really need to be.

Expand All @@ -90,18 +183,32 @@ If you do want to use "services" and dependency injection in your game, I would

#### `GraphicsDevice`

By removing these types mean that some types that depend on services to get a `GraphicsDevice` like `ContentManger` need to be adjusted. With Katabasis, you can access the `GraphicsDevice` at any time by going through the public instance field member: `GraphicsDeviceManager.Instance.GraphicsDevice`. This is possible because with FNA a `GraphicsDevice` is never lost which allows for only one `GraphicsDevice` instance. This means that any types that take a dependecy on `GraphicsDevice` in their constructor like `ContentManager` is no longer required.
By removing these types mean that some types that depend on services to get a `GraphicsDevice` like `ContentManger` need to be adjusted. With Katabasis, you can access the `GraphicsDevice` at any time by going through the public instance field member: `GraphicsDeviceManager.Instance.GraphicsDevice`. This is possible because with FNA a `GraphicsDevice` is never lost which allows for only one `GraphicsDevice` instance. This means that any types that take a dependecy on `GraphicsDevice` in their constructor like `Texture2D` is no longer required.

For example, before with the XNA API:

```
```cs
var graphicsDevice = Game.GraphicsDevice;
var myContentManager = new ContentManager(graphicsDevice);
var myTexture = new Texture2D(graphicsDevice, 1, 1);
```

With Katabasis:
```cs
var myTexture = new Texture2D(1, 1);
```
var myContentManager = new ContentManager();
```

This also means that the following types no longer requires a `GraphicsDevice` in it's constructor: `SpriteBatch`, `Texture2D`, `Texture3D`, `TextureCube`, `RenderTarget2D`, `RenderTargetCube`, `VertexBuffer`, `IndexBuffer`, `DynamicVertexBuffer`, `DynamicIndexBuffer`, `AlphaTestEffect`, `BasicEffect`, `DualTextureEffect`, `EnvironmentMapEffect`, `SkinnedEffect`, `SpriteEffect`, `Effect`, `Video`, and `VideoPlayer`.
The following types no longer requires a `GraphicsDevice` in it's constructor: `SpriteBatch`, `Texture2D`, `Texture3D`, `TextureCube`, `RenderTarget2D`, `RenderTargetCube`, `VertexBuffer`, `IndexBuffer`, `DynamicVertexBuffer`, `DynamicIndexBuffer`, `SpriteEffect`, `Effect`, `Video`, and `VideoPlayer`.

### Removed the content pipeline

The runtime for loading assets using `ContentManager` and all the related types have been removed. For loading a `Texture2D` use `Texture2D.FromStream`. For loading a `SoundEffect` use `SoundEffect.FromStream`. For loading an `Effect` use `Effect.FromStream`. Tther types that you previously used `ContentManager` to load from disk will have similar functions or have a suitable constructor (this was always true in FNA).

### Removed stock effects and friends: `AlphaTestEffect`, `BasicEffect`, `DualTextureEffect`, `EffectHelpers`, `EnvironmentalMapEffect`, `SkinnedEffect`, `IEffectLights`, and `IEffectMatrices`

These default shaders can easily be implemented yourself. In fact, I recommend you write your own shaders for better understanding and control of your game. To learn how to build `.fx` files see the [FNA documentation](https://github.com/FNA-XNA/FNA/wiki/Appendix-D:-MonoGame-Compatibility#incompatible-formats).

The only exception of course is that `SpriteEffect` is still remaining for support of `SpriteBatch` which is not yet ready to be removed.

### Removed packed vectors (pixel formats): - `Alpha8`, `Bgr565`, `Bgra4444`, etc.

These types were not used by anything; if you need them in your game copy over the ones you need.

This file was deleted.

0 comments on commit 39128e8

Please sign in to comment.