-
-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add compile time exclusion #964
Add compile time exclusion #964
Conversation
The extension exist on KNI as well. The extension will not work on FNA because ContentReader doesn't have a graphicsDevice field. The proper way to get a graphicsDevice inside a ContentTypeReader, is through the ServiceProvider.
|
Interesting, I'm not trying to add it, I'm trying to exclude it. It sounds like you're saying it's either in or won't work in eveything (fna, kni, monogame). If thats true, I say it should be removed from extended. This method extension is in monogame. I don't know if "monogame/kni" is different than "kni". So I'm not sure what you mean in your last statement, as monogame does have this method. |
You are excluding it from monogame because of a conflct. The same method exist on KNI, so you have to exclude it from KNI as well. Which leaves FNA, where the reflection will fail. I think it's ok to remove it, as it didn't work for some time now. Unless it's used from Extended internally. |
I could be adjusted to remove reflection so it's compatible with FNA. This is also a step that will need to be looked at in the future to ensure MGE is AoT compatible once MonoGame removes the BRUTE dependency. So we would need to adjust it to the service pattern like MonoGame and KNI has implemented like suggested by @nkast , but only for FNA The #if FNA
public static GraphicsDevice GetGraphicsDevice(this ContentReader contentReader)
{
var serviceProvider = contentReader.ContentManager.ServiceProvider;
var graphicsDeviceService = serviceProvider.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
if (graphicsDeviceService == null)
{
throw new InvalidOperationException("No Graphics Device Service");
}
return graphicsDeviceService.GraphicsDevice;
}
#endif Since FNA's goal is to remain 1:1 compatible with the XNA Api, i don't see them adding this extension method in. |
Sounds good @nkast and @AristurtleDev. This small change spawned because I was trying to validate and update the documentation for ContentManager Extensions in Monogame.Extended . https://www.monogameextended.net/docs/features/contentmanager/contentManager-extensions/ Please let me know if there are any other changes you wish, I'm going to notate the section in the Extended docs to indicate that it only applies for FNI. |
Looks good. Thanks. |
Thanks @kaltinril |
This fixes an issue where because Monogame now comes with this extension method, it fails if someone has Monogame and Extended functionality mixed on in their ContentTypeReader class.
https://github.com/MonoGame/MonoGame/blob/8df1e3edb3076b010822d2c9cf019f2f7f5f70a0/MonoGame.Framework/Content/ContentReaderExtensions.cs#L24
Example code that will break, can't have both of these using statements. To fix I've simply made it so Monogame.Extended doesn't add these methods during compile time.