diff --git a/Assets/Plugins/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs b/Assets/Plugins/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs index b26d8f0..dbf8166 100644 --- a/Assets/Plugins/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs +++ b/Assets/Plugins/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs @@ -27,6 +27,7 @@ using System; using OpenMetaverse.Imaging; +using UnityEngine; namespace OpenMetaverse.Assets { @@ -97,9 +98,10 @@ namespace OpenMetaverse.Assets this.Components = 0; + Texture2D texture = new Texture2D(1,1); // using (var reader = new OpenJpegDotNet.IO.Reader(AssetData)) - var texture = Imaging.T2D.LoadT2DWithoutMipMaps(AssetData); - Image = new ManagedImage(texture); + T2D.LoadT2DWithoutMipMaps(AssetData, texture); //blocking. + Image = new ManagedImage(texture); //blocking. // using (var reader = new OpenJpegDotNet.IO.Reader(AssetData)) // { // // *hack: decode from ManagedImage directly or better yet, get rid of ManagedImage entirely! diff --git a/Assets/Plugins/LibreMetaverse/Imaging/T2D.cs b/Assets/Plugins/LibreMetaverse/Imaging/T2D.cs index caee5fb..95ee723 100644 --- a/Assets/Plugins/LibreMetaverse/Imaging/T2D.cs +++ b/Assets/Plugins/LibreMetaverse/Imaging/T2D.cs @@ -1,12 +1,16 @@ -using UnityEngine; +using System; +using UnityEngine; +using UnityEngine.PlayerLoop; namespace OpenMetaverse.Imaging { public class T2D { - public static Texture2D LoadT2DWithoutMipMaps(byte[] thebytes) + // Create a NEW T2D, by providing a bitmap in byte-array form. + public static Texture2D LoadT2DWithoutMipMaps(byte[] thebytes, Texture2D texture) { - var texture = new Texture2D(1, 1, TextureFormat.ARGB32, false); // impt there is a jobs bug here + // texture = new Texture2D(1, 1, TextureFormat.ARGB32, false); // impt there is a jobs bug here + //also, new Texture2d can't be called outside the main thread! var loaderSettings = AsyncImageLoader.LoaderSettings.Default; loaderSettings.generateMipmap = false; // impt there is a bug here diff --git a/Assets/Raindrop/Disk/DirectoryHelpers.cs b/Assets/Raindrop/Disk/DirectoryHelpers.cs index fd2e0a8..8644603 100644 --- a/Assets/Raindrop/Disk/DirectoryHelpers.cs +++ b/Assets/Raindrop/Disk/DirectoryHelpers.cs @@ -2,50 +2,59 @@ namespace Raindrop.Disk { - public class DirectoryHelpers + public static class DirectoryHelpers { - // returns SD card if the bool is true OR the sd card is not available. - // otherwise i will return internal-but-shared storage - public static string GetAndroidExternalFilesDir(bool preferSDcard) + // returns SD card if the bool is true OR the sd card is not available. + // otherwise i will return internal-but-shared storage + private static string GetAndroidExternalFilesDir(bool preferSDcard) + { + using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { - using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) + using (AndroidJavaObject context = unityPlayer.GetStatic("currentActivity")) { - using (AndroidJavaObject context = unityPlayer.GetStatic("currentActivity")) - { - // Get all available external file directories (emulated and sdCards) - AndroidJavaObject[] externalFilesDirectories = context.Call("getExternalFilesDirs", null); - AndroidJavaObject emulated = null; - AndroidJavaObject sdCard = null; + // Get all available external file directories (emulated and sdCards) + AndroidJavaObject[] externalFilesDirectories = context.Call("getExternalFilesDirs", null); + AndroidJavaObject emulated = null; + AndroidJavaObject sdCard = null; - for (int i = 0; i < externalFilesDirectories.Length; i++) + for (int i = 0; i < externalFilesDirectories.Length; i++) + { + AndroidJavaObject directory = externalFilesDirectories[i]; + using (AndroidJavaClass environment = new AndroidJavaClass("android.os.Environment")) { - AndroidJavaObject directory = externalFilesDirectories[i]; - using (AndroidJavaClass environment = new AndroidJavaClass("android.os.Environment")) - { - // Check which one is the emulated and which the sdCard. - bool isRemovable = environment.CallStatic ("isExternalStorageRemovable", directory); - bool isEmulated = environment.CallStatic ("isExternalStorageEmulated", directory); - if (isEmulated) - emulated = directory; - else if (isRemovable && isEmulated == false) - sdCard = directory; - } + // Check which one is the emulated and which the sdCard. + bool isRemovable = environment.CallStatic ("isExternalStorageRemovable", directory); + bool isEmulated = environment.CallStatic ("isExternalStorageEmulated", directory); + if (isEmulated) + emulated = directory; + else if (isRemovable && isEmulated == false) + sdCard = directory; } - // Return the sdCard if available - if (sdCard != null && preferSDcard) - return sdCard.Call("getAbsolutePath"); - else - return emulated.Call("getAbsolutePath"); } + // Return the sdCard if available + if (sdCard != null && preferSDcard) + return sdCard.Call("getAbsolutePath"); + else + return emulated.Call("getAbsolutePath"); } } + } - //gives us the base directory where we should be storing the cache files - public static string GetCacheDir() - { - return Application.persistentDataPath; //todo : correctly implement this. + //gives us the base directory where we should be storing the cache files + public static string GetCacheDir() + { + #if UNITY_EDITOR + + return Application.persistentDataPath; //todo : correctly implement this. + #endif + + #if UNITY_ANDROID + + return GetAndroidExternalFilesDir(true); //todo : correctly implement this. + #endif - } + + } } } \ No newline at end of file diff --git a/Assets/Raindrop/RaindropInstance.cs b/Assets/Raindrop/RaindropInstance.cs index 0dfb847..eb7bf71 100644 --- a/Assets/Raindrop/RaindropInstance.cs +++ b/Assets/Raindrop/RaindropInstance.cs @@ -38,6 +38,7 @@ using Raindrop.Netcom; using Raindrop.Media; using Raindrop.UI.Notification; using OpenMetaverse; +using Raindrop.Disk; using Raindrop.ServiceLocator; using UnityEngine; using Logger = OpenMetaverse.Logger; @@ -268,7 +269,7 @@ namespace Raindrop public RaindropInstance(GridClient client0) { - _appDataDir = Application.persistentDataPath; + _appDataDir = DirectoryHelpers.GetCacheDir(); //Application.persistentDataPath; _streamingAssetsDir = Application.streamingAssetsPath; InitializeLoggingAndConfig(); diff --git a/Assets/Raindrop/Unity/SceneBootstrapperGenerator.cs b/Assets/Raindrop/Unity/SceneBootstrapperGenerator.cs new file mode 100644 index 0000000..1d09599 --- /dev/null +++ b/Assets/Raindrop/Unity/SceneBootstrapperGenerator.cs @@ -0,0 +1,21 @@ +using Raindrop.Services.Bootstrap; +using UnityEngine; + +namespace Raindrop.Unity +{ + public class SceneBootstrapperGenerator + { + public static GameObject mtd; + public static void Init() + { + mtd = GameObject.CreatePrimitive(PrimitiveType.Cube); + mtd.AddComponent(); + + } + public static void AddMainThreadDispatcher() + { + mtd.AddComponent(); + } + + } +} \ No newline at end of file diff --git a/Assets/Raindrop/Unity/SceneBootstrapperGenerator.cs.meta b/Assets/Raindrop/Unity/SceneBootstrapperGenerator.cs.meta new file mode 100644 index 0000000..1888685 --- /dev/null +++ b/Assets/Raindrop/Unity/SceneBootstrapperGenerator.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6d694132a38d459ba7e1da4f79021833 +timeCreated: 1642647269 \ No newline at end of file diff --git a/Assets/Tests/ImagingTests/ImagingTests.cs b/Assets/Tests/ImagingTests/ImagingTests.cs index 8e35816..9ed18b8 100644 --- a/Assets/Tests/ImagingTests/ImagingTests.cs +++ b/Assets/Tests/ImagingTests/ImagingTests.cs @@ -67,9 +67,11 @@ namespace Raindrop.Tests.ImagingTests byte[] thebytes = BetterStreamingAssets.ReadAllBytes(_inputImageSubPath); Assert.True(thebytes.Length > 0); - - - var texture = T2D.LoadT2DWithoutMipMaps(thebytes); + + + Texture2D texture + = new Texture2D(1, 1, TextureFormat.ARGB32, false); + T2D.LoadT2DWithoutMipMaps(thebytes, texture); Assert.True(texture.height > 5); //todo so arbitrary @@ -98,10 +100,9 @@ namespace Raindrop.Tests.ImagingTests } - + // fixme: after implementing on-sd/on-device caching preferences [Test] - [UnityPlatform (RuntimePlatform.Android)] - public void printImportantPaths_Android() + public void printImportantPaths_Platforms() { //get from SA // var j2p_bytes = BetterStreamingAssets.ReadAllBytes(_largeImageRelativePath); @@ -121,10 +122,10 @@ namespace Raindrop.Tests.ImagingTests // should be /storage/emulated/0/Android/data/com.UnityTestRunner.UnityTestRunner/files/Pictures/ Debug.Log("Application.sataPath" + Application.dataPath); - Debug.Log("GetAndroidExternalFilesDir internal"+ Disk.DirectoryHelpers.GetAndroidExternalFilesDir(true)); + // Debug.Log("GetAndroidExternalFilesDir internal"+ Disk.DirectoryHelpers.GetAndroidExternalFilesDir(true)); // should be /storage/6106-8710/Android/data/com.UnityTestRunner.UnityTestRunner/files - Debug.Log("GetAndroidExternalFilesDir prefersdcard"+ Disk.DirectoryHelpers.GetAndroidExternalFilesDir(false)); + // Debug.Log("GetAndroidExternalFilesDir prefersdcard"+ Disk.DirectoryHelpers.GetAndroidExternalFilesDir(false)); //should be /storage/emulated/0/Android/data/com.UnityTestRunner.UnityTestRunner/files/Pictures/ } diff --git a/Assets/Tests/RaindropIntegrationTests.cs b/Assets/Tests/RaindropIntegrationTests.cs index 01e2e14..eceedd2 100644 --- a/Assets/Tests/RaindropIntegrationTests.cs +++ b/Assets/Tests/RaindropIntegrationTests.cs @@ -214,7 +214,7 @@ namespace Raindrop.Tests Assert.True(instance.Client.Network.Connected == false, "check API that we are logged out"); LoginPresenterIsAvailable(vm); TypeUserAndPassIntoLoginPanel(); - yield return new WaitForSeconds(2); + yield return new WaitForSeconds(5); Utils.UIHelpers.ClickButtonByUnityName("LoginBtn"); //assert the backend API; that we are logged in.