variation on #387 that also introduces errorcodes

This commit is contained in:
AzaezelX 2020-12-01 19:16:36 -06:00
parent 80eb4ab2ba
commit 220771d2fe
4 changed files with 123 additions and 23 deletions

View file

@ -119,6 +119,7 @@ ShapeAsset::ShapeAsset()
mConstructorFileName = StringTable->EmptyString(); mConstructorFileName = StringTable->EmptyString();
mFilePath = StringTable->EmptyString(); mFilePath = StringTable->EmptyString();
mConstructorFilePath = StringTable->EmptyString(); mConstructorFilePath = StringTable->EmptyString();
mLoadedState = AssetErrCode::NotLoaded;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -264,7 +265,8 @@ bool ShapeAsset::loadShape()
if (!mShape) if (!mShape)
{ {
Con::errorf("StaticMesh::updateShape : failed to load shape file!"); Con::errorf("ShapeAsset::loadShape : failed to load shape file!");
mLoadedState = BadFileReference;
return false; //if it failed to load, bail out return false; //if it failed to load, bail out
} }
@ -280,8 +282,10 @@ bool ShapeAsset::loadShape()
if (!mShape->addSequence(srcPath, srcName, srcName, if (!mShape->addSequence(srcPath, srcName, srcName,
mAnimationAssets[i]->getStartFrame(), mAnimationAssets[i]->getEndFrame(), mAnimationAssets[i]->getPadRotation(), mAnimationAssets[i]->getPadTransforms())) mAnimationAssets[i]->getStartFrame(), mAnimationAssets[i]->getEndFrame(), mAnimationAssets[i]->getPadRotation(), mAnimationAssets[i]->getPadTransforms()))
{
mLoadedState = MissingAnimatons;
return false; return false;
}
if (mAnimationAssets[i]->isBlend()) if (mAnimationAssets[i]->isBlend())
hasBlends = true; hasBlends = true;
} }
@ -300,14 +304,20 @@ bool ShapeAsset::loadShape()
if (blendAnimAsset.isNull()) if (blendAnimAsset.isNull())
{ {
Con::errorf("ShapeAsset::initializeAsset - Unable to acquire reference animation asset %s for asset %s to blend!", mAnimationAssets[i]->getBlendAnimationName(), mAnimationAssets[i]->getAssetName()); Con::errorf("ShapeAsset::initializeAsset - Unable to acquire reference animation asset %s for asset %s to blend!", mAnimationAssets[i]->getBlendAnimationName(), mAnimationAssets[i]->getAssetName());
return false; {
mLoadedState = MissingAnimatons;
return false;
}
} }
String refAnimName = blendAnimAsset->getAnimationName(); String refAnimName = blendAnimAsset->getAnimationName();
if (!mShape->setSequenceBlend(mAnimationAssets[i]->getAnimationName(), true, blendAnimAsset->getAnimationName(), mAnimationAssets[i]->getBlendFrame())) if (!mShape->setSequenceBlend(mAnimationAssets[i]->getAnimationName(), true, blendAnimAsset->getAnimationName(), mAnimationAssets[i]->getBlendFrame()))
{ {
Con::errorf("ShapeAnimationAsset::initializeAsset - Unable to set animation clip %s for asset %s to blend!", mAnimationAssets[i]->getAnimationName(), mAnimationAssets[i]->getAssetName()); Con::errorf("ShapeAnimationAsset::initializeAsset - Unable to set animation clip %s for asset %s to blend!", mAnimationAssets[i]->getAnimationName(), mAnimationAssets[i]->getAssetName());
return false; {
mLoadedState = MissingAnimatons;
return false;
}
} }
} }
} }
@ -315,6 +325,7 @@ bool ShapeAsset::loadShape()
mChangeSignal.trigger(); mChangeSignal.trigger();
mLoadedState = Ok;
return true; return true;
} }
@ -410,21 +421,21 @@ StringTableEntry ShapeAsset::getAssetIdByFilename(StringTableEntry fileName)
return shapeAssetId; return shapeAssetId;
} }
bool ShapeAsset::getAssetById(StringTableEntry assetId, AssetPtr<ShapeAsset>* shapeAsset) U32 ShapeAsset::getAssetById(StringTableEntry assetId, AssetPtr<ShapeAsset>* shapeAsset)
{ {
(*shapeAsset) = assetId; (*shapeAsset) = assetId;
if (!shapeAsset->isNull()) if ((*shapeAsset))
return true; return (*shapeAsset)->mLoadedState;
//Didn't work, so have us fall back to a placeholder asset //Didn't work, so have us fall back to a placeholder asset
StringTableEntry noShapeId = StringTable->insert("Core_Rendering:noshape"); StringTableEntry noShapeId = StringTable->insert("Core_Rendering:noshape");
shapeAsset->setAssetId(noShapeId); shapeAsset->setAssetId(noShapeId);
(*shapeAsset)->mLoadedState = AssetErrCode::UsingFallback;
if (shapeAsset->notNull())
return AssetErrCode::UsingFallback;
if (!shapeAsset->isNull()) return AssetErrCode::Failed;
return true;
return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -503,6 +514,7 @@ DefineEngineMethod(ShapeAsset, getAnimation, ShapeAnimationAsset*, (S32 index),
// GuiInspectorTypeAssetId // GuiInspectorTypeAssetId
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifdef TORQUE_TOOLS
IMPLEMENT_CONOBJECT(GuiInspectorTypeShapeAssetPtr); IMPLEMENT_CONOBJECT(GuiInspectorTypeShapeAssetPtr);
ConsoleDocClass(GuiInspectorTypeShapeAssetPtr, ConsoleDocClass(GuiInspectorTypeShapeAssetPtr,
@ -596,6 +608,8 @@ void GuiInspectorTypeShapeAssetId::consoleInit()
ConsoleBaseType::getType(TypeShapeAssetId)->setInspectorFieldType("GuiInspectorTypeShapeAssetId"); ConsoleBaseType::getType(TypeShapeAssetId)->setInspectorFieldType("GuiInspectorTypeShapeAssetId");
} }
#endif
DefineEngineMethod(ShapeAsset, getShapeFile, const char*, (), , DefineEngineMethod(ShapeAsset, getShapeFile, const char*, (), ,
"Creates a new script asset using the targetFilePath.\n" "Creates a new script asset using the targetFilePath.\n"
"@return The bool result of calling exec") "@return The bool result of calling exec")

View file

@ -54,7 +54,9 @@
#include "ShapeAnimationAsset.h" #include "ShapeAnimationAsset.h"
#endif #endif
#ifdef TORQUE_TOOLS
#include "gui/editor/guiInspectorTypes.h" #include "gui/editor/guiInspectorTypes.h"
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class ShapeAsset : public AssetBase class ShapeAsset : public AssetBase
@ -81,6 +83,13 @@ protected:
ShapeAssetChanged mChangeSignal; ShapeAssetChanged mChangeSignal;
public: public:
enum ShapeAssetErrCode
{
TooManyVerts = AssetErrCode::Extended,
TooManyBones,
MissingAnimatons
};
ShapeAsset(); ShapeAsset();
virtual ~ShapeAsset(); virtual ~ShapeAsset();
@ -96,6 +105,7 @@ public:
DECLARE_CONOBJECT(ShapeAsset); DECLARE_CONOBJECT(ShapeAsset);
bool loadShape(); bool loadShape();
U32 mLoadedState;
TSShape* getShape() { return mShape; } TSShape* getShape() { return mShape; }
@ -138,8 +148,9 @@ public:
inline StringTableEntry getShapeConstructorFilePath(void) const { return mConstructorFilePath; }; inline StringTableEntry getShapeConstructorFilePath(void) const { return mConstructorFilePath; };
static bool getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAsset>* shapeAsset); static bool getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAsset>* shapeAsset);
static StringTableEntry getAssetIdByFilename(StringTableEntry fileName); static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
static bool getAssetById(StringTableEntry assetId, AssetPtr<ShapeAsset>* shapeAsset); static U32 getAssetById(StringTableEntry assetId, AssetPtr<ShapeAsset>* shapeAsset);
static StringTableEntry getNoShapeAssetId() { return StringTable->insert("Core_Rendering:noshape"); } static StringTableEntry getNoShapeAssetId() { return StringTable->insert("Core_Rendering:noshape"); }
@ -154,6 +165,7 @@ protected:
}; };
#ifdef TORQUE_TOOLS
DefineConsoleType(TypeShapeAssetPtr, S32) DefineConsoleType(TypeShapeAssetPtr, S32)
DefineConsoleType(TypeShapeAssetId, String) DefineConsoleType(TypeShapeAssetId, String)
@ -182,6 +194,72 @@ public:
DECLARE_CONOBJECT(GuiInspectorTypeShapeAssetId); DECLARE_CONOBJECT(GuiInspectorTypeShapeAssetId);
static void consoleInit(); static void consoleInit();
}; };
#endif
#define assetText(x,suff) std::string(std::string(#x) + std::string(#suff)).c_str()
#define initShapeAsset(name) m##name##Filename = StringTable->EmptyString(); m##name##AssetId = StringTable->EmptyString(); m##name##Asset = NULL;
#define bindShapeAsset(name) if (m##name##AssetId != StringTable->EmptyString()) m##name##Asset = m##name##AssetId;
#define scriptBindShapeAsset(name, consoleClass, docs) addProtectedField(assetText(name, File), TypeShapeFilename, Offset(m##name##Filename, consoleClass), consoleClass::_set##name##Filename, & defaultProtectedGetFn, assetText(name, docs)); \
addProtectedField(assetText(name, Asset), TypeShapeAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & defaultProtectedGetFn, assetText(name, asset reference.));
#define DECLARE_SHAPEASSET(className,name) protected: \
StringTableEntry m##name##Filename;\
StringTableEntry m##name##AssetId;\
AssetPtr<ShapeAsset> m##name##Asset;\
public: \
const StringTableEntry& get##name() const { return m##name##Filename; }\
void set##name(FileName _in) { m##name##Filename = _in; }\
const AssetPtr<ShapeAsset> & get##name##Asset() const { return m##name##Asset; }\
void set##name##Asset(AssetPtr<ShapeAsset>_in) { m##name##Asset = _in; }\
static bool _set##name##Filename(void* obj, const char* index, const char* data)\
{\
className* shape = static_cast<className*>(obj);\
\
StringTableEntry assetId = ShapeAsset::getAssetIdByFilename(StringTable->insert(data));\
if (assetId != StringTable->EmptyString())\
{\
if (shape->_set##name##Asset(obj, index, assetId))\
{\
if (assetId == StringTable->insert("Core_Rendering:noShape"))\
{\
shape->m##name##Filename = data;\
shape->m##name##AssetId = StringTable->EmptyString();\
\
return true;\
}\
else\
{\
shape->m##name##AssetId = assetId;\
shape->m##name##Filename = StringTable->EmptyString();\
\
return false;\
}\
}\
}\
else\
{\
shape->m##name##Asset = StringTable->EmptyString();\
}\
\
return true;\
}\
\
static bool _set##name##Asset(void* obj, const char* index, const char* data)\
{\
className* shape = static_cast<className*>(obj);\
shape->m##name##AssetId = StringTable->insert(data);\
if (ShapeAsset::getAssetById(shape->m##name##AssetId, &shape->m##name##Asset))\
{\
if (shape->m##name##Asset.getAssetId() != StringTable->insert("Core_Rendering:noShape"))\
shape->m##name##Filename = StringTable->EmptyString();\
\
shape->setMaskBits(-1);\
return true;\
}\
return false;\
}
#endif #endif

View file

@ -361,20 +361,15 @@ bool ShapeBaseData::preload(bool server, String &errorStr)
} }
//Legacy catch //Legacy catch
if (shapeAssetId == StringTable->EmptyString() && shapeName != StringTable->EmptyString()) if (shapeName != StringTable->EmptyString())
{ {
StringTableEntry assetId = ShapeAsset::getAssetIdByFilename(shapeName); shapeAssetId = ShapeAsset::getAssetIdByFilename(shapeName);
if (assetId != StringTable->EmptyString())
{
shapeAssetId = assetId;
}
} }
U32 assetState = ShapeAsset::getAssetById(shapeAssetId, &shapeAsset);
if (ShapeAsset::getAssetById(shapeAssetId, &shapeAsset)) if (AssetErrCode::Failed != assetState)
{ {
//Special exception case. If we've defaulted to the 'no shape' mesh, don't save it out, we'll retain the original ids/paths so it doesn't break //only clear the legacy direct file reference if everything checks out fully
//the TSStatic if (assetState == AssetErrCode::Ok)
if (shapeAsset.getAssetId() != StringTable->insert("Core_Rendering:noshape"))
{ {
shapeName = StringTable->EmptyString(); shapeName = StringTable->EmptyString();
} }

View file

@ -56,6 +56,19 @@ extern StringTableEntry assetAutoUnloadField;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
enum AssetErrCode
{
Failed,
Ok,
NotLoaded,
BadFileReference,
InvalidFormat,
DependencyNotFound,
FileTooLarge,
UsingFallback,
Extended
};
class AssetBase : public SimObject class AssetBase : public SimObject
{ {
friend class AssetManager; friend class AssetManager;