From de288a859a631acf6aac10fad825cafaa3744dc9 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 1 Oct 2024 15:21:31 +0200 Subject: fix audio segfault --- src/crepe/Sound.cpp | 2 +- src/crepe/Sound.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 09ffd5f..136a71d 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -16,7 +16,7 @@ Sound::Sound(const char * src) { } void Sound::load(std::unique_ptr res) { - this->sample.load(this->res->canonical()); + this->sample.load(res->canonical()); } void Sound::play() { diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h index 163c5b4..9da17b9 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/Sound.h @@ -60,7 +60,6 @@ private: void load(std::unique_ptr res); private: - std::unique_ptr res; SoLoud::Wav sample; SoLoud::handle handle; }; -- cgit v1.2.3 From 311e98572c26750e4a4695079fa80ca5648d109e Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 1 Oct 2024 17:21:37 +0200 Subject: implement remaining Sound functions --- src/crepe/Sound.cpp | 29 ++++++++++++++++++++++++++--- src/crepe/Sound.h | 15 +++++++++++++++ src/crepe/SoundSystem.cpp | 2 +- src/crepe/SoundSystem.h | 2 +- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 136a71d..20f1787 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -20,19 +20,42 @@ void Sound::load(std::unique_ptr res) { } void Sound::play() { - SoundSystem & system = SoundSystem::instance(); + SoundSystem & system = SoundSystem::get_instance(); if (system.engine.getPause(this->handle)) { // resume if paused system.engine.setPause(this->handle, false); } else { // or start new sound - this->handle = system.engine.play(this->sample); + this->handle = system.engine.play(this->sample, this->volume); + system.engine.setLooping(this->handle, this->looping); } } void Sound::pause() { - SoundSystem & system = SoundSystem::instance(); + SoundSystem & system = SoundSystem::get_instance(); if (system.engine.getPause(this->handle)) return; system.engine.setPause(this->handle, true); } +void Sound::rewind() { + SoundSystem & system = SoundSystem::get_instance(); + if (!system.engine.isValidVoiceHandle(this->handle)) return; + system.engine.seek(this->handle, 0); +} + +void Sound::set_volume(float volume) { + this->volume = volume; + + SoundSystem & system = SoundSystem::get_instance(); + if (!system.engine.isValidVoiceHandle(this->handle)) return; + system.engine.setVolume(this->handle, this->volume); +} + +void Sound::set_looping(bool looping) { + this->looping = looping; + + SoundSystem & system = SoundSystem::get_instance(); + if (!system.engine.isValidVoiceHandle(this->handle)) return; + system.engine.setLooping(this->handle, this->looping); +} + diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h index 9da17b9..4c51188 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/Sound.h @@ -45,12 +45,24 @@ public: * \param volume Volume (0 = muted, 1 = full volume) */ void set_volume(float volume); + /** + * \brief Get playback volume / gain + * + * \return Volume + */ + float get_volume() const { return this->volume; } /** * \brief Set looping behavior for this sample * * \param looping Looping behavior (false = one-shot, true = loop) */ void set_looping(bool looping); + /** + * \brief Get looping behavior + * + * \return true if looping, false if one-shot + */ + bool get_looping() const { return this->looping; } public: Sound(const char * src); @@ -62,6 +74,9 @@ private: private: SoLoud::Wav sample; SoLoud::handle handle; + + float volume = 1.0f; + bool looping = false; }; } diff --git a/src/crepe/SoundSystem.cpp b/src/crepe/SoundSystem.cpp index 00f874c..b57e51a 100644 --- a/src/crepe/SoundSystem.cpp +++ b/src/crepe/SoundSystem.cpp @@ -4,7 +4,7 @@ using namespace crepe; -SoundSystem & SoundSystem::instance() { +SoundSystem & SoundSystem::get_instance() { static SoundSystem instance; return instance; } diff --git a/src/crepe/SoundSystem.h b/src/crepe/SoundSystem.h index da3927a..34dd6c5 100644 --- a/src/crepe/SoundSystem.h +++ b/src/crepe/SoundSystem.h @@ -12,7 +12,7 @@ private: virtual ~SoundSystem(); // singleton - static SoundSystem & instance(); + static SoundSystem & get_instance(); SoundSystem(const SoundSystem &) = delete; SoundSystem(SoundSystem &&) = delete; SoundSystem &operator=(const SoundSystem &) = delete; -- cgit v1.2.3 From fe9bf1344ceae0fac9144e4a28fdcdbcb2267850 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 1 Oct 2024 17:23:33 +0200 Subject: rename SoundSystem to SoundContext (1/2) --- src/crepe/SoundContext.cpp | 21 +++++++++++++++++++++ src/crepe/SoundContext.h | 27 +++++++++++++++++++++++++++ src/crepe/SoundSystem.cpp | 21 --------------------- src/crepe/SoundSystem.h | 27 --------------------------- 4 files changed, 48 insertions(+), 48 deletions(-) create mode 100644 src/crepe/SoundContext.cpp create mode 100644 src/crepe/SoundContext.h delete mode 100644 src/crepe/SoundSystem.cpp delete mode 100644 src/crepe/SoundSystem.h diff --git a/src/crepe/SoundContext.cpp b/src/crepe/SoundContext.cpp new file mode 100644 index 0000000..b57e51a --- /dev/null +++ b/src/crepe/SoundContext.cpp @@ -0,0 +1,21 @@ +#include "util/log.h" + +#include "SoundSystem.h" + +using namespace crepe; + +SoundSystem & SoundSystem::get_instance() { + static SoundSystem instance; + return instance; +} + +SoundSystem::SoundSystem() { + dbg_trace(); + engine.init(); +} + +SoundSystem::~SoundSystem() { + dbg_trace(); + engine.deinit(); +} + diff --git a/src/crepe/SoundContext.h b/src/crepe/SoundContext.h new file mode 100644 index 0000000..34dd6c5 --- /dev/null +++ b/src/crepe/SoundContext.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +#include "Sound.h" + +namespace crepe { + +class SoundSystem { +private: + SoundSystem(); + virtual ~SoundSystem(); + + // singleton + static SoundSystem & get_instance(); + SoundSystem(const SoundSystem &) = delete; + SoundSystem(SoundSystem &&) = delete; + SoundSystem &operator=(const SoundSystem &) = delete; + SoundSystem &operator=(SoundSystem &&) = delete; + +private: + SoLoud::Soloud engine; + friend class Sound; +}; + +} + diff --git a/src/crepe/SoundSystem.cpp b/src/crepe/SoundSystem.cpp deleted file mode 100644 index b57e51a..0000000 --- a/src/crepe/SoundSystem.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "util/log.h" - -#include "SoundSystem.h" - -using namespace crepe; - -SoundSystem & SoundSystem::get_instance() { - static SoundSystem instance; - return instance; -} - -SoundSystem::SoundSystem() { - dbg_trace(); - engine.init(); -} - -SoundSystem::~SoundSystem() { - dbg_trace(); - engine.deinit(); -} - diff --git a/src/crepe/SoundSystem.h b/src/crepe/SoundSystem.h deleted file mode 100644 index 34dd6c5..0000000 --- a/src/crepe/SoundSystem.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -#include "Sound.h" - -namespace crepe { - -class SoundSystem { -private: - SoundSystem(); - virtual ~SoundSystem(); - - // singleton - static SoundSystem & get_instance(); - SoundSystem(const SoundSystem &) = delete; - SoundSystem(SoundSystem &&) = delete; - SoundSystem &operator=(const SoundSystem &) = delete; - SoundSystem &operator=(SoundSystem &&) = delete; - -private: - SoLoud::Soloud engine; - friend class Sound; -}; - -} - -- cgit v1.2.3 From 8e67adc6828181b1df7c95da76f32962444fc7fd Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 1 Oct 2024 17:25:06 +0200 Subject: rename SoundSystem to SoundContext (2/2) --- src/crepe/CMakeLists.txt | 4 ++-- src/crepe/Sound.cpp | 36 ++++++++++++++++++------------------ src/crepe/SoundContext.cpp | 10 +++++----- src/crepe/SoundContext.h | 16 ++++++++-------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index 9f7c91c..3a60840 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -1,11 +1,11 @@ target_sources(crepe PUBLIC Sound.cpp - SoundSystem.cpp + SoundContext.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES Sound.h - SoundSystem.h + SoundContext.h ) add_subdirectory(api) diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 20f1787..1758282 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -1,7 +1,7 @@ #include "util/log.h" #include "Sound.h" -#include "SoundSystem.h" +#include "SoundContext.h" using namespace crepe; @@ -20,42 +20,42 @@ void Sound::load(std::unique_ptr res) { } void Sound::play() { - SoundSystem & system = SoundSystem::get_instance(); - if (system.engine.getPause(this->handle)) { + SoundContext & ctx = SoundContext::get_instance(); + if (ctx.engine.getPause(this->handle)) { // resume if paused - system.engine.setPause(this->handle, false); + ctx.engine.setPause(this->handle, false); } else { // or start new sound - this->handle = system.engine.play(this->sample, this->volume); - system.engine.setLooping(this->handle, this->looping); + this->handle = ctx.engine.play(this->sample, this->volume); + ctx.engine.setLooping(this->handle, this->looping); } } void Sound::pause() { - SoundSystem & system = SoundSystem::get_instance(); - if (system.engine.getPause(this->handle)) return; - system.engine.setPause(this->handle, true); + SoundContext & ctx = SoundContext::get_instance(); + if (ctx.engine.getPause(this->handle)) return; + ctx.engine.setPause(this->handle, true); } void Sound::rewind() { - SoundSystem & system = SoundSystem::get_instance(); - if (!system.engine.isValidVoiceHandle(this->handle)) return; - system.engine.seek(this->handle, 0); + SoundContext & ctx = SoundContext::get_instance(); + if (!ctx.engine.isValidVoiceHandle(this->handle)) return; + ctx.engine.seek(this->handle, 0); } void Sound::set_volume(float volume) { this->volume = volume; - SoundSystem & system = SoundSystem::get_instance(); - if (!system.engine.isValidVoiceHandle(this->handle)) return; - system.engine.setVolume(this->handle, this->volume); + SoundContext & ctx = SoundContext::get_instance(); + if (!ctx.engine.isValidVoiceHandle(this->handle)) return; + ctx.engine.setVolume(this->handle, this->volume); } void Sound::set_looping(bool looping) { this->looping = looping; - SoundSystem & system = SoundSystem::get_instance(); - if (!system.engine.isValidVoiceHandle(this->handle)) return; - system.engine.setLooping(this->handle, this->looping); + SoundContext & ctx = SoundContext::get_instance(); + if (!ctx.engine.isValidVoiceHandle(this->handle)) return; + ctx.engine.setLooping(this->handle, this->looping); } diff --git a/src/crepe/SoundContext.cpp b/src/crepe/SoundContext.cpp index b57e51a..cfb7d82 100644 --- a/src/crepe/SoundContext.cpp +++ b/src/crepe/SoundContext.cpp @@ -1,20 +1,20 @@ #include "util/log.h" -#include "SoundSystem.h" +#include "SoundContext.h" using namespace crepe; -SoundSystem & SoundSystem::get_instance() { - static SoundSystem instance; +SoundContext & SoundContext::get_instance() { + static SoundContext instance; return instance; } -SoundSystem::SoundSystem() { +SoundContext::SoundContext() { dbg_trace(); engine.init(); } -SoundSystem::~SoundSystem() { +SoundContext::~SoundContext() { dbg_trace(); engine.deinit(); } diff --git a/src/crepe/SoundContext.h b/src/crepe/SoundContext.h index 34dd6c5..d361d83 100644 --- a/src/crepe/SoundContext.h +++ b/src/crepe/SoundContext.h @@ -6,17 +6,17 @@ namespace crepe { -class SoundSystem { +class SoundContext { private: - SoundSystem(); - virtual ~SoundSystem(); + SoundContext(); + virtual ~SoundContext(); // singleton - static SoundSystem & get_instance(); - SoundSystem(const SoundSystem &) = delete; - SoundSystem(SoundSystem &&) = delete; - SoundSystem &operator=(const SoundSystem &) = delete; - SoundSystem &operator=(SoundSystem &&) = delete; + static SoundContext & get_instance(); + SoundContext(const SoundContext &) = delete; + SoundContext(SoundContext &&) = delete; + SoundContext &operator=(const SoundContext &) = delete; + SoundContext &operator=(SoundContext &&) = delete; private: SoLoud::Soloud engine; -- cgit v1.2.3 From 65eda52aa51017f6f7aad158c4f8b6e91054cf0d Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 1 Oct 2024 17:27:14 +0200 Subject: `make format` --- mwe/audio/soloud/main.cpp | 3 +-- mwe/dynlink/exec/main.c | 1 - src/crepe/Sound.cpp | 1 - src/crepe/Sound.h | 3 +-- src/crepe/SoundContext.cpp | 1 - src/crepe/SoundContext.h | 7 +++---- src/crepe/api/AudioSource.cpp | 5 +---- src/crepe/api/AudioSource.h | 3 +-- src/crepe/api/Component.h | 3 +-- src/crepe/api/Resource.cpp | 9 ++------- src/crepe/api/Resource.h | 5 ++--- src/crepe/util/color.h | 3 +-- src/crepe/util/log.cpp | 1 - src/crepe/util/log.h | 20 ++++++++++---------- src/dummy_audio.cpp | 3 +-- test/audio.cpp | 3 +-- 16 files changed, 25 insertions(+), 46 deletions(-) diff --git a/mwe/audio/soloud/main.cpp b/mwe/audio/soloud/main.cpp index 25ba003..50df0b7 100644 --- a/mwe/audio/soloud/main.cpp +++ b/mwe/audio/soloud/main.cpp @@ -38,8 +38,7 @@ int main() { this_thread::sleep_for(500ms); // play all samples simultaniously - for (unsigned i = 0; i < 3; i++) - soloud.play(sfx[i]); + for (unsigned i = 0; i < 3; i++) soloud.play(sfx[i]); this_thread::sleep_for(1000ms); // stop all audio and exit diff --git a/mwe/dynlink/exec/main.c b/mwe/dynlink/exec/main.c index ea55feb..ff884f2 100644 --- a/mwe/dynlink/exec/main.c +++ b/mwe/dynlink/exec/main.c @@ -5,4 +5,3 @@ int main() { return 0; } - diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 1758282..e1150ac 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -58,4 +58,3 @@ void Sound::set_looping(bool looping) { if (!ctx.engine.isValidVoiceHandle(this->handle)) return; ctx.engine.setLooping(this->handle, this->looping); } - diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h index 4c51188..ac93991 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/Sound.h @@ -79,5 +79,4 @@ private: bool looping = false; }; -} - +} // namespace crepe diff --git a/src/crepe/SoundContext.cpp b/src/crepe/SoundContext.cpp index cfb7d82..72047d2 100644 --- a/src/crepe/SoundContext.cpp +++ b/src/crepe/SoundContext.cpp @@ -18,4 +18,3 @@ SoundContext::~SoundContext() { dbg_trace(); engine.deinit(); } - diff --git a/src/crepe/SoundContext.h b/src/crepe/SoundContext.h index d361d83..090966d 100644 --- a/src/crepe/SoundContext.h +++ b/src/crepe/SoundContext.h @@ -15,13 +15,12 @@ private: static SoundContext & get_instance(); SoundContext(const SoundContext &) = delete; SoundContext(SoundContext &&) = delete; - SoundContext &operator=(const SoundContext &) = delete; - SoundContext &operator=(SoundContext &&) = delete; + SoundContext & operator=(const SoundContext &) = delete; + SoundContext & operator=(SoundContext &&) = delete; private: SoLoud::Soloud engine; friend class Sound; }; -} - +} // namespace crepe diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index cbde79f..4d1b093 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -9,9 +9,7 @@ AudioSource::AudioSource(std::unique_ptr audio_clip) { this->_sound = std::make_unique(std::move(audio_clip)); } -void AudioSource::play() { - return this->play(false); -} +void AudioSource::play() { return this->play(false); } void AudioSource::play(bool looping) { this->_sound->set_looping(looping); @@ -22,4 +20,3 @@ void AudioSource::stop() { this->_sound->pause(); this->_sound->rewind(); } - diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index 6a038be..4300c48 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -38,5 +38,4 @@ private: std::unique_ptr _sound; }; -} - +} // namespace crepe::api diff --git a/src/crepe/api/Component.h b/src/crepe/api/Component.h index 2abb461..d5e0499 100644 --- a/src/crepe/api/Component.h +++ b/src/crepe/api/Component.h @@ -7,5 +7,4 @@ public: bool active; }; -} - +} // namespace crepe::api diff --git a/src/crepe/api/Resource.cpp b/src/crepe/api/Resource.cpp index 6bb081d..1a647ce 100644 --- a/src/crepe/api/Resource.cpp +++ b/src/crepe/api/Resource.cpp @@ -9,11 +9,6 @@ Resource::Resource(const std::string & src) { this->file = std::ifstream(this->src, std::ios::in | std::ios::binary); } -const std::istream & Resource::read() { - return this->file; -} - -const char * Resource::canonical() { - return this->src.c_str(); -} +const std::istream & Resource::read() { return this->file; } +const char * Resource::canonical() { return this->src.c_str(); } diff --git a/src/crepe/api/Resource.h b/src/crepe/api/Resource.h index 2b62ff9..f2b2a0e 100644 --- a/src/crepe/api/Resource.h +++ b/src/crepe/api/Resource.h @@ -1,8 +1,8 @@ #pragma once -#include #include #include +#include namespace crepe::api { @@ -21,5 +21,4 @@ private: std::ifstream file; }; -} - +} // namespace crepe::api diff --git a/src/crepe/util/color.h b/src/crepe/util/color.h index 1af6c8f..066c9d3 100644 --- a/src/crepe/util/color.h +++ b/src/crepe/util/color.h @@ -38,5 +38,4 @@ constexpr const char * BG_MAGENTA_BRIGHT = "\e[105m"; constexpr const char * BG_CYAN_BRIGHT = "\e[106m"; constexpr const char * BG_WHITE_BRIGHT = "\e[107m"; -} - +} // namespace crepe::util::color diff --git a/src/crepe/util/log.cpp b/src/crepe/util/log.cpp index 796df49..6829ec3 100644 --- a/src/crepe/util/log.cpp +++ b/src/crepe/util/log.cpp @@ -48,4 +48,3 @@ void crepe::util::logf(log_level level, const char * fmt, ...) { va_logf(level, args, fmt); va_end(args); } - diff --git a/src/crepe/util/log.h b/src/crepe/util/log.h index 5295cb9..4cab338 100644 --- a/src/crepe/util/log.h +++ b/src/crepe/util/log.h @@ -8,12 +8,9 @@ // utility macros #define _crepe_logf_here(fmt, ...) \ crepe::util::logf(util::log_level::debug, "%s%s (%s:%d)" fmt "\n", \ - crepe::util::color::FG_WHITE, \ - __PRETTY_FUNCTION__, \ - __FILE_NAME__, \ - __LINE__, \ - crepe::util::color::RESET, \ - __VA_ARGS__) + crepe::util::color::FG_WHITE, __PRETTY_FUNCTION__, \ + __FILE_NAME__, __LINE__, crepe::util::color::RESET, \ + __VA_ARGS__) #define dbg_logf(fmt, ...) _crepe_logf_here(": " fmt, __VA_ARGS__) #define dbg_log(str) _crepe_logf_here(": %s", str) @@ -23,11 +20,14 @@ namespace crepe::util { -enum log_level { debug, info, warning, error, }; +enum log_level { + debug, + info, + warning, + error, +}; void logf(const char * fmt, ...); void logf(enum log_level level, const char * fmt, ...); -} - - +} // namespace crepe::util diff --git a/src/dummy_audio.cpp b/src/dummy_audio.cpp index 1249076..049bb49 100644 --- a/src/dummy_audio.cpp +++ b/src/dummy_audio.cpp @@ -1,5 +1,5 @@ -#include "crepe/util/log.h" #include "crepe/Sound.h" +#include "crepe/util/log.h" #include #include @@ -38,4 +38,3 @@ int main() { return 0; } - diff --git a/test/audio.cpp b/test/audio.cpp index a415919..47c5e84 100644 --- a/test/audio.cpp +++ b/test/audio.cpp @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include @@ -26,4 +26,3 @@ TEST(audio, play) { ASSERT_TRUE(true); } - -- cgit v1.2.3 From f4bb6d57cc88a7e25b3a5f43faafa49a7f500b7c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 5 Oct 2024 14:16:57 +0200 Subject: restructure unit tests and dummies --- readme.md | 3 ++- src/CMakeLists.txt | 11 +++++++--- src/crepe/Sound.cpp | 1 + src/dummy_audio.cpp | 40 ------------------------------------ src/example/CMakeLists.txt | 3 +++ src/example/audio_internal.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++ src/readme.md | 8 ++++++++ src/test/CMakeLists.txt | 5 +++++ src/test/audio.cpp | 29 ++++++++++++++++++++++++++ src/test/dummy.cpp | 4 ++++ test/CMakeLists.txt | 23 --------------------- test/audio.cpp | 28 ------------------------- test/dummy.cpp | 3 --- 13 files changed, 106 insertions(+), 98 deletions(-) delete mode 100644 src/dummy_audio.cpp create mode 100644 src/example/CMakeLists.txt create mode 100644 src/example/audio_internal.cpp create mode 100644 src/readme.md create mode 100644 src/test/CMakeLists.txt create mode 100644 src/test/audio.cpp create mode 100644 src/test/dummy.cpp delete mode 100644 test/CMakeLists.txt delete mode 100644 test/audio.cpp delete mode 100644 test/dummy.cpp diff --git a/readme.md b/readme.md index f3aab09..5351dfe 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,8 @@ This repository contains: |`lib/`|third-party libraries as git submodules| |`mwe/`|minimal working examples and proof-of-concepts| |`src/crepe/`|game engine source code| -|`test/`|game engine unit tests| +|`src/test/`|unit tests| +|`src/example`|standalone examples using game engine| ## Compilation diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 232d330..62ca9a0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,10 +9,12 @@ set(CMAKE_BUILD_TYPE Debug) add_compile_definitions(DEBUG) add_subdirectory(../lib/soloud soloud) +add_subdirectory(../lib/googletest googletest) project(crepe C CXX) add_library(crepe SHARED) +add_executable(test_main EXCLUDE_FROM_ALL) target_include_directories(crepe PUBLIC SYSTEM INTERFACE . @@ -24,13 +26,16 @@ target_link_libraries(crepe ) add_subdirectory(crepe) +add_subdirectory(test) +add_subdirectory(example) install( TARGETS crepe FILE_SET HEADERS DESTINATION include/crepe ) - -add_executable(dummy_audio dummy_audio.cpp) -target_link_libraries(dummy_audio PUBLIC crepe) +target_link_libraries(test_main + PRIVATE gtest_main + PUBLIC crepe +) diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index e1150ac..1758282 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -58,3 +58,4 @@ void Sound::set_looping(bool looping) { if (!ctx.engine.isValidVoiceHandle(this->handle)) return; ctx.engine.setLooping(this->handle, this->looping); } + diff --git a/src/dummy_audio.cpp b/src/dummy_audio.cpp deleted file mode 100644 index 049bb49..0000000 --- a/src/dummy_audio.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "crepe/Sound.h" -#include "crepe/util/log.h" - -#include -#include - -using namespace crepe; -using namespace std; -using namespace std::chrono_literals; -using std::make_unique; - -int main() { - dbg_trace(); - - auto bgm = Sound("../mwe/audio/bgm.ogg"); - auto sfx1 = Sound("../mwe/audio/sfx1.wav"); - auto sfx2 = Sound("../mwe/audio/sfx2.wav"); - auto sfx3 = Sound("../mwe/audio/sfx3.wav"); - - bgm.play(); - - // play each sample sequentially - this_thread::sleep_for(500ms); - sfx1.play(); - this_thread::sleep_for(500ms); - sfx2.play(); - bgm.pause(); - this_thread::sleep_for(500ms); - sfx3.play(); - bgm.play(); - this_thread::sleep_for(500ms); - - // play all samples simultaniously - sfx1.play(); - sfx2.play(); - sfx3.play(); - this_thread::sleep_for(1000ms); - - return 0; -} diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt new file mode 100644 index 0000000..bcc9271 --- /dev/null +++ b/src/example/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(audio_internal EXCLUDE_FROM_ALL audio_internal.cpp) +target_link_libraries(audio_internal PUBLIC crepe) + diff --git a/src/example/audio_internal.cpp b/src/example/audio_internal.cpp new file mode 100644 index 0000000..09bd55c --- /dev/null +++ b/src/example/audio_internal.cpp @@ -0,0 +1,46 @@ +/** \file + * + * Standalone example for usage of the internal \c Sound class. + */ + +#include +#include + +#include +#include + +using namespace crepe; +using namespace std; +using namespace std::chrono_literals; +using std::make_unique; + +int main() { + dbg_trace(); + + auto bgm = Sound("../mwe/audio/bgm.ogg"); + auto sfx1 = Sound("../mwe/audio/sfx1.wav"); + auto sfx2 = Sound("../mwe/audio/sfx2.wav"); + auto sfx3 = Sound("../mwe/audio/sfx3.wav"); + + bgm.play(); + + // play each sample sequentially + this_thread::sleep_for(500ms); + sfx1.play(); + this_thread::sleep_for(500ms); + sfx2.play(); + bgm.pause(); + this_thread::sleep_for(500ms); + sfx3.play(); + bgm.play(); + this_thread::sleep_for(500ms); + + // play all samples simultaniously + sfx1.play(); + sfx2.play(); + sfx3.play(); + this_thread::sleep_for(1000ms); + + return 0; +} + diff --git a/src/readme.md b/src/readme.md new file mode 100644 index 0000000..1c5d3a2 --- /dev/null +++ b/src/readme.md @@ -0,0 +1,8 @@ +# engine source + +This folder contains the crêpe engine source files, unit tests, and some toy +examples. The only target built by default by the CMakeLists.txt in this folder +is the crêpe shared library object. Unit tests can be built by explicitly +specifying the target `test_main` when running the build command. Each source +file in the example/ folder corresponds to a CMake target as well. + diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt new file mode 100644 index 0000000..0d316d6 --- /dev/null +++ b/src/test/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources(test_main PUBLIC + dummy.cpp + # audio.cpp +) + diff --git a/src/test/audio.cpp b/src/test/audio.cpp new file mode 100644 index 0000000..5bb2607 --- /dev/null +++ b/src/test/audio.cpp @@ -0,0 +1,29 @@ +#include +#include + +#include +#include + +#include +#include + +using namespace std; +using namespace std::chrono_literals; + +using namespace crepe::api; + +// TODO: mock internal audio class + +TEST(audio, play) { + auto res = std::make_unique("../mwe/audio/bgm.ogg"); + auto bgm = AudioSource(std::move(res)); + + bgm.play(); + + this_thread::sleep_for(2s); + + bgm.stop(); + + ASSERT_TRUE(true); +} + diff --git a/src/test/dummy.cpp b/src/test/dummy.cpp new file mode 100644 index 0000000..7f4c083 --- /dev/null +++ b/src/test/dummy.cpp @@ -0,0 +1,4 @@ +#include + +TEST(dummy, foo) { ASSERT_TRUE(1); } + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index f015570..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -cmake_minimum_required(VERSION 3.28) - -set(CMAKE_C_STANDARD 11) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_EXPORT_COMPILE_COMMANDS 1) - -set(CMAKE_BUILD_TYPE Debug) - -project(test C CXX) - -add_subdirectory(../lib/googletest googletest) -add_subdirectory(../src crepe) - -add_executable(test - dummy.cpp - # audio.cpp -) - -target_link_libraries(test - PRIVATE gtest_main - PUBLIC crepe # TODO: this does not work properly -) - diff --git a/test/audio.cpp b/test/audio.cpp deleted file mode 100644 index 47c5e84..0000000 --- a/test/audio.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -#include -#include - -#include -#include - -using namespace std; -using namespace std::chrono_literals; - -using namespace crepe::api; - -// TODO: mock internal audio class - -TEST(audio, play) { - auto res = std::make_unique("../mwe/audio/bgm.ogg"); - auto bgm = AudioSource(std::move(res)); - - bgm.play(); - - this_thread::sleep_for(2s); - - bgm.stop(); - - ASSERT_TRUE(true); -} diff --git a/test/dummy.cpp b/test/dummy.cpp deleted file mode 100644 index a00a9c6..0000000 --- a/test/dummy.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -TEST(dummy, foo) { ASSERT_TRUE(1); } -- cgit v1.2.3 From 202a9ec288ded78771e1f7e4c711a7612b201b9d Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 5 Oct 2024 14:20:45 +0200 Subject: rename Resource to Asset --- src/crepe/Sound.cpp | 6 +++--- src/crepe/Sound.h | 6 +++--- src/crepe/api/Asset.cpp | 14 ++++++++++++++ src/crepe/api/Asset.h | 24 ++++++++++++++++++++++++ src/crepe/api/AudioSource.cpp | 2 +- src/crepe/api/AudioSource.h | 6 +++--- src/crepe/api/CMakeLists.txt | 4 ++-- src/crepe/api/Resource.cpp | 14 -------------- src/crepe/api/Resource.h | 24 ------------------------ src/test/audio.cpp | 4 ++-- 10 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 src/crepe/api/Asset.cpp create mode 100644 src/crepe/api/Asset.h delete mode 100644 src/crepe/api/Resource.cpp delete mode 100644 src/crepe/api/Resource.h diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 1758282..c6e87d5 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -5,17 +5,17 @@ using namespace crepe; -Sound::Sound(std::unique_ptr res) { +Sound::Sound(std::unique_ptr res) { dbg_trace(); this->load(std::move(res)); } Sound::Sound(const char * src) { dbg_trace(); - this->load(std::make_unique(src)); + this->load(std::make_unique(src)); } -void Sound::load(std::unique_ptr res) { +void Sound::load(std::unique_ptr res) { this->sample.load(res->canonical()); } diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h index ac93991..339dd7c 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/Sound.h @@ -5,7 +5,7 @@ #include -#include "api/Resource.h" +#include "api/Asset.h" namespace crepe { @@ -66,10 +66,10 @@ public: public: Sound(const char * src); - Sound(std::unique_ptr res); + Sound(std::unique_ptr res); private: - void load(std::unique_ptr res); + void load(std::unique_ptr res); private: SoLoud::Wav sample; diff --git a/src/crepe/api/Asset.cpp b/src/crepe/api/Asset.cpp new file mode 100644 index 0000000..92ee50e --- /dev/null +++ b/src/crepe/api/Asset.cpp @@ -0,0 +1,14 @@ +#include + +#include "Asset.h" + +using namespace crepe::api; + +Asset::Asset(const std::string & src) { + this->src = std::filesystem::canonical(src); + this->file = std::ifstream(this->src, std::ios::in | std::ios::binary); +} + +const std::istream & Asset::read() { return this->file; } + +const char * Asset::canonical() { return this->src.c_str(); } diff --git a/src/crepe/api/Asset.h b/src/crepe/api/Asset.h new file mode 100644 index 0000000..259c696 --- /dev/null +++ b/src/crepe/api/Asset.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include + +namespace crepe::api { + +class Asset { +public: + Asset(const std::string & src); + +public: + //! Get an input stream to the contents of this resource + const std::istream & read(); + //! Get the canonical path to this resource + const char * canonical(); + +private: + std::string src; + std::ifstream file; +}; + +} // namespace crepe::api diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index 4d1b093..656fc46 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -5,7 +5,7 @@ using namespace crepe::api; -AudioSource::AudioSource(std::unique_ptr audio_clip) { +AudioSource::AudioSource(std::unique_ptr audio_clip) { this->_sound = std::make_unique(std::move(audio_clip)); } diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index 4300c48..9dfaf46 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -3,7 +3,7 @@ #include #include "Component.h" -#include "Resource.h" +#include "Asset.h" namespace crepe { class Sound; @@ -14,7 +14,7 @@ namespace crepe::api { //! Audio source component class AudioSource : Component { public: - AudioSource(std::unique_ptr audio_clip); + AudioSource(std::unique_ptr audio_clip); virtual ~AudioSource() = default; public: @@ -26,7 +26,7 @@ public: public: //! Sample file location - std::unique_ptr audio_clip; + std::unique_ptr audio_clip; //! TODO: ????? bool play_on_awake; //! Repeat the current audio clip during playback diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index feb03ef..54c7fdc 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -1,11 +1,11 @@ target_sources(crepe PUBLIC # AudioSource.cpp - Resource.cpp + Asset.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES AudioSource.h Component.h - Resource.h + Asset.h ) diff --git a/src/crepe/api/Resource.cpp b/src/crepe/api/Resource.cpp deleted file mode 100644 index 1a647ce..0000000 --- a/src/crepe/api/Resource.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#include "Resource.h" - -using namespace crepe::api; - -Resource::Resource(const std::string & src) { - this->src = std::filesystem::canonical(src); - this->file = std::ifstream(this->src, std::ios::in | std::ios::binary); -} - -const std::istream & Resource::read() { return this->file; } - -const char * Resource::canonical() { return this->src.c_str(); } diff --git a/src/crepe/api/Resource.h b/src/crepe/api/Resource.h deleted file mode 100644 index f2b2a0e..0000000 --- a/src/crepe/api/Resource.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace crepe::api { - -class Resource { -public: - Resource(const std::string & src); - -public: - //! Get an input stream to the contents of this resource - const std::istream & read(); - //! Get the canonical path to this resource - const char * canonical(); - -private: - std::string src; - std::ifstream file; -}; - -} // namespace crepe::api diff --git a/src/test/audio.cpp b/src/test/audio.cpp index 5bb2607..1d84551 100644 --- a/src/test/audio.cpp +++ b/src/test/audio.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -15,7 +15,7 @@ using namespace crepe::api; // TODO: mock internal audio class TEST(audio, play) { - auto res = std::make_unique("../mwe/audio/bgm.ogg"); + auto res = std::make_unique("../mwe/audio/bgm.ogg"); auto bgm = AudioSource(std::move(res)); bgm.play(); -- cgit v1.2.3 From b99e38badb82c5cc79771a77c5f6ea180c67ee4f Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 5 Oct 2024 14:24:39 +0200 Subject: move Asset from crepe::api to crepe --- src/crepe/Asset.cpp | 14 ++++++++++++++ src/crepe/Asset.h | 24 ++++++++++++++++++++++++ src/crepe/CMakeLists.txt | 2 ++ src/crepe/Sound.cpp | 6 +++--- src/crepe/Sound.h | 6 +++--- src/crepe/api/Asset.cpp | 14 -------------- src/crepe/api/Asset.h | 24 ------------------------ src/crepe/api/CMakeLists.txt | 2 -- 8 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 src/crepe/Asset.cpp create mode 100644 src/crepe/Asset.h delete mode 100644 src/crepe/api/Asset.cpp delete mode 100644 src/crepe/api/Asset.h diff --git a/src/crepe/Asset.cpp b/src/crepe/Asset.cpp new file mode 100644 index 0000000..15ddc27 --- /dev/null +++ b/src/crepe/Asset.cpp @@ -0,0 +1,14 @@ +#include + +#include "Asset.h" + +using namespace crepe; + +Asset::Asset(const std::string & src) { + this->src = std::filesystem::canonical(src); + this->file = std::ifstream(this->src, std::ios::in | std::ios::binary); +} + +const std::istream & Asset::read() { return this->file; } + +const char * Asset::canonical() { return this->src.c_str(); } diff --git a/src/crepe/Asset.h b/src/crepe/Asset.h new file mode 100644 index 0000000..736ba44 --- /dev/null +++ b/src/crepe/Asset.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include + +namespace crepe { + +class Asset { +public: + Asset(const std::string & src); + +public: + //! Get an input stream to the contents of this resource + const std::istream & read(); + //! Get the canonical path to this resource + const char * canonical(); + +private: + std::string src; + std::ifstream file; +}; + +} // namespace crepe diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index 3a60840..208ba1f 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -1,9 +1,11 @@ target_sources(crepe PUBLIC + Asset.cpp Sound.cpp SoundContext.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES + Asset.h Sound.h SoundContext.h ) diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index c6e87d5..73ad69c 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -5,17 +5,17 @@ using namespace crepe; -Sound::Sound(std::unique_ptr res) { +Sound::Sound(std::unique_ptr res) { dbg_trace(); this->load(std::move(res)); } Sound::Sound(const char * src) { dbg_trace(); - this->load(std::make_unique(src)); + this->load(std::make_unique(src)); } -void Sound::load(std::unique_ptr res) { +void Sound::load(std::unique_ptr res) { this->sample.load(res->canonical()); } diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h index 339dd7c..1ac20a7 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/Sound.h @@ -5,7 +5,7 @@ #include -#include "api/Asset.h" +#include "Asset.h" namespace crepe { @@ -66,10 +66,10 @@ public: public: Sound(const char * src); - Sound(std::unique_ptr res); + Sound(std::unique_ptr res); private: - void load(std::unique_ptr res); + void load(std::unique_ptr res); private: SoLoud::Wav sample; diff --git a/src/crepe/api/Asset.cpp b/src/crepe/api/Asset.cpp deleted file mode 100644 index 92ee50e..0000000 --- a/src/crepe/api/Asset.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#include "Asset.h" - -using namespace crepe::api; - -Asset::Asset(const std::string & src) { - this->src = std::filesystem::canonical(src); - this->file = std::ifstream(this->src, std::ios::in | std::ios::binary); -} - -const std::istream & Asset::read() { return this->file; } - -const char * Asset::canonical() { return this->src.c_str(); } diff --git a/src/crepe/api/Asset.h b/src/crepe/api/Asset.h deleted file mode 100644 index 259c696..0000000 --- a/src/crepe/api/Asset.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace crepe::api { - -class Asset { -public: - Asset(const std::string & src); - -public: - //! Get an input stream to the contents of this resource - const std::istream & read(); - //! Get the canonical path to this resource - const char * canonical(); - -private: - std::string src; - std::ifstream file; -}; - -} // namespace crepe::api diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index 54c7fdc..9548594 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -1,11 +1,9 @@ target_sources(crepe PUBLIC # AudioSource.cpp - Asset.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES AudioSource.h Component.h - Asset.h ) -- cgit v1.2.3 From c40332b990b025d2bd7b94e41184d7f0547da203 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 5 Oct 2024 14:33:43 +0200 Subject: add doxygen comments to Asset class --- src/crepe/Asset.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/crepe/Asset.h b/src/crepe/Asset.h index 736ba44..0cb5834 100644 --- a/src/crepe/Asset.h +++ b/src/crepe/Asset.h @@ -6,8 +6,17 @@ namespace crepe { +/** + * \brief Asset location helper + * + * This class is used to locate and canonicalize paths to game asset files, and + * should *always* be used when retrieving files from disk. + */ class Asset { public: + /** + * \param src Unique identifier to asset + */ Asset(const std::string & src); public: -- cgit v1.2.3 From e54ebc7e74f3ca94de3467a03397c0aad2aed079 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 5 Oct 2024 14:50:49 +0200 Subject: `make format` + clang-tidy --- makefile | 3 +-- src/crepe/Sound.cpp | 1 - src/crepe/api/AudioSource.h | 2 +- src/crepe/util/log.h | 3 +++ src/example/audio_internal.cpp | 1 - src/makefile | 6 ++++++ src/test/audio.cpp | 23 ++--------------------- src/test/dummy.cpp | 1 - 8 files changed, 13 insertions(+), 27 deletions(-) create mode 100644 src/makefile diff --git a/makefile b/makefile index 737e7a8..dd7c587 100644 --- a/makefile +++ b/makefile @@ -6,6 +6,5 @@ doxygen: Doxyfile FORCE FMT += $(shell git ls-files '*.c' '*.cpp' '*.h' '*.hpp') format: FORCE clang-format -i $(FMT) -# clang tidy doesn't work that well :/ -# clang-tidy --fix-errors $(FMT) + $(MAKE) -C src $@ diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 73ad69c..64fa281 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -58,4 +58,3 @@ void Sound::set_looping(bool looping) { if (!ctx.engine.isValidVoiceHandle(this->handle)) return; ctx.engine.setLooping(this->handle, this->looping); } - diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index 9dfaf46..2002d1a 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -2,8 +2,8 @@ #include -#include "Component.h" #include "Asset.h" +#include "Component.h" namespace crepe { class Sound; diff --git a/src/crepe/util/log.h b/src/crepe/util/log.h index 4cab338..bfe7291 100644 --- a/src/crepe/util/log.h +++ b/src/crepe/util/log.h @@ -12,9 +12,12 @@ __FILE_NAME__, __LINE__, crepe::util::color::RESET, \ __VA_ARGS__) +// very illegal global function-style macros +// NOLINTBEGIN #define dbg_logf(fmt, ...) _crepe_logf_here(": " fmt, __VA_ARGS__) #define dbg_log(str) _crepe_logf_here(": %s", str) #define dbg_trace() _crepe_logf_here("%s", "") +// NOLINTEND #endif diff --git a/src/example/audio_internal.cpp b/src/example/audio_internal.cpp index 09bd55c..1199e2d 100644 --- a/src/example/audio_internal.cpp +++ b/src/example/audio_internal.cpp @@ -43,4 +43,3 @@ int main() { return 0; } - diff --git a/src/makefile b/src/makefile new file mode 100644 index 0000000..c1ef601 --- /dev/null +++ b/src/makefile @@ -0,0 +1,6 @@ +.PHONY: FORCE + +FMT += $(shell git ls-files '*.c' '*.cpp' '*.h' '*.hpp') +format: FORCE + clang-tidy -p build/compile_commands.json --fix-errors $(FMT) + diff --git a/src/test/audio.cpp b/src/test/audio.cpp index 1d84551..d6ff689 100644 --- a/src/test/audio.cpp +++ b/src/test/audio.cpp @@ -1,29 +1,10 @@ #include -#include - -#include -#include - -#include -#include using namespace std; using namespace std::chrono_literals; -using namespace crepe::api; +// using namespace crepe; // TODO: mock internal audio class -TEST(audio, play) { - auto res = std::make_unique("../mwe/audio/bgm.ogg"); - auto bgm = AudioSource(std::move(res)); - - bgm.play(); - - this_thread::sleep_for(2s); - - bgm.stop(); - - ASSERT_TRUE(true); -} - +TEST(audio, play) { ASSERT_TRUE(true); } diff --git a/src/test/dummy.cpp b/src/test/dummy.cpp index 7f4c083..a00a9c6 100644 --- a/src/test/dummy.cpp +++ b/src/test/dummy.cpp @@ -1,4 +1,3 @@ #include TEST(dummy, foo) { ASSERT_TRUE(1); } - -- cgit v1.2.3 From b5a5d9b1d4725f3001486c9bbd69263ed0918303 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 5 Oct 2024 14:57:26 +0200 Subject: update code style --- contributing.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contributing.md b/contributing.md index eec5bc0..2ff411a 100644 --- a/contributing.md +++ b/contributing.md @@ -22,6 +22,14 @@ - When using libraries of which the header include order is important, make sure to separate the include statements using a blank line (clang-format may sort include statements, but does not sort across empty lines). +- All engine-related code is implemented under the `crepe` namespace, + user-facing APIs under `crepe::api` (the folder structure should also reflect + this). +- `using namespace` may not be used in header files, only in source files. +- Do not (indirectly) include private dependency headers in API header files, + as these are no longer accessible when the engine is installed +- Getter and setter functions are appropriately prefixed with `get_` and + `set_`. ## CMakeLists specific -- cgit v1.2.3 From 515aab5ab7e3281d2d77177724aae42cffc6faae Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 8 Oct 2024 13:47:44 +0200 Subject: fix feedback --- src/crepe/api/AudioSource.cpp | 10 +++++----- src/crepe/api/AudioSource.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index 656fc46..b512d27 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -6,17 +6,17 @@ using namespace crepe::api; AudioSource::AudioSource(std::unique_ptr audio_clip) { - this->_sound = std::make_unique(std::move(audio_clip)); + this->sound = std::make_unique(std::move(audio_clip)); } void AudioSource::play() { return this->play(false); } void AudioSource::play(bool looping) { - this->_sound->set_looping(looping); - this->_sound->play(); + this->sound->set_looping(looping); + this->sound->play(); } void AudioSource::stop() { - this->_sound->pause(); - this->_sound->rewind(); + this->sound->pause(); + this->sound->rewind(); } diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index 2002d1a..2d26cda 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -35,7 +35,7 @@ public: float volume; private: - std::unique_ptr _sound; + std::unique_ptr sound; }; } // namespace crepe::api -- cgit v1.2.3