diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-10 13:40:42 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-10 13:40:42 +0100 |
commit | d80c98ee03e59e0c38e025a7fe83ab4c39115fb8 (patch) | |
tree | c31c861b82d384e64071b4e7f64dfafe99b888c0 /src/crepe/api | |
parent | b2c72ee8ce282bb13b0fbeb2ddb01fdfd6ad1280 (diff) | |
parent | 7a8657dfe019104aced61a5b63e63f61ad919f7a (diff) |
font progress
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/AssetManager.cpp | 17 | ||||
-rw-r--r-- | src/crepe/api/AssetManager.hpp | 22 | ||||
-rw-r--r-- | src/crepe/api/AudioSource.cpp | 15 | ||||
-rw-r--r-- | src/crepe/api/AudioSource.h | 75 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 9 | ||||
-rw-r--r-- | src/crepe/api/Config.h | 18 | ||||
-rw-r--r-- | src/crepe/api/Text.cpp | 0 | ||||
-rw-r--r-- | src/crepe/api/Text.h | 12 |
8 files changed, 112 insertions, 56 deletions
diff --git a/src/crepe/api/AssetManager.cpp b/src/crepe/api/AssetManager.cpp deleted file mode 100644 index 3925758..0000000 --- a/src/crepe/api/AssetManager.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "util/Log.h" - -#include "AssetManager.h" - -using namespace crepe; - -AssetManager & AssetManager::get_instance() { - static AssetManager instance; - return instance; -} - -AssetManager::~AssetManager() { - dbg_trace(); - this->asset_cache.clear(); -} - -AssetManager::AssetManager() { dbg_trace(); } diff --git a/src/crepe/api/AssetManager.hpp b/src/crepe/api/AssetManager.hpp deleted file mode 100644 index 1c0e978..0000000 --- a/src/crepe/api/AssetManager.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "AssetManager.h" - -namespace crepe { - -template <typename asset> -std::shared_ptr<asset> AssetManager::cache(const std::string & file_path, bool reload) { - auto it = asset_cache.find(file_path); - - if (!reload && it != asset_cache.end()) { - return std::any_cast<std::shared_ptr<asset>>(it->second); - } - - std::shared_ptr<asset> new_asset = std::make_shared<asset>(file_path.c_str()); - - asset_cache[file_path] = new_asset; - - return new_asset; -} - -} // namespace crepe diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp new file mode 100644 index 0000000..7b05cb1 --- /dev/null +++ b/src/crepe/api/AudioSource.cpp @@ -0,0 +1,15 @@ +#include "AudioSource.h" + +using namespace crepe; +using namespace std; + +AudioSource::AudioSource(game_object_id_t id, const Asset & src) + : Component(id), + source(src) {} + +void AudioSource::play(bool looping) { + this->loop = looping; + this->oneshot_play = true; +} + +void AudioSource::stop() { this->oneshot_stop = true; } diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h new file mode 100644 index 0000000..7c1f161 --- /dev/null +++ b/src/crepe/api/AudioSource.h @@ -0,0 +1,75 @@ +#pragma once + +#include "../Component.h" +#include "../types.h" +#include "../facade/SoundHandle.h" + +#include "Asset.h" +#include "GameObject.h" + +namespace crepe { + +class AudioSystem; + +//! Audio source component +class AudioSource : public Component { + //! AudioSource components are handled by AudioSystem + friend class AudioSystem; + +protected: + /** + * \param source Sound sample to load + */ + AudioSource(game_object_id_t id, const Asset & source); + //! Only ComponentManager creates components + friend class ComponentManager; + +public: + // std::unique_ptr needs to be able to destoy this component + virtual ~AudioSource() = default; + +public: + //! Start this audio source + void play(bool looping = false); + //! Stop this audio source + void stop(); + +public: + //! Play when this component becomes active + bool play_on_awake = false; + //! Repeat the current audio clip during playback + bool loop = false; + //! Normalized volume (0.0 - 1.0) + float volume = 1.0; + +private: + //! This audio source's clip + const Asset source; + + /** + * \name One-shot state variables + * + * These variables trigger function calls when set to true, and are unconditionally reset on + * every system update. + * + * \{ + */ + //! Play this sample + bool oneshot_play = false; + //! Stop this sample + bool oneshot_stop = false; + //! \} + /** + * \name State diffing variables + * \{ + */ + typeof(active) last_active = false; + typeof(volume) last_volume = volume; + typeof(loop) last_loop = loop; + //! \} + //! This source's voice handle + SoundHandle voice{}; + +}; + +} // namespace crepe diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index 593c4e6..44ea243 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 GameObject.cpp Rigidbody.cpp @@ -7,7 +7,6 @@ target_sources(crepe PUBLIC Transform.cpp Color.cpp Texture.cpp - AssetManager.cpp Sprite.cpp Config.cpp Metadata.cpp @@ -27,7 +26,7 @@ target_sources(crepe PUBLIC ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES - # AudioSource.h + AudioSource.h BehaviorScript.h Config.h Script.h @@ -39,9 +38,7 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Vector2.h Vector2.hpp Color.h - Texture.h - AssetManager.h - AssetManager.hpp + Texture.h Scene.h Metadata.h Camera.h diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index e4808fe..def4c49 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -15,20 +15,10 @@ namespace crepe { * modified *before* execution is handed over from the game programmer to the engine (i.e. the * main loop is started). */ -class Config final { -public: +struct Config final { //! Retrieve handle to global Config instance static Config & get_instance(); -private: - Config() = default; - ~Config() = default; - Config(const Config &) = default; - Config(Config &&) = default; - Config & operator=(const Config &) = default; - Config & operator=(Config &&) = default; - -public: //! Logging-related settings struct { /** @@ -97,6 +87,12 @@ public: */ int font_size = 16; } font; + + //! Audio system settings + struct { + //! Max amount of simultanious voices + unsigned int voices = 32; + } audio; }; } // namespace crepe diff --git a/src/crepe/api/Text.cpp b/src/crepe/api/Text.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/crepe/api/Text.cpp diff --git a/src/crepe/api/Text.h b/src/crepe/api/Text.h new file mode 100644 index 0000000..5c527af --- /dev/null +++ b/src/crepe/api/Text.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Asset.h" +#include "../Component.h" +class Text : public Component{ +public: + Text(game_object_id_t id, const Asset & font, int font_size); + + int font_size = 16; + const Asset source; +private: +}; |