Port to android working :) ( not finished, but working )

This commit is contained in:
spartanj@gmail.com
2012-01-21 00:08:17 -03:00
parent 1d219c8972
commit 04aebba250
15 changed files with 105 additions and 33 deletions

View File

@@ -5,7 +5,10 @@
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/icon" android:debuggable="true">
<activity android:name="SDLActivity"
android:label="@string/app_name">
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

8
android-project/compile.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
cd $(dirname "$0")
export NDK_PROJECT_PATH=$(dirname "$0")
ndk-build -j4
rm -rf ./bin
ant debug
adb install -r bin/EEPPApp-debug.apk
ndk-gdb --force --start

View File

@@ -15,7 +15,7 @@ MY_C_FLAGS := -DANDROID \
$(EE_GLES_VERSION) \
-DEE_NO_SNDFILE
MY_LDLIBS := -llog -landroid -lEGL $(EE_GLES_LINK) -lm
MY_LDLIBS := -llog -landroid -lEGL $(EE_GLES_LINK) -lm -lz
include $(call all-subdir-makefiles)
@@ -62,7 +62,7 @@ LOCAL_SRC_FILES := $(foreach F, $(CODE_SRCS), $(addprefix $(dir $(F)),$(notdir $
LOCAL_STATIC_LIBRARIES := sdl-1.3 chipmunk freetype openal
include $(BUILD_SHARED_LIBRARY)
include $(BUILD_STATIC_LIBRARY)
#*************** EEPP ***************
#*************** CHIPMUNK ***************
@@ -227,7 +227,7 @@ CORE_SRCS := \
LOCAL_SRC_FILES := $(foreach F, $(CORE_SRCS), $(addprefix $(dir $(F)),$(notdir $(wildcard $(LOCAL_PATH)/$(F)))))
LOCAL_SHARED_LIBRARIES := eepp
LOCAL_STATIC_LIBRARIES := eepp
include $(BUILD_SHARED_LIBRARY)
#************ empty_window ************
@@ -253,7 +253,7 @@ LOCAL_C_INCLUDES := $(MY_C_INCLUDES)
LOCAL_SRC_FILES := $(foreach F, $(CORE_SRCS), $(addprefix $(dir $(F)),$(notdir $(wildcard $(LOCAL_PATH)/$(F)))))
LOCAL_SHARED_LIBRARIES := eepp
LOCAL_STATIC_LIBRARIES := eepp
include $(BUILD_SHARED_LIBRARY)
#************ BnB ************

View File

@@ -35,4 +35,4 @@ APP_STL := gnustl_static
APP_CFLAGS := -DDEBUG
APP_PLATFORM := android-10
APP_MODULES := main
APP_MODULES := bnb

View File

@@ -34,8 +34,9 @@ public class SDLActivity extends Activity {
// Load the .so
static {
System.loadLibrary("eepp");
System.loadLibrary("main");
//System.loadLibrary("eepp");
System.loadLibrary("bnb");
//System.loadLibrary("main");
}
// Setup

View File

@@ -198,6 +198,15 @@
#define eeSAFE_DELETE_ARRAY(p) { if(p) { eeDeleteArray(p); (p)=NULL; } }
#define eeINDEX_NOT_FOUND 0xFFFFFFFF
#if EE_PLATFORM == EE_PLATFORM_ANDROID
#include <android/log.h>
#define ANDROID_LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "eepp", __VA_ARGS__)
#define ANDROID_LOGD(...) __android_log_print(ANDROID_LOG_DEBUG , "eepp", __VA_ARGS__)
#define ANDROID_LOGI(...) __android_log_print(ANDROID_LOG_INFO , "eepp", __VA_ARGS__)
#define ANDROID_LOGW(...) __android_log_print(ANDROID_LOG_WARN , "eepp", __VA_ARGS__)
#define ANDROID_LOGE(...) __android_log_print(ANDROID_LOG_ERROR , "eepp", __VA_ARGS__)
#endif
namespace EE {
#if 1 == EE_USE_DOUBLES
#define EE_SIZE_OF_FLOAT 8

View File

@@ -572,10 +572,13 @@ Uint32 Utf<32>::DecodeAnsi(In input, const std::locale& locale)
return static_cast<Uint32>(character);
#else
// Get the facet of the locale which deals with character conversion
#if EE_PLATFORM != EE_PLATFORM_ANDROID
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
#else
const std::ctype<char>& facet = std::use_facet< std::ctype<char> >(locale);
#endif
// Use the facet to convert each character of the input string
return static_cast<Uint32>(facet.widen(input));
@@ -615,9 +618,12 @@ Out Utf<32>::EncodeAnsi(Uint32 codepoint, Out output, char replacement, const st
return output;
#else
// Get the facet of the locale which deals with character conversion
#if EE_PLATFORM != EE_PLATFORM_ANDROID
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
#else
const std::ctype<char>& facet = std::use_facet< std::ctype<char> >(locale);
#endif
// Use the facet to convert each character of the input string
*output++ = facet.narrow(static_cast<wchar_t>(codepoint), replacement);

View File

@@ -323,7 +323,7 @@ void cFont::SubDraw( const String& Text, const eeFloat& X, const eeFloat& Y, con
cTextureFactory::instance()->Bind( mTexId );
cTextureFactory::instance()->SetPreBlendFunc( Effect );
if ( !Cached && ( Text.size() != mRenderCoords.size() / 4 || Angle != 0.f || Scale != 1.f || FontHAlignGet( Flags ) == FONT_DRAW_CENTER || FontHAlignGet( Flags ) == FONT_DRAW_RIGHT ) ) {
if ( !Cached && ( Text.size() != mRenderCoords.size() / EE_QUAD_VERTEX || Angle != 0.f || Scale != 1.f || FontHAlignGet( Flags ) == FONT_DRAW_CENTER || FontHAlignGet( Flags ) == FONT_DRAW_RIGHT ) ) {
SetText( Text );
}

View File

@@ -170,7 +170,7 @@ void cTextureLoader::LoadFromPath() {
}
if ( NULL == mPixels )
cLog::instance()->Write( stbi_failure_reason() );
cLog::instance()->Write( "Filed to load: " + mFilepath + " Reason: " + std::string( stbi_failure_reason() ) );
} else if ( cPackManager::instance()->FallbackToPacks() ) {
mPack = cPackManager::instance()->Exists( mFilepath );

View File

@@ -67,10 +67,12 @@ static float fLastAccelerometer[3];
*******************************************************************************/
// Library init
/*
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
return JNI_VERSION_1_4;
}
* */
// Called before SDL_main() to initialize JNI bindings
extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls)

View File

@@ -41,15 +41,23 @@ void cLog::Write( const std::string& Text, const bool& newLine ) {
if ( newLine ) {
mData += '\n';
}
if ( mConsoleOutput ) {
#if EE_PLATFORM == EE_PLATFORM_ANDROID
if ( newLine ) {
ANDROID_LOGI( ( Text + std::string( "\n" ) ).c_str() );
} else {
ANDROID_LOGI( Text.c_str() );
}
#else
if ( newLine ) {
std::cout << Text << std::endl;
} else {
std::cout << Text;
}
#endif
}
if ( mLiveWrite ) {
openfs();
@@ -96,7 +104,11 @@ void cLog::Writef( const char* format, ... ) {
mData += tstr + '\n';
if ( mConsoleOutput ) {
#if EE_PLATFORM != EE_PLATFORM_ANDROID
std::cout << tstr << std::endl;
#else
ANDROID_LOGI( ( tstr + std::string( "\n" ) ).c_str() );
#endif
}
if ( mLiveWrite ) {

View File

@@ -1,7 +1,8 @@
#ifndef EE_SYSTEMSINGLETON_H
#define EE_SYSTEMSINGLETON_H
#include "../base.hpp"
#include "../base.hpp"
#include <typeinfo>
namespace EE { namespace System {
@@ -13,9 +14,10 @@ class tSingleton {
public:
/** Get the singleton pointer */
static T* CreateSingleton() {
if (ms_singleton == 0)
if (ms_singleton == 0) {
ms_singleton = eeNew( T, () );
}
return ms_singleton;
}

View File

@@ -5,33 +5,33 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
{
// Create a new window
cWindow * win = cEngine::instance()->CreateWindow( WindowSettings( 800, 600, 32, WindowStyle::Default, "", "eepp - Empty Window" ), ContextSettings( ) );
// Set window background color
win->BackColor( eeColor( 50, 50, 50 ) );
// Check if created
if ( win->Created() )
{
// Get input pointer
cInput * imp = win->GetInput();
eeFloat ang = 0;
// Application loop
while ( win->Running() )
{
// Update the input
imp->Update();
// Check if ESCAPE key is pressed
if ( imp->IsKeyDown( KEY_ESCAPE ) )
{
// Close the window
win->Close();
}
ang += cEngine::instance()->Elapsed() * 0.01;
// Create an instance of the primitive renderer
cPrimitives p;
@@ -46,7 +46,7 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
// Draw a circle
p.DrawCircle( win->GetWidth() / 2, win->GetHeight() / 2, 200 );
// Draw frame
win->Display();
@@ -54,12 +54,12 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
eeSleep( 10 );
}
}
// Destroy the engine instance. Destroys all the windows and engine singletons.
cEngine::DestroySingleton();
// If was compiled in debug mode it will print the memory manager report
EE::MemoryManager::LogResults();
return 0;
}

View File

@@ -9,6 +9,13 @@
#elif EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_ANDROID
#include <libgen.h>
#include <unistd.h>
#if EE_PLATFORM != EE_PLATFORM_ANDROID
#include <sys/statvfs.h>
#else
#include <sys/vfs.h>
#define statvfs statfs
#define fstatvfs fstatfs
#endif
#elif EE_PLATFORM == EE_PLATFORM_HAIKU
#include <kernel/OS.h>
#include <kernel/image.h>
@@ -16,6 +23,8 @@
#include <stdlib.h>
#endif
#if EE_PLATFORM == EE_PLATFORM_MACOSX || EE_PLATFORM == EE_PLATFORM_BSD
#include <sys/sysctl.h>
#endif
@@ -570,7 +579,7 @@ std::vector<std::string> FilesGetInPath( const std::string& path ) {
#endif
}
Uint32 FileSize( const std::string& Filepath ) {
Uint64 FileSize( const std::string& Filepath ) {
struct stat st;
int res = stat( Filepath.c_str(), &st );
@@ -758,7 +767,7 @@ eeInt GetCPUCount() {
GetSystemInfo(&info);
nprocs = (eeInt) info.dwNumberOfProcessors;
#elif EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_SOLARIS
#elif EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_SOLARIS || EE_PLATFORM == EE_PLATFORM_ANDROID
nprocs = sysconf(_SC_NPROCESSORS_ONLN);
#elif EE_PLATFORM == EE_PLATFORM_MACOSX || EE_PLATFORM == EE_PLATFORM_BSD
int mib[2];
@@ -914,4 +923,21 @@ void SetFlagValue( Uint32 * Key, Uint32 Val, Uint32 BitWrite ) {
}
}
Int64 GetDiskFreeSpace(const std::string& path) {
#if defined( EE_PLATFORM_POSIX )
struct statvfs data;
statvfs(path.c_str(), &data);
return (Int64)data.f_bsize * (Int64)data.f_bfree;
#elif EE_PLATFORM == EE_PLATFORM_WIN
Int64 AvailableBytes;
Int64 TotalBytes;
Int64 FreeBytes;
GetDiskFreeSpaceEx(path.c_str(),(PULARGE_INTEGER) &AvailableBytes,
(PULARGE_INTEGER) &TotalBytes, (PULARGE_INTEGER) &FreeBytes);
return FreeBytes;
#else
return -1;
#endif
}
}}

View File

@@ -24,7 +24,7 @@ namespace EE { namespace Utils {
std::vector<String> EE_API FilesGetInPath( const String& path );
/** @return The size of a file */
Uint32 EE_API FileSize( const std::string& Filepath );
Uint64 EE_API FileSize( const std::string& Filepath );
/** @return The System Time */
eeDouble EE_API GetSystemTime();
@@ -134,6 +134,9 @@ namespace EE { namespace Utils {
/** @return The OS Architecture */
std::string EE_API GetOSArchitecture();
/** @return Returns free disk space for a given path */
Int64 EE_API GetDiskFreeSpace(const std::string& path);
}
}