diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-14 13:57:13 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-14 13:57:13 +0100 |
commit | 07adbf48e0781cd8c95983c1871a84b6160ee5bf (patch) | |
tree | e3a55673b20ebaa3baec6665c107c177bd59ff14 /src/crepe/api | |
parent | 01c09a196c3f3e5cefaa4119a95a1cdeb7b9c263 (diff) |
implement asset + more WIP audio system
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/AudioSource.cpp | 6 | ||||
-rw-r--r-- | src/crepe/api/AudioSource.h | 5 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/crepe/api/Config.h | 14 | ||||
-rw-r--r-- | src/crepe/api/Texture.cpp | 2 |
5 files changed, 22 insertions, 9 deletions
diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index b0cf28c..4baac9a 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -1,13 +1,11 @@ -#include <memory> - #include "AudioSource.h" using namespace crepe; using namespace std; -AudioSource::AudioSource(game_object_id_t id, unique_ptr<Asset> audio_clip) : +AudioSource::AudioSource(game_object_id_t id, const Asset & src) : Component(id), - audio_clip(std::move(audio_clip)) + source(src) { } void AudioSource::play(bool looping) { diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index 5bc70f9..0748267 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -21,8 +21,6 @@ public: void stop(); public: - //! Sample file location - const std::unique_ptr<Asset> audio_clip; //! Play when this component becomes active bool play_on_awake = false; //! Repeat the current audio clip during playback @@ -31,6 +29,9 @@ public: float volume = 1.0; private: + //! This audio source's clip + const Asset source; + //! If this source is playing audio bool playing = false; //! Rewind the sample location diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index 85696c4..93a1fac 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(crepe PUBLIC - # AudioSource.cpp + AudioSource.cpp BehaviorScript.cpp Script.cpp GameObject.cpp @@ -23,7 +23,7 @@ target_sources(crepe PUBLIC ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES - # AudioSource.h + AudioSource.h BehaviorScript.h Config.h Script.h diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index e3f86bf..c3f9474 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -58,6 +58,20 @@ public: */ double gravity = 1; } physics; + + //! Asset loading options + struct { + /** + * \brief Pattern to match for Asset base directory + * + * All non-absolute paths resolved using \c Asset will be made relative to + * the first parent directory relative to the calling executable where + * appending this pattern results in a path that exists. If this string is + * empty, path resolution is disabled, and Asset will return all paths + * as-is. + */ + std::string root_pattern = ".crepe-root"; + } asset; }; } // namespace crepe diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp index de0d0ea..6a1e4d8 100644 --- a/src/crepe/api/Texture.cpp +++ b/src/crepe/api/Texture.cpp @@ -26,7 +26,7 @@ Texture::~Texture() { void Texture::load(unique_ptr<Asset> res) { SDLContext & ctx = SDLContext::get_instance(); - this->texture = std::move(ctx.texture_from_path(res->get_canonical())); + this->texture = std::move(ctx.texture_from_path(res->get_path())); } int Texture::get_width() const { |