Ver código fonte

Adding the modified files to support gameplay on android platform.
(Git for some reason wont let me add "added" and "modified" together)

Ramprasad Madhavan 14 anos atrás
pai
commit
714743af08

+ 37 - 2
gameplay/src/Base.h

@@ -39,6 +39,10 @@ using std::min;
 using std::max;
 using std::max;
 using std::modf;
 using std::modf;
 
 
+#ifdef __ANDROID__
+#include <android/asset_manager.h>
+#endif
+
 // Common
 // Common
 #ifndef NULL
 #ifndef NULL
 #define NULL     0
 #define NULL     0
@@ -50,6 +54,31 @@ namespace gameplay
 extern void printError(const char* format, ...);
 extern void printError(const char* format, ...);
 }
 }
 
 
+#ifdef __ANDROID__
+#include <android/log.h>
+#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__))
+
+// System Errors
+#define LOG_ERROR(x) \
+    { \
+        LOGI(x); \
+        assert(#x == 0); \
+    }
+#define LOG_ERROR_VARG(x, ...) \
+    { \
+        LOGI(x, __VA_ARGS__); \
+        assert(#x == 0); \
+    }
+
+// Warning macro
+#ifdef WARN
+#undef WARN
+#endif
+#define WARN(x) LOGI(x)
+#define WARN_VARG(x, ...) LOGI(x, __VA_ARGS__)
+
+#else
+
 // System Errors
 // System Errors
 #define LOG_ERROR(x) \
 #define LOG_ERROR(x) \
     { \
     { \
@@ -69,6 +98,8 @@ extern void printError(const char* format, ...);
 #define WARN(x) printError(x)
 #define WARN(x) printError(x)
 #define WARN_VARG(x, ...) printError(x, __VA_ARGS__)
 #define WARN_VARG(x, ...) printError(x, __VA_ARGS__)
 
 
+#endif
+
 // Bullet Physics
 // Bullet Physics
 #include <btBulletDynamicsCommon.h>
 #include <btBulletDynamicsCommon.h>
 
 
@@ -124,7 +155,7 @@ extern void printError(const char* format, ...);
 #endif
 #endif
 
 
 // Audio (OpenAL)
 // Audio (OpenAL)
-#ifdef __QNX__
+#if defined (__QNX__) || defined(__ANDROID__)
 #include <AL/al.h>
 #include <AL/al.h>
 #include <AL/alc.h>
 #include <AL/alc.h>
 #elif WIN32
 #elif WIN32
@@ -146,7 +177,7 @@ extern void printError(const char* format, ...);
 #include <png.h>
 #include <png.h>
 
 
 // Graphics (OpenGL)
 // Graphics (OpenGL)
-#ifdef __QNX__
+#if defined (__QNX__) || defined(__ANDROID__)
     #include <EGL/egl.h>
     #include <EGL/egl.h>
     #include <GLES2/gl2.h>
     #include <GLES2/gl2.h>
     #include <GLES2/gl2ext.h>
     #include <GLES2/gl2ext.h>
@@ -250,5 +281,9 @@ extern GLenum __gl_error_code;
     #pragma warning( disable : 4996 )
     #pragma warning( disable : 4996 )
 #endif
 #endif
 
 
+#ifdef __ANDROID__
+#include <android_native_app_glue.h>
+extern void amain(struct android_app* state);
+#endif
 
 
 #endif
 #endif

+ 68 - 3
gameplay/src/FileSystem.cpp

@@ -1,9 +1,55 @@
 #include "Base.h"
 #include "Base.h"
 #include "FileSystem.h"
 #include "FileSystem.h"
 
 
+#ifdef __ANDROID__
+extern AAssetManager* __assetManager;
+#endif
+
 namespace gameplay
 namespace gameplay
 {
 {
 
 
+#ifdef __ANDROID__
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+void makepath(std::string path, int mode)
+{
+    std::vector<std::string> dirs;
+    while (path.length() > 0)
+    {
+        int index = path.find('/');
+        std::string dir = (index == -1 ) ? path : path.substr(0, index);
+        if (dir.length() > 0)
+            dirs.push_back(dir);
+        
+        if (index + 1 >= path.length() || index == -1)
+            break;
+            
+        path = path.substr(index + 1);
+    }
+    
+    struct stat s;
+    std::string dirPath;
+    for (unsigned int i = 0; i < dirs.size(); i++)
+    {
+        dirPath += "/";
+        dirPath += dirs[i];
+        if (stat(dirPath.c_str(), &s) != 0)
+        {
+            // Directory does not exist.
+            if (mkdir(dirPath.c_str(), 0777) != 0)
+            {
+                WARN_VARG("Failed to create directory: '%s'", dirPath.c_str());
+                return;
+            }
+        }
+    }
+    
+    return;
+}
+#endif
+
 static std::string __resourcePath("./");
 static std::string __resourcePath("./");
 
 
 FileSystem::FileSystem()
 FileSystem::FileSystem()
@@ -28,10 +74,29 @@ FILE* FileSystem::openFile(const char* path, const char* mode)
 {
 {
     std::string fullPath(__resourcePath);
     std::string fullPath(__resourcePath);
     fullPath += path;
     fullPath += path;
-
+    
+#ifdef __ANDROID__
+    std::string directoryPath = fullPath.substr(0, fullPath.rfind('/'));
+    struct stat s;
+    if (stat(directoryPath.c_str(), &s) != 0)
+        makepath(directoryPath.c_str(), 0777);
+
+    if (stat(fullPath.c_str(), &s) != 0)
+    {
+        AAsset* asset = AAssetManager_open(__assetManager, path, AASSET_MODE_RANDOM);
+        const void* data = AAsset_getBuffer(asset);
+        int length = AAsset_getLength(asset);
+        FILE* file = fopen(fullPath.c_str(), "wb");
+        
+        int ret = fwrite(data, sizeof(unsigned char), length, file);
+        assert(ret == length);
+        fclose(file);
+    }
+#endif
+    
     FILE* fp = fopen(fullPath.c_str(), mode);
     FILE* fp = fopen(fullPath.c_str(), mode);
-
-// Win32 doesnt support a asset or bundle definitions.
+    
+// Win32 doesn't support an asset or bundle definitions.
 #ifdef WIN32
 #ifdef WIN32
     if (fp == NULL)
     if (fp == NULL)
     {
     {

+ 1 - 1
gameplay/src/Font.cpp

@@ -53,7 +53,7 @@ Font::Font(const Font& copy)
 Font::~Font()
 Font::~Font()
 {
 {
     // Remove this Font from the font cache.
     // Remove this Font from the font cache.
-    std::vector<Font*>::iterator itr = find(__fontCache.begin(), __fontCache.end(), this);
+    std::vector<Font*>::iterator itr = std::find(__fontCache.begin(), __fontCache.end(), this);
     if (itr != __fontCache.end())
     if (itr != __fontCache.end())
     {
     {
         __fontCache.erase(itr);
         __fontCache.erase(itr);

+ 12 - 1
gameplay/src/Game.cpp

@@ -90,8 +90,10 @@ bool Game::startup()
     _animationController = new AnimationController();
     _animationController = new AnimationController();
     _animationController->initialize();
     _animationController->initialize();
 
 
+    #if 0
     _audioController = new AudioController();
     _audioController = new AudioController();
     _audioController->initialize();
     _audioController->initialize();
+    #endif
 
 
     _physicsController = new PhysicsController();
     _physicsController = new PhysicsController();
     _physicsController->initialize();
     _physicsController->initialize();
@@ -111,8 +113,10 @@ void Game::shutdown()
         _animationController->finalize();
         _animationController->finalize();
         SAFE_DELETE(_animationController);
         SAFE_DELETE(_animationController);
 
 
+        #if 0
         _audioController->finalize();
         _audioController->finalize();
         SAFE_DELETE(_audioController);
         SAFE_DELETE(_audioController);
+        #endif
 
 
         _physicsController->finalize();
         _physicsController->finalize();
         SAFE_DELETE(_physicsController);
         SAFE_DELETE(_physicsController);
@@ -130,7 +134,9 @@ void Game::pause()
         _state = PAUSED;
         _state = PAUSED;
         _pausedTimeLast = Platform::getAbsoluteTime();
         _pausedTimeLast = Platform::getAbsoluteTime();
         _animationController->pause();
         _animationController->pause();
+        #if 0
         _audioController->pause();
         _audioController->pause();
+        #endif
         _physicsController->pause();
         _physicsController->pause();
     }
     }
 }
 }
@@ -142,7 +148,9 @@ void Game::resume()
         _state = RUNNING;
         _state = RUNNING;
         _pausedTimeTotal += Platform::getAbsoluteTime() - _pausedTimeLast;
         _pausedTimeTotal += Platform::getAbsoluteTime() - _pausedTimeLast;
         _animationController->resume();
         _animationController->resume();
+        #if 0
         _audioController->resume();
         _audioController->resume();
+        #endif
         _physicsController->resume();
         _physicsController->resume();
     }
     }
 }
 }
@@ -175,13 +183,16 @@ void Game::frame()
 
 
     // Update the scheduled and running animations.
     // Update the scheduled and running animations.
     _animationController->update(elapsedTime);
     _animationController->update(elapsedTime);
+    
     // Update the physics.
     // Update the physics.
     _physicsController->update(elapsedTime);
     _physicsController->update(elapsedTime);
     // Application Update.
     // Application Update.
     update(elapsedTime);
     update(elapsedTime);
 
 
     // Audio Rendering.
     // Audio Rendering.
+    #if 0
     _audioController->update(elapsedTime);
     _audioController->update(elapsedTime);
+    #endif
     // Graphics Rendering.
     // Graphics Rendering.
     render(elapsedTime);
     render(elapsedTime);
 
 
@@ -250,4 +261,4 @@ void Game::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactI
 {
 {
 }
 }
 
 
-}
+}

+ 2 - 3
gameplay/src/PlatformQNX.cpp

@@ -671,7 +671,6 @@ int Platform::enterMessagePump()
     int eventType;
     int eventType;
     int flags;
     int flags;
     int value;
     int value;
-    int visible = 1;
     int position[2];
     int position[2];
     int domain;
     int domain;
     mtouch_event_t touchEvent;
     mtouch_event_t touchEvent;
@@ -780,8 +779,8 @@ int Platform::enterMessagePump()
             break;
             break;
 
 
         // Idle time (no events left to process) is spent rendering.
         // Idle time (no events left to process) is spent rendering.
-        // We skip rendering when the window is not visible or the app is paused.
-        if (visible && _game->getState() != Game::PAUSED)
+        // We skip rendering when the app is paused.
+        if (_game->getState() != Game::PAUSED)
         {
         {
             _game->frame();
             _game->frame();
 
 

+ 1 - 1
gameplay/src/Texture.cpp

@@ -26,7 +26,7 @@ Texture::~Texture()
     // Remove ourself from the texture cache.
     // Remove ourself from the texture cache.
     if (_cached)
     if (_cached)
     {
     {
-        std::vector<Texture*>::iterator itr = find(__textureCache.begin(), __textureCache.end(), this);
+        std::vector<Texture*>::iterator itr = std::find(__textureCache.begin(), __textureCache.end(), this);
         if (itr != __textureCache.end())
         if (itr != __textureCache.end())
         {
         {
             __textureCache.erase(itr);
             __textureCache.erase(itr);

+ 1 - 1
gameplay/src/VertexAttributeBinding.cpp

@@ -17,7 +17,7 @@ VertexAttributeBinding::VertexAttributeBinding() :
 VertexAttributeBinding::~VertexAttributeBinding()
 VertexAttributeBinding::~VertexAttributeBinding()
 {
 {
     // Delete from the vertex attribute binding cache.
     // Delete from the vertex attribute binding cache.
-    std::vector<VertexAttributeBinding*>::iterator itr = find(__vertexAttributeBindingCache.begin(), __vertexAttributeBindingCache.end(), this);
+    std::vector<VertexAttributeBinding*>::iterator itr = std::find(__vertexAttributeBindingCache.begin(), __vertexAttributeBindingCache.end(), this);
     if (itr != __vertexAttributeBindingCache.end())
     if (itr != __vertexAttributeBindingCache.end())
     {
     {
         __vertexAttributeBindingCache.erase(itr);
         __vertexAttributeBindingCache.erase(itr);