diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-07 20:52:06 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-07 20:52:06 +0100 |
commit | 827f09031e2d3cc15e956b242774a4566e1403c1 (patch) | |
tree | 5ac1f025afea82ce892272deafcf8918ef518d33 /src/crepe/system | |
parent | 1c4156ee127b14760ed3b1a0cd16ad12180c7ac6 (diff) |
more WIP audio system
Diffstat (limited to 'src/crepe/system')
-rw-r--r-- | src/crepe/system/AudioSystem.cpp | 24 | ||||
-rw-r--r-- | src/crepe/system/AudioSystem.h | 21 | ||||
-rw-r--r-- | src/crepe/system/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/crepe/system/ScriptSystem.cpp | 3 | ||||
-rw-r--r-- | src/crepe/system/System.cpp | 7 | ||||
-rw-r--r-- | src/crepe/system/System.h | 10 |
6 files changed, 65 insertions, 3 deletions
diff --git a/src/crepe/system/AudioSystem.cpp b/src/crepe/system/AudioSystem.cpp new file mode 100644 index 0000000..93c0955 --- /dev/null +++ b/src/crepe/system/AudioSystem.cpp @@ -0,0 +1,24 @@ +#pragma once + +#include "AudioSystem.h" +#include "ComponentManager.h" + +#include "../api/AudioSource.h" + +using namespace crepe; +using namespace std; + +AudioSystem::AudioSystem(SoundContext & ctx) : ctx(ctx) {} + +void AudioSystem::update() { + vector<reference_wrapper<AudioSource>> components = this->compmgr.get_components_by_type<AudioSource>(); + + for (auto component_ref : components) { + AudioSource & component = component_ref.get(); + if (!component.active) continue; + + // TODO: fetch Sound instance from resourcemanager + // TODO: lots of state diffing + } +} + diff --git a/src/crepe/system/AudioSystem.h b/src/crepe/system/AudioSystem.h new file mode 100644 index 0000000..8fb681f --- /dev/null +++ b/src/crepe/system/AudioSystem.h @@ -0,0 +1,21 @@ +#pragma once + +#include "../facade/SoundContext.h" + +#include "System.h" + +namespace crepe { + +class AudioSystem : public System { +public: + AudioSystem(SoundContext & ctx); + +public: + void update(); + +private: + SoundContext & ctx; +}; + +} // namespace crepe + diff --git a/src/crepe/system/CMakeLists.txt b/src/crepe/system/CMakeLists.txt index ff6f66f..ca62add 100644 --- a/src/crepe/system/CMakeLists.txt +++ b/src/crepe/system/CMakeLists.txt @@ -1,9 +1,11 @@ target_sources(crepe PUBLIC + System.cpp ParticleSystem.cpp ScriptSystem.cpp PhysicsSystem.cpp CollisionSystem.cpp RenderSystem.cpp + AudioSystem.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES @@ -12,4 +14,5 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES PhysicsSystem.h CollisionSystem.h RenderSystem.h + AudioSystem.h ) diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index f2673e7..68fbb02 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -22,9 +22,8 @@ void ScriptSystem::update() { forward_list<Script *> ScriptSystem::get_scripts() { forward_list<Script *> scripts = {}; - ComponentManager & mgr = ComponentManager::get_instance(); vector<reference_wrapper<BehaviorScript>> behavior_scripts - = mgr.get_components_by_type<BehaviorScript>(); + = this->compmgr.get_components_by_type<BehaviorScript>(); for (auto behavior_script_ref : behavior_scripts) { BehaviorScript & behavior_script = behavior_script_ref.get(); diff --git a/src/crepe/system/System.cpp b/src/crepe/system/System.cpp new file mode 100644 index 0000000..fa51d2f --- /dev/null +++ b/src/crepe/system/System.cpp @@ -0,0 +1,7 @@ +#include "System.h" + +using namespace crepe; + +// TODO: ComponentManager shouldn't be a singleton +System::System() : compmgr(ComponentManager::get_instance()) {} + diff --git a/src/crepe/system/System.h b/src/crepe/system/System.h index 3b81bef..5091977 100644 --- a/src/crepe/system/System.h +++ b/src/crepe/system/System.h @@ -1,14 +1,22 @@ #pragma once +#include "../ComponentManager.h" + namespace crepe { +//! ECS system base class class System { public: + //! Process components belonging to this system virtual void update() = 0; public: - System() = default; + System(); virtual ~System() = default; + +public: + //! Reference to component manager + ComponentManager & compmgr; }; } // namespace crepe |