diff --git a/CMakeLists.txt b/CMakeLists.txt index 8423797..a4f95c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,10 +11,53 @@ find_package(OpenGL REQUIRED) find_package(GLUT REQUIRED) find_package(ZLIB REQUIRED) find_package(Irrlicht REQUIRED) +find_package(SDL REQUIRED) +find_package(SDL_mixer REQUIRED) find_package(LZ4 REQUIRED) -include_directories(${X11_INCLUDE_DIR} ${IRRLICHT_INCLUDE_DIR} ${LZ4_INCLUDE_DIR} .) +include_directories(${X11_INCLUDE_DIR} ${IRRLICHT_INCLUDE_DIR} ${LZ4_INCLUDE_DIR} ${SDL_INCLUDE_DIRS} ${SDL_MIXER_INCLUDE_DIRS} .) -add_executable(wallengine main.cpp wallpaperengine/shaders/compiler.h wallpaperengine/shaders/compiler.cpp wallpaperengine/project.cpp wallpaperengine/project.h wallpaperengine/scene.cpp wallpaperengine/scene.h wallpaperengine/object.cpp wallpaperengine/object.h wallpaperengine/camera.cpp wallpaperengine/camera.h wallpaperengine/core.cpp wallpaperengine/core.h wallpaperengine/image.cpp wallpaperengine/image.h wallpaperengine/object3d.cpp wallpaperengine/object3d.h wallpaperengine/effect.cpp wallpaperengine/effect.h wallpaperengine/fs/utils.cpp wallpaperengine/fs/utils.h wallpaperengine/irrlicht.cpp wallpaperengine/irrlicht.h wallpaperengine/video/renderer.cpp wallpaperengine/video/renderer.h wallpaperengine/video/node.cpp wallpaperengine/video/node.h wallpaperengine/video/material.cpp wallpaperengine/video/material.h wallpaperengine/texture.cpp wallpaperengine/texture.h wallpaperengine/irr/CImageLoaderTEX.h wallpaperengine/irr/CImageLoaderTEX.cpp wallpaperengine/irr/CPkgReader.h wallpaperengine/irr/CPkgReader.cpp wallpaperengine/irr/CFileList.h wallpaperengine/irr/CFileList.cpp) +add_executable( + wallengine + main.cpp + wallpaperengine/shaders/compiler.h + wallpaperengine/shaders/compiler.cpp + wallpaperengine/project.cpp + wallpaperengine/project.h + wallpaperengine/scene.cpp + wallpaperengine/scene.h + wallpaperengine/object.cpp + wallpaperengine/object.h + wallpaperengine/camera.cpp + wallpaperengine/camera.h + wallpaperengine/core.cpp + wallpaperengine/core.h + wallpaperengine/image.cpp + wallpaperengine/image.h + wallpaperengine/object3d.cpp + wallpaperengine/object3d.h + wallpaperengine/effect.cpp + wallpaperengine/effect.h + wallpaperengine/fs/utils.cpp + wallpaperengine/fs/utils.h + wallpaperengine/irrlicht.cpp + wallpaperengine/irrlicht.h + wallpaperengine/video/renderer.cpp + wallpaperengine/video/renderer.h + wallpaperengine/video/node.cpp + wallpaperengine/video/node.h + wallpaperengine/video/material.cpp + wallpaperengine/video/material.h + wallpaperengine/texture.cpp + wallpaperengine/texture.h + wallpaperengine/irr/CImageLoaderTEX.h + wallpaperengine/irr/CImageLoaderTEX.cpp + wallpaperengine/irr/CPkgReader.h + wallpaperengine/irr/CPkgReader.cpp + wallpaperengine/irr/CFileList.h + wallpaperengine/irr/CFileList.cpp + wallpaperengine/sound.cpp + wallpaperengine/sound.h +) -target_link_libraries(wallengine ${X11_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${IRRLICHT_LIBRARY} ${LZ4_LIBRARY}) \ No newline at end of file +target_link_libraries(wallengine ${X11_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${IRRLICHT_LIBRARY} ${LZ4_LIBRARY} ${SDL_LIBRARY} ${SDL_MIXER_LIBRARIES}) \ No newline at end of file diff --git a/README.md b/README.md index be43454..e3eef46 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Wallpaper Engine is a software designed by [Kristjan Skutta](https://store.steam - Irrlicht - LZ4 - ZLIB +- SDL +- SDL_mixer # 5. How to use ## 5.1. Pre-requirements diff --git a/main.cpp b/main.cpp index 92823ba..2243ca1 100644 --- a/main.cpp +++ b/main.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "wallpaperengine/shaders/compiler.h" #include "wallpaperengine/project.h" @@ -77,6 +79,7 @@ void preconfigure_wallpaper_engine () int main (int argc, char* argv[]) { int mode = 0; + bool audio_support = true; std::string path; // parse the integer if it exists @@ -93,12 +96,13 @@ int main (int argc, char* argv[]) {"win", required_argument, 0, 'w'}, {"pkg", required_argument, 0, 'p'}, {"dir", required_argument, 0, 'd'}, + {"silent", optional_argument, 0, 's'}, {nullptr, 0, 0, 0} }; while (true) { - int c = getopt_long (argc, argv, "w:p:d:", long_options, &option_index); + int c = getopt_long (argc, argv, "w:p:d:s", long_options, &option_index); if (c == -1) break; @@ -120,6 +124,10 @@ int main (int argc, char* argv[]) path = optarg; break; + case 's': + audio_support = false; + break; + default: break; } @@ -162,6 +170,20 @@ int main (int argc, char* argv[]) break; } + if (audio_support == true) + { + int mixer_flags = MIX_INIT_MP3 | MIX_INIT_FLAC | MIX_INIT_OGG; + + if (SDL_Init (SDL_INIT_AUDIO) < 0 || mixer_flags != Mix_Init (mixer_flags)) + { + wp::irrlicht::device->getLogger ()->log ("Cannot initialize SDL audio system", irr::ELL_ERROR); + return -1; + } + + // initialize audio engine + Mix_OpenAudio (22050, AUDIO_S16SYS, 2, 640); + } + wp::project* wp_project = new wp::project (project_path); if (wp_project->getScene ()->isOrthogonal() == true) @@ -200,6 +222,7 @@ int main (int argc, char* argv[]) } } + SDL_Quit (); delete wp_project; return 0; diff --git a/wallpaperengine/object.cpp b/wallpaperengine/object.cpp index 760d721..bffb834 100644 --- a/wallpaperengine/object.cpp +++ b/wallpaperengine/object.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace wp { @@ -65,6 +66,7 @@ namespace wp json::const_iterator image = json_data.find ("image"); json::const_iterator model = json_data.find ("model"); json::const_iterator particle = json_data.find ("particle"); + json::const_iterator sound = json_data.find ("sound"); object3d::Type _type = object3d::Type::Type_None; @@ -83,6 +85,11 @@ namespace wp _type = object3d::Type::Type_Particle; } + if (sound != json_data.end () && (*sound).is_null () == false) + { + _type = object3d::Type::Type_Sound; + } + // load the effects first so we have access to the textures needed json::const_iterator effects = json_data.find ("effects"); @@ -108,6 +115,10 @@ namespace wp case object3d::Type::Type_Particle: break; + + case object3d::Type::Type_Sound: + this->m_object3d = new wp::sound ((*sound), this); + break; } } diff --git a/wallpaperengine/object3d.h b/wallpaperengine/object3d.h index 828d027..092eecd 100644 --- a/wallpaperengine/object3d.h +++ b/wallpaperengine/object3d.h @@ -15,7 +15,8 @@ namespace wp Type_Material = 0, Type_Model = 1, Type_Particle = 2, - Type_None = 3 + Type_Sound = 3, + Type_None = 4 }; object3d (Type type, wp::object* parent); diff --git a/wallpaperengine/sound.cpp b/wallpaperengine/sound.cpp new file mode 100644 index 0000000..17d78dc --- /dev/null +++ b/wallpaperengine/sound.cpp @@ -0,0 +1,65 @@ +// +// Created by almamu on 17/05/19. +// + +#include +#include +#include "sound.h" +#include "irrlicht.h" + +namespace wp +{ + sound::sound (json json_data, wp::object* parent) : object3d (object3d::Type::Type_Material, parent) + { + json::const_iterator cur = json_data.begin (); + json::const_iterator end = json_data.end (); + + for (; cur != end; cur ++) + { + this->m_filenames.push_back ((*cur).get ()); + } + + this->play (); + } + + void sound::play () + { + std::vector::const_iterator cur = this->m_filenames.begin (); + std::vector::const_iterator end = this->m_filenames.end (); + + for (; cur != end; cur ++) + { + SDL_RWops* sdlRwops = nullptr; + Mix_Music* music = nullptr; + irr::io::IReadFile* readfile = wp::irrlicht::device->getFileSystem ()->createAndOpenFile ((*cur).c_str ()); + int filesize = readfile->getSize (); + char* filebuffer = new char [filesize]; + + readfile->read (filebuffer, filesize); + + sdlRwops = SDL_RWFromConstMem(filebuffer, filesize); + music = Mix_LoadMUS_RW (sdlRwops); + readfile->drop (); + + if (music == nullptr) + { + wp::irrlicht::device->getLogger ()->log ("Cannot load audio", Mix_GetError (), irr::ELL_ERROR); + } + + this->m_bufferReader.push_back (sdlRwops); + this->m_soundBuffer.push_back (filebuffer); + this->m_sdl.push_back (music); + } + + std::vector::const_iterator mixcur = this->m_sdl.begin (); + std::vector::const_iterator mixend = this->m_sdl.end (); + + for (; mixcur != mixend; mixcur ++) + { + if (Mix_PlayMusic ((*mixcur), -1) == -1) + { + wp::irrlicht::device->getLogger ()->log ("Cannot play audio", Mix_GetError (), irr::ELL_ERROR); + } + } + } +} \ No newline at end of file diff --git a/wallpaperengine/sound.h b/wallpaperengine/sound.h new file mode 100644 index 0000000..877e976 --- /dev/null +++ b/wallpaperengine/sound.h @@ -0,0 +1,31 @@ +#ifndef WALLENGINE_SOUND_H +#define WALLENGINE_SOUND_H + +#include +#include +#include + +#include +#include + +namespace wp +{ + using json = nlohmann::json; + + class sound : public wp::object3d + { + public: + sound (json json_data, wp::object* parent); + + void play (); + + private: + std::vector m_filenames; + std::vector m_sdl; + std::vector m_bufferReader; + std::vector m_soundBuffer; + }; +}; + + +#endif //WALLENGINE_SOUND_H