mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 14:44:36 +00:00
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:
parent
c2c5674fe9
commit
b44158cb89
52 changed files with 1860 additions and 1086 deletions
|
|
@ -239,7 +239,7 @@ ExplosionData::ExplosionData()
|
|||
explosionScale.set(1.0f, 1.0f, 1.0f);
|
||||
playSpeed = 1.0f;
|
||||
|
||||
mExplosionShapeAsset.registerRefreshNotify(this);
|
||||
explosionShapeAssetRef.assetPtr.registerRefreshNotify(this);
|
||||
|
||||
explosionAnimation = -1;
|
||||
|
||||
|
|
@ -315,7 +315,7 @@ ExplosionData::ExplosionData(const ExplosionData& other, bool temp_clone) : Game
|
|||
particleEmitterId = other.particleEmitterId; // -- for pack/unpack of particleEmitter ptr
|
||||
explosionScale = other.explosionScale;
|
||||
playSpeed = other.playSpeed;
|
||||
mExplosionShapeAsset = other.mExplosionShapeAsset;
|
||||
explosionShapeAssetRef = other.explosionShapeAssetRef;
|
||||
explosionAnimation = other.explosionAnimation; // -- from explosionShape sequence "ambient"
|
||||
dMemcpy( emitterList, other.emitterList, sizeof( emitterList ) );
|
||||
dMemcpy( emitterIDList, other.emitterIDList, sizeof( emitterIDList ) ); // -- for pack/unpack of emitterList ptrs
|
||||
|
|
@ -360,8 +360,6 @@ ExplosionData::~ExplosionData()
|
|||
if (!isTempClone())
|
||||
return;
|
||||
|
||||
mExplosionShapeAsset.unregisterRefreshNotify();
|
||||
|
||||
// particleEmitter, emitterList[*], debrisList[*], explosionList[*] will delete themselves
|
||||
|
||||
#ifdef TRACK_EXPLOSION_DATA_CLONES
|
||||
|
|
@ -395,8 +393,9 @@ void ExplosionData::initPersistFields()
|
|||
{
|
||||
docsURL;
|
||||
addGroup("Shapes");
|
||||
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.");
|
||||
ADD_FIELD("explosionShapeAsset", TypeShapeAssetRef, Offset(explosionShapeAssetRef, ExplosionData))
|
||||
.doc("@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.");
|
||||
endGroup("Shapes");
|
||||
|
||||
addGroup("Sounds");
|
||||
|
|
@ -673,7 +672,7 @@ void ExplosionData::packData(BitStream* stream)
|
|||
{
|
||||
Parent::packData(stream);
|
||||
|
||||
PACKDATA_ASSET_REFACTOR(ExplosionShape);
|
||||
AssetDatabase.packDataAsset(stream, explosionShapeAssetRef.assetId);
|
||||
|
||||
//PACKDATA_SOUNDASSET(Sound);
|
||||
PACKDATA_ASSET(Sound);
|
||||
|
|
@ -778,7 +777,7 @@ void ExplosionData::unpackData(BitStream* stream)
|
|||
{
|
||||
Parent::unpackData(stream);
|
||||
|
||||
UNPACKDATA_ASSET_REFACTOR(ExplosionShape);
|
||||
explosionShapeAssetRef = AssetDatabase.unpackDataAsset(stream);
|
||||
|
||||
UNPACKDATA_ASSET(Sound);
|
||||
|
||||
|
|
@ -913,23 +912,21 @@ bool ExplosionData::preload(bool server, String &errorStr)
|
|||
}
|
||||
}
|
||||
|
||||
if (getExplosionShape()) {
|
||||
|
||||
// Resolve animations
|
||||
explosionAnimation = getExplosionShape()->findSequence("ambient");
|
||||
|
||||
// Preload textures with a dummy instance...
|
||||
TSShapeInstance* pDummy = new TSShapeInstance(getExplosionShape(), !server);
|
||||
delete pDummy;
|
||||
|
||||
}
|
||||
else if (mExplosionShapeAsset.notNull())
|
||||
if (!explosionShapeAssetRef.isNull())
|
||||
{
|
||||
errorStr = String::ToString("ExplosionData::preload: Couldn't load shape \"%s\"", _getExplosionShapeAssetId());
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
explosionAnimation = -1;
|
||||
Resource<TSShape> shape = explosionShapeAssetRef.assetPtr->getShapeResource();
|
||||
if (shape)
|
||||
{
|
||||
TSShapeInstance* pDummy = new TSShapeInstance(shape, !server);
|
||||
delete pDummy;
|
||||
if (!server && !explosionShapeAssetRef.assetPtr->preloadMaterialList() && NetConnection::filesWereDownloaded())
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorStr = String::ToString("ExplosionData(%s)::preload: Couldn't load shape \"%s\"", getName(), explosionShapeAssetRef.assetId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -1417,8 +1414,12 @@ bool Explosion::explode()
|
|||
launchDebris( mInitialNormal );
|
||||
spawnSubExplosions();
|
||||
|
||||
if (bool(mDataBlock->getExplosionShape()) && mDataBlock->explosionAnimation != -1) {
|
||||
mExplosionInstance = new TSShapeInstance(mDataBlock->getExplosionShape(), true);
|
||||
Resource<TSShape> eShape;
|
||||
if (mDataBlock->explosionShapeAssetRef.notNull())
|
||||
eShape = mDataBlock->explosionShapeAssetRef.assetPtr->getShapeResource();
|
||||
|
||||
if (bool(eShape) && mDataBlock->explosionAnimation != -1) {
|
||||
mExplosionInstance = new TSShapeInstance(eShape, true);
|
||||
|
||||
mExplosionThread = mExplosionInstance->addThread();
|
||||
mExplosionInstance->setSequence(mExplosionThread, mDataBlock->explosionAnimation, 0);
|
||||
|
|
@ -1428,7 +1429,7 @@ bool Explosion::explode()
|
|||
mEndingMS = U32(mExplosionInstance->getScaledDuration(mExplosionThread) * 1000.0f);
|
||||
|
||||
mObjScale.convolve(mDataBlock->explosionScale);
|
||||
mObjBox = mDataBlock->getExplosionShape()->mBounds;
|
||||
mObjBox = eShape->mBounds;
|
||||
resetWorldBox();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class ExplosionData : public GameBaseData, protected AssetPtrCallback {
|
|||
Point3F explosionScale;
|
||||
F32 playSpeed;
|
||||
|
||||
DECLARE_SHAPEASSET_REFACTOR(ExplosionData, ExplosionShape)
|
||||
AssetRef<ShapeAsset> explosionShapeAssetRef;
|
||||
|
||||
S32 explosionAnimation;
|
||||
|
||||
|
|
|
|||
|
|
@ -513,9 +513,6 @@ GroundCover::GroundCover()
|
|||
mLayerAsset[i] = NULL;
|
||||
mLayerFile[i] = StringTable->EmptyString();
|
||||
|
||||
mShapeAsset[i] = NULL;
|
||||
mShapeFile[i] = StringTable->EmptyString();
|
||||
|
||||
mInvertLayer[i] = NULL;
|
||||
|
||||
mMinClumpCount[i] = 1;
|
||||
|
|
@ -526,7 +523,7 @@ GroundCover::GroundCover()
|
|||
mBillboardRects[i].point.set( 0.0f, 0.0f );
|
||||
mBillboardRects[i].extent.set( 1.0f, 1.0f );
|
||||
|
||||
mShapeAsset[i].registerRefreshNotify(this);
|
||||
mShapeAssetRef[i].assetPtr.registerRefreshNotify(this);
|
||||
|
||||
mShapeInstances[i] = NULL;
|
||||
|
||||
|
|
@ -568,7 +565,10 @@ void GroundCover::initPersistFields()
|
|||
|
||||
addField( "billboardUVs", TypeRectUV, Offset( mBillboardRects, GroundCover ), MAX_COVERTYPES, "Subset material UV coordinates for this cover billboard." );
|
||||
|
||||
INITPERSISTFIELD_SHAPEASSET_ARRAY_REFACTOR(Shape, MAX_COVERTYPES, GroundCover, "The cover shape. [Optional]");
|
||||
ADD_FIELD("shapeAsset", TypeShapeAssetRef, Offset(mShapeAssetRef, GroundCover))
|
||||
.elements(MAX_COVERTYPES)
|
||||
.doc("The cover shape. [Optional]")
|
||||
.network(-1);
|
||||
|
||||
INITPERSISTFIELD_TERRAINMATERIALASSET_ARRAY(Layer, MAX_COVERTYPES, GroundCover, "Terrain material assetId to limit coverage to, or blank to not limit.");
|
||||
|
||||
|
|
@ -773,10 +773,11 @@ U32 GroundCover::packUpdate( NetConnection *connection, U32 mask, BitStream *str
|
|||
stream->write( mBillboardRects[i].point.y );
|
||||
stream->write( mBillboardRects[i].extent.x );
|
||||
stream->write( mBillboardRects[i].extent.y );
|
||||
|
||||
AssetDatabase.packUpdateAsset(connection, mask, stream, mShapeAssetRef[i].assetId);
|
||||
}
|
||||
|
||||
PACK_ASSET_ARRAY_REFACTOR(connection, Layer, MAX_COVERTYPES)
|
||||
PACK_ASSET_ARRAY_REFACTOR(connection, Shape, MAX_COVERTYPES)
|
||||
|
||||
stream->writeFlag( mDebugRenderCells );
|
||||
stream->writeFlag( mDebugNoBillboards );
|
||||
|
|
@ -844,12 +845,12 @@ void GroundCover::unpackUpdate( NetConnection *connection, BitStream *stream )
|
|||
stream->read( &mBillboardRects[i].point.y );
|
||||
stream->read( &mBillboardRects[i].extent.x );
|
||||
stream->read( &mBillboardRects[i].extent.y );
|
||||
|
||||
mShapeAssetRef[i] = AssetDatabase.unpackUpdateAsset(connection, stream);
|
||||
}
|
||||
|
||||
UNPACK_ASSET_ARRAY_REFACTOR(connection, Layer, MAX_COVERTYPES)
|
||||
|
||||
UNPACK_ASSET_ARRAY_REFACTOR(connection, Shape, MAX_COVERTYPES)
|
||||
|
||||
mDebugRenderCells = stream->readFlag();
|
||||
mDebugNoBillboards = stream->readFlag();
|
||||
mDebugNoShapes = stream->readFlag();
|
||||
|
|
@ -895,17 +896,21 @@ void GroundCover::_initShapes()
|
|||
|
||||
for ( S32 i=0; i < MAX_COVERTYPES; i++ )
|
||||
{
|
||||
if ( mShapeAsset[i].isNull() || getShape(i) == NULL)
|
||||
if ( mShapeAssetRef[i].isNull())
|
||||
continue;
|
||||
|
||||
if ( isClientObject() && !getShape(i)->preloadMaterialList(getShapeFile(i)) && NetConnection::filesWereDownloaded() )
|
||||
Resource<TSShape> shape = mShapeAssetRef[i].assetPtr->getShapeResource();
|
||||
if (!shape)
|
||||
continue;
|
||||
|
||||
if ( isClientObject() && !mShapeAssetRef[i].assetPtr->preloadMaterialList() && NetConnection::filesWereDownloaded() )
|
||||
{
|
||||
Con::warnf( "GroundCover::_initShapes() material preload failed for shape: %s", _getShapeAssetId(i));
|
||||
Con::warnf( "GroundCover::_initShapes() material preload failed for shape: %s", mShapeAssetRef[i].assetId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create the shape instance.
|
||||
mShapeInstances[i] = new TSShapeInstance(getShape(i), isClientObject() );
|
||||
mShapeInstances[i] = new TSShapeInstance(shape, isClientObject() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -345,7 +345,7 @@ protected:
|
|||
RectF mBillboardRects[MAX_COVERTYPES];
|
||||
|
||||
/// The cover shape filenames.
|
||||
DECLARE_SHAPEASSET_ARRAY_NET_REFACTOR(GroundCover, Shape, MAX_COVERTYPES, -1)
|
||||
AssetRef<ShapeAsset> mShapeAssetRef[MAX_COVERTYPES];
|
||||
|
||||
/// The cover shape instances.
|
||||
TSShapeInstance* mShapeInstances[MAX_COVERTYPES];
|
||||
|
|
|
|||
|
|
@ -850,9 +850,6 @@ ConsoleSetType(TypeParticleList)
|
|||
const char* values = argv[0];
|
||||
numUnits = StringUnit::getUnitCount(values, " ");
|
||||
|
||||
if (numUnits > 1)
|
||||
bool dafgdf = true;
|
||||
|
||||
for (U32 i = 0; i < numUnits; i++)
|
||||
{
|
||||
const char* value = StringUnit::getUnit(values, i, " ");
|
||||
|
|
@ -877,7 +874,6 @@ ConsoleSetType(TypeParticleList)
|
|||
Con::printf("TypeParticleList vec results: %s", testVec[x]);
|
||||
}
|
||||
}
|
||||
bool test = false;
|
||||
}
|
||||
|
||||
#ifdef TORQUE_TOOLS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue