SoundAssetImplements

-Explosion
-Lightning
-Splash

-Other sound asset implementations will require soundasset array if possible.
This commit is contained in:
marauder2k7 2021-09-20 09:37:31 +01:00
parent bda5266c88
commit c92cfe3e81
6 changed files with 87 additions and 35 deletions

View file

@ -230,7 +230,9 @@ ExplosionData::ExplosionData()
faceViewer = false; faceViewer = false;
soundProfile = NULL; INIT_SOUNDASSET(Sound);
//soundProfile = NULL;
particleEmitter = NULL; particleEmitter = NULL;
particleEmitterId = 0; particleEmitterId = 0;
@ -308,7 +310,7 @@ ExplosionData::ExplosionData(const ExplosionData& other, bool temp_clone) : Game
faceViewer = other.faceViewer; faceViewer = other.faceViewer;
particleDensity = other.particleDensity; particleDensity = other.particleDensity;
particleRadius = other.particleRadius; particleRadius = other.particleRadius;
soundProfile = other.soundProfile; CLONE_SOUNDASSET(Sound);
particleEmitter = other.particleEmitter; particleEmitter = other.particleEmitter;
particleEmitterId = other.particleEmitterId; // -- for pack/unpack of particleEmitter ptr particleEmitterId = other.particleEmitterId; // -- for pack/unpack of particleEmitter ptr
explosionScale = other.explosionScale; explosionScale = other.explosionScale;
@ -358,12 +360,6 @@ ExplosionData::~ExplosionData()
if (!isTempClone()) if (!isTempClone())
return; return;
if (soundProfile && soundProfile->isTempClone())
{
delete soundProfile;
soundProfile = 0;
}
// particleEmitter, emitterList[*], debrisList[*], explosionList[*] will delete themselves // particleEmitter, emitterList[*], debrisList[*], explosionList[*] will delete themselves
#ifdef TRACK_EXPLOSION_DATA_CLONES #ifdef TRACK_EXPLOSION_DATA_CLONES
@ -399,8 +395,9 @@ void ExplosionData::initPersistFields()
"of the explosion." ); "of the explosion." );
addField( "playSpeed", TypeF32, Offset(playSpeed, ExplosionData), addField( "playSpeed", TypeF32, Offset(playSpeed, ExplosionData),
"Time scale at which to play the explosionShape <i>ambient</i> sequence." ); "Time scale at which to play the explosionShape <i>ambient</i> sequence." );
addField( "soundProfile", TYPEID< SFXTrack >(), Offset(soundProfile, ExplosionData),
"Non-looping sound effect that will be played at the start of the explosion." ); INITPERSISTFIELD_SOUNDASSET(Sound, ExplosionData, "Sound to play when this explosion explodes.");
addField( "faceViewer", TypeBool, Offset(faceViewer, ExplosionData), addField( "faceViewer", TypeBool, Offset(faceViewer, ExplosionData),
"Controls whether the visual effects of the explosion always face the camera." ); "Controls whether the visual effects of the explosion always face the camera." );
@ -523,7 +520,6 @@ void ExplosionData::initPersistFields()
onlyKeepClearSubstitutions("debris"); // subs resolving to "~~", or "~0" are OK onlyKeepClearSubstitutions("debris"); // subs resolving to "~~", or "~0" are OK
onlyKeepClearSubstitutions("emitter"); onlyKeepClearSubstitutions("emitter");
onlyKeepClearSubstitutions("particleEmitter"); onlyKeepClearSubstitutions("particleEmitter");
onlyKeepClearSubstitutions("soundProfile");
onlyKeepClearSubstitutions("subExplosion"); onlyKeepClearSubstitutions("subExplosion");
Parent::initPersistFields(); Parent::initPersistFields();
} }
@ -656,7 +652,8 @@ void ExplosionData::packData(BitStream* stream)
PACKDATA_SHAPEASSET(ExplosionShape); PACKDATA_SHAPEASSET(ExplosionShape);
sfxWrite( stream, soundProfile ); PACKDATA_SOUNDASSET(Sound);
if (stream->writeFlag(particleEmitter)) if (stream->writeFlag(particleEmitter))
stream->writeRangedU32(particleEmitter->getId(),DataBlockObjectIdFirst,DataBlockObjectIdLast); stream->writeRangedU32(particleEmitter->getId(),DataBlockObjectIdFirst,DataBlockObjectIdLast);
@ -759,7 +756,7 @@ void ExplosionData::unpackData(BitStream* stream)
UNPACKDATA_SHAPEASSET(ExplosionShape); UNPACKDATA_SHAPEASSET(ExplosionShape);
sfxRead( stream, &soundProfile ); UNPACKDATA_SOUNDASSET(Sound);
if (stream->readFlag()) if (stream->readFlag())
particleEmitterId = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast); particleEmitterId = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast);
@ -862,11 +859,12 @@ bool ExplosionData::preload(bool server, String &errorStr)
if (Parent::preload(server, errorStr) == false) if (Parent::preload(server, errorStr) == false)
return false; return false;
if (!server && !getSFXProfile())
return false;
if( !server ) if( !server )
{ {
String sfxErrorStr; String sfxErrorStr;
if( !sfxResolve( &soundProfile, sfxErrorStr ) )
Con::errorf(ConsoleLogEntry::General, "Error, unable to load sound profile for explosion datablock: %s", sfxErrorStr.c_str());
if (!particleEmitter && particleEmitterId != 0) if (!particleEmitter && particleEmitterId != 0)
if (Sim::findObject(particleEmitterId, particleEmitter) == false) if (Sim::findObject(particleEmitterId, particleEmitter) == false)
Con::errorf(ConsoleLogEntry::General, "Error, unable to load particle emitter for explosion datablock"); Con::errorf(ConsoleLogEntry::General, "Error, unable to load particle emitter for explosion datablock");
@ -1384,7 +1382,7 @@ bool Explosion::explode()
resetWorldBox(); resetWorldBox();
} }
SFXProfile* sound_prof = dynamic_cast<SFXProfile*>(mDataBlock->soundProfile); SFXProfile* sound_prof = dynamic_cast<SFXProfile*>(mDataBlock->getSFXProfile());
if (sound_prof) if (sound_prof)
{ {
soundProfile_clone = sound_prof->cloneAndPerformSubstitutions(ss_object, ss_index); soundProfile_clone = sound_prof->cloneAndPerformSubstitutions(ss_object, ss_index);

View file

@ -42,6 +42,7 @@
#endif #endif
#include "T3D/assets/ShapeAsset.h" #include "T3D/assets/ShapeAsset.h"
#include "T3D/assets/SoundAsset.h"
class ParticleEmitter; class ParticleEmitter;
class ParticleEmitterData; class ParticleEmitterData;
@ -69,7 +70,17 @@ class ExplosionData : public GameBaseData {
S32 particleDensity; S32 particleDensity;
F32 particleRadius; F32 particleRadius;
SFXTrack* soundProfile; //SFXTrack* soundProfile;
DECLARE_SOUNDASSET(ExplosionData, Sound);
DECLARE_SOUNDASSET_SETGET(ExplosionData, Sound);
SFXProfile* getSFXProfile() {
if (mSoundAsset.notNull())
return mSoundAsset->getSfxProfile();
else
return NULL;
}
ParticleEmitterData* particleEmitter; ParticleEmitterData* particleEmitter;
S32 particleEmitterId; S32 particleEmitterId;

View file

@ -238,7 +238,7 @@ void LightningStrikeEvent::process(NetConnection*)
// //
LightningData::LightningData() LightningData::LightningData()
{ {
strikeSound = NULL; INIT_SOUNDASSET(StrikeSound);
for (S32 i = 0; i < MaxThunders; i++) for (S32 i = 0; i < MaxThunders; i++)
thunderSounds[i] = NULL; thunderSounds[i] = NULL;
@ -260,8 +260,9 @@ LightningData::~LightningData()
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
void LightningData::initPersistFields() void LightningData::initPersistFields()
{ {
addField( "strikeSound", TYPEID< SFXTrack >(), Offset(strikeSound, LightningData),
"Sound profile to play when a lightning strike occurs." ); INITPERSISTFIELD_SOUNDASSET(StrikeSound, LightningData, "Sound to play when lightning STRIKES!");
addField( "thunderSounds", TYPEID< SFXTrack >(), Offset(thunderSounds, LightningData), MaxThunders, addField( "thunderSounds", TYPEID< SFXTrack >(), Offset(thunderSounds, LightningData), MaxThunders,
"@brief List of thunder sound effects to play.\n\n" "@brief List of thunder sound effects to play.\n\n"
"A random one of these sounds will be played shortly after each strike " "A random one of these sounds will be played shortly after each strike "
@ -302,8 +303,8 @@ bool LightningData::preload(bool server, String &errorStr)
Con::errorf(ConsoleLogEntry::General, "LightningData::preload: Invalid packet: %s", sfxErrorStr.c_str()); Con::errorf(ConsoleLogEntry::General, "LightningData::preload: Invalid packet: %s", sfxErrorStr.c_str());
} }
if( !sfxResolve( &strikeSound, sfxErrorStr ) ) if(!getSFXProfile())
Con::errorf(ConsoleLogEntry::General, "LightningData::preload: Invalid packet: %s", sfxErrorStr.c_str()); Con::errorf(ConsoleLogEntry::General, "LightningData::preload: can't get sfxProfile from asset");
mNumStrikeTextures = 0; mNumStrikeTextures = 0;
for (U32 i = 0; i < MaxTextures; i++) for (U32 i = 0; i < MaxTextures; i++)
@ -338,7 +339,7 @@ void LightningData::packData(BitStream* stream)
for (i = 0; i < MaxTextures; i++) for (i = 0; i < MaxTextures; i++)
stream->writeString(strikeTextureNames[i]); stream->writeString(strikeTextureNames[i]);
sfxWrite( stream, strikeSound ); PACKDATA_SOUNDASSET(StrikeSound);
} }
void LightningData::unpackData(BitStream* stream) void LightningData::unpackData(BitStream* stream)
@ -359,7 +360,7 @@ void LightningData::unpackData(BitStream* stream)
for (i = 0; i < MaxTextures; i++) for (i = 0; i < MaxTextures; i++)
strikeTextureNames[i] = stream->readSTString(); strikeTextureNames[i] = stream->readSTString();
sfxRead( stream, &strikeSound ); UNPACKDATA_SOUNDASSET(StrikeSound);
} }
@ -735,9 +736,9 @@ void Lightning::processEvent(LightningStrikeEvent* pEvent)
MatrixF trans(true); MatrixF trans(true);
trans.setPosition( strikePoint ); trans.setPosition( strikePoint );
if (mDataBlock->strikeSound) if (mDataBlock->getSFXProfile())
{ {
SFX->playOnce(mDataBlock->strikeSound, &trans ); SFX->playOnce(mDataBlock->getSFXProfile(), &trans );
} }
} }

View file

@ -41,7 +41,8 @@
#include "gfx/gfxTextureHandle.h" #include "gfx/gfxTextureHandle.h"
#include "T3D/assets/ImageAsset.h"
#include "T3D/assets/SoundAsset.h"
class ShapeBase; class ShapeBase;
class LightningStrikeEvent; class LightningStrikeEvent;
@ -63,7 +64,10 @@ class LightningData : public GameBaseData
//-------------------------------------- Console set variables //-------------------------------------- Console set variables
public: public:
SFXTrack* thunderSounds[MaxThunders]; SFXTrack* thunderSounds[MaxThunders];
SFXTrack* strikeSound;
DECLARE_SOUNDASSET(LightningData, StrikeSound);
DECLARE_SOUNDASSET_SETGET(LightningData, StrikeSound);
StringTableEntry strikeTextureNames[MaxTextures]; StringTableEntry strikeTextureNames[MaxTextures];
//-------------------------------------- load set variables //-------------------------------------- load set variables
@ -86,6 +90,14 @@ class LightningData : public GameBaseData
DECLARE_CONOBJECT(LightningData); DECLARE_CONOBJECT(LightningData);
static void initPersistFields(); static void initPersistFields();
SFXProfile* getSFXProfile() {
if (mStrikeSoundAsset.notNull())
return mStrikeSoundAsset->getSfxProfile();
else
return NULL;
}
}; };

