Merge pull request #1199 from Azaezel/alpha41/sfxSafties

sfx safeties
This commit is contained in:
Brian Roberts 2024-02-04 00:09:56 -06:00 committed by GitHub
commit f940360b96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 36 additions and 31 deletions

View file

@ -550,7 +550,12 @@ DefineEngineMethod(SoundAsset, playSound, S32, (Point3F position), (Point3F::Zer
{ {
MatrixF transform; MatrixF transform;
transform.setPosition(position); transform.setPosition(position);
SFXSource* source = SFX->playOnce(object->getSFXTrack(), &transform, NULL, -1); SFXSource* source;
if (position == Point3F::Zero || !object->is3D())
source = SFX->playOnce(object->getSFXTrack());
else
source = SFX->playOnce(object->getSFXTrack(), &transform, NULL, -1);
if(source) if(source)
return source->getId(); return source->getId();
else else

View file

@ -161,7 +161,7 @@ public:
inline StringTableEntry getSoundPath(const U32 slotId = 0) const { return mSoundPath[slotId]; }; inline StringTableEntry getSoundPath(const U32 slotId = 0) const { return mSoundPath[slotId]; };
SFXProfile* getSfxProfile(const U32 slotId = 0) { return &mSFXProfile[slotId]; } SFXProfile* getSfxProfile(const U32 slotId = 0) { return &mSFXProfile[slotId]; }
SFXPlayList* getSfxPlaylist() { return &mPlaylist; } SFXPlayList* getSfxPlaylist() { return &mPlaylist; }
SFXTrack* getSFXTrack() { return mIsPlaylist ? dynamic_cast<SFXTrack*>(&mPlaylist) : dynamic_cast<SFXTrack*>(&mSFXProfile[0]); } SFXTrack* getSFXTrack() { load(); return mIsPlaylist ? dynamic_cast<SFXTrack*>(&mPlaylist) : dynamic_cast<SFXTrack*>(&mSFXProfile[0]); }
SFXDescription* getSfxDescription() { return &mProfileDesc; } SFXDescription* getSfxDescription() { return &mProfileDesc; }
bool isPlaylist(){ return mIsPlaylist; } bool isPlaylist(){ return mIsPlaylist; }

View file

@ -1566,7 +1566,7 @@ void GameConnection::play2D(StringTableEntry assetId)
{ {
if (AssetDatabase.isDeclaredAsset(assetId)) if (AssetDatabase.isDeclaredAsset(assetId))
{ {
postNetEvent(new SimSoundAssetEvent(assetId)); postNetEvent(new SimSoundAssetEvent(assetId));
} }
} }
@ -1582,7 +1582,7 @@ void GameConnection::play3D(StringTableEntry assetId, const MatrixF *transform)
tempSoundAsset = assetId; tempSoundAsset = assetId;
if (!mControlObject) if (!mControlObject)
postNetEvent(new SimSoundAssetEvent(assetId, *transform)); postNetEvent(new SimSoundAssetEvent(assetId, transform));
else else
{ {
// TODO: Maybe improve this to account for the duration // TODO: Maybe improve this to account for the duration
@ -1596,7 +1596,7 @@ void GameConnection::play3D(StringTableEntry assetId, const MatrixF *transform)
transform->getColumn(3, &pos); transform->getColumn(3, &pos);
mControlObject->getTransform().getColumn(3, &ear); mControlObject->getTransform().getColumn(3, &ear);
if ((ear - pos).len() < tempSoundAsset->getSfxDescription()->mMaxDistance) if ((ear - pos).len() < tempSoundAsset->getSfxDescription()->mMaxDistance)
postNetEvent(new SimSoundAssetEvent(assetId, *transform)); postNetEvent(new SimSoundAssetEvent(assetId, transform));
} }
} }

View file

@ -297,13 +297,16 @@ void SimDataBlockEvent::process(NetConnection *cptr)
static F32 SoundPosAccuracy = 0.5; static F32 SoundPosAccuracy = 0.5;
static S32 SoundRotBits = 8; static S32 SoundRotBits = 8;
SimSoundAssetEvent::SimSoundAssetEvent(StringTableEntry assetId, const MatrixF& mat) SimSoundAssetEvent::SimSoundAssetEvent(StringTableEntry assetId, const MatrixF* mat)
{ {
// cant get here unless the asset is declared. // cant get here unless the asset is declared.
mAsset = assetId; mAsset = assetId;
sentTransform = false;
if (mat) if (mat)
mTransform = mat; {
mTransform = *mat;
sentTransform = true;
}
} }
void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream) void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream)
@ -311,10 +314,9 @@ void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream)
NetStringHandle assetIdStr = mAsset->getAssetId(); NetStringHandle assetIdStr = mAsset->getAssetId();
con->packNetStringHandleU(stream, assetIdStr); con->packNetStringHandleU(stream, assetIdStr);
// only stream if this is a 3d sound asset. SFXDescription* ad = mAsset->getSfxDescription();
if (mAsset->is3D()) if (stream->writeFlag(sentTransform))
{ {
SFXDescription* ad = mAsset->getSfxDescription();
if (stream->writeFlag(ad->mConeInsideAngle || ad->mConeOutsideAngle)) if (stream->writeFlag(ad->mConeInsideAngle || ad->mConeOutsideAngle))
{ {
QuatF q(mTransform); QuatF q(mTransform);
@ -322,10 +324,10 @@ void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream)
// LH - we can get a valid quat that's very slightly over 1 in and so // LH - we can get a valid quat that's very slightly over 1 in and so
// this fails (barely) check against zero. So use some error- // this fails (barely) check against zero. So use some error-
AssertFatal((1.0 - ((q.x * q.x) + (q.y * q.y) + (q.z * q.z))) >= (0.0 - 0.001), AssertFatal((1.0 - ((q.x * q.x) + (q.y * q.y) + (q.z * q.z))) >= (0.0 - 0.001),
"QuatF::normalize() is broken in Sim3DAudioEvent"); "QuatF::normalize() is broken in Sim3DAudioEvent");
stream->writeSignedFloat(q.x, SoundRotBits); stream->writeSignedFloat(q.x, SoundRotBits);
stream->writeSignedFloat(q.y, SoundRotBits); stream->writeSignedFloat(q.y, SoundRotBits);
stream->writeSignedFloat(q.z, SoundRotBits); stream->writeSignedFloat(q.z, SoundRotBits);
stream->writeFlag(q.w < 0.0); stream->writeFlag(q.w < 0.0);
@ -335,7 +337,6 @@ void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream)
mTransform.getColumn(3, &pos); mTransform.getColumn(3, &pos);
stream->writeCompressedPoint(pos, SoundPosAccuracy); stream->writeCompressedPoint(pos, SoundPosAccuracy);
} }
} }
void SimSoundAssetEvent::write(NetConnection* con, BitStream* stream) void SimSoundAssetEvent::write(NetConnection* con, BitStream* stream)
@ -356,8 +357,8 @@ void SimSoundAssetEvent::unpack(NetConnection* con, BitStream* stream)
mAsset = temp; mAsset = temp;
} }
if (mAsset->is3D()) sentTransform = stream->readFlag();
{ if (sentTransform) {
if (stream->readFlag()) { if (stream->readFlag()) {
QuatF q; QuatF q;
q.x = stream->readSignedFloat(SoundRotBits); q.x = stream->readSignedFloat(SoundRotBits);
@ -381,16 +382,15 @@ void SimSoundAssetEvent::unpack(NetConnection* con, BitStream* stream)
stream->readCompressedPoint(&pos, SoundPosAccuracy); stream->readCompressedPoint(&pos, SoundPosAccuracy);
mTransform.setColumn(3, pos); mTransform.setColumn(3, pos);
} }
else
{
mTransform = SFX->getListener(0).getTransform();
}
} }
void SimSoundAssetEvent::process(NetConnection* con) void SimSoundAssetEvent::process(NetConnection* con)
{ {
SFX->playOnce(mAsset->getSFXTrack(), &mTransform);
if (mAsset->is3D())
SFX->playOnce(mAsset->getSFXTrack(), &mTransform);
else
SFX->playOnce(mAsset->getSFXTrack());
} }
Sim2DAudioEvent::Sim2DAudioEvent(SFXProfile *profile) Sim2DAudioEvent::Sim2DAudioEvent(SFXProfile *profile)

