diff --git a/Readme.md b/Readme.md index 5d8f8f7..c201f67 100644 --- a/Readme.md +++ b/Readme.md @@ -38,6 +38,10 @@ https://github.com/gametutorials/tutorials/blob/master/OpenGL/MD3%20Animation/Ma linux: ``` -g++ Game.cpp main.cpp Math.cpp OpenGlExtensions.cpp Physics.cpp Renderer.cpp ShaderManager.cpp TextureManager.cpp Utils.cpp BoneAnimatedModel.cpp ObjLoader.cpp -o sdl_app -O2 -std=c++14 $(pkg-config --cflags --libs sdl2 gl) +g++ Game.cpp main.cpp Math.cpp OpenGlExtensions.cpp Physics.cpp Renderer.cpp ShaderManager.cpp TextureManager.cpp Utils.cpp BoneAnimatedModel.cpp ObjLoader.cpp cmakeaudioplayer/src/AudioPlayer.cpp TextModel.cpp Inventory.cpp -o sdl_app -O2 -std=c++17 \ +-I cmakeaudioplayer/include \ +$(pkg-config --cflags --libs sdl2 gl) \ +$(pkg-config --cflags --libs vorbis vorbisfile ogg) \ +-lopenal ``` \ No newline at end of file diff --git a/cmakeaudioplayer/CMakeLists.txt b/cmakeaudioplayer/CMakeLists.txt index 4e467b4..788d0d8 100644 --- a/cmakeaudioplayer/CMakeLists.txt +++ b/cmakeaudioplayer/CMakeLists.txt @@ -33,3 +33,4 @@ target_link_libraries(audioplayer # Test executable add_executable(test_audio examples/test_audio.cpp) target_link_libraries(test_audio PRIVATE audioplayer stdc++fs) +git add ../../sounds diff --git a/cmakeaudioplayer/src/AudioPlayer.cpp b/cmakeaudioplayer/src/AudioPlayer.cpp index b31d295..4d37c27 100644 --- a/cmakeaudioplayer/src/AudioPlayer.cpp +++ b/cmakeaudioplayer/src/AudioPlayer.cpp @@ -44,22 +44,29 @@ bool AudioPlayer::isOggFile(const std::string& filename) const { } std::string AudioPlayer::findFileInSounds(const std::string& filename) { - // Check relative to executable location first (../../sounds) - std::filesystem::path soundsDir = std::filesystem::current_path() / ".." / ".." / "sounds"; + // Primary search path - "sounds" directory next to executable + std::filesystem::path soundsDir = std::filesystem::current_path() / "sounds"; - // Fallback to ../sounds if not found - std::filesystem::path altSoundsDir = std::filesystem::current_path() / ".." / "sounds"; + // Alternative search paths + std::vector altPaths = { + std::filesystem::current_path() / ".." / "sounds", // One level up + std::filesystem::current_path() / ".." / ".." / "sounds", // Two levels up + "/home/albert/gay-jam/ZeptoLabTest1/sounds" // Absolute path + }; std::cout << "🔠Searching for \"" << filename << "\" in:\n"; std::cout << " " << soundsDir << "\n"; - std::cout << " " << altSoundsDir << "\n"; if (std::filesystem::exists(soundsDir / filename)) { return (soundsDir / filename).string(); } - if (std::filesystem::exists(altSoundsDir / filename)) { - return (altSoundsDir / filename).string(); + // Try alternative paths + for (const auto& path : altPaths) { + std::cout << " " << path << "\n"; + if (std::filesystem::exists(path / filename)) { + return (path / filename).string(); + } } throw std::runtime_error("⌠File not found: " + filename); diff --git a/main.cpp b/main.cpp index cbfa8f4..d2013ff 100755 --- a/main.cpp +++ b/main.cpp @@ -18,6 +18,7 @@ #include "TextModel.h" #include "Inventory.h" +#include "cmakeaudioplayer/include/AudioPlayer.hpp" #include namespace ZL @@ -32,11 +33,11 @@ namespace ZL Vector4f clipCoords = MultMatrixVector(projectionModelView, inx); - // Ïåðñïåêòèâíîå äåëåíèå + // ������������� ������� float ndcX = clipCoords.v[0] / clipCoords.v[3]; float ndcY = clipCoords.v[1] / clipCoords.v[3]; - // Ïðåîáðàçóåì NDC â ýêðàííûå êîîðäèíàòû + // ����������� NDC � �������� ���������� screenX = (int)((ndcX + 1.0f) * 0.5f * screenWidth); //screenY = (int)((1.0f - ndcY) * 0.5f * screenHeight); screenY = (int)((1.0f + ndcY) * 0.5f * screenHeight); @@ -108,6 +109,9 @@ namespace ZL VertexRenderStruct coneMeshMutable; std::vector activeObjects; + + // Add AudioPlayer instance + std::unique_ptr audioPlayer; } static SDL_Window* window = NULL; @@ -397,6 +401,11 @@ namespace ZL std::cout << "\nAfter removal:\n"; ZL::PrintInventory(); + + // Initialize audio player + GameObjects::audioPlayer = std::make_unique(); + + /// } void render() { @@ -461,6 +470,12 @@ namespace ZL case SDLK_s: Env::downPressed = true; break; + case SDLK_SPACE: + // Play the symphony when space is pressed + if (GameObjects::audioPlayer) { + GameObjects::audioPlayer->playFromSoundsDir("Symphony No.6 (1st movement).ogg"); + } + break; } }