Compiling for android but have some bugs

This commit is contained in:
Tulioh 2014-12-25 14:22:37 -02:00
parent c28d2c1555
commit 389c7f2a60
20 changed files with 149 additions and 195 deletions

7
.gitignore vendored
View File

@ -4,6 +4,13 @@ CMakeFiles
cmake_install.cmake cmake_install.cmake
Makefile Makefile
/otclient /otclient
/android/project/build.xml
/android/project/proguard-project.txt
/android/project/gen*
/android/project/bin*
/android/project/libs/*
libs*
.idea*
/*.h /*.h
/*.cxx /*.cxx
*.o *.o

View File

@ -33,9 +33,10 @@ add_definitions(-D"VERSION=\\"${VERSION}\\"")
if(ANDROID) if(ANDROID)
include_directories($ENV{ANDROID_NDK}/sources/android/native_app_glue)
set(executable_SOURCES set(executable_SOURCES
android/android.cpp "android/android.cpp"
src/main.cpp "$ENV{ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c"
) )
# add shared library for android # add shared library for android

View File

@ -1,10 +1,35 @@
#include <jni.h> /*
#include <main.cpp> * Copyright (c) 2010-2014 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <android_native_app_glue.h>
#include <client/client.h>
void android_main( struct android_app* state ) { void android_main( struct android_app* state ) {
int argc = 0; int argc = 1;
const char* argv[1]; const char* argv[1];
argv[0] = NULL; argv[0] = "NULL";
main(argc, argv); Client client( argc, argv );
client.terminateAndFreeMemory();
ANativeActivity_finish(state->activity);
} }

View File

@ -1,7 +1,19 @@
#!/bin/sh #!/bin/sh
mkdir ../build && cd ../build mkdir ../build && cd ../build
cmake -DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake -DANDROID_ABI=armeabi -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.6 .. cmake -DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake -DANDROID_ABI=armeabi-v7a -DANDROID_NATIVE_API_LEVEL=android-16 -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.6 ..
make make
cd ../ && rm -r build && mkdir build && cd build cd ../ && rm -r build
cp -r libs android/project/ && rm -r libs
cd android/project
android update project -p . --name OTClientMob --target android-16
ant debug
cd bin
adb install -r OTClientMob-debug.apk

View File

@ -21,29 +21,38 @@
*/ */
#include "client.h" #include "client.h"
#include <framework/core/modulemanager.h>
#include <framework/core/resourcemanager.h>
#include <framework/graphics/graphics.h>
#include "game.h" #include "game.h"
#include "map.h" #include "map.h"
#include "shadermanager.h" #include "shadermanager.h"
#include "spritemanager.h" #include "spritemanager.h"
#include "minimap.h" #include "minimap.h"
#include <framework/luaengine/luainterface.h>
#include <framework/core/application.h>
#include <framework/core/modulemanager.h>
#include <framework/core/resourcemanager.h>
#include <framework/core/configmanager.h> #include <framework/core/configmanager.h>
#include <framework/graphics/graphics.h>
Client g_client; Client::Client(int argc, const char* argv[]) {
std::vector<std::string> args(argv, argv + argc);
initAppFrameworkAndOTClient(args);
}
void Client::init(std::vector<std::string>& args) void Client::initAppFrameworkAndOTClient(std::vector<std::string>& args)
{ {
// register needed lua functions setupAppNameAndVersion();
registerLuaFunctions();
g_app.init(args);
g_map.init(); g_map.init();
g_minimap.init(); g_minimap.init();
g_game.init(); g_game.init();
g_shaders.init(); g_shaders.init();
g_things.init(); g_things.init();
registerLuaFunctions();
findLuaInitScript();
g_app.runAppMainLoop();
//TODO: restore options //TODO: restore options
/* /*
if(g_graphics.parseOption(arg)) if(g_graphics.parseOption(arg))
@ -81,8 +90,28 @@ void Client::init(std::vector<std::string>& args)
*/ */
} }
void Client::terminate() void Client::setupAppNameAndVersion() {
g_app.setName("OTClient");
g_app.setCompactName("otclient");
g_app.setVersion(VERSION);
}
void Client::findLuaInitScript() {
if(!g_resources.discoverWorkDir("init.lua"))
g_logger.fatal("Unable to find work directory, the application cannot be initialized.");
else
runLuaInitScript();
}
void Client::runLuaInitScript() {
if(!g_lua.safeRunScript("init.lua"))
g_logger.fatal("Unable to run script init.lua!");
}
void Client::terminateAndFreeMemory()
{ {
g_app.unloadModules();
g_creatures.terminate(); g_creatures.terminate();
g_game.terminate(); g_game.terminate();
g_map.terminate(); g_map.terminate();
@ -90,4 +119,5 @@ void Client::terminate()
g_things.terminate(); g_things.terminate();
g_sprites.terminate(); g_sprites.terminate();
g_shaders.terminate(); g_shaders.terminate();
g_app.terminate();
} }

