Minor - Improves scene editor and adds audio support - V13.1.0
Improves the scene editor by adding an inspector window to view and modify entity components. Adds audio component support with basic playback controls integrated into the inspector. Adds default audio files.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
// AudioComponent.h
|
||||
#pragma once
|
||||
#include "ecs/component.h"
|
||||
#include "../component.h"
|
||||
#include <Fmod/core/inc/fmod.hpp>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
namespace ecs {
|
||||
class AudioComponent : public Component {
|
||||
@@ -10,11 +11,59 @@ public:
|
||||
AudioComponent() : m_system(nullptr), 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>
|
||||
}
|
||||
|
||||
bool Load(FMOD::System* system, const std::string& path) {
|
||||
m_system = system;
|
||||
return m_system->createSound(path.c_str(), FMOD_DEFAULT, nullptr, &m_sound) == FMOD_OK;
|
||||
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, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Load(const std::string& path) {
|
||||
if (!m_system) {
|
||||
Initialize();
|
||||
if (!m_system) return false; // L'erreur est d<>j<EFBFBD> d<>finie dans Initialize()
|
||||
}
|
||||
|
||||
m_soundPath = path;
|
||||
|
||||
// V<>rifier si le fichier existe
|
||||
if (!std::filesystem::exists(path)) {
|
||||
m_lastError = "Fichier non trouv<75>: " + path;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Lib<69>rer le son pr<70>c<EFBFBD>dent s'il existe
|
||||
if (m_sound) {
|
||||
m_sound->release();
|
||||
m_sound = nullptr;
|
||||
}
|
||||
|
||||
// Essayer de charger avec le chemin absolu
|
||||
std::filesystem::path absolutePath = std::filesystem::absolute(path);
|
||||
FMOD_RESULT result = m_system->createSound(absolutePath.string().c_str(), FMOD_DEFAULT, nullptr, &m_sound);
|
||||
if (result != FMOD_OK) {
|
||||
m_lastError = "<EFBFBD>chec du chargement du son: " + std::to_string(result) +
|
||||
" (chemin: " + absolutePath.string() + ")";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Play() {
|
||||
@@ -27,9 +76,44 @@ public:
|
||||
m_channel->stop();
|
||||
}
|
||||
|
||||
void OnImGuiRender() override {
|
||||
// Afficher le r<>pertoire de travail actuel
|
||||
std::string currentDir = std::filesystem::current_path().string();
|
||||
ImGui::Text("R<EFBFBD>pertoire actuel: %s", currentDir.c_str());
|
||||
|
||||
if (m_sound) {
|
||||
ImGui::Text("Son charg<72>: %s", m_soundPath.c_str());
|
||||
if (ImGui::Button("Jouer")) {
|
||||
Play();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Arr<EFBFBD>ter")) {
|
||||
Stop();
|
||||
}
|
||||
} else {
|
||||
ImGui::Text("Aucun son charg<72>");
|
||||
|
||||
// Montrer l'erreur s'il y en a une
|
||||
if (!m_lastError.empty()) {
|
||||
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Erreur: %s", m_lastError.c_str());
|
||||
}
|
||||
|
||||
static char path[256] = "F:/Github_Repo/khaotic-engine-Reborn/x64/Release/assets/sounds/default.mp3";
|
||||
ImGui::InputText("Chemin du fichier", path, sizeof(path));
|
||||
|
||||
if (ImGui::Button("Charger le son")) {
|
||||
if (!Load(path)) {
|
||||
// L'erreur est d<>j<EFBFBD> d<>finie dans Load()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
FMOD::System* m_system;
|
||||
FMOD::Sound* m_sound;
|
||||
FMOD::Channel* m_channel;
|
||||
std::string m_soundPath;
|
||||
std::string m_lastError;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user