init commit

start of attempt 3
This commit is contained in:
marauder2k7 2024-12-21 11:16:55 +00:00
parent 71d08e9e0c
commit eca0820134
10 changed files with 374 additions and 223 deletions

View file

@ -106,6 +106,56 @@ ConsoleSetType(TypeImageAssetId)
// Warn.
Con::warnf("(TypeImageAssetId) - Cannot set multiple args to a single asset.");
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// REFACTOR
//-----------------------------------------------------------------------------
IMPLEMENT_STRUCT(AssetPtr<ImageAsset>, AssetPtrImageAsset,, "")
END_IMPLEMENT_STRUCT
ConsoleType(ImageAssetPtr, TypeImageAssetPtrRefactor, AssetPtr<ImageAsset>, "")
ConsoleGetType(TypeImageAssetPtrRefactor)
{
// Fetch asset Id.
return (*((AssetPtr<ImageAsset>*)dptr)).getAssetId();
}
ConsoleSetType(TypeImageAssetPtrRefactor)
{
// Was a single argument specified?
if (argc == 1)
{
// Yes, so fetch field value.
const char* pFieldValue = argv[0];
// Fetch asset pointer.
AssetPtr<ImageAsset>* pAssetPtr = dynamic_cast<AssetPtr<ImageAsset>*>((AssetPtrBase*)(dptr));
// Is the asset pointer the correct type?
if (pAssetPtr == NULL)
{
// No, so fail.
Con::warnf("(TypeImageAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
return;
}
// Set asset.
pAssetPtr->setAssetId(pFieldValue);
return;
}
// Warn.
Con::warnf("(TypeImageAssetPtr) - Cannot set multiple args to a single asset.");
}
//-----------------------------------------------------------------------------
// REFACTOR END
//-----------------------------------------------------------------------------
ImplementEnumType(ImageAssetType,
@ -131,14 +181,6 @@ const String ImageAsset::mErrCodeStrings[] =
"UnKnown"
};
//-----------------------------------------------------------------------------
ImageAsset::ImageAsset() : AssetBase(), mIsValidImage(false), mUseMips(true), mIsHDRImage(false), mImageType(Albedo)
{
mImageFileName = StringTable->EmptyString();
mImagePath = StringTable->EmptyString();
mLoadedState = AssetErrCode::NotLoaded;
mChangeSignal.notify(this, &ImageAsset::onAssetRefresh);
}
//-----------------------------------------------------------------------------
ImageAsset::~ImageAsset()
@ -164,17 +206,28 @@ void ImageAsset::initPersistFields()
// Call parent.
Parent::initPersistFields();
addProtectedField("imageFile", TypeAssetLooseFilePath, Offset(mImageFileName, ImageAsset),
&setImageFileName, &getImageFileName, "Path to the image file.");
addProtectedField("imageFile", TypeAssetLooseFilePath, Offset(mImageFile, ImageAsset), &setImageFile, &getImageFile, &writeImageFile, "Path to the image file.");
addField("useMips", TypeBool, Offset(mUseMips, ImageAsset), "Should the image use mips? (Currently unused).");
addField("isHDRImage", TypeBool, Offset(mIsHDRImage, ImageAsset), "Is the image in an HDR format? (Currently unused)");
addProtectedField("useMips", TypeBool, Offset(mUseMips, ImageAsset), &setGenMips, &defaultProtectedGetFn, &writeGenMips, "Generate mip maps?");
addProtectedField("isHDRImage", TypeBool, Offset(mIsHDRImage, ImageAsset), &setTextureHDR, &defaultProtectedGetFn, &writeTextureHDR, "HDR Image?");
addField("imageType", TypeImageAssetType, Offset(mImageType, ImageAsset), "What the main use-case for the image is for.");
}
bool ImageAsset::onAdd()
{
// Call Parent.
if (!Parent::onAdd())
return false;
return true;
}
void ImageAsset::onRemove()
{
// Call Parent.
Parent::onRemove();
}
//------------------------------------------------------------------------------
//Utility function to 'fill out' bindings and resources with a matching asset if one exists
U32 ImageAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset)
{
AssetQuery query;
@ -262,168 +315,162 @@ U32 ImageAsset::getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* ima
}
}
void ImageAsset::initializeAsset(void)
{
// Call parent.
Parent::initializeAsset();
// Ensure the image-file is expanded.
mImageFile = expandAssetFilePath(mImageFile);
}
void ImageAsset::onAssetRefresh(void)
{
// Ignore if not yet added to the sim.
if (!isProperlyAdded())
return;
// Call parent.
Parent::onAssetRefresh();
//mLoadedState = NotLoaded;
}
//------------------------------------------------------------------------------
void ImageAsset::copyTo(SimObject* object)
{
// Call to parent.
Parent::copyTo(object);
ImageAsset* pAsset = static_cast<ImageAsset*>(object);
// Sanity!
AssertFatal(pAsset != NULL, "ImageAsset::copyTo() - Object is not the correct type.");
pAsset->setImageFile(getImageFile());
pAsset->setGenMips(getGenMips());
pAsset->setTextureHDR(getTextureHDR());
}
void ImageAsset::setImageFile(StringTableEntry pImageFile)
{
// Sanity!
AssertFatal(pImageFile != NULL, "Cannot use a NULL image file.");
pImageFile = StringTable->insert(pImageFile);
if (pImageFile == mImageFile)
return;
// if we previously loaded, remove the listener for the file.
if (mLoadedState == Ok)
Torque::FS::RemoveChangeNotification(mImageFile, this, &ImageAsset::_onFileChanged);
mImageFile = getOwned() ? expandAssetFilePath(pImageFile) : StringTable->insert(pImageFile);
refreshAsset();
}
void ImageAsset::setGenMips(const bool pGenMips)
{
if (pGenMips == mUseMips)
return;
mUseMips = pGenMips;
refreshAsset();
}
void ImageAsset::setTextureHDR(const bool pIsHDR)
{
if (pIsHDR == mIsHDRImage)
return;
mIsHDRImage = pIsHDR;
refreshAsset();
}
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);
mLoadedState = BadFileReference;
return mLoadedState;
}
if (mLoadedState == Ok)
return mLoadedState;
mLoadedState = Ok;
mIsValidImage = true;
if (!Torque::FS::IsFile(mImageFile))
{
Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFile);
mLoadedState = BadFileReference;
return mLoadedState;
}
mLoadedState = BadFileReference;
else
{
Torque::FS::AddChangeNotification(mImageFile, this, &ImageAsset::_onFileChanged);
mLoadedState = Ok;
}
mIsValidImage = false;
return mLoadedState;
}
void ImageAsset::initializeAsset()
{
ResourceManager::get().getChangedSignal().notify(this, &ImageAsset::_onResourceChanged);
if (mImageFileName[0] != '$' && mImageFileName[0] != '#')
{
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
}
else
{
mImagePath = mImageFileName;
}
}
void ImageAsset::onAssetRefresh()
{
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.
while (assetDependenciesItr != mpOwningAssetManager->getDependedOnAssets()->end() && assetDependenciesItr->key == mpAssetDefinition->mAssetId)
{
StringTableEntry assetId = assetDependenciesItr->value;
AssetBase* dependent = AssetDatabase.acquireAsset<AssetBase>(assetId);
dependent->refreshAsset();
}
}
void ImageAsset::_onResourceChanged(const Torque::Path& path)
{
if (path != Torque::Path(mImagePath))
return;
refreshAsset();
}
void ImageAsset::setImageFileName(const char* pScriptFile)
{
// Sanity!
AssertFatal(pScriptFile != NULL, "Cannot use a NULL image file.");
// Update.
mImageFileName = StringTable->insert(pScriptFile, true);
// Refresh the asset.
refreshAsset();
}
GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
{
load();
if (mResourceMap.contains(requestedProfile))
if (mLoadedState == Ok)
{
mLoadedState = Ok;
return mResourceMap.find(requestedProfile)->value;
}
else
{
// this is a target.
if (mImageFileName[0] == '$' || mImageFileName[0] == '#')
if (mResourceMap.contains(requestedProfile))
{
mLoadedState = Ok;
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();
}
return mResourceMap.find(requestedProfile)->value;
}
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);
GFXTexHandle newTex;
newTex.set(mImageFile, requestedProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
if (newTex)
{
mLoadedState = AssetErrCode::Ok;
mResourceMap.insert(requestedProfile, newTex);
mLoadedState = Ok;
return newTex;
}
else
mLoadedState = BadFileReference;
}
}
mLoadedState = AssetErrCode::Failed;
return nullptr;
}
const char* ImageAsset::getImageInfo()
void ImageAsset::generateTexture(void)
{
if (mIsValidImage)
// implement some defaults, eventually SRGB should be optional.
U32 flags = GFXTextureProfile::Static | GFXTextureProfile::SRGB;
// dont want mips?
if (!mUseMips)
{
static const U32 bufSize = 2048;
char* returnBuffer = Con::getReturnBuffer(bufSize);
GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, &GFXStaticTextureSRGBProfile);
if (newTex)
{
dSprintf(returnBuffer, bufSize, "%s %d %d %d", GFXStringTextureFormat[newTex->getFormat()], newTex->getHeight(), newTex->getWidth(), newTex->getDepth());
newTex = nullptr;
}
else
{
dSprintf(returnBuffer, bufSize, "ImageAsset::getImageInfo() - Failed to get image info for %s", getAssetId());
}
return returnBuffer;
flags |= GFXTextureProfile::NoMipmap;
}
return "";
GFXTextureProfile::Types type = GFXTextureProfile::Types::DiffuseMap;
if (mImageType == ImageTypes::Normal) {
type = GFXTextureProfile::Types::NormalMap;
}
GFXTextureProfile* genProfile = new GFXTextureProfile("ImageAssetGennedProfile", type, flags);
mTextureHandle.set(mImageFile, genProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
mResourceMap.insert(genProfile, mTextureHandle);
if (mTextureHandle.isValid())
mLoadedState = AssetErrCode::Ok;
else
mLoadedState = AssetErrCode::Failed;
ResourceManager::get().getChangedSignal().notify(this, &ImageAsset::_onResourceChanged);
}
const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type)
@ -452,7 +499,7 @@ const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type)
return _names[type];
}
ImageAsset::ImageTypes ImageAsset::getImageTypeFromName(const char* name)
ImageAsset::ImageTypes ImageAsset::getImageTypeFromName(StringTableEntry name)
{
if (dStrIsEmpty(name))
{
@ -475,11 +522,69 @@ ImageAsset::ImageTypes ImageAsset::getImageTypeFromName(const char* name)
return (ImageTypes)ret;
}
DefineEngineMethod(ImageAsset, getImagePath, const char*, (), ,
void ImageAsset::_onFileChanged(const Torque::Path& path)
{
if (path != Torque::Path(mImageFile))
return;
refreshAsset();
}
void ImageAsset::_onResourceChanged(const Torque::Path& path)
{
if (path != Torque::Path(mImageFile))
return;
refreshAsset();
}
void ImageAsset::onTamlPreWrite(void)
{
// Call parent.
Parent::onTamlPreWrite();
// Ensure the image-file is collapsed.
mImageFile = getOwned() ? collapseAssetFilePath(mImageFile) : mImageFile;
}
void ImageAsset::onTamlPostWrite(void)
{
// Call parent.
Parent::onTamlPostWrite();
// Ensure the image-file is expanded.
mImageFile = getOwned() ? expandAssetFilePath(mImageFile) : mImageFile;
}
const char* ImageAsset::getImageInfo()
{
if (isAssetValid())
{
static const U32 bufSize = 2048;
char* returnBuffer = Con::getReturnBuffer(bufSize);
GFXTexHandle newTex = TEXMGR->createTexture(mImageFile, &GFXStaticTextureSRGBProfile);
if (newTex)
{
dSprintf(returnBuffer, bufSize, "%s %d %d %d", GFXStringTextureFormat[newTex->getFormat()], newTex->getHeight(), newTex->getWidth(), newTex->getDepth());
newTex = nullptr;
}
else
{
dSprintf(returnBuffer, bufSize, "ImageAsset::getImageInfo() - Failed to get image info for %s", getAssetId());
}
return returnBuffer;
}
return "";
}
DefineEngineMethod(ImageAsset, getImageFile, const char*, (), ,
"Gets the image filepath of this asset.\n"
"@return File path of the image file.")
{
return object->getImagePath();
return object->getImageFile();
}
DefineEngineMethod(ImageAsset, getImageInfo, const char*, (), ,
@ -496,7 +601,7 @@ DefineEngineStaticMethod(ImageAsset, getAssetIdByFilename, const char*, (const c
{
return ImageAsset::getAssetIdByFilename(StringTable->insert(filePath));
}
#endif
//-----------------------------------------------------------------------------
// GuiInspectorTypeAssetId
//-----------------------------------------------------------------------------
@ -652,7 +757,7 @@ bool GuiInspectorTypeImageAssetPtr::renderTooltip(const Point2I& hoverPos, const
if (imgAsset == NULL || assetState == ImageAsset::Failed)
return false;
StringTableEntry filename = imgAsset->getImagePath();
StringTableEntry filename = imgAsset->getImageFile();
if (!filename || !filename[0])
return false;
@ -665,7 +770,7 @@ bool GuiInspectorTypeImageAssetPtr::renderTooltip(const Point2I& hoverPos, const
if (AssetDatabase.isDeclaredAsset(previewFilename))
{
ImageAsset* previewAsset = AssetDatabase.acquireAsset<ImageAsset>(previewFilename);
previewFilename = previewAsset->getImagePath();
previewFilename = previewAsset->getImageFile();
}
}
@ -802,5 +907,3 @@ void GuiInspectorTypeImageAssetId::consoleInit()
ConsoleBaseType::getType(TypeImageAssetId)->setInspectorFieldType("GuiInspectorTypeImageAssetId");
}
#endif

View file

@ -79,6 +79,39 @@ public:
ImageTypeCount = 11
};
class Frame
{
public:
Frame(const S32 pixelOffsetX, const S32 pixelOffsetY,
const U32 pixelWidth, const U32 pixelHeight,
const F32 texelWidthScale, const F32 texelHeightScale,
StringTableEntry inRegionName = StringTable->EmptyString())
: regionName(inRegionName)
{
pixelOffset.set(pixelOffsetY, pixelOffsetY);
pixelSize.set(pixelWidth, pixelHeight);
texelLower.set(pixelOffsetX * texelWidthScale, pixelOffsetY * texelHeightScale);
texelSize.set(pixelWidth * texelWidthScale, pixelHeight * texelHeightScale);
texelUpper.set(texelLower.x + texelSize.x, texelLower.y + texelSize.y);
}
void setFlip(bool flipX, bool flipY)
{
if (flipX) mSwap(texelLower.x, texelUpper.x);
if (flipY) mSwap(texelLower.y, texelUpper.y);
}
Point2I pixelOffset;
Point2I pixelSize;
Point2F texelLower;
Point2F texelUpper;
Point2F texelSize;
StringTableEntry regionName;
};
static StringTableEntry smNoImageAssetFallback;
enum ImageAssetErrCode
@ -96,26 +129,16 @@ public:
if (errCode > ImageAssetErrCode::Extended) return "undefined error";
return mErrCodeStrings[errCode - Parent::Extended];
};
private:
protected:
StringTableEntry mImageFileName;
StringTableEntry mImagePath;
NamedTexTargetRef mNamedTarget;
bool mIsValidImage;
bool mUseMips;
bool mIsHDRImage;
ImageTypes mImageType;
StringTableEntry mImageFile;
bool mUseMips;
bool mIsHDRImage;
GFXTexHandle mTextureHandle;
ImageTypes mImageType;
HashMap<GFXTextureProfile*, GFXTexHandle> mResourceMap;
typedef Signal<void()> ImageAssetChanged;
ImageAssetChanged mChangeSignal;
typedef Signal<void(S32 index)> ImageAssetArrayChanged;
ImageAssetArrayChanged mChangeArraySignal;
void generateTexture(void);
public:
ImageAsset();
virtual ~ImageAsset();
@ -125,6 +148,10 @@ public:
/// Engine.
static void initPersistFields();
/// Sim
bool onAdd() override;
void onRemove() override;
void copyTo(SimObject* object) override;
/// Declare Console Object.
@ -132,44 +159,75 @@ public:
void _onResourceChanged(const Torque::Path& path);
ImageAssetChanged& getChangedSignal() { return mChangeSignal; }
ImageAssetArrayChanged& getChangedArraySignal() { return mChangeArraySignal; }
// asset Base load
U32 load() override;
void setImageFileName(StringTableEntry pScriptFile);
inline StringTableEntry getImageFileName(void) const { return mImageFileName; };
void setImageFile(StringTableEntry pImageFile);
inline StringTableEntry getImageFile(void) const { return mImageFile; };
inline StringTableEntry getImagePath(void) const { return mImagePath; };
void setGenMips(const bool pGenMips);
inline bool getGenMips(void) const { return mUseMips; };
bool isValid() { return mIsValidImage; }
void setTextureHDR(const bool pIsHDR);
inline bool getTextureHDR(void) const { return mIsHDRImage; };
GFXTexHandle getTexture(GFXTextureProfile* requestedProfile);
StringTableEntry getImageInfo();
inline GFXTexHandle& getTexture(void) { load(); generateTexture(); return mTextureHandle; }
GFXTexHandle getTexture(GFXTextureProfile* requestedProfile);
static StringTableEntry getImageTypeNameFromType(ImageTypes type);
static ImageTypes getImageTypeFromName(StringTableEntry name);
static ImageTypes getImageTypeFromName(StringTableEntry name);
void setImageType(ImageTypes type) { mImageType = type; }
ImageTypes getImageType() { return mImageType; }
void setImageType(ImageTypes type) { mImageType = type; }
ImageTypes getImageType() { return mImageType; }
inline U32 getTextureWidth(void) const { return mTextureHandle->getWidth(); }
inline U32 getTextureHeight(void) const { return mTextureHandle->getHeight(); }
inline U32 getTextureDepth(void) const { return mTextureHandle->getDepth(); }
inline U32 getTextureBitmapWidth(void) const { return mTextureHandle->getBitmapWidth(); }
inline U32 getTextureBitmapHeight(void) const { return mTextureHandle->getBitmapHeight(); }
inline U32 getTextureBitmapDepth(void) const { return mTextureHandle->getBitmapDepth(); }
bool isAssetValid(void) const override { return !mTextureHandle.isNull(); }
static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset);
static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
static U32 getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset);
static U32 getAssetById(String assetId, AssetPtr<ImageAsset>* imageAsset) { return getAssetById(assetId.c_str(), imageAsset); };
U32 load() override;
const char* getImageInfo();
protected:
void initializeAsset(void) override;
void onAssetRefresh(void) override;
// Asset Base callback
void initializeAsset(void) override;
void onAssetRefresh(void) override;
void _onFileChanged(const Torque::Path& path);
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(); }
/// Taml callbacks.
void onTamlPreWrite(void) override;
void onTamlPostWrite(void) override;
protected:
// Texture file
static bool setImageFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setImageFile(data); return false; }
static const char* getImageFile(void* obj, StringTableEntry data) { return static_cast<ImageAsset*>(obj)->getImageFile(); }
static bool writeImageFile(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getImageFile() != StringTable->EmptyString(); }
// Gen mips?
static bool setGenMips(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setGenMips(dAtob(data)); return false; }
static bool writeGenMips(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getGenMips() == true; }
// Texture Is Hdr?
static bool setTextureHDR(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setTextureHDR(dAtob(data)); return false; }
static bool writeTextureHDR(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getTextureHDR() == true; }
};
DefineConsoleType(TypeImageAssetPtr, ImageAsset)
DefineConsoleType(TypeImageAssetId, String)
DECLARE_STRUCT(AssetPtr<ImageAsset>)
DefineConsoleType(TypeImageAssetPtrRefactor, AssetPtr<ImageAsset> )
typedef ImageAsset::ImageTypes ImageAssetType;
DefineEnumType(ImageAssetType);
@ -196,10 +254,6 @@ public: \
{\
if(m##name##AssetId != _in || m##name##Name != _in)\
{\
if (m##name##Asset.notNull())\
{\
m##name##Asset->getChangedSignal().remove(this, &className::changeFunc);\
}\
if (_in == NULL || _in == StringTable->EmptyString())\
{\
m##name##Name = StringTable->EmptyString();\
@ -251,10 +305,6 @@ public: \
}\
if (get##name() != StringTable->EmptyString() && m##name##Name != StringTable->insert("texhandle"))\
{\
if (m##name##Asset.notNull())\
{\
m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\
}\
\
if (get##name()[0] != '$' && get##name()[0] != '#') {\
m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
@ -285,11 +335,8 @@ public: \
\
const StringTableEntry get##name() const\
{\
if (m##name##Asset && (m##name##Asset->getImageFileName() != StringTable->EmptyString()))\
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());\
if (m##name##Asset && (m##name##Asset->getImageFile() != StringTable->EmptyString()))\
return Platform::makeRelativePathName(m##name##Asset->getImageFile(), Platform::getMainDotCsDir());\
else if (m##name##AssetId != StringTable->EmptyString())\
return m##name##AssetId;\
else if (m##name##Name != StringTable->EmptyString())\
@ -435,11 +482,8 @@ public: \
\
const StringTableEntry get##name(const U32& index) const\
{\
if (m##name##Asset[index] && (m##name##Asset[index]->getImageFileName() != StringTable->EmptyString()))\
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());\
if (m##name##Asset[index] && (m##name##Asset[index]->getImageFile() != StringTable->EmptyString()))\
return Platform::makeRelativePathName(m##name##Asset[index]->getImageFile(), Platform::getMainDotCsDir());\
else if (m##name##AssetId[index] != StringTable->EmptyString())\
return m##name##AssetId[index];\
else if (m##name##Name[index] != StringTable->EmptyString())\
@ -542,4 +586,19 @@ if (m##name##AssetId[index] != StringTable->EmptyString())\
#pragma endregion
#pragma region Refactor Asset Macros
#define DECLARE_IMAGEASSET_REFACTOR(className, name, profile) \
private: \
AssetPtr<ImageAsset> m##name##Asset; \
public: \
void _set##name(StringTableEntry _in); \
inline StringTableEntry _get##name(void) const { return m##name##Asset.getAssetId(); } \
GFXTexHandle get##name() { return m##name##Asset.notNull() ? m##name##Asset->getTexture(&profile) : NULL; } \
AssetPtr<ImageAsset> 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;}
#define INITPERSISTFIELD_IMAGEASSET_REFACTOR(name, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeImageAssetPtrRefactor, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
#pragma endregion

View file

@ -230,7 +230,7 @@ StringTableEntry LevelAsset::getPreviewImagePath(void) const
{
if (mPreviewImageAsset.notNull() && mPreviewImageAsset->isAssetValid())
{
return mPreviewImageAsset->getImagePath();
return mPreviewImageAsset->getImageFile();
}
return StringTable->EmptyString();

View file

@ -1877,7 +1877,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem)
{
//got a match!
ImageAsset* foundImageAsset = AssetDatabase.acquireAsset<ImageAsset>(testAssetId.c_str());
imagePath = foundImageAsset->getImagePath();
imagePath = foundImageAsset->getImageFile();
AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
@ -1921,7 +1921,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem)
{
//got a match!
ImageAsset* foundImageAsset = AssetDatabase.acquireAsset<ImageAsset>(testAssetId.c_str());
imagePath = foundImageAsset->getImagePath();
imagePath = foundImageAsset->getImageFile();
AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
@ -2834,7 +2834,7 @@ Torque::Path AssetImporter::importImageAsset(AssetImportObject* assetItem)
#endif
newAsset->setAssetName(assetName);
newAsset->setImageFileName(imageFileName.c_str());
newAsset->setImageFile(imageFileName.c_str());
//If it's not a re-import, check that the file isn't being in-place imported. If it isn't, store off the original
//file path for reimporting support later

View file

@ -349,11 +349,6 @@ void afxZodiacData::onPerformSubstitutions()
{
if (getTexture() != StringTable->EmptyString() && mTextureName != StringTable->insert("texhandle"))
{
if (mTextureAsset.notNull())
{
mTextureAsset->getChangedSignal().notify(this, &afxZodiacData::onImageChanged);
}
mTexture.set(getTexture(), mTextureProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
}
}

View file

@ -301,7 +301,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
if( mUseModifiers )
baseName += modifiers[ i ];
mTextures[ i ].mTextureNormal = GFXTexHandle( mBitmapAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__));
mTextures[ i ].mTextureNormal = GFXTexHandle( mBitmapAsset->getImageFile(), &GFXDefaultGUIProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__));
if( mUseStates )
{
@ -323,7 +323,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
mTextures[i].mTextureNormalAsset->load();
if (mTextures[i].mTextureNormalAsset->getStatus() == AssetBase::Ok)
{
mTextures[i].mTextureNormal = GFXTexHandle(mTextures[i].mTextureNormalAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
mTextures[i].mTextureNormal = GFXTexHandle(mTextures[i].mTextureNormalAsset->getImageFile(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
break;
}
}
@ -345,7 +345,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
mTextures[i].mTextureHilightAsset->load();
if (mTextures[i].mTextureHilightAsset->getStatus() == AssetBase::Ok)
{
mTextures[i].mTextureHilight = GFXTexHandle(mTextures[i].mTextureHilightAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
mTextures[i].mTextureHilight = GFXTexHandle(mTextures[i].mTextureHilightAsset->getImageFile(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
break;
}
}
@ -369,7 +369,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
mTextures[i].mTextureDepressedAsset->load();
if (mTextures[i].mTextureDepressedAsset->getStatus() == AssetBase::Ok)
{
mTextures[i].mTextureDepressed = GFXTexHandle(mTextures[i].mTextureDepressedAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
mTextures[i].mTextureDepressed = GFXTexHandle(mTextures[i].mTextureDepressedAsset->getImageFile(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
break;
}
}
@ -393,7 +393,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
mTextures[i].mTextureInactiveAsset->load();
if (mTextures[i].mTextureInactiveAsset->getStatus() == AssetBase::Ok)
{
mTextures[i].mTextureInactive = GFXTexHandle(mTextures[i].mTextureInactiveAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
mTextures[i].mTextureInactive = GFXTexHandle(mTextures[i].mTextureInactiveAsset->getImageFile(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
break;
}
}

View file

@ -203,7 +203,7 @@ bool GuiControlProfile::protectedSetBitmap( void *object, const char *index, con
{
if (profile->mBitmapAsset.notNull() && profile->getBitmap() != StringTable->insert("texHandle"))
{
profile->mBitmap.set(profile->mBitmapAsset->getImagePath(), profile->mBitmapProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
profile->mBitmap.set(profile->mBitmapAsset->getImageFile(), profile->mBitmapProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
}
//verify the bitmap
@ -648,7 +648,7 @@ void GuiControlProfile::incLoadCount()
{
if (mBitmapAsset.notNull() && getBitmap() != StringTable->insert("texHandle"))
{
mBitmap.set(mBitmapAsset->getImagePath(), mBitmapProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
mBitmap.set(mBitmapAsset->getImageFile(), mBitmapProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
}
//verify the bitmap

View file

@ -475,10 +475,6 @@ public:
{
if (mBitmapAssetId != _in || mBitmapName != _in)
{
if (mBitmapAsset.notNull())
{
mBitmapAsset->getChangedSignal().remove(this, &GuiControlProfile::onBitmapChanged);
}
if (_in == StringTable->EmptyString())
{
mBitmapName = StringTable->EmptyString();
@ -530,10 +526,6 @@ public:
}
if (getBitmap() != StringTable->EmptyString() && mBitmapName != StringTable->insert("texhandle"))
{
if (mBitmapAsset.notNull())
{
mBitmapAsset->getChangedSignal().notify(this, &GuiControlProfile::onBitmapChanged);
}
}
else
{
@ -551,8 +543,8 @@ public:
const StringTableEntry getBitmap() const
{
if (mBitmapAsset && (mBitmapAsset->getImageFileName() != StringTable->EmptyString()))
return Platform::makeRelativePathName(mBitmapAsset->getImagePath(), Platform::getMainDotCsDir());
if (mBitmapAsset && (mBitmapAsset->getImageFile() != StringTable->EmptyString()))
return Platform::makeRelativePathName(mBitmapAsset->getImageFile(), Platform::getMainDotCsDir());
else if (mBitmapAssetId != StringTable->EmptyString())
return mBitmapAssetId;
else if (mBitmapName != StringTable->EmptyString())

View file

@ -674,7 +674,7 @@ void Material::_mapMaterial()
}
else if (!mDiffuseMapAsset->isNull())
{
mMapTo = mDiffuseMapAsset[0]->getImageFileName();
mMapTo = mDiffuseMapAsset[0]->getImageFile();
}
}
}

View file

@ -531,5 +531,7 @@ inline F64 mSquared( F64 n )
return n * n;
}
template< typename T >
inline void mSwap(T& a, T& b) { T temp = b; b = a; a = temp; }
#endif //_MMATHFN_H_