mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-19 19:35:26 +00:00
Merge pull request #1340 from marauder2k9-torque/ImageAsset-NamedTexTarget
NamedTexTargets as ImageAssets
This commit is contained in:
commit
69fa4b389f
13 changed files with 168 additions and 53 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@
|
|||
#include "assetMacroHelpers.h"
|
||||
|
||||
#include "gfx/gfxDevice.h"
|
||||
|
||||
#ifndef _MATTEXTURETARGET_H_
|
||||
#include "materials/matTextureTarget.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class ImageAsset : public AssetBase
|
||||
{
|
||||
|
|
@ -95,6 +100,7 @@ public:
|
|||
protected:
|
||||
StringTableEntry mImageFileName;
|
||||
StringTableEntry mImagePath;
|
||||
NamedTexTargetRef mNamedTarget;
|
||||
|
||||
bool mIsValidImage;
|
||||
bool mUseMips;
|
||||
|
|
@ -205,7 +211,7 @@ public: \
|
|||
}\
|
||||
else if(_in[0] == '$' || _in[0] == '#')\
|
||||
{\
|
||||
m##name##Name = _in;\
|
||||
m##name##Name = _in;\
|
||||
m##name##AssetId = StringTable->EmptyString();\
|
||||
m##name##Asset = NULL;\
|
||||
m##name.free();\
|
||||
|
|
@ -250,7 +256,9 @@ public: \
|
|||
m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\
|
||||
}\
|
||||
\
|
||||
m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
|
||||
if (get##name()[0] != '$' && get##name()[0] != '#') {\
|
||||
m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
|
||||
}\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
|
|
@ -278,7 +286,10 @@ public: \
|
|||
const StringTableEntry get##name() const\
|
||||
{\
|
||||
if (m##name##Asset && (m##name##Asset->getImageFileName() != StringTable->EmptyString()))\
|
||||
return Platform::makeRelativePathName(m##name##Asset->getImagePath(), Platform::getMainDotCsDir());\
|
||||
if (m##name##Asset->getImageFileName()[0] == '#' || m##name##Asset->getImageFileName()[0] == '$')\
|
||||
return m##name##Asset->getImageFileName();\
|
||||
else\
|
||||
return Platform::makeRelativePathName(m##name##Asset->getImagePath(), Platform::getMainDotCsDir());\
|
||||
else if (m##name##AssetId != StringTable->EmptyString())\
|
||||
return m##name##AssetId;\
|
||||
else if (m##name##Name != StringTable->EmptyString())\
|
||||
|
|
@ -288,6 +299,8 @@ public: \
|
|||
}\
|
||||
GFXTexHandle get##name##Resource() \
|
||||
{\
|
||||
if (m##name##Asset && (m##name##Asset->getImageFileName() != StringTable->EmptyString()))\
|
||||
return m##name##Asset->getTexture(m##name##Profile);\
|
||||
return m##name;\
|
||||
}\
|
||||
bool name##Valid() {return (get##name() != StringTable->EmptyString() && m##name##Asset->getStatus() == AssetBase::Ok); }
|
||||
|
|
@ -323,7 +336,7 @@ if (m##name##AssetId != StringTable->EmptyString())\
|
|||
#pragma region Arrayed Asset Macros
|
||||
|
||||
//Arrayed Assets
|
||||
#define DECLARE_IMAGEASSET_ARRAY(className, name, max) public: \
|
||||
#define DECLARE_IMAGEASSET_ARRAY(className, name, max, changeFunc) public: \
|
||||
static const U32 sm##name##Count = max;\
|
||||
GFXTexHandle m##name[max];\
|
||||
StringTableEntry m##name##Name[max]; \
|
||||
|
|
@ -353,7 +366,7 @@ public: \
|
|||
}\
|
||||
else if(_in[0] == '$' || _in[0] == '#')\
|
||||
{\
|
||||
m##name##Name[index] = _in;\
|
||||
m##name##Name[index] = _in;\
|
||||
m##name##AssetId[index] = StringTable->EmptyString();\
|
||||
m##name##Asset[index] = NULL;\
|
||||
m##name[index].free();\
|
||||
|
|
@ -393,7 +406,9 @@ public: \
|
|||
}\
|
||||
if (get##name(index) != StringTable->EmptyString() && m##name##Name[index] != StringTable->insert("texhandle"))\
|
||||
{\
|
||||
m##name[index].set(get##name(index), m##name##Profile[index], avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
|
||||
m##name##Asset[index]->getChangedSignal().notify(this, &className::changeFunc);\
|
||||
if (get##name(index)[0] != '$' && get##name(index)[0] != '#')\
|
||||
m##name[index].set(get##name(index), m##name##Profile[index], avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
|
|
@ -421,7 +436,10 @@ public: \
|
|||
const StringTableEntry get##name(const U32& index) const\
|
||||
{\
|
||||
if (m##name##Asset[index] && (m##name##Asset[index]->getImageFileName() != StringTable->EmptyString()))\
|
||||
return Platform::makeRelativePathName(m##name##Asset[index]->getImagePath(), Platform::getMainDotCsDir());\
|
||||
if (m##name##Asset[index]->getImageFileName()[0] == '#' || m##name##Asset[index]->getImageFileName()[0] == '$')\
|
||||
return m##name##Asset[index]->getImageFileName();\
|
||||
else\
|
||||
return Platform::makeRelativePathName(m##name##Asset[index]->getImagePath(), Platform::getMainDotCsDir());\
|
||||
else if (m##name##AssetId[index] != StringTable->EmptyString())\
|
||||
return m##name##AssetId[index];\
|
||||
else if (m##name##Name[index] != StringTable->EmptyString())\
|
||||
|
|
@ -438,6 +456,8 @@ public: \
|
|||
{\
|
||||
if(index >= sm##name##Count || index < 0)\
|
||||
return nullptr;\
|
||||
if (m##name##Asset[index] && (m##name##Asset[index]->getImageFileName() != StringTable->EmptyString()))\
|
||||
return m##name##Asset[index]->getTexture(m##name##Profile[index]);\
|
||||
return m##name[index];\
|
||||
}\
|
||||
bool name##Valid(const U32& id) {return (get##name(id) != StringTable->EmptyString() && m##name##Asset[id]->getStatus() == AssetBase::Ok); }
|
||||
|
|
|
|||
|
|
@ -122,8 +122,9 @@ public:
|
|||
F32 times[ NUM_TIME_KEYS ];
|
||||
LinearColorF colors[ NUM_TIME_KEYS ];
|
||||
|
||||
DECLARE_IMAGEASSET_ARRAY(SplashData, Texture, NUM_TEX);
|
||||
DECLARE_IMAGEASSET_ARRAY(SplashData, Texture, NUM_TEX, onTextureChanged);
|
||||
DECLARE_IMAGEASSET_ARRAY_SETGET(SplashData, Texture)
|
||||
void onTextureChanged() {}
|
||||
|
||||
ExplosionData* explosion;
|
||||
S32 explosionId;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue