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` --- 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 ++--- 5 files changed, 7 insertions(+), 18 deletions(-) (limited to 'src/crepe/api') 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 -- 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 (limited to 'src/crepe/api') 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 (limited to 'src/crepe/api') 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 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 (limited to 'src/crepe/api') 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 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(-) (limited to 'src/crepe/api') 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