explosion and guiobjectview

This commit is contained in:
marauder2k7 2025-06-19 16:27:16 +01:00
parent 2b973abdcf
commit 51f4255c14
4 changed files with 67 additions and 74 deletions

View file

@ -239,7 +239,7 @@ ExplosionData::ExplosionData()
explosionScale.set(1.0f, 1.0f, 1.0f); explosionScale.set(1.0f, 1.0f, 1.0f);
playSpeed = 1.0f; playSpeed = 1.0f;
INIT_ASSET(ExplosionShape); mExplosionShapeAsset.registerRefreshNotify(this);
explosionAnimation = -1; explosionAnimation = -1;
@ -315,7 +315,7 @@ ExplosionData::ExplosionData(const ExplosionData& other, bool temp_clone) : Game
particleEmitterId = other.particleEmitterId; // -- for pack/unpack of particleEmitter ptr particleEmitterId = other.particleEmitterId; // -- for pack/unpack of particleEmitter ptr
explosionScale = other.explosionScale; explosionScale = other.explosionScale;
playSpeed = other.playSpeed; playSpeed = other.playSpeed;
CLONE_ASSET(ExplosionShape); mExplosionShapeAsset = other.mExplosionShapeAsset;
explosionAnimation = other.explosionAnimation; // -- from explosionShape sequence "ambient" explosionAnimation = other.explosionAnimation; // -- from explosionShape sequence "ambient"
dMemcpy( emitterList, other.emitterList, sizeof( emitterList ) ); dMemcpy( emitterList, other.emitterList, sizeof( emitterList ) );
dMemcpy( emitterIDList, other.emitterIDList, sizeof( emitterIDList ) ); // -- for pack/unpack of emitterList ptrs dMemcpy( emitterIDList, other.emitterIDList, sizeof( emitterIDList ) ); // -- for pack/unpack of emitterList ptrs
@ -360,6 +360,8 @@ ExplosionData::~ExplosionData()
if (!isTempClone()) if (!isTempClone())
return; return;
mExplosionShapeAsset.unregisterRefreshNotify();
// particleEmitter, emitterList[*], debrisList[*], explosionList[*] will delete themselves // particleEmitter, emitterList[*], debrisList[*], explosionList[*] will delete themselves
#ifdef TRACK_EXPLOSION_DATA_CLONES #ifdef TRACK_EXPLOSION_DATA_CLONES
@ -393,7 +395,7 @@ void ExplosionData::initPersistFields()
{ {
docsURL; docsURL;
addGroup("Shapes"); addGroup("Shapes");
INITPERSISTFIELD_SHAPEASSET(ExplosionShape, ExplosionData, "@brief Optional shape asset to place at the center of the explosion.\n\n" INITPERSISTFIELD_SHAPEASSET_REFACTOR(ExplosionShape, ExplosionData, "@brief Optional shape asset to place at the center of the explosion.\n\n"
"The <i>ambient</i> animation of this model will be played automatically at the start of the explosion."); "The <i>ambient</i> animation of this model will be played automatically at the start of the explosion.");
endGroup("Shapes"); endGroup("Shapes");
@ -668,7 +670,7 @@ void ExplosionData::packData(BitStream* stream)
{ {
Parent::packData(stream); Parent::packData(stream);
PACKDATA_ASSET(ExplosionShape); PACKDATA_ASSET_REFACTOR(ExplosionShape);
//PACKDATA_SOUNDASSET(Sound); //PACKDATA_SOUNDASSET(Sound);
PACKDATA_ASSET(Sound); PACKDATA_ASSET(Sound);
@ -773,7 +775,7 @@ void ExplosionData::unpackData(BitStream* stream)
{ {
Parent::unpackData(stream); Parent::unpackData(stream);
UNPACKDATA_ASSET(ExplosionShape); UNPACKDATA_ASSET_REFACTOR(ExplosionShape);
UNPACKDATA_ASSET(Sound); UNPACKDATA_ASSET(Sound);
@ -897,10 +899,10 @@ bool ExplosionData::preload(bool server, String &errorStr)
if (mExplosionShapeAsset.notNull()) { if (mExplosionShapeAsset.notNull()) {
// Resolve animations // Resolve animations
explosionAnimation = mExplosionShape->findSequence("ambient"); explosionAnimation = getExplosionShape()->findSequence("ambient");
// Preload textures with a dummy instance... // Preload textures with a dummy instance...
TSShapeInstance* pDummy = new TSShapeInstance(mExplosionShape, !server); TSShapeInstance* pDummy = new TSShapeInstance(getExplosionShape(), !server);
delete pDummy; delete pDummy;
} else { } else {
@ -1392,8 +1394,8 @@ bool Explosion::explode()
launchDebris( mInitialNormal ); launchDebris( mInitialNormal );
spawnSubExplosions(); spawnSubExplosions();
if (bool(mDataBlock->mExplosionShape) && mDataBlock->explosionAnimation != -1) { if (bool(mDataBlock->getExplosionShape()) && mDataBlock->explosionAnimation != -1) {
mExplosionInstance = new TSShapeInstance(mDataBlock->mExplosionShape, true); mExplosionInstance = new TSShapeInstance(mDataBlock->getExplosionShape(), true);
mExplosionThread = mExplosionInstance->addThread(); mExplosionThread = mExplosionInstance->addThread();
mExplosionInstance->setSequence(mExplosionThread, mDataBlock->explosionAnimation, 0); mExplosionInstance->setSequence(mExplosionThread, mDataBlock->explosionAnimation, 0);
@ -1403,7 +1405,7 @@ bool Explosion::explode()
mEndingMS = U32(mExplosionInstance->getScaledDuration(mExplosionThread) * 1000.0f); mEndingMS = U32(mExplosionInstance->getScaledDuration(mExplosionThread) * 1000.0f);
mObjScale.convolve(mDataBlock->explosionScale); mObjScale.convolve(mDataBlock->explosionScale);
mObjBox = mDataBlock->mExplosionShape->mBounds; mObjBox = mDataBlock->getExplosionShape()->mBounds;
resetWorldBox(); resetWorldBox();
} }

View file

@ -52,7 +52,7 @@ struct DebrisData;
class SFXProfile; class SFXProfile;
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
class ExplosionData : public GameBaseData { class ExplosionData : public GameBaseData, protected AssetPtrCallback {
public: public:
typedef GameBaseData Parent; typedef GameBaseData Parent;
@ -79,8 +79,7 @@ class ExplosionData : public GameBaseData {
Point3F explosionScale; Point3F explosionScale;
F32 playSpeed; F32 playSpeed;
DECLARE_SHAPEASSET(ExplosionData, ExplosionShape, onShapeChanged); DECLARE_SHAPEASSET_REFACTOR(ExplosionData, ExplosionShape)
DECLARE_ASSET_SETGET(ExplosionData, ExplosionShape);
S32 explosionAnimation; S32 explosionAnimation;
@ -143,7 +142,8 @@ public:
ExplosionData* cloneAndPerformSubstitutions(const SimObject*, S32 index=0); ExplosionData* cloneAndPerformSubstitutions(const SimObject*, S32 index=0);
bool allowSubstitutions() const override { return true; } bool allowSubstitutions() const override { return true; }
void onShapeChanged() protected:
void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
{ {
reloadOnLocalClient(); reloadOnLocalClient();
} }

View file

@ -119,8 +119,6 @@ GuiObjectView::GuiObjectView()
// By default don't do dynamic reflection // By default don't do dynamic reflection
// updates for this viewport. // updates for this viewport.
mReflectPriority = 0.0f; mReflectPriority = 0.0f;
INIT_ASSET(Model);
INIT_ASSET(MountedModel);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -137,7 +135,7 @@ void GuiObjectView::initPersistFields()
{ {
docsURL; docsURL;
addGroup( "Model" ); addGroup( "Model" );
INITPERSISTFIELD_SHAPEASSET(Model, GuiObjectView, "The source shape asset."); INITPERSISTFIELD_SHAPEASSET_REFACTOR(Model, GuiObjectView, "The source shape asset.");
addField( "skin", TypeRealString, Offset( mSkinName, GuiObjectView ), addField( "skin", TypeRealString, Offset( mSkinName, GuiObjectView ),
"The skin to use on the object model." ); "The skin to use on the object model." );
endGroup( "Model" ); endGroup( "Model" );
@ -150,7 +148,7 @@ void GuiObjectView::initPersistFields()
endGroup( "Animation" ); endGroup( "Animation" );
addGroup( "Mounting" ); addGroup( "Mounting" );
INITPERSISTFIELD_SHAPEASSET(MountedModel, GuiObjectView, "The mounted shape asset."); INITPERSISTFIELD_SHAPEASSET_REFACTOR(MountedModel, GuiObjectView, "The mounted shape asset.");
addField( "mountedSkin", TypeRealString, Offset( mMountSkinName, GuiObjectView ), addField( "mountedSkin", TypeRealString, Offset( mMountSkinName, GuiObjectView ),
"Skin name used on mounted shape file." ); "Skin name used on mounted shape file." );
addField( "mountedNode", TypeRealString, Offset( mMountNodeName, GuiObjectView ), addField( "mountedNode", TypeRealString, Offset( mMountNodeName, GuiObjectView ),
@ -335,19 +333,23 @@ bool GuiObjectView::setObjectModel( const String& modelName )
{ {
mRunThread = 0; mRunThread = 0;
// Load the shape. // Load the shape if its not the one already set.
_setModel(modelName); if (modelName.c_str() != _getModelAssetId())
if( !getModelResource()) _setModel(modelName.c_str());
else
return true;
if( !getModel())
{ {
Con::warnf( "GuiObjectView::setObjectModel - Failed to load model '%s'", modelName.c_str() ); Con::warnf( "GuiObjectView::setObjectModel - Failed to load model '%s'", modelName.c_str() );
return false; return false;
} }
if (!getModelResource()->preloadMaterialList(getModelResource().getPath())) return false; if (!getModel()->preloadMaterialList(getModel().getPath())) return false;
// Instantiate it. // Instantiate it.
mModelInstance = new TSShapeInstance(getModelResource(), true ); mModelInstance = new TSShapeInstance(getModel(), true );
mModelInstance->resetMaterialList(); mModelInstance->resetMaterialList();
mModelInstance->cloneMaterialList(); mModelInstance->cloneMaterialList();
@ -359,8 +361,8 @@ bool GuiObjectView::setObjectModel( const String& modelName )
mModelInstance->initMaterialList(); mModelInstance->initMaterialList();
// Initialize camera values. // Initialize camera values.
mOrbitPos = getModelResource()->center; mOrbitPos = getModel()->center;
mMinOrbitDist = getModelResource()->mRadius; mMinOrbitDist = getModel()->mRadius;
// Initialize animation. // Initialize animation.
@ -369,11 +371,6 @@ bool GuiObjectView::setObjectModel( const String& modelName )
return true; return true;
} }
void GuiObjectView::onModelChanged()
{
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void GuiObjectView::setSkin( const String& name ) void GuiObjectView::setSkin( const String& name )
@ -389,17 +386,21 @@ void GuiObjectView::setSkin( const String& name )
bool GuiObjectView::setMountedObject( const String& modelName ) bool GuiObjectView::setMountedObject( const String& modelName )
{ {
// Load the model. // Load the model if it is not already the asset then set it..
_setMountedModel(modelName); if (modelName.c_str() != _getMountedModelAssetId())
if (!getMountedModelResource()) _setMountedModel(modelName.c_str());
else
return true;
if (!getMountedModel())
{ {
Con::warnf("GuiObjectView::setMountedObject - Failed to load model '%s'", modelName.c_str()); Con::warnf("GuiObjectView::setMountedObject - Failed to load model '%s'", modelName.c_str());
return false; return false;
} }
if (!getMountedModelResource()->preloadMaterialList(getMountedModelResource().getPath())) return false; if (!getMountedModel()->preloadMaterialList(getMountedModel().getPath())) return false;
mMountedModelInstance = new TSShapeInstance(getMountedModelResource(), true); mMountedModelInstance = new TSShapeInstance(getMountedModel(), true);
mMountedModelInstance->resetMaterialList(); mMountedModelInstance->resetMaterialList();
mMountedModelInstance->cloneMaterialList(); mMountedModelInstance->cloneMaterialList();
@ -413,11 +414,6 @@ bool GuiObjectView::setMountedObject( const String& modelName )
return true; return true;
} }
void GuiObjectView::onMountedModelChanged()
{
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void GuiObjectView::setMountSkin(const String& name) void GuiObjectView::setMountSkin(const String& name)
@ -632,7 +628,7 @@ void GuiObjectView::setLightDirection( const Point3F& direction )
void GuiObjectView::_initAnimation() void GuiObjectView::_initAnimation()
{ {
AssertFatal(getModelResource(), "GuiObjectView::_initAnimation - No model loaded!" ); AssertFatal(getModel(), "GuiObjectView::_initAnimation - No model loaded!" );
if( mAnimationSeqName.isEmpty() && mAnimationSeq == -1 ) if( mAnimationSeqName.isEmpty() && mAnimationSeq == -1 )
return; return;
@ -641,13 +637,13 @@ void GuiObjectView::_initAnimation()
if( !mAnimationSeqName.isEmpty() ) if( !mAnimationSeqName.isEmpty() )
{ {
mAnimationSeq = getModelResource()->findSequence( mAnimationSeqName ); mAnimationSeq = getModel()->findSequence( mAnimationSeqName );
if( mAnimationSeq == -1 ) if( mAnimationSeq == -1 )
{ {
Con::errorf( "GuiObjectView::_initAnimation - Cannot find animation sequence '%s' on '%s'", Con::errorf( "GuiObjectView::_initAnimation - Cannot find animation sequence '%s' on '%s'",
mAnimationSeqName.c_str(), mAnimationSeqName.c_str(),
mModelName _getModelAssetId()
); );
return; return;
@ -658,11 +654,11 @@ void GuiObjectView::_initAnimation()
if( mAnimationSeq != -1 ) if( mAnimationSeq != -1 )
{ {
if( mAnimationSeq >= getModelResource()->sequences.size() ) if( mAnimationSeq >= getModel()->sequences.size() )
{ {
Con::errorf( "GuiObjectView::_initAnimation - Sequence '%i' out of range for model '%s'", Con::errorf( "GuiObjectView::_initAnimation - Sequence '%i' out of range for model '%s'",
mAnimationSeq, mAnimationSeq,
mModelName _getModelAssetId()
); );
mAnimationSeq = -1; mAnimationSeq = -1;
@ -693,12 +689,12 @@ void GuiObjectView::_initMount()
if( !mMountNodeName.isEmpty() ) if( !mMountNodeName.isEmpty() )
{ {
mMountNode = getModelResource()->findNode( mMountNodeName ); mMountNode = getModel()->findNode( mMountNodeName );
if( mMountNode == -1 ) if( mMountNode == -1 )
{ {
Con::errorf( "GuiObjectView::_initMount - No node '%s' on '%s'", Con::errorf( "GuiObjectView::_initMount - No node '%s' on '%s'",
mMountNodeName.c_str(), mMountNodeName.c_str(),
mModelName _getModelAssetId()
); );
return; return;
@ -707,11 +703,11 @@ void GuiObjectView::_initMount()
// Make sure mount node is valid. // Make sure mount node is valid.
if( mMountNode != -1 && mMountNode >= getModelResource()->nodes.size() ) if( mMountNode != -1 && mMountNode >= getModel()->nodes.size() )
{ {
Con::errorf( "GuiObjectView::_initMount - Mount node index '%i' out of range for '%s'", Con::errorf( "GuiObjectView::_initMount - Mount node index '%i' out of range for '%s'",
mMountNode, mMountNode,
mModelName _getModelAssetId()
); );
mMountNode = -1; mMountNode = -1;
@ -720,11 +716,11 @@ void GuiObjectView::_initMount()
// Look up node on the mounted model from // Look up node on the mounted model from
// which to mount to the primary model's node. // which to mount to the primary model's node.
if (!getMountedModelResource()) return; if (!getMountedModel()) return;
S32 mountPoint = getMountedModelResource()->findNode( "mountPoint" ); S32 mountPoint = getMountedModel()->findNode( "mountPoint" );
if( mountPoint != -1 ) if( mountPoint != -1 )
{ {
getMountedModelResource()->getNodeWorldTransform(mountPoint, &mMountTransform), getMountedModel()->getNodeWorldTransform(mountPoint, &mMountTransform),
mMountTransform.inverse(); mMountTransform.inverse();
} }
} }
@ -745,7 +741,7 @@ DefineEngineMethod( GuiObjectView, getModel, const char*, (),,
"@return Name of the displayed model.\n\n" "@return Name of the displayed model.\n\n"
"@see GuiControl") "@see GuiControl")
{ {
return Con::getReturnBuffer( object->getModel() ); return Con::getReturnBuffer( object->_getModelAssetId() );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -775,7 +771,7 @@ DefineEngineMethod( GuiObjectView, getMountedModel, const char*, (),,
"@return Name of the mounted model.\n\n" "@return Name of the mounted model.\n\n"
"@see GuiControl") "@see GuiControl")
{ {
return Con::getReturnBuffer( object->getMountedModel() ); return Con::getReturnBuffer( object->_getMountedModelAssetId() );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -37,7 +37,7 @@ class LightInfo;
/// A control that displays a TSShape in its view. /// A control that displays a TSShape in its view.
class GuiObjectView : public GuiTSCtrl class GuiObjectView : public GuiTSCtrl, protected AssetPtrCallback
{ {
public: public:
@ -70,15 +70,8 @@ class GuiObjectView : public GuiTSCtrl
/// @{ /// @{
///Model loaded for display. ///Model loaded for display.
DECLARE_SHAPEASSET(GuiObjectView, Model, onModelChanged); DECLARE_SHAPEASSET_REFACTOR(GuiObjectView, Model)
static bool _setModelData(void* obj, const char* index, const char* data)\
{
bool ret = false;
GuiObjectView* object = static_cast<GuiObjectView*>(obj);
ret = object->setObjectModel(StringTable->insert(data));
return ret;
}
void onModelChanged();
TSShapeInstance* mModelInstance; TSShapeInstance* mModelInstance;
/// Name of skin to use on model. /// Name of skin to use on model.
String mSkinName; String mSkinName;
@ -109,15 +102,7 @@ class GuiObjectView : public GuiTSCtrl
/// @{ /// @{
///Model to mount to the primary model. ///Model to mount to the primary model.
DECLARE_SHAPEASSET(GuiObjectView, MountedModel, onMountedModelChanged); DECLARE_SHAPEASSET_REFACTOR(GuiObjectView, MountedModel)
static bool _setMountedModelData(void* obj, const char* index, const char* data)\
{
bool ret = false;
GuiObjectView* object = static_cast<GuiObjectView*>(obj);
ret = object->setMountedObject(StringTable->insert(data));
return ret;
}
void onMountedModelChanged();
TSShapeInstance* mMountedModelInstance; TSShapeInstance* mMountedModelInstance;
/// ///
@ -284,7 +269,17 @@ class GuiObjectView : public GuiTSCtrl
static void initPersistFields(); static void initPersistFields();
DECLARE_CONOBJECT( GuiObjectView ); DECLARE_CONOBJECT( GuiObjectView );
DECLARE_DESCRIPTION( "A control that shows a TSShape model." ); DECLARE_DESCRIPTION( "A control that shows a TSShape model." );
protected:
void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
{
if (mModelAsset.notNull())
setObjectModel(_getModelAssetId());
if (mMountedModelAsset.notNull())
setMountedObject(_getMountedModelAssetId());
}
}; };
#endif // !_GUIOBJECTVIEW_H_ #endif // !_GUIOBJECTVIEW_H_