Cleaned up implementation of #712

Also updates other game classes like the shapebase to utilize the sound asset hooks properly.
This commit is contained in:
JeffR 2022-01-03 20:57:10 -06:00
parent 3812ce2e82
commit 15ef8b4fbe
12 changed files with 312 additions and 187 deletions

View file

@ -1562,33 +1562,50 @@ void GameConnection::packetDropped(PacketNotify *note)
//----------------------------------------------------------------------------
void GameConnection::play2D(SFXProfile* profile)
void GameConnection::play2D(StringTableEntry assetId)
{
postNetEvent(new Sim2DAudioEvent(profile));
if (AssetDatabase.isDeclaredAsset(assetId))
{
AssetPtr<SoundAsset> tempSoundAsset;
tempSoundAsset = assetId;
postNetEvent(new SimSoundAssetEvent(tempSoundAsset));
}
}
void GameConnection::play3D(SFXProfile* profile, const MatrixF *transform)
void GameConnection::play3D(StringTableEntry assetId, const MatrixF *transform)
{
if ( !transform )
play2D(profile);
play2D(assetId);
else if ( !mControlObject )
postNetEvent(new Sim3DAudioEvent(profile,transform));
else
if (AssetDatabase.isDeclaredAsset(assetId))
{
// TODO: Maybe improve this to account for the duration
// of the sound effect and if the control object can get
// into hearing range within time?
// Only post the event if it's within audible range
// of the control object.
Point3F ear,pos;
transform->getColumn(3,&pos);
mControlObject->getTransform().getColumn(3,&ear);
if ((ear - pos).len() < profile->getDescription()->mMaxDistance)
postNetEvent(new Sim3DAudioEvent(profile,transform));
}
AssetPtr<SoundAsset> tempSoundAsset;
tempSoundAsset = assetId;
if (!mControlObject)
postNetEvent(new SimSoundAssetEvent(tempSoundAsset, transform));
else
{
// TODO: Maybe improve this to account for the duration
// of the sound effect and if the control object can get
// into hearing range within time?
// Only post the event if it's within audible range
// of the control object.
tempSoundAsset->getSfxDescription();
Point3F ear, pos;
transform->getColumn(3, &pos);
mControlObject->getTransform().getColumn(3, &ear);
if ((ear - pos).len() < tempSoundAsset->getSfxDescription()->mMaxDistance)
postNetEvent(new SimSoundAssetEvent(tempSoundAsset, transform));
}
}
}
void GameConnection::doneScopingScene()
@ -2010,49 +2027,49 @@ DefineEngineMethod( GameConnection, isControlObjectRotDampedCamera, bool, (),,
return object->isControlObjectRotDampedCamera();
}
DefineEngineMethod( GameConnection, play2D, bool, (SFXProfile* profile),,
DefineEngineMethod( GameConnection, play2D, bool, (StringTableEntry assetId),,
"@brief Used on the server to play a 2D sound that is not attached to any object.\n\n"
"@param profile The SFXProfile that defines the sound to play.\n\n"
"@param assetID The SoundAsset ID that defines the sound to play.\n"
"@tsexample\n"
"function ServerPlay2D(%profile)\n"
"function ServerPlay2D(%assetId)\n"
"{\n"
" // Play the given sound profile on every client.\n"
" // Play the given sound asset on every client.\n"
" // The sounds will be transmitted as an event, not attached to any object.\n"
" for(%idx = 0; %idx < ClientGroup.getCount(); %idx++)\n"
" ClientGroup.getObject(%idx).play2D(%profile);\n"
" ClientGroup.getObject(%idx).play2D(%assetId);\n"
"}\n"
"@endtsexample\n\n")
{
if(!profile)
if(assetId == StringTable->EmptyString())
return false;
object->play2D(profile);
object->play2D(assetId);
return true;
}
DefineEngineMethod( GameConnection, play3D, bool, (SFXProfile* profile, TransformF location),,
DefineEngineMethod( GameConnection, play3D, bool, (StringTableEntry assetId, TransformF location),,
"@brief Used on the server to play a 3D sound that is not attached to any object.\n\n"
"@param profile The SFXProfile that defines the sound to play.\n"
"@param assetID The SoundAsset ID that defines the sound to play.\n"
"@param location The position and orientation of the 3D sound given in the form of \"x y z ax ay az aa\".\n\n"
"@tsexample\n"
"function ServerPlay3D(%profile,%transform)\n"
"function ServerPlay3D(%assetId,%transform)\n"
"{\n"
" // Play the given sound profile at the given position on every client\n"
" // Play the given sound asset at the given position on every client\n"
" // The sound will be transmitted as an event, not attached to any object.\n"
" for(%idx = 0; %idx < ClientGroup.getCount(); %idx++)\n"
" ClientGroup.getObject(%idx).play3D(%profile,%transform);\n"
" ClientGroup.getObject(%idx).play3D(%assetID,%transform);\n"
"}\n"
"@endtsexample\n\n")
{
if(!profile)
if(assetId == StringTable->EmptyString())
return false;
MatrixF mat = location.getMatrix();
object->play3D(profile,&mat);
object->play3D(assetId,&mat);
return true;
}