sound asset conversions - afxmagicmissile for a datablock case and guimltextcrtl for an object-instance case

This commit is contained in:
AzaezelX 2021-10-14 15:06:49 -05:00
parent 33210c4a1e
commit 00515fffa8
4 changed files with 30 additions and 20 deletions

View file

@ -142,8 +142,7 @@ U32 Projectile::smProjectileWarpTicks = 5;
afxMagicMissileData::afxMagicMissileData()
{
INIT_ASSET(ProjectileShape);
sound = NULL;
INIT_ASSET(ProjectileSound);
/* From stock Projectile code...
explosion = NULL;
@ -248,7 +247,7 @@ afxMagicMissileData::afxMagicMissileData(const afxMagicMissileData& other, bool
{
CLONE_ASSET(ProjectileShape);
projectileShape = other.projectileShape; // -- TSShape loads using projectileShapeName
sound = other.sound;
CLONE_ASSET(ProjectileSound);
splash = other.splash;
splashId = other.splashId; // -- for pack/unpack of splash ptr
lightDesc = other.lightDesc;
@ -338,7 +337,7 @@ void afxMagicMissileData::initPersistFields()
INITPERSISTFIELD_SHAPEASSET(ProjectileShape, afxMagicMissileData, "Shape for the projectile");
addField("scale", TypePoint3F, Offset(scale, afxMagicMissileData));
addField("sound", TypeSFXTrackName, Offset(sound, afxMagicMissileData));
INITPERSISTFIELD_SOUNDASSET(ProjectileSound, afxMagicMissileData, "sound for the projectile");
/* From stock Projectile code...
addField("explosion", TYPEID< ExplosionData >(), Offset(explosion, ProjectileData));
@ -533,9 +532,12 @@ bool afxMagicMissileData::preload(bool server, String &errorStr)
Con::errorf(ConsoleLogEntry::General, "ProjectileData::preload: Invalid packet, bad datablockId(decal): %d", decalId);
*/
String sfxErrorStr;
if( !sfxResolve( &sound, sfxErrorStr) )
Con::errorf(ConsoleLogEntry::General, "afxMagicMissileData::preload: Invalid packet: %s", sfxErrorStr.c_str());
_setProjectileSound(getProjectileSound());
if (getProjectileSound() != StringTable->EmptyString())
{
if (!getProjectileSoundProfile())
Con::errorf(ConsoleLogEntry::General, "afxMagicMissileData::preload: Cant get an sfxProfile for afxMagicMissileData.");
}
if (!lightDesc && lightDescId != 0)
if (Sim::findObject(lightDescId, lightDesc) == false)
@ -547,7 +549,7 @@ bool afxMagicMissileData::preload(bool server, String &errorStr)
projectileShape = mProjectileShapeAsset->getShapeResource();
if (bool(projectileShape) == false)
{
errorStr = String::ToString("afxMagicMissileData::load: Couldn't load shape \"%s\"", mProjectileShapeAssetId);
errorStr = String::ToString("afxMagicMissileData::preload: Couldn't load shape \"%s\"", mProjectileShapeAssetId);
return false;
}
/* From stock Projectile code...
@ -641,7 +643,7 @@ void afxMagicMissileData::packData(BitStream* stream)
DataBlockObjectIdLast);
*/
sfxWrite( stream, sound );
PACKDATA_ASSET(ProjectileSound);
if ( stream->writeFlag(lightDesc != NULL))
stream->writeRangedU32(lightDesc->getId(), DataBlockObjectIdFirst,
@ -747,7 +749,7 @@ void afxMagicMissileData::unpackData(BitStream* stream)
decalId = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast);
*/
sfxRead( stream, &sound );
UNPACKDATA_ASSET(ProjectileSound);
if (stream->readFlag())
lightDescId = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast);
@ -1170,8 +1172,8 @@ bool afxMagicMissile::onNewDataBlock(GameBaseData* dptr, bool reload)
SFX_DELETE( mSound );
if ( mDataBlock->sound )
mSound = SFX->createSource( mDataBlock->sound );
if (mDataBlock->getProjectileSound())
mSound = SFX->createSource(mDataBlock->getProjectileSoundProfile());
}
return true;
@ -2006,7 +2008,7 @@ void afxMagicMissile::get_launch_data(Point3F& pos, Point3F& vel)
void afxMagicMissile::updateSound()
{
if (!mDataBlock->sound)
if (!mDataBlock->isProjectileSoundValid())
return;
if ( mSound )

View file

@ -126,7 +126,8 @@ public:
SplashData* splash; // Water Splash Datablock
S32 splashId; // Water splash ID
SFXTrack* sound; // Projectile Sound
DECLARE_SOUNDASSET(afxMagicMissileData, ProjectileSound);
DECLARE_ASSET_SETGET(afxMagicMissileData, ProjectileSound);
LightDescription *lightDesc;
S32 lightDescId;

View file

@ -268,7 +268,7 @@ GuiMLTextCtrl::GuiMLTextCtrl()
{
mActive = true;
//mInitialText = StringTable->EmptyString();
Sim::findObject("InputDeniedSound", mDeniedSound);
INIT_ASSET(DeniedSound);
}
//--------------------------------------------------------------------------
@ -290,7 +290,7 @@ void GuiMLTextCtrl::initPersistFields()
addField("lineSpacing", TypeS32, Offset(mLineSpacingPixels, GuiMLTextCtrl), "The number of blank pixels to place between each line.\n");
addField("allowColorChars", TypeBool, Offset(mAllowColorChars, GuiMLTextCtrl), "If true, the control will allow characters to have unique colors.");
addField("maxChars", TypeS32, Offset(mMaxBufferSize, GuiMLTextCtrl), "Maximum number of characters that the control will display.");
addField("deniedSound", TypeSFXTrackName, Offset(mDeniedSound, GuiMLTextCtrl), "If the text will not fit in the control, the deniedSound is played.");
INITPERSISTFIELD_SOUNDASSET(DeniedSound, GuiMLTextCtrl, "If the text will not fit in the control, the deniedSound is played.");
addField("text", TypeCaseString, Offset( mInitialText, GuiMLTextCtrl ), "Text to display in this control.");
addField("useURLMouseCursor", TypeBool, Offset(mUseURLMouseCursor, GuiMLTextCtrl), "If true, the mouse cursor will turn into a hand cursor while over a link in the text.\n"
"This is dependant on the markup language used by the GuiMLTextCtrl\n");
@ -323,6 +323,9 @@ bool GuiMLTextCtrl::onAdd()
if (!mTextBuffer.length() && mInitialText[0] != 0)
setText(mInitialText, dStrlen(mInitialText)+1);
_setDeniedSound(getDeniedSound());
return true;
}
@ -917,8 +920,8 @@ void GuiMLTextCtrl::insertChars(const char* inputChars,
if (numCharsToInsert <= 0)
{
// Play the "Denied" sound:
if ( numInputChars > 0 && mDeniedSound )
SFX->playOnce(mDeniedSound);
if ( numInputChars > 0 && getDeniedSoundProfile())
SFX->playOnce(getDeniedSoundProfile());
return;
}

View file

@ -31,6 +31,10 @@
#include "core/stringBuffer.h"
#endif
#ifndef SOUND_ASSET_H
#include "T3D/assets/SoundAsset.h"
#endif
class GFont;
class SFXTrack;
@ -258,8 +262,8 @@ class GuiMLTextCtrl : public GuiControl
bool mUseURLMouseCursor;
// Too many chars sound:
SFXTrack* mDeniedSound;
DECLARE_SOUNDASSET(GuiMLTextCtrl, DeniedSound);
DECLARE_ASSET_SETGET(GuiMLTextCtrl, DeniedSound);
//-------------------------------------- Protected interface
protected:
// Inserting and deleting character blocks...