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 --- 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 ++++++++- 7 files changed, 42 insertions(+), 8 deletions(-) (limited to 'source') 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) -- cgit v1.2.3