mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
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:
parent
b12cd00b74
commit
846cec8dff
|
|
@ -1566,11 +1566,7 @@ void GameConnection::play2D(StringTableEntry assetId)
|
|||
{
|
||||
if (AssetDatabase.isDeclaredAsset(assetId))
|
||||
{
|
||||
AssetPtr<SoundAsset> tempSoundAsset = assetId;
|
||||
if (tempSoundAsset && tempSoundAsset->is3D())
|
||||
{
|
||||
postNetEvent(new SimSoundAssetEvent(assetId, SFX->getListener(0).getTransform()));
|
||||
}
|
||||
postNetEvent(new SimSoundAssetEvent(assetId));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1586,7 +1582,7 @@ void GameConnection::play3D(StringTableEntry assetId, const MatrixF *transform)
|
|||
tempSoundAsset = assetId;
|
||||
|
||||
if (!mControlObject)
|
||||
postNetEvent(new SimSoundAssetEvent(assetId, *transform));
|
||||
postNetEvent(new SimSoundAssetEvent(assetId, transform));
|
||||
else
|
||||
{
|
||||
// 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);
|
||||
mControlObject->getTransform().getColumn(3, &ear);
|
||||
if ((ear - pos).len() < tempSoundAsset->getSfxDescription()->mMaxDistance)
|
||||
postNetEvent(new SimSoundAssetEvent(assetId, *transform));
|
||||
postNetEvent(new SimSoundAssetEvent(assetId, transform));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,15 +297,15 @@ void SimDataBlockEvent::process(NetConnection *cptr)
|
|||
static F32 SoundPosAccuracy = 0.5;
|
||||
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.
|
||||
mAsset = assetId;
|
||||
mIs3D = false;
|
||||
sentTransform = false;
|
||||
if (mat)
|
||||
{
|
||||
mTransform = mat;
|
||||
mIs3D = true;
|
||||
mTransform = *mat;
|
||||
sentTransform = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -314,35 +314,29 @@ void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream)
|
|||
NetStringHandle assetIdStr = mAsset->getAssetId();
|
||||
con->packNetStringHandleU(stream, assetIdStr);
|
||||
|
||||
// only stream if this is a 3d sound asset.
|
||||
stream->writeFlag(mIs3D);
|
||||
if (mIs3D)
|
||||
SFXDescription* ad = mAsset->getSfxDescription();
|
||||
if (stream->writeFlag(sentTransform))
|
||||
{
|
||||
if (mAsset->is3D())
|
||||
if (stream->writeFlag(ad->mConeInsideAngle || ad->mConeOutsideAngle))
|
||||
{
|
||||
SFXDescription* ad = mAsset->getSfxDescription();
|
||||
if (stream->writeFlag(ad->mConeInsideAngle || ad->mConeOutsideAngle))
|
||||
{
|
||||
QuatF q(mTransform);
|
||||
q.normalize();
|
||||
QuatF q(mTransform);
|
||||
q.normalize();
|
||||
|
||||
// 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-
|
||||
// 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-
|
||||
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");
|
||||
|
||||
stream->writeSignedFloat(q.x, SoundRotBits);
|
||||
stream->writeSignedFloat(q.y, SoundRotBits);
|
||||
stream->writeSignedFloat(q.z, SoundRotBits);
|
||||
stream->writeFlag(q.w < 0.0);
|
||||
}
|
||||
|
||||
Point3F pos;
|
||||
mTransform.getColumn(3, &pos);
|
||||
stream->writeCompressedPoint(pos, SoundPosAccuracy);
|
||||
stream->writeSignedFloat(q.x, SoundRotBits);
|
||||
stream->writeSignedFloat(q.y, SoundRotBits);
|
||||
stream->writeSignedFloat(q.z, SoundRotBits);
|
||||
stream->writeFlag(q.w < 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
Point3F pos;
|
||||
mTransform.getColumn(3, &pos);
|
||||
stream->writeCompressedPoint(pos, SoundPosAccuracy);
|
||||
}
|
||||
}
|
||||
|
||||
void SimSoundAssetEvent::write(NetConnection* con, BitStream* stream)
|
||||
|
|
@ -363,48 +357,40 @@ void SimSoundAssetEvent::unpack(NetConnection* con, BitStream* stream)
|
|||
mAsset = temp;
|
||||
}
|
||||
|
||||
if (stream->readFlag())
|
||||
{
|
||||
mIs3D = true;
|
||||
if (mAsset->is3D())
|
||||
{
|
||||
if (stream->readFlag()) {
|
||||
QuatF q;
|
||||
q.x = stream->readSignedFloat(SoundRotBits);
|
||||
q.y = stream->readSignedFloat(SoundRotBits);
|
||||
q.z = stream->readSignedFloat(SoundRotBits);
|
||||
F32 value = ((q.x * q.x) + (q.y * q.y) + (q.z * q.z));
|
||||
// #ifdef __linux
|
||||
// Hmm, this should never happen, but it does...
|
||||
if (value > 1.f)
|
||||
value = 1.f;
|
||||
// #endif
|
||||
q.w = mSqrt(1.f - value);
|
||||
if (stream->readFlag())
|
||||
q.w = -q.w;
|
||||
q.setMatrix(&mTransform);
|
||||
}
|
||||
else
|
||||
mTransform.identity();
|
||||
|
||||
Point3F pos;
|
||||
stream->readCompressedPoint(&pos, SoundPosAccuracy);
|
||||
mTransform.setColumn(3, pos);
|
||||
sentTransform = stream->readFlag();
|
||||
if (sentTransform) {
|
||||
if (stream->readFlag()) {
|
||||
QuatF q;
|
||||
q.x = stream->readSignedFloat(SoundRotBits);
|
||||
q.y = stream->readSignedFloat(SoundRotBits);
|
||||
q.z = stream->readSignedFloat(SoundRotBits);
|
||||
F32 value = ((q.x * q.x) + (q.y * q.y) + (q.z * q.z));
|
||||
// #ifdef __linux
|
||||
// Hmm, this should never happen, but it does...
|
||||
if (value > 1.f)
|
||||
value = 1.f;
|
||||
// #endif
|
||||
q.w = mSqrt(1.f - value);
|
||||
if (stream->readFlag())
|
||||
q.w = -q.w;
|
||||
q.setMatrix(&mTransform);
|
||||
}
|
||||
else
|
||||
mTransform.identity();
|
||||
|
||||
Point3F pos;
|
||||
stream->readCompressedPoint(&pos, SoundPosAccuracy);
|
||||
mTransform.setColumn(3, pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
mTransform = SFX->getListener(0).getTransform();
|
||||
}
|
||||
}
|
||||
|
||||
void SimSoundAssetEvent::process(NetConnection* con)
|
||||
{
|
||||
|
||||
if (mIs3D)
|
||||
{
|
||||
if (mAsset->is3D())
|
||||
SFX->playOnce(mAsset->getSFXTrack(), &mTransform);
|
||||
}
|
||||
else
|
||||
SFX->playOnce(mAsset->getSFXTrack());
|
||||
|
||||
SFX->playOnce(mAsset->getSFXTrack(), &mTransform);
|
||||
}
|
||||
|
||||
Sim2DAudioEvent::Sim2DAudioEvent(SFXProfile *profile)
|
||||
|
|
|
|||
|
|
@ -110,11 +110,11 @@ class SimSoundAssetEvent : public NetEvent
|
|||
private:
|
||||
AssetPtr<SoundAsset> mAsset;
|
||||
MatrixF mTransform;
|
||||
bool mIs3D;
|
||||
bool sentTransform;
|
||||
public:
|
||||
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 write(NetConnection*, BitStream* bstream);
|
||||
void unpack(NetConnection*, BitStream* bstream);
|
||||
|
|
|
|||
Loading…
Reference in a new issue