KRAmbientZone now using KRAudioSampleBinding

This commit is contained in:
2025-11-19 23:29:49 -08:00
parent 8c52ed697f
commit 635278022e
3 changed files with 23 additions and 13 deletions

View File

@@ -45,12 +45,12 @@ void KRAmbientZone::InitNodeInfo(KrNodeInfo* nodeInfo)
nodeInfo->ambient_zone.sample = -1;
}
KRAmbientZone::KRAmbientZone(KRScene& scene, std::string name) : KRNode(scene, name)
{
m_ambient = "";
m_ambient_gain = 1.0f;
KRAmbientZone::KRAmbientZone(KRScene& scene, std::string name)
: KRNode(scene, name)
, m_ambient_gain(1.f)
, m_gradient_distance(0.25f)
m_gradient_distance = 0.25f;
{
}
@@ -66,7 +66,7 @@ tinyxml2::XMLElement* KRAmbientZone::saveXML(tinyxml2::XMLNode* parent)
{
tinyxml2::XMLElement* e = KRNode::saveXML(parent);
e->SetAttribute("zone", m_zone.c_str());
e->SetAttribute("sample", m_ambient.c_str());
e->SetAttribute("sample", m_ambient.getName().c_str());
e->SetAttribute("gain", m_ambient_gain);
e->SetAttribute("gradient", m_gradient_distance);
return e;
@@ -83,7 +83,12 @@ void KRAmbientZone::loadXML(tinyxml2::XMLElement* e)
m_gradient_distance = 0.25f;
}
m_ambient = e->Attribute("sample");
const char* szAudioSampleName = e->Attribute("sample");
if (szAudioSampleName == nullptr) {
m_ambient.clear();
} else {
m_ambient.set(szAudioSampleName);
}
m_ambient_gain = 1.0f;
if (e->QueryFloatAttribute("gain", &m_ambient_gain) != tinyxml2::XML_SUCCESS) {
@@ -91,14 +96,15 @@ void KRAmbientZone::loadXML(tinyxml2::XMLElement* e)
}
}
std::string KRAmbientZone::getAmbient()
KRAudioSample* KRAmbientZone::getAmbient()
{
return m_ambient;
m_ambient.bind(&getContext());
return m_ambient.get();
}
void KRAmbientZone::setAmbient(const std::string& ambient)
{
m_ambient = ambient;
m_ambient.set(ambient);
}
float KRAmbientZone::getAmbientGain()

View File

@@ -31,9 +31,13 @@
#pragma once
#include "KREngine-common.h"
#include "resources/KRResource.h"
#include "resources/audio/KRAudioSampleBinding.h"
#include "KRNode.h"
class KRAudioSample;
class KRAmbientZone : public KRNode
{
public:
@@ -53,7 +57,7 @@ public:
float getGradientDistance();
void setGradientDistance(float gradient_distance);
std::string getAmbient();
KRAudioSample* getAmbient();
void setAmbient(const std::string& ambient);
float getAmbientGain();
@@ -68,6 +72,6 @@ private:
float m_gradient_distance;
std::string m_ambient;
KRAudioSampleBinding m_ambient;
float m_ambient_gain;
};

View File

@@ -1424,7 +1424,7 @@ void KRAudioManager::startFrame(float deltaTime)
if (zi.weight > 0.0f) {
if (m_ambient_zone_weights.find(sphere->getZone()) == m_ambient_zone_weights.end()) {
zi.ambient_zone = sphere;
zi.ambient_sample = get(sphere->getAmbient());
zi.ambient_sample = sphere->getAmbient();
m_ambient_zone_weights[sphere->getZone()] = zi;
m_ambient_zone_total_weight += zi.weight;
} else {