Skip to content

Commit

Permalink
Android .NET 8 works in Glue.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Mar 23, 2024
1 parent df74803 commit 9c9bb62
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ private Texture2D LoadTextureFromFile(string loc)

Texture2D file = null;

#if NET8_0_OR_GREATER && (ANDROID || IOS)
if(loc.StartsWith("./"))
{
loc = loc.Substring(2);
}
#endif

using (Stream titleStream = FileManager.GetStreamForFile(loc))
{
file = Texture2D.FromStream(Renderer.GraphicsDevice, titleStream);
Expand Down
11 changes: 9 additions & 2 deletions Engines/FlatRedBallXNA/FlatRedBall/Content/ContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ public static Texture2D GetDefaultFontTexture(GraphicsDevice graphicsDevice)
try
{

using (var stream = androidAssetManager.Open("content/defaultfonttexture.png"))
var fileName = "Content/defaultfonttexture.png";

#if !NET8_0
fileName = "content/defaultfonttexture.png";

#endif

using (var stream = androidAssetManager.Open(fileName))
{
texture = Texture2D.FromStream(graphicsDevice, stream);
}
Expand All @@ -125,7 +132,7 @@ public static Texture2D GetDefaultFontTexture(GraphicsDevice graphicsDevice)
#else


var colors = DefaultFontDataColors.GetColorArray();
var colors = DefaultFontDataColors.GetColorArray();

Texture2D texture = new Texture2D(graphicsDevice, 256, 128);

Expand Down
8 changes: 3 additions & 5 deletions Engines/FlatRedBallXNA/FlatRedBall/FlatRedBallServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public class SyntaxVersionAttribute : Attribute
public int Version;
}

[SyntaxVersion(Version=54)]
[SyntaxVersion(Version=55)]
public static partial class FlatRedBallServices
{
internal static SingleThreadSynchronizationContext singleThreadSynchronizationContext;
Expand Down Expand Up @@ -779,10 +779,8 @@ public static void InitializeShaders()


var shaderFileName =
"Content/shader";
#if ANDROID
shaderFileName = shaderFileName.ToLower();
#endif
"Content/Shader";

var preInitGlobalContent = new Microsoft.Xna.Framework.Content.ContentManager(mServices);
Renderer.Effect = preInitGlobalContent.Load<Effect>(shaderFileName);

Expand Down
24 changes: 10 additions & 14 deletions Engines/FlatRedBallXNA/FlatRedBall/IO/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ public static bool FileExists(string fileName)


// I think we can make this to-lower on iOS and Android so we don't have to spread to-lowers everywhere else:
#if !NET8_0_OR_GREATER
fileName = fileName.ToLowerInvariant();
#endif

#if ANDROID
// We may be checking for a file outside of the title container
Expand All @@ -468,17 +470,16 @@ public static bool FileExists(string fileName)
{
stream = TitleContainer.OpenStream(fileName);
}
#if MONODROID
catch (Java.IO.FileNotFoundException fnfe)
#if MONODROID || ANDROID
catch (Java.IO.FileNotFoundException)
{
return false;
}
#else
#endif
catch (FileNotFoundException fnfe)
{
return false;
}
#endif

if (stream != null)
{
Expand All @@ -491,8 +492,8 @@ public static bool FileExists(string fileName)
}
}
#else
if (fileName.Length > 1 && fileName[0] == '.' && fileName[1] == '/')

if (fileName.Length > 1 && fileName[0] == '.' && fileName[1] == '/')
fileName = fileName.Substring(2);

return System.IO.File.Exists(fileName);
Expand Down Expand Up @@ -1838,7 +1839,7 @@ public static Stream GetStreamForFile(string fileName, FileMode mode)
fileName = FileManager.RelativeDirectory + fileName;
}

#if IOS || ANDROID
#if (IOS || ANDROID) && !NET8_0_OR_GREATER
fileName = fileName.ToLowerInvariant();
#endif

Expand All @@ -1848,8 +1849,7 @@ public static Stream GetStreamForFile(string fileName, FileMode mode)
fileName = fileName.Substring(2);
}
Stream stream = null;
#if USES_DOT_SLASH_ABOLUTE_FILES && !IOS && !ANDROID
// Silverlight and 360 don't like ./ at the start of the file name, but that's what we use to identify an absolute path
#if USES_DOT_SLASH_ABOLUTE_FILES
if (fileName.Length > 1 && fileName[0] == '.' && fileName[1] == '/')
fileName = fileName.Substring(2);

Expand All @@ -1859,19 +1859,15 @@ public static Stream GetStreamForFile(string fileName, FileMode mode)
{
fileName = GetIsolatedStorageFileName(fileName);

#if WINDOWS_8 || UWP
throw new NotImplementedException();
#else
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, mode, mIsolatedStorageFile);

stream = isfs;
#endif
}
else
{


#if ANDROID || WINDOWS_8 || IOS || UWP
#if ANDROID || IOS
stream = TitleContainer.OpenStream(fileName);
#else

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>$(DefineConstants);FRB_XNA;ANDROID;MONOGAME;XNA4;MONOGAME_381</DefineConstants>
<DefineConstants>$(DefineConstants);ANDROID;FRB_XNA;MONOGAME;MONOGAME_381;XNA4;USE_ISOLATED_STORAGE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>$(DefineConstants);FRB_XNA;ANDROID;MONOGAME;XNA4;MONOGAME_381</DefineConstants>
<DefineConstants>$(DefineConstants);ANDROID;FRB_XNA;MONOGAME;MONOGAME_381;XNA4;USE_ISOLATED_STORAGE</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
28 changes: 23 additions & 5 deletions FRBDK/Glue/Glue/CodeGeneration/ReferencedFileSaveCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class ReferencedFileSaveCodeGenerator : ElementComponentCodeGenerator
public static Dictionary<string, ReferencedFileSave> GlobalContentFilesDictionary =
new Dictionary<string, ReferencedFileSave>();

// See GluxVersions 55: https://docs.flatredball.com/flatredball/glue-reference/glujglux
// This is set when projects are loaded if using case sensitive versions
public static bool GenerateCaseSensitive { get; set; } = false;

public static void RefreshGlobalContentDictionary()
{
Expand Down Expand Up @@ -835,14 +838,29 @@ public static void AddIfConditionalSymbolIfNecesssary(ICodeBlock codeBlock, Refe

public static string GetFileToLoadForRfs(ReferencedFileSave referencedFile, AssetTypeInfo ati = null)
{
var referencedFileName = "content/" + referencedFile.Name;
ati ??= referencedFile.GetAssetTypeInfo();
if (ati?.MustBeAddedToContentPipeline == true || referencedFile.UseContentPipeline)
if(GenerateCaseSensitive)
{
referencedFileName = FileManager.RemoveExtension(referencedFileName);
}
var referencedFileName = "Content/" + referencedFile.Name;
if (ati?.MustBeAddedToContentPipeline == true || referencedFile.UseContentPipeline)
{
referencedFileName = FileManager.RemoveExtension(referencedFileName);
}

return referencedFileName.ToLowerInvariant();
return referencedFileName;

}
else
{
var referencedFileName = "content/" + referencedFile.Name;
if (ati?.MustBeAddedToContentPipeline == true || referencedFile.UseContentPipeline)
{
referencedFileName = FileManager.RemoveExtension(referencedFileName);
}

return referencedFileName.ToLowerInvariant();

}
}

public static void AppendAddUnloadMethod(ICodeBlock codeBlock, IElement element)
Expand Down
2 changes: 2 additions & 0 deletions FRBDK/Glue/Glue/IO/ProjectLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ private void PerformGluxLoad(string projectFileName, string glueProjectFile, Ini

// Fix before doing any generation
GlueState.Self.CurrentGlueProject.FixAllTypesPostLoad();
ReferencedFileSaveCodeGenerator.GenerateCaseSensitive =
GlueState.Self.CurrentGlueProject.FileVersion >= (int)SaveClasses.GlueProjectSave.GluxVersions.CaseSensitiveLoading;
GlueCommands.Self.GenerateCodeCommands.GenerateAllCode();
Section.EndContextAndTime();

Expand Down
19 changes: 3 additions & 16 deletions FRBDK/Glue/Glue/Plugins/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,22 +1520,9 @@ internal static void ReactToVariableAdded(CustomVariable newVariable)

internal static void ReactToVariableRemoved(CustomVariable removedVariable)
{
foreach (PluginManager pluginManager in mInstances)
{
var plugins = pluginManager.ImportedPlugins.Where(x => x.ReactToVariableRemoved != null);

foreach (var plugin in plugins)
{
var container = pluginManager.mPluginContainers[plugin];
if (container.IsEnabled)
{
PluginCommand(() =>
{
plugin.ReactToVariableRemoved(removedVariable);
}, container, "Failed in ReactToVariableRemoved");
}
}
}
CallMethodOnPlugin(
plugin => plugin.ReactToVariableRemoved(removedVariable),
plugin => plugin.ReactToVariableRemoved != null);
}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion FRBDK/Glue/Glue/SaveClasses/GlueProjectSave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public enum GluxVersions

// February 23, 2023
ITopDownEntity = 54,

// March 23, 2024
CaseSensitiveLoading = 55,

// Stop! If adding an entry here, modify SyntaxVersionAttribute on FlatRedBallServices
// and LatestVersion down below
}
Expand All @@ -149,7 +153,7 @@ public enum GluxVersions

#region Versions

public const int LatestVersion = (int)GluxVersions.ITopDownEntity;
public const int LatestVersion = (int)GluxVersions.CaseSensitiveLoading;

public int FileVersion { get; set; }

Expand Down
52 changes: 43 additions & 9 deletions FRBDK/Glue/Glue/VSHelpers/Projects/AndroidMonoGameNet8Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,53 @@ public override string ProcessInclude(string path)
{
var returnValue = base.ProcessInclude(path);

if (returnValue != null)
{
// March 23, 2024
// For now we will continue
// to ToLower files just like
// old Android/iOS.
// actually no, adding v55 to handle this
//returnValue = returnValue.ToLowerInvariant();

}
// I think we need to replace and consider slashes as this could be part of a file name
// like assets.png
// March 21, 2024
// Vic asks - are these needed for .NET 8 projects? I don't think they are...
//if (returnValue.StartsWith("assets\\") || returnValue.Contains("assets/"))
//{
// returnValue = "Assets\\" + returnValue.Substring("assets/".Length);
//}
return returnValue;
}

public override string ProcessLink(string path)
{
var returnValue = base.ProcessLink(path);
if (returnValue != null)
{

// Android is case-sensitive
// v55 handles this
//returnValue = returnValue.ToLowerInvariant();

//if (returnValue.StartsWith("assets/", StringComparison.OrdinalIgnoreCase) || returnValue.StartsWith(@"assets\", StringComparison.OrdinalIgnoreCase))
//{
// // Assets folder is capitalized in FRB Android projects:
// returnValue = "A" + returnValue[1..];
//}

if (returnValue.Contains("/", StringComparison.OrdinalIgnoreCase))
{
returnValue = returnValue.Replace("/", @"\");
}
}

// I think we need to replace and consider slashes as this could be part of a file name
// like assets.png
// March 21, 2024
// Vic asks - are these needed for .NET 8 projects? I don't think they are...
//returnValue = returnValue.ToLowerInvariant();
//if (returnValue.StartsWith("assets\\") || returnValue.Contains("assets/"))
//{
// returnValue = "Assets\\" + returnValue.Substring("assets/".Length);
//}
return returnValue;
}


public override string ContentDirectory => "content/";

public override List<string> LibraryDlls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
<DefineConstants>$(DefineConstants);ANDROID</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Remove="content\defaultfonttexture.png" />
<None Remove="content\Shader.xnb" />
<None Remove="Content\defaultfonttexture.png" />
<None Remove="Content\Shader.xnb" />
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="content\defaultfonttexture.png" />
<AndroidAsset Include="content\shader.xnb" />
<AndroidAsset Include="Content\defaultfonttexture.png" />
<AndroidAsset Include="Content\Shader.xnb" />
</ItemGroup>
<ItemGroup>
<Compile Include="Activity1.cs" />
Expand Down

0 comments on commit 9c9bb62

Please sign in to comment.