mirror of
https://github.com/edubart/otclient.git
synced 2025-06-07 19:34:29 +02:00
Changes to compile on android
This commit is contained in:
parent
b3b849000d
commit
e6ee88af43
2
init.lua
2
init.lua
@ -48,7 +48,7 @@ g_modules.ensureModuleLoaded("game_interface")
|
||||
-- mods 1000-9999
|
||||
g_modules.autoLoadModules(9999)
|
||||
|
||||
local script = '/' .. g_app.getCompactName() .. 'rc'
|
||||
local script = '/' .. g_app.getCompactName() .. 'rc.lua'
|
||||
|
||||
if g_resources.fileExists(script) then
|
||||
dofile(script)
|
||||
|
@ -1,5 +1,5 @@
|
||||
local musicFilename = "/sounds/startup"
|
||||
local musicChannel = g_sounds.getChannel(1)
|
||||
local musicChannel = nil
|
||||
|
||||
function setMusic(filename)
|
||||
musicFilename = filename
|
||||
@ -57,11 +57,14 @@ function init()
|
||||
onExit = exit })
|
||||
|
||||
g_window.setMinimumSize({ width = 600, height = 480 })
|
||||
|
||||
musicChannel = g_sounds.getChannel(1)
|
||||
g_sounds.preload(musicFilename)
|
||||
|
||||
-- initialize in fullscreen mode on mobile devices
|
||||
if g_window.getPlatformType() == "X11-EGL" then
|
||||
if g_app.getOs() == "android" then
|
||||
g_window.setFullscreen(true)
|
||||
g_window.maximize()
|
||||
else
|
||||
-- window size
|
||||
local size = { width = 800, height = 600 }
|
||||
|
@ -2,4 +2,3 @@
|
||||
-- you can place any custom user code here
|
||||
|
||||
print 'Startup done :]'
|
||||
|
||||
|
@ -3,9 +3,9 @@
|
||||
# SDL2_INCLUDE_DIR - the SDL2 include directory
|
||||
# SDL2_LIBRARY - the SDL2 library
|
||||
|
||||
FIND_PATH(SDL2_INCLUDE_DIR NAMES SDL2/SDL.h)
|
||||
SET(_SDL2_STATIC_LIBS libSDL2.a)
|
||||
SET(_SDL2_SHARED_LIBS libSDL2.dll.a SDL2)
|
||||
FIND_PATH(SDL2_INCLUDE_DIR PATH_SUFFIXES SDL2 SDL NAMES SDL.h)
|
||||
SET(_SDL2_STATIC_LIBS libSDL2.a libSDL.a)
|
||||
SET(_SDL2_SHARED_LIBS libSDL2.dll.a SDL2 SDL libSDL.dll.a SDL)
|
||||
IF(USE_STATIC_LIBS)
|
||||
FIND_LIBRARY(SDL2_LIBRARY NAMES ${_SDL2_STATIC_LIBS} ${_SDL2_SHARED_LIBS})
|
||||
ELSE()
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <framework/platform/platform.h>
|
||||
|
||||
#include <locale>
|
||||
#include <boost/concept_check.hpp>
|
||||
|
||||
#ifdef FW_NET
|
||||
#include <framework/net/connection.h>
|
||||
@ -163,10 +164,14 @@ void Application::close()
|
||||
|
||||
std::string Application::getOs()
|
||||
{
|
||||
#if defined(WIN32)
|
||||
#if defined(ANDROID)
|
||||
return "android";
|
||||
#elif defined(IOS)
|
||||
return "ios";
|
||||
#elif defined(WIN32)
|
||||
return "windows";
|
||||
#elif defined(__APPLE__)
|
||||
return "mac";
|
||||
return "macos";
|
||||
#elif __linux
|
||||
return "linux";
|
||||
#else
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "graphicalapplication.h"
|
||||
#include <framework/core/clock.h>
|
||||
#include <framework/core/eventdispatcher.h>
|
||||
#include <framework/input/mouse.h>
|
||||
#include <framework/platform/platformwindow.h>
|
||||
#include <framework/ui/uimanager.h>
|
||||
#include <framework/graphics/graphics.h>
|
||||
|
@ -25,12 +25,17 @@
|
||||
|
||||
//#include <boost/regex.hpp>
|
||||
#include <framework/core/resourcemanager.h>
|
||||
#include "application.h"
|
||||
|
||||
#ifdef FW_GRAPHICS
|
||||
#include <framework/platform/platformwindow.h>
|
||||
#include <framework/luaengine/luainterface.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOBILE
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
Logger g_logger;
|
||||
|
||||
void Logger::log(Fw::LogLevel level, const std::string& message)
|
||||
@ -66,7 +71,11 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifdef ANDROID
|
||||
__android_log_print(ANDROID_LOG_INFO, g_app.getCompactName().c_str(), outmsg.c_str());
|
||||
#else
|
||||
std::cout << outmsg << std::endl;
|
||||
#endif
|
||||
|
||||
if(m_outFile.good()) {
|
||||
m_outFile << outmsg << std::endl;
|
||||
|
@ -29,6 +29,10 @@
|
||||
|
||||
#include <physfs.h>
|
||||
|
||||
#ifdef MOBILE
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
|
||||
ResourceManager g_resources;
|
||||
|
||||
void ResourceManager::init(const char *argv0)
|
||||
@ -45,10 +49,15 @@ void ResourceManager::terminate()
|
||||
bool ResourceManager::discoverWorkDir(const std::string& existentFile)
|
||||
{
|
||||
// search for modules directory
|
||||
std::string possiblePaths[] = { g_platform.getCurrentDir(),
|
||||
#ifdef ANDROID
|
||||
std::string possiblePaths[] = { std::string("/sdcard/") + g_app.getCompactName() + "/" };
|
||||
#else
|
||||
std::string possiblePaths[] = { "./",
|
||||
g_platform.getCurrentDir(),
|
||||
g_resources.getBaseDir(),
|
||||
g_resources.getBaseDir() + "../",
|
||||
g_resources.getBaseDir() + "../share/" + g_app.getCompactName() + "/" };
|
||||
#endif
|
||||
|
||||
bool found = false;
|
||||
for(const std::string& dir : possiblePaths) {
|
||||
@ -309,7 +318,11 @@ std::string ResourceManager::getBaseDir()
|
||||
|
||||
std::string ResourceManager::getUserDir()
|
||||
{
|
||||
#ifdef ANDROID
|
||||
return std::string("/sdcard/");
|
||||
#else
|
||||
return PHYSFS_getUserDir();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string ResourceManager::guessFilePath(const std::string& filename, const std::string& type)
|
||||
|
@ -33,15 +33,15 @@
|
||||
#include <fstream>
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1300
|
||||
#define swap16(data) _byteswap_ushort(data)
|
||||
#define swap32(data) _byteswap_ulong(data)
|
||||
#define lswap16(data) _byteswap_ushort(data)
|
||||
#define lswap32(data) _byteswap_ulong(data)
|
||||
#elif __linux__
|
||||
#include <byteswap.h>
|
||||
#define swap16(data) bswap_16(data)
|
||||
#define swap32(data) bswap_32(data)
|
||||
#define lswap16(data) bswap_16(data)
|
||||
#define lswap32(data) bswap_32(data)
|
||||
#else
|
||||
#define swap16(data) (((data >> 8) & 255) | ((data & 255) << 8))
|
||||
#define swap32(data) ((swap16(data) << 16) | swap16(data >> 16))
|
||||
#define lswap16(data) (((data >> 8) & 255) | ((data & 255) << 8))
|
||||
#define lswap32(data) ((swap16(data) << 16) | swap16(data >> 16))
|
||||
#endif
|
||||
|
||||
#define PNG_ZBUF_SIZE 32768
|
||||
@ -865,7 +865,7 @@ int load_apng(std::stringstream& file, struct apng_data *apng)
|
||||
void write_chunk(std::ostream& f, const char* name, unsigned char* data, unsigned int length)
|
||||
{
|
||||
unsigned int crc = crc32(0, Z_NULL, 0);
|
||||
unsigned int len = swap32(length);
|
||||
unsigned int len = lswap32(length);
|
||||
|
||||
f.write((char*)&len, 4);
|
||||
f.write(name, 4);
|
||||
@ -876,7 +876,7 @@ void write_chunk(std::ostream& f, const char* name, unsigned char* data, unsigne
|
||||
crc = crc32(crc, data, length);
|
||||
}
|
||||
|
||||
crc = swap32(crc);
|
||||
crc = lswap32(crc);
|
||||
f.write((char*)&crc, 4);
|
||||
}
|
||||
|
||||
@ -937,7 +937,7 @@ void save_png(std::stringstream& f, unsigned int width, unsigned int height, int
|
||||
unsigned char mCompression;
|
||||
unsigned char mFilterMethod;
|
||||
unsigned char mInterlaceMethod;
|
||||
} ihdr = { swap32(width), swap32(height), 8, coltype, 0, 0, 0 };
|
||||
} ihdr = { lswap32(width), lswap32(height), 8, coltype, 0, 0, 0 };
|
||||
|
||||
z_stream zstream1;
|
||||
z_stream zstream2;
|
||||
|
@ -33,13 +33,13 @@ public:
|
||||
|
||||
std::string getName() { return m_name; }
|
||||
|
||||
virtual void create() = 0;
|
||||
virtual void destroy() = 0;
|
||||
virtual void restore() = 0;
|
||||
virtual void create() {}
|
||||
virtual void destroy() {}
|
||||
virtual void restore() {}
|
||||
|
||||
virtual void swapBuffers() = 0;
|
||||
virtual void swapBuffers() {}
|
||||
|
||||
virtual void setVerticalSync(bool enable) = 0;
|
||||
virtual void setVerticalSync(bool enable) {}
|
||||
|
||||
protected:
|
||||
std::string m_name;
|
||||
|
@ -34,7 +34,9 @@
|
||||
|
||||
PainterOGL::PainterOGL()
|
||||
{
|
||||
#ifdef OPENGL_ES
|
||||
#ifdef SDL
|
||||
m_graphicsContext = GraphicsContextPtr(new GraphicsContext("null"));
|
||||
#elif OPENGL_ES
|
||||
m_graphicsContext = GraphicsContextPtr(new GraphicsContextEGL);
|
||||
#elif WIN32
|
||||
m_graphicsContext = GraphicsContextPtr(new GraphicsContextWGL);
|
||||
|
@ -20,6 +20,9 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MOUSE_H
|
||||
#define MOUSE_H
|
||||
|
||||
#include <framework/global.h>
|
||||
|
||||
class Mouse
|
||||
@ -43,3 +46,5 @@ private:
|
||||
};
|
||||
|
||||
extern Mouse g_mouse;
|
||||
|
||||
#endif
|
||||
|
@ -36,14 +36,34 @@ void SDLWindow::init()
|
||||
{
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 4);
|
||||
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 4);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
|
||||
|
||||
#ifdef OPENGL_ES
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, OPENGL_ES);
|
||||
#endif
|
||||
|
||||
#ifdef MOBILE
|
||||
int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_SHOWN;
|
||||
#else
|
||||
int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
|
||||
#endif
|
||||
|
||||
m_window = SDL_CreateWindow(g_app.getName().c_str(),
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
m_size.width(), m_size.height(),
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN);
|
||||
flags);
|
||||
|
||||
if(!m_window)
|
||||
g_logger.fatal("Unable to create SDL window");
|
||||
|
||||
int w, h;
|
||||
SDL_GetWindowSize(m_window, &w, &h);
|
||||
m_size = Size(w,h);
|
||||
|
||||
m_context = SDL_GL_CreateContext(m_window);
|
||||
if(!m_context)
|
||||
g_logger.fatal("Unable to create SDL GL context");
|
||||
@ -108,6 +128,7 @@ void SDLWindow::poll()
|
||||
m_position = Point(event.window.data1, event.window.data2);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
g_logger.info(stdext::format("resize %d %d", event.window.data1, event.window.data2));
|
||||
m_size = Size(event.window.data1, event.window.data2);
|
||||
if(m_onResize)
|
||||
m_onResize(m_size);
|
||||
@ -147,6 +168,7 @@ void SDLWindow::poll()
|
||||
case SDL_QUIT:
|
||||
if(m_onClose)
|
||||
m_onClose();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#define SDLWINDOW_H
|
||||
|
||||
#include "platformwindow.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL.h>
|
||||
#include <framework/graphics/glutil.h>
|
||||
|
||||
class SDLWindow : public PlatformWindow
|
||||
|
@ -36,7 +36,7 @@ void Platform::processArgs(std::vector<std::string>& args)
|
||||
bool Platform::spawnProcess(std::string process, const std::vector<std::string>& args)
|
||||
{
|
||||
struct stat sts;
|
||||
if(stat(process.c_str(), &sts) == -1 && errno == ENOENT)
|
||||
if(stat(process.c_str(), &sts) == -1)
|
||||
return false;
|
||||
|
||||
pid_t pid = fork();
|
||||
|
@ -33,8 +33,4 @@
|
||||
#error "Compiler not supported."
|
||||
#endif
|
||||
|
||||
#if !defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
#error "Sorry, you must enable C++0x to compile."
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -25,7 +25,11 @@
|
||||
#include <framework/luaengine/luainterface.h>
|
||||
#include <client/client.h>
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
#ifdef SDL
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> args(argv, argv + argc);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user