Przeglądaj źródła

Merge remote-tracking branch 'origin/dev' into new-render

# Conflicts:
#	oxygine/src/oxygine/core/oxygine.cpp
[email protected] 8 lat temu
rodzic
commit
05fb088946

+ 4 - 1
examples/Demo/src/example.cpp

@@ -49,6 +49,7 @@ Resources resources;
 spStage stage2;
 spStage stage2;
 #endif
 #endif
 
 
+
 class TestActor: public Test
 class TestActor: public Test
 {
 {
 public:
 public:
@@ -56,6 +57,8 @@ public:
     TestActor()
     TestActor()
     {
     {
 
 
+
+
         _x = 90;//getStage()->getWidth()/2.0f;
         _x = 90;//getStage()->getWidth()/2.0f;
         _y = 80;
         _y = 80;
 
 
@@ -165,7 +168,7 @@ void example_init()
     //Load resources in xml file
     //Load resources in xml file
     resources.loadXML("xmls/res.xml");
     resources.loadXML("xmls/res.xml");
     Test::init();
     Test::init();
-
+    
     Test::instance = new TestActor;
     Test::instance = new TestActor;
     getStage()->addChild(Test::instance);
     getStage()->addChild(Test::instance);
 
 

+ 8 - 1
oxygine/SDL/android/lib/src/org/oxygine/lib/Utils.java

@@ -9,7 +9,7 @@ import android.net.NetworkInfo;
 import android.net.Uri;
 import android.net.Uri;
 import android.provider.Settings;
 import android.provider.Settings;
 import android.app.PendingIntent;
 import android.app.PendingIntent;
-
+import android.os.StatFs;
 import java.io.File;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.IOException;
@@ -22,6 +22,13 @@ public class Utils {
         return System.currentTimeMillis();
         return System.currentTimeMillis();
     }
     }
 
 
+    public static long getFreeSpace(String path) {
+        StatFs fs = new StatFs(path);
+        long blocks = fs.getFreeBlocks();
+        long blsize = fs.getBlockSize();
+        return blocks * blsize;
+    }
+
     public static String getLanguage() {
     public static String getLanguage() {
         return Locale.getDefault().getLanguage();
         return Locale.getDefault().getLanguage();
     }
     }

+ 1 - 0
oxygine/src/oxygine/HttpRequestTask.h

@@ -57,6 +57,7 @@ namespace oxygine
         void setFileName(const std::string& name, bool continueDownload = false);
         void setFileName(const std::string& name, bool continueDownload = false);
         void setCacheEnabled(bool enabled);
         void setCacheEnabled(bool enabled);
 
 
+
         void setResponseCodeChecker(const responseCodeChecker& f) {_responseCodeChecker = f;}
         void setResponseCodeChecker(const responseCodeChecker& f) {_responseCodeChecker = f;}
         /**by default only response code == 200 is succeded, other codes are dispatching Event::ERROR*/
         /**by default only response code == 200 is succeded, other codes are dispatching Event::ERROR*/
         void setSuccessOnAnyResponseCode(bool en);
         void setSuccessOnAnyResponseCode(bool en);

+ 20 - 20
oxygine/src/oxygine/MaterialCache.cpp

@@ -10,32 +10,32 @@ namespace oxygine
         MaterialX::compare cm;
         MaterialX::compare cm;
         other.update(hash, cm);
         other.update(hash, cm);
 
 
-        MaterialX* free = 0;
-        for (auto m_ : _materials)
-        {
-            MaterialX* mat = m_.get();
-            if (mat->_compare != cm)
-                continue;
-            if (mat->_ref_counter == 1)
-                free = mat;
-            if (mat->_hash != hash)
-                continue;
-            bool same = cm(mat, &other);
-            if (same)
-                return mat;
-        }
-        if (free)
+
+        materials::iterator itl = _materials.lower_bound(hash);
+                
+        if (itl != _materials.end())
         {
         {
-            free->copyFrom(other);
-            free->_hash = hash;
-            free->_compare = cm;
-            return free;
+            MaterialX *sec = itl->second.get();
+            if (cm(sec, &other))
+                return sec;
+
+            ++itl;
+
+            //same hash but not same object
+            materials::iterator ith = _materials.upper_bound(hash);
+            for(; itl != ith; itl++)
+            { 
+                MaterialX *sec = itl->second.get();
+                if (cm(sec, &other))
+                    return sec;
+            }
         }
         }
 
 
+
         MaterialX* copy = other.clone();
         MaterialX* copy = other.clone();
         copy->_hash = hash;
         copy->_hash = hash;
         copy->_compare = cm;
         copy->_compare = cm;
-        _materials.push_back(copy);
+        _materials.insert(std::make_pair(hash, copy));
 
 
         return copy;
         return copy;
     }
     }

+ 2 - 1
oxygine/src/oxygine/MaterialCache.h

@@ -3,6 +3,7 @@
 #include "core/ref_counter.h"
 #include "core/ref_counter.h"
 #include "core/intrusive_ptr.h"
 #include "core/intrusive_ptr.h"
 #include <vector>
 #include <vector>
+#include <unordered_map>
 
 
 namespace oxygine
 namespace oxygine
 {
 {
@@ -32,7 +33,7 @@ namespace oxygine
         size_t getTotalMaterials() const { return _materials.size(); }
         size_t getTotalMaterials() const { return _materials.size(); }
 
 
     protected:
     protected:
-        typedef std::vector<spMaterialX> materials;
+        typedef std::unordered_multimap<size_t, spMaterialX> materials;
         materials _materials;
         materials _materials;
 
 
         MaterialX* clone_(const MaterialX& other);
         MaterialX* clone_(const MaterialX& other);

+ 23 - 15
oxygine/src/oxygine/core/android/jniUtils.cpp

@@ -14,6 +14,7 @@ jmethodID _jUtils_getLanguage = 0;
 jmethodID _jUtils_getPackage = 0;
 jmethodID _jUtils_getPackage = 0;
 jmethodID _jUtils_getProperty = 0;
 jmethodID _jUtils_getProperty = 0;
 jmethodID _jUtils_isNetworkAvailable = 0;
 jmethodID _jUtils_isNetworkAvailable = 0;
+jmethodID _jUtils_getFreeSpace = 0;
 jmethodID _jRunnable_run = 0;
 jmethodID _jRunnable_run = 0;
 
 
 namespace oxygine
 namespace oxygine
@@ -44,8 +45,11 @@ namespace oxygine
             _jUtils = (jclass)env->NewGlobalRef(env->FindClass("org/oxygine/lib/Utils"));
             _jUtils = (jclass)env->NewGlobalRef(env->FindClass("org/oxygine/lib/Utils"));
             JNI_NOT_NULL(_jUtils);
             JNI_NOT_NULL(_jUtils);
 
 
-            _jUtils_getTimeUTCMS = env->GetStaticMethodID(_jUtils, "getTimeUTCMS", "()J");
-            JNI_NOT_NULL(_jUtils_getTimeUTCMS);
+			_jUtils_getTimeUTCMS = env->GetStaticMethodID(_jUtils, "getTimeUTCMS", "()J");
+			JNI_NOT_NULL(_jUtils_getTimeUTCMS);
+
+			_jUtils_getFreeSpace = env->GetStaticMethodID(_jUtils, "getFreeSpace", "(Ljava/lang/String;)J");
+			JNI_NOT_NULL(_jUtils_getFreeSpace);
 
 
             _jUtils_getLanguage = env->GetStaticMethodID(_jUtils, "getLanguage", "()Ljava/lang/String;");
             _jUtils_getLanguage = env->GetStaticMethodID(_jUtils, "getLanguage", "()Ljava/lang/String;");
             JNI_NOT_NULL(_jUtils_getLanguage);
             JNI_NOT_NULL(_jUtils_getLanguage);
@@ -74,20 +78,11 @@ namespace oxygine
 
 
     int64 jniGetTimeUTCMS()
     int64 jniGetTimeUTCMS()
     {
     {
-        try
-        {
-            JNIEnv* env = jniGetEnv();
-            LOCAL_REF_HOLDER(env);
-
-            jlong value = env->CallStaticLongMethod(_jUtils, _jUtils_getTimeUTCMS);
-            return value;
-        }
-        catch (const notFound&)
-        {
-
-        }
+        JNIEnv* env = jniGetEnv();
+        LOCAL_REF_HOLDER(env);
 
 
-        return 0;
+        jlong value = env->CallStaticLongMethod(_jUtils, _jUtils_getTimeUTCMS);
+        return value;
     }
     }
 
 
     std::string     jniGetLanguage()
     std::string     jniGetLanguage()
@@ -128,6 +123,19 @@ namespace oxygine
         return false;
         return false;
     }
     }
 
 
+
+	int64			jniGetFreeSpace(const char *path)
+	{
+		JNIEnv* env = jniGetEnv();
+		LOCAL_REF_HOLDER(env);
+
+		jstring jarg = env->NewStringUTF(path);
+		jlong value = env->CallStaticLongMethod(_jUtils, _jUtils_getFreeSpace, jarg);
+		return value;
+
+		
+	}
+
     bool            jniExit()
     bool            jniExit()
     {
     {
         try
         try

+ 2 - 0
oxygine/src/oxygine/core/android/jniUtils.h

@@ -18,6 +18,8 @@ namespace oxygine
     std::string     jniGetPackage();
     std::string     jniGetPackage();
     bool            jniIsNetworkAvailable();
     bool            jniIsNetworkAvailable();
 
 
+	int64			jniGetFreeSpace(const char *);
+
     bool            jniExit();
     bool            jniExit();
     void            jniRestartApp();
     void            jniRestartApp();
     void            jniMoveTaskToBack();
     void            jniMoveTaskToBack();

+ 2 - 0
oxygine/src/oxygine/core/ios/ios.h

@@ -16,4 +16,6 @@ namespace oxygine
 
 
     void iosGetMemoryUsage(size_t& a);
     void iosGetMemoryUsage(size_t& a);
     void iosNavigate(const char*);
     void iosNavigate(const char*);
+    
+    int64 iosGetFreeDiskspace();
 }
 }

+ 22 - 0
oxygine/src/oxygine/core/ios/ios.mm

@@ -162,4 +162,26 @@ namespace oxygine
         [[UIApplication sharedApplication] openURL:url];
         [[UIApplication sharedApplication] openURL:url];
 #endif
 #endif
     }
     }