View File

@ -27,12 +27,14 @@
class Client class Client
{ {
public: void initAppFrameworkAndOTClient(std::vector<std::string>& args);
void init(std::vector<std::string>& args); void setupAppNameAndVersion();
void terminate(); void findLuaInitScript();
void runLuaInitScript();
void registerLuaFunctions(); void registerLuaFunctions();
public:
Client(int argc, const char* argv[]);
void terminateAndFreeMemory();
}; };
extern Client g_client;
#endif #endif

View File

@ -126,10 +126,10 @@ set(framework_SOURCES ${framework_SOURCES}
# crash handler # crash handler
${CMAKE_CURRENT_LIST_DIR}/platform/crashhandler.h ${CMAKE_CURRENT_LIST_DIR}/platform/crashhandler.h
#${CMAKE_CURRENT_LIST_DIR}/platform/unixcrashhandler.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/unixcrashhandler.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/win32crashhandler.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/win32crashhandler.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/win32platform.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/win32platform.cpp
#${CMAKE_CURRENT_LIST_DIR}/platform/unixplatform.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/unixplatform.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/platform.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/platform.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/platform.h ${CMAKE_CURRENT_LIST_DIR}/platform/platform.h
) )
@ -140,7 +140,11 @@ set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp
# some build options # some build options
option(LUAJIT "Use lua jit" OFF) option(LUAJIT "Use lua jit" OFF)
if(NOT APPLE) if(NOT APPLE)
if(ANDROID)
set(CRASH_HANDLER OFF)
else()
option(CRASH_HANDLER "Generate crash reports" ON) option(CRASH_HANDLER "Generate crash reports" ON)
endif()
option(USE_STATIC_LIBS "Don't use shared libraries (dlls)" ON) option(USE_STATIC_LIBS "Don't use shared libraries (dlls)" ON)
option(USE_LIBCPP "Use the new libc++ library instead of stdc++" OFF) option(USE_LIBCPP "Use the new libc++ library instead of stdc++" OFF)
option(USE_LTO "Use link time optimizations" OFF) option(USE_LTO "Use link time optimizations" OFF)
@ -206,12 +210,7 @@ if(WIN32)
endif() endif()
set(Boost_USE_MULTITHREADED ON) set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_LIBS ${USE_STATIC_LIBS}) set(Boost_USE_STATIC_LIBS ${USE_STATIC_LIBS})
find_package(Boost 1.48.0 COMPONENTS ${REQUIRED_BOOST_COMPONENTS} REQUIRED)
if(ANDROID)
else()
find_package(Boost 1.48.0 COMPONENTS ${REQUIRED_BOOST_COMPONENTS} REQUIRED)
endif()
#find lua #find lua
if(LUAJIT) if(LUAJIT)
@ -230,11 +229,10 @@ message(STATUS "LuaJIT: " ${LUAJIT})
find_package(PhysFS REQUIRED) find_package(PhysFS REQUIRED)
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
# android already has zlib
if(NOT ANDROID) if(NOT ANDROID)
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
else() else()
set(framework_LIBRARIES ${framework_LIBRARIES} android) set(framework_LIBRARIES ${framework_LIBRARIES} z android log)
endif() endif()
set(framework_LIBRARIES ${framework_LIBRARIES} set(framework_LIBRARIES ${framework_LIBRARIES}
@ -292,8 +290,12 @@ else()
else() else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -rdynamic -Wl,-rpath,./libs") # rdynamic is needed by backtrace.h used in crash handler set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -rdynamic -Wl,-rpath,./libs") # rdynamic is needed by backtrace.h used in crash handler
if(ANDROID)
set(SYSTEM_LIBRARIES dl)
else()
set(SYSTEM_LIBRARIES dl rt) set(SYSTEM_LIBRARIES dl rt)
endif() endif()
endif()
endif() endif()
set(framework_LIBRARIES ${framework_LIBRARIES} ${SYSTEM_LIBRARIES}) set(framework_LIBRARIES ${framework_LIBRARIES} ${SYSTEM_LIBRARIES})
@ -303,7 +305,7 @@ endif()
if(FRAMEWORK_GRAPHICS) if(FRAMEWORK_GRAPHICS)
set(OPENGLES "OFF" CACHE "Use OpenGL ES 1.0 or 2.0 (for mobiles devices)" STRING) set(OPENGLES "OFF" CACHE "Use OpenGL ES 1.0 or 2.0 (for mobiles devices)" STRING)
if(OPENGLES STREQUAL "2.0" OR ANDROID_NATIVE_API_LEVEL VERSION_GREATER 7) if(OPENGLES STREQUAL "2.0" OR (ANDROID_NATIVE_API_LEVEL AND ANDROID_NATIVE_API_LEVEL VERSION_GREATER 7))
if(NOT ANDROID) if(NOT ANDROID)
find_package(OpenGLES2 REQUIRED) find_package(OpenGLES2 REQUIRED)
find_package(EGL REQUIRED) find_package(EGL REQUIRED)
@ -313,7 +315,7 @@ if(FRAMEWORK_GRAPHICS)
set(framework_LIBRARIES ${framework_LIBRARIES} GLESv2) set(framework_LIBRARIES ${framework_LIBRARIES} GLESv2)
endif() endif()
set(framework_DEFINITIONS ${framework_DEFINITIONS} -DOPENGL_ES=2) set(framework_DEFINITIONS ${framework_DEFINITIONS} -DOPENGL_ES=2)
ELSEif(OPENGLES STREQUAL "1.0" OR ANDROID_NATIVE_API_LEVEL VERSION_LESS 8) ELSEif(OPENGLES STREQUAL "1.0" OR (ANDROID_NATIVE_API_LEVEL AND ANDROID_NATIVE_API_LEVEL VERSION_LESS 8))
if(NOT ANDROID) if(NOT ANDROID)
find_package(OpenGLES1 REQUIRED) find_package(OpenGLES1 REQUIRED)
find_package(EGL REQUIRED) find_package(EGL REQUIRED)
@ -460,8 +462,8 @@ if(FRAMEWORK_GRAPHICS)
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.h ${CMAKE_CURRENT_LIST_DIR}/platform/win32window.h
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.h ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.h
${CMAKE_CURRENT_LIST_DIR}/platform/sdlplatform.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/sdlwindow.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/sdlplatform.h ${CMAKE_CURRENT_LIST_DIR}/platform/sdlwindow.h
# window input # window input
${CMAKE_CURRENT_LIST_DIR}/input/mouse.cpp ${CMAKE_CURRENT_LIST_DIR}/input/mouse.cpp

View File

@ -101,7 +101,7 @@ void Application::init(std::vector<std::string>& args)
registerLuaFunctions(); registerLuaFunctions();
} }
void Application::deinit() void Application::unloadModules()
{ {
g_lua.callGlobalField("g_app", "onTerminate"); g_lua.callGlobalField("g_app", "onTerminate");

View File

@ -34,9 +34,9 @@ public:
virtual ~Application() {} virtual ~Application() {}
virtual void init(std::vector<std::string>& args); virtual void init(std::vector<std::string>& args);
virtual void deinit(); virtual void unloadModules();
virtual void terminate(); virtual void terminate();
virtual void run() = 0; virtual void runAppMainLoop() = 0;
virtual void poll(); virtual void poll();
virtual void exit(); virtual void exit();
virtual void close(); virtual void close();

View File

@ -31,7 +31,7 @@
ConsoleApplication g_app; ConsoleApplication g_app;
void ConsoleApplication::run() void ConsoleApplication::runAppMainLoop()
{ {
m_running = true; m_running = true;

View File

@ -29,7 +29,7 @@
class ConsoleApplication : public Application class ConsoleApplication : public Application
{ {
public: public:
void run(); void runAppMainLoop();
int getFps() { return m_frameCounter.getLastFps(); } int getFps() { return m_frameCounter.getLastFps(); }

View File

@ -66,12 +66,12 @@ void GraphicalApplication::init(std::vector<std::string>& args)
#endif #endif
} }
void GraphicalApplication::deinit() void GraphicalApplication::unloadModules()
{ {
// hide the window because there is no render anymore // hide the window because there is no render anymore
g_window.hide(); g_window.hide();
Application::deinit(); Application::unloadModules();
} }
void GraphicalApplication::terminate() void GraphicalApplication::terminate()
@ -101,7 +101,7 @@ void GraphicalApplication::terminate()
m_terminated = true; m_terminated = true;
} }
void GraphicalApplication::run() void GraphicalApplication::runAppMainLoop()
{ {
m_running = true; m_running = true;

View File

@ -36,9 +36,9 @@ class GraphicalApplication : public Application
public: public:
void init(std::vector<std::string>& args); void init(std::vector<std::string>& args);
void deinit(); void unloadModules();
void terminate(); void terminate();
void run(); void runAppMainLoop();
void poll(); void poll();
void close(); void close();

View File

@ -26,8 +26,8 @@
#include "win32window.h" #include "win32window.h"
WIN32Window window; WIN32Window window;
#elif defined ANDROID #elif defined ANDROID
#include "sdlplatform.h" #include "sdlwindow.h"
SDLPlatform window; SDLWindow window;
#else #else
#include "x11window.h" #include "x11window.h"
#include <framework/core/clock.h> #include <framework/core/clock.h>

View File

@ -1,75 +0,0 @@
#include "sdlplatform.h"
void SDLPlatform::init() {
}
void SDLPlatform::terminate() {
}
void SDLPlatform::move(const Point& pos) {
}
void SDLPlatform::resize(const Size& size) {
}
void SDLPlatform::show() {
}
void SDLPlatform::hide() {
}
void SDLPlatform::maximize() {
}
void SDLPlatform::poll() {
}
void SDLPlatform::swapBuffers() {
}
void SDLPlatform::showMouse() {
}
void SDLPlatform::hideMouse() {
}
int SDLPlatform::internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot) {
return 0;
}
void SDLPlatform::setMouseCursor(int cursorId) {
}
void SDLPlatform::restoreMouseCursor() {
}
void SDLPlatform::setTitle(const std::string& title) {
}
void SDLPlatform::setMinimumSize(const Size& minimumSize) {
}
void SDLPlatform::setFullscreen(bool fullscreen) {
}
void SDLPlatform::setVerticalSync(bool enable) {
}
void SDLPlatform::setIcon(const std::string& iconFile) {
}
void SDLPlatform::setClipboardText(const std::string& text) {
}
Size SDLPlatform::getDisplaySize() {
Size TODO;
return TODO;
}
std::string SDLPlatform::getClipboardText() {
return nullptr;
}
std::string SDLPlatform::getPlatformType() {
return nullptr;
}

View File

@ -1,39 +0,0 @@
#ifndef SDL_PLATFORM_H
#define SDL_PLATFORM_H
#include "platformwindow.h"
class SDLPlatform : public PlatformWindow
{
public:
void init();
void terminate();
void move(const Point& pos);
void resize(const Size& size);
void show();
void hide();
void maximize();
void poll();
void swapBuffers();
void showMouse();
void hideMouse();
void setMouseCursor(int cursorId);
void restoreMouseCursor();
void setTitle(const std::string& title);
void setMinimumSize(const Size& minimumSize);
void setFullscreen(bool fullscreen);
void setVerticalSync(bool enable);
void setIcon(const std::string& iconFile);
void setClipboardText(const std::string& text);
Size getDisplaySize();
std::string getClipboardText();
std::string getPlatformType();
protected:
int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot);
};
#endif

View File

@ -1,5 +1,12 @@
#include "sdlwindow.h" #include "sdlwindow.h"
SDLWindow::SDLWindow() {
m_window = 0;
m_cursor = 0;
m_minimumSize = Size(600,480);
m_size = Size(600,480);
}
void SDLWindow::init() { void SDLWindow::init() {
} }
@ -83,7 +90,7 @@ Size SDLWindow::getDisplaySize() {
} }
std::string SDLWindow::getClipboardText() { std::string SDLWindow::getClipboardText() {
return nullptr; return "";
} }
std::string SDLWindow::getPlatformType() { std::string SDLWindow::getPlatformType() {

View File

@ -20,7 +20,7 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#if !defined(WIN32) && defined(CRASH_HANDLER) #if !defined(WIN32) && !defined(ANDROID) && defined(CRASH_HANDLER)
#include "crashhandler.h" #include "crashhandler.h"
#include <framework/global.h> #include <framework/global.h>

View File

@ -29,7 +29,12 @@
#include <framework/stdext/stdext.h> #include <framework/stdext/stdext.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifdef ANDROID
#include <errno.h>
#else
#include <execinfo.h> #include <execinfo.h>
#endif
void Platform::processArgs(std::vector<std::string>& args) void Platform::processArgs(std::vector<std::string>& args)
{ {
@ -169,6 +174,7 @@ std::string Platform::getOSName()
return std::string(); return std::string();
} }
#ifndef ANDROID
std::string Platform::traceback(const std::string& where, int level, int maxDepth) std::string Platform::traceback(const std::string& where, int level, int maxDepth)
{ {
std::stringstream ss; std::stringstream ss;
@ -199,5 +205,8 @@ std::string Platform::traceback(const std::string& where, int level, int maxDept
return ss.str(); return ss.str();
} }
#else
std::string Platform::traceback(const std::string& where, int level, int maxDepth){ return "TODO"; }
#endif
#endif #endif

View File

@ -20,39 +20,12 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <framework/core/application.h>
#include <framework/core/resourcemanager.h>
#include <framework/luaengine/luainterface.h>
#include <client/client.h> #include <client/client.h>
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
std::vector<std::string> args(argv, argv + argc); Client client(argc, argv);
client.terminateAndFreeMemory();
// setup application name and version
g_app.setName("OTClient");
g_app.setCompactName("otclient");
g_app.setVersion(VERSION);
// initialize application framework and otclient
g_app.init(args);
g_client.init(args);
// find script init.lua and run it
if(!g_resources.discoverWorkDir("init.lua"))
g_logger.fatal("Unable to find work directory, the application cannot be initialized.");
if(!g_lua.safeRunScript("init.lua"))
g_logger.fatal("Unable to run script init.lua!");
// the run application main loop
g_app.run();
// unload modules
g_app.deinit();
// terminate everything and free memory
g_client.terminate();
g_app.terminate();
return 0; return 0;
} }