Merge pull request #1340 from marauder2k9-torque/ImageAsset-NamedTexTarget

NamedTexTargets as ImageAssets
This commit is contained in:
Brian Roberts 2024-12-23 03:12:22 -06:00 committed by GitHub
commit 69fa4b389f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 168 additions and 53 deletions

View file

@ -274,6 +274,20 @@ U32 ImageAsset::load()
if (mLoadedState == AssetErrCode::Ok) return mLoadedState;
if (mImagePath)
{
// this is a target.
if (mImageFileName[0] == '$' || mImageFileName[0] == '#')
{
NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1);
if (namedTarget) {
mLoadedState = Ok;
mIsValidImage = true;
return mLoadedState;
}
else
{
Con::errorf("ImageAsset::initializeAsset: Attempted find named target %s failed.", mImageFileName);
}
}
if (!Torque::FS::IsFile(mImagePath))
{
Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFileName);
@ -295,12 +309,26 @@ void ImageAsset::initializeAsset()
{
ResourceManager::get().getChangedSignal().notify(this, &ImageAsset::_onResourceChanged);
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
if (mImageFileName[0] != '$' && mImageFileName[0] != '#')
{
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
}
else
{
mImagePath = mImageFileName;
}
}
void ImageAsset::onAssetRefresh()
{
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
if (mImageFileName[0] != '$' && mImageFileName[0] != '#')
{
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
}
else
{
mImagePath = mImageFileName;
}
AssetManager::typeAssetDependsOnHash::Iterator assetDependenciesItr = mpOwningAssetManager->getDependedOnAssets()->find(mpAssetDefinition->mAssetId);
// Iterate all dependencies.
@ -334,6 +362,7 @@ void ImageAsset::setImageFileName(const char* pScriptFile)
GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
{
load();
if (mResourceMap.contains(requestedProfile))
{
mLoadedState = Ok;
@ -341,21 +370,35 @@ GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
}
else
{
//If we don't have an existing map case to the requested format, we'll just create it and insert it in
GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, requestedProfile);
if (newTex)
// this is a target.
if (mImageFileName[0] == '$' || mImageFileName[0] == '#')
{
mResourceMap.insert(requestedProfile, newTex);
mLoadedState = Ok;
return newTex;
NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1);
if (namedTarget.isValid() && namedTarget->getTexture())
{
mNamedTarget = namedTarget;
mIsValidImage = true;
mResourceMap.insert(requestedProfile, mNamedTarget->getTexture());
mChangeSignal.trigger();
return mNamedTarget->getTexture();
}
}
else
mLoadedState = BadFileReference;
{
//If we don't have an existing map case to the requested format, we'll just create it and insert it in
GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, requestedProfile);
if (newTex)
{
mResourceMap.insert(requestedProfile, newTex);
mLoadedState = Ok;
return newTex;
}
else
mLoadedState = BadFileReference;
}
}
//if (mTexture.isValid())
// return mTexture;
return nullptr;
}