View file

@ -110,11 +110,11 @@ class SimSoundAssetEvent : public NetEvent
private: private:
AssetPtr<SoundAsset> mAsset; AssetPtr<SoundAsset> mAsset;
MatrixF mTransform; MatrixF mTransform;
bool sentTransform;
public: public:
typedef NetEvent Parent; typedef NetEvent Parent;
SimSoundAssetEvent(StringTableEntry assetId = StringTable->EmptyString(), const MatrixF& mat = MatrixF::Identity); SimSoundAssetEvent(StringTableEntry assetId = StringTable->EmptyString(), const MatrixF* mat = NULL);
void pack(NetConnection*, BitStream* bstream); void pack(NetConnection*, BitStream* bstream);
void write(NetConnection*, BitStream* bstream); void write(NetConnection*, BitStream* bstream);
void unpack(NetConnection*, BitStream* bstream); void unpack(NetConnection*, BitStream* bstream);

View file

@ -21,21 +21,21 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//
function ServerPlay2D(%profile) function ServerPlay2D(%assetID)
{ {
// Play the given sound profile on every client. // Play the given sound profile on every client.
// The sounds will be transmitted as an event, not attached to any object. // The sounds will be transmitted as an event, not attached to any object.
for(%idx = 0; %idx < ClientGroup.getCount(); %idx++) for(%idx = 0; %idx < ClientGroup.getCount(); %idx++)
ClientGroup.getObject(%idx).play2D(%profile); ClientGroup.getObject(%idx).play2D(%assetID);
} }
function ServerPlay3D(%profile,%transform) function ServerPlay3D(%assetID,%transform)
{ {
// Play the given sound profile at the given position on every client // Play the given sound assetID at the given position on every client
// The sound will be transmitted as an event, not attached to any object. // The sound will be transmitted as an event, not attached to any object.
for(%idx = 0; %idx < ClientGroup.getCount(); %idx++) for(%idx = 0; %idx < ClientGroup.getCount(); %idx++)
ClientGroup.getObject(%idx).play3D(%profile,%transform); ClientGroup.getObject(%idx).play3D(%assetID,%transform);
} }
function ServerPlaySound(%profile,%pos) function ServerPlaySound(%profile,%pos)