try to load shapes during preload

it's half the point of the protocol
This commit is contained in:
AzaezelX 2025-07-06 19:51:55 -05:00
parent c138d838bb
commit e8ccb3443a
18 changed files with 63 additions and 71 deletions

View file

@ -122,7 +122,7 @@ public:
U32 load() override;
TSShape* getShape() { return mShape; }
TSShape* getShape() { load(); return mShape; }
Resource<TSShape> getShapeResource() { load(); return mShape; }
@ -295,7 +295,7 @@ public:
}; \
\
inline StringTableEntry _get##name##AssetId(void) const { return m##name##Asset.getAssetId(); } \
Resource<TSShape> get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShapeResource(); else return ResourceManager::get().load( "" ); } \
TSShape* get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShape(); else return NULL; } \
AssetPtr<ShapeAsset> get##name##Asset(void) { return m##name##Asset; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false; } \
StringTableEntry get##name##File() { return m##name##Asset.notNull() ? m##name##Asset->getShapeFile() : ""; }
@ -353,12 +353,12 @@ public:
}; \
\
inline StringTableEntry _get##name##AssetId(void) const { return m##name##Asset.getAssetId(); } \
Resource<TSShape> get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShapeResource(); else return ResourceManager::get().load( "" ); } \
TSShape* get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShape(); else return NULL; } \
AssetPtr<ShapeAsset> get##name##Asset(void) { return m##name##Asset; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false; } \
StringTableEntry get##name##File() { return m##name##Asset.notNull() ? m##name##Asset->getShapeFile() : ""; }
#define INITPERSISTFIELD_SHAPEASSET_REFACTOR(name, consoleClass, docs) \
#define INITPERSISTFIELD_SHAPEASSET_REFACTOR(name, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeShapeAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.)); \
addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, file docs.));
@ -414,7 +414,7 @@ public:
}; \
\
inline StringTableEntry _get##name##AssetId(const U32& index) const { return m##name##Asset[index].getAssetId(); } \
Resource<TSShape> get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShapeResource(); else return ResourceManager::get().load( "" ); } \
TSShape* get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShape(); else return NULL; } \
AssetPtr<ShapeAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}\
StringTableEntry get##name##File(const U32& idx) { return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getShapeFile() : ""; }
@ -472,7 +472,7 @@ public:
}; \
\
inline StringTableEntry _get##name##AssetId(const U32& index) const { return m##name##Asset[index].getAssetId(); } \
Resource<TSShape> get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShapeResource(); else return ResourceManager::get().load( "" ); } \
TSShape* get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShape(); else return NULL; } \
AssetPtr<ShapeAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}\
StringTableEntry get##name##File(const U32& idx) { return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getShapeFile() : ""; }

View file

@ -274,21 +274,20 @@ bool DebrisData::preload(bool server, String &errorStr)
if( server ) return true;
if (mShapeAsset.notNull())
if (getShape())
{
if (!getShape())
{
errorStr = String::ToString("DebrisData::load: Couldn't load shape \"%s\"", _getShapeAssetId());
return false;
}
else
{
TSShapeInstance* pDummy = new TSShapeInstance(getShape(), !server);
delete pDummy;
if (!server && !getShape()->preloadMaterialList(getShape().getPath()) && NetConnection::filesWereDownloaded())
if (!server && !getShape()->preloadMaterialList(getShapeFile()) && NetConnection::filesWereDownloaded())
return false;
}
}
else
{
errorStr = String::ToString("DebrisData::load: Couldn't load shape \"%s\"", _getShapeAssetId());
return false;
}
return true;
}

View file

