mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
Merge pull request #805 from Areloch/SoundFixRandD
Sound Networking Fixes
This commit is contained in:
commit
dc6eba0519
8 changed files with 143 additions and 43 deletions
|
|
@ -228,6 +228,9 @@ bool SoundAsset::loadSound()
|
||||||
mSFXProfile.setDescription(&mProfileDesc);
|
mSFXProfile.setDescription(&mProfileDesc);
|
||||||
mSFXProfile.setSoundFileName(mSoundPath);
|
mSFXProfile.setSoundFileName(mSoundPath);
|
||||||
mSFXProfile.setPreload(mPreload);
|
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;
|
MatrixF transform;
|
||||||
transform.setPosition(position);
|
transform.setPosition(position);
|
||||||
SFXSource* source = SFX->playOnce(object->getSfxProfile(), &transform, NULL, -1);
|
SFXSource* source = SFX->playOnce(object->getSfxProfile(), &transform, NULL, -1);
|
||||||
return source->getId();
|
if(source)
|
||||||
|
return source->getId();
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,7 @@ public:
|
||||||
AssetPtr<SoundAsset> m##name##Asset = NULL;\
|
AssetPtr<SoundAsset> m##name##Asset = NULL;\
|
||||||
SFXProfile* m##name##Profile = NULL;\
|
SFXProfile* m##name##Profile = NULL;\
|
||||||
SFXDescription* m##name##Desc = NULL;\
|
SFXDescription* m##name##Desc = NULL;\
|
||||||
|
SimObjectId m##name##SFXId = NULL;\
|
||||||
public: \
|
public: \
|
||||||
const StringTableEntry get##name##File() const { return m##name##Name; }\
|
const StringTableEntry get##name##File() const { return m##name##Name; }\
|
||||||
void set##name##File(const FileName &_in) { m##name##Name = StringTable->insert(_in.c_str());}\
|
void set##name##File(const FileName &_in) { m##name##Name = StringTable->insert(_in.c_str());}\
|
||||||
|
|
@ -253,7 +254,7 @@ public: \
|
||||||
Con::errorf("%s(%s)::_set%s() - sound asset failure\"%s\" due to [%s]", macroText(className), getName(), macroText(name), _in, SoundAsset::getAssetErrstrn(m##name##Asset->getStatus()).c_str());\
|
Con::errorf("%s(%s)::_set%s() - sound asset failure\"%s\" due to [%s]", macroText(className), getName(), macroText(name), _in, SoundAsset::getAssetErrstrn(m##name##Asset->getStatus()).c_str());\
|
||||||
return false; \
|
return false; \
|
||||||
}\
|
}\
|
||||||
else if (!m##name)\
|
else if (!m##name && (m##name##Name != StringTable->EmptyString() && !Sim::findObject(m##name##Name)))\
|
||||||
{\
|
{\
|
||||||
Con::errorf("%s(%s)::_set%s() - Couldn't load sound \"%s\"", macroText(className), getName(), macroText(name), _in);\
|
Con::errorf("%s(%s)::_set%s() - Couldn't load sound \"%s\"", macroText(className), getName(), macroText(name), _in);\
|
||||||
return false;\
|
return false;\
|
||||||
|
|
@ -310,31 +311,57 @@ public: \
|
||||||
#define PACKDATA_SOUNDASSET(name)\
|
#define PACKDATA_SOUNDASSET(name)\
|
||||||
if (stream->writeFlag(m##name##Asset.notNull()))\
|
if (stream->writeFlag(m##name##Asset.notNull()))\
|
||||||
{\
|
{\
|
||||||
if (m##name##Profile)\
|
stream->writeString(m##name##Asset.getAssetId());\
|
||||||
m##name##Profile->packData(stream);\
|
|
||||||
sfxWrite(stream, m##name##Desc);\
|
|
||||||
}\
|
}\
|
||||||
else\
|
else\
|
||||||
stream->writeString(m##name##Name);
|
{\
|
||||||
|
if(stream->writeFlag(Sim::findObject(m##name##Name)))\
|
||||||
|
{\
|
||||||
|
SFXTrack* sndTrack;\
|
||||||
|
Sim::findObject(m##name##Name, sndTrack);\
|
||||||
|
stream->writeRangedU32(SimObjectId(sndTrack->getId()), DataBlockObjectIdFirst, DataBlockObjectIdLast);\
|
||||||
|
}\
|
||||||
|
else\
|
||||||
|
{\
|
||||||
|
stream->writeString(m##name##Name);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//network recieve - datablock
|
//network recieve - datablock
|
||||||
#define UNPACKDATA_SOUNDASSET(name)\
|
#define UNPACKDATA_SOUNDASSET(name)\
|
||||||
if (stream->readFlag())\
|
if (stream->readFlag())\
|
||||||
{\
|
{\
|
||||||
if (m##name##Profile)\
|
m##name##AssetId = stream->readSTString();\
|
||||||
m##name##Profile->unpackData(stream);\
|
_set##name(m##name##AssetId);\
|
||||||
sfxRead(stream, &m##name##Desc);\
|
|
||||||
}\
|
}\
|
||||||
else\
|
else\
|
||||||
{\
|
{\
|
||||||
m##name##Name = stream->readSTString();\
|
if(stream->readFlag())\
|
||||||
_set##name(m##name##Name);\
|
{\
|
||||||
|
m##name##SFXId = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast );\
|
||||||
|
}\
|
||||||
|
else\
|
||||||
|
{\
|
||||||
|
m##name##Name = stream->readSTString(); \
|
||||||
|
_set##name(m##name##Name); \
|
||||||
|
}\
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region Arrayed Asset Macros
|
#pragma region Arrayed Asset Macros
|
||||||
|
|
||||||
|
#define INIT_SOUNDASSET_ARRAY(name, index) \
|
||||||
|
{\
|
||||||
|
m##name##Name[index] = StringTable->EmptyString(); \
|
||||||
|
m##name##AssetId[index] = StringTable->EmptyString(); \
|
||||||
|
m##name##Asset[index] = NULL;\
|
||||||
|
m##name[index] = NULL;\
|
||||||
|
m##name##Profile[index] = NULL;\
|
||||||
|
m##name##SFXId[index] = 0;\
|
||||||
|
}
|
||||||
|
|
||||||
#define DECLARE_SOUNDASSET_ARRAY(className,name,max) public: \
|
#define DECLARE_SOUNDASSET_ARRAY(className,name,max) public: \
|
||||||
static const U32 sm##name##Count = max;\
|
static const U32 sm##name##Count = max;\
|
||||||
Resource<SFXResource> m##name[max];\
|
Resource<SFXResource> m##name[max];\
|
||||||
|
|
@ -342,6 +369,7 @@ public: \
|
||||||
StringTableEntry m##name##AssetId[max];\
|
StringTableEntry m##name##AssetId[max];\
|
||||||
AssetPtr<SoundAsset> m##name##Asset[max];\
|
AssetPtr<SoundAsset> m##name##Asset[max];\
|
||||||
SFXProfile* m##name##Profile[max];\
|
SFXProfile* m##name##Profile[max];\
|
||||||
|
SimObjectId m##name##SFXId[max];\
|
||||||
public: \
|
public: \
|
||||||
const StringTableEntry get##name##File(const U32& index) const { return m##name##Name[index]; }\
|
const StringTableEntry get##name##File(const U32& index) const { return m##name##Name[index]; }\
|
||||||
void set##name##File(const FileName &_in, const U32& index) { m##name##Name[index] = StringTable->insert(_in.c_str());}\
|
void set##name##File(const FileName &_in, const U32& index) { m##name##Name[index] = StringTable->insert(_in.c_str());}\
|
||||||
|
|
@ -417,7 +445,7 @@ public: \
|
||||||
Con::errorf("%s(%s)::_set%s(%i) - sound asset failure\"%s\" due to [%s]", macroText(className), getName(), macroText(name),index, _in, SoundAsset::getAssetErrstrn(m##name##Asset[index]->getStatus()).c_str());\
|
Con::errorf("%s(%s)::_set%s(%i) - sound asset failure\"%s\" due to [%s]", macroText(className), getName(), macroText(name),index, _in, SoundAsset::getAssetErrstrn(m##name##Asset[index]->getStatus()).c_str());\
|
||||||
return false; \
|
return false; \
|
||||||
}\
|
}\
|
||||||
else if (!m##name[index])\
|
else if (!m##name[index] && (m##name##Name[index] != StringTable->EmptyString() && !Sim::findObject(m##name##Name[index])))\
|
||||||
{\
|
{\
|
||||||
Con::errorf("%s(%s)::_set%s(%i) - Couldn't load sound \"%s\"", macroText(className), getName(), macroText(name),index, _in);\
|
Con::errorf("%s(%s)::_set%s(%i) - Couldn't load sound \"%s\"", macroText(className), getName(), macroText(name),index, _in);\
|
||||||
return false;\
|
return false;\
|
||||||
|
|
@ -489,6 +517,46 @@ if (m##name##AssetId[index] != StringTable->EmptyString())\
|
||||||
addField(assetEnumNameConcat(enumString, Asset), TypeSoundAssetId, Offset(m##name##AssetId[0], consoleClass) + sizeof(m##name##AssetId[0])*i, assetText(name, asset reference.));\
|
addField(assetEnumNameConcat(enumString, Asset), TypeSoundAssetId, Offset(m##name##AssetId[0], consoleClass) + sizeof(m##name##AssetId[0])*i, assetText(name, asset reference.));\
|
||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PACKDATA_SOUNDASSET_ARRAY(name, index)\
|
||||||
|
if (stream->writeFlag(m##name##Asset[index].notNull()))\
|
||||||
|
{\
|
||||||
|
stream->writeString(m##name##Asset[index].getAssetId());\
|
||||||
|
}\
|
||||||
|
else\
|
||||||
|
{\
|
||||||
|
if(stream->writeFlag(Sim::findObject(m##name##Name[index])))\
|
||||||
|
{\
|
||||||
|
SFXTrack* sndTrack;\
|
||||||
|
Sim::findObject(m##name##Name[index], sndTrack);\
|
||||||
|
stream->writeRangedU32(SimObjectId(sndTrack->getId()), DataBlockObjectIdFirst, DataBlockObjectIdLast);\
|
||||||
|
}\
|
||||||
|
else\
|
||||||
|
{\
|
||||||
|
stream->writeString(m##name##Name[index]);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//network recieve - datablock
|
||||||
|
#define UNPACKDATA_SOUNDASSET_ARRAY(name, index)\
|
||||||
|
if (stream->readFlag())\
|
||||||
|
{\
|
||||||
|
m##name##AssetId[index] = stream->readSTString();\
|
||||||
|
_set##name(m##name##AssetId[index], index);\
|
||||||
|
}\
|
||||||
|
else\
|
||||||
|
{\
|
||||||
|
if(stream->readFlag())\
|
||||||
|
{\
|
||||||
|
m##name##SFXId[index] = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast );\
|
||||||
|
}\
|
||||||
|
else\
|
||||||
|
{\
|
||||||
|
m##name##Name[index] = stream->readSTString(); \
|
||||||
|
_set##name(m##name##Name[index], index); \
|
||||||
|
}\
|
||||||
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#endif // _ASSET_BASE_H_
|
#endif // _ASSET_BASE_H_
|
||||||
|
|
|
||||||
|
|
@ -652,7 +652,8 @@ void ExplosionData::packData(BitStream* stream)
|
||||||
|
|
||||||
PACKDATA_ASSET(ExplosionShape);
|
PACKDATA_ASSET(ExplosionShape);
|
||||||
|
|
||||||
PACKDATA_SOUNDASSET(Sound);
|
//PACKDATA_SOUNDASSET(Sound);
|
||||||
|
PACKDATA_ASSET(Sound);
|
||||||
|
|
||||||
if (stream->writeFlag(particleEmitter))
|
if (stream->writeFlag(particleEmitter))
|
||||||
stream->writeRangedU32(particleEmitter->getId(),DataBlockObjectIdFirst,DataBlockObjectIdLast);
|
stream->writeRangedU32(particleEmitter->getId(),DataBlockObjectIdFirst,DataBlockObjectIdLast);
|
||||||
|
|
@ -756,7 +757,7 @@ void ExplosionData::unpackData(BitStream* stream)
|
||||||
|
|
||||||
UNPACKDATA_ASSET(ExplosionShape);
|
UNPACKDATA_ASSET(ExplosionShape);
|
||||||
|
|
||||||
UNPACKDATA_SOUNDASSET(Sound);
|
UNPACKDATA_ASSET(Sound);
|
||||||
|
|
||||||
if (stream->readFlag())
|
if (stream->readFlag())
|
||||||
particleEmitterId = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast);
|
particleEmitterId = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast);
|
||||||
|
|
|
||||||
|
|
@ -1566,12 +1566,7 @@ void GameConnection::play2D(StringTableEntry assetId)
|
||||||
{
|
{
|
||||||
if (AssetDatabase.isDeclaredAsset(assetId))
|
if (AssetDatabase.isDeclaredAsset(assetId))
|
||||||
{
|
{
|
||||||
|
postNetEvent(new SimSoundAssetEvent(assetId));
|
||||||
AssetPtr<SoundAsset> tempSoundAsset;
|
|
||||||
tempSoundAsset = assetId;
|
|
||||||
|
|
||||||
postNetEvent(new SimSoundAssetEvent(tempSoundAsset));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1587,7 +1582,7 @@ void GameConnection::play3D(StringTableEntry assetId, const MatrixF *transform)
|
||||||
tempSoundAsset = assetId;
|
tempSoundAsset = assetId;
|
||||||
|
|
||||||
if (!mControlObject)
|
if (!mControlObject)
|
||||||
postNetEvent(new SimSoundAssetEvent(tempSoundAsset, 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
|
||||||
|
|
@ -1601,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(tempSoundAsset, transform));
|
postNetEvent(new SimSoundAssetEvent(assetId, *transform));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -297,13 +297,13 @@ 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(AssetPtr<SoundAsset> asset, 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 = asset;
|
mAsset = assetId;
|
||||||
|
|
||||||
if (mat)
|
if (mat)
|
||||||
mTransform = *mat;
|
mTransform = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream)
|
void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream)
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ private:
|
||||||
public:
|
public:
|
||||||
typedef NetEvent Parent;
|
typedef NetEvent Parent;
|
||||||
|
|
||||||
SimSoundAssetEvent(AssetPtr<SoundAsset> asset = NULL, const MatrixF* mat = NULL);
|
SimSoundAssetEvent(StringTableEntry assetId = StringTable->EmptyString(), const MatrixF& mat = MatrixF::Identity);
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -504,6 +504,8 @@ struct ShapeBaseImageData: public GameBaseData {
|
||||||
|
|
||||||
void inspectPostApply();
|
void inspectPostApply();
|
||||||
|
|
||||||
|
void handleStateSoundTrack(const U32& stateId);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
/// @name Callbacks
|
/// @name Callbacks
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ ShapeBaseImageData::ShapeBaseImageData()
|
||||||
stateShapeSequence[i] = 0;
|
stateShapeSequence[i] = 0;
|
||||||
stateScaleShapeSequence[i] = false;
|
stateScaleShapeSequence[i] = false;
|
||||||
|
|
||||||
INIT_ASSET_ARRAY(stateSound, i);
|
INIT_SOUNDASSET_ARRAY(stateSound, i);
|
||||||
stateScript[i] = 0;
|
stateScript[i] = 0;
|
||||||
stateEmitter[i] = 0;
|
stateEmitter[i] = 0;
|
||||||
stateEmitterTime[i] = 0;
|
stateEmitterTime[i] = 0;
|
||||||
|
|
@ -372,20 +372,8 @@ bool ShapeBaseImageData::onAdd()
|
||||||
s.shapeSequenceScale = stateScaleShapeSequence[i];
|
s.shapeSequenceScale = stateScaleShapeSequence[i];
|
||||||
|
|
||||||
//_setstateSound(getstateSound(i),i);
|
//_setstateSound(getstateSound(i),i);
|
||||||
s.sound = getstateSoundAsset(i);
|
handleStateSoundTrack(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.script = stateScript[i];
|
s.script = stateScript[i];
|
||||||
s.emitter = stateEmitter[i];
|
s.emitter = stateEmitter[i];
|
||||||
s.emitterTime = stateEmitterTime[i];
|
s.emitterTime = stateEmitterTime[i];
|
||||||
|
|
@ -591,6 +579,45 @@ bool ShapeBaseImageData::preload(bool server, String &errorStr)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShapeBaseImageData::handleStateSoundTrack(const U32& stateId)
|
||||||
|
{
|
||||||
|
if (stateId > MaxStates)
|
||||||
|
return;
|
||||||
|
|
||||||
|
StateData& s = state[stateId];
|
||||||
|
|
||||||
|
s.sound = getstateSoundAsset(stateId);
|
||||||
|
|
||||||
|
if (s.sound == NULL)
|
||||||
|
{
|
||||||
|
if (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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (mstateSoundSFXId[stateId] != 0)
|
||||||
|
{
|
||||||
|
SFXTrack* sndTrack;
|
||||||
|
if (!Sim::findObject(mstateSoundSFXId[stateId], sndTrack))
|
||||||
|
{
|
||||||
|
Con::errorf("ShapeBaseImageData::onAdd() - attempted to find sound %i but failed!", mstateSoundSFXId[stateId]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s.soundTrack = sndTrack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
S32 ShapeBaseImageData::lookupState(const char* name)
|
S32 ShapeBaseImageData::lookupState(const char* name)
|
||||||
{
|
{
|
||||||
if (!name || !name[0])
|
if (!name || !name[0])
|
||||||
|
|
@ -1160,7 +1187,7 @@ void ShapeBaseImageData::packData(BitStream* stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PACKDATA_ASSET_ARRAY(stateSound, i);
|
PACKDATA_SOUNDASSET_ARRAY(stateSound, i);
|
||||||
}
|
}
|
||||||
stream->write(maxConcurrentSounds);
|
stream->write(maxConcurrentSounds);
|
||||||
stream->writeFlag(useRemainderDT);
|
stream->writeFlag(useRemainderDT);
|
||||||
|
|
@ -1365,7 +1392,8 @@ void ShapeBaseImageData::unpackData(BitStream* stream)
|
||||||
else
|
else
|
||||||
s.emitter = 0;
|
s.emitter = 0;
|
||||||
|
|
||||||
UNPACKDATA_ASSET_ARRAY(stateSound, i);
|
UNPACKDATA_SOUNDASSET_ARRAY(stateSound, i);
|
||||||
|
handleStateSoundTrack(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue