mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
Merge pull request #1605 from marauder2k9-torque/Asset-Networking
follow up to asset data management
This commit is contained in:
commit
3448d8f21a
|
|
@ -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<SFXSource*>(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<SFXSource*>(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<SFXSource*>(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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<SoundAsset> tempSoundAsset;
|
||||
tempSoundAsset = temp;
|
||||
|
||||
mAsset = temp;
|
||||
}
|
||||
mAsset = AssetDatabase.unpackUpdateAsset(con, stream);
|
||||
|
||||
sentTransform = stream->readFlag();
|
||||
if (sentTransform) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue