diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-10-01 21:22:30 +0200 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-10-01 21:22:30 +0200 |
commit | e0ea870fdfcfbe9e3f0e47215bb809d4353d88e2 (patch) | |
tree | 16f694c46ec4b76019187322da2bdd87906bf5ba | |
parent | 7230b630025886939c726e07eba1a0b35511f687 (diff) |
removed submodule and updating resource_manager
25 files changed, 280 insertions, 82 deletions
diff --git a/lib/SDL_image/CMakeLists.txt b/lib/SDL_image/CMakeLists.txt new file mode 100644 index 0000000..aaccd96 --- /dev/null +++ b/lib/SDL_image/CMakeLists.txt @@ -0,0 +1,97 @@ +cmake_minimum_required(VERSION 3.28) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 20) + +add_compile_definitions(WITH_SDL2) + +add_subdirectory(../sdl2 sdl2) + +project(soloud C CXX) + +add_library(soloud SHARED + src/src/audiosource/ay/chipplayer.cpp + src/src/audiosource/ay/sndbuffer.cpp + src/src/audiosource/ay/sndchip.cpp + src/src/audiosource/ay/sndrender.cpp + src/src/audiosource/ay/soloud_ay.cpp + src/src/audiosource/monotone/soloud_monotone.cpp + src/src/audiosource/noise/soloud_noise.cpp + src/src/audiosource/openmpt/soloud_openmpt.cpp + src/src/audiosource/openmpt/soloud_openmpt_dll.c + src/src/audiosource/sfxr/soloud_sfxr.cpp + src/src/audiosource/speech/darray.cpp + src/src/audiosource/speech/klatt.cpp + src/src/audiosource/speech/resonator.cpp + src/src/audiosource/speech/soloud_speech.cpp + src/src/audiosource/speech/tts.cpp + src/src/audiosource/tedsid/sid.cpp + src/src/audiosource/tedsid/soloud_tedsid.cpp + src/src/audiosource/tedsid/ted.cpp + src/src/audiosource/vic/soloud_vic.cpp + src/src/audiosource/vizsn/soloud_vizsn.cpp + src/src/audiosource/wav/dr_impl.cpp + src/src/audiosource/wav/soloud_wav.cpp + src/src/audiosource/wav/soloud_wavstream.cpp + src/src/audiosource/wav/stb_vorbis.c + + src/src/backend/alsa/soloud_alsa.cpp + src/src/backend/coreaudio/soloud_coreaudio.cpp + src/src/backend/jack/soloud_jack.cpp + src/src/backend/miniaudio/soloud_miniaudio.cpp + src/src/backend/nosound/soloud_nosound.cpp + src/src/backend/null/soloud_null.cpp + src/src/backend/openal/soloud_openal.cpp + src/src/backend/openal/soloud_openal_dll.c + src/src/backend/opensles/soloud_opensles.cpp + src/src/backend/oss/soloud_oss.cpp + src/src/backend/portaudio/soloud_portaudio.cpp + src/src/backend/portaudio/soloud_portaudio_dll.c + src/src/backend/sdl/soloud_sdl1.cpp + src/src/backend/sdl/soloud_sdl1_dll.c + src/src/backend/sdl/soloud_sdl2.cpp + src/src/backend/sdl/soloud_sdl2_dll.c + src/src/backend/sdl2_static/soloud_sdl2_static.cpp + src/src/backend/sdl_static/soloud_sdl_static.cpp + src/src/backend/wasapi/soloud_wasapi.cpp + src/src/backend/winmm/soloud_winmm.cpp + src/src/backend/xaudio2/soloud_xaudio2.cpp + + src/src/core/soloud.cpp + src/src/core/soloud_audiosource.cpp + src/src/core/soloud_bus.cpp + src/src/core/soloud_core_3d.cpp + src/src/core/soloud_core_basicops.cpp + src/src/core/soloud_core_faderops.cpp + src/src/core/soloud_core_filterops.cpp + src/src/core/soloud_core_getters.cpp + src/src/core/soloud_core_setters.cpp + src/src/core/soloud_core_voicegroup.cpp + src/src/core/soloud_core_voiceops.cpp + src/src/core/soloud_fader.cpp + src/src/core/soloud_fft.cpp + src/src/core/soloud_fft_lut.cpp + src/src/core/soloud_file.cpp + src/src/core/soloud_filter.cpp + src/src/core/soloud_misc.cpp + src/src/core/soloud_queue.cpp + src/src/core/soloud_thread.cpp + + # src/src/filter/soloud_bassboostfilter.cpp + # src/src/filter/soloud_biquadresonantfilter.cpp + # src/src/filter/soloud_dcremovalfilter.cpp + # src/src/filter/soloud_duckfilter.cpp + # src/src/filter/soloud_echofilter.cpp + # src/src/filter/soloud_eqfilter.cpp + # src/src/filter/soloud_fftfilter.cpp + # src/src/filter/soloud_flangerfilter.cpp + # src/src/filter/soloud_freeverbfilter.cpp + # src/src/filter/soloud_lofifilter.cpp + # src/src/filter/soloud_robotizefilter.cpp + # src/src/filter/soloud_waveshaperfilter.cpp +) +target_include_directories(soloud PRIVATE src/include) +target_include_directories(soloud SYSTEM INTERFACE src/include) + +target_link_libraries(soloud PRIVATE SDL2) + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cb310af..27e5188 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,7 @@ set(CMAKE_BUILD_TYPE Debug) add_compile_definitions(DEBUG) add_subdirectory(../lib/soloud soloud) +add_subdirectory(../lib/SDL_image SDL_image) project(crepe C CXX) @@ -21,6 +22,8 @@ target_include_directories(crepe # TODO: libraries should be linked as PRIVATE target_link_libraries(crepe PUBLIC soloud + PUBLIC SDL2 + PUBLIC SDL2_image ) add_subdirectory(crepe) @@ -30,5 +33,5 @@ install( FILE_SET HEADERS DESTINATION include/crepe ) -add_executable(dummy_rm dummy_resource_manager.cpp) +add_executable(dummy_rm dummy_audio.cpp) target_link_libraries(dummy_rm PUBLIC crepe) diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index ed6ebe5..69e67ac 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -1,14 +1,11 @@ target_sources(crepe PUBLIC - Sound.cpp - SoundContext.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES - Sound.h - SoundContext.h ) add_subdirectory(api) add_subdirectory(util) add_subdirectory(fabricator) +add_subdirectory(facade) diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index 4d1b093..f0d708a 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -1,6 +1,6 @@ #include "AudioSource.h" -#include "../Sound.h" +#include "facade/Sound.h" #include <memory> using namespace crepe::api; diff --git a/src/crepe/api/Audio_asset.cpp b/src/crepe/api/Audio_asset.cpp deleted file mode 100644 index a9b04ed..0000000 --- a/src/crepe/api/Audio_asset.cpp +++ /dev/null @@ -1,16 +0,0 @@ - - - - -#include "Audio_asset.h" -#include <string> - - -using namespace crepe::api; - -Audio::Audio(const std::string& content){ - this->m_content = content; -} - -Audio::~Audio(){ -} diff --git a/src/crepe/api/Audio_asset.h b/src/crepe/api/Audio_asset.h deleted file mode 100644 index 0b8e48e..0000000 --- a/src/crepe/api/Audio_asset.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - - -#include "resource.h" -#include <string> - - -namespace crepe::api { - - -class Audio : public Resource { - -public: - Audio(const std::string&); - ~Audio(); - -}; -} diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index 4f3fada..2cf0bcc 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -1,18 +1,17 @@ target_sources(crepe PUBLIC - Image_asset.cpp - map_asset.cpp - Audio_asset.cpp - spritesheet.cpp - resource_manager.cpp + #Image_asset.cpp + #map_asset.cpp + #spritesheet.cpp + #resource_manager.cpp + Resource.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES - resource.h - Image_asset.h - map_asset.h - Audio_asset.h - spritesheet.h - resource_manager.h + Resource.h + #Image_asset.h + #map_asset.h + #spritesheet.h + #resource_manager.h Component.h AudioSource.h ) diff --git a/src/crepe/api/Image_asset.h b/src/crepe/api/Image_asset.h index 69549af..0a36b0b 100644 --- a/src/crepe/api/Image_asset.h +++ b/src/crepe/api/Image_asset.h @@ -2,7 +2,7 @@ -#include "resource.h" +#include "Resource.h" #include <string> namespace crepe::api { diff --git a/src/crepe/api/map_asset.h b/src/crepe/api/map_asset.h index a3b994f..a4f3df7 100644 --- a/src/crepe/api/map_asset.h +++ b/src/crepe/api/map_asset.h @@ -1,6 +1,6 @@ #pragma once -#include "resource.h" +#include "Resource.h" #include <string> diff --git a/src/crepe/api/resource.h b/src/crepe/api/resource.h deleted file mode 100644 index e6456f9..0000000 --- a/src/crepe/api/resource.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - - -#include <string> - -namespace crepe::api { - -class Resource{ - -public: - - virtual ~Resource() =default; - - const std::string& getContent() const{ - return this->m_content; - } - -protected: - std::string m_content; -}; - - -} diff --git a/src/crepe/api/resource_manager.cpp b/src/crepe/api/resource_manager.cpp index a5644ee..0ecdae5 100644 --- a/src/crepe/api/resource_manager.cpp +++ b/src/crepe/api/resource_manager.cpp @@ -6,9 +6,9 @@ using namespace crepe::api; -ResourceManager* ResourceManager::get_instance(){ +ResourceManager& ResourceManager::get_instance(){ static ResourceManager instance; - return &instance; + return instance; } diff --git a/src/crepe/api/resource_manager.h b/src/crepe/api/resource_manager.h index 1b91524..5b0e0e1 100644 --- a/src/crepe/api/resource_manager.h +++ b/src/crepe/api/resource_manager.h @@ -8,7 +8,7 @@ #include <utility> -#include "api/resource.h" +#include "Resource.h" #include "fabricator/resource_fabricator.h" diff --git a/src/crepe/api/spritesheet.h b/src/crepe/api/spritesheet.h index 7f49156..e7530c2 100644 --- a/src/crepe/api/spritesheet.h +++ b/src/crepe/api/spritesheet.h @@ -3,7 +3,7 @@ -#include "resource.h" +#include "Resource.h" #include <string> diff --git a/src/crepe/fabricator/resource_fabricator.h b/src/crepe/fabricator/resource_fabricator.h index 9299ed3..2b0030d 100644 --- a/src/crepe/fabricator/resource_fabricator.h +++ b/src/crepe/fabricator/resource_fabricator.h @@ -2,7 +2,7 @@ -#include "api/resource.h" +#include "api/Resource.h" #include <memory> #include <string> diff --git a/src/crepe/facade/CMakeLists.txt b/src/crepe/facade/CMakeLists.txt new file mode 100644 index 0000000..1263683 --- /dev/null +++ b/src/crepe/facade/CMakeLists.txt @@ -0,0 +1,13 @@ +target_sources(crepe PUBLIC + Sound.cpp + SoundContext.cpp + Texture.cpp + SdlContext.cpp +) + +target_sources(crepe PUBLIC FILE_SET HEADERS FILES + Sound.h + SoundContext.h + Texture.h + SdlContext.h +) diff --git a/src/crepe/facade/SdlContext.cpp b/src/crepe/facade/SdlContext.cpp new file mode 100644 index 0000000..fc68b40 --- /dev/null +++ b/src/crepe/facade/SdlContext.cpp @@ -0,0 +1,57 @@ + + +#include "SdlContext.h" +#include <SDL2/SDL.h> +#include <SDL2/SDL_render.h> +#include <SDL2/SDL_surface.h> +#include <SDL2/SDL_video.h> +#include <SDL2/SDL_image.h> + +using namespace crepe; + + +SdlContext& SdlContext::get_instance(){ + static SdlContext instance; + return instance; +} + + +SdlContext::SdlContext(){ + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + std::cerr << "SDL could not initialize! SDL_Error: " << SDL_GetError() << std::endl; + return; + } + + m_game_window = SDL_CreateWindow("Crepe Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN); + if (!m_game_window) { + std::cerr << "Window could not be created! SDL_Error: " << SDL_GetError() << std::endl; + } + + m_game_renderer = SDL_CreateRenderer(m_game_window, -1, SDL_RENDERER_ACCELERATED); + if (!m_game_renderer) { + std::cerr << "Renderer could not be created! SDL_Error: " << SDL_GetError() << std::endl; + SDL_DestroyWindow(m_game_window); + return; + } + + IMG_Init(IMG_INIT_PNG); +} + +SdlContext::~SdlContext(){ + if(m_game_renderer) + SDL_DestroyRenderer(m_game_renderer); + + if (m_game_window) { + SDL_DestroyWindow(m_game_window); + } + IMG_Quit(); +} + + +SDL_Texture* SdlContext::setTextureFromPath(const char* path){ + SDL_Surface* tmp = IMG_Load(path); + SDL_Texture* CreatedTexture = SDL_CreateTextureFromSurface(m_game_renderer, tmp); + SDL_FreeSurface(tmp); + + return CreatedTexture; +} diff --git a/src/crepe/facade/SdlContext.h b/src/crepe/facade/SdlContext.h new file mode 100644 index 0000000..c275300 --- /dev/null +++ b/src/crepe/facade/SdlContext.h @@ -0,0 +1,33 @@ +#pragma once + +#include "Texture.h" +#include <SDL2/SDL_render.h> +#include <SDL2/SDL_video.h> +#include <string> + +namespace crepe { + +class SdlContext { + +private: + SdlContext(); + virtual ~SdlContext(); + + // singleton + static SdlContext & get_instance(); + SdlContext(const SdlContext &) = delete; + SdlContext(SdlContext &&) = delete; + SdlContext & operator=(const SdlContext &) = delete; + SdlContext & operator=(SdlContext &&) = delete; + + SDL_Texture* setTextureFromPath(const char*); + +private: + friend class Texture; + + SDL_Window* m_game_window; + SDL_Renderer* m_game_renderer; +}; + +} // + diff --git a/src/crepe/Sound.cpp b/src/crepe/facade/Sound.cpp index e1150ac..e1150ac 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/facade/Sound.cpp diff --git a/src/crepe/Sound.h b/src/crepe/facade/Sound.h index ac93991..ac93991 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/facade/Sound.h diff --git a/src/crepe/SoundContext.cpp b/src/crepe/facade/SoundContext.cpp index 72047d2..72047d2 100644 --- a/src/crepe/SoundContext.cpp +++ b/src/crepe/facade/SoundContext.cpp diff --git a/src/crepe/SoundContext.h b/src/crepe/facade/SoundContext.h index 090966d..090966d 100644 --- a/src/crepe/SoundContext.h +++ b/src/crepe/facade/SoundContext.h diff --git a/src/crepe/facade/Texture.cpp b/src/crepe/facade/Texture.cpp new file mode 100644 index 0000000..c24312a --- /dev/null +++ b/src/crepe/facade/Texture.cpp @@ -0,0 +1,31 @@ + + +#include "util/log.h" + +#include "Texture.h" +#include "SdlContext.h" +#include <SDL2/SDL_render.h> + +using namespace crepe; + +Texture::Texture(std::unique_ptr<api::Resource> res) { + dbg_trace(); + this->load(std::move(res)); +} + +Texture::Texture(const char * src) { + dbg_trace(); + this->load(std::make_unique<api::Resource>(src)); +} + +Texture::~Texture(){ + dbg_trace(); + if(this->m_texture){ + SDL_DestroyTexture(m_texture); + } +} +void Texture::load(std::unique_ptr<api::Resource> res) { + SdlContext& ctx = SdlContext::get_instance(); + m_texture = ctx.setTextureFromPath(res->canonical()); +} + diff --git a/src/crepe/facade/Texture.h b/src/crepe/facade/Texture.h new file mode 100644 index 0000000..3677f6e --- /dev/null +++ b/src/crepe/facade/Texture.h @@ -0,0 +1,25 @@ +#pragma once + +#include "api/Resource.h" +#include <SDL2/SDL_render.h> +#include <memory> + + +namespace crepe { + +class Texture { + +public: + Texture(const char * src); + Texture(std::unique_ptr<api::Resource> res); + ~Texture(); + +private: + void load(std::unique_ptr<api::Resource> res); + +private: + SDL_Texture* m_texture; +}; + +} // namespace crepe + diff --git a/src/crepe/facade/touch b/src/crepe/facade/touch new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/crepe/facade/touch diff --git a/src/dummy_audio.cpp b/src/dummy_audio.cpp index 049bb49..211a503 100644 --- a/src/dummy_audio.cpp +++ b/src/dummy_audio.cpp @@ -1,4 +1,4 @@ -#include "crepe/Sound.h" +#include "crepe/facade/Sound.h" #include "crepe/util/log.h" #include <chrono> |