ソースを参照

Fix crash with BasicFileProvider, add physfs support, fix emulator crash.

Joachim Meyer 9 年 前
コミット
7b25ab3313

+ 11 - 6
build/android/TemplateApp/jni/Android.mk

@@ -12,16 +12,21 @@ LOCAL_MODULE := freetype
 LOCAL_SRC_FILES := $(LIBDIR)/libfreetype.a
 include $(PREBUILT_STATIC_LIBRARY)
 
-include $(CLEAR_VARS)
-LOCAL_MODULE := ogg
-LOCAL_SRC_FILES := $(LIBDIR)/libogg.so
-include $(PREBUILT_SHARED_LIBRARY)
-
 include $(CLEAR_VARS)
 LOCAL_MODULE := lua
 LOCAL_SRC_FILES := $(LIBDIR)/liblua.a
 include $(PREBUILT_STATIC_LIBRARY)
 
+include $(CLEAR_VARS)
+LOCAL_MODULE := physfs
+LOCAL_SRC_FILES := $(LIBDIR)/libphysfs.a
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := ogg
+LOCAL_SRC_FILES := $(LIBDIR)/libogg.so
+include $(PREBUILT_SHARED_LIBRARY)
+
 include $(CLEAR_VARS)
 LOCAL_MODULE := vorbis
 LOCAL_SRC_FILES := $(LIBDIR)/libvorbis.so
@@ -30,7 +35,7 @@ include $(PREBUILT_SHARED_LIBRARY)
 include $(CLEAR_VARS)
 LOCAL_MODULE := TemplateApp
 LOCAL_LDLIBS := -landroid -lEGL -lGLESv2 -lOpenSLES -lz -llog
-LOCAL_STATIC_LIBRARIES := Polycore freetype lua
+LOCAL_STATIC_LIBRARIES := Polycore freetype lua physfs
 LOCAL_SHARED_LIBRARIES := ogg vorbis
 LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../include -DUSE_EGL -DSTRICT_OPENGLES2
 LOCAL_SRC_FILES := PolycodeTemplate.cpp PolycodeTemplateApp.cpp

+ 21 - 21
include/polycode/core/PolyAAssetFileProvider.h

