tsforestitem and forestitem

This commit is contained in:
marauder2k7 2025-06-19 17:24:43 +01:00
parent 08f52cfa16
commit 9208cdfcd6
3 changed files with 19 additions and 18 deletions

View file

@ -53,7 +53,8 @@ ForestItemData::ForestItemData()
mTightnessCoefficient( 0.4f ), mTightnessCoefficient( 0.4f ),
mDampingCoefficient( 0.7f ) mDampingCoefficient( 0.7f )
{ {
INIT_ASSET(Shape); mShape = NULL;
mShapeAsset.registerRefreshNotify(this);
} }
void ForestItemData::initPersistFields() void ForestItemData::initPersistFields()
@ -61,10 +62,8 @@ void ForestItemData::initPersistFields()
docsURL; docsURL;
addGroup( "Shapes" ); addGroup( "Shapes" );
INITPERSISTFIELD_SHAPEASSET(Shape, ForestItemData, "Shape asset for this item type"); INITPERSISTFIELD_SHAPEASSET_REFACTOR(Shape, ForestItemData, "Shape asset for this item type");
addProtectedField( "shapeFile", TypeShapeFilename, Offset( mShapeName, ForestItemData ), &_setShapeData, &defaultProtectedGetFn,
"Shape file for this item type", AbstractClassRep::FIELD_HideInInspectors );
endGroup( "Shapes" ); endGroup( "Shapes" );
addGroup("Physics"); addGroup("Physics");
@ -164,7 +163,7 @@ void ForestItemData::packData(BitStream* stream)
stream->write( localName ); stream->write( localName );
PACKDATA_ASSET(Shape); PACKDATA_ASSET_REFACTOR(Shape);
stream->writeFlag( mCollidable ); stream->writeFlag( mCollidable );
@ -190,7 +189,7 @@ void ForestItemData::unpackData(BitStream* stream)
stream->read( &localName ); stream->read( &localName );
setInternalName( localName ); setInternalName( localName );
UNPACKDATA_ASSET(Shape); UNPACKDATA_ASSET_REFACTOR(Shape);
mCollidable = stream->readFlag(); mCollidable = stream->readFlag();

View file

@ -48,7 +48,7 @@ struct RayInfo;
class AbstractPolyList; class AbstractPolyList;
class ForestItemData : public SimDataBlock class ForestItemData : public SimDataBlock, protected AssetPtrCallback
{ {
protected: protected:
@ -62,8 +62,7 @@ protected:
public: public:
DECLARE_SHAPEASSET(ForestItemData, Shape, onShapeChanged); DECLARE_SHAPEASSET_REFACTOR(ForestItemData, Shape)
DECLARE_ASSET_SETGET(ForestItemData, Shape);
/// This is the radius used during placement to ensure /// This is the radius used during placement to ensure
/// the element isn't crowded up against other trees. /// the element isn't crowded up against other trees.
@ -144,7 +143,10 @@ public:
return theSignal; return theSignal;
} }
void onShapeChanged() Resource<TSShape> mShape;
protected:
void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
{ {
reloadOnLocalClient(); reloadOnLocalClient();
} }

View file

@ -99,13 +99,13 @@ void TSForestItemData::inspectPostApply()
void TSForestItemData::_onResourceChanged( const Torque::Path &path ) void TSForestItemData::_onResourceChanged( const Torque::Path &path )
{ {
U32 assetStatus = ShapeAsset::getAssetErrCode(mShapeAsset); U32 assetStatus = ShapeAsset::getAssetErrCode(_getShapeAssetId());
if (assetStatus != AssetBase::Ok && assetStatus != AssetBase::UsingFallback) if (assetStatus != AssetBase::Ok && assetStatus != AssetBase::UsingFallback)
{ {
return; return;
} }
if ( path != Path(mShapeAsset->getShapeFilePath()) ) if ( path != Path(getShapeFile()) )
return; return;
SAFE_DELETE( mShapeInstance ); SAFE_DELETE( mShapeInstance );
@ -116,18 +116,18 @@ void TSForestItemData::_onResourceChanged( const Torque::Path &path )
void TSForestItemData::_loadShape() void TSForestItemData::_loadShape()
{ {
U32 assetStatus = ShapeAsset::getAssetErrCode(mShapeAsset); mShape = getShape();
U32 assetStatus = ShapeAsset::getAssetErrCode(_getShapeAssetId());
if (assetStatus != AssetBase::Ok && assetStatus != AssetBase::UsingFallback) if (assetStatus != AssetBase::Ok && assetStatus != AssetBase::UsingFallback)
{ {
return; return;
} }
_setShape(mShapeAssetId);
if ( !(bool)mShape ) if ( !(bool)mShape )
return; return;
if ( mIsClientObject && if ( mIsClientObject &&
!mShape->preloadMaterialList(mShapeAsset->getShapeFilePath()) ) !mShape->preloadMaterialList(mShape.getPath()) )
return; return;
// Lets add an autobillboard detail if don't have one. // Lets add an autobillboard detail if don't have one.
@ -165,7 +165,7 @@ TSShapeInstance* TSForestItemData::_getShapeInstance() const
void TSForestItemData::_checkLastDetail() void TSForestItemData::_checkLastDetail()
{ {
U32 assetStatus = ShapeAsset::getAssetErrCode(mShapeAsset); U32 assetStatus = ShapeAsset::getAssetErrCode(_getShapeAssetId());
if (assetStatus != AssetBase::Ok && assetStatus != AssetBase::UsingFallback) if (assetStatus != AssetBase::Ok && assetStatus != AssetBase::UsingFallback)
{ {
return; return;
@ -177,7 +177,7 @@ void TSForestItemData::_checkLastDetail()
// TODO: Expose some real parameters to the datablock maybe? // TODO: Expose some real parameters to the datablock maybe?
if ( detail->subShapeNum != -1 ) if ( detail->subShapeNum != -1 )
{ {
mShape->addImposter(mShapeAsset->getShapeFilePath(), 10, 4, 0, 0, 256, 0, 0 ); mShape->addImposter(mShape.getPath(), 10, 4, 0, 0, 256, 0, 0);
// HACK: If i don't do this it crashes! // HACK: If i don't do this it crashes!
while ( mShape->detailCollisionAccelerators.size() < mShape->details.size() ) while ( mShape->detailCollisionAccelerators.size() < mShape->details.size() )