From d3d33383ec67118b741482dbca1375f877ef1a5c Mon Sep 17 00:00:00 2001 From: ecker Date: Mon, 27 Jul 2026 07:24:14 -0500 Subject: [PATCH] actually flycast had a bug that refused to play audio from kallistios-based programs... --- dep/include/ctti/detail/pretty_function.hpp | 12 ++++++-- engine/inc/uf/macros.h | 9 ++++++ engine/src/ext/aica/aica.cpp | 31 ++------------------- engine/src/ext/opengl/commands.cpp | 15 ++++------ engine/src/utils/camera/camera.cpp | 6 +--- makefiles/platforms/win64.gcc.mk | 2 +- 6 files changed, 30 insertions(+), 45 deletions(-) diff --git a/dep/include/ctti/detail/pretty_function.hpp b/dep/include/ctti/detail/pretty_function.hpp index 22a2ed8e..e51bf249 100644 --- a/dep/include/ctti/detail/pretty_function.hpp +++ b/dep/include/ctti/detail/pretty_function.hpp @@ -43,7 +43,11 @@ constexpr ctti::detail::cstring value() #define CTTI_TYPE_PRETTY_FUNCTION_PREFIX "ctti::detail::cstring ctti::pretty_function::type() [T = " #define CTTI_TYPE_PRETTY_FUNCTION_SUFFIX "]" #elif defined(__GNUC__) && !defined(__clang__) - #define CTTI_TYPE_PRETTY_FUNCTION_PREFIX "constexpr ctti::detail::cstring ctti::pretty_function::type() [with T = " + #if __GNUC__ >= 16 + #define CTTI_TYPE_PRETTY_FUNCTION_PREFIX "ctti::detail::cstring ctti::pretty_function::type() [with T = " + #else + #define CTTI_TYPE_PRETTY_FUNCTION_PREFIX "constexpr ctti::detail::cstring ctti::pretty_function::type() [with T = " + #endif #define CTTI_TYPE_PRETTY_FUNCTION_SUFFIX "]" #elif defined(_MSC_VER) #define CTTI_TYPE_PRETTY_FUNCTION_PREFIX "struct ctti::detail::cstring __cdecl ctti::pretty_function::type<" @@ -60,7 +64,11 @@ constexpr ctti::detail::cstring value() #define CTTI_VALUE_PRETTY_FUNCTION_SEPARATOR "; Value = " #define CTTI_VALUE_PRETTY_FUNCTION_SUFFIX "]" #elif defined(__GNUC__) && !defined(__clang__) - #define CTTI_VALUE_PRETTY_FUNCTION_PREFIX "constexpr ctti::detail::cstring ctti::pretty_function::value() [with T = " + #if __GNUC__ >= 16 + #define CTTI_VALUE_PRETTY_FUNCTION_PREFIX "ctti::detail::cstring ctti::pretty_function::value() [with T = " + #else + #define CTTI_VALUE_PRETTY_FUNCTION_PREFIX "constexpr ctti::detail::cstring ctti::pretty_function::value() [with T = " + #endif #define CTTI_VALUE_PRETTY_FUNCTION_SEPARATOR "; T Value = " #define CTTI_VALUE_PRETTY_FUNCTION_SUFFIX "]" #elif defined(_MSC_VER) diff --git a/engine/inc/uf/macros.h b/engine/inc/uf/macros.h index 7866395b..e417127c 100644 --- a/engine/inc/uf/macros.h +++ b/engine/inc/uf/macros.h @@ -108,12 +108,21 @@ #define TYPE_SANITIZE(T) std::remove_cv_t> #if UF_CTTI +#if 0 + #include + #define TYPE_INDEX_T decltype(ctti::type_id_of()) + #define TYPE_HASH_T decltype(ctti::type_id_of().hash()) + #define TYPE(T) ctti::type_id_of() + #define TYPE_HASH(T) TYPE(T).hash() + #define TYPE_NAME(T) ctti::name_of() +#else #include #define TYPE_INDEX_T ctti::type_id_t #define TYPE_HASH_T ctti::detail::hash_t #define TYPE(T) ctti::type_id() #define TYPE_HASH(T) TYPE(T).hash() #define TYPE_NAME(T) ctti::nameof().str() +#endif #else #define TYPE_INDEX_T std::type_index #define TYPE_HASH_T std::size_t diff --git a/engine/src/ext/aica/aica.cpp b/engine/src/ext/aica/aica.cpp index 9a0d7314..cfe00abf 100644 --- a/engine/src/ext/aica/aica.cpp +++ b/engine/src/ext/aica/aica.cpp @@ -18,6 +18,7 @@ namespace impl { typedef int (*fill_callback_t)(void* user_data, uint8_t* buffer, int req_bytes); constexpr int STREAM_BUFFER_SIZE = 16384; + constexpr int DRIVER_BUFFER_SIZE = 65536; constexpr size_t MAX_VIRTUAL_SOURCES = 256; constexpr size_t MAX_VIRTUAL_BUFFERS = 1024; @@ -58,7 +59,6 @@ namespace impl { mutex_t g_streamMutex = MUTEX_INITIALIZER; void* kos_stream_callback( snd_stream_hnd_t hnd, int req_bytes, int* bytes_returned ) { - UF_MSG_DEBUG("[AICA] Requesting {} bytes", req_bytes); auto it = g_activeStreams.find(hnd); if ( it == g_activeStreams.end() ) { *bytes_returned = 0; @@ -68,39 +68,14 @@ namespace impl { impl::Buffer* buf = it->second; if ( req_bytes > impl::STREAM_BUFFER_SIZE ) { - UF_MSG_WARNING("[AICA] Requesting more than buffer: {} > {}", req_bytes, impl::STREAM_BUFFER_SIZE); req_bytes = impl::STREAM_BUFFER_SIZE; } - // generate a sin wave for testing - // washdc plays this, albeit slowly because emulation speed is hindered - // flycast doesn't play audio, this callback gets called twice then never again - #if 1 - float frequency = 440.0f; - float sample_rate = buf->frequency > 0 ? buf->frequency : 44100.0f; - int channels = (buf->format == AL_FORMAT_STEREO16 || buf->format == AL_FORMAT_STEREO8) ? 2 : 1; - - int16_t* samples = (int16_t*)buf->stream_buffer; - int num_samples = req_bytes / sizeof(int16_t); - int half_period = (int)(sample_rate / (frequency * 2.0f)); - static int sample_count = 0; - - for( int i = 0; i < num_samples; i += channels ) { - int16_t sample_val = ((sample_count / half_period) % 2 == 0) ? 16000 : -16000; - - samples[i] = sample_val; - if ( channels == 2 ) samples[i + 1] = sample_val; - sample_count++; - } - - *bytes_returned = req_bytes; - #else if ( buf->fill_callback && buf->user_data ) { *bytes_returned = buf->fill_callback(buf->user_data, buf->stream_buffer, req_bytes); } else { *bytes_returned = 0; } - #endif if ( *bytes_returned == 0 ) return nullptr; @@ -281,7 +256,7 @@ void ext::al::Source::play() { int pan = 128; if ( buffer.aica_addr != 0 ) { - snd_sfx_play(buffer.aica_addr, vol, pan); + // snd_sfx_play(buffer.aica_addr, vol, pan); // earrape } else if ( buffer.stream_hnd != SND_STREAM_INVALID ) { int channels = (buffer.format == AL_FORMAT_STEREO16 || buffer.format == AL_FORMAT_STEREO8) ? 1 : 0; @@ -471,7 +446,7 @@ void ext::al::Buffer::buffer( ALuint index, ALenum format, const ALvoid* data, A UF_MSG_ERROR("[AICA] Failed to allocate {} bytes", impl::STREAM_BUFFER_SIZE); return; } - buffer.stream_hnd = snd_stream_alloc( impl::kos_stream_callback, impl::STREAM_BUFFER_SIZE ); + buffer.stream_hnd = snd_stream_alloc( impl::kos_stream_callback, impl::DRIVER_BUFFER_SIZE ); if ( buffer.stream_hnd == SND_STREAM_INVALID ) { UF_MSG_ERROR("[AICA] Failed to allocate {} bytes", impl::STREAM_BUFFER_SIZE); return; diff --git a/engine/src/ext/opengl/commands.cpp b/engine/src/ext/opengl/commands.cpp index 9e0d447c..d8cb1af3 100644 --- a/engine/src/ext/opengl/commands.cpp +++ b/engine/src/ext/opengl/commands.cpp @@ -568,7 +568,10 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: GL_ERROR_CHECK(glEnableClientState(GL_COLOR_ARRAY)); ::shadowState.colorArrayEnabled = true; } - GLenum colorType = (drawInfo.attributes.color.descriptor.size / drawInfo.attributes.color.descriptor.components == sizeof(uint8_t)) ? GL_UNSIGNED_BYTE : GL_FLOAT; + GLenum colorType = GL_FLOAT; + if ( drawInfo.attributes.color.descriptor.type == uf::renderer::enums::Type::UBYTE || drawInfo.attributes.color.descriptor.size == sizeof(uint8_t)) { + colorType = GL_UNSIGNED_BYTE; + } GL_ERROR_CHECK(glColorPointer(drawInfo.attributes.color.descriptor.components, colorType, drawInfo.attributes.color.stride, colorPtr)); } else if ( ::shadowState.colorArrayEnabled ) { GL_ERROR_CHECK(glDisableClientState(GL_COLOR_ARRAY)); @@ -598,9 +601,9 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: } GL_ERROR_CHECK(glTexCoordPointer(2, uvType, uvStride, uvPtr)); - GL_ERROR_CHECK(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, drawInfo.attributes.color.pointer ? GL_MODULATE : GL_REPLACE)); + //GL_ERROR_CHECK(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, drawInfo.attributes.color.pointer ? GL_MODULATE : GL_REPLACE)); // washdc works fine, flycast renders nothing if GL_MODULATE is set, although GL_REPLACE just renders the background - //GL_ERROR_CHECK(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)); + GL_ERROR_CHECK(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)); } else { if ( ::shadowState.tex0Enabled ) { GL_ERROR_CHECK(glClientActiveTexture(GL_TEXTURE0)); @@ -677,12 +680,6 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: GL_ERROR_CHECK(glDrawArrays(mode, drawInfo.descriptor.inputs.vertex.first, drawInfo.descriptor.inputs.vertex.count)); } - if ( drawInfo.descriptor.inputs.index.count ) { - GL_ERROR_CHECK(glDrawElements(mode, drawInfo.descriptor.inputs.index.count, indicesType, (static_cast(drawInfo.attributes.index.pointer) + drawInfo.attributes.index.stride * drawInfo.descriptor.inputs.index.first))); - } else { - GL_ERROR_CHECK(glDrawArrays(mode, drawInfo.descriptor.inputs.vertex.first, drawInfo.descriptor.inputs.vertex.count)); - } - GL_ERROR_CHECK(glDisableClientState(GL_VERTEX_ARRAY)); } #endif \ No newline at end of file diff --git a/engine/src/utils/camera/camera.cpp b/engine/src/utils/camera/camera.cpp index e46095ce..1263b8a6 100644 --- a/engine/src/utils/camera/camera.cpp +++ b/engine/src/utils/camera/camera.cpp @@ -3,11 +3,7 @@ #include #include -#if UF_ENV_DREAMCAST - bool uf::matrix::reverseInfiniteProjection = false; -#else - bool uf::matrix::reverseInfiniteProjection = true; -#endif +bool uf::matrix::reverseInfiniteProjection = true; pod::Vector3f uf::camera::eye( const pod::Camera& camera, int i ) { if ( i < 0 ) i = 0; diff --git a/makefiles/platforms/win64.gcc.mk b/makefiles/platforms/win64.gcc.mk index ad002a5e..f1bf5d8b 100644 --- a/makefiles/platforms/win64.gcc.mk +++ b/makefiles/platforms/win64.gcc.mk @@ -9,7 +9,7 @@ FLAGS += -fdiagnostics-color=always # MSYS2 INCS += -I/mingw64/include/ -LIBS += -I/mingw64/lib/ +LIBS += -L/mingw64/lib/ TARGET_EXTENSION = .exe DLIB_EXTENSION = .dll