From d21e4dacf7341b924fa534523ba31348ff6789ad Mon Sep 17 00:00:00 2001 From: faketruth Date: Wed, 15 Aug 2012 21:24:11 +0000 Subject: Compiles on Android! Added Eclipse project, import it into your workspace and it should be runnable on Android! Disabled Squirrel for Android cLog now logs to Android LogCat as well Fixed Lua so it compiles on Android Removed/commented out exceptions in JsonCpp so it compiles on Android git-svn-id: http://mc-server.googlecode.com/svn/trunk@741 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- .classpath | 8 +++ .project | 33 ++++++++++ .settings/org.eclipse.jdt.core.prefs | 4 ++ AndroidManifest.xml | 25 +++++++ WebServer/Socket.cpp | 4 ++ WebServer/base64.cpp | 3 + gen/com/mcserver/BuildConfig.java | 6 ++ gen/com/mcserver/R.java | 23 +++++++ jni/Android.mk | 44 +++++++++++++ jni/Application.mk | 4 ++ jni/app-android.cpp | 87 +++++++++++++++++++++++++ jsoncpp-src-0.5.0/src/lib_json/json_reader.cpp | 6 +- jsoncpp-src-0.5.0/src/lib_json/json_value.cpp | 27 +++++--- lua-5.1.4/src/llex.c | 6 +- proguard-project.txt | 20 ++++++ project.properties | 14 ++++ res/drawable-hdpi/ic_launcher.png | Bin 0 -> 9397 bytes res/drawable-ldpi/ic_launcher.png | Bin 0 -> 2729 bytes res/drawable-mdpi/ic_launcher.png | Bin 0 -> 5237 bytes res/drawable-xhdpi/ic_launcher.png | Bin 0 -> 14383 bytes res/layout/main.xml | 12 ++++ res/values/strings.xml | 7 ++ source/Globals.h | 6 ++ source/StringUtils.cpp | 3 + source/cLog.cpp | 7 ++ source/cPluginManager.cpp | 19 ++++-- source/cRoot.cpp | 2 + source/cSocket.cpp | 4 +- source/main.cpp | 9 ++- src/com/mcserver/MCServerActivity.java | 37 +++++++++++ 30 files changed, 399 insertions(+), 21 deletions(-) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 AndroidManifest.xml create mode 100644 gen/com/mcserver/BuildConfig.java create mode 100644 gen/com/mcserver/R.java create mode 100644 jni/Android.mk create mode 100644 jni/Application.mk create mode 100644 jni/app-android.cpp create mode 100644 proguard-project.txt create mode 100644 project.properties create mode 100644 res/drawable-hdpi/ic_launcher.png create mode 100644 res/drawable-ldpi/ic_launcher.png create mode 100644 res/drawable-mdpi/ic_launcher.png create mode 100644 res/drawable-xhdpi/ic_launcher.png create mode 100644 res/layout/main.xml create mode 100644 res/values/strings.xml create mode 100644 src/com/mcserver/MCServerActivity.java diff --git a/.classpath b/.classpath new file mode 100644 index 000000000..a4f1e4054 --- /dev/null +++ b/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 000000000..34dd17184 --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ + + + MCServer + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..da5d06089 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 000000000..e9613f36c --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WebServer/Socket.cpp b/WebServer/Socket.cpp index 2dde93b22..82c76a8f1 100644 --- a/WebServer/Socket.cpp +++ b/WebServer/Socket.cpp @@ -98,7 +98,9 @@ Socket::Socket() : if (!IsValid()) { +#if !defined(ANDROID_NDK) throw "INVALID_SOCKET"; +#endif } refCounter_ = new int(1); @@ -354,7 +356,9 @@ SocketSelect::SocketSelect(Socket const * const s1, Socket const * const s2, Typ } if (select(Highest + 1, &fds_, NULL, NULL, NULL) == SOCKET_ERROR) { +#if !defined(ANDROID_NDK) throw "Error in select"; +#endif } } diff --git a/WebServer/base64.cpp b/WebServer/base64.cpp index 4c19b600b..f505ea6c3 100644 --- a/WebServer/base64.cpp +++ b/WebServer/base64.cpp @@ -3,6 +3,9 @@ #include "base64.h" #include +#if defined(ANDROID_NDK) +#include +#endif static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" diff --git a/gen/com/mcserver/BuildConfig.java b/gen/com/mcserver/BuildConfig.java new file mode 100644 index 000000000..e40837927 --- /dev/null +++ b/gen/com/mcserver/BuildConfig.java @@ -0,0 +1,6 @@ +/** Automatically generated file. DO NOT MODIFY */ +package com.mcserver; + +public final class BuildConfig { + public final static boolean DEBUG = true; +} \ No newline at end of file diff --git a/gen/com/mcserver/R.java b/gen/com/mcserver/R.java new file mode 100644 index 000000000..3cbfd936d --- /dev/null +++ b/gen/com/mcserver/R.java @@ -0,0 +1,23 @@ +/* AUTO-GENERATED FILE. DO NOT MODIFY. + * + * This class was automatically generated by the + * aapt tool from the resource data it found. It + * should not be modified by hand. + */ + +package com.mcserver; + +public final class R { + public static final class attr { + } + public static final class drawable { + public static final int ic_launcher=0x7f020000; + } + public static final class layout { + public static final int main=0x7f030000; + } + public static final class string { + public static final int app_name=0x7f040001; + public static final int hello=0x7f040000; + } +} diff --git a/jni/Android.mk b/jni/Android.mk new file mode 100644 index 000000000..b55990005 --- /dev/null +++ b/jni/Android.mk @@ -0,0 +1,44 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := mcserver + + + +LOCAL_SRC_FILES := $(shell find lua-5.1.4 jsoncpp-src-0.5.0 zlib-1.2.7 source squirrel_3_0_1_stable tolua++-1.0.93 iniFile WebServer '(' -name '*.cpp' -o -name '*.c' ')') +LOCAL_SRC_FILES := $(filter-out %SquirrelFunctions.cpp %SquirrelBindings.cpp %cPlugin_Squirrel.cpp %cSquirrelCommandBinder.cpp %minigzip.c %lua.c %tolua.c %toluabind.c %LeakFinder.cpp %StackWalker.cpp %example.c,$(LOCAL_SRC_FILES)) +LOCAL_SRC_FILES := $(patsubst %.cpp,../%.cpp,$(LOCAL_SRC_FILES)) +LOCAL_SRC_FILES := $(patsubst %.c,../%.c,$(LOCAL_SRC_FILES)) +LOCAL_SRC_FILES += app-android.cpp + +LOCAL_CFLAGS := -DANDROID_NDK \ + -ffast-math \ + -O3 \ + -funroll-loops \ + -mfloat-abi=softfp -mfpu=neon \ + + +LOCAL_STATIC_LIBRARIES := cpufeatures + +LOCAL_C_INCLUDES := ./source \ + ./source/md5 \ + ./WebServer \ + ./source/packets \ + ./source/items \ + ./source/blocks \ + ./tolua++-1.0.93/src/lib \ + ./lua-5.1.4/src \ + ./zlib-1.2.7 \ + ./iniFile \ + ./tolua++-1.0.93/include \ + ./jsoncpp-src-0.5.0/include \ + ./jsoncpp-src-0.5.0/src/lib_json \ + ./squirrel_3_0_1_stable/include \ + ./squirrel_3_0_1_stable \ + ./squirrel_3_0_1_stable/sqrat \ + + +LOCAL_LDLIBS := -ldl -llog + +include $(BUILD_SHARED_LIBRARY) +$(call import-module,cpufeatures) diff --git a/jni/Application.mk b/jni/Application.mk new file mode 100644 index 000000000..c68dfe204 --- /dev/null +++ b/jni/Application.mk @@ -0,0 +1,4 @@ +# Build both ARMv5TE and ARMv7-A machine code. +APP_MODULES := mcserver +# APP_ABI := armeabi armeabi-v7a +APP_STL := stlport_static \ No newline at end of file diff --git a/jni/app-android.cpp b/jni/app-android.cpp new file mode 100644 index 000000000..d874f0fb0 --- /dev/null +++ b/jni/app-android.cpp @@ -0,0 +1,87 @@ +#include "Globals.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "cCriticalSection.h" +#include "cRoot.h" + +#include + +cCriticalSection g_CriticalSection; + +JNIEnv* g_CurrentJNIEnv = 0; +jobject g_JavaRenderer = 0; + +/* Called when program/activity is created */ +extern "C" void Java_com_mcserver_MainThread_NativeOnCreate( JNIEnv* env ) +{ + g_CriticalSection.Lock(); + g_CurrentJNIEnv = env; + //if( !cLogger::GetSingletonPtr() ) new cLogger(); + __android_log_print(ANDROID_LOG_ERROR,"Arashi", "%s", "Logging from C++!"); + g_CriticalSection.Unlock(); + + cRoot Root; + Root.Start(); +} + +extern "C" void Java_com_mcserver_MCServerActivity_NativeCleanUp( JNIEnv* env ) +{ + g_CriticalSection.Lock(); + g_CurrentJNIEnv = env; + + g_CriticalSection.Unlock(); +} + +/* Call to initialize the graphics state */ +extern "C" void Java_com_ballz_CppWrapperRenderer_NativeInitGL( JNIEnv* env, jobject thiz ) +{ + g_CriticalSection.Lock(); + g_CurrentJNIEnv = env; + g_JavaRenderer = thiz; + + g_CriticalSection.Unlock(); +} + +extern "C" void Java_com_ballz_CppWrapperRenderer_NativeResize( JNIEnv* env, jobject thiz, jint w, jint h ) +{ + g_CriticalSection.Lock(); + g_CurrentJNIEnv = env; + g_JavaRenderer = thiz; + + g_CriticalSection.Unlock(); +} + +extern "C" void Java_com_ballz_CppWrapperRenderer_NativeRender( JNIEnv* env, jobject thiz ) +{ + g_CriticalSection.Lock(); + g_CurrentJNIEnv = env; + g_JavaRenderer = thiz; + + + g_CriticalSection.Unlock(); +} + +extern "C" void Java_com_ballz_CppWrapperGLSurfaceView_NativeTouchScreen( JNIEnv* env, jobject thiz, jint mouseid, jint touched ) +{ + g_CriticalSection.Lock(); + g_CurrentJNIEnv = env; + + g_CriticalSection.Unlock(); +} + +extern "C" void Java_com_ballz_CppWrapperGLSurfaceView_NativeTouchEvent( JNIEnv* env, jobject thiz, jint mouseid, jfloat x, jfloat y ) +{ + g_CriticalSection.Lock(); + g_CurrentJNIEnv = env; + + g_CriticalSection.Unlock(); +} \ No newline at end of file diff --git a/jsoncpp-src-0.5.0/src/lib_json/json_reader.cpp b/jsoncpp-src-0.5.0/src/lib_json/json_reader.cpp index 4eb2d11fd..7c94e612e 100644 --- a/jsoncpp-src-0.5.0/src/lib_json/json_reader.cpp +++ b/jsoncpp-src-0.5.0/src/lib_json/json_reader.cpp @@ -871,13 +871,13 @@ Reader::getFormatedErrorMessages() const return formattedMessage; } - +#define JSON_ASSERT( condition ) assert( condition ); std::istream& operator>>( std::istream &sin, Value &root ) { Json::Reader reader; bool ok = reader.parse(sin, root, true); - //JSON_ASSERT( ok ); - if (!ok) throw std::runtime_error(reader.getFormatedErrorMessages()); + JSON_ASSERT( ok ); + //if (!ok) throw std::runtime_error(reader.getFormatedErrorMessages()); return sin; } diff --git a/jsoncpp-src-0.5.0/src/lib_json/json_value.cpp b/jsoncpp-src-0.5.0/src/lib_json/json_value.cpp index 573205f13..89271cd00 100644 --- a/jsoncpp-src-0.5.0/src/lib_json/json_value.cpp +++ b/jsoncpp-src-0.5.0/src/lib_json/json_value.cpp @@ -153,7 +153,8 @@ Value::CommentInfo::setComment( const char *text ) if ( comment_ ) valueAllocator()->releaseStringValue( comment_ ); JSON_ASSERT( text ); - JSON_ASSERT_MESSAGE( text[0]=='\0' || text[0]=='/', "Comments must start with /"); + //JSON_ASSERT_MESSAGE( text[0]=='\0' || text[0]=='/', "Comments must start with /"); + JSON_ASSERT( text[0]=='\0' || text[0]=='/' ); // It seems that /**/ style comments are acceptable as well. comment_ = valueAllocator()->duplicateStringValue( text ); } @@ -697,7 +698,8 @@ Value::asString() const case realValue: case arrayValue: case objectValue: - JSON_ASSERT_MESSAGE( false, "Type is not convertible to string" ); + //JSON_ASSERT_MESSAGE( false, "Type is not convertible to string" ); + JSON_ASSERT( false ); default: JSON_ASSERT_UNREACHABLE; } @@ -722,17 +724,20 @@ Value::asInt() const case intValue: return value_.int_; case uintValue: - JSON_ASSERT_MESSAGE( value_.uint_ < (unsigned)maxInt, "integer out of signed integer range" ); + //JSON_ASSERT_MESSAGE( value_.uint_ < (unsigned)maxInt, "integer out of signed integer range" ); + JSON_ASSERT( value_.uint_ < (unsigned)maxInt ); return value_.uint_; case realValue: - JSON_ASSERT_MESSAGE( value_.real_ >= minInt && value_.real_ <= maxInt, "Real out of signed integer range" ); + //JSON_ASSERT_MESSAGE( value_.real_ >= minInt && value_.real_ <= maxInt, "Real out of signed integer range" ); + JSON_ASSERT( value_.real_ >= minInt && value_.real_ <= maxInt ); return Int( value_.real_ ); case booleanValue: return value_.bool_ ? 1 : 0; case stringValue: case arrayValue: case objectValue: - JSON_ASSERT_MESSAGE( false, "Type is not convertible to int" ); + //JSON_ASSERT_MESSAGE( false, "Type is not convertible to int" ); + JSON_ASSERT( false ); default: JSON_ASSERT_UNREACHABLE; } @@ -747,19 +752,22 @@ Value::asUInt() const case nullValue: return 0; case intValue: - JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to unsigned integer" ); + //JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to unsigned integer" ); + JSON_ASSERT( value_.int_ >= 0 ); return value_.int_; case uintValue: return value_.uint_; case realValue: - JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt, "Real out of unsigned integer range" ); + //JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt, "Real out of unsigned integer range" ); + JSON_ASSERT( value_.real_ >= 0 && value_.real_ <= maxUInt ); return UInt( value_.real_ ); case booleanValue: return value_.bool_ ? 1 : 0; case stringValue: case arrayValue: case objectValue: - JSON_ASSERT_MESSAGE( false, "Type is not convertible to uint" ); + //JSON_ASSERT_MESSAGE( false, "Type is not convertible to uint" ); + JSON_ASSERT( false ); default: JSON_ASSERT_UNREACHABLE; } @@ -784,7 +792,8 @@ Value::asDouble() const case stringValue: case arrayValue: case objectValue: - JSON_ASSERT_MESSAGE( false, "Type is not convertible to double" ); + //JSON_ASSERT_MESSAGE( false, "Type is not convertible to double" ); + JSON_ASSERT( false ); default: JSON_ASSERT_UNREACHABLE; } diff --git a/lua-5.1.4/src/llex.c b/lua-5.1.4/src/llex.c index 6dc319358..02849fa8f 100644 --- a/lua-5.1.4/src/llex.c +++ b/lua-5.1.4/src/llex.c @@ -176,9 +176,13 @@ static void buffreplace (LexState *ls, char from, char to) { static void trydecpoint (LexState *ls, SemInfo *seminfo) { /* format error: try to update decimal point separator */ - struct lconv *cv = localeconv(); char old = ls->decpoint; +#if defined(ANDROID_NDK) + ls->decpoint = '.'; +#else + struct lconv *cv = localeconv(); ls->decpoint = (cv ? cv->decimal_point[0] : '.'); +#endif buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { /* format error with correct decimal point: no more options */ diff --git a/proguard-project.txt b/proguard-project.txt new file mode 100644 index 000000000..f2fe1559a --- /dev/null +++ b/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/project.properties b/project.properties new file mode 100644 index 000000000..7a6518b77 --- /dev/null +++ b/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt + +# Project target. +target=android-12 diff --git a/res/drawable-hdpi/ic_launcher.png b/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 000000000..96a442e5b Binary files /dev/null and b/res/drawable-hdpi/ic_launcher.png differ diff --git a/res/drawable-ldpi/ic_launcher.png b/res/drawable-ldpi/ic_launcher.png new file mode 100644 index 000000000..99238729d Binary files /dev/null and b/res/drawable-ldpi/ic_launcher.png differ diff --git a/res/drawable-mdpi/ic_launcher.png b/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 000000000..359047dfa Binary files /dev/null and b/res/drawable-mdpi/ic_launcher.png differ diff --git a/res/drawable-xhdpi/ic_launcher.png b/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 000000000..71c6d760f Binary files /dev/null and b/res/drawable-xhdpi/ic_launcher.png differ diff --git a/res/layout/main.xml b/res/layout/main.xml new file mode 100644 index 000000000..ac9c0abab --- /dev/null +++ b/res/layout/main.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml new file mode 100644 index 000000000..8c782a739 --- /dev/null +++ b/res/values/strings.xml @@ -0,0 +1,7 @@ + + + + Hello World, MCServerActivity! + MCServer + + \ No newline at end of file diff --git a/source/Globals.h b/source/Globals.h index 12cdd8c94..4816e2769 100644 --- a/source/Globals.h +++ b/source/Globals.h @@ -114,8 +114,14 @@ typedef short Int16; #include #include #include +#if !defined(ANDROID_NDK) #include #endif +#endif + +#if !defined(ANDROID_NDK) + #define USE_SQUIRREL +#endif diff --git a/source/StringUtils.cpp b/source/StringUtils.cpp index 652c680c7..fa61a61e7 100644 --- a/source/StringUtils.cpp +++ b/source/StringUtils.cpp @@ -5,6 +5,9 @@ #include "Globals.h" +#if defined(ANDROID_NDK) +#include +#endif diff --git a/source/cLog.cpp b/source/cLog.cpp index 5e79b48bf..372616be8 100644 --- a/source/cLog.cpp +++ b/source/cLog.cpp @@ -9,6 +9,9 @@ #include "cIsThread.h" +#if defined(ANDROID_NDK) +#include +#endif @@ -97,6 +100,10 @@ void cLog::ClearLog() void cLog::Log(const char * a_Format, va_list argList) { +#if defined(ANDROID_NDK) + __android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList); + return; // This is as far as android goes +#endif AString Message; AppendVPrintf(Message, a_Format, argList); diff --git a/source/cPluginManager.cpp b/source/cPluginManager.cpp index 64f6442ca..a722520bf 100644 --- a/source/cPluginManager.cpp +++ b/source/cPluginManager.cpp @@ -4,20 +4,21 @@ #include "cPlugin.h" #include "cPlugin_Lua.h" #include "cPlugin_NewLua.h" -#include "cPlugin_Squirrel.h" #include "cWebAdmin.h" #include "cItem.h" #include "cRoot.h" #include "cLuaCommandBinder.h" -#include "cSquirrelCommandBinder.h" +#if USE_SQUIRREL +# include "cPlugin_Squirrel.h" +# include "cSquirrelCommandBinder.h" +#endif #include "../iniFile/iniFile.h" #include "tolua++.h" #include "cPlayer.h" -#include "squirrelbindings/SquirrelBindings.h" -#include "squirrelbindings/SquirrelFunctions.h" - #if USE_SQUIRREL + #include "squirrelbindings/SquirrelBindings.h" + #include "squirrelbindings/SquirrelFunctions.h" #pragma warning(disable:4100;disable:4127;disable:4510;disable:4610;disable:4244;disable:4512) // Getting A LOT of these warnings from SqPlus #pragma warning(default:4100;default:4127;default:4510;default:4610;default:4244;default:4512) @@ -39,7 +40,9 @@ cPluginManager* cPluginManager::GetPluginManager() cPluginManager::cPluginManager() : m_LuaCommandBinder( new cLuaCommandBinder() ) +#if USE_SQUIRREL , m_SquirrelCommandBinder( new cSquirrelCommandBinder() ) +#endif , m_bReloadPlugins(false) { } @@ -53,7 +56,9 @@ cPluginManager::~cPluginManager() UnloadPluginsNow(); delete m_LuaCommandBinder; +#if USE_SQUIRREL delete m_SquirrelCommandBinder; +#endif } @@ -197,10 +202,12 @@ bool cPluginManager::CallHook(PluginHook a_Hook, unsigned int a_NumArgs, ...) cPlayer * Player = va_arg(argptr, cPlayer * ); va_end (argptr); +#if USE_SQUIRREL if (m_SquirrelCommandBinder->HandleCommand( std::string( Message ), Player)) { return true; } +#endif if (m_LuaCommandBinder->HandleCommand( std::string( Message ), Player)) { @@ -682,7 +689,9 @@ void cPluginManager::RemovePlugin( cPlugin* a_Plugin, bool a_bDelete /* = false if( a_bDelete ) { m_LuaCommandBinder->RemoveBindingsForPlugin( a_Plugin ); +#if USE_SQUIRREL m_SquirrelCommandBinder->RemoveBindingsForPlugin( a_Plugin ); +#endif m_Plugins.remove( a_Plugin ); RemoveHooks( a_Plugin ); a_Plugin->OnDisable(); diff --git a/source/cRoot.cpp b/source/cRoot.cpp index df89eb966..4d69635e2 100644 --- a/source/cRoot.cpp +++ b/source/cRoot.cpp @@ -16,8 +16,10 @@ #include "cRedstone.h" #include "blocks/Block.h" #include "items/Item.h" +#if USE_SQUIRREL #include "squirrelbindings/SquirrelFunctions.h" #include "squirrelbindings/SquirrelBindings.h" +#endif #include "cChunk.h" #include "../iniFile/iniFile.h" diff --git a/source/cSocket.cpp b/source/cSocket.cpp index 57ecfcbdc..edce83981 100644 --- a/source/cSocket.cpp +++ b/source/cSocket.cpp @@ -111,7 +111,7 @@ AString cSocket::GetErrorString( int a_ErrNo ) // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r(): - #if ( _GNU_SOURCE ) // GNU version of strerror_r() + #if ( _GNU_SOURCE ) && !defined(ANDROID_NDK) // GNU version of strerror_r() char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) ); if( res != NULL ) @@ -158,7 +158,7 @@ int cSocket::GetLastError() int cSocket::SetReuseAddress() { -#ifdef _WIN32 +#if defined(_WIN32) || defined(ANDROID_NDK) char yes = 1; #else int yes = 1; diff --git a/source/main.cpp b/source/main.cpp index 4b498ae0a..0fdaf2d50 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -6,13 +6,16 @@ #include //std::exception #include //std::signal #include //exit() +#ifdef USE_SQUIRREL #include "squirrelbindings/SquirrelFunctions.h" +#include "squirrelbindings/SquirrelBindings.h" +#endif #ifdef _WIN32 #include #endif // _WIN32 -#include "squirrelbindings/SquirrelBindings.h" + @@ -168,11 +171,14 @@ int main( int argc, char **argv ) // DEBUG: test the dumpfile creation: // *((int *)0) = 0; + #if !defined(ANDROID_NDK) try + #endif { cRoot Root; Root.Start(); } + #if !defined(ANDROID_NDK) catch( std::exception& e ) { LOGERROR("Standard exception: %s", e.what() ); @@ -181,6 +187,7 @@ int main( int argc, char **argv ) { LOGERROR("Unknown exception!"); } + #endif #if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER) diff --git a/src/com/mcserver/MCServerActivity.java b/src/com/mcserver/MCServerActivity.java new file mode 100644 index 000000000..225ba7a94 --- /dev/null +++ b/src/com/mcserver/MCServerActivity.java @@ -0,0 +1,37 @@ +package com.mcserver; + +import android.app.Activity; +import android.os.Bundle; + +public class MCServerActivity extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + MainThread p = new MainThread(); + p.start(); + + //NativeOnCreate(); + } + + + static { + System.loadLibrary("mcserver"); + } + + private static native void NativeOnCreate(); +} + + +class MainThread extends Thread { + MainThread() { + } + + public void run() { + NativeOnCreate(); + } + + private static native void NativeOnCreate(); +} \ No newline at end of file -- cgit v1.2.3