From 24465f29c5e0d9f1a074d2c4fe75fb40c2a8d40e Mon Sep 17 00:00:00 2001 From: shweet Date: Tue, 11 Nov 2025 20:28:31 -0500 Subject: [PATCH] uuuuuuuuuuuuuggggggggggggggggghhhhhhhhhhhhhhhhhh --- .gitmodules | 1 - CMakeLists.txt | 21 ++++++++++++++++++- include/libxm | 1 - .../xm_wrapper.h => include/libxm_compat.h | 4 +--- src/imgui/taskbar.cpp | 7 ++++--- src/resource/audio.cpp | 11 +++++----- src/resource/xm_music.h | 3 ++- src/resources.cpp | 19 ++++++++++++++--- src/resources.h | 7 ++++++- 9 files changed, 55 insertions(+), 19 deletions(-) delete mode 160000 include/libxm rename src/resource/xm_wrapper.h => include/libxm_compat.h (76%) diff --git a/.gitmodules b/.gitmodules index 6fdd051..7172566 100644 --- a/.gitmodules +++ b/.gitmodules @@ -17,7 +17,6 @@ [submodule "external/SDL_mixer"] path = external/SDL_mixer url = https://github.com/libsdl-org/SDL_mixer - [submodule "external/libxm"] path = external/libxm url = https://github.com/Artefact2/libxm diff --git a/CMakeLists.txt b/CMakeLists.txt index 6546e96..c61a301 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.27) -project(anm2ed CXX) +project(anm2ed LANGUAGES C CXX) if (WIN32 AND DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" @@ -22,7 +22,18 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) set(SDL_STATIC ON CACHE BOOL "" FORCE) set(SDL_SHARED OFF CACHE BOOL "" FORCE) +if (NOT WIN32) + set(SDL_ALSA ON CACHE BOOL "" FORCE) + set(SDL_ALSA_SHARED ON CACHE BOOL "" FORCE) + set(SDL_JACK ON CACHE BOOL "" FORCE) + set(SDL_JACK_SHARED ON CACHE BOOL "" FORCE) + set(SDL_PIPEWIRE ON CACHE BOOL "" FORCE) + set(SDL_PIPEWIRE_SHARED ON CACHE BOOL "" FORCE) + set(SDL_SNDIO ON CACHE BOOL "" FORCE) + set(SDL_SNDIO_SHARED ON CACHE BOOL "" FORCE) +endif () set(SDL_HAPTIC OFF CACHE BOOL "" FORCE) +set(SDL_JOYSTICK OFF CACHE BOOL "" FORCE) set(SDL_SENSOR OFF CACHE BOOL "" FORCE) set(SDL_HIDAPI OFF CACHE BOOL "" FORCE) set(SDL_CAMERA OFF CACHE BOOL "" FORCE) @@ -49,6 +60,7 @@ if (WIN32) set(MATH_LIBRARY "" CACHE FILEPATH "Windows doesn't require libm for libxm" FORCE) endif () add_subdirectory(external/libxm/src EXCLUDE_FROM_ALL) +set(LIBXM_COMPAT_HEADER "${CMAKE_SOURCE_DIR}/include/libxm_compat.h") set(GLAD_SRC ${CMAKE_CURRENT_SOURCE_DIR}/include/glad/glad.cpp) @@ -86,6 +98,13 @@ add_executable(${PROJECT_NAME} ${TINYXML2_SRC} ${PROJECT_SRC} ) +if (MSVC) + cmake_path(CONVERT "${LIBXM_COMPAT_HEADER}" TO_NATIVE_PATH LIBXM_COMPAT_HEADER_NATIVE) + target_compile_options(${PROJECT_NAME} PRIVATE "/FI${LIBXM_COMPAT_HEADER_NATIVE}") + if (TARGET xm) + target_compile_options(xm PRIVATE "/FI${LIBXM_COMPAT_HEADER_NATIVE}") + endif () +endif () if (WIN32) enable_language(RC) diff --git a/include/libxm b/include/libxm deleted file mode 160000 index 9f599c4..0000000 --- a/include/libxm +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9f599c4dd4079700e2d9b8af62dc1ab8d76808f5 diff --git a/src/resource/xm_wrapper.h b/include/libxm_compat.h similarity index 76% rename from src/resource/xm_wrapper.h rename to include/libxm_compat.h index d5a8b5a..837e8fa 100644 --- a/src/resource/xm_wrapper.h +++ b/include/libxm_compat.h @@ -5,8 +5,6 @@ #define __attribute__(x) #endif #ifndef restrict - #define restrict + #define restrict __restrict #endif #endif - -#include diff --git a/src/imgui/taskbar.cpp b/src/imgui/taskbar.cpp index c4ff6d2..83a0cc2 100644 --- a/src/imgui/taskbar.cpp +++ b/src/imgui/taskbar.cpp @@ -41,7 +41,7 @@ namespace anm2ed::imgui if (ImGui::BeginMenu("File")) { if (ImGui::MenuItem("New", settings.shortcutNew.c_str())) dialog.file_save(dialog::ANM2_NEW); - if (ImGui::MenuItem("Open", settings.shortcutOpen.c_str())) dialog.file_open(dialog::ANM2_NEW); + if (ImGui::MenuItem("Open", settings.shortcutOpen.c_str())) dialog.file_open(dialog::ANM2_OPEN); if (ImGui::BeginMenu("Open Recent", !manager.recentFiles.empty())) { @@ -699,7 +699,7 @@ namespace anm2ed::imgui auto credits_reset = [&]() { - resources.music.play(true); + resources.music_track().play(true); creditsState = {}; creditsState.spawnTimer = CREDIT_DELAY; }; @@ -802,7 +802,8 @@ namespace anm2ed::imgui ImGui::EndPopup(); } - if (resources.music.is_playing() && !aboutPopup.isOpen) resources.music.stop(); + if (auto* music = resources.music_track_if_loaded()) + if (music->is_playing() && !aboutPopup.isOpen) music->stop(); aboutPopup.end(); diff --git a/src/resource/audio.cpp b/src/resource/audio.cpp index 0f137cb..9bab51c 100644 --- a/src/resource/audio.cpp +++ b/src/resource/audio.cpp @@ -7,13 +7,14 @@ #include #include -#include "xm_wrapper.h" +#include "libxm_compat.h" +#include namespace anm2ed::resource { namespace { - constexpr int XM_SAMPLE_RATE = 44100; + constexpr int XM_SAMPLE_RATE_ = 44100; constexpr uint16_t XM_CHUNK_FRAMES = 1024; constexpr int XM_MAX_SECONDS = 600; constexpr int XM_CHANNELS = 2; @@ -51,14 +52,14 @@ namespace anm2ed::resource auto context = xm_create_context(pool.get(), prescan, (const char*)data, (uint32_t)size); if (!context) return; - xm_set_sample_rate(context, (uint16_t)XM_SAMPLE_RATE); + xm_set_sample_rate(context, (uint16_t)XM_SAMPLE_RATE_); xm_set_max_loop_count(context, 1); auto pcm = std::vector{}; pcm.reserve(static_cast(XM_CHUNK_FRAMES) * XM_CHANNELS * 8); size_t framesGenerated = 0; - const auto maxFrames = static_cast(XM_SAMPLE_RATE) * XM_MAX_SECONDS; + const auto maxFrames = static_cast(XM_SAMPLE_RATE_) * XM_MAX_SECONDS; auto heardAudio = false; while (framesGenerated < maxFrames) @@ -88,7 +89,7 @@ namespace anm2ed::resource if (pcm.empty()) return; auto spec = SDL_AudioSpec{}; - spec.freq = XM_SAMPLE_RATE; + spec.freq = XM_SAMPLE_RATE_; spec.format = SDL_AUDIO_F32; spec.channels = XM_CHANNELS; diff --git a/src/resource/xm_music.h b/src/resource/xm_music.h index af46aff..a21e181 100644 --- a/src/resource/xm_music.h +++ b/src/resource/xm_music.h @@ -1,7 +1,8 @@ #pragma once #include -#include "xm_wrapper.h" +#include "libxm_compat.h" +#include namespace anm2ed::resource::xm { diff --git a/src/resources.cpp b/src/resources.cpp index 68329a2..7a4e5c6 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -18,7 +18,20 @@ namespace anm2ed for (auto [i, shader] : std::views::enumerate(shader::SHADERS)) shaders[i] = Shader(shader.vertex, shader.fragment); - - music = Audio(xm::ABOUT, std::size(xm::ABOUT)); }; -} \ No newline at end of file + + resource::Audio& Resources::music_track() + { + if (!isMusicLoaded) + { + music = Audio(xm::ABOUT, std::size(xm::ABOUT)); + isMusicLoaded = true; + } + return music; + } + + resource::Audio* Resources::music_track_if_loaded() + { + return isMusicLoaded ? &music : nullptr; + } +} diff --git a/src/resources.h b/src/resources.h index c1c5f78..7e7a0d8 100644 --- a/src/resources.h +++ b/src/resources.h @@ -19,5 +19,10 @@ namespace anm2ed resource::Audio music{}; Resources(); + resource::Audio& music_track(); + resource::Audio* music_track_if_loaded(); + + private: + bool isMusicLoaded{false}; }; -} \ No newline at end of file +}