diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-10-29 23:36:53 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-10-29 23:39:29 +0300 |
commit | 7f2484d82112851dbeba83afd18790a58b03599d (patch) | |
tree | 6449022bbae8a55825febc7b08e3d4095f1de64f | |
parent | 24179041d619875bda96eb94307b1f3dd64e6add (diff) | |
download | manaplus-7f2484d82112851dbeba83afd18790a58b03599d.tar.gz manaplus-7f2484d82112851dbeba83afd18790a58b03599d.tar.bz2 manaplus-7f2484d82112851dbeba83afd18790a58b03599d.tar.xz manaplus-7f2484d82112851dbeba83afd18790a58b03599d.zip |
Initial porting to NACL by Vasily_Makarov.
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/client.cpp | 22 | ||||
-rw-r--r-- | src/gui/palette.h | 5 | ||||
-rw-r--r-- | src/main.cpp | 17 | ||||
-rw-r--r-- | src/net/nacltcpnet.cpp | 116 | ||||
-rw-r--r-- | src/net/nacltcpnet.h | 71 | ||||
-rw-r--r-- | src/net/sdltcpnet.cpp | 4 | ||||
-rw-r--r-- | src/net/sdltcpnet.h | 3 | ||||
-rw-r--r-- | src/resources/imagewriter.cpp | 1 | ||||
-rw-r--r-- | src/utils/files.cpp | 6 | ||||
-rw-r--r-- | src/utils/files.h | 7 | ||||
-rw-r--r-- | src/utils/gettext.h | 4 | ||||
-rw-r--r-- | src/utils/mkdir.cpp | 3 | ||||
-rw-r--r-- | src/utils/paths.cpp | 9 |
15 files changed, 263 insertions, 9 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 254704a88..6bada3941 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -418,6 +418,8 @@ SET(SRCS net/messageout.cpp net/messageout.h net/npchandler.h + net/nacltcpnet.cpp + net/nacltcpnet.h net/net.cpp net/net.h net/partyhandler.h diff --git a/src/Makefile.am b/src/Makefile.am index 9f07e72f7..ebce034ea 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -428,6 +428,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ net/messagein.h \ net/messageout.cpp \ net/messageout.h \ + net/nacltcpnet.cpp \ + net/nacltcpnet.h \ net/net.cpp \ net/net.h \ net/npchandler.h \ diff --git a/src/client.cpp b/src/client.cpp index 8f1110162..24ed15987 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -140,12 +140,17 @@ #include <sys/stat.h> #include <climits> +#include <errno.h> #include <fstream> #include "mumblemanager.h" #include "debug.h" +#if defined __native_client__ +#define _nacl_dir std::string("/persistent/manaplus") +#endif + /** * Tells the max tick value, * setting it back to zero (and start again). @@ -400,6 +405,12 @@ void Client::gameInit() #endif #endif +#if defined __native_client__ + + const std::string dirName = _nacl_dir.append("/data"); + Files::extractZip("/http/data.zip", "data", dirName); +#endif + #ifdef ENABLE_NLS std::string lang = config.getStringValue("lang"); #ifdef WIN32 @@ -551,6 +562,11 @@ void Client::gameInit() } #endif #endif + +#if defined __native_client__ + resman->addToSearchPath(_nacl_dir.append("/data"), false); +#endif + // Add branding/data to PhysFS search path if (!mOptions.brandingPath.empty()) { @@ -756,11 +772,13 @@ Client::~Client() void Client::bindTextDomain(const char *const name, const char *const path) { +#ifdef ENABLE_NLS const char *const dir = bindtextdomain(name, path); if (dir) logger->log("bindtextdomain: %s", dir); else logger->log("bindtextdomain failed"); +#endif } void Client::setEnv(const char *const name, const char *const value) @@ -1944,6 +1962,8 @@ void Client::initLocalDataDir() #elif defined __ANDROID__ mLocalDataDir = getSdStoragePath() + branding.getValue( "appShort", "ManaPlus") + "/local"; +#elif defined __native_client__ + mLocalDataDir = _nacl_dir.append("/local"); #else mLocalDataDir = std::string(PhysFs::getUserDir()) + ".local/share/mana"; @@ -2001,6 +2021,8 @@ void Client::initConfigDir() #elif defined __ANDROID__ mConfigDir = getSdStoragePath() + branding.getValue( "appShort", "ManaPlus").append("/config"); +#elif defined __native_client__ + mConfigDir = _nacl_dir.append("/config"); #else mConfigDir = std::string(PhysFs::getUserDir()).append( "/.config/mana/").append(branding.getValue("appShort", "mana")); diff --git a/src/gui/palette.h b/src/gui/palette.h index f9980291f..fdde01737 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -28,7 +28,12 @@ #include <guichan/color.hpp> +#if defined __native_client__ +#include <stdlib.h> +#else #include <cstdlib> +#endif + #include <map> #include <string> #include <set> diff --git a/src/main.cpp b/src/main.cpp index 193610156..f9ee5d5d7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,6 +48,10 @@ #include <windows.h> #endif +#ifdef __native_client__ +#include <sys/mount.h> +#endif + #include <SDL_image.h> #include <SDL_mixer.h> #include <SDL_version.h> @@ -274,6 +278,15 @@ int main(int argc, char *argv[]) LoadLibrary("exchndl.dll"); #endif +#if defined __native_client__ + // for now for debug hardcoded path + umount("/"); + mount("", "/", "memfs", 0, ""); + mount("", "/persistent", "html5fs", 0, + "type=PERSISTENT,expected_size=104857600"); + mount("http://localhost:5103/my/manaplus", "/http", "httpfs", 0, ""); +#endif + selfName = argv[0]; // Parse command line options @@ -292,7 +305,9 @@ int main(int argc, char *argv[]) } // Initialize PhysicsFS -#ifdef ANDROID +#if defined(__native_client__) + if (!PHYSFS_init("/fakebinary")) +#elif defined(ANDROID) mkdir_r(getSdStoragePath().c_str()); if (!PHYSFS_init((getRealPath(".").append("/fakebinary")).c_str())) diff --git a/src/net/nacltcpnet.cpp b/src/net/nacltcpnet.cpp new file mode 100644 index 000000000..ccdb5a3f6 --- /dev/null +++ b/src/net/nacltcpnet.cpp @@ -0,0 +1,116 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#if defined __native_client__ + +#include "net/sdltcpnet.h" + +#if defined __linux__ || defined __linux +#include "logger.h" + +#include <sys/socket.h> + +#if defined(M_TCPOK) && !defined(ANDROID) +#include <netinet/in.h> +#include <netdb.h> +#include <linux/tcp.h> +#else +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <netdb.h> +#include <netinet/tcp.h> +// Use linear timeouts for thin streams +#define TCP_THIN_LINEAR_TIMEOUTS 16 +// Fast retrans. after 1 dupack +#define TCP_THIN_DUPACK 17 +#endif + +#endif + +#include "debug.h" + +struct _SDLNet_SocketSet +{ +}; + +struct _TCPsocket +{ + int ready; + int channel; + IPaddress remoteAddress; + IPaddress localAddress; + int sflag; +}; + +void TcpNet::init() +{ +} + +void TcpNet::quit() +{ +} + +void TcpNet::closeSocket(const TcpNet::Socket socket) +{ +} + +int TcpNet::send(const TcpNet::Socket sock, const void *const data, + const int len) +{ +} + +const char *TcpNet::getError() +{ +} + +int TcpNet::resolveHost(IPaddress *const address, const char *const host, + const Uint16 port) +{ +} + +TcpNet::Socket TcpNet::open(IPaddress *const ip) +{ +} + +TcpNet::SocketSet TcpNet::allocSocketSet(const int maxsockets) +{ +} + +int TcpNet::addSocket(const TcpNet::SocketSet set, const TcpNet::Socket sock) +{ +} + +int TcpNet::checkSockets(const TcpNet::SocketSet set, const Uint32 timeout) +{ +} + +int TcpNet::recv(const TcpNet::Socket sock, void *const data, const int maxlen) +{ +} + +int TcpNet::delSocket(const TcpNet::SocketSet set, const TcpNet::Socket sock) +{ +} + +void TcpNet::freeSocketSet(const TcpNet::SocketSet set) +{ +} + +#endif // __native_client__ diff --git a/src/net/nacltcpnet.h b/src/net/nacltcpnet.h new file mode 100644 index 000000000..770384e7e --- /dev/null +++ b/src/net/nacltcpnet.h @@ -0,0 +1,71 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef NET_NACLTCPNET_H +#define NET_NACLTCPNET_H + +#if defined __native_client__ + +#include <SDL.h> +#include "localconsts.h" + +typedef struct { + Uint32 host; /* 32-bit IPv4 host address */ + Uint16 port; /* 16-bit protocol port */ +} IPaddress; + +typedef struct _SDLNet_SocketSet *SDLNet_SocketSet; +typedef struct _TCPsocket *TCPsocket; + +namespace TcpNet +{ + typedef ::SDLNet_SocketSet SocketSet; + typedef ::TCPsocket Socket; + + void init(); + + void quit(); + + void closeSocket(const TcpNet::Socket socket); + + int send(const TcpNet::Socket sock, const void *const data, const int len); + + const char *getError(); + + int resolveHost(IPaddress *const address, const char *const host, + const Uint16 port); + + TcpNet::Socket open(IPaddress *const ip); + + SocketSet allocSocketSet(const int maxsockets); + + int addSocket(const TcpNet::SocketSet set, const TcpNet::Socket sock); + + int checkSockets(const TcpNet::SocketSet set, const Uint32 timeout); + + int recv(const TcpNet::Socket sock, void *const data, const int maxlen); + + int delSocket(const TcpNet::SocketSet set, const TcpNet::Socket sock); + + void freeSocketSet(const TcpNet::SocketSet set); +} // namespace TcpNet + +#endif // __native_client__ +#endif // NET_NACLTCPNET_H diff --git a/src/net/sdltcpnet.cpp b/src/net/sdltcpnet.cpp index 4ea659ecf..4d708ea68 100644 --- a/src/net/sdltcpnet.cpp +++ b/src/net/sdltcpnet.cpp @@ -18,6 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#if !defined __native_client__ + #include "net/sdltcpnet.h" #if defined __linux__ || defined __linux @@ -150,3 +152,5 @@ void TcpNet::freeSocketSet(const TcpNet::SocketSet set) { SDLNet_FreeSocketSet(set); } + +#endif // __native_client__ diff --git a/src/net/sdltcpnet.h b/src/net/sdltcpnet.h index a61c218b8..04c80e71a 100644 --- a/src/net/sdltcpnet.h +++ b/src/net/sdltcpnet.h @@ -21,6 +21,8 @@ #ifndef NET_SDLTCPNET_H #define NET_SDLTCPNET_H +#if !defined __native_client__ + #include <SDL_net.h> #include "localconsts.h" @@ -58,4 +60,5 @@ namespace TcpNet void freeSocketSet(const TcpNet::SocketSet set); } // namespace TcpNet +#endif // __native_client__ #endif // NET_SDLTCPNET_H diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index 1db9f139d..3e1eeead5 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -24,6 +24,7 @@ #include "logger.h" +#include <stdlib.h> #include <png.h> #include <SDL_video.h> #include <string> diff --git a/src/utils/files.cpp b/src/utils/files.cpp index f4c93e6e6..c06b3d892 100644 --- a/src/utils/files.cpp +++ b/src/utils/files.cpp @@ -18,7 +18,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifdef ANDROID +#if defined(ANDROID) || defined(__native_client__) #include "utils/files.h" #include "logger.h" @@ -30,6 +30,7 @@ #include "localconsts.h" +#ifdef ANDROID void Files::extractLocale() { // in future need also remove all locales in local dir @@ -60,6 +61,7 @@ void Files::extractLocale() resman->removeFromSearchPath(fileName2); remove(fileName2.c_str()); } +#endif // ANDROID void Files::copyPhysFsFile(const std::string &inFile, const std::string &outFile) @@ -98,4 +100,4 @@ void Files::extractZip(const std::string &zipName, const std::string &inDir, remove(zipName.c_str()); } -#endif // ANDROID +#endif // ANDROID __native_client__ diff --git a/src/utils/files.h b/src/utils/files.h index bb9a6a11f..519b7f520 100644 --- a/src/utils/files.h +++ b/src/utils/files.h @@ -21,13 +21,14 @@ #ifndef UTILS_FILES_H #define UTILS_FILES_H -#ifdef ANDROID +#if defined(ANDROID) || defined(__native_client__) #include <string> namespace Files { +#ifdef ANDROID void extractLocale(); - +#endif void copyPhysFsFile(const std::string &inFile, const std::string &outFile); void copyPhysFsDir(const std::string &inDir, const std::string &outDir); @@ -36,5 +37,5 @@ namespace Files const std::string &outDir); } // namespace Files -#endif // ANDROID +#endif // ANDROID __native_client__ #endif // UTILS_FILES_H diff --git a/src/utils/gettext.h b/src/utils/gettext.h index ed686cffd..a00e44898 100644 --- a/src/utils/gettext.h +++ b/src/utils/gettext.h @@ -27,10 +27,10 @@ #include "config.h" #endif -#include <libintl.h> - #ifdef ENABLE_NLS +#include <libintl.h> + #define _(s) (const_cast <char*>(gettext(s))) #define N_(s) (const_cast <char*>(s)) diff --git a/src/utils/mkdir.cpp b/src/utils/mkdir.cpp index fc6909710..959b15b04 100644 --- a/src/utils/mkdir.cpp +++ b/src/utils/mkdir.cpp @@ -36,6 +36,8 @@ #include <cstdlib> #endif +#include <errno.h> + #include "debug.h" #if defined WIN32 @@ -112,6 +114,7 @@ int mkdir_r(const char *const pathname) return 0; } #else + /// Create a directory, making leading components first if necessary int mkdir_r(const char *const pathname) { diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index e3992cd72..dbe0cccce 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -30,11 +30,18 @@ #include "resources/resourcemanager.h" +#ifdef __native_client__ +#include <limits.h> +#define realpath(N, R) strcpy(R, N) +#endif + #ifdef WIN32 #include "utils/specialfolder.h" #define realpath(N, R) _fullpath((R), (N), _MAX_PATH) #elif defined __OpenBSD__ #include <limits> +#elif defined __native_client__ +#include <limits.h> #endif #ifdef ANDROID @@ -47,7 +54,7 @@ std::string getRealPath(const std::string &str) { -#if defined(__OpenBSD__) || defined(__ANDROID__) +#if defined(__OpenBSD__) || defined(__ANDROID__) || defined(__native_client__) char *realPath = reinterpret_cast<char*>(calloc(PATH_MAX, sizeof(char))); realpath(str.c_str(), realPath); #else |