hybridize suggested approaches with older code style, passing along either a matrix or a null.

for network transmission purposes, send which along as a bool
This commit is contained in:
AzaezelX 2024-02-03 22:35:41 -06:00
parent b12cd00b74
commit 846cec8dff
3 changed files with 52 additions and 70 deletions

View file

@ -1566,11 +1566,7 @@ void GameConnection::play2D(StringTableEntry assetId)
{ {
if (AssetDatabase.isDeclaredAsset(assetId)) if (AssetDatabase.isDeclaredAsset(assetId))
{ {
AssetPtr<SoundAsset> tempSoundAsset = assetId; postNetEvent(new SimSoundAssetEvent(assetId));
if (tempSoundAsset && tempSoundAsset->is3D())
{
postNetEvent(new SimSoundAssetEvent(assetId, SFX->getListener(0).getTransform()));
}
} }
} }
@ -1586,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
@ -1600,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,15 +297,15 @@ 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;
mIs3D = false; sentTransform = false;
if (mat) if (mat)
{ {
mTransform = mat; mTransform = *mat;
mIs3D = true; sentTransform = true;
} }
} }
@ -314,13 +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.
stream->writeFlag(mIs3D);
if (mIs3D)
{
if (mAsset->is3D())
{
SFXDescription* ad = mAsset->getSfxDescription(); SFXDescription* ad = mAsset->getSfxDescription();
if (stream->writeFlag(sentTransform))
{
if (stream->writeFlag(ad->mConeInsideAngle || ad->mConeOutsideAngle)) if (stream->writeFlag(ad->mConeInsideAngle || ad->mConeOutsideAngle))
{ {
QuatF q(mTransform); QuatF q(mTransform);
@ -343,8 +339,6 @@ void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream)
} }
} }
}
void SimSoundAssetEvent::write(NetConnection* con, BitStream* stream) void SimSoundAssetEvent::write(NetConnection* con, BitStream* stream)
{ {
// Just do the normal pack... // Just do the normal pack...
@ -363,11 +357,8 @@ void SimSoundAssetEvent::unpack(NetConnection* con, BitStream* stream)
mAsset = temp; mAsset = temp;
} }
if (stream->readFlag()) sentTransform = stream->readFlag();
{ if (sentTransform) {
mIs3D = true;
if (mAsset->is3D())
{
if (stream->readFlag()) { if (stream->readFlag()) {
QuatF q; QuatF q;
q.x = stream->readSignedFloat(SoundRotBits); q.x = stream->readSignedFloat(SoundRotBits);
@ -391,21 +382,16 @@ 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)
{ {
if (mIs3D)
{
if (mAsset->is3D())
SFX->playOnce(mAsset->getSFXTrack(), &mTransform); 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 mIs3D; 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);