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

View File

@@ -21,29 +21,38 @@
*/
#include "client.h"
#include <framework/core/modulemanager.h>
#include <framework/core/resourcemanager.h>
#include <framework/graphics/graphics.h>
#include "game.h"
#include "map.h"
#include "shadermanager.h"
#include "spritemanager.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/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
registerLuaFunctions();
setupAppNameAndVersion();
g_app.init(args);
g_map.init();
g_minimap.init();
g_game.init();
g_shaders.init();
g_things.init();
registerLuaFunctions();
findLuaInitScript();
g_app.runAppMainLoop();
//TODO: restore options
/*
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_game.terminate();
g_map.terminate();
@@ -90,4 +119,5 @@ void Client::terminate()
g_things.terminate();
g_sprites.terminate();
g_shaders.terminate();
g_app.terminate();
}

View File

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

View File

@@ -126,10 +126,10 @@ set(framework_SOURCES ${framework_SOURCES}
# crash handler
${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/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.h
)
@@ -140,7 +140,11 @@ set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp
# some build options
option(LUAJIT "Use lua jit" OFF)
if(NOT APPLE)
option(CRASH_HANDLER "Generate crash reports" ON)
if(ANDROID)
set(CRASH_HANDLER OFF)
else()
option(CRASH_HANDLER "Generate crash reports" ON)
endif()
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_LTO "Use link time optimizations" OFF)
@@ -206,12 +210,7 @@ if(WIN32)
endif()
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_LIBS ${USE_STATIC_LIBS})
if(ANDROID)
else()
find_package(Boost 1.48.0 COMPONENTS ${REQUIRED_BOOST_COMPONENTS} REQUIRED)
endif()
find_package(Boost 1.48.0 COMPONENTS ${REQUIRED_BOOST_COMPONENTS} REQUIRED)
#find lua
if(LUAJIT)
@@ -230,11 +229,10 @@ message(STATUS "LuaJIT: " ${LUAJIT})
find_package(PhysFS REQUIRED)
find_package(OpenSSL REQUIRED)
# android already has zlib
if(NOT ANDROID)
find_package(ZLIB REQUIRED)
else()
set(framework_LIBRARIES ${framework_LIBRARIES} android)
set(framework_LIBRARIES ${framework_LIBRARIES} z android log)
endif()
set(framework_LIBRARIES ${framework_LIBRARIES}
@@ -292,7 +290,11 @@ else()
else()
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(SYSTEM_LIBRARIES dl rt)
if(ANDROID)
set(SYSTEM_LIBRARIES dl)
else()
set(SYSTEM_LIBRARIES dl rt)
endif()
endif()
endif()
set(framework_LIBRARIES ${framework_LIBRARIES} ${SYSTEM_LIBRARIES})
@@ -303,7 +305,7 @@ endif()
if(FRAMEWORK_GRAPHICS)
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)
find_package(OpenGLES2 REQUIRED)
find_package(EGL REQUIRED)
@@ -313,7 +315,7 @@ if(FRAMEWORK_GRAPHICS)
set(framework_LIBRARIES ${framework_LIBRARIES} GLESv2)
endif()
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)
find_package(OpenGLES1 REQUIRED)
find_package(EGL REQUIRED)
@@ -460,8 +462,8 @@ if(FRAMEWORK_GRAPHICS)
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.h
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.h
${CMAKE_CURRENT_LIST_DIR}/platform/sdlplatform.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/sdlplatform.h
${CMAKE_CURRENT_LIST_DIR}/platform/sdlwindow.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/sdlwindow.h
# window input
${CMAKE_CURRENT_LIST_DIR}/input/mouse.cpp

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -26,8 +26,8 @@
#include "win32window.h"
WIN32Window window;
#elif defined ANDROID
#include "sdlplatform.h"
SDLPlatform window;
#include "sdlwindow.h"
SDLWindow window;
#else
#include "x11window.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"
SDLWindow::SDLWindow() {
m_window = 0;
m_cursor = 0;
m_minimumSize = Size(600,480);
m_size = Size(600,480);
}
void SDLWindow::init() {
}
@@ -83,7 +90,7 @@ Size SDLWindow::getDisplaySize() {
}
std::string SDLWindow::getClipboardText() {
return nullptr;
return "";
}
std::string SDLWindow::getPlatformType() {

View File

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

View File

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

View File

@@ -20,39 +20,12 @@
* THE SOFTWARE.
*/
#include <framework/core/application.h>
#include <framework/core/resourcemanager.h>
#include <framework/luaengine/luainterface.h>
#include <client/client.h>
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;
}