Changes to compile on android

This commit is contained in:
Eduardo Bart 2013-03-07 04:50:45 -03:00
parent b3b849000d
commit e6ee88af43
17 changed files with 92 additions and 33 deletions

View File

@ -48,7 +48,7 @@ g_modules.ensureModuleLoaded("game_interface")
-- mods 1000-9999 -- mods 1000-9999
g_modules.autoLoadModules(9999) g_modules.autoLoadModules(9999)
local script = '/' .. g_app.getCompactName() .. 'rc' local script = '/' .. g_app.getCompactName() .. 'rc.lua'
if g_resources.fileExists(script) then if g_resources.fileExists(script) then
dofile(script) dofile(script)

View File

@ -1,5 +1,5 @@
local musicFilename = "/sounds/startup" local musicFilename = "/sounds/startup"
local musicChannel = g_sounds.getChannel(1) local musicChannel = nil
function setMusic(filename) function setMusic(filename)
musicFilename = filename musicFilename = filename
@ -57,11 +57,14 @@ function init()
onExit = exit }) onExit = exit })
g_window.setMinimumSize({ width = 600, height = 480 }) g_window.setMinimumSize({ width = 600, height = 480 })
musicChannel = g_sounds.getChannel(1)
g_sounds.preload(musicFilename) g_sounds.preload(musicFilename)
-- initialize in fullscreen mode on mobile devices -- 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.setFullscreen(true)
g_window.maximize()
else else
-- window size -- window size
local size = { width = 800, height = 600 } local size = { width = 800, height = 600 }

View File

@ -2,4 +2,3 @@
-- you can place any custom user code here -- you can place any custom user code here
print 'Startup done :]' print 'Startup done :]'

View File

@ -3,9 +3,9 @@
# SDL2_INCLUDE_DIR - the SDL2 include directory # SDL2_INCLUDE_DIR - the SDL2 include directory
# SDL2_LIBRARY - the SDL2 library # SDL2_LIBRARY - the SDL2 library
FIND_PATH(SDL2_INCLUDE_DIR NAMES SDL2/SDL.h) FIND_PATH(SDL2_INCLUDE_DIR PATH_SUFFIXES SDL2 SDL NAMES SDL.h)
SET(_SDL2_STATIC_LIBS libSDL2.a) SET(_SDL2_STATIC_LIBS libSDL2.a libSDL.a)
SET(_SDL2_SHARED_LIBS libSDL2.dll.a SDL2) SET(_SDL2_SHARED_LIBS libSDL2.dll.a SDL2 SDL libSDL.dll.a SDL)
IF(USE_STATIC_LIBS) IF(USE_STATIC_LIBS)
FIND_LIBRARY(SDL2_LIBRARY NAMES ${_SDL2_STATIC_LIBS} ${_SDL2_SHARED_LIBS}) FIND_LIBRARY(SDL2_LIBRARY NAMES ${_SDL2_STATIC_LIBS} ${_SDL2_SHARED_LIBS})
ELSE() ELSE()

View File

