diff options
author | cpasjuste <cpasjuste@gmail.com> | 2020-04-22 15:24:08 +0200 |
---|---|---|
committer | cpasjuste <cpasjuste@gmail.com> | 2020-04-22 15:24:08 +0200 |
commit | f43e3aa48aeb561f5c7e85f1b7121aab6a61decd (patch) | |
tree | 1c23a1e1db2676c27a99b6385f0580442b29f7a0 | |
parent | b0c696eaab501391512b08826c3c9a52023e2be7 (diff) | |
download | plus-f43e3aa48aeb561f5c7e85f1b7121aab6a61decd.tar.gz plus-f43e3aa48aeb561f5c7e85f1b7121aab6a61decd.tar.bz2 plus-f43e3aa48aeb561f5c7e85f1b7121aab6a61decd.tar.xz plus-f43e3aa48aeb561f5c7e85f1b7121aab6a61decd.zip |
switch: first commit
-rw-r--r-- | .gitignore | 9 | ||||
-rw-r--r-- | CMakeLists.txt.switch | 93 | ||||
-rw-r--r-- | src/fs/paths.cpp | 10 | ||||
-rw-r--r-- | src/logger.cpp | 4 | ||||
-rw-r--r-- | src/maingui.cpp | 30 | ||||
-rw-r--r-- | src/progs/manaplus/client.cpp | 2 | ||||
-rw-r--r-- | src/render/renderers.cpp | 3 | ||||
-rw-r--r-- | src/render/rendererslistsdl2.h | 33 |
8 files changed, 180 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore index 2f38535ba..b38337d15 100644 --- a/.gitignore +++ b/.gitignore @@ -161,3 +161,12 @@ gmon.out #english po /po/en.po + +# CLion ide +.idea +cmake-build-* + +# Nintendo Switch port +src/manaplus.nacp +src/manaplus.nro +src/resources/image/image.h.gch diff --git a/CMakeLists.txt.switch b/CMakeLists.txt.switch new file mode 100644 index 000000000..12f2d5c3f --- /dev/null +++ b/CMakeLists.txt.switch @@ -0,0 +1,93 @@ +cmake_minimum_required(VERSION 3.0) +set(CMAKE_VERBOSE_MAKEFILE ON) + +set(CMAKE_SYSTEM_NAME "Generic") + +set(DEVKITPRO $ENV{DEVKITPRO}) +set(CMAKE_SYSTEM_PROCESSOR "armv8-a") +set(CMAKE_C_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc") +set(CMAKE_CXX_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-g++") +set(CMAKE_ASM_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-as") +set(CMAKE_AR "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc-ar" CACHE STRING "") +set(CMAKE_RANLIB "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc-ranlib" CACHE STRING "") +set(CMAKE_C_FLAGS "-g -march=armv8-a -mtune=cortex-a57 -mtp=soft -ftls-model=local-exec -fPIC -I${DEVKITPRO}/libnx/include -I${DEVKITPRO}/portlibs/switch/include" CACHE STRING "C flags") +set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "C++ flags") #-fno-rtti -fno-exceptions +set(CMAKE_FIND_ROOT_PATH ${DEVKITPRO} ${DEVKITPRO}/devkitA64 ${DEVKITPRO}/libnx ${DEVKITPRO}/portlibs/switch) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) +set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Shared libs not available") + +project(ManaPlus) + +file(GLOB SOURCES src/*.cpp) +set(SOURCES_DIRS + src/being + src/enums/being + src/fs + src/gui + src/input + src/listeners + src/net + src/particle + src/progs/manaplus + src/render + src/resources + src/sdl2gfx + src/test + src/utils + ) + +foreach (DIR ${SOURCES_DIRS}) + file(GLOB_RECURSE FILES ${DIR}/*.cpp) + list(APPEND SOURCES ${FILES}) +endforeach (DIR) + +set(INCLUDES + ${DEVKITPRO}/portlibs/switch/include/SDL2 + ${DEVKITPRO}/portlibs/switch/include/libxml2 + src src/sdl2gfx + ) + +set(FLAGS -DPACKAGE_NAME=\"ManaPlus\" -DPACKAGE_TARNAME=\"manaplus\" -DPACKAGE_VERSION=\"1.9.3.23\" + -DPACKAGE_STRING=\"ManaPlus\ 1.9.3.23\" -DPACKAGE_BUGREPORT=\"akaras@inbox.ru\" -DPACKAGE_URL=\"\" + -DPACKAGE=\"manaplus\" -DVERSION=\"1.9.3.23\" -DTIME_WITH_SYS_TIME=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 + -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 + -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SYS_SELECT_H=1 -DHAVE_SYS_SOCKET_H=1 + -DSELECT_TYPE_ARG1=int -DSELECT_TYPE_ARG234=\(fd_set\ \\*\) -DSELECT_TYPE_ARG5=\(struct\ timeval\ \\*\) + -DHAVE_VPRINTF=1 -DHAVE_FORK=1 -Dvfork=fork -DHAVE_WORKING_FORK=1 -DHAVE_STDLIB_H=1 -DHAVE_UNISTD_H=1 + -DHAVE_SYS_PARAM_H=1 -DHAVE_ATEXIT=1 -DHAVE_FLOOR=1 -DHAVE_GETCWD=1 -DHAVE_GETHOSTBYNAME=1 -DHAVE_MEMSET=1 + -DHAVE_MKDIR=1 -DHAVE_SELECT=1 -DHAVE_SOCKET=1 -DHAVE_CLOCK_GETTIME=1 -DHAVE_DUP2=1 -DHAVE_GETTIMEOFDAY=1 + -DHAVE_MEMCHR=1 -DHAVE_MEMMOVE=1 -DHAVE_POW=1 -DHAVE_PUTENV=1 -DHAVE_SETENV=1 -DHAVE_SETLOCALE=1 + -DHAVE_SQRT=1 -DHAVE_STRCHR=1 -DHAVE_MALLOC_TRIM=1 -DHAVE_LIMITS_H=1 -DHAVE_SYS_PARAM_H=1 -DHAVE_SYS_TIME_H=1 + -DHAVE_WCHAR_H=1 -DHAVE_LIBSDL2=1 -DHAVE_LIBSDL2_IMAGE=1 -DHAVE_LIBSDL2_TTF=1 -DHAVE_LIBSDL2_MIXER=1 + -DHAVE_LIBSDL2_NET=1 -DUSE_INTERNALSDLGFX=1 -DHAVE_SDL_H=1 -DHAVE_LIBPTHREAD=1 -DHAVE_LIBZ=1 -DHAVE_LIBCURL=1 + -DHAVE_CURL_CURL_H=1 -DHAVE_LIBXML2=1 -DHAVE_LIBXML_XMLREADER_H=1 -DHAVE_LIBPNG=1 -DSTDC_HEADERS=1 -DHAVE_ARPA_INET_H=1 + -DHAVE_FCNTL_H=1 -DHAVE_MALLOC_H=1 -DHAVE_NETDB_H=1 -DHAVE_NETINET_IN_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 + -DHAVE_SYS_SOCKET_H=1 -DHAVE_UNISTD_H=1 -Wall -DENABLE_ASSERTS -DHAVE_GLEXT -DENABLE_LIBXML -DUSE_SDL2 -DTMWA_SUPPORT -DCURL_STATICLIB + ) + +add_executable(${PROJECT_NAME} ${SOURCES}) +target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDES}) +target_compile_options(${PROJECT_NAME} PRIVATE -D__SWITCH__ ${FLAGS}) +target_link_libraries(${PROJECT_NAME} + png xml2 curl z pthread SDL2_net SDL2_mixer SDL2_ttf SDL2_image SDL2 + SDL2_image png16 z m nx z jpeg webp + SDL2_mixer vorbisidec modplug mpg123 + opusfile ogg opus + SDL2_net + SDL2_ttf freetype bz2 + curl mbedtls mbedx509 mbedcrypto + EGL + glapi + drm_nouveau + nx + stdc++ + m + ) +set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS + "-specs=${DEVKITPRO}/libnx/switch.specs -L${DEVKITPRO}/libnx/lib -L${DEVKITPRO}/portlibs/switch/lib") +add_custom_target(${PROJECT_NAME}.nro + DEPENDS ${PROJECT_NAME} + COMMAND elf2nro ${PROJECT_NAME} ${PROJECT_NAME}.nro) diff --git a/src/fs/paths.cpp b/src/fs/paths.cpp index 06186c7f0..036020fce 100644 --- a/src/fs/paths.cpp +++ b/src/fs/paths.cpp @@ -37,7 +37,7 @@ #include "utils/foreach.h" #endif // USE_X11 -#ifdef __native_client__ +#if defined(__native_client__) || defined(__SWITCH__) #define realpath(N, R) strcpy(R, N) #endif // __native_client__ @@ -67,7 +67,7 @@ PRAGMA48(GCC diagnostic ignored "-Wshadow") #endif // ANDROID PRAGMA48(GCC diagnostic pop) -#ifdef __native_client__ +#if defined(__native_client__) || defined(__SWITCH__) #ifndef SSIZE_MAX #define SSIZE_MAX INT_MAX #endif @@ -92,7 +92,7 @@ std::string getRealPath(const std::string &str) { return std::string(); } -#if defined(__OpenBSD__) || defined(__ANDROID__) || defined(__native_client__) +#if defined(__OpenBSD__) || defined(__ANDROID__) || defined(__native_client__) || defined(__SWITCH__) char *realPath = reinterpret_cast<char*>(calloc(PATH_MAX, sizeof(char))); if (!realPath) return ""; @@ -261,6 +261,9 @@ std::string getHomePath() const char *path = getenv("HOME"); if (path == nullptr) { +#ifdef __SWITCH__ + return "/switch/manaplus"; +#else const uid_t uid = getuid(); const struct passwd *const pw = getpwuid(uid); if (pw != nullptr && @@ -270,6 +273,7 @@ std::string getHomePath() } if (path == nullptr) return dirSeparator; +#endif } std::string dir = path; if (findLast(dir, std::string(dirSeparator)) == false) diff --git a/src/logger.cpp b/src/logger.cpp index b7d3b422e..90aefaeeb 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -120,7 +120,11 @@ void Logger::setLogFile(const std::string &logFilename) { closeFile(); +#ifdef __SWITCH__ + mLogFile = nullptr; +#else mLogFile = fopen(logFilename.c_str(), "wt"); +#endif if (mLogFile == nullptr) { diff --git a/src/maingui.cpp b/src/maingui.cpp index 176c5cd6e..054db6b05 100644 --- a/src/maingui.cpp +++ b/src/maingui.cpp @@ -97,6 +97,29 @@ PRAGMA48(GCC diagnostic pop) #include "debug.h" +#ifdef __SWITCH__ +extern "C" { +#include <switch/runtime/devices/socket.h> +#include <switch/runtime/nxlink.h> +} +#include <unistd.h> +static int sock = -1; +void initNxLink() { + socketInitializeDefault(); + sock = nxlinkStdio(); + if (sock < 0) { + socketExit(); + } +} +void deinitNxLink() { + if (sock >= 0) { + close(sock); + socketExit(); + sock = -1; + } +} +#endif + char *selfName = nullptr; #ifndef UNITTESTS @@ -107,6 +130,9 @@ int main(int argc, char *argv[]) int mainGui(int argc, char *argv[]) #endif // ANDROID { +#ifdef __SWITCH__ + initNxLink(); +#endif #if defined(__MINGW32__) // load mingw crash handler. Won't fail if dll is not present. // may load libray from current dir, it may not same as program dir @@ -159,6 +185,10 @@ int mainGui(int argc, char *argv[]) IMG_Quit(); #endif // SDL_IMAGE_VERSION_ATLEAST(1, 2, 11) +#ifdef __SWITCH__ + deinitNxLink(); +#endif + return ret; } #else // UNITTESTS diff --git a/src/progs/manaplus/client.cpp b/src/progs/manaplus/client.cpp index 76d64221d..772975214 100644 --- a/src/progs/manaplus/client.cpp +++ b/src/progs/manaplus/client.cpp @@ -411,7 +411,7 @@ void Client::gameInit() DyePalette::initFunctions(); #if defined(USE_OPENGL) #if !defined(ANDROID) && !defined(__APPLE__) && \ - !defined(__native_client__) && !defined(UNITTESTS) + !defined(__native_client__) && !defined(__SWITCH__) && !defined(UNITTESTS) if (!settings.options.safeMode && settings.options.renderer < 0 && settings.options.test.empty() && diff --git a/src/render/renderers.cpp b/src/render/renderers.cpp index c81ac9b57..efcad9ff2 100644 --- a/src/render/renderers.cpp +++ b/src/render/renderers.cpp @@ -41,6 +41,9 @@ static RenderType getDefault() noexcept2 RenderType intToRenderType(const int mode) noexcept2 { +#ifdef __SWITCH__ + return RENDER_SDL2_DEFAULT; +#endif if (mode < 0 || mode >= RENDER_LAST) return getDefault(); diff --git a/src/render/rendererslistsdl2.h b/src/render/rendererslistsdl2.h index 60202c2dd..b13324b2d 100644 --- a/src/render/rendererslistsdl2.h +++ b/src/render/rendererslistsdl2.h @@ -99,6 +99,39 @@ const int renderToIndex[] = 3 // RENDER_GLES2_OPENGL }; +#elif defined(__SWITCH__) + +// map for index to RenderType +const RenderType indexToRender[] = +{ + RENDER_SOFTWARE, + RENDER_SDL2_DEFAULT, + RENDER_MODERN_OPENGL +}; + +const char *OPENGL_NAME[] = +{ + // TRANSLATORS: draw backend + N_("Software"), + // TRANSLATORS: draw backend + N_("SDL2 default"), + // TRANSLATORS: draw backend + N_("Modern OpenGL") +}; + +const int renderModesListSize = 3; + +const int renderToIndex[] = +{ + 2, // RENDER_SOFTWARE + 2, // RENDER_NORMAL_OPENGL + 2, // RENDER_SAFE_OPENGL + 2, // RENDER_GLES_OPENGL + 1, // RENDER_SDL2_DEFAULT + 2, // RENDER_MODERN_OPENGL + 2 // RENDER_GLES2_OPENGL +}; + #else // ANDROID or nacl // defined OPENGL |