[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16264] trunk/blender/source/gameengine/ Converter: BGE: allow sound actuators to be converted even when they have invalid samples

Campbell Barton ideasman42 at gmail.com
Wed Aug 27 03:03:57 CEST 2008


Revision: 16264
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16264
Author:   campbellbarton
Date:     2008-08-27 03:03:55 +0200 (Wed, 27 Aug 2008)

Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
    trunk/blender/source/gameengine/Converter/KX_ConvertSensors.cpp

Modified: trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp	2008-08-26 17:53:04 UTC (rev 16263)
+++ trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp	2008-08-27 01:03:55 UTC (rev 16264)
@@ -355,22 +355,26 @@
 				
 				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 @@
 							/* 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);
-							}
+							if (soundact->sound->flags & SOUND_FLAGS_BIDIRECTIONAL_LOOP)
+								sndobj->SetLoopMode(SND_LOOP_BIDIRECTIONAL);
 							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);
-							
-							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;
 			}

Modified: trunk/blender/source/gameengine/Converter/KX_ConvertSensors.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_ConvertSensors.cpp	2008-08-26 17:53:04 UTC (rev 16263)
+++ trunk/blender/source/gameengine/Converter/KX_ConvertSensors.cpp	2008-08-27 01:03:55 UTC (rev 16264)
@@ -765,17 +765,17 @@
 						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





More information about the Bf-blender-cvs mailing list