From 6c5c58e05799f2b593cd81fcff57e6ef72ad57fb Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Sun, 9 Aug 2009 21:16:39 +0000 Subject: 2.5: Sound branch merge! See mailing list for additional information. --- .../gameengine/Converter/KX_ConvertActuators.cpp | 154 ++++----------------- 1 file changed, 28 insertions(+), 126 deletions(-) (limited to 'source/gameengine/Converter/KX_ConvertActuators.cpp') diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index c18e4fce8a5..1afadac5c0a 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -38,7 +38,7 @@ #include "KX_BlenderSceneConverter.h" #include "KX_ConvertActuators.h" -#include "SND_Scene.h" +#include "AUD_C-API.h" // Actuators //SCA logiclibrary native logicbricks #include "SCA_PropertyActuator.h" @@ -347,8 +347,7 @@ void BL_ConvertActuators(char* maggiename, { bSoundActuator* soundact = (bSoundActuator*) bact->data; /* get type, and possibly a start and end frame */ - short startFrame = soundact->sta, stopFrame = soundact->end; - KX_SoundActuator::KX_SOUNDACT_TYPE + KX_SoundActuator::KX_SOUNDACT_TYPE soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF; switch(soundact->type) { @@ -378,114 +377,38 @@ void BL_ConvertActuators(char* maggiename, if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF) { - SND_Scene* soundscene = scene->GetSoundScene(); - STR_String samplename = ""; - bool sampleisloaded = false; - - if (soundact->sound) { - /* Need to convert the samplename into absolute path - * before checking if its loaded */ - char fullpath[FILE_MAX]; - - /* dont modify soundact->sound->name, only change a copy */ - BLI_strncpy(fullpath, soundact->sound->name, sizeof(fullpath)); - BLI_convertstringcode(fullpath, maggiename); - samplename = fullpath; - - /* let's see if the sample was already loaded */ - if (soundscene->IsSampleLoaded(samplename)) - { - sampleisloaded = true; - } - else { - /* if not, make it so */ - PackedFile* pf = soundact->sound->newpackedfile; - - /* but we need a packed file then */ - if (pf) - { - if (soundscene->LoadSample(samplename, pf->data, pf->size) > -1) - sampleisloaded = true; - } - /* or else load it from disk */ - else - { - if (soundscene->LoadSample(samplename, NULL, 0) > -1) { - sampleisloaded = true; - } - else { - std::cout << "WARNING: Sound actuator \"" << bact->name << - "\" from object \"" << blenderobject->id.name+2 << - "\" failed to load sample." << std::endl; - } - } - } - } else { + bSound* sound = soundact->sound; + bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false; + AUD_Sound* snd_sound = NULL; + KX_3DSoundSettings settings; + settings.cone_inner_angle = soundact->sound3D.cone_inner_angle; + settings.cone_outer_angle = soundact->sound3D.cone_outer_angle; + settings.cone_outer_gain = soundact->sound3D.cone_outer_gain; + settings.max_distance = soundact->sound3D.max_distance; + settings.max_gain = soundact->sound3D.max_gain; + settings.min_gain = soundact->sound3D.min_gain; + settings.reference_distance = soundact->sound3D.reference_distance; + settings.rolloff_factor = soundact->sound3D.rolloff_factor; + + if(!sound) + { std::cout << "WARNING: Sound actuator \"" << bact->name << "\" from object \"" << blenderobject->id.name+2 << "\" has no sound datablock." << std::endl; } - - /* Note, allowing actuators for sounds that are not there was added since 2.47 - * This is because python may expect the actuator and raise an exception if it dosnt find it - * better just to add a dummy sound actuator. */ - SND_SoundObject* sndobj = NULL; - if (sampleisloaded) - { - /* setup the SND_SoundObject */ - sndobj = new SND_SoundObject(); - sndobj->SetSampleName(samplename.Ptr()); - sndobj->SetObjectName(bact->name); - if (soundact->sound) { - sndobj->SetRollOffFactor(soundact->sound->attenuation); - sndobj->SetGain(soundact->sound->volume); - sndobj->SetPitch(exp((soundact->sound->pitch / 12.0) * log(2.0))); - // sndobj->SetLoopStart(soundact->sound->loopstart); - // sndobj->SetLoopStart(soundact->sound->loopend); - if (soundact->sound->flags & SOUND_FLAGS_LOOP) - { - if (soundact->sound->flags & SOUND_FLAGS_BIDIRECTIONAL_LOOP) - sndobj->SetLoopMode(SND_LOOP_BIDIRECTIONAL); - else - sndobj->SetLoopMode(SND_LOOP_NORMAL); - } - else { - sndobj->SetLoopMode(SND_LOOP_OFF); - } - - if (soundact->sound->flags & SOUND_FLAGS_PRIORITY) - sndobj->SetHighPriority(true); - else - sndobj->SetHighPriority(false); - - if (soundact->sound->flags & SOUND_FLAGS_3D) - sndobj->Set3D(true); - else - sndobj->Set3D(false); - } - else { - /* dummy values for a NULL sound - * see editsound.c - defaults are unlikely to change soon */ - sndobj->SetRollOffFactor(1.0); - sndobj->SetGain(1.0); - sndobj->SetPitch(1.0); - sndobj->SetLoopMode(SND_LOOP_OFF); - sndobj->SetHighPriority(false); - sndobj->Set3D(false); - } - } - KX_SoundActuator* tmpsoundact = - new KX_SoundActuator(gameobj, - sndobj, - scene->GetSoundScene(), // needed for replication! - soundActuatorType, - startFrame, - stopFrame); - + else + snd_sound = sound->cache ? sound->cache : sound->snd_sound; + KX_SoundActuator* tmpsoundact = + new KX_SoundActuator(gameobj, + snd_sound, + soundact->volume, + exp((soundact->pitch / 12.0) * log(2.0)), + is3d, + settings, + soundActuatorType); + tmpsoundact->SetName(bact->name); baseact = tmpsoundact; - if (sndobj) - soundscene->AddObject(sndobj); } break; } @@ -525,27 +448,6 @@ void BL_ConvertActuators(char* maggiename, /* This is an error!!! */ cdActuatorType = KX_CDActuator::KX_CDACT_NODEF; } - - if (cdActuatorType != KX_CDActuator::KX_CDACT_NODEF) - { - SND_CDObject* pCD = SND_CDObject::Instance(); - - if (pCD) - { - pCD->SetGain(cdact->volume); - - KX_CDActuator* tmpcdact = - new KX_CDActuator(gameobj, - scene->GetSoundScene(), // needed for replication! - cdActuatorType, - cdact->track, - startFrame, - stopFrame); - - tmpcdact->SetName(bact->name); - baseact = tmpcdact; - } - } break; } case ACT_PROPERTY: -- cgit v1.2.3