diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-08-27 05:03:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-08-27 05:03:55 +0400 |
commit | 6778c8dc2914e5714f0211d0643c1ade34864d02 (patch) | |
tree | 4b52fdec59be1ca7d62f4655962b312995d16c79 /source/gameengine | |
parent | 0b523ac3e6145f5428cfbe3906a4ccf1831a601b (diff) |
BGE: allow sound actuators to be converted even when they have invalid samples
without this, an incorrect sound path could cause scripts to to fail, making some functionality not work at all.
This also fixes a problem where samples would be loaded multiple times.
Diffstat (limited to 'source/gameengine')
-rw-r--r-- | source/gameengine/Converter/KX_ConvertActuators.cpp | 139 | ||||
-rw-r--r-- | source/gameengine/Converter/KX_ConvertSensors.cpp | 12 |
2 files changed, 85 insertions, 66 deletions
diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index b1f86afa4ee..e71928b8cee 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -355,22 +355,26 @@ void BL_ConvertActuators(char* maggiename, if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF) { - SND_SoundObject* sndobj = NULL; + SND_Scene* soundscene = scene->GetSoundScene(); + STR_String samplename = ""; + bool sampleisloaded = false; - if (soundact->sound) - { - SND_Scene* soundscene = scene->GetSoundScene(); - STR_String samplename = soundact->sound->name; + if (soundact->sound) { + /* Need to convert the samplename into absolute path + * before checking if its loaded */ + char fullpath[sizeof(soundact->sound->name)]; - bool sampleisloaded = false; + /* 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 - { + else { /* if not, make it so */ PackedFile* pf = soundact->sound->newpackedfile; @@ -383,65 +387,80 @@ void BL_ConvertActuators(char* maggiename, /* or else load it from disk */ else { - /* but we need to convert the samplename into absolute pathname first */ - char fullpath[sizeof(soundact->sound->name)]; - - /* dont modify soundact->sound->name, only change a copy */ - BLI_strncpy(fullpath, soundact->sound->name, sizeof(fullpath)); - BLI_convertstringcode(fullpath, maggiename); - samplename = fullpath; - - /* and now we can load it */ - if (soundscene->LoadSample(samplename, NULL, 0) > -1) + 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; + } } } - - if (sampleisloaded) + } else { + 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. */ + /*if (sampleisloaded)*/ + + /* setup the SND_SoundObject */ + 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) { - sndobj = new SND_SoundObject(); - sndobj->SetSampleName(samplename.Ptr()); - sndobj->SetObjectName(bact->name); - 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); + if (soundact->sound->flags & SOUND_FLAGS_BIDIRECTIONAL_LOOP) + sndobj->SetLoopMode(SND_LOOP_BIDIRECTIONAL); else - sndobj->SetHighPriority(false); - - if (soundact->sound->flags & SOUND_FLAGS_3D) - sndobj->Set3D(true); - else - sndobj->Set3D(false); - - KX_SoundActuator* tmpsoundact = - new KX_SoundActuator(gameobj, - sndobj, - scene->GetSoundScene(), // needed for replication! - soundActuatorType, - startFrame, - stopFrame); - - tmpsoundact->SetName(bact->name); - baseact = tmpsoundact; - soundscene->AddObject(sndobj); - } else { - std::cout << "WARNING: Sound actuator " << bact->name << " failed to load sample." << std::endl; + 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); + + tmpsoundact->SetName(bact->name); + baseact = tmpsoundact; + soundscene->AddObject(sndobj); } break; } diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp index 4806df36090..98e078ccf8d 100644 --- a/source/gameengine/Converter/KX_ConvertSensors.cpp +++ b/source/gameengine/Converter/KX_ConvertSensors.cpp @@ -765,17 +765,17 @@ void BL_ConvertSensors(struct Object* blenderobject, logicmgr->RegisterToSensor(gamecont,gamesensor); } else { printf( - "Warning, sensor \"%s\" could not find its controller" - "(link %d of %d)\n" + "Warning, sensor \"%s\" could not find its controller " + "(link %d of %d) from object \"%s\"\n" "\tthere has been an error converting the blender controller for the game engine," - "logic may be incorrect\n", sens->name, i+1, sens->totlinks); + "logic may be incorrect\n", sens->name, i+1, sens->totlinks, blenderobject->id.name+2); } } else { printf( - "Warning, sensor \"%s\" has lost a link to a controller" - "(link %d of %d)\n" + "Warning, sensor \"%s\" has lost a link to a controller " + "(link %d of %d) from object \"%s\"\n" "\tpossible causes are partially appended objects or an error reading the file," - "logic may be incorrect\n", sens->name, i+1, sens->totlinks); + "logic may be incorrect\n", sens->name, i+1, sens->totlinks, blenderobject->id.name+2); } } // done with gamesensor |