very small sound asset changes

Adds the resolved track stuff from the soundAsset refactor
also uses the refresh asset so changes do not cause a sound to stop working
This commit is contained in:
marauder2k7 2026-05-09 15:54:04 +01:00
parent bcde183786
commit 823054ed86
6 changed files with 459 additions and 260 deletions

View file

@ -59,31 +59,43 @@
IMPLEMENT_CONOBJECT(SoundAsset);
ConsoleType(SoundAssetPtr, TypeSoundAssetPtr, const char*, ASSET_ID_FIELD_PREFIX)
IMPLEMENT_STRUCT(AssetPtr<SoundAsset>, AssetPtrSoundAsset, , "")
END_IMPLEMENT_STRUCT
//-----------------------------------------------------------------------------
ConsoleType(SoundAssetPtr, TypeSoundAssetPtr, AssetPtr<SoundAsset>, ASSET_ID_FIELD_PREFIX)
ConsoleGetType(TypeSoundAssetPtr)
{
// Fetch asset Id.
return *((const char**)(dptr));
return (*((AssetPtr<SoundAsset>*)dptr)).getAssetId();
}
//-----------------------------------------------------------------------------
ConsoleSetType(TypeSoundAssetPtr)
{
// Was a single argument specified?
if (argc == 1)
{
// Yes, so fetch field value.
*((const char**)dptr) = StringTable->insert(argv[0]);
const char* pFieldValue = argv[0];
// Fetch asset pointer.
AssetPtr<SoundAsset>* pAssetPtr = dynamic_cast<AssetPtr<SoundAsset>*>((AssetPtrBase*)(dptr));
// Is the asset pointer the correct type?
if (pAssetPtr == NULL)
{
Con::warnf("(TypeSoundAssetPtrRefactor) - Failed to set asset Id '%d'.", pFieldValue);
return;
}
// Set asset.
pAssetPtr->setAssetId(pFieldValue);
return;
}
// Warn.
Con::warnf("(TypeSoundAssetPtr) - Cannot set multiple args to a single asset.");
Con::warnf("(TypeSoundAssetPtrRefactor) - Cannot set multiple args to a single asset.");
}
//-----------------------------------------------------------------------------
@ -134,7 +146,7 @@ SoundAsset::SoundAsset()
for (U32 i = 0; i < SFXPlayList::NUM_SLOTS; i++)
{
mSoundFile[i] = StringTable->EmptyString();
mSoundPath[i] = StringTable->EmptyString();
mSoundResource[i] = NULL;
mPlaylist.mSlots.mTransitionOut[i] = SFXPlayList::TRANSITION_Wait;
mPlaylist.mSlots.mVolumeScale.mValue[i] = 1.f;
@ -184,6 +196,9 @@ SoundAsset::SoundAsset()
mPlaylist.mLoopMode = SFXPlayList::LOOP_All;
mPlaylist.mActiveSlots = 1;
mResolvedTrack = NULL;
mResolvedDescription = NULL;
}
//-----------------------------------------------------------------------------
@ -191,8 +206,17 @@ SoundAsset::SoundAsset()
SoundAsset::~SoundAsset()
{
if (mPlaylist.isProperlyAdded() && !mPlaylist.isDeleted())
mPlaylist.unregisterObject();
if (mResolvedTrack)
{
if (mResolvedTrack->isProperlyAdded() && !mResolvedTrack->isDeleted())
mResolvedTrack->deleteObject();
}
if (mResolvedDescription)
{
if (mResolvedDescription->isProperlyAdded() && !mResolvedDescription->isDeleted())
mResolvedDescription->deleteObject();
}
}
//-----------------------------------------------------------------------------
@ -203,77 +227,77 @@ void SoundAsset::initPersistFields()
Parent::initPersistFields();
addGroup("SoundSlots");
addArray("slots", SFXPlayList::SFXPlaylistSettings::NUM_SLOTS);
addProtectedField("soundFile", TypeAssetLooseFilePath, Offset(mSoundFile, SoundAsset),
&_setSoundFile, &defaultProtectedGetFn, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS, "Path to the sound file.");
addProtectedField("soundFile", TypeAssetLooseFilePath, Offset(mSoundFile, SoundAsset),
&_setSoundFile, &defaultProtectedGetFn, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS, "Path to the sound file.");
addField("replay", TYPEID< SFXPlayList::EReplayMode >(), Offset(mPlaylist.mSlots.mReplayMode, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Behavior when an already playing sound is encountered on this slot from a previous cycle.\n"
"Each slot can have an arbitrary number of sounds playing on it from previous cycles. This field determines "
"how SFXController will handle these sources.");
addField("transitionIn", TYPEID< SFXPlayList::ETransitionMode >(), Offset(mPlaylist.mSlots.mTransitionIn, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Behavior when moving into this slot.\n"
"After the delayIn time has expired (if any), this slot determines what the controller "
"will do before actually playing the slot.");
addField("transitionOut", TYPEID< SFXPlayList::ETransitionMode >(), Offset(mPlaylist.mSlots.mTransitionOut, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Behavior when moving out of this slot.\n"
"After the #detailTimeOut has expired (if any), this slot determines what the controller "
"will do before moving on to the next slot.");
addFieldV("delayTimeIn", TypeRangedF32, Offset(mPlaylist.mSlots.mDelayTimeIn.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Seconds to wait after moving into slot before #transitionIn.");
addField("delayTimeInVariance", TypePoint2F, Offset(mPlaylist.mSlots.mDelayTimeIn.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #delayTimeIn.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("delayTimeOut", TypeRangedF32, Offset(mPlaylist.mSlots.mDelayTimeOut.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Seconds to wait before moving out of slot after #transitionOut.");
addField("delayTimeOutVariance", TypePoint2F, Offset(mPlaylist.mSlots.mDelayTimeOut.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #delayTimeOut.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("fadeTimeIn", TypeRangedF32, Offset(mPlaylist.mSlots.mFadeTimeIn.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Seconds to fade sound in (-1 to use the track's own fadeInTime.)\n"
"@see SFXDescription::fadeTimeIn");
addField("fadeTimeInVariance", TypePoint2F, Offset(mPlaylist.mSlots.mFadeTimeIn.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #fadeInTime.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("fadeTimeOut", TypeRangedF32, Offset(mPlaylist.mSlots.mFadeTimeOut.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Seconds to fade sound out (-1 to use the track's own fadeOutTime.)\n"
"@see SFXDescription::fadeTimeOut");
addField("fadeTimeOutVariance", TypePoint2F, Offset(mPlaylist.mSlots.mFadeTimeOut.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #fadeOutTime\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("referenceDistance", TypeRangedF32, Offset(mPlaylist.mSlots.mMinDistance.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"@c referenceDistance to set for 3D sounds in this slot (<1 to use @c referenceDistance of track's own description).\n"
"@see SFXDescription::referenceDistance");
addField("referenceDistanceVariance", TypePoint2F, Offset(mPlaylist.mSlots.mMinDistance.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #referenceDistance.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("maxSlotDistance", TypeRangedF32, Offset(mPlaylist.mSlots.mMaxDistance.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"@c maxDistance to apply to 3D sounds in this slot (<1 to use @c maxDistance of track's own description).\n"
"@see SFXDescription::maxDistance");
addField("maxSlotDistanceVariance", TypePoint2F, Offset(mPlaylist.mSlots.mMaxDistance.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #maxDistance.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("volumeScale", TypeRangedF32, Offset(mPlaylist.mSlots.mVolumeScale.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Scale factor to apply to volume of sounds played on this list slot.\n"
"This value will scale the actual volume level set on the track assigned to the slot, i.e. a value of 0.5 will "
"cause the track to play at half-volume.");
addField("volumeScaleVariance", TypePoint2F, Offset(mPlaylist.mSlots.mVolumeScale.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #volumeScale.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("pitchScale", TypeRangedF32, Offset(mPlaylist.mSlots.mPitchScale.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Scale factor to apply to pitch of sounds played on this list slot.\n"
"This value will scale the actual pitch set on the track assigned to the slot, i.e. a value of 0.5 will "
"cause the track to play at half its assigned speed.");
addField("pitchScaleVariance", TypePoint2F, Offset(mPlaylist.mSlots.mPitchScale.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #pitchScale.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("repeatCount", TypeRangedS32, Offset(mPlaylist.mSlots.mRepeatCount, SoundAsset), &CommonValidators::PositiveInt, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Number of times to loop this slot.");
addField("state", TypeSFXStateName, Offset(mPlaylist.mSlots.mState, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"State that must be active for this slot to play.\n\n"
"@ref SFXPlayList_states");
addField("stateMode", TYPEID< SFXPlayList::EStateMode >(), Offset(mPlaylist.mSlots.mStateMode, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Behavior when assigned state is deactivated while slot is playing.\n\n"
"@ref SFXPlayList_states");
addField("replay", TYPEID< SFXPlayList::EReplayMode >(), Offset(mPlaylist.mSlots.mReplayMode, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Behavior when an already playing sound is encountered on this slot from a previous cycle.\n"
"Each slot can have an arbitrary number of sounds playing on it from previous cycles. This field determines "
"how SFXController will handle these sources.");
addField("transitionIn", TYPEID< SFXPlayList::ETransitionMode >(), Offset(mPlaylist.mSlots.mTransitionIn, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Behavior when moving into this slot.\n"
"After the delayIn time has expired (if any), this slot determines what the controller "
"will do before actually playing the slot.");
addField("transitionOut", TYPEID< SFXPlayList::ETransitionMode >(), Offset(mPlaylist.mSlots.mTransitionOut, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Behavior when moving out of this slot.\n"
"After the #detailTimeOut has expired (if any), this slot determines what the controller "
"will do before moving on to the next slot.");
addFieldV("delayTimeIn", TypeRangedF32, Offset(mPlaylist.mSlots.mDelayTimeIn.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Seconds to wait after moving into slot before #transitionIn.");
addField("delayTimeInVariance", TypePoint2F, Offset(mPlaylist.mSlots.mDelayTimeIn.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #delayTimeIn.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("delayTimeOut", TypeRangedF32, Offset(mPlaylist.mSlots.mDelayTimeOut.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Seconds to wait before moving out of slot after #transitionOut.");
addField("delayTimeOutVariance", TypePoint2F, Offset(mPlaylist.mSlots.mDelayTimeOut.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #delayTimeOut.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("fadeTimeIn", TypeRangedF32, Offset(mPlaylist.mSlots.mFadeTimeIn.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Seconds to fade sound in (-1 to use the track's own fadeInTime.)\n"
"@see SFXDescription::fadeTimeIn");
addField("fadeTimeInVariance", TypePoint2F, Offset(mPlaylist.mSlots.mFadeTimeIn.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #fadeInTime.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("fadeTimeOut", TypeRangedF32, Offset(mPlaylist.mSlots.mFadeTimeOut.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Seconds to fade sound out (-1 to use the track's own fadeOutTime.)\n"
"@see SFXDescription::fadeTimeOut");
addField("fadeTimeOutVariance", TypePoint2F, Offset(mPlaylist.mSlots.mFadeTimeOut.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #fadeOutTime\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("referenceDistance", TypeRangedF32, Offset(mPlaylist.mSlots.mMinDistance.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"@c referenceDistance to set for 3D sounds in this slot (<1 to use @c referenceDistance of track's own description).\n"
"@see SFXDescription::referenceDistance");
addField("referenceDistanceVariance", TypePoint2F, Offset(mPlaylist.mSlots.mMinDistance.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #referenceDistance.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("maxSlotDistance", TypeRangedF32, Offset(mPlaylist.mSlots.mMaxDistance.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"@c maxDistance to apply to 3D sounds in this slot (<1 to use @c maxDistance of track's own description).\n"
"@see SFXDescription::maxDistance");
addField("maxSlotDistanceVariance", TypePoint2F, Offset(mPlaylist.mSlots.mMaxDistance.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #maxDistance.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("volumeScale", TypeRangedF32, Offset(mPlaylist.mSlots.mVolumeScale.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Scale factor to apply to volume of sounds played on this list slot.\n"
"This value will scale the actual volume level set on the track assigned to the slot, i.e. a value of 0.5 will "
"cause the track to play at half-volume.");
addField("volumeScaleVariance", TypePoint2F, Offset(mPlaylist.mSlots.mVolumeScale.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #volumeScale.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("pitchScale", TypeRangedF32, Offset(mPlaylist.mSlots.mPitchScale.mValue, SoundAsset), &CommonValidators::PositiveFloat, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Scale factor to apply to pitch of sounds played on this list slot.\n"
"This value will scale the actual pitch set on the track assigned to the slot, i.e. a value of 0.5 will "
"cause the track to play at half its assigned speed.");
addField("pitchScaleVariance", TypePoint2F, Offset(mPlaylist.mSlots.mPitchScale.mVariance, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Bounds on randomization of #pitchScale.\n\n"
"@ref SFXPlayList_randomization\n");
addFieldV("repeatCount", TypeRangedS32, Offset(mPlaylist.mSlots.mRepeatCount, SoundAsset), &CommonValidators::PositiveInt, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Number of times to loop this slot.");
addField("state", TypeSFXStateName, Offset(mPlaylist.mSlots.mState, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"State that must be active for this slot to play.\n\n"
"@ref SFXPlayList_states");
addField("stateMode", TYPEID< SFXPlayList::EStateMode >(), Offset(mPlaylist.mSlots.mStateMode, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS,
"Behavior when assigned state is deactivated while slot is playing.\n\n"
"@ref SFXPlayList_states");
endArray("slots");
endGroup("SoundSlots");
@ -285,48 +309,79 @@ void SoundAsset::initPersistFields()
// if streaming, a default packet size should be chosen for all sounds.
addField("isStreaming", TypeBool, Offset(mProfileDesc.mIsStreaming, SoundAsset), "Use streaming.");
//....why?
addFieldV("priority", TypeRangedF32, Offset(mProfileDesc.mPriority, SoundAsset), &CommonValidators::PositiveFloat, "Priority level for virtualization of sounds (1 = base level).\n"
"When there are more concurrently active sounds than supported by the audio mixer, some of the sounds "
"need to be culled. Which sounds are culled first depends primarily on total audibility of individual sounds. "
"However, the priority of invidual sounds may be decreased or decreased through this field.\n\n"
"@ref SFXSound_virtualization");
addField("parameters", TypeSFXParameterName, Offset(mProfileDesc.mParameters, SoundAsset), SFXDescription::MaxNumParameters,
"Names of the parameters to which sources using this description will automatically be linked.\n\n"
"Individual parameters are identified by their #internalName.\n\n"
"@ref SFX_interactive");
addField("useHardware", TypeBool, Offset(mProfileDesc.mUseHardware, SoundAsset), "Use hardware mixing for this sound.");
addField("sourceGroup", TypeSFXSourceName, Offset(mProfileDesc.mSourceGroup, SoundAsset), "Group that sources playing with this description should be put into.");
addField("preload", TypeBool, Offset(mPreload, SoundAsset), "Whether to preload sound data when the profile is added to system.");
endGroup("General Profile");
addGroup("Fading");
addFieldV("fadeInTime", TypeRangedF32, Offset(mProfileDesc.mFadeInTime, SoundAsset), &CommonValidators::PositiveFloat, "Number of seconds to gradually fade in volume from zero when playback starts.");
addFieldV("fadeOutTime", TypeRangedF32, Offset(mProfileDesc.mFadeOutTime, SoundAsset), &CommonValidators::PositiveFloat, "Number of seconds to gradually fade out volume down to zero when playback is stopped or paused.");
addField("fadeInEase", TypeEaseF, Offset(mProfileDesc.mFadeInEase, SoundAsset), "Easing curve for fade-in transition.");
addField("fadeOutEase", TypeEaseF, Offset(mProfileDesc.mFadeOutEase, SoundAsset), "Easing curve for fade-out transition.");
addField("fadeLoops", TypeBool, Offset(mProfileDesc.mFadeLoops, SoundAsset), "Fade each cycle of a loop in and/or out; otherwise only fade-in first cycle.");
addFieldV("fadeInTime", TypeRangedF32, Offset(mProfileDesc.mFadeInTime, SoundAsset), &CommonValidators::PositiveFloat, "Number of seconds to gradually fade in volume from zero when playback starts.");
addFieldV("fadeOutTime", TypeRangedF32, Offset(mProfileDesc.mFadeOutTime, SoundAsset), &CommonValidators::PositiveFloat, "Number of seconds to gradually fade out volume down to zero when playback is stopped or paused.");
addField("fadeInEase", TypeEaseF, Offset(mProfileDesc.mFadeInEase, SoundAsset), "Easing curve for fade-in transition.");
addField("fadeOutEase", TypeEaseF, Offset(mProfileDesc.mFadeOutEase, SoundAsset), "Easing curve for fade-out transition.");
addField("fadeLoops", TypeBool, Offset(mProfileDesc.mFadeLoops, SoundAsset), "Fade each cycle of a loop in and/or out; otherwise only fade-in first cycle.");
endGroup("Fading");
addGroup("3D");
addFieldV("minDistance", TypeRangedF32, Offset(mProfileDesc.mMinDistance, SoundAsset), &CommonValidators::PositiveFloat, "Minimum distance for sound.");
addFieldV("maxDistance", TypeRangedF32, Offset(mProfileDesc.mMaxDistance, SoundAsset), &CommonValidators::PositiveFloat, "Max distance for sound.");
addFieldV("coneInsideAngle", TypeRangedS32, Offset(mProfileDesc.mConeInsideAngle, SoundAsset), &CommonValidators::S32_PosDegreeRange, "Cone inside angle.");
addFieldV("coneOutsideAngle", TypeRangedS32, Offset(mProfileDesc.mConeOutsideAngle, SoundAsset), &CommonValidators::S32_PosDegreeRange, "Cone outside angle.");
addFieldV("coneOutsideVolume", TypeRangedF32, Offset(mProfileDesc.mConeOutsideVolume, SoundAsset), &CommonValidators::NormalizedFloat, "Cone outside volume.");
addFieldV("rolloffFactor", TypeRangedF32, Offset(mProfileDesc.mRolloffFactor, SoundAsset), &CommonValidators::NegDefaultF32, "Rolloff factor.");
addField("scatterDistance", TypePoint3F, Offset(mProfileDesc.mScatterDistance, SoundAsset), "Randomization to the spacial position of the sound.");
addFieldV("minDistance", TypeRangedF32, Offset(mProfileDesc.mMinDistance, SoundAsset), &CommonValidators::PositiveFloat, "Minimum distance for sound.");
addFieldV("maxDistance", TypeRangedF32, Offset(mProfileDesc.mMaxDistance, SoundAsset), &CommonValidators::PositiveFloat, "Max distance for sound.");
addFieldV("coneInsideAngle", TypeRangedS32, Offset(mProfileDesc.mConeInsideAngle, SoundAsset), &CommonValidators::S32_PosDegreeRange, "Cone inside angle.");
addFieldV("coneOutsideAngle", TypeRangedS32, Offset(mProfileDesc.mConeOutsideAngle, SoundAsset), &CommonValidators::S32_PosDegreeRange, "Cone outside angle.");
addFieldV("coneOutsideVolume", TypeRangedF32, Offset(mProfileDesc.mConeOutsideVolume, SoundAsset), &CommonValidators::NormalizedFloat, "Cone outside volume.");
addFieldV("rolloffFactor", TypeRangedF32, Offset(mProfileDesc.mRolloffFactor, SoundAsset), &CommonValidators::NegDefaultF32, "Rolloff factor.");
addField("scatterDistance", TypePoint3F, Offset(mProfileDesc.mScatterDistance, SoundAsset), "Randomization to the spacial position of the sound.");
endGroup("3D");
addGroup("Playlist settings");
addField("random", TYPEID< SFXPlayList::ERandomMode >(), Offset(mPlaylist.mRandomMode, SoundAsset), "Slot playback order randomization pattern.");
addField("loopMode", TYPEID< SFXPlayList::ELoopMode >(), Offset(mPlaylist.mLoopMode, SoundAsset), "Behavior when description has looping enabled.");
addFieldV("numSlotsToPlay", TypeRangedS32, Offset(mPlaylist.mNumSlotsToPlay, SoundAsset), &playlistSlotRange, "Number of slots to play.");
addField("trace", TypeBool, Offset(mPlaylist.mTrace, SoundAsset), "Enable/disable execution tracing for this playlist (local only).");
addField("random", TYPEID< SFXPlayList::ERandomMode >(), Offset(mPlaylist.mRandomMode, SoundAsset), "Slot playback order randomization pattern.");
addField("loopMode", TYPEID< SFXPlayList::ELoopMode >(), Offset(mPlaylist.mLoopMode, SoundAsset), "Behavior when description has looping enabled.");
addFieldV("numSlotsToPlay", TypeRangedS32, Offset(mPlaylist.mNumSlotsToPlay, SoundAsset), &playlistSlotRange, "Number of slots to play.");
addField("trace", TypeBool, Offset(mPlaylist.mTrace, SoundAsset), "Enable/disable execution tracing for this playlist (local only).");
endGroup("Playlist settings");
}
//------------------------------------------------------------------------------
void SoundAsset::onRemove()
{
for (U32 i = 0; i < SFXPlayList::SFXPlaylistSettings::NUM_SLOTS; i++)
{
if (mSoundFile[i] == StringTable->EmptyString())
break;
Torque::FS::RemoveChangeNotification(mSoundFile[i], this, &SoundAsset::_onResourceChanged);
}
Parent::onRemove();
}
void SoundAsset::inspectPostApply()
{
Parent::inspectPostApply();
refreshAsset();
}
void SoundAsset::copyTo(SimObject* object)
{
// Call to parent.
Parent::copyTo(object);
}
void SoundAsset::initializeAsset(void)
{
Parent::initializeAsset();
for (U32 i = 0; i < SFXPlayList::SFXPlaylistSettings::NUM_SLOTS; i++)
{
if (i == 0 && mSoundFile[i] == StringTable->EmptyString())
@ -335,134 +390,59 @@ void SoundAsset::initializeAsset(void)
if (mSoundFile[i] == StringTable->EmptyString())
break;
mSoundPath[i] = getOwned() ? expandAssetFilePath(mSoundFile[i]) : mSoundPath[i];
if (!Torque::FS::IsFile(mSoundPath[i]))
Con::errorf("SoundAsset::initializeAsset (%s)[%d] could not find %s!", getAssetName(), i, mSoundPath[i]);
mSoundFile[i] = expandAssetFilePath(mSoundFile[i]);
if (getOwned())
Torque::FS::AddChangeNotification(mSoundFile[i], this, &SoundAsset::_onResourceChanged);
}
populateSFXTrack();
}
void SoundAsset::_onResourceChanged(const Torque::Path &path)
void SoundAsset::_onResourceChanged(const Torque::Path& path)
{
for (U32 i = 0; i < SFXPlayList::NUM_SLOTS; i++)
{
if (path != Torque::Path(mSoundPath[i]))
if (path != Torque::Path(mSoundFile[i]))
return;
}
refreshAsset();
}
void SoundAsset::onAssetRefresh(void)
{
for (U32 i = 0; i < SFXPlayList::SFXPlaylistSettings::NUM_SLOTS; i++)
{
if (i == 0 && mSoundFile[i] == StringTable->EmptyString())
return;
if (!isProperlyAdded())
return;
if (mSoundFile[i] == StringTable->EmptyString())
break;
mSoundPath[i] = getOwned() ? expandAssetFilePath(mSoundFile[i]) : mSoundPath[i];
}
Parent::onAssetRefresh();
populateSFXTrack();
}
U32 SoundAsset::load()
{
if (mLoadedState == AssetErrCode::Ok) return mLoadedState;
if (mLoadedState == AssetErrCode::Ok)
return mLoadedState;
// find out how many active slots we have.
U32 numSlots = 0;
for (U32 i = 0; i < SFXPlayList::SFXPlaylistSettings::NUM_SLOTS; i++)
if (!mResolvedTrack)
{
if (i == 0 && mSoundPath[i] == StringTable->EmptyString())
return false;
if (mSoundPath[i] == StringTable->EmptyString())
break;
numSlots++;
}
if (mProfileDesc.mSourceGroup == NULL)
mProfileDesc.mSourceGroup = dynamic_cast<SFXSource*>(Sim::findObject("AudioChannelMaster"));
if (numSlots > 1)
{
mIsPlaylist = true;
for (U32 i = 0; i < numSlots; i++)
if (mIsPlaylist)
{
if (mSoundPath[i])
{
if (!Torque::FS::IsFile(mSoundPath[i]))
{
Con::errorf("SoundAsset::initializeAsset: Attempted to load file %s but it was not valid!", mSoundFile[i]);
mLoadedState = BadFileReference;
return mLoadedState;
}
else
{
mSFXProfile[i] = new SFXProfile;
mSFXProfile[i]->setDescription(&mProfileDesc);
mSFXProfile[i]->setSoundFileName(mSoundPath[i]);
mSFXProfile[i]->setPreload(mPreload);
mSFXProfile[i]->registerObject(String::ToString("%s_profile_track%d", getAssetName()).c_str());
mPlaylist.mSlots.mTrack[i] = mSFXProfile[i];
}
}
mResolvedTrack = buildPlaylist();
}
else
{
mResolvedTrack = buildProfile();
}
mPlaylist.setDescription(&mProfileDesc);
mPlaylist.registerObject(String::ToString("%s_playlist", getAssetName()).c_str());
}
else
{
if (mSoundPath[0])
{
if (!Torque::FS::IsFile(mSoundPath[0]))
{
Con::errorf("SoundAsset::initializeAsset: Attempted to load file %s but it was not valid!", mSoundFile[0]);
mLoadedState = BadFileReference;
return mLoadedState;
}
else
{
mSFXProfile[0] = new SFXProfile;
mSFXProfile[0]->setDescription(&mProfileDesc);
mSFXProfile[0]->setSoundFileName(mSoundPath[0]);
mSFXProfile[0]->setPreload(mPreload);
mSFXProfile[0]->registerObject(String::ToString("%s_profile", getAssetName()).c_str());
}
}
mResolvedTrack->registerObject(String::ToString("%s_profile_track", getAssetName()).c_str());
}
mChangeSignal.trigger();
mLoadedState = Ok;
return mLoadedState;
}
bool SoundAsset::_setSoundFile(void* object, const char* index, const char* data)
{
SoundAsset* pData = static_cast<SoundAsset*>(object);
U32 id = 0;
if (index)
id = dAtoui(index);
// Update.
pData->mSoundFile[id] = StringTable->insert(data, true);
if (pData->mSoundFile[id] == StringTable->EmptyString())
pData->mSoundPath[id] = StringTable->EmptyString();
// Refresh the asset.
pData->refreshAsset();
return true;
}
StringTableEntry SoundAsset::getAssetIdByFileName(StringTableEntry fileName)
{
if (fileName == StringTable->EmptyString())
@ -479,7 +459,7 @@ StringTableEntry SoundAsset::getAssetIdByFileName(StringTableEntry fileName)
SoundAsset* soundAsset = AssetDatabase.acquireAsset<SoundAsset>(query.mAssetList[i]);
if (soundAsset)
{
if (soundAsset->getSoundPath() == fileName)
if (soundAsset->getSoundFile() == fileName)
soundAssetId = soundAsset->getAssetId();
AssetDatabase.releaseAsset(query.mAssetList[i]);
@ -506,7 +486,7 @@ U32 SoundAsset::getAssetById(StringTableEntry assetId, AssetPtr<SoundAsset>* sou
}
}
U32 SoundAsset::getAssetByFileName(StringTableEntry fileName, AssetPtr<SoundAsset>* soundAsset)
U32 SoundAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<SoundAsset>* soundAsset)
{
AssetQuery query;
U32 foundAssetcount = AssetDatabase.findAssetType(&query, "SoundAsset");
@ -521,7 +501,7 @@ U32 SoundAsset::getAssetByFileName(StringTableEntry fileName, AssetPtr<SoundAsse
for (U32 i = 0; i < foundAssetcount; i++)
{
SoundAsset* tSoundAsset = AssetDatabase.acquireAsset<SoundAsset>(query.mAssetList[i]);
if (tSoundAsset && tSoundAsset->getSoundPath() == fileName)
if (tSoundAsset && tSoundAsset->getSoundFile() == fileName)
{
soundAsset->setAssetId(query.mAssetList[i]);
AssetDatabase.releaseAsset(query.mAssetList[i]);
@ -535,9 +515,172 @@ U32 SoundAsset::getAssetByFileName(StringTableEntry fileName, AssetPtr<SoundAsse
return AssetErrCode::Failed;
}
void SoundAsset::buildDescription()
{
if (!mResolvedDescription)
{
mResolvedDescription = new SFXDescription;
// calls on add which should validate the description. but do it on mProfileDesc before applying values anyway.
mResolvedDescription->registerObject(String::ToString("%s_profile_description", getAssetName()).c_str());
}
mProfileDesc.validate();
mResolvedDescription->mPitch = mProfileDesc.mPitch;
mResolvedDescription->mVolume = mProfileDesc.mVolume;
mResolvedDescription->mIs3D = mProfileDesc.mIs3D;
mResolvedDescription->mIsLooping = mProfileDesc.mIsLooping;
mResolvedDescription->mIsStreaming = mProfileDesc.mIsStreaming;
mResolvedDescription->mUseHardware = mProfileDesc.mUseHardware;
mResolvedDescription->mMinDistance = mProfileDesc.mMinDistance;
mResolvedDescription->mMaxDistance = mProfileDesc.mMaxDistance;
mResolvedDescription->mConeInsideAngle = mProfileDesc.mConeInsideAngle;
mResolvedDescription->mConeOutsideAngle = mProfileDesc.mConeOutsideAngle;
mResolvedDescription->mConeOutsideVolume = mProfileDesc.mConeOutsideVolume;
mResolvedDescription->mRolloffFactor = mProfileDesc.mRolloffFactor;
mResolvedDescription->mFadeInTime = mProfileDesc.mFadeInTime;
mResolvedDescription->mFadeOutTime = mProfileDesc.mFadeOutTime;
mResolvedDescription->mFadeLoops = mProfileDesc.mFadeLoops;
mResolvedDescription->mScatterDistance = mProfileDesc.mScatterDistance;
mResolvedDescription->mStreamPacketSize = mProfileDesc.mStreamPacketSize;
mResolvedDescription->mStreamReadAhead = mProfileDesc.mStreamReadAhead;
mResolvedDescription->mPriority = mProfileDesc.mPriority;
mResolvedDescription->mSourceGroup = mProfileDesc.mSourceGroup;
mResolvedDescription->mFadeInEase = mProfileDesc.mFadeInEase;
mResolvedDescription->mSourceGroup = mProfileDesc.mSourceGroup;
}
SFXProfile* SoundAsset::buildProfile()
{
SFXProfile* profile = new SFXProfile(mResolvedDescription, mSoundFile[0], mPreload);
mSoundResource[0] = profile->getResource();
return profile;
}
//-----------------------------------------------------------------------------
// BUILD PLAYLIST
//-----------------------------------------------------------------------------
SFXPlayList* SoundAsset::buildPlaylist()
{
SFXPlayList* pl = new SFXPlayList();
pl->mRandomMode = mPlaylist.mRandomMode;
pl->mLoopMode = mPlaylist.mLoopMode;
pl->mNumSlotsToPlay = mPlaylist.mNumSlotsToPlay;
pl->mTrace = mPlaylist.mTrace;
pl->mSlots = mPlaylist.mSlots;
// Build child tracks for each valid slot
for (U32 i = 0; i < SFXPlayList::SFXPlaylistSettings::NUM_SLOTS; ++i)
{
if (mSoundFile[i] == StringTable->EmptyString())
continue;
// Build child SFXProfile
SFXProfile* child = new SFXProfile(mResolvedDescription, mSoundFile[i], mPreload);
mSoundResource[i] = child->getResource();
pl->mSlots.mTrack[i] = child;
}
return pl;
}
void SoundAsset::populateSFXTrack(void)
{
U32 count = 0;
for (U32 i = 0; i < SFXPlayList::SFXPlaylistSettings::NUM_SLOTS; ++i)
{
if (mSoundFile[i] != StringTable->EmptyString())
{
if (!Torque::FS::IsFile(mSoundFile[i]))
{
mLoadedState = AssetErrCode::BadFileReference;
return;
}
++count;
}
}
mIsPlaylist = (count > 1);
buildDescription();
if (mResolvedTrack && mResolvedDescription)
{
if (SFX)
SFX->notifyDescriptionChanged(mResolvedDescription);
return;
}
mResolvedTrack = NULL;
// reset loaded state.
mLoadedState = AssetErrCode::NotLoaded;
}
void SoundAsset::setSoundFile(StringTableEntry pSoundFile, U32 slot)
{
AssertFatal(pSoundFile != NULL, "Cannot use a NULL sound file.");
pSoundFile = StringTable->insert(pSoundFile);
if (pSoundFile == mSoundFile[slot])
return;
mSoundFile[slot] = getOwned() ? expandAssetFilePath(pSoundFile) : StringTable->insert(pSoundFile);;
refreshAsset();
}
void SoundAsset::onTamlPreWrite(void)
{
// Call parent.
Parent::onTamlPreWrite();
for (U32 i = 0; i < SFXPlayList::SFXPlaylistSettings::NUM_SLOTS; i++)
{
if (mSoundFile[i] == StringTable->EmptyString())
break;
mSoundFile[i] = collapseAssetFilePath(mSoundFile[i]);
}
}
void SoundAsset::onTamlPostWrite(void)
{
for (U32 i = 0; i < SFXPlayList::SFXPlaylistSettings::NUM_SLOTS; i++)
{
if (mSoundFile[i] == StringTable->EmptyString())
break;
mSoundFile[i] = expandAssetFilePath(mSoundFile[i]);
}
}
void SoundAsset::onTamlCustomWrite(TamlCustomNodes& customNodes)
{
// Debug Profiling.
PROFILE_SCOPE(SoundAsset_OnTamlCustomWrite);
// Call parent.
Parent::onTamlCustomRead(customNodes);
}
void SoundAsset::onTamlCustomRead(const TamlCustomNodes& customNodes)
{
// Debug Profiling.
PROFILE_SCOPE(SoundAsset_OnTamlCustomRead);
// Call parent.
Parent::onTamlCustomRead(customNodes);
}
DefineEngineMethod(SoundAsset, getSoundPath, const char*, (), , "")
{
return object->getSoundPath();
return object->getSoundFile();
}
DefineEngineMethod(SoundAsset, playSound, S32, (Point3F position), (Point3F::Zero),
@ -549,12 +692,18 @@ DefineEngineMethod(SoundAsset, playSound, S32, (Point3F position), (Point3F::Zer
MatrixF transform;
transform.setPosition(position);
SFXSource* source;
if (position == Point3F::Zero || !object->is3D())
if (position == Point3F::Zero && !object->is3D())
{
source = SFX->playOnce(object->getSFXTrack());
}
else
{
if (position == Point3F::Zero)
transform = SFX->getListener().getTransform();
source = SFX->playOnce(object->getSFXTrack(), &transform, NULL, -1);
}
if(source)
if (source)
return source->getId();
else
return 0;
@ -585,7 +734,7 @@ void GuiInspectorTypeSoundAssetPtr::consoleInit()
ConsoleBaseType::getType(TypeSoundAssetPtr)->setInspectorFieldType("GuiInspectorTypeSoundAssetPtr");
}
GuiControl * GuiInspectorTypeSoundAssetPtr::constructEditControl()
GuiControl* GuiInspectorTypeSoundAssetPtr::constructEditControl()
{
// Create base filename edit controls
GuiControl* retCtrl = Parent::constructEditControl();