Starting work on Android port
This commit is contained in:
parent
5d1b7678f0
commit
ab13ccd595
183 changed files with 6790 additions and 906 deletions
|
|
@ -1,5 +1,9 @@
|
|||
#include "Logger.hpp"
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
Logger Logger::global;
|
||||
|
||||
|
|
@ -20,3 +24,11 @@ void Logger::log(const std::string& log, const std::string& text) {
|
|||
else
|
||||
it->second(text);
|
||||
}
|
||||
|
||||
void Logger::cross_platform_println(const std::string& text) {
|
||||
#ifdef __ANDROID__
|
||||
__android_log_print(ANDROID_LOG_INFO, "Logger", "%s", text.c_str());
|
||||
#else
|
||||
std::cout << text << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ class Logger {
|
|||
static Logger& get();
|
||||
void add_log(const std::string& log, const std::function<void(const std::string&)> callback);
|
||||
void log(const std::string& log, const std::string& text);
|
||||
void cross_platform_println(const std::string& text);
|
||||
private:
|
||||
static Logger global;
|
||||
std::mutex logMutex;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#endif
|
||||
|
||||
template <typename ContainerType> void parallel_loop_container(const ContainerType& c, std::function<void(const typename ContainerType::value_type&)> func, bool forceSingleThread = false) {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#if defined(__EMSCRIPTEN__) || defined(__ANDROID__)
|
||||
std::for_each(c.begin(), c.end(), func);
|
||||
#else
|
||||
if(forceSingleThread)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <regex>
|
||||
#include <SDL3/SDL_iostream.h>
|
||||
|
||||
std::vector<std::string> split_string_by_token(std::string str, std::string token) {
|
||||
// slightly modified from: https://stackoverflow.com/a/46943631
|
||||
|
|
@ -44,27 +45,18 @@ std::string byte_vector_to_hex_str(const std::vector<uint8_t>& byteVec) {
|
|||
}
|
||||
|
||||
std::string read_file_to_string(const std::filesystem::path& filePath) {
|
||||
// Could also use SDL_LoadFile, but that allocates into a void* and involves a copy into std::string
|
||||
|
||||
std::string toRet;
|
||||
// https://nullptr.org/cpp-read-file-into-string/
|
||||
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
|
||||
|
||||
if(!file.is_open())
|
||||
throw std::runtime_error("[read_file_to_string] Could not open file");
|
||||
|
||||
size_t resourcesize;
|
||||
|
||||
auto tellgResult = file.tellg();
|
||||
|
||||
if(tellgResult == -1)
|
||||
throw std::runtime_error("[read_file_to_string] tellg failed for file");
|
||||
|
||||
resourcesize = static_cast<size_t>(tellgResult);
|
||||
|
||||
file.seekg(0, std::ios_base::beg);
|
||||
toRet.resize(resourcesize);
|
||||
file.read(toRet.data(), resourcesize);
|
||||
file.close();
|
||||
|
||||
SDL_IOStream* file = SDL_IOFromFile(filePath.c_str(), "rb");
|
||||
if(!file)
|
||||
throw std::runtime_error("[read_file_to_string] Could not open file " + filePath.string());
|
||||
Sint64 fileSize = SDL_GetIOSize(file);
|
||||
if(fileSize < 0)
|
||||
throw std::runtime_error("[read_file_to_string] tellg failed for file " + filePath.string());
|
||||
toRet.resize(fileSize);
|
||||
SDL_ReadIO(file, toRet.data(), fileSize);
|
||||
SDL_CloseIO(file);
|
||||
return toRet;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue