diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index ff3870df..90fa919e 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -593,8 +593,10 @@ jobs: - name: Configure core run: | echo "[binaries]" | tee -a ${{ runner.temp }}/cross.ini - echo "c = ['clang', '--target=${{ matrix.arch_llvm }}', '-fuse-ld=lld', '--sysroot=${{ steps.sysroot.outputs.root-path }}']" | tee -a ${{ runner.temp }}/cross.ini - echo "cpp = ['clang++', '--target=${{ matrix.arch_llvm }}', '-fuse-ld=lld', '--sysroot=${{ steps.sysroot.outputs.root-path }}']" | tee -a ${{ runner.temp }}/cross.ini + echo "c = ['clang', '--target=${{ matrix.arch_llvm }}', '--sysroot=${{ steps.sysroot.outputs.root-path }}']" | tee -a ${{ runner.temp }}/cross.ini + echo "c_ld = 'lld'" | tee -a ${{ runner.temp }}/cross.ini + echo "cpp = ['clang++', '--target=${{ matrix.arch_llvm }}', '--sysroot=${{ steps.sysroot.outputs.root-path }}']" | tee -a ${{ runner.temp }}/cross.ini + echo "cpp_ld = 'lld'" | tee -a ${{ runner.temp }}/cross.ini echo "ar = 'llvm-ar'" | tee -a ${{ runner.temp }}/cross.ini echo "strip = 'llvm-strip'" | tee -a ${{ runner.temp }}/cross.ini echo "[host_machine]" | tee -a ${{ runner.temp }}/cross.ini @@ -604,6 +606,11 @@ jobs: echo "endian = '${{ matrix.endian }}'" | tee -a ${{ runner.temp }}/cross.ini echo "[properties]" | tee -a ${{ runner.temp }}/cross.ini echo "sys_root = '${{ steps.sysroot.outputs.root-path }}'" | tee -a ${{ runner.temp }}/cross.ini + echo "[cmake]" | tee -a ${{ runner.temp }}/cross.ini + echo "CMAKE_EXE_LINKER_FLAGS_INIT = '-fuse-ld=lld'" | tee -a ${{ runner.temp }}/cross.ini + echo "CMAKE_MODULE_LINKER_FLAGS_INIT = '-fuse-ld=lld'" | tee -a ${{ runner.temp }}/cross.ini + echo "CMAKE_SHARED_LINKER_FLAGS_INIT = '-fuse-ld=lld'" | tee -a ${{ runner.temp }}/cross.ini + echo "CMAKE_STATIC_LINKER_FLAGS_INIT = '-fuse-ld=lld'" | tee -a ${{ runner.temp }}/cross.ini echo '--------------------------------------------------------------------------------' CLICOLOR_FORCE=1 meson setup build --cross-file ${{ runner.temp }}/cross.ini --buildtype release -Db_lto=true -Dretro=true -Dretro_phase1_path=retro/build/retro-phase1 diff --git a/meson.build b/meson.build index fff0c5d4..805a06db 100644 --- a/meson.build +++ b/meson.build @@ -152,8 +152,13 @@ if get_option('retro') == true '-DSHARED_FLUID', ] if host_endian == 'big' + retro_defines += '-DMKXPZ_BIG_ENDIAN' retro_defines += '-DWABT_BIG_ENDIAN=1' endif + if host_system == 'emscripten' or not compilers['cpp'].compiles('struct E {}; int main() { throw E(); }', name: 'check if C++ exceptions are enabled') + retro_defines += '-DMKXPZ_NO_EXCEPTIONS' + retro_defines += '-DBOOST_NO_EXCEPTIONS' + endif retro_link_args = [] retro_cppflags = [] @@ -290,6 +295,14 @@ if get_option('retro') == true else global_sources += vcs_tag(command: ['git', 'rev-parse', '--short', 'HEAD'], fallback: 'unknown', input: 'src/git-hash.h.in', output: 'git-hash.h', replace_string: '@MKXPZ_GIT_HASH@') +if host_endian == 'big' + global_args += '-DMKXPZ_BIG_ENDIAN' + global_args += '-DWABT_BIG_ENDIAN=1' +endif +if host_system == 'emscripten' or not compilers['cpp'].compiles('struct E {}; int main() { throw E(); }', name: 'check if C++ exceptions are enabled') + retro_defines += '-DMKXPZ_NO_EXCEPTIONS' + retro_defines += '-DBOOST_NO_EXCEPTIONS' +endif xxd = find_program('xxd', native: true) diff --git a/src/audio/al-util.h b/src/audio/al-util.h index bf30d18f..bcc4a5a3 100644 --- a/src/audio/al-util.h +++ b/src/audio/al-util.h @@ -22,8 +22,8 @@ #ifndef ALUTIL_H #define ALUTIL_H -#include -#include +#include +#include #ifdef MKXPZ_RETRO # include diff --git a/src/audio/alstream.cpp b/src/audio/alstream.cpp index 8534c173..b7c3bff3 100644 --- a/src/audio/alstream.cpp +++ b/src/audio/alstream.cpp @@ -31,9 +31,11 @@ #include "sdl-util.h" #include "debugwriter.h" -#include -#include -#include +#ifndef MKXPZ_RETRO +# include +# include +# include +#endif // MKXPZ_RETRO ALStream::ALStream(LoopMode loopMode, const std::string &threadId) @@ -41,7 +43,10 @@ ALStream::ALStream(LoopMode loopMode, state(Closed), source(0), #ifdef MKXPZ_RETRO + streamInited(false), sourceExhausted(false), + threadTermReq(false), + needsRewind(false), #else thread(0), #endif // MKXPZ_RETRO @@ -308,7 +313,9 @@ void ALStream::openSource(const std::string &filename) void ALStream::stopStream() { -#ifndef MKXPZ_RETRO +#ifdef MKXPZ_RETRO + threadTermReq = true; +#else threadTermReq.set(); if (thread) @@ -331,8 +338,12 @@ void ALStream::startStream(double offset) { AL::Source::clearQueue(alSrc); -#ifndef MKXPZ_RETRO preemptPause = false; +#ifdef MKXPZ_RETRO + streamInited = false; + sourceExhausted = false; + threadTermReq = false; +#else streamInited.clear(); sourceExhausted.clear(); threadTermReq.clear(); @@ -389,13 +400,11 @@ void ALStream::checkStopped() if (state != Playing) return; -#ifndef MKXPZ_RETRO /* If streaming thread hasn't queued up * buffers yet there's not point in querying * the AL source */ if (!streamInited) return; -#endif // MKXPZ_RETRO /* If alSrc isn't playing, but we haven't * exhausted the data source yet, we're just @@ -414,15 +423,13 @@ void ALStream::renderInit() { bool firstBuffer = true; ALDataSource::Status status; - //if (needsRewind) + if (needsRewind) source->seekToOffset(startOffset); for (int i = 0; i < STREAM_BUFS; ++i) { -#ifndef MKXPZ_RETRO if (threadTermReq) return; -#endif AL::Buffer::ID buf = alBuf[i]; @@ -438,15 +445,15 @@ void ALStream::renderInit() { resumeStream(); firstBuffer = false; -#ifndef MKXPZ_RETRO +#ifdef MKXPZ_RETRO + streamInited = true; +#else streamInited.set(); -#endif +#endif // MKXPZ_RETRO } -#ifndef MKXPZ_RETRO if (threadTermReq) return; -#endif if (status == ALDataSource::EndOfStream) { @@ -454,7 +461,7 @@ void ALStream::renderInit() { sourceExhausted = true; #else sourceExhausted.set(); -#endif +#endif // MKXPZ_RETRO break; } } @@ -465,16 +472,24 @@ void ALStream::render() { while (procBufs--) { -#ifndef MKXPZ_RETRO if (threadTermReq) break; -#endif AL::Buffer::ID buf = AL::Source::unqueueBuffer(alSrc); +#ifndef MKXPZ_NO_EXCEPTIONS // `unqueueBuffer` will abort on error if C++ exceptions are disabled so we only need to check if `buf == AL::Buffer::ID(0)` if C++ exceptions are enabled +# ifdef MKXPZ_RETRO + if (buf == AL::Buffer::ID(0)) + { + mkxp_retro::log_printf(RETRO_LOG_ERROR, "Error unqueueing OpenAL buffer\n"); + std::abort(); + } +# else /* If something went wrong, try again later */ if (buf == AL::Buffer::ID(0)) break; +# endif // MKXPZ_RETRO +#endif // MKXPZ_NO_EXCEPTIONS if (buf == lastBuf) { @@ -506,7 +521,7 @@ void ALStream::render() { sourceExhausted = true; #else sourceExhausted.set(); -#endif +#endif // MKXPZ_RETRO return; } @@ -529,7 +544,7 @@ void ALStream::render() { sourceExhausted = true; #else sourceExhausted.set(); -#endif +#endif // MKXPZ_RETRO } } diff --git a/src/audio/alstream.h b/src/audio/alstream.h index 1b6fc0b1..1d5b6a5f 100644 --- a/src/audio/alstream.h +++ b/src/audio/alstream.h @@ -52,7 +52,10 @@ struct ALStream ALDataSource *source; #ifdef MKXPZ_RETRO + bool streamInited; bool sourceExhausted; + bool threadTermReq; + bool needsRewind; #else SDL_Thread *thread; diff --git a/src/core.cpp b/src/core.cpp index 1be327ab..e44798fe 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -25,8 +25,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include "git-hash.h" diff --git a/src/eventthread.h b/src/eventthread.h index 10f2535e..f521120d 100644 --- a/src/eventthread.h +++ b/src/eventthread.h @@ -38,7 +38,7 @@ #include "keybindings.h" #ifdef MKXPZ_RETRO -# include +# include #else typedef struct MKXPZ_ALCDEVICE ALCdevice; #endif // MKXPZ_RETRO diff --git a/src/main.cpp b/src/main.cpp index e90b5176..9aca9c06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,7 @@ #include "icon.png.xxd" #endif -#include +#include #include #include diff --git a/src/util/serial-util.h b/src/util/serial-util.h index 29eb8df6..50b18775 100644 --- a/src/util/serial-util.h +++ b/src/util/serial-util.h @@ -25,16 +25,9 @@ #include #include -#ifdef MKXPZ_RETRO -# if WABT_BIG_ENDIAN -# error "Non little endian systems not supported" -# endif -#else -# include -# if SDL_BYTEORDER != SDL_LIL_ENDIAN -# error "Non little endian systems not supported" -# endif -#endif // MKXPZ_RETRO +#ifdef MKXPZ_BIG_ENDIAN +# error "Non little endian systems not supported" +#endif // MKXPZ_BIG_ENDIAN static inline int32_t readInt32(const char **dataP)