@ -191,7 +191,7 @@ void RenderShapeExample::createShape()
// Attempt to preload the Materials for this shape
if ( isClientObject() &&
!getShape()->preloadMaterialList(getShape().getPath() ) &&
!getShape()->preloadMaterialList(getShapeFile()) &&
NetConnection::filesWereDownloaded() )
{
return;

View file

@ -896,7 +896,7 @@ bool ExplosionData::preload(bool server, String &errorStr)
}
}
if (mExplosionShapeAsset.notNull()) {
if (getExplosionShape()) {
// Resolve animations
explosionAnimation = getExplosionShape()->findSequence("ambient");

View file

@ -889,7 +889,7 @@ void GroundCover::_initShapes()
if ( mShapeAsset[i].isNull() || getShape(i) == nullptr)
continue;
if ( isClientObject() && !getShape(i)->preloadMaterialList(getShape(i).getPath()) && NetConnection::filesWereDownloaded() )
if ( isClientObject() && !getShape(i)->preloadMaterialList(getShapeFile(i)) && NetConnection::filesWereDownloaded() )
{
Con::warnf( "GroundCover::_initShapes() material preload failed for shape: %s", _getShapeAssetId(i));
continue;

View file

@ -345,7 +345,7 @@ bool GuiObjectView::setObjectModel( const String& modelName )
return false;
}
if (!getModel()->preloadMaterialList(getModel().getPath())) return false;
if (!getModel()->preloadMaterialList(getModelFile())) return false;
// Instantiate it.
@ -398,7 +398,7 @@ bool GuiObjectView::setMountedObject( const String& modelName )
return false;
}
if (!getMountedModel()->preloadMaterialList(getMountedModel().getPath())) return false;
if (!getMountedModel()->preloadMaterialList(getMountedModelFile())) return false;
mMountedModelInstance = new TSShapeInstance(getMountedModel(), true);
mMountedModelInstance->resetMaterialList();

View file

@ -274,10 +274,10 @@ class GuiObjectView : public GuiTSCtrl, protected AssetPtrCallback
protected:
void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
{
if (mModelAsset.notNull())
if (getModel())
setObjectModel(_getModelAssetId());
if (mMountedModelAsset.notNull())
if (getMountedModel())
setMountedObject(_getMountedModelAssetId());
}
};

View file

@ -97,7 +97,7 @@ bool PhysicsDebrisData::preload( bool server, String &errorStr )
if ( server ) return true;
if ( mShapeAsset.notNull() )
if ( getShape() )
{
// Create a dummy shape to force the generation of shaders and materials
// during the level load and not during gameplay.

View file

@ -285,16 +285,15 @@ bool PhysicsShapeData::preload( bool server, String &errorBuffer )
bool shapeError = false;
if (mShapeAsset.notNull())
if (getShape())
{
if (bool(getShape()) == false)
{
errorBuffer = String::ToString("PhysicsShapeData: Couldn't load shape \"%s\"", _getShapeAssetId());
return false;
}
if (!server && !getShape()->preloadMaterialList(getShape().getPath()) && NetConnection::filesWereDownloaded())
if (!server && !getShape()->preloadMaterialList(getShapeFile()) && NetConnection::filesWereDownloaded())
shapeError = true;
}
else
{
errorBuffer = String::ToString("PhysicsShapeData: Couldn't load shape \"%s\"", _getShapeAssetId());
return false;
}
// Prepare the shared physics collision shape.

View file

@ -615,18 +615,18 @@ bool PlayerData::preload(bool server, String &errorStr)
return false;
}
if (!server && !getShapeFP(i)->preloadMaterialList(getShapeFP(i).getPath()) && NetConnection::filesWereDownloaded())
if (!server && !getShapeFP(i)->preloadMaterialList(getShapeFPFile(i)) && NetConnection::filesWereDownloaded())
shapeError = true;
if (computeCRC)
{
Con::printf("Validation required for mounted image %d shape: %s", i, _getShapeFPAssetId(i));
Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode(getShapeFP(i).getPath());
Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode(getShapeFPFile(i));
if (!fileRef)
{
errorStr = String::ToString("PlayerData: Mounted image %d loading failed, shape \"%s\" is not found.", i, getShapeFP(i).getPath().getFullPath().c_str());
errorStr = String::ToString("PlayerData: Mounted image %d loading failed, shape \"%s\" is not found.", i, getShapeFPFile(i));
return false;
}

View file

@ -381,22 +381,18 @@ bool ProjectileData::preload(bool server, String &errorStr)
Con::errorf(ConsoleLogEntry::General, "ProjectileData::preload: Invalid packet, bad datablockid(lightDesc): %d", lightDescId);
}
if (mProjectileShapeAsset.notNull())
if (getProjectileShape())
{
//If we've got a shapeAsset assigned for our projectile, but we failed to load the shape data itself, report the error
if (!getProjectileShape())
{
errorStr = String::ToString("ProjectileData::load: Couldn't load shape \"%s\"", _getProjectileShapeAssetId());
return false;
}
else
{
activateSeq = getProjectileShape()->findSequence("activate");
maintainSeq = getProjectileShape()->findSequence("maintain");
activateSeq = getProjectileShape()->findSequence("activate");
maintainSeq = getProjectileShape()->findSequence("maintain");
TSShapeInstance* pDummy = new TSShapeInstance(getProjectileShape(), !server);
delete pDummy;
}
TSShapeInstance* pDummy = new TSShapeInstance(getProjectileShape(), !server);
delete pDummy;
}
else
{
errorStr = String::ToString("ProjectileData::load: Couldn't load shape \"%s\"", _getProjectileShapeAssetId());
return false;
}
return true;