@ -33,6 +33,7 @@
#include <framework/platform/platform.h> #include <framework/platform/platform.h>
#include <locale> #include <locale>
#include <boost/concept_check.hpp>
#ifdef FW_NET #ifdef FW_NET
#include <framework/net/connection.h> #include <framework/net/connection.h>
@ -163,10 +164,14 @@ void Application::close()
std::string Application::getOs() std::string Application::getOs()
{ {
#if defined(WIN32) #if defined(ANDROID)
return "android";
#elif defined(IOS)
return "ios";
#elif defined(WIN32)
return "windows"; return "windows";
#elif defined(__APPLE__) #elif defined(__APPLE__)
return "mac"; return "macos";
#elif __linux #elif __linux
return "linux"; return "linux";
#else #else

View File

@ -24,6 +24,7 @@
#include "graphicalapplication.h" #include "graphicalapplication.h"
#include <framework/core/clock.h> #include <framework/core/clock.h>
#include <framework/core/eventdispatcher.h> #include <framework/core/eventdispatcher.h>
#include <framework/input/mouse.h>
#include <framework/platform/platformwindow.h> #include <framework/platform/platformwindow.h>
#include <framework/ui/uimanager.h> #include <framework/ui/uimanager.h>
#include <framework/graphics/graphics.h> #include <framework/graphics/graphics.h>

View File

@ -25,12 +25,17 @@
//#include <boost/regex.hpp> //#include <boost/regex.hpp>
#include <framework/core/resourcemanager.h> #include <framework/core/resourcemanager.h>
#include "application.h"
#ifdef FW_GRAPHICS #ifdef FW_GRAPHICS
#include <framework/platform/platformwindow.h> #include <framework/platform/platformwindow.h>
#include <framework/luaengine/luainterface.h> #include <framework/luaengine/luainterface.h>
#endif #endif
#ifdef MOBILE
#include <android/log.h>
#endif
Logger g_logger; Logger g_logger;
void Logger::log(Fw::LogLevel level, const std::string& message) 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 #endif
*/ */
#ifdef ANDROID
__android_log_print(ANDROID_LOG_INFO, g_app.getCompactName().c_str(), outmsg.c_str());
#else
std::cout << outmsg << std::endl; std::cout << outmsg << std::endl;
#endif
if(m_outFile.good()) { if(m_outFile.good()) {
m_outFile << outmsg << std::endl; m_outFile << outmsg << std::endl;

View File

@ -29,6 +29,10 @@
#include <physfs.h> #include <physfs.h>
#ifdef MOBILE
#include <SDL.h>
#endif
ResourceManager g_resources; ResourceManager g_resources;
void ResourceManager::init(const char *argv0) void ResourceManager::init(const char *argv0)
@ -45,10 +49,15 @@ void ResourceManager::terminate()
bool ResourceManager::discoverWorkDir(const std::string& existentFile) bool ResourceManager::discoverWorkDir(const std::string& existentFile)
{ {
// search for modules directory // 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() + "../", g_resources.getBaseDir() + "../",
g_resources.getBaseDir() + "../share/" + g_app.getCompactName() + "/" }; g_resources.getBaseDir() + "../share/" + g_app.getCompactName() + "/" };
#endif
bool found = false; bool found = false;
for(const std::string& dir : possiblePaths) { for(const std::string& dir : possiblePaths) {
@ -309,7 +318,11 @@ std::string ResourceManager::getBaseDir()
std::string ResourceManager::getUserDir() std::string ResourceManager::getUserDir()
{ {
#ifdef ANDROID
return std::string("/sdcard/");
#else
return PHYSFS_getUserDir(); return PHYSFS_getUserDir();
#endif
} }
std::string ResourceManager::guessFilePath(const std::string& filename, const std::string& type) std::string ResourceManager::guessFilePath(const std::string& filename, const std::string& type)

View File

@ -33,15 +33,15 @@
#include <fstream> #include <fstream>
#if defined(_MSC_VER) && _MSC_VER >= 1300 #if defined(_MSC_VER) && _MSC_VER >= 1300
#define swap16(data) _byteswap_ushort(data) #define lswap16(data) _byteswap_ushort(data)
#define swap32(data) _byteswap_ulong(data) #define lswap32(data) _byteswap_ulong(data)
#elif __linux__ #elif __linux__
#include <byteswap.h> #include <byteswap.h>
#define swap16(data) bswap_16(data) #define lswap16(data) bswap_16(data)
#define swap32(data) bswap_32(data) #define lswap32(data) bswap_32(data)
#else #else
#define swap16(data) (((data >> 8) & 255) | ((data & 255) << 8)) #define lswap16(data) (((data >> 8) & 255) | ((data & 255) << 8))
#define swap32(data) ((swap16(data) << 16) | swap16(data >> 16)) #define lswap32(data) ((swap16(data) << 16) | swap16(data >> 16))
#endif #endif
#define PNG_ZBUF_SIZE 32768 #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) 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 crc = crc32(0, Z_NULL, 0);
unsigned int len = swap32(length); unsigned int len = lswap32(length);
f.write((char*)&len, 4); f.write((char*)&len, 4);
f.write(name, 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 = crc32(crc, data, length);
} }
crc = swap32(crc); crc = lswap32(crc);
f.write((char*)&crc, 4); 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 mCompression;
unsigned char mFilterMethod; unsigned char mFilterMethod;
unsigned char mInterlaceMethod; 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 zstream1;
z_stream zstream2; z_stream zstream2;

View File

@ -33,13 +33,13 @@ public:
std::string getName() { return m_name; } std::string getName() { return m_name; }
virtual void create() = 0; virtual void create() {}
virtual void destroy() = 0; virtual void destroy() {}
virtual void restore() = 0; virtual void restore() {}
virtual void swapBuffers() = 0; virtual void swapBuffers() {}
virtual void setVerticalSync(bool enable) = 0; virtual void setVerticalSync(bool enable) {}
protected: protected:
std::string m_name; std::string m_name;

View File

@ -34,7 +34,9 @@
PainterOGL::PainterOGL() PainterOGL::PainterOGL()
{ {
#ifdef OPENGL_ES #ifdef SDL
m_graphicsContext = GraphicsContextPtr(new GraphicsContext("null"));
#elif OPENGL_ES
m_graphicsContext = GraphicsContextPtr(new GraphicsContextEGL); m_graphicsContext = GraphicsContextPtr(new GraphicsContextEGL);
#elif WIN32 #elif WIN32
m_graphicsContext = GraphicsContextPtr(new GraphicsContextWGL); m_graphicsContext = GraphicsContextPtr(new GraphicsContextWGL);

View File

@ -20,6 +20,9 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifndef MOUSE_H
#define MOUSE_H
#include <framework/global.h> #include <framework/global.h>
class Mouse class Mouse
@ -43,3 +46,5 @@ private:
}; };
extern Mouse g_mouse; extern Mouse g_mouse;
#endif

View File

@ -36,14 +36,34 @@ void SDLWindow::init()
{ {
SDL_Init(SDL_INIT_VIDEO); 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(), m_window = SDL_CreateWindow(g_app.getName().c_str(),
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
m_size.width(), m_size.height(), m_size.width(), m_size.height(),
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN); flags);
if(!m_window) if(!m_window)
g_logger.fatal("Unable to create SDL 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); m_context = SDL_GL_CreateContext(m_window);
if(!m_context) if(!m_context)
g_logger.fatal("Unable to create SDL GL 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); m_position = Point(event.window.data1, event.window.data2);
break; break;
case SDL_WINDOWEVENT_RESIZED: 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); m_size = Size(event.window.data1, event.window.data2);
if(m_onResize) if(m_onResize)
m_onResize(m_size); m_onResize(m_size);
@ -147,6 +168,7 @@ void SDLWindow::poll()
case SDL_QUIT: case SDL_QUIT:
if(m_onClose) if(m_onClose)
m_onClose(); m_onClose();
break;
} }
} }

View File

@ -24,7 +24,7 @@
#define SDLWINDOW_H #define SDLWINDOW_H
#include "platformwindow.h" #include "platformwindow.h"
#include <SDL2/SDL.h> #include <SDL.h>
#include <framework/graphics/glutil.h> #include <framework/graphics/glutil.h>
class SDLWindow : public PlatformWindow class SDLWindow : public PlatformWindow

View File

@ -36,7 +36,7 @@ void Platform::processArgs(std::vector<std::string>& args)
bool Platform::spawnProcess(std::string process, const std::vector<std::string>& args) bool Platform::spawnProcess(std::string process, const std::vector<std::string>& args)
{ {
struct stat sts; struct stat sts;
if(stat(process.c_str(), &sts) == -1 && errno == ENOENT) if(stat(process.c_str(), &sts) == -1)
return false; return false;
pid_t pid = fork(); pid_t pid = fork();

View File

@ -33,8 +33,4 @@
#error "Compiler not supported." #error "Compiler not supported."
#endif #endif
#if !defined(__GXX_EXPERIMENTAL_CXX0X__)
#error "Sorry, you must enable C++0x to compile."
#endif
#endif #endif

View File

@ -25,7 +25,11 @@
#include <framework/luaengine/luainterface.h> #include <framework/luaengine/luainterface.h>
#include <client/client.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); std::vector<std::string> args(argv, argv + argc);