Просмотр исходного кода

Merge branch 'next' of https://github.com/blackberry/GamePlay into bugfix

Adam Blake 12 лет назад
Родитель
Сommit
7546084bbb
2 измененных файлов с 72 добавлено и 26 удалено
  1. 2 0
      gameplay/android/jni/Android.mk
  2. 70 26
      gameplay/src/FileSystem.cpp

+ 2 - 0
gameplay/android/jni/Android.mk

@@ -180,6 +180,7 @@ LOCAL_SRC_FILES := \
     lua/lua_Global.cpp \
     lua/lua_Global.cpp \
     lua/lua_HeightField.cpp \
     lua/lua_HeightField.cpp \
     lua/lua_Image.cpp \
     lua/lua_Image.cpp \
+    lua/lua_ImageControl.cpp \
     lua/lua_ImageFormat.cpp \
     lua/lua_ImageFormat.cpp \
     lua/lua_Joint.cpp \
     lua/lua_Joint.cpp \
     lua/lua_Joystick.cpp \
     lua/lua_Joystick.cpp \
@@ -262,6 +263,7 @@ LOCAL_SRC_FILES := \
     lua/lua_Technique.cpp \
     lua/lua_Technique.cpp \
     lua/lua_Terrain.cpp \
     lua/lua_Terrain.cpp \
     lua/lua_TerrainFlags.cpp \
     lua/lua_TerrainFlags.cpp \
+    lua/lua_TerrainListener.cpp \
     lua/lua_TextBox.cpp \
     lua/lua_TextBox.cpp \
     lua/lua_Texture.cpp \
     lua/lua_Texture.cpp \
     lua/lua_TextureFilter.cpp \
     lua/lua_TextureFilter.cpp \

+ 70 - 26
gameplay/src/FileSystem.cpp

@@ -86,6 +86,27 @@ static bool androidFileExists(const char* filePath)
 static std::string __resourcePath("./");
 static std::string __resourcePath("./");
 static std::map<std::string, std::string> __aliases;
 static std::map<std::string, std::string> __aliases;
 
 