+    
+    
+    int64 iosGetFreeDiskspace()
+    {
+        int64 totalSpace = 0;
+        int64 totalFreeSpace = 0;
+        NSError *error = nil;
+        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+        NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
+        
+        if (dictionary) {
+            NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
+            NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
+            totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
+            totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
+            NSLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));
+        } else {
+            NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
+        }  
+        
+        return totalFreeSpace;
+    }
 }
 }

+ 14 - 1
oxygine/src/oxygine/core/oxygine.cpp

@@ -1020,7 +1020,20 @@ namespace oxygine
         return true;
         return true;
     }
     }
 
 
-    std::string     getLanguage()
+	int64 getFreeSpace(const char *fullpath /*= 0*/)
+	{
+#ifdef __ANDROID__
+		if (fullpath)
+			return jniGetFreeSpace(fullpath);
+		return jniGetFreeSpace(file::wfs().getFullPath("").c_str());
+#elif __APPLE__
+        return iosGetFreeDiskspace();
+#endif
+        
+		return std::numeric_limits<int64>::max();
+	}
+
+	std::string     getLanguage()
     {
     {
 #ifdef __ANDROID__
 #ifdef __ANDROID__
         return jniGetLanguage();
         return jniGetLanguage();

+ 3 - 0
oxygine/src/oxygine/core/oxygine.h

@@ -31,6 +31,9 @@ namespace oxygine
     /** is any network connection available?*/
     /** is any network connection available?*/
     bool            isNetworkAvailable();
     bool            isNetworkAvailable();
 
 
+
+	int64			getFreeSpace(const char *fullpath = 0);
+
     /**returns locale. ISO 639-1 */
     /**returns locale. ISO 639-1 */
     std::string     getLanguage();
     std::string     getLanguage();