Added PlatformHelper ( moved all the Android platform helpers there ).

Fixed a couple of minor bugs.

--HG--
branch : dev
This commit is contained in:
Martín Lucas Golini
2017-12-29 22:06:36 -03:00
parent aada050aa3
commit e28f606f38
15 changed files with 258 additions and 200 deletions

View File

@@ -12,6 +12,7 @@
#include <eepp/window/cursormanager.hpp>
#include <eepp/window/joystick.hpp>
#include <eepp/window/joystickmanager.hpp>
#include <eepp/window/platformhelper.hpp>
#include <eepp/window/engine.hpp>
#endif

View File

@@ -3,6 +3,7 @@
#include <eepp/window/base.hpp>
#include <eepp/window/window.hpp>
#include <eepp/window/platformhelper.hpp>
#include <list>
namespace EE { namespace System { class IniFile; class Pack; } }
@@ -117,11 +118,8 @@ class EE_API Engine {
/** @return The id of the thread that was used to initialize the OpenGL Context. */
Uint32 getMainThreadId();
#if EE_PLATFORM == EE_PLATFORM_ANDROID
std::string getExternalStoragePath();
std::string getInternalStoragePath();
#endif
/** @return The instance of platform class that provides some helpers for some platforms */
PlatformHelper * getPlatformHelper();
protected:
friend class Window;
@@ -130,6 +128,7 @@ class EE_API Engine {
EE::Window::Window * mWindow;
bool mSharedGLContext;
Uint32 mMainThreadId;
PlatformHelper * mPlatformHelper;
Pack * mZip;
Engine();

View File

@@ -0,0 +1,44 @@
#ifndef EE_WINDOW_PLATFORM_HPP
#define EE_WINDOW_PLATFORM_HPP
#include <eepp/config.hpp>
#include <string>
namespace EE { namespace Window {
class PlatformHelper
{
public:
#if EE_PLATFORM == EE_PLATFORM_ANDROID
/** @return The Activity object for the application */
virtual void * getActivity() = 0;
/** @return The JNI environment for the current thread */
virtual void * getJNIEnv() = 0;
/** @return The path used for external storage for this application.
* This path is unique to your application, but is public and can be
* written to by other applications.
*/
virtual std::string getExternalStoragePath() = 0;
/** @return The path used for internal storage for this application.
* This path is unique to your application and cannot be written to
* by other applications.
*/
virtual std::string getInternalStoragePath() = 0;
/** @return The application APK file path */
virtual std::string getApkPath() = 0;
/** @return True if the external storage is readable. */
virtual bool isExternalStorageReadable() = 0;
/** @return True if the external storage is writeable. */
virtual bool isExternalStorageWritable() = 0;
#endif
};
}}
#endif

View File

@@ -148,13 +148,6 @@ class DisplayMode {
Uint32 ScreenIndex;
};
/* See the official Android developer guide for more information:
http://developer.android.com/guide/topics/data/data-storage.html
*/
#define EE_ANDROID_EXTERNAL_STORAGE_READ 0x01
#define EE_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
class EE_API Window {
public:
typedef cb::Callback1<void, Window*> WindowResizeCallback;
@@ -397,40 +390,6 @@ class EE_API Window {
*/
virtual bool isScreenKeyboardShown();
#if EE_PLATFORM == EE_PLATFORM_ANDROID
/** @return The JNI environment for the current thread
* This returns JNIEnv*, but the prototype is void* so we don't need jni.h
*/
virtual void * getJNIEnv();
/** @return The SDL Activity object for the application
* This returns jobject, but the prototype is void* so we don't need jni.h
*/
virtual void * getActivity();
/** @return The current state of external storage, a bitmask of these values:
* EE_ANDROID_EXTERNAL_STORAGE_READ
* EE_ANDROID_EXTERNAL_STORAGE_WRITE
* If external storage is currently unavailable, this will return 0.
*/
virtual int getExternalStorageState();
/** @return The path used for internal storage for this application.
* This path is unique to your application and cannot be written to
* by other applications.
*/
virtual std::string getInternalStoragePath();
/** @return The path used for external storage for this application.
* This path is unique to your application, but is public and can be
* written to by other applications.
*/
virtual std::string getExternalStoragePath();
/** @return The application APK file path */
virtual std::string getApkPath();
#endif
/** @return True if the current window support a threaded GL Context. This means that supports OpenGL Shared Contexts ( multithreaded opengl contexts ).
** Only supported with SDL2 backend.*/
virtual bool isThreadedGLContext();

View File

@@ -436,7 +436,12 @@
../../include/eepp/window/cursor.hpp
../../include/eepp/window/clipboard.hpp
../../include/eepp/window/base.hpp
../../src/eepp/window/backend/SDL2/platformhelpersdl2.cpp
../../src/eepp/window/backend/SDL2/platformhelpersdl2.hpp
../../src/eepp/window/backend/SFML/platformhelpersfml.cpp
../../src/eepp/window/backend/SFML/platformhelpersfml.hpp
../../src/eepp/window/inputhelper.cpp
../../src/eepp/window/platformhelper.hpp
../../src/eepp/window/window.cpp
../../src/eepp/window/view.cpp
../../src/eepp/window/platformimpl.cpp

View File

@@ -515,7 +515,7 @@ static std::string sGetProcessPath() {
return FileSystem::fileRemoveFileName( std::string( info.name ) );
#elif EE_PLATFORM == EE_PLATFORM_ANDROID
return Window::Engine::instance()->getExternalStoragePath() + "/";
return Window::Engine::instance()->getPlatformHelper()->getExternalStoragePath() + "/";
#else
#warning Sys::GetProcessPath() not implemented on this platform. ( will return "./" )
return "./";
@@ -623,7 +623,7 @@ std::string Sys::getConfigPath( std::string appname ) {
#elif EE_PLATFORM == EE_PLATFORM_IOS
return GetProcessPath() + "config";
#elif EE_PLATFORM == EE_PLATFORM_ANDROID
return Window::Engine::instance()->getInternalStoragePath() + "/";
return Window::Engine::instance()->getPlatformHelper()->getInternalStoragePath() + "/";
#else
#warning Sys::GetConfigPath not implemented for this platform ( it will use HOME directory + /.appname )
@@ -649,11 +649,7 @@ std::string Sys::getTempPath() {
return std::string( "C:\\WINDOWS\\TEMP\\" );
}
#elif EE_PLATFORM == EE_PLATFORM_ANDROID
if ( NULL != Window::Engine::instance() ) {
String::strCopy( path, Window::Engine::instance()->getCurrentWindow()->getInternalStoragePath().c_str(), EE_MAX_CFG_PATH_LEN );
} else {
String::strCopy( path, "/tmp", EE_MAX_CFG_PATH_LEN );
}
String::strCopy( path, std::string( Window::Engine::instance()->getPlatformHelper()->getInternalStoragePath() + "/tmp/" ).c_str(), EE_MAX_CFG_PATH_LEN );
#else
char * tmpdir = getenv("TMPDIR");

View File

@@ -432,10 +432,10 @@ static BlendMode toBlendMode( std::string val ) {
BlendMode blendMode;
if ( val == "add" ) blendMode == BlendAdd;
else if ( val == "alpha" ) blendMode == BlendAlpha;
else if ( val == "multiply" ) blendMode == BlendMultiply;
else if ( val == "none" ) blendMode == BlendNone;
if ( val == "add" ) blendMode = BlendAdd;
else if ( val == "alpha" ) blendMode = BlendAlpha;
else if ( val == "multiply" ) blendMode = BlendMultiply;
else if ( val == "none" ) blendMode = BlendNone;
return blendMode;
}

View File

@@ -0,0 +1,73 @@
#include <eepp/window/backend/SDL2/platformhelpersdl2.hpp>
#include <eepp/window/backend/SDL2/base.hpp>
#if EE_PLATFORM == EE_PLATFORM_ANDROID
#include <jni.h>
#endif
namespace EE { namespace Window { namespace Backend { namespace SDL2 {
PlatformHelperSDL2::PlatformHelperSDL2()
{
}
#if EE_PLATFORM == EE_PLATFORM_ANDROID
void * PlatformHelperSDL2::getActivity() {
return SDL_AndroidGetActivity();
}
void * PlatformHelperSDL2::getJNIEnv() {
return SDL_AndroidGetJNIEnv();
}
std::string PlatformHelperSDL2::getExternalStoragePath() {
return std::string( SDL_AndroidGetExternalStoragePath() );
}
std::string PlatformHelperSDL2::getInternalStoragePath() {
return std::string( SDL_AndroidGetInternalStoragePath() );
}
std::string PlatformHelperSDL2::getApkPath() {
static std::string apkPath = "";
if ( "" == apkPath ) {
jmethodID mid;
jobject context;
jobject fileObject;
const char *path;
JNIEnv *env = (JNIEnv*)getJNIEnv();
jclass ActivityClass = env->GetObjectClass((jobject)getActivity());
// context = SDLActivity.getContext();
mid = env->GetStaticMethodID(ActivityClass,"getContext","()Landroid/content/Context;");
context = env->CallStaticObjectMethod(ActivityClass, mid);
// fileObj = context.getFilesDir();
mid = env->GetMethodID(env->GetObjectClass(context),"getPackageCodePath", "()Ljava/lang/String;");
fileObject = env->CallObjectMethod(context, mid);
jboolean isCopy;
path = env->GetStringUTFChars((jstring)fileObject, &isCopy);
apkPath = std::string( path );
}
return apkPath;
}
bool PlatformHelperSDL2::isExternalStorageReadable() {
return 0 != ( SDL_AndroidGetExternalStorageState() & SDL_ANDROID_EXTERNAL_STORAGE_READ );
}
bool PlatformHelperSDL2::isExternalStorageWritable() {
return 0 != ( SDL_AndroidGetExternalStorageState() & SDL_ANDROID_EXTERNAL_STORAGE_WRITE );
}
#endif
}}}}

View File

@@ -0,0 +1,33 @@
#ifndef EE_PLATFORMHELPERSDL2_HPP
#define EE_PLATFORMHELPERSDL2_HPP
#include <eepp/window/platformhelper.hpp>
#include <string>
namespace EE { namespace Window { namespace Backend { namespace SDL2 {
class PlatformHelperSDL2 : public PlatformHelper
{
public:
PlatformHelperSDL2();
#if EE_PLATFORM == EE_PLATFORM_ANDROID
void * getActivity();
void * getJNIEnv();
std::string getExternalStoragePath();
std::string getInternalStoragePath();
std::string getApkPath();
bool isExternalStorageReadable();
bool isExternalStorageWritable();
#endif
};
}}}}
#endif

View File

@@ -23,52 +23,6 @@
namespace EE { namespace Window { namespace Backend { namespace SDL2 {
#if EE_PLATFORM == EE_PLATFORM_ANDROID
#include <eepp/system/zip.hpp>
#include <jni.h>
std::string WindowSDL::SDL_AndroidGetApkPath() {
static std::string apkPath = "";
if ( "" == apkPath ) {
jmethodID mid;
jobject context;
jobject fileObject;
const char *path;
JNIEnv *env = (JNIEnv*)SDL_AndroidGetJNIEnv();
jclass ActivityClass = env->GetObjectClass((jobject)SDL_AndroidGetActivity());
// context = SDLActivity.getContext();
mid = env->GetStaticMethodID(ActivityClass,"getContext","()Landroid/content/Context;");
context = env->CallStaticObjectMethod(ActivityClass, mid);
// fileObj = context.getFilesDir();
mid = env->GetMethodID(env->GetObjectClass(context),"getPackageCodePath", "()Ljava/lang/String;");
fileObject = env->CallObjectMethod(context, mid);
jboolean isCopy;
path = env->GetStringUTFChars((jstring)fileObject, &isCopy);
apkPath = std::string( path );
}
return apkPath;
}
std::string WindowSDL::SDL_AndroidGetExternalStoragePath() {
return std::string( SDL_AndroidGetExternalStoragePath() );
}
std::string WindowSDL::SDL_AndroidGetInternalStoragePath() {
return std::string( SDL_AndroidGetInternalStoragePath() );
}
#endif
WindowSDL::WindowSDL( WindowSettings Settings, ContextSettings Context ) :
Window( Settings, Context, eeNew( ClipboardSDL, ( this ) ), eeNew( InputSDL, ( this ) ), eeNew( CursorManagerSDL, ( this ) ) ),
mSDLWindow( NULL ),
@@ -687,32 +641,6 @@ bool WindowSDL::isScreenKeyboardShown() {
#endif
}
#if EE_PLATFORM == EE_PLATFORM_ANDROID
void * WindowSDL::getJNIEnv() {
return SDL_AndroidGetJNIEnv();
}
void * WindowSDL::getActivity() {
return SDL_AndroidGetActivity();
}
int WindowSDL::getExternalStorageState() {
return SDL_AndroidGetExternalStorageState();
}
std::string WindowSDL::getInternalStoragePath() {
return std::string( SDL_AndroidGetInternalStoragePath() );
}
std::string WindowSDL::getExternalStoragePath() {
return std::string( SDL_AndroidGetExternalStoragePath() );
}
std::string WindowSDL::getApkPath() {
return SDL_AndroidGetApkPath();
}
#endif
}}}}
#endif

View File

@@ -13,20 +13,10 @@
#define EE_USE_WMINFO
#endif
namespace EE { namespace System { class Zip; } }
namespace EE { namespace Window { namespace Backend { namespace SDL2 {
class EE_API WindowSDL : public Window {
public:
#if EE_PLATFORM == EE_PLATFORM_ANDROID
static std::string SDL_AndroidGetApkPath();
static std::string SDL_AndroidGetExternalStoragePath();
static std::string SDL_AndroidGetInternalStoragePath();
#endif
WindowSDL( WindowSettings Settings, ContextSettings Context );
virtual ~WindowSDL();
@@ -81,20 +71,6 @@ class EE_API WindowSDL : public Window {
bool isScreenKeyboardShown();
#if EE_PLATFORM == EE_PLATFORM_ANDROID
void * getJNIEnv();
void * getActivity();
int getExternalStorageState();
std::string getInternalStoragePath();
std::string getExternalStoragePath();
std::string getApkPath();
#endif
bool isThreadedGLContext();
void setGLContextThread();

View File

@@ -0,0 +1,39 @@
#include <eepp/window/backend/SFML/platformhelpersfml.hpp>
namespace EE { namespace Window { namespace Backend { namespace SFML {
PlatformHelperSFML::PlatformHelperSFML()
{
}
#if EE_PLATFORM == EE_PLATFORM_ANDROID
void * PlatformHelperSFML::getActivity() {
return NULL;
}
void * PlatformHelperSFML::getJNIEnv() {
return NULL;
}
std::string PlatformHelperSFML::getExternalStoragePath() {
return std::string();
}
std::string PlatformHelperSFML::getInternalStoragePath() {
return std::string();
}
std::string PlatformHelperSFML::getApkPath() {
return std::string();
}
bool PlatformHelperSFML::isExternalStorageReadable() {
return true;
}
bool PlatformHelperSFML::isExternalStorageWritable() {
return true;
}
#endif
}}}}

View File

@@ -0,0 +1,33 @@
#ifndef EE_PLATFORMHELPERSFML_HPP
#define EE_PLATFORMHELPERSFML_HPP
#include <eepp/window/platformhelper.hpp>
#include <string>
namespace EE { namespace Window { namespace Backend { namespace SFML {
class PlatformHelperSFML : public PlatformHelper
{
public:
PlatformHelperSFML();
#if EE_PLATFORM == EE_PLATFORM_ANDROID
void * getActivity();
void * getJNIEnv();
std::string getExternalStoragePath();
std::string getInternalStoragePath();
std::string getApkPath();
bool isExternalStorageReadable();
bool isExternalStorageWritable();
#endif
};
}}}}
#endif

View File

@@ -16,6 +16,8 @@
#include <eepp/window/backend.hpp>
#include <eepp/window/backend/SDL2/backendsdl2.hpp>
#include <eepp/window/backend/SFML/backendsfml.hpp>
#include <eepp/window/backend/SDL2/platformhelpersdl2.hpp>
#include <eepp/window/backend/SFML/platformhelpersfml.hpp>
#include <eepp/graphics/renderer/renderer.hpp>
#if EE_PLATFORM == EE_PLATFORM_ANDROID
@@ -43,11 +45,14 @@ Engine::Engine() :
mBackend( NULL ),
mWindow( NULL ),
mSharedGLContext( false ),
mMainThreadId( 0 )
#if EE_PLATFORM == EE_PLATFORM_ANDROID
, mZip( NULL )
#endif
mMainThreadId( 0 ),
mPlatformHelper( NULL )
{
#if EE_PLATFORM == EE_PLATFORM_ANDROID
mZip = eeNew( Zip, () );
mZip->open( getPlatformHelper()->getApkPath() );
#endif
TextureAtlasManager::createSingleton();
}
@@ -88,6 +93,8 @@ Engine::~Engine() {
eeSAFE_DELETE( mZip );
#endif
eeSAFE_DELETE( mPlatformHelper );
eeSAFE_DELETE( mBackend );
}
@@ -334,25 +341,16 @@ Uint32 Engine::getMainThreadId() {
return mMainThreadId;
}
#if EE_PLATFORM == EE_PLATFORM_ANDROID
std::string Engine::getExternalStoragePath() {
#if defined( EE_BACKEND_SDL2 )
if ( NULL == mZip ) {
mZip = eeNew( Zip, () );
mZip->open( Backend::SDL2::WindowSDL::SDL_AndroidGetApkPath() );
PlatformHelper * Engine::getPlatformHelper() {
if ( NULL == mPlatformHelper ) {
#if DEFAULT_BACKEND == BACKEND_SDL2
mPlatformHelper = eeNew( Backend::SDL2::PlatformHelperSDL2, () );
#elif DEFAULT_BACKEND == BACKEND_SFML
mPlatform = eeNew( Backend::SFML::PlatformHelperSFML, () );
#endif
}
return SDL_AndroidGetExternalStoragePath();
#endif
return "";
return mPlatformHelper;
}
std::string Engine::getInternalStoragePath() {
#if defined( EE_BACKEND_SDL2 )
return SDL_AndroidGetExternalStoragePath();
#endif
return "";
}
#endif
}}

View File

@@ -520,30 +520,4 @@ void Window::runMainLoop( void (*func)(), int fps ) {
#endif
}
#if EE_PLATFORM == EE_PLATFORM_ANDROID
void * Window::getJNIEnv() {
return NULL;
}
void * Window::getActivity() {
return NULL;
}
int Window::getExternalStorageState() {
return 0;
}
std::string Window::getInternalStoragePath() {
return std::string("");
}
std::string Window::getExternalStoragePath() {
return std::string("");
}
std::string Window::getApkPath() {
return std::string("");
}
#endif
}}