Minor - Adds FMOD integration for audio support - V13.4.0

Initializes FMOD sound system within the application class and propagates it to the entity manager and entities. This allows for audio components to access and use the FMOD system for playing sounds.

Removes redundant FMOD system initialization from the audio component.
This commit is contained in:
2025-09-16 16:34:08 +02:00
parent 42b7ca04a4
commit f875580197
6 changed files with 44 additions and 23 deletions

View File

@@ -662,6 +662,13 @@ private :
input inputs_;
bool tab_was_pressed_;
// ------------------------------------------------- //
// ------------------- SOUND ----------------------- //
// ------------------------------------------------- //
// shared pointer to the FMOD system
FMOD::System* sound_system_;
};
#endif

View File

@@ -16,7 +16,7 @@
namespace ecs {
class AudioComponent : public Component {
public:
AudioComponent() : m_system(nullptr), m_sound(nullptr), m_channel(nullptr) {}
AudioComponent() : m_sound(nullptr), m_channel(nullptr) {}
~AudioComponent() override {
if (m_sound) m_sound->release();
// Ne pas lib<69>rer m_system ici car il peut <20>tre partag<61>
@@ -24,27 +24,12 @@ public:
void Initialize() override
{
// create FMOD system if not already created
if (!m_system)
{
FMOD_RESULT result = FMOD::System_Create(&m_system);
if (result != FMOD_OK) {
m_lastError = "<EFBFBD>chec de la cr<63>ation du syst<73>me FMOD: " + std::to_string(result);
return;
}
result = m_system->init(512, FMOD_INIT_NORMAL | FMOD_INIT_3D_RIGHTHANDED, nullptr);
if (result != FMOD_OK) {
m_lastError = "<EFBFBD>chec de l'initialisation du syst<73>me FMOD: " + std::to_string(result);
m_system->release();
m_system = nullptr;
}
}
auto parent = GetParent();
if (parent && parent->GetCamera())
{
SetCamera(parent->GetCamera());
SetSoundSystem(parent->GetSoundSystem());
}
}
@@ -392,7 +377,9 @@ public:
}
}
void SetSoundSystem(FMOD::System* system) {
m_system = system;
}
private:
FMOD::System* m_system;

View File

@@ -7,6 +7,7 @@
#include <cassert>
#include "camera_class.h"
#include <Fmod/core/inc/fmod.hpp>
namespace ecs {
/**
@@ -140,6 +141,9 @@ public:
void SetCamera(camera_class* camera) {m_camera = camera; }
camera_class* GetCamera() const { return m_camera; }
void SetSoundSystem(FMOD::System* soundSystem) {m_soundSystem = soundSystem; }
FMOD::System* GetSoundSystem() const { return m_soundSystem; }
private:
/**
@@ -154,6 +158,9 @@ private:
// camera
camera_class* m_camera = nullptr;
// FMOD sound system
FMOD::System* m_soundSystem = nullptr;
};
} // namespace ecs

View File

@@ -32,6 +32,7 @@ public:
auto entity = std::make_shared<Entity>(id);
entity->SetCamera(camera_);
entity->SetSoundSystem(sound_system_);
m_Entities[id] = entity;
return entity;
@@ -148,11 +149,15 @@ public:
void SetCamera(camera_class* camera) { camera_ = camera; }
camera_class* GetCamera() const { return camera_; }
void SetSoundSystem(FMOD::System* sound_system) { sound_system_ = sound_system; }
FMOD::System* GetSoundSystem() const { return sound_system_; }
private:
EntityID m_NextEntityID;
std::unordered_map<EntityID, std::shared_ptr<Entity>> m_Entities;
std::queue<EntityID> m_FreeIDs; // IDs <20> r<>utiliser
camera_class* camera_ = nullptr;
FMOD::System* sound_system_ = nullptr;
};
} // namespace ecs

View File

@@ -46,6 +46,7 @@ application_class::application_class() : should_quit_(false)
light_model_ = nullptr;
render_count_ = 0;
tab_was_pressed_ = false;
sound_system_ = nullptr;
}
application_class::~application_class()
@@ -503,8 +504,23 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
culling_active_ = true;
culling_thread_ = std::thread(&application_class::culling_thread_function, this);
FMOD_RESULT FMOD_result = FMOD::System_Create(&sound_system_);
std::string m_lastError;
if (FMOD_result != FMOD_OK) {
m_lastError = "<EFBFBD>chec de la cr<63>ation du syst<73>me FMOD: " + std::to_string(FMOD_result);
return false;
}
FMOD_result = sound_system_->init(512, FMOD_INIT_NORMAL | FMOD_INIT_3D_RIGHTHANDED, nullptr);
if (FMOD_result != FMOD_OK) {
m_lastError = "<EFBFBD>chec de l'initialisation du syst<73>me FMOD: " + std::to_string(FMOD_result);
sound_system_->release();
sound_system_ = nullptr;
}
entity_manager_->SetCamera(camera_);
entity_manager_->SetSoundSystem(sound_system_);
}