View file

@ -343,7 +343,7 @@ bool ShapeBaseData::preload(bool server, String &errorStr)
"ShapeBaseData::preload: invalid debris data");
}
if(mDebrisShapeAsset.notNull())
if(getDebrisShape())
{
TSShapeInstance* pDummy = new TSShapeInstance(getDebrisShape(), !server);
delete pDummy;
@ -351,12 +351,13 @@ bool ShapeBaseData::preload(bool server, String &errorStr)
}
S32 i;
if (mShapeAsset.notNull())
if (getShape())
{
//mShapeAsset->load();
U32 assetStatus = ShapeAsset::getAssetErrCode(mShapeAsset);
if (assetStatus == AssetBase::Ok || assetStatus == AssetBase::UsingFallback)
{
if (!server && !getShape()->preloadMaterialList(getShape().getPath()) && NetConnection::filesWereDownloaded())
if (!server && !getShape()->preloadMaterialList(getShapeFile()) && NetConnection::filesWereDownloaded())
shapeError = true;
if (computeCRC)

View file

@ -461,7 +461,7 @@ bool ShapeBaseImageData::preload(bool server, String &errorStr)
{
Con::printf("Validation required for shape asset: %s", mShapeAsset[i]->getAssetId());
Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode(getShape(i).getPath());
Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode(getShapeFile(i));
if (!fileRef)
{

View file

@ -390,16 +390,10 @@ bool TSStatic::_createShape()
mAmbientThread = NULL;
//mShape = NULL;
if (mShapeAsset.notNull())
if (getShape())
{
if (!getShape())
{
Con::errorf("TSStatic::_createShape() - Shape Asset %s had no valid shape!", mShapeAsset.getAssetId());
return false;
}
if (isClientObject() &&
!getShape()->preloadMaterialList(getShape().getPath()) &&
!getShape()->preloadMaterialList(getShapeFile()) &&
NetConnection::filesWereDownloaded())
return false;
@ -440,6 +434,11 @@ bool TSStatic::_createShape()
Sim::findObject(cubeDescId, reflectorDesc);
}
}
else
{
Con::errorf("TSStatic::_createShape() - Shape Asset %s had no valid shape!", mShapeAsset.getAssetId());
return false;
}
//Set up the material slot vars for easy manipulation
/*S32 materialCount = mShape->materialList->getMaterialNameList().size(); //mMeshAsset->getMaterialCount();

View file

@ -139,7 +139,7 @@ public:
*/
// variables set on preload:
Resource<TSShape> projectileShape;
TSShape* projectileShape;
/*
S32 activateSeq;
S32 maintainSeq;

View file

@ -127,14 +127,8 @@ bool afxModelData::preload(bool server, String &errorStr)
if (server)
return true;
if (mShapeAsset.notNull())
if (getShape())
{
if (!getShape())
{
errorStr = String::ToString("afxModelData::load: Failed to load shape \"%s\"", _getShapeAssetId());
return false;
}
// just parse up the string and collect the remappings in txr_tag_remappings.
if (remap_txr_tags != ST_NULLSTRING)
{
@ -167,7 +161,11 @@ bool afxModelData::preload(bool server, String &errorStr)
delete pDummy;
}
}
else
{
errorStr = String::ToString("afxModelData::load: Failed to load shape \"%s\"", _getShapeAssetId());
return false;
}
return true;
}

View file

@ -143,7 +143,7 @@ public:
return theSignal;
}
Resource<TSShape> mShape;
TSShape* mShape;
protected:
void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override

View file

@ -127,7 +127,7 @@ void TSForestItemData::_loadShape()
return;
if ( mIsClientObject &&
!mShape->preloadMaterialList(mShape.getPath()) )
!mShape->preloadMaterialList(getShapeFile()) )
return;
// Lets add an autobillboard detail if don't have one.
@ -177,7 +177,7 @@ void TSForestItemData::_checkLastDetail()
// TODO: Expose some real parameters to the datablock maybe?
if ( detail->subShapeNum != -1 )
{
mShape->addImposter(mShape.getPath(), 10, 4, 0, 0, 256, 0, 0);
mShape->addImposter(getShapeFile(), 10, 4, 0, 0, 256, 0, 0);
// HACK: If i don't do this it crashes!
while ( mShape->detailCollisionAccelerators.size() < mShape->details.size() )