MonoGame / MonoGame

One framework for creating powerful cross-platform games.
http://www.monogame.net
Other
11.57k stars 2.93k forks source link

Support common platform identifier for non-platform specific content #8556

Open tomspilman opened 3 weeks ago

tomspilman commented 3 weeks ago

Intent

The final XNB from the content pipeline embeds an identifier for the target platform the content is built for. Also at ContentManager.Load it looks for the identifier and fails to load if it doesn't match the current platform.

This issue with this is that for many content files... mostly data files... there is no platform specific content. So the content is identical on all platforms except for the identifier at the top of the XNB. This also causes binary diff tools to report differences in the file when there is really nothing different (other than the single byte of the platform identifier itself).

What i propose is using a common identifier (maybe the original w or x identifier) in cases where the content is not platform specific. To do this we would need to extend the ContentWriter and ContentTypeWriter to identify "common" non-platform specific content.

Motivation

This would benefit users of larger games manage content better.

TROLLERLOLL commented 2 weeks ago

I found an issue with Native Aot, which would have to do with XNB files and there for might be smart to do at the same time.

If you have a pipeline extension it can't read the resulting xnb file because it uses reflections to create a new instance of the ContentTypeReader. You could just require the user to pass an instance of the correct ContentTypeReader as a variable (which would need to be added) Error I encountered

Object reference not set to an instance of an object.
   at Microsoft.Xna.Framework.Content.ContentTypeReaderManager.LoadAssetReaders(ContentReader reader) + 0xa57
   at Microsoft.Xna.Framework.Content.ContentReader.InitializeTypeReaders() + 0x40
   at Microsoft.Xna.Framework.Content.ContentReader.ReadAsset[T]() + 0x19
   at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject) + 0xb6
   at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName) + 0xc3