@@ -27,16 +27,16 @@
 
 namespace Polycode {
     
-    class _PolyExport AAssetFile : public CoreFile {
-    public:
-        
-        long read( void * ptr, size_t size, size_t count);
-        long write( const void * ptr, size_t size, size_t count);
-        int seek(long int offset, int origin);
-        long tell();
-        
-        AAsset *file;
-    };
+	class _PolyExport AAssetFile : public CoreFile {
+	public:
+		
+		long read( void * ptr, size_t size, size_t count);
+		long write( const void * ptr, size_t size, size_t count);
+		int seek(long int offset, int origin);
+		long tell();
+		
+		AAsset *file;
+	};
     
 	class _PolyExport AAssetDirClass : public PolyBase {
 	public:
@@ -44,21 +44,21 @@ namespace Polycode {
 		String name;
 	};
 	
-    class _PolyExport AAssetFileProvider : public CoreFileProvider {
-        public:
-            AAssetFileProvider(AAssetManager *manager);
-            
+	class _PolyExport AAssetFileProvider : public CoreFileProvider {
+		public:
+			AAssetFileProvider(AAssetManager *manager);
+			
 			Polycode::CoreFile *openFile(const String &fileName, const String &opts);
-            void closeFile(Polycode::CoreFile *file);
-            
+			void closeFile(Polycode::CoreFile *file);
+			
 			bool parseFolder(const Polycode::String& pathString, bool showHidden, std::vector<OSFileEntry> &targetVector);
 			
 			void addSource(const String &source);
-            void removeSource(const String &source);
-      
-            std::vector<AAssetDirClass> sourceFolders;
+			void removeSource(const String &source);
+		
+			std::vector<AAssetDirClass> sourceFolders;
 			
 			AAssetManager* manager;
-    };
-    
+	};
+
 }

+ 36 - 39
src/core/PolyAAssetFileProvider.cpp

@@ -25,8 +25,8 @@
 
 using namespace Polycode;
 
-AAssetFileProvider::AAssetFileProvider(AAssetManager* manager) {
-    type = "android";
+AAssetFileProvider::AAssetFileProvider(AAssetManager* manager) : CoreFileProvider() {
+	type = "aasset";
 	this->manager = manager;
 	canListFiles = true;
 }
@@ -36,45 +36,43 @@ void AAssetFileProvider::addSource(const String &source) {
 	dir.name = source;
 	dir.system = AAssetManager_openDir(manager, source.c_str());
 	sourceFolders.push_back(dir);
-// 	Logger::log("addSource");
 }
 
 void AAssetFileProvider::removeSource(const String &source) {
-    for(int i=0; i < sourceFolders.size(); i++) {
-        if(sourceFolders[i].name == source) {
+	for(int i=0; i < sourceFolders.size(); i++) {
+		if(sourceFolders[i].name == source) {
 			AAssetDir_close(sourceFolders[i].system);
-            sourceFolders.erase(sourceFolders.begin()+i);
-            return;
-        }
-    }
+			sourceFolders.erase(sourceFolders.begin()+i);
+			return;
+		}
+	}
 }
 
 Polycode::CoreFile *AAssetFileProvider::openFile(const String &fileName, const String &opts) {
-    Logger::log("openFile %s", fileName.c_str());
-    AAsset *file = NULL;
-    for(int i=0; i < sourceFolders.size(); i++) {
-        file = AAssetManager_open(manager, (sourceFolders[i].name+"/"+fileName).c_str(), AASSET_MODE_BUFFER);
-        if(file) {
-            break;
-        }
-    }
-    
-    if(!file) {
-        file = AAssetManager_open(manager, fileName.c_str(), AASSET_MODE_BUFFER);
-    }
-    
-    if(file) {
-        AAssetFile *retFile = NULL;
-        retFile = new AAssetFile();
-        retFile->file = file;
-        return retFile;
-    }
-    
-    return NULL;
+	Logger::log("openFile %s", fileName.c_str());
+	AAsset *file = NULL;
+	for(int i=0; i < sourceFolders.size(); i++) {
+		file = AAssetManager_open(manager, (sourceFolders[i].name+"/"+fileName).c_str(), AASSET_MODE_BUFFER);
+		if(file) {
+			break;
+		}
+	}
+	
+	if(!file) {
+		file = AAssetManager_open(manager, fileName.c_str(), AASSET_MODE_BUFFER);
+	}
+	
+	if(file) {
+		AAssetFile *retFile = NULL;
+		retFile = new AAssetFile();
+		retFile->file = file;
+		return retFile;
+	}
+	
+	return NULL;
 }
 
 bool AAssetFileProvider::parseFolder(const String& pathString, bool showHidden, std::vector< OSFileEntry >& targetVector){
-// 	Logger::log("Parse AAsset [%s]", pathString.c_str());
 	String path = pathString;
 	if(pathString.substr(pathString.length(),1)!="/")
 		path = pathString + "/";
@@ -87,7 +85,6 @@ bool AAssetFileProvider::parseFolder(const String& pathString, bool showHidden,
 		String name = AAssetDir_getNextFileName(dir);
 		if(name == "")
 			break;
-// 		Logger::log("Parse AAsset Found File: %s", (path+name).c_str());
 		OSFileEntry entry = OSFileEntry(path + name, OSFileEntry::TYPE_FILE);
 		targetVector.push_back(entry);
 	}
@@ -96,23 +93,23 @@ bool AAssetFileProvider::parseFolder(const String& pathString, bool showHidden,
 
 
 void AAssetFileProvider::closeFile(Polycode::CoreFile *file) {
-    AAssetFile *aassetFile = (AAssetFile*) file;
-    AAsset_close(aassetFile->file);
-    delete aassetFile;
+	AAssetFile *aassetFile = (AAssetFile*) file;
+	AAsset_close(aassetFile->file);
+	delete aassetFile;
 }
 
 long AAssetFile::read( void * ptr, size_t size, size_t count) {
-    return AAsset_read(file, ptr, count*size) / size;
+	return AAsset_read(file, ptr, count*size) / size;
 }
 
 long AAssetFile::write( const void * ptr, size_t size, size_t count) {
-    return 0;
+	return 0;
 }
 
 int AAssetFile::seek(long int offset, int origin) {
-    return AAsset_seek(file, offset, origin);
+	return AAsset_seek(file, offset, origin);
 }
 
 long AAssetFile::tell() {
-    return AAsset_getLength(file);
+	return AAsset_getLength(file);
 }

+ 11 - 3
src/core/PolyAndroidCore.cpp

@@ -23,6 +23,8 @@
 #include "polycode/core/PolyAndroidCore.h"
 #include "polycode/core/PolyOpenGLGraphicsInterface.h"
 #include "polycode/core/PolyAAssetFileProvider.h"
+#include "polycode/core/PolyBasicFileProvider.h"
+#include "polycode/core/PolyPhysFSFileProvider.h"
 #include "polycode/core/PolyLogger.h"
 #include "polycode/core/PolyResourceManager.h"
 #include "polycode/core/PolyOpenSLAudioInterface.h"
@@ -50,6 +52,8 @@ AndroidCore::AndroidCore(PolycodeView *view, int xRes, int yRes, bool fullScreen
 	: Core(xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {
 	
 	fileProviders.push_back(new AAssetFileProvider(view->native_activity->assetManager));
+	fileProviders.push_back(new BasicFileProvider());
+	fileProviders.push_back(new PhysFSFileProvider());
 	
 	eventMutex = createMutex();
 	eglMutex = createMutex();
@@ -77,7 +81,9 @@ AndroidCore::AndroidCore(PolycodeView *view, int xRes, int yRes, bool fullScreen
 	//DP are the Density Independent Pixels - this is afaik what should be the size this should work with enabled retinaSupport
 	setVideoMode(AConfiguration_getScreenWidthDp(view->native_config), AConfiguration_getScreenHeightDp(view->native_config), fullScreen, vSync, aaLevel, anisotropyLevel, retinaSupport);
 	
-
+	defaultWorkingDirectory = view->native_activity->internalDataPath;
+	userHomeDirectory = view->native_activity->internalDataPath;
+	
 // 	services->getSoundManager()->setAudioInterface(new OpenSLAudioInterface());
 	paused = true;
 	
@@ -305,8 +311,10 @@ void AndroidCore::handleVideoModeChange(VideoModeChangeInfo *modeInfo) {
 			assert(context!=EGL_NO_CONTEXT);
 		}
 		
-		if(surface)
-			eglDestroySurface(display, surface);
+		// this works on my Fairphone but not in the Emulator.. and it did work in the Emulator for quite some while.. but now it says: "E/Surface﹕ getSlotFromBufferLocked: unknown buffer:"
+		// everything is running without this as well...
+// 		if(surface)
+// 			eglDestroySurface(display, surface);
 		
 		surface = eglCreateWindowSurface( display, config, view->native_window, NULL );
 		assert(surface != EGL_NO_SURFACE);

+ 1 - 1
src/core/PolyBasicFileProvider.cpp

@@ -3,7 +3,7 @@
 
 using namespace Polycode;
 
-BasicFileProvider::BasicFileProvider() {
+BasicFileProvider::BasicFileProvider() : CoreFileProvider() {
 	type = "folder";
 }