+/**
+ * Gets the fully resolved path.
+ * If the path is relative then it will be prefixed with the resource path.
+ * Aliases will be converted to a relative path.
+ * 
+ * @param path The path to resolve.
+ * @param fullPath The full resolved path. (out param)
+ */
+static void getFullPath(const char* path, std::string& fullPath)
+{
+    if (FileSystem::isAbsolutePath(path))
+    {
+        fullPath.assign(path);
+    }
+    else
+    {
+        fullPath.assign(__resourcePath);
+        fullPath += FileSystem::resolvePath(path);
+    }
+}
+
 /**
 /**
  * 
  * 
  * @script{ignore}
  * @script{ignore}
@@ -259,30 +280,54 @@ bool FileSystem::listFiles(const char* dirPath, std::vector<std::string>& files)
         path.append(dirPath);
         path.append(dirPath);
     }
     }
     path.append("/.");
     path.append("/.");
+    bool result = false;
+
     struct dirent* dp;
     struct dirent* dp;
     DIR* dir = opendir(path.c_str());
     DIR* dir = opendir(path.c_str());
-    if (!dir)
+    if (dir != NULL)
     {
     {
-        return false;
+        while ((dp = readdir(dir)) != NULL)
+        {
+            std::string filepath(path);
+            filepath.append("/");
+            filepath.append(dp->d_name);
+
+            struct stat buf;
+            if (!stat(filepath.c_str(), &buf))
+            {
+                // Add to the list if this is not a directory
+                if (!S_ISDIR(buf.st_mode))
+                {
+                    files.push_back(dp->d_name);
+                }
+            }
+        }
+        closedir(dir);
+        result = true;
     }
     }
-    while ((dp = readdir(dir)) != NULL)
-    {
-        std::string filepath(path);
-        filepath.append("/");
-        filepath.append(dp->d_name);
 
 
-        struct stat buf;
-        if (!stat(filepath.c_str(), &buf))
+#ifdef __ANDROID__
+    // List the files that are in the android APK at this path
+    AAssetDir* assetDir = AAssetManager_openDir(__assetManager, dirPath);
+    if (assetDir != NULL)
+    {
+        AAssetDir_rewind(assetDir);
+        const char* file = NULL;
+        while ((file = AAssetDir_getNextFileName(assetDir)) != NULL)
         {
         {
-            // Add to the list if this is not a directory
-            if (!S_ISDIR(buf.st_mode))
+            std::string filename(file);
+            // Check if this file was already added to the list because it was copied to the SD card.
+            if (find(files.begin(), files.end(), filename) == files.end())
             {
             {
-                files.push_back(dp->d_name);
+                files.push_back(filename);
             }
             }
         }
         }
+        AAssetDir_close(assetDir);
+        result = true;
     }
     }
-    closedir(dir);
-    return true;
+#endif
+
+    return result;
 #endif
 #endif
 }
 }
 
 
@@ -297,13 +342,13 @@ bool FileSystem::fileExists(const char* filePath)
     }
     }
 #endif
 #endif
 
 
-    std::string fullPath(__resourcePath);
-    fullPath += resolvePath(filePath);
+    std::string fullPath;
+    getFullPath(filePath, fullPath);
 
 
     gp_stat_struct s;
     gp_stat_struct s;
 
 
 #ifdef WIN32
 #ifdef WIN32
-    if (stat(fullPath.c_str(), &s) != 0)
+    if (!isAbsolutePath(filePath) && stat(fullPath.c_str(), &s) != 0)
     {
     {
         fullPath = __resourcePath;
         fullPath = __resourcePath;
         fullPath += "../../gameplay/";
         fullPath += "../../gameplay/";
@@ -352,12 +397,12 @@ Stream* FileSystem::open(const char* path, size_t mode)
         return FileStreamAndroid::create(resolvePath(path), modeStr);
         return FileStreamAndroid::create(resolvePath(path), modeStr);
     }
     }
 #else
 #else
-    std::string fullPath(__resourcePath);
-    fullPath += resolvePath(path);
+    std::string fullPath;
+    getFullPath(path, fullPath);
     
     
 #ifdef WIN32
 #ifdef WIN32
     gp_stat_struct s;
     gp_stat_struct s;
-    if (stat(fullPath.c_str(), &s) != 0 && (mode & WRITE) == 0)
+    if (!isAbsolutePath(path) && stat(fullPath.c_str(), &s) != 0 && (mode & WRITE) == 0)
     {
     {
         fullPath = __resourcePath;
         fullPath = __resourcePath;
         fullPath += "../../gameplay/";
         fullPath += "../../gameplay/";
@@ -386,15 +431,15 @@ FILE* FileSystem::openFile(const char* filePath, const char* mode)
     GP_ASSERT(filePath);
     GP_ASSERT(filePath);
     GP_ASSERT(mode);
     GP_ASSERT(mode);
 
 
-    std::string fullPath(__resourcePath);
-    fullPath += resolvePath(filePath);
+    std::string fullPath;
+    getFullPath(filePath, fullPath);
 
 
     createFileFromAsset(filePath);
     createFileFromAsset(filePath);
     
     
     FILE* fp = fopen(fullPath.c_str(), mode);
     FILE* fp = fopen(fullPath.c_str(), mode);
     
     
 #ifdef WIN32
 #ifdef WIN32
-    if (fp == NULL)
+    if (fp == NULL && !isAbsolutePath(filePath))
     {
     {
         fullPath = __resourcePath;
         fullPath = __resourcePath;
         fullPath += "../../gameplay/";
         fullPath += "../../gameplay/";
@@ -452,11 +497,10 @@ bool FileSystem::isAbsolutePath(const char* filePath)
     if (filePath == 0 || filePath[0] == '\0')
     if (filePath == 0 || filePath[0] == '\0')
         return false;
         return false;
 #ifdef WIN32
 #ifdef WIN32
-    if (strlen(filePath) >= 2)
+    if (filePath[1] != '\0')
     {
     {
         char first = filePath[0];
         char first = filePath[0];
-        if (filePath[1] == ':' && ((first >= 'a' && first <= 'z') || (first >= 'A' && first <= 'Z')))
-            return true;
+        return (filePath[1] == ':' && ((first >= 'a' && first <= 'z') || (first >= 'A' && first <= 'Z')));
     }
     }
     return false;
     return false;
 #else
 #else