diff --git a/Engine/source/T3D/assets/SoundAsset.cpp b/Engine/source/T3D/assets/SoundAsset.cpp index af834b2c2..f4882c50f 100644 --- a/Engine/source/T3D/assets/SoundAsset.cpp +++ b/Engine/source/T3D/assets/SoundAsset.cpp @@ -149,7 +149,7 @@ SoundAsset::SoundAsset() mSubtitleString = StringTable->EmptyString(); mLoadedState = AssetErrCode::NotLoaded; - mPreload = false; + mPreload = true; // SFX description inits // reverb is useless here, reverb is inacted on listener. mProfileDesc.mPitch = 1; @@ -164,10 +164,17 @@ SoundAsset::SoundAsset() mProfileDesc.mConeOutsideAngle = 360; mProfileDesc.mConeOutsideVolume = 1; mProfileDesc.mRolloffFactor = -1.0f; + mProfileDesc.mFadeInTime = 0.0f; + mProfileDesc.mFadeOutTime = 0.0f; + mProfileDesc.mFadeLoops = false; mProfileDesc.mScatterDistance = Point3F(0.f, 0.f, 0.f); + mProfileDesc.mStreamPacketSize = 8; + mProfileDesc.mStreamReadAhead = 3; mProfileDesc.mPriority = 1.0f; mProfileDesc.mSourceGroup = NULL; mProfileDesc.mFadeInEase = EaseF(); + mProfileDesc.mReverb = SFXSoundReverbProperties(); + dMemset(mProfileDesc.mParameters, 0, sizeof(mProfileDesc.mParameters)); mIsPlaylist = false; mPlaylist.mNumSlotsToPlay = SFXPlayList::SFXPlaylistSettings::NUM_SLOTS; @@ -182,6 +189,15 @@ SoundAsset::SoundAsset() SoundAsset::~SoundAsset() { + + for (U32 i = 0; i < SFXPlayList::NUM_SLOTS; i++) + { + if(mSFXProfile[i].isProperlyAdded() && !mSFXProfile[i].isDeleted()) + mSFXProfile[i].unregisterObject(); + } + + if (mPlaylist.isProperlyAdded() && !mPlaylist.isDeleted()) + mPlaylist.unregisterObject(); } //----------------------------------------------------------------------------- @@ -353,6 +369,7 @@ void SoundAsset::onAssetRefresh(void) mSoundPath[i] = getOwned() ? expandAssetFilePath(mSoundFile[i]) : mSoundPath[i]; } + } U32 SoundAsset::load() @@ -372,6 +389,8 @@ U32 SoundAsset::load() numSlots++; } + if (mProfileDesc.mSourceGroup == NULL) + mProfileDesc.mSourceGroup = dynamic_cast(Sim::findObject("AudioChannelMaster")); if (numSlots > 1) { @@ -391,16 +410,14 @@ U32 SoundAsset::load() return mLoadedState; } else - {// = new SFXProfile(mProfileDesc, mSoundFile, mPreload); - if (mProfileDesc.mSourceGroup == NULL) - mProfileDesc.mSourceGroup = dynamic_cast(Sim::findObject("AudioChannelMaster")); + { SFXProfile* trackProfile = new SFXProfile(); trackProfile->setDescription(&mProfileDesc); trackProfile->setSoundFileName(mSoundPath[i]); trackProfile->setPreload(mPreload); - trackProfile->getBuffer(); mSFXProfile[i] = *trackProfile; + mSFXProfile[i].registerObject(String::ToString("%s_profile_track%d", getAssetName()).c_str()); mPlaylist.mSlots.mTrack[i] = trackProfile; @@ -409,6 +426,7 @@ U32 SoundAsset::load() } mPlaylist.setDescription(&mProfileDesc); + mPlaylist.registerObject(String::ToString("%s_playlist", getAssetName()).c_str()); } else { @@ -424,15 +442,12 @@ U32 SoundAsset::load() return mLoadedState; } else - {// = new SFXProfile(mProfileDesc, mSoundFile, mPreload); - if (mProfileDesc.mSourceGroup == NULL) - mProfileDesc.mSourceGroup = dynamic_cast(Sim::findObject("AudioChannelMaster")); + { mSFXProfile[0].setDescription(&mProfileDesc); mSFXProfile[0].setSoundFileName(mSoundPath[0]); mSFXProfile[0].setPreload(mPreload); - //give it a nudge to preload if required - mSFXProfile[0].getBuffer(); + mSFXProfile[0].registerObject(String::ToString("%s_profile", getAssetName()).c_str()); } } diff --git a/Engine/source/T3D/gameBase/gameConnectionEvents.cpp b/Engine/source/T3D/gameBase/gameConnectionEvents.cpp index 4b173902f..dbdab1c83 100644 --- a/Engine/source/T3D/gameBase/gameConnectionEvents.cpp +++ b/Engine/source/T3D/gameBase/gameConnectionEvents.cpp @@ -311,8 +311,7 @@ SimSoundAssetEvent::SimSoundAssetEvent(StringTableEntry assetId, const MatrixF* void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream) { - NetStringHandle assetIdStr = mAsset->getAssetId(); - con->packNetStringHandleU(stream, assetIdStr); + AssetDatabase.packUpdateAsset(con, 0, stream, mAsset.getAssetId()); SFXDescription* ad = mAsset->getSfxDescription(); if (stream->writeFlag(sentTransform)) @@ -348,14 +347,7 @@ void SimSoundAssetEvent::write(NetConnection* con, BitStream* stream) void SimSoundAssetEvent::unpack(NetConnection* con, BitStream* stream) { - StringTableEntry temp = StringTable->insert(con->unpackNetStringHandleU(stream).getString()); - if (AssetDatabase.isDeclaredAsset(temp)) - { - AssetPtr tempSoundAsset; - tempSoundAsset = temp; - - mAsset = temp; - } + mAsset = AssetDatabase.unpackUpdateAsset(con, stream); sentTransform = stream->readFlag(); if (sentTransform) { diff --git a/Engine/source/assets/assetManager.cpp b/Engine/source/assets/assetManager.cpp index 9f1f603ee..45ddb0c38 100644 --- a/Engine/source/assets/assetManager.cpp +++ b/Engine/source/assets/assetManager.cpp @@ -326,6 +326,17 @@ bool AssetManager::addDeclaredAsset( ModuleDefinition* pModuleDefinition, const //----------------------------------------------------------------------------- +static U32 HashAssetId(const char* str) +{ + U32 hash = 2166136261u; + while (*str) + { + hash ^= (U8)*str++; + hash *= 16777619u; + } + return hash; +} + StringTableEntry AssetManager::addPrivateAsset( AssetBase* pAssetBase ) { // Debug Profiling. @@ -377,6 +388,22 @@ StringTableEntry AssetManager::addPrivateAsset( AssetBase* pAssetBase ) // Set ownership by asset manager. pAssetDefinition->mpAssetBase->setOwned( this, pAssetDefinition ); + U32 netId = HashAssetId(pAssetDefinition->mAssetName); + + // Collision detection + typeNetIdToAssetMap::iterator netIterator = mNetIdToAsset.find(netId); + if (netIterator != mNetIdToAsset.end()) + { + Con::warnf( + "AssetManager: Hash collision for '%s' and '%s'", + pAssetDefinition->mAssetName, + mNetIdToAsset.find(netId)->value + ); + } + + mNetIdToAsset.insert(netId, pAssetDefinition->mAssetId); + mAssetToNetId.insert(pAssetDefinition->mAssetId, netId); + // Store in declared assets. mDeclaredAssets.insert( pAssetDefinition->mAssetId, pAssetDefinition ); @@ -475,6 +502,14 @@ bool AssetManager::removeDeclaredAsset( const char* pAssetId ) // Remove from declared assets. mDeclaredAssets.erase( declaredAssetItr ); + typeAssetToNetIdMap::iterator netId = mAssetToNetId.find(pAssetId); + typeNetIdToAssetMap::iterator netChar = mNetIdToAsset.find(netId->value); + if (netId != mAssetToNetId.end() && netChar != mNetIdToAsset.end()) + { + mNetIdToAsset.erase(netChar); + mAssetToNetId.erase(netId); + } + // Info. if ( mEchoInfo ) { @@ -2691,17 +2726,6 @@ const char* AssetManager::getAssetLooseFile(const char* pAssetId, const S32& ind //----------------------------------------------------------------------------- -static U32 HashAssetId(const char* str) -{ - U32 hash = 2166136261u; - while (*str) - { - hash ^= (U8)*str++; - hash *= 16777619u; - } - return hash; -} - bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension, const bool recurse, ModuleDefinition* pModuleDefinition ) { // Debug Profiling. @@ -2829,13 +2853,11 @@ bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension typeNetIdToAssetMap::iterator netIterator = mNetIdToAsset.find(netId); if (netIterator != mNetIdToAsset.end()) { - Con::errorf( + Con::warnf( "AssetManager: Hash collision for '%s' and '%s'", assetIdBuffer, mNetIdToAsset.find(netId)->value ); - - AssertFatal(false, "Asset hash collision detected."); } mNetIdToAsset.insert(netId, foundAssetDefinition.mAssetId);