summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcpasjuste <cpasjuste@gmail.com>2020-04-22 15:24:08 +0200
committercpasjuste <cpasjuste@gmail.com>2020-04-22 15:24:08 +0200
commitf43e3aa48aeb561f5c7e85f1b7121aab6a61decd (patch)
tree1c23a1e1db2676c27a99b6385f0580442b29f7a0 /src
parentb0c696eaab501391512b08826c3c9a52023e2be7 (diff)
downloadmv-f43e3aa48aeb561f5c7e85f1b7121aab6a61decd.tar.gz
mv-f43e3aa48aeb561f5c7e85f1b7121aab6a61decd.tar.bz2
mv-f43e3aa48aeb561f5c7e85f1b7121aab6a61decd.tar.xz
mv-f43e3aa48aeb561f5c7e85f1b7121aab6a61decd.zip
switch: first commit
Diffstat (limited to 'src')
-rw-r--r--src/fs/paths.cpp10
-rw-r--r--src/logger.cpp4
-rw-r--r--src/maingui.cpp30
-rw-r--r--src/progs/manaplus/client.cpp2
-rw-r--r--src/render/renderers.cpp3
-rw-r--r--src/render/rendererslistsdl2.h33
6 files changed, 78 insertions, 4 deletions
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