View file

@ -67,8 +67,10 @@ ConsoleDocClass( Splash,
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
SplashData::SplashData() SplashData::SplashData()
{ {
soundProfile = NULL; //soundProfile = NULL;
soundProfileId = 0; //soundProfileId = 0;
INIT_SOUNDASSET(Sound);
scale.set(1, 1, 1); scale.set(1, 1, 1);
@ -112,7 +114,8 @@ SplashData::SplashData()
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
void SplashData::initPersistFields() void SplashData::initPersistFields()
{ {
addField("soundProfile", TYPEID< SFXProfile >(), Offset(soundProfile, SplashData), "SFXProfile effect to play.\n"); INITPERSISTFIELD_SOUNDASSET(Sound, SplashData, "Sound to play when splash, splashes.");
addField("scale", TypePoint3F, Offset(scale, SplashData), "The scale of this splashing effect, defined as the F32 points X, Y, Z.\n"); addField("scale", TypePoint3F, Offset(scale, SplashData), "The scale of this splashing effect, defined as the F32 points X, Y, Z.\n");
addField("emitter", TYPEID< ParticleEmitterData >(), Offset(emitterList, SplashData), NUM_EMITTERS, "List of particle emitters to create at the point of this Splash effect.\n"); addField("emitter", TYPEID< ParticleEmitterData >(), Offset(emitterList, SplashData), NUM_EMITTERS, "List of particle emitters to create at the point of this Splash effect.\n");
addField("delayMS", TypeS32, Offset(delayMS, SplashData), "Time to delay, in milliseconds, before actually starting this effect.\n"); addField("delayMS", TypeS32, Offset(delayMS, SplashData), "Time to delay, in milliseconds, before actually starting this effect.\n");
@ -158,6 +161,8 @@ void SplashData::packData(BitStream* stream)
{ {
Parent::packData(stream); Parent::packData(stream);
PACKDATA_SOUNDASSET(Sound);
mathWrite(*stream, scale); mathWrite(*stream, scale);
stream->write(delayMS); stream->write(delayMS);
stream->write(delayVariance); stream->write(delayVariance);
@ -212,6 +217,8 @@ void SplashData::unpackData(BitStream* stream)
{ {
Parent::unpackData(stream); Parent::unpackData(stream);
UNPACKDATA_SOUNDASSET(Sound);
mathRead(*stream, &scale); mathRead(*stream, &scale);
stream->read(&delayMS); stream->read(&delayMS);
stream->read(&delayVariance); stream->read(&delayVariance);
@ -267,6 +274,9 @@ bool SplashData::preload(bool server, String &errorStr)
if (Parent::preload(server, errorStr) == false) if (Parent::preload(server, errorStr) == false)
return false; return false;
if (!server && !getSFXProfile())
return false;
if (!server) if (!server)
{ {
S32 i; S32 i;
@ -667,6 +677,14 @@ void Splash::spawnExplosion()
{ {
if( !mDataBlock->explosion ) return; if( !mDataBlock->explosion ) return;
/// could just play the explosion one, but explosion could be weapon specific,
/// splash sound could be liquid specific. food for thought.
SFXProfile* sound_prof = dynamic_cast<SFXProfile*>(mDataBlock->getSFXProfile());
if (sound_prof)
{
SFX->playOnce(sound_prof, &getTransform());
}
Explosion* pExplosion = new Explosion; Explosion* pExplosion = new Explosion;
pExplosion->onNewDataBlock(mDataBlock->explosion, false); pExplosion->onNewDataBlock(mDataBlock->explosion, false);

View file

@ -34,6 +34,7 @@
#include "gfx/gfxTextureHandle.h" #include "gfx/gfxTextureHandle.h"
#include "T3D/assets/ImageAsset.h" #include "T3D/assets/ImageAsset.h"
#include "T3D/assets/SoundAsset.h"
class ParticleEmitter; class ParticleEmitter;
class ParticleEmitterData; class ParticleEmitterData;
@ -91,8 +92,19 @@ class SplashData : public GameBaseData
}; };
public: public:
AudioProfile* soundProfile; //AudioProfile* soundProfile;
S32 soundProfileId; //S32 soundProfileId;
DECLARE_SOUNDASSET(SplashData, Sound);
DECLARE_SOUNDASSET_SETGET(SplashData, Sound);
/// this should probably be added as a function higher up to stop repeats.
SFXProfile* getSFXProfile() {
if (mSoundAsset.notNull())
return mSoundAsset->getSfxProfile();
else
return NULL;
}
ParticleEmitterData* emitterList[NUM_EMITTERS]; ParticleEmitterData* emitterList[NUM_EMITTERS];
S32 emitterIDList[NUM_EMITTERS]; S32 emitterIDList[NUM_EMITTERS];