mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
asset load refactor
genral load method, now returns loadedstate across the board
This commit is contained in:
parent
11ad16583e
commit
1cf754dbca
|
|
@ -207,8 +207,7 @@ U32 ImageAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsse
|
|||
{
|
||||
//acquire and bind the asset, and return it out
|
||||
imageAsset->setAssetId(query.mAssetList[0]);
|
||||
(*imageAsset)->loadImage();
|
||||
return (*imageAsset)->mLoadedState;
|
||||
return (*imageAsset)->load();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -240,8 +239,7 @@ U32 ImageAsset::getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* ima
|
|||
|
||||
if (imageAsset->notNull())
|
||||
{
|
||||
(*imageAsset)->loadImage();
|
||||
return (*imageAsset)->mLoadedState;
|
||||
return (*imageAsset)->load();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -253,7 +251,6 @@ U32 ImageAsset::getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* ima
|
|||
//handle fallback not being loaded itself
|
||||
if ((*imageAsset)->mLoadedState == BadFileReference)
|
||||
{
|
||||
(*imageAsset)->loadImage();
|
||||
Con::warnf("ImageAsset::getAssetById - Finding of asset with id %s failed, and fallback asset reported error of Bad File Reference.", assetId);
|
||||
return AssetErrCode::BadFileReference;
|
||||
}
|
||||
|
|
@ -272,25 +269,26 @@ void ImageAsset::copyTo(SimObject* object)
|
|||
Parent::copyTo(object);
|
||||
}
|
||||
|
||||
void ImageAsset::loadImage()
|
||||
U32 ImageAsset::load()
|
||||
{
|
||||
if (mLoadedState == AssetErrCode::Ok) return;
|
||||
if (mLoadedState == AssetErrCode::Ok) return mLoadedState;
|
||||
if (mImagePath)
|
||||
{
|
||||
if (!Torque::FS::IsFile(mImagePath))
|
||||
{
|
||||
Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFileName);
|
||||
mLoadedState = BadFileReference;
|
||||
return;
|
||||
return mLoadedState;
|
||||
}
|
||||
|
||||
mLoadedState = Ok;
|
||||
mIsValidImage = true;
|
||||
return;
|
||||
return mLoadedState;
|
||||
}
|
||||
mLoadedState = BadFileReference;
|
||||
|
||||
mIsValidImage = false;
|
||||
return mLoadedState;
|
||||
}
|
||||
|
||||
void ImageAsset::initializeAsset()
|
||||
|
|
@ -327,11 +325,6 @@ void ImageAsset::setImageFileName(const char* pScriptFile)
|
|||
refreshAsset();
|
||||
}
|
||||
|
||||
const GBitmap& ImageAsset::getImage()
|
||||
{
|
||||
return GBitmap(); //TODO fix this
|
||||
}
|
||||
|
||||
GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
|
||||
{
|
||||
if (mResourceMap.contains(requestedProfile))
|
||||
|
|
|
|||
|
|
@ -136,7 +136,6 @@ public:
|
|||
|
||||
bool isValid() { return mIsValidImage; }
|
||||
|
||||
const GBitmap& getImage();
|
||||
GFXTexHandle getTexture(GFXTextureProfile* requestedProfile);
|
||||
|
||||
StringTableEntry getImageInfo();
|
||||
|
|
@ -152,14 +151,14 @@ public:
|
|||
static U32 getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset);
|
||||
static U32 getAssetById(String assetId, AssetPtr<ImageAsset>* imageAsset) { return getAssetById(assetId.c_str(), imageAsset); };
|
||||
|
||||
U32 load();
|
||||
|
||||
protected:
|
||||
virtual void initializeAsset(void);
|
||||
virtual void onAssetRefresh(void);
|
||||
|
||||
static bool setImageFileName(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setImageFileName(data); return false; }
|
||||
static StringTableEntry getImageFileName(void* obj, StringTableEntry data) { return static_cast<ImageAsset*>(obj)->getImageFileName(); }
|
||||
|
||||
void loadImage();
|
||||
};
|
||||
|
||||
DefineConsoleType(TypeImageAssetPtr, ImageAsset)
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ void MaterialAsset::initializeAsset()
|
|||
}
|
||||
}
|
||||
|
||||
loadMaterial();
|
||||
load();
|
||||
}
|
||||
|
||||
void MaterialAsset::onAssetRefresh()
|
||||
|
|
@ -236,7 +236,7 @@ void MaterialAsset::onAssetRefresh()
|
|||
Con::setVariable("$Con::redefineBehavior", redefineBehaviorPrev.c_str());
|
||||
}
|
||||
|
||||
loadMaterial();
|
||||
load();
|
||||
}
|
||||
|
||||
void MaterialAsset::setScriptFile(const char* pScriptFile)
|
||||
|
|
@ -255,7 +255,7 @@ void MaterialAsset::setScriptFile(const char* pScriptFile)
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MaterialAsset::loadMaterial()
|
||||
U32 MaterialAsset::load()
|
||||
{
|
||||
if (mMaterialDefinition)
|
||||
{
|
||||
|
|
@ -274,7 +274,7 @@ void MaterialAsset::loadMaterial()
|
|||
mLoadedState = Ok;
|
||||
mMaterialDefinition->setInternalName(getAssetId());
|
||||
mMaterialDefinition->reload();
|
||||
return;
|
||||
return mLoadedState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -286,7 +286,7 @@ void MaterialAsset::loadMaterial()
|
|||
{
|
||||
Con::errorf("MaterialAsset: Unable to find the Material %s", mMatDefinitionName);
|
||||
mLoadedState = BadFileReference;
|
||||
return;
|
||||
return mLoadedState;
|
||||
}
|
||||
|
||||
mMaterialDefinition = matDef;
|
||||
|
|
@ -294,10 +294,11 @@ void MaterialAsset::loadMaterial()
|
|||
mLoadedState = Ok;
|
||||
mMaterialDefinition->setInternalName(getAssetId());
|
||||
mMaterialDefinition->reload();
|
||||
return;
|
||||
return mLoadedState;
|
||||
}
|
||||
|
||||
mLoadedState = Failed;
|
||||
return mLoadedState;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public:
|
|||
static void initPersistFields();
|
||||
virtual void copyTo(SimObject* object);
|
||||
|
||||
void loadMaterial();
|
||||
U32 load();
|
||||
|
||||
StringTableEntry getMaterialDefinitionName() { return mMatDefinitionName; }
|
||||
SimObjectPtr<Material> getMaterialDefinition() { return mMaterialDefinition; }
|
||||
|
|
|
|||
|
|
@ -308,9 +308,9 @@ void ShapeAsset::_onResourceChanged(const Torque::Path &path)
|
|||
onAssetRefresh();
|
||||
}
|
||||
|
||||
bool ShapeAsset::loadShape()
|
||||
U32 ShapeAsset::load()
|
||||
{
|
||||
if (mLoadedState == AssetErrCode::Ok) return true;
|
||||
if (mLoadedState == AssetErrCode::Ok) return mLoadedState;
|
||||
|
||||
mMaterialAssets.clear();
|
||||
mMaterialAssetIds.clear();
|
||||
|
|
@ -357,7 +357,7 @@ bool ShapeAsset::loadShape()
|
|||
{
|
||||
Con::errorf("ShapeAsset::loadShape : failed to load shape file %s (%s)!", getAssetName(), mFilePath);
|
||||
mLoadedState = BadFileReference;
|
||||
return false; //if it failed to load, bail out
|
||||
return mLoadedState; //if it failed to load, bail out
|
||||
}
|
||||
// Construct billboards if not done already
|
||||
if (GFXDevice::devicePresent())
|
||||
|
|
@ -379,7 +379,7 @@ bool ShapeAsset::loadShape()
|
|||
mAnimationAssets[i]->getStartFrame(), mAnimationAssets[i]->getEndFrame(), mAnimationAssets[i]->getPadRotation(), mAnimationAssets[i]->getPadTransforms()))
|
||||
{
|
||||
mLoadedState = MissingAnimatons;
|
||||
return false;
|
||||
return mLoadedState;
|
||||
}
|
||||
if (mAnimationAssets[i]->isBlend())
|
||||
hasBlends = true;
|
||||
|
|
@ -402,7 +402,7 @@ bool ShapeAsset::loadShape()
|
|||
Con::errorf("ShapeAsset::initializeAsset - Unable to acquire reference animation asset %s for asset %s to blend!", mAnimationAssets[i]->getBlendAnimationName(), mAnimationAssets[i]->getAssetName());
|
||||
{
|
||||
mLoadedState = MissingAnimatons;
|
||||
return false;
|
||||
return mLoadedState;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -412,7 +412,7 @@ bool ShapeAsset::loadShape()
|
|||
Con::errorf("ShapeAnimationAsset::initializeAsset - Unable to set animation clip %s for asset %s to blend!", mAnimationAssets[i]->getAnimationName(), mAnimationAssets[i]->getAssetName());
|
||||
{
|
||||
mLoadedState = MissingAnimatons;
|
||||
return false;
|
||||
return mLoadedState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -422,7 +422,7 @@ bool ShapeAsset::loadShape()
|
|||
mChangeSignal.trigger();
|
||||
|
||||
mLoadedState = Ok;
|
||||
return true;
|
||||
return mLoadedState;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
@ -706,7 +706,7 @@ DefineEngineMethod(ShapeAsset, generateCachedPreviewImage, const char*, (S32 res
|
|||
"@param resolution Optional field for what resolution to bake the preview image at. Must be pow2\n"
|
||||
"@param overrideMaterialName Optional field for overriding the material used when rendering the shape for the bake.")
|
||||
{
|
||||
object->loadShape();
|
||||
object->load();
|
||||
return object->generateCachedPreviewImage(resolution, overrideMaterialName);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -132,11 +132,11 @@ public:
|
|||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(ShapeAsset);
|
||||
|
||||
bool loadShape();
|
||||
U32 load();
|
||||
|
||||
TSShape* getShape() { return mShape; }
|
||||
|
||||
Resource<TSShape> getShapeResource() { loadShape(); return mShape; }
|
||||
Resource<TSShape> getShapeResource() { load(); return mShape; }
|
||||
|
||||
void SplitSequencePathAndName(String& srcPath, String& srcName);
|
||||
StringTableEntry getShapeFileName() { return mFileName; }
|
||||
|
|
|
|||
|
|
@ -322,10 +322,6 @@ void SoundAsset::initializeAsset(void)
|
|||
|
||||
mSoundPath[i] = getOwned() ? expandAssetFilePath(mSoundFile[i]) : mSoundPath[i];
|
||||
}
|
||||
|
||||
//loadSound(slotCount);
|
||||
//mSoundPath = getOwned() ? expandAssetFilePath(mSoundFile) : mSoundPath;
|
||||
//loadSound();
|
||||
}
|
||||
|
||||
void SoundAsset::_onResourceChanged(const Torque::Path &path)
|
||||
|
|
@ -337,9 +333,6 @@ void SoundAsset::_onResourceChanged(const Torque::Path &path)
|
|||
return;
|
||||
}
|
||||
refreshAsset();
|
||||
|
||||
//loadSound(slotCount);
|
||||
//loadSound();
|
||||
}
|
||||
|
||||
void SoundAsset::onAssetRefresh(void)
|
||||
|
|
@ -354,16 +347,11 @@ void SoundAsset::onAssetRefresh(void)
|
|||
|
||||
mSoundPath[i] = getOwned() ? expandAssetFilePath(mSoundFile[i]) : mSoundPath[i];
|
||||
}
|
||||
|
||||
//loadSound(slotCount);
|
||||
//Update
|
||||
//mSoundPath = getOwned() ? expandAssetFilePath(mSoundFile) : mSoundPath;
|
||||
//loadSound();
|
||||
}
|
||||
|
||||
bool SoundAsset::loadSound()
|
||||
U32 SoundAsset::load()
|
||||
{
|
||||
if (mLoadedState == AssetErrCode::Ok) return true;
|
||||
if (mLoadedState == AssetErrCode::Ok) return mLoadedState;
|
||||
|
||||
// find out how many active slots we have.
|
||||
U32 numSlots = 0;
|
||||
|
|
@ -394,7 +382,7 @@ bool SoundAsset::loadSound()
|
|||
mSFXProfile[i].setDescription(NULL);
|
||||
mSFXProfile[i].setSoundFileName(StringTable->insert(StringTable->EmptyString()));
|
||||
mSFXProfile[i].setPreload(false);
|
||||
return false;
|
||||
return mLoadedState;
|
||||
}
|
||||
else
|
||||
{// = new SFXProfile(mProfileDesc, mSoundFile, mPreload);
|
||||
|
|
@ -427,7 +415,7 @@ bool SoundAsset::loadSound()
|
|||
mSFXProfile[0].setDescription(NULL);
|
||||
mSFXProfile[0].setSoundFileName(StringTable->insert(StringTable->EmptyString()));
|
||||
mSFXProfile[0].setPreload(false);
|
||||
return false;
|
||||
return mLoadedState;
|
||||
}
|
||||
else
|
||||
{// = new SFXProfile(mProfileDesc, mSoundFile, mPreload);
|
||||
|
|
@ -446,7 +434,7 @@ bool SoundAsset::loadSound()
|
|||
|
||||
mChangeSignal.trigger();
|
||||
mLoadedState = Ok;
|
||||
return true;
|
||||
return mLoadedState;
|
||||
}
|
||||
|
||||
StringTableEntry SoundAsset::getSoundFile(const char* pSoundFile, const U32 slotId)
|
||||
|
|
|
|||
|
|
@ -150,13 +150,13 @@ public:
|
|||
virtual void copyTo(SimObject* object);
|
||||
|
||||
//SFXResource* getSound() { return mSoundResource; }
|
||||
Resource<SFXResource> getSoundResource(const U32 slotId = 0) { loadSound(); return mSFXProfile[slotId].getResource(); }
|
||||
Resource<SFXResource> getSoundResource(const U32 slotId = 0) { load(); return mSFXProfile[slotId].getResource(); }
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(SoundAsset);
|
||||
|
||||
void setSoundFile(const char* pSoundFile, const U32 slotId = 0);
|
||||
bool loadSound();
|
||||
U32 load();
|
||||
StringTableEntry getSoundFile(const char* pSoundFile, const U32 slotId = 0);
|
||||
inline StringTableEntry getSoundPath(const U32 slotId = 0) const { return mSoundPath[slotId]; };
|
||||
SFXProfile* getSfxProfile(const U32 slotId = 0) { return &mSFXProfile[slotId]; }
|
||||
|
|
|
|||
|
|
@ -161,14 +161,14 @@ void TerrainAsset::initializeAsset()
|
|||
|
||||
mTerrainFilePath = getOwned() ? expandAssetFilePath(mTerrainFileName) : mTerrainFilePath;
|
||||
|
||||
loadTerrain();
|
||||
load();
|
||||
}
|
||||
|
||||
void TerrainAsset::onAssetRefresh()
|
||||
{
|
||||
mTerrainFilePath = getOwned() ? expandAssetFilePath(mTerrainFileName) : mTerrainFilePath;
|
||||
|
||||
loadTerrain();
|
||||
load();
|
||||
}
|
||||
|
||||
void TerrainAsset::setTerrainFileName(const char* pScriptFile)
|
||||
|
|
@ -189,10 +189,10 @@ void TerrainAsset::setTerrainFileName(const char* pScriptFile)
|
|||
refreshAsset();
|
||||
}
|
||||
|
||||
bool TerrainAsset::loadTerrain()
|
||||
U32 TerrainAsset::load()
|
||||
{
|
||||
if (!Torque::FS::IsFile(mTerrainFilePath))
|
||||
return false;
|
||||
return BadFileReference;
|
||||
|
||||
mTerrMaterialAssets.clear();
|
||||
mTerrMaterialAssetIds.clear();
|
||||
|
|
@ -229,9 +229,9 @@ bool TerrainAsset::loadTerrain()
|
|||
mTerrainFile = ResourceManager::get().load(mTerrainFilePath);
|
||||
|
||||
if (mTerrainFile)
|
||||
return true;
|
||||
return Ok;
|
||||
|
||||
return false;
|
||||
return BadFileReference;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public:
|
|||
|
||||
inline Resource<TerrainFile> getTerrainResource(void) const { return mTerrainFile; };
|
||||
|
||||
bool loadTerrain();
|
||||
U32 load();
|
||||
|
||||
static bool getAssetByFilename(StringTableEntry fileName, AssetPtr<TerrainAsset>* shapeAsset);
|
||||
static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ void TerrainMaterialAsset::initializeAsset()
|
|||
}
|
||||
}
|
||||
|
||||
loadMaterial();
|
||||
load();
|
||||
}
|
||||
|
||||
void TerrainMaterialAsset::onAssetRefresh()
|
||||
|
|
@ -232,7 +232,7 @@ void TerrainMaterialAsset::onAssetRefresh()
|
|||
Con::setVariable("$Con::redefineBehavior", redefineBehaviorPrev.c_str());
|
||||
}
|
||||
|
||||
loadMaterial();
|
||||
load();
|
||||
}
|
||||
|
||||
void TerrainMaterialAsset::setScriptFile(const char* pScriptFile)
|
||||
|
|
@ -251,7 +251,7 @@ void TerrainMaterialAsset::setScriptFile(const char* pScriptFile)
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void TerrainMaterialAsset::loadMaterial()
|
||||
U32 TerrainMaterialAsset::load()
|
||||
{
|
||||
if (mMaterialDefinition)
|
||||
mMaterialDefinition->safeDeleteObject();
|
||||
|
|
@ -287,7 +287,7 @@ void TerrainMaterialAsset::loadMaterial()
|
|||
}
|
||||
|
||||
if(mLoadedState == Ok)
|
||||
return;
|
||||
return mLoadedState;
|
||||
}
|
||||
else if ((mLoadedState == ScriptLoaded || mLoadedState == DefinitionAlreadyExists) && mMatDefinitionName != StringTable->EmptyString())
|
||||
{
|
||||
|
|
@ -296,17 +296,18 @@ void TerrainMaterialAsset::loadMaterial()
|
|||
{
|
||||
Con::errorf("TerrainMaterialAsset: Unable to find the Material %s", mMatDefinitionName);
|
||||
mLoadedState = BadFileReference;
|
||||
return;
|
||||
return mLoadedState;
|
||||
}
|
||||
|
||||
mMaterialDefinition = matDef;
|
||||
|
||||
mLoadedState = Ok;
|
||||
mMaterialDefinition->setInternalName(getAssetId());
|
||||
return;
|
||||
return mLoadedState;
|
||||
}
|
||||
|
||||
mLoadedState = Failed;
|
||||
return mLoadedState;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public:
|
|||
static void initPersistFields();
|
||||
virtual void copyTo(SimObject* object);
|
||||
|
||||
void loadMaterial();
|
||||
U32 load();
|
||||
|
||||
StringTableEntry getMaterialDefinitionName() { return mMatDefinitionName; }
|
||||
SimObjectPtr<TerrainMaterial> getMaterialDefinition() { return mMaterialDefinition; }
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public:
|
|||
return mErrCodeStrings[errCode];
|
||||
};
|
||||
U32 getStatus() { return mLoadedState; };
|
||||
|
||||
U32 load() { return NotLoaded; };
|
||||
AssetBase();
|
||||
virtual ~AssetBase();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue