From f3eeedc91a04ca0651e0fe78a2119e7e3e38e391 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 25 Sep 2024 17:36:31 +0200 Subject: WIP Audio API + facade --- src/crepe/api/AudioSource.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/crepe/api/AudioSource.h (limited to 'src/crepe/api/AudioSource.h') diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h new file mode 100644 index 0000000..6a038be --- /dev/null +++ b/src/crepe/api/AudioSource.h @@ -0,0 +1,42 @@ +#pragma once + +#include + +#include "Component.h" +#include "Resource.h" + +namespace crepe { +class Sound; +} + +namespace crepe::api { + +//! Audio source component +class AudioSource : Component { +public: + AudioSource(std::unique_ptr audio_clip); + virtual ~AudioSource() = default; + +public: + //! Start or resume this audio source + void play(); + void play(bool looping); + //! Stop this audio source + void stop(); + +public: + //! Sample file location + std::unique_ptr audio_clip; + //! TODO: ????? + bool play_on_awake; + //! Repeat the current audio clip during playback + bool loop; + //! Normalized volume (0.0 - 1.0) + float volume; + +private: + std::unique_ptr _sound; +}; + +} + -- 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(-) (limited to 'src/crepe/api/AudioSource.h') 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 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/AudioSource.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 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/AudioSource.h') 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/AudioSource.h') 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 From 04a040e28ade412ea5b1767bf77eed3956121973 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 23 Oct 2024 13:12:18 +0200 Subject: move user-facing classes to api namespace --- src/crepe/CMakeLists.txt | 9 --------- src/crepe/Collider.cpp | 5 ----- src/crepe/Collider.h | 14 -------------- src/crepe/Component.h | 3 +-- src/crepe/GameObject.cpp | 7 ------- src/crepe/GameObject.h | 24 ------------------------ src/crepe/GameObject.hpp | 15 --------------- src/crepe/Rigidbody.cpp | 6 ------ src/crepe/Rigidbody.h | 16 ---------------- src/crepe/Sprite.cpp | 8 -------- src/crepe/Sprite.h | 16 ---------------- src/crepe/api/AudioSource.cpp | 3 ++- src/crepe/api/AudioSource.h | 4 ++-- src/crepe/api/BehaviorScript.cpp | 1 - src/crepe/api/BehaviorScript.h | 2 +- src/crepe/api/CMakeLists.txt | 9 +++++++++ src/crepe/api/Collider.cpp | 5 +++++ src/crepe/api/Collider.h | 14 ++++++++++++++ src/crepe/api/GameObject.cpp | 7 +++++++ src/crepe/api/GameObject.h | 24 ++++++++++++++++++++++++ src/crepe/api/GameObject.hpp | 15 +++++++++++++++ src/crepe/api/Rigidbody.cpp | 6 ++++++ src/crepe/api/Rigidbody.h | 16 ++++++++++++++++ src/crepe/api/Sprite.cpp | 8 ++++++++ src/crepe/api/Sprite.h | 16 ++++++++++++++++ src/example/CMakeLists.txt | 4 ++++ src/example/components_internal.cpp | 11 +++++++---- src/example/script.cpp | 2 +- src/readme.md | 3 ++- 29 files changed, 140 insertions(+), 133 deletions(-) delete mode 100644 src/crepe/Collider.cpp delete mode 100644 src/crepe/Collider.h delete mode 100644 src/crepe/GameObject.cpp delete mode 100644 src/crepe/GameObject.h delete mode 100644 src/crepe/GameObject.hpp delete mode 100644 src/crepe/Rigidbody.cpp delete mode 100644 src/crepe/Rigidbody.h delete mode 100644 src/crepe/Sprite.cpp delete mode 100644 src/crepe/Sprite.h create mode 100644 src/crepe/api/Collider.cpp create mode 100644 src/crepe/api/Collider.h create mode 100644 src/crepe/api/GameObject.cpp create mode 100644 src/crepe/api/GameObject.h create mode 100644 src/crepe/api/GameObject.hpp create mode 100644 src/crepe/api/Rigidbody.cpp create mode 100644 src/crepe/api/Rigidbody.h create mode 100644 src/crepe/api/Sprite.cpp create mode 100644 src/crepe/api/Sprite.h (limited to 'src/crepe/api/AudioSource.h') diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index 8323490..cfa51fb 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -4,10 +4,6 @@ target_sources(crepe PUBLIC SoundContext.cpp ComponentManager.cpp Component.cpp - GameObject.cpp - Collider.cpp - Rigidbody.cpp - Sprite.cpp ScriptSystem.cpp ) @@ -18,11 +14,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES ComponentManager.h ComponentManager.hpp Component.h - GameObject.h - GameObject.hpp - Collider.h - Rigidbody.h - Sprite.h System.h ScriptSystem.h ) diff --git a/src/crepe/Collider.cpp b/src/crepe/Collider.cpp deleted file mode 100644 index 3f12afd..0000000 --- a/src/crepe/Collider.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "Collider.h" - -using namespace crepe; - -Collider::Collider(int size) : size(size) {} diff --git a/src/crepe/Collider.h b/src/crepe/Collider.h deleted file mode 100644 index 120da05..0000000 --- a/src/crepe/Collider.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "Component.h" - -namespace crepe { - -class Collider : public Component { -public: - Collider(int size); - - int size; -}; - -} // namespace crepe diff --git a/src/crepe/Component.h b/src/crepe/Component.h index d9a01ac..9cda177 100644 --- a/src/crepe/Component.h +++ b/src/crepe/Component.h @@ -8,9 +8,8 @@ protected: public: virtual ~Component() = default; - // TODO: shouldn't this constructor be deleted because this class will never - // directly be instantiated? +public: bool active = true; }; diff --git a/src/crepe/GameObject.cpp b/src/crepe/GameObject.cpp deleted file mode 100644 index de3beb6..0000000 --- a/src/crepe/GameObject.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "GameObject.h" - -using namespace crepe; - -GameObject::GameObject(uint32_t id, std::string name, std::string tag, - int layer) - : id(id), name(name), tag(tag), active(true), layer(layer) {} diff --git a/src/crepe/GameObject.h b/src/crepe/GameObject.h deleted file mode 100644 index b5d6399..0000000 --- a/src/crepe/GameObject.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include - -namespace crepe { - -class GameObject { -public: - GameObject(uint32_t id, std::string name, std::string tag, int layer); - - template - T & add_component(Args &&... args); - - uint32_t id; - std::string name; - std::string tag; - bool active; - int layer; -}; - -} // namespace crepe - -#include "GameObject.hpp" diff --git a/src/crepe/GameObject.hpp b/src/crepe/GameObject.hpp deleted file mode 100644 index 8cd1abe..0000000 --- a/src/crepe/GameObject.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "GameObject.h" - -#include "ComponentManager.h" - -namespace crepe { - -template -T & GameObject::add_component(Args &&... args) { - auto & mgr = ComponentManager::get_instance(); - return mgr.add_component(id, std::forward(args)...); -} - -} // namespace crepe diff --git a/src/crepe/Rigidbody.cpp b/src/crepe/Rigidbody.cpp deleted file mode 100644 index 495d908..0000000 --- a/src/crepe/Rigidbody.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "Rigidbody.h" - -using namespace crepe; - -Rigidbody::Rigidbody(int mass, int gravityScale, int bodyType) - : mass(mass), gravity_scale(gravityScale), body_type(bodyType) {} diff --git a/src/crepe/Rigidbody.h b/src/crepe/Rigidbody.h deleted file mode 100644 index 63a8877..0000000 --- a/src/crepe/Rigidbody.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Component.h" - -namespace crepe { - -class Rigidbody : public Component { -public: - Rigidbody(int mass, int gravityScale, int bodyType); - - int mass; - int gravity_scale; - int body_type; -}; - -} // namespace crepe diff --git a/src/crepe/Sprite.cpp b/src/crepe/Sprite.cpp deleted file mode 100644 index a5a5e68..0000000 --- a/src/crepe/Sprite.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -#include "Sprite.h" - -using namespace crepe; -using namespace std; - -Sprite::Sprite(string path) : path(path) {} diff --git a/src/crepe/Sprite.h b/src/crepe/Sprite.h deleted file mode 100644 index 143e702..0000000 --- a/src/crepe/Sprite.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include - -#include "Component.h" - -namespace crepe { - -class Sprite : public Component { -public: - Sprite(std::string path); - - std::string path; -}; - -} // namespace crepe diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index b512d27..bb067dc 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -1,7 +1,8 @@ +#include + #include "AudioSource.h" #include "../Sound.h" -#include using namespace crepe::api; diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index 2d26cda..7980212 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -2,8 +2,8 @@ #include -#include "Asset.h" -#include "Component.h" +#include "../Asset.h" +#include "../Component.h" namespace crepe { class Sound; diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp index 1f236b4..84bfd4c 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -1,7 +1,6 @@ #include "../util/log.h" #include "BehaviorScript.h" -#include "Script.h" using namespace crepe::api; diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 6ce6798..25d3cc5 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -2,7 +2,7 @@ #include -#include "Component.h" +#include "../Component.h" #include "Script.h" namespace crepe { diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index 6b337be..ae92f3d 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -2,11 +2,20 @@ target_sources(crepe PUBLIC # AudioSource.cpp BehaviorScript.cpp Script.cpp + GameObject.cpp + Collider.cpp + Rigidbody.cpp + Sprite.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES # AudioSource.h BehaviorScript.h Script.h + GameObject.h + GameObject.hpp + Collider.h + Rigidbody.h + Sprite.h ) diff --git a/src/crepe/api/Collider.cpp b/src/crepe/api/Collider.cpp new file mode 100644 index 0000000..6370a42 --- /dev/null +++ b/src/crepe/api/Collider.cpp @@ -0,0 +1,5 @@ +#include "Collider.h" + +using namespace crepe::api; + +Collider::Collider(int size) : size(size) {} diff --git a/src/crepe/api/Collider.h b/src/crepe/api/Collider.h new file mode 100644 index 0000000..72d8e77 --- /dev/null +++ b/src/crepe/api/Collider.h @@ -0,0 +1,14 @@ +#pragma once + +#include "../Component.h" + +namespace crepe::api { + +class Collider : public Component { +public: + Collider(int size); + + int size; +}; + +} // namespace crepe::api diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp new file mode 100644 index 0000000..b167187 --- /dev/null +++ b/src/crepe/api/GameObject.cpp @@ -0,0 +1,7 @@ +#include "GameObject.h" + +using namespace crepe::api; +using namespace std; + +GameObject::GameObject(uint32_t id, string name, string tag, int layer) + : id(id), name(name), tag(tag), active(true), layer(layer) {} diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h new file mode 100644 index 0000000..57508c5 --- /dev/null +++ b/src/crepe/api/GameObject.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +namespace crepe::api { + +class GameObject { +public: + GameObject(uint32_t id, std::string name, std::string tag, int layer); + + template + T & add_component(Args &&... args); + + uint32_t id; + std::string name; + std::string tag; + bool active; + int layer; +}; + +} // namespace crepe::api + +#include "GameObject.hpp" diff --git a/src/crepe/api/GameObject.hpp b/src/crepe/api/GameObject.hpp new file mode 100644 index 0000000..8295ea3 --- /dev/null +++ b/src/crepe/api/GameObject.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "../ComponentManager.h" + +#include "GameObject.h" + +namespace crepe::api { + +template +T & GameObject::add_component(Args &&... args) { + auto & mgr = ComponentManager::get_instance(); + return mgr.add_component(id, std::forward(args)...); +} + +} // namespace crepe::api diff --git a/src/crepe/api/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp new file mode 100644 index 0000000..98d1d60 --- /dev/null +++ b/src/crepe/api/Rigidbody.cpp @@ -0,0 +1,6 @@ +#include "Rigidbody.h" + +using namespace crepe::api; + +Rigidbody::Rigidbody(int mass, int gravityScale, int bodyType) + : mass(mass), gravity_scale(gravityScale), body_type(bodyType) {} diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h new file mode 100644 index 0000000..6cae579 --- /dev/null +++ b/src/crepe/api/Rigidbody.h @@ -0,0 +1,16 @@ +#pragma once + +#include "../Component.h" + +namespace crepe::api { + +class Rigidbody : public Component { +public: + Rigidbody(int mass, int gravityScale, int bodyType); + + int mass; + int gravity_scale; + int body_type; +}; + +} // namespace crepe::api diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp new file mode 100644 index 0000000..aa7dbb0 --- /dev/null +++ b/src/crepe/api/Sprite.cpp @@ -0,0 +1,8 @@ +#include + +#include "Sprite.h" + +using namespace crepe::api; +using namespace std; + +Sprite::Sprite(string path) : path(path) {} diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h new file mode 100644 index 0000000..580f825 --- /dev/null +++ b/src/crepe/api/Sprite.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include "../Component.h" + +namespace crepe::api { + +class Sprite : public Component { +public: + Sprite(std::string path); + + std::string path; +}; + +} // namespace crepe::api diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index 6df4ce7..53f584f 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -1,3 +1,6 @@ +# all examples +add_custom_target(examples) + # add_example(target_name [SOURCES...]) function(add_example target_name) # if SOURCES is not specified @@ -10,6 +13,7 @@ function(add_example target_name) add_executable(${target_name} EXCLUDE_FROM_ALL ${sources}) target_link_libraries(${target_name} PUBLIC crepe) + add_dependencies(examples ${target_name}) endfunction() add_example(audio_internal) diff --git a/src/example/components_internal.cpp b/src/example/components_internal.cpp index 54ce295..e2169e1 100644 --- a/src/example/components_internal.cpp +++ b/src/example/components_internal.cpp @@ -6,14 +6,17 @@ #include #include -#include #include #include -#include -#include -#include + +#include +#include +#include +#include + #include +using namespace crepe::api; using namespace crepe; using namespace std; diff --git a/src/example/script.cpp b/src/example/script.cpp index cc585db..6e5563c 100644 --- a/src/example/script.cpp +++ b/src/example/script.cpp @@ -4,11 +4,11 @@ */ #include -#include #include #include #include +#include #include using namespace crepe; diff --git a/src/readme.md b/src/readme.md index a4a71e7..a8ffc51 100644 --- a/src/readme.md +++ b/src/readme.md @@ -18,7 +18,8 @@ running the build command: $ ninja -C build test_main ``` -Each source file in the example/ folder corresponds to a CMake target as well: +Each source file in the example/ folder corresponds to a CMake target as well +(all examples can be built at once by specifying the `examples` target): ``` $ ninja -C build audio_internal components_internal -- cgit v1.2.3