diff --git a/Engine/source/T3D/assets/SoundAsset.cpp b/Engine/source/T3D/assets/SoundAsset.cpp index 06a30b7e4..a3b1aed81 100644 --- a/Engine/source/T3D/assets/SoundAsset.cpp +++ b/Engine/source/T3D/assets/SoundAsset.cpp @@ -228,6 +228,9 @@ bool SoundAsset::loadSound() mSFXProfile.setDescription(&mProfileDesc); mSFXProfile.setSoundFileName(mSoundPath); mSFXProfile.setPreload(mPreload); + + //give it a nudge to preload if required + mSFXProfile.getBuffer(); } } @@ -341,7 +344,10 @@ DefineEngineMethod(SoundAsset, playSound, S32, (Point3F position), (Point3F::Zer MatrixF transform; transform.setPosition(position); SFXSource* source = SFX->playOnce(object->getSfxProfile(), &transform, NULL, -1); - return source->getId(); + if(source) + return source->getId(); + else + return 0; } else return 0; diff --git a/Engine/source/T3D/gameBase/gameConnection.cpp b/Engine/source/T3D/gameBase/gameConnection.cpp index 0331e3764..b88bde05e 100644 --- a/Engine/source/T3D/gameBase/gameConnection.cpp +++ b/Engine/source/T3D/gameBase/gameConnection.cpp @@ -1566,12 +1566,7 @@ void GameConnection::play2D(StringTableEntry assetId) { if (AssetDatabase.isDeclaredAsset(assetId)) { - - AssetPtr tempSoundAsset; - tempSoundAsset = assetId; - - postNetEvent(new SimSoundAssetEvent(tempSoundAsset)); - + postNetEvent(new SimSoundAssetEvent(assetId)); } } @@ -1587,7 +1582,7 @@ void GameConnection::play3D(StringTableEntry assetId, const MatrixF *transform) tempSoundAsset = assetId; if (!mControlObject) - postNetEvent(new SimSoundAssetEvent(tempSoundAsset, transform)); + postNetEvent(new SimSoundAssetEvent(assetId, *transform)); else { // TODO: Maybe improve this to account for the duration @@ -1601,7 +1596,7 @@ void GameConnection::play3D(StringTableEntry assetId, const MatrixF *transform) transform->getColumn(3, &pos); mControlObject->getTransform().getColumn(3, &ear); if ((ear - pos).len() < tempSoundAsset->getSfxDescription()->mMaxDistance) - postNetEvent(new SimSoundAssetEvent(tempSoundAsset, transform)); + postNetEvent(new SimSoundAssetEvent(assetId, *transform)); } } diff --git a/Engine/source/T3D/gameBase/gameConnectionEvents.cpp b/Engine/source/T3D/gameBase/gameConnectionEvents.cpp index d2c3badce..184d504bf 100644 --- a/Engine/source/T3D/gameBase/gameConnectionEvents.cpp +++ b/Engine/source/T3D/gameBase/gameConnectionEvents.cpp @@ -297,13 +297,13 @@ void SimDataBlockEvent::process(NetConnection *cptr) static F32 SoundPosAccuracy = 0.5; static S32 SoundRotBits = 8; -SimSoundAssetEvent::SimSoundAssetEvent(AssetPtr asset, const MatrixF* mat) +SimSoundAssetEvent::SimSoundAssetEvent(StringTableEntry assetId, const MatrixF& mat) { // cant get here unless the asset is declared. - mAsset = asset; + mAsset = assetId; if (mat) - mTransform = *mat; + mTransform = mat; } void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream) diff --git a/Engine/source/T3D/gameBase/gameConnectionEvents.h b/Engine/source/T3D/gameBase/gameConnectionEvents.h index ede198645..755e02957 100644 --- a/Engine/source/T3D/gameBase/gameConnectionEvents.h +++ b/Engine/source/T3D/gameBase/gameConnectionEvents.h @@ -114,7 +114,7 @@ private: public: typedef NetEvent Parent; - SimSoundAssetEvent(AssetPtr asset = NULL, const MatrixF* mat = NULL); + SimSoundAssetEvent(StringTableEntry assetId = StringTable->EmptyString(), const MatrixF& mat = MatrixF::Identity); void pack(NetConnection*, BitStream* bstream); void write(NetConnection*, BitStream* bstream); void unpack(NetConnection*, BitStream* bstream); diff --git a/Engine/source/T3D/shapeBase.h b/Engine/source/T3D/shapeBase.h index 6ef0fd985..035e6c55c 100644 --- a/Engine/source/T3D/shapeBase.h +++ b/Engine/source/T3D/shapeBase.h @@ -504,6 +504,8 @@ struct ShapeBaseImageData: public GameBaseData { void inspectPostApply(); + void handleStateSoundTrack(const U32& stateId); + /// @} /// @name Callbacks diff --git a/Engine/source/T3D/shapeImage.cpp b/Engine/source/T3D/shapeImage.cpp index 88d5f837c..38a7fda2a 100644 --- a/Engine/source/T3D/shapeImage.cpp +++ b/Engine/source/T3D/shapeImage.cpp @@ -372,20 +372,8 @@ bool ShapeBaseImageData::onAdd() s.shapeSequenceScale = stateScaleShapeSequence[i]; //_setstateSound(getstateSound(i),i); - s.sound = getstateSoundAsset(i); - if (s.sound == NULL && mstateSoundName[i] != StringTable->EmptyString()) - { - //ok, so we've got some sort of special-case here like a fallback or SFXPlaylist. So do the hook-up now - SFXTrack* sndTrack; - if (!Sim::findObject(mstateSoundName[i], sndTrack)) - { - Con::errorf("ShapeBaseImageData::onAdd() - attempted to find sound %s but failed!", mstateSoundName[i]); - } - else - { - s.soundTrack = sndTrack; - } - } + handleStateSoundTrack(i); + s.script = stateScript[i]; s.emitter = stateEmitter[i]; s.emitterTime = stateEmitterTime[i]; @@ -591,6 +579,30 @@ bool ShapeBaseImageData::preload(bool server, String &errorStr) return true; } +void ShapeBaseImageData::handleStateSoundTrack(const U32& stateId) +{ + if (stateId > MaxStates) + return; + + StateData& s = state[stateId]; + + s.sound = getstateSoundAsset(stateId); + + if (s.sound == NULL && mstateSoundName[stateId] != StringTable->EmptyString()) + { + //ok, so we've got some sort of special-case here like a fallback or SFXPlaylist. So do the hook-up now + SFXTrack* sndTrack; + if (!Sim::findObject(mstateSoundName[stateId], sndTrack)) + { + Con::errorf("ShapeBaseImageData::onAdd() - attempted to find sound %s but failed!", mstateSoundName[stateId]); + } + else + { + s.soundTrack = sndTrack; + } + } +} + S32 ShapeBaseImageData::lookupState(const char* name) { if (!name || !name[0]) @@ -1366,6 +1378,7 @@ void ShapeBaseImageData::unpackData(BitStream* stream) s.emitter = 0; UNPACKDATA_ASSET_ARRAY(stateSound, i); + handleStateSoundTrack(i); } }