mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 08:34:40 +00:00
Merge pull request #1605 from marauder2k9-torque/Asset-Networking
follow up to asset data management
This commit is contained in:
commit
3448d8f21a
3 changed files with 63 additions and 34 deletions
|
|
@ -149,7 +149,7 @@ SoundAsset::SoundAsset()
|
||||||
mSubtitleString = StringTable->EmptyString();
|
mSubtitleString = StringTable->EmptyString();
|
||||||
|
|
||||||
mLoadedState = AssetErrCode::NotLoaded;
|
mLoadedState = AssetErrCode::NotLoaded;
|
||||||
mPreload = false;
|
mPreload = true;
|
||||||
// SFX description inits
|
// SFX description inits
|
||||||
// reverb is useless here, reverb is inacted on listener.
|
// reverb is useless here, reverb is inacted on listener.
|
||||||
mProfileDesc.mPitch = 1;
|
mProfileDesc.mPitch = 1;
|
||||||
|
|
@ -164,10 +164,17 @@ SoundAsset::SoundAsset()
|
||||||
mProfileDesc.mConeOutsideAngle = 360;
|
mProfileDesc.mConeOutsideAngle = 360;
|
||||||
mProfileDesc.mConeOutsideVolume = 1;
|
mProfileDesc.mConeOutsideVolume = 1;
|
||||||
mProfileDesc.mRolloffFactor = -1.0f;
|
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.mScatterDistance = Point3F(0.f, 0.f, 0.f);
|
||||||
|
mProfileDesc.mStreamPacketSize = 8;
|
||||||
|
mProfileDesc.mStreamReadAhead = 3;
|
||||||
mProfileDesc.mPriority = 1.0f;
|
mProfileDesc.mPriority = 1.0f;
|
||||||
mProfileDesc.mSourceGroup = NULL;
|
mProfileDesc.mSourceGroup = NULL;
|
||||||
mProfileDesc.mFadeInEase = EaseF();
|
mProfileDesc.mFadeInEase = EaseF();
|
||||||
|
mProfileDesc.mReverb = SFXSoundReverbProperties();
|
||||||
|
dMemset(mProfileDesc.mParameters, 0, sizeof(mProfileDesc.mParameters));
|
||||||
mIsPlaylist = false;
|
mIsPlaylist = false;
|
||||||
|
|
||||||
mPlaylist.mNumSlotsToPlay = SFXPlayList::SFXPlaylistSettings::NUM_SLOTS;
|
mPlaylist.mNumSlotsToPlay = SFXPlayList::SFXPlaylistSettings::NUM_SLOTS;
|
||||||
|
|
@ -182,6 +189,15 @@ SoundAsset::SoundAsset()
|
||||||
|
|
||||||
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];
|
mSoundPath[i] = getOwned() ? expandAssetFilePath(mSoundFile[i]) : mSoundPath[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
U32 SoundAsset::load()
|
U32 SoundAsset::load()
|
||||||
|
|
@ -372,6 +389,8 @@ U32 SoundAsset::load()
|
||||||
numSlots++;
|
numSlots++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mProfileDesc.mSourceGroup == NULL)
|
||||||
|
mProfileDesc.mSourceGroup = dynamic_cast<SFXSource*>(Sim::findObject("AudioChannelMaster"));
|
||||||
|
|
||||||
if (numSlots > 1)
|
if (numSlots > 1)
|
||||||
{
|
{
|
||||||
|
|
@ -391,16 +410,14 @@ U32 SoundAsset::load()
|
||||||
return mLoadedState;
|
return mLoadedState;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{// = new SFXProfile(mProfileDesc, mSoundFile, mPreload);
|
{
|
||||||
if (mProfileDesc.mSourceGroup == NULL)
|
|
||||||
mProfileDesc.mSourceGroup = dynamic_cast<SFXSource*>(Sim::findObject("AudioChannelMaster"));
|
|
||||||
SFXProfile* trackProfile = new SFXProfile();
|
SFXProfile* trackProfile = new SFXProfile();
|
||||||
trackProfile->setDescription(&mProfileDesc);
|
trackProfile->setDescription(&mProfileDesc);
|
||||||
trackProfile->setSoundFileName(mSoundPath[i]);
|
trackProfile->setSoundFileName(mSoundPath[i]);
|
||||||
trackProfile->setPreload(mPreload);
|
trackProfile->setPreload(mPreload);
|
||||||
trackProfile->getBuffer();
|
|
||||||
|
|
||||||
mSFXProfile[i] = *trackProfile;
|
mSFXProfile[i] = *trackProfile;
|
||||||
|
mSFXProfile[i].registerObject(String::ToString("%s_profile_track%d", getAssetName()).c_str());
|
||||||
|
|
||||||
mPlaylist.mSlots.mTrack[i] = trackProfile;
|
mPlaylist.mSlots.mTrack[i] = trackProfile;
|
||||||
|
|
||||||
|
|
@ -409,6 +426,7 @@ U32 SoundAsset::load()
|
||||||
}
|
}
|
||||||
|
|
||||||
mPlaylist.setDescription(&mProfileDesc);
|
mPlaylist.setDescription(&mProfileDesc);
|
||||||
|
mPlaylist.registerObject(String::ToString("%s_playlist", getAssetName()).c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -424,15 +442,12 @@ U32 SoundAsset::load()
|
||||||
return mLoadedState;
|
return mLoadedState;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{// = new SFXProfile(mProfileDesc, mSoundFile, mPreload);
|
{
|
||||||
if (mProfileDesc.mSourceGroup == NULL)
|
|
||||||
mProfileDesc.mSourceGroup = dynamic_cast<SFXSource*>(Sim::findObject("AudioChannelMaster"));
|
|
||||||
mSFXProfile[0].setDescription(&mProfileDesc);
|
mSFXProfile[0].setDescription(&mProfileDesc);
|
||||||
mSFXProfile[0].setSoundFileName(mSoundPath[0]);
|
mSFXProfile[0].setSoundFileName(mSoundPath[0]);
|
||||||
mSFXProfile[0].setPreload(mPreload);
|
mSFXProfile[0].setPreload(mPreload);
|
||||||
|
|
||||||
//give it a nudge to preload if required
|
mSFXProfile[0].registerObject(String::ToString("%s_profile", getAssetName()).c_str());
|
||||||
mSFXProfile[0].getBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -311,8 +311,7 @@ SimSoundAssetEvent::SimSoundAssetEvent(StringTableEntry assetId, const MatrixF*
|
||||||
|
|
||||||
void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream)
|
void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream)
|
||||||
{
|
{
|
||||||
NetStringHandle assetIdStr = mAsset->getAssetId();
|
AssetDatabase.packUpdateAsset(con, 0, stream, mAsset.getAssetId());
|
||||||
con->packNetStringHandleU(stream, assetIdStr);
|
|
||||||
|
|
||||||
SFXDescription* ad = mAsset->getSfxDescription();
|
SFXDescription* ad = mAsset->getSfxDescription();
|
||||||
if (stream->writeFlag(sentTransform))
|
if (stream->writeFlag(sentTransform))
|
||||||
|
|
@ -348,14 +347,7 @@ void SimSoundAssetEvent::write(NetConnection* con, BitStream* stream)
|
||||||
void SimSoundAssetEvent::unpack(NetConnection* con, BitStream* stream)
|
void SimSoundAssetEvent::unpack(NetConnection* con, BitStream* stream)
|
||||||
{
|
{
|
||||||
|
|
||||||
StringTableEntry temp = StringTable->insert(con->unpackNetStringHandleU(stream).getString());
|
mAsset = AssetDatabase.unpackUpdateAsset(con, stream);
|
||||||
if (AssetDatabase.isDeclaredAsset(temp))
|
|
||||||
{
|
|
||||||
AssetPtr<SoundAsset> tempSoundAsset;
|
|
||||||
tempSoundAsset = temp;
|
|
||||||
|
|
||||||
mAsset = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
sentTransform = stream->readFlag();
|
sentTransform = stream->readFlag();
|
||||||
if (sentTransform) {
|
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 )
|
StringTableEntry AssetManager::addPrivateAsset( AssetBase* pAssetBase )
|
||||||
{
|
{
|
||||||
// Debug Profiling.
|
// Debug Profiling.
|
||||||
|
|
@ -377,6 +388,22 @@ StringTableEntry AssetManager::addPrivateAsset( AssetBase* pAssetBase )
|
||||||
// Set ownership by asset manager.
|
// Set ownership by asset manager.
|
||||||
pAssetDefinition->mpAssetBase->setOwned( this, pAssetDefinition );
|
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.
|
// Store in declared assets.
|
||||||
mDeclaredAssets.insert( pAssetDefinition->mAssetId, pAssetDefinition );
|
mDeclaredAssets.insert( pAssetDefinition->mAssetId, pAssetDefinition );
|
||||||
|
|
||||||
|
|
@ -475,6 +502,14 @@ bool AssetManager::removeDeclaredAsset( const char* pAssetId )
|
||||||
// Remove from declared assets.
|
// Remove from declared assets.
|
||||||
mDeclaredAssets.erase( declaredAssetItr );
|
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.
|
// Info.
|
||||||
if ( mEchoInfo )
|
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 )
|
bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension, const bool recurse, ModuleDefinition* pModuleDefinition )
|
||||||
{
|
{
|
||||||
// Debug Profiling.
|
// Debug Profiling.
|
||||||
|
|
@ -2829,13 +2853,11 @@ bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension
|
||||||
typeNetIdToAssetMap::iterator netIterator = mNetIdToAsset.find(netId);
|
typeNetIdToAssetMap::iterator netIterator = mNetIdToAsset.find(netId);
|
||||||
if (netIterator != mNetIdToAsset.end())
|
if (netIterator != mNetIdToAsset.end())
|
||||||
{
|
{
|
||||||
Con::errorf(
|
Con::warnf(
|
||||||
"AssetManager: Hash collision for '%s' and '%s'",
|
"AssetManager: Hash collision for '%s' and '%s'",
|
||||||
assetIdBuffer,
|
assetIdBuffer,
|
||||||
mNetIdToAsset.find(netId)->value
|
mNetIdToAsset.find(netId)->value
|
||||||
);
|
);
|
||||||
|
|
||||||
AssertFatal(false, "Asset hash collision detected.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mNetIdToAsset.insert(netId, foundAssetDefinition.mAssetId);
|
mNetIdToAsset.insert(netId, foundAssetDefinition.mAssetId);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue