Cleans up ShapeAsset of some unnecessary/redundant elements like extra material and animations tracking

Removed the old SHAPE_ASSET macros
Implements AssetRef struct that acts as a universal wrapper for an templated AssetPtr and AssetId pair
Adds Type handling for AssetRef for ShapeAsset to unify handling in classes that utilize a shapeAsset, so assigning an assetPtr or an assetId will keep a record of the assignment in the event the assetPtr is invalid.
Update all classes that utilized the old SHAPE_ASSET macros to utilize the AssetRef struct and updated the class code to utilize it to provide much more clean and concise code that isn't blocked behind macro definitions
Added a new example class: shapeDatablockExample which allows render of a simple shape object utilizing a simple example datablock.
This commit is contained in:
JeffR 2026-05-31 01:19:26 -05:00
parent c2c5674fe9
commit b44158cb89
52 changed files with 1860 additions and 1086 deletions

View file

@ -145,7 +145,7 @@ U32 Projectile::smProjectileWarpTicks = 5;
//
ProjectileData::ProjectileData()
{
mProjectileShapeAsset.registerRefreshNotify(this);
projectileShapeAssetRef.assetPtr.registerRefreshNotify(this);
INIT_ASSET(ProjectileSound);
@ -223,7 +223,7 @@ ProjectileData::ProjectileData(const ProjectileData& other, bool temp_clone) : G
CLONE_ASSET(ProjectileSound);
lightDesc = other.lightDesc;
lightDescId = other.lightDescId; // -- for pack/unpack of lightDesc ptr
mProjectileShapeAsset = other.mProjectileShapeAsset;// -- TSShape loads using mProjectileShapeName
projectileShapeAssetRef = other.projectileShapeAssetRef;// -- TSShape loads using projectileShapeAssetRef
activateSeq = other.activateSeq; // -- from projectileShape sequence "activate"
maintainSeq = other.maintainSeq; // -- from projectileShape sequence "maintain"
particleEmitter = other.particleEmitter;
@ -237,7 +237,8 @@ void ProjectileData::initPersistFields()
{
docsURL;
addGroup("Shapes");
INITPERSISTFIELD_SHAPEASSET_REFACTOR(ProjectileShape, ProjectileData, "@brief The model of the projectile.\n\n");
ADD_FIELD("projectileShapeAsset", TypeShapeAssetRef, Offset(projectileShapeAssetRef, ProjectileData))
.doc("@brief The model of the projectile.\n\n");
addField("scale", TypePoint3F, Offset(scale, ProjectileData),
"@brief Scale to apply to the projectile's size.\n\n"
"@note This is applied after SceneObject::scale\n");
@ -422,18 +423,21 @@ bool ProjectileData::preload(bool server, String &errorStr)
Con::errorf(ConsoleLogEntry::General, "ProjectileData::preload: Invalid packet, bad datablockid(lightDesc): %d", lightDescId);
}
if (getProjectileShape())
if (!projectileShapeAssetRef.isNull())
{
activateSeq = getProjectileShape()->findSequence("activate");
maintainSeq = getProjectileShape()->findSequence("maintain");
TSShapeInstance* pDummy = new TSShapeInstance(getProjectileShape(), !server);
delete pDummy;
}
else if (mProjectileShapeAsset.notNull())
{
errorStr = String::ToString("ProjectileData::preload: Couldn't load shape \"%s\"", _getProjectileShapeAssetId());
return false;
Resource<TSShape> shape = projectileShapeAssetRef.assetPtr->getShapeResource();
if (shape)
{
TSShapeInstance* pDummy = new TSShapeInstance(shape, !server);
delete pDummy;
if (!server && !projectileShapeAssetRef.assetPtr->preloadMaterialList() && NetConnection::filesWereDownloaded())
return false;
}
else
{
errorStr = String::ToString("ProjectileData(%s)::preload: Couldn't load shape \"%s\"", getName(), projectileShapeAssetRef.assetId);
return false;
}
}
return true;
@ -444,7 +448,7 @@ void ProjectileData::packData(BitStream* stream)
{
Parent::packData(stream);
PACKDATA_ASSET_REFACTOR(ProjectileShape);
AssetDatabase.packDataAsset(stream, projectileShapeAssetRef.assetId);;
stream->writeFlag(faceViewer);
if(stream->writeFlag(scale.x != 1 || scale.y != 1 || scale.z != 1))
@ -509,7 +513,7 @@ void ProjectileData::unpackData(BitStream* stream)
{
Parent::unpackData(stream);
UNPACKDATA_ASSET_REFACTOR(ProjectileShape);
projectileShapeAssetRef = AssetDatabase.unpackDataAsset(stream);
faceViewer = stream->readFlag();
if(stream->readFlag())
@ -808,6 +812,8 @@ bool Projectile::onAdd()
return false;
}
Resource<TSShape> pShape;
if (isServerObject())
{
ShapeBase* ptr;
@ -835,15 +841,19 @@ bool Projectile::onAdd()
}
else
{
if (bool(mDataBlock->getProjectileShape()))
if (mDataBlock->projectileShapeAssetRef.notNull())
{
mProjectileShape = new TSShapeInstance(mDataBlock->getProjectileShape(), isClientObject());
if (mDataBlock->activateSeq != -1)
pShape = mDataBlock->projectileShapeAssetRef.assetPtr->getShapeResource();
if (pShape)
{
mActivateThread = mProjectileShape->addThread();
mProjectileShape->setTimeScale(mActivateThread, 1);
mProjectileShape->setSequence(mActivateThread, mDataBlock->activateSeq, 0);
mProjectileShape = new TSShapeInstance(pShape, isClientObject());
if (mDataBlock->activateSeq != -1)
{
mActivateThread = mProjectileShape->addThread();
mProjectileShape->setTimeScale(mActivateThread, 1);
mProjectileShape->setSequence(mActivateThread, mDataBlock->activateSeq, 0);
}
}
}
if (mDataBlock->particleEmitter != NULL)
@ -876,8 +886,8 @@ bool Projectile::onAdd()
processAfter(mSourceObject);
// Setup our bounding box
if (bool(mDataBlock->getProjectileShape()) == true)
mObjBox = mDataBlock->getProjectileShape()->mBounds;
if (bool(pShape) == true)
mObjBox = pShape->mBounds;
else
mObjBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));