diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
index 467c771..2939729 100644
--- a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
+++ b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
@@ -62,26 +62,26 @@
- {
+ "keyToString": {
+ "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "C++ Project.enginecustom.executor": "Run",
+ "C/C++ Project.KhaoticDemo.executor": "Run",
+ "C/C++ Project.enginecustom.executor": "Run",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.git.unshallow": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "git-widget-placeholder": "main",
+ "ignore.virus.scanning.warn.message": "true",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "settings.editor.selected.configurable": "preferences.pluginManager",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
diff --git a/enginecustom/src/inc/system/ecs/component.h b/enginecustom/src/inc/system/ecs/component.h
index b4f74cb..3d80dea 100644
--- a/enginecustom/src/inc/system/ecs/component.h
+++ b/enginecustom/src/inc/system/ecs/component.h
@@ -32,6 +32,11 @@ public:
*/
virtual void Initialize() {}
+ /**
+ *Virtual function to shutdown the component.
+ */
+ virtual void Shutdown() {}
+
/**
* Virtual function to update the component.
* @param deltaTime Time since the last update.
diff --git a/enginecustom/src/inc/system/ecs/components/audio_component.h b/enginecustom/src/inc/system/ecs/components/audio_component.h
index ed1938b..ebcd9fe 100644
--- a/enginecustom/src/inc/system/ecs/components/audio_component.h
+++ b/enginecustom/src/inc/system/ecs/components/audio_component.h
@@ -30,6 +30,27 @@ public:
// Ne pas libérer m_system ici car il peut être partagé
}
+ /**
+ * Shutdown the audio component by releasing the sound and channel.
+ * This method is called when the component is removed from an entity or when the entity is destroyed.
+ */
+ void Shutdown() override {
+ if (m_channel) {
+ bool isPlaying = false;
+ m_channel->isPlaying(&isPlaying);
+ if (isPlaying) {
+ m_channel->stop();
+ }
+ m_channel = nullptr;
+ }
+ if (m_sound) {
+ m_sound->release();
+ m_sound = nullptr;
+ }
+ m_system = nullptr; // Ne pas libérer m_system ici car il peut être partagé
+ m_camera = nullptr;
+ }
+
/**
* Initialize the audio component by setting up the FMOD system and camera from the parent entity.
* This method is called when the component is added to an entity.
diff --git a/enginecustom/src/inc/system/ecs/entity.h b/enginecustom/src/inc/system/ecs/entity.h
index cec0898..6a45a9f 100644
--- a/enginecustom/src/inc/system/ecs/entity.h
+++ b/enginecustom/src/inc/system/ecs/entity.h
@@ -163,6 +163,22 @@ public:
*/
FMOD::System* GetSoundSystem() const { return m_soundSystem; }
+ /**
+ * Release all data associated with the entity.
+ * This includes clearing all components and resetting the camera and sound system pointers.
+ */
+ void release()
+ {
+ // call shutdown on all components if needed
+ for (auto& [typeID, component] : m_Components) {
+ // If components had a shutdown method, we would call it here
+ component->Shutdown();
+ }
+ m_Components.clear();
+ m_camera = nullptr;
+ m_soundSystem = nullptr;
+ }
+
void SetDevice (ID3D11Device* dev) { device = dev; }
void SetContext(ID3D11DeviceContext* ctx) { context = ctx; }
ID3D11Device* GetDevice() const { return device; }
diff --git a/enginecustom/src/inc/system/ecs/entity_manager.h b/enginecustom/src/inc/system/ecs/entity_manager.h
index be5852b..f641876 100644
--- a/enginecustom/src/inc/system/ecs/entity_manager.h
+++ b/enginecustom/src/inc/system/ecs/entity_manager.h
@@ -48,6 +48,7 @@ public:
void DestroyEntity(EntityID id) {
auto it = m_Entities.find(id);
if (it != m_Entities.end()) {
+ it->second->release();
m_Entities.erase(it);
m_FreeIDs.push(id); // Recycler l'ID
}