From eca0820134376a23fce3458598ea0eef9300ccd7 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Sat, 21 Dec 2024 11:16:55 +0000 Subject: [PATCH] init commit start of attempt 3 --- Engine/source/T3D/assets/ImageAsset.cpp | 391 +++++++++++------- Engine/source/T3D/assets/ImageAsset.h | 163 +++++--- Engine/source/T3D/assets/LevelAsset.cpp | 2 +- Engine/source/T3D/assets/assetImporter.cpp | 6 +- Engine/source/afx/ce/afxZodiac.cpp | 5 - .../gui/buttons/guiBitmapButtonCtrl.cpp | 10 +- Engine/source/gui/core/guiTypes.cpp | 4 +- Engine/source/gui/core/guiTypes.h | 12 +- .../source/materials/materialDefinition.cpp | 2 +- Engine/source/math/mMathFn.h | 2 + 10 files changed, 374 insertions(+), 223 deletions(-) diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index 162626b84..a13d8c422 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -106,6 +106,56 @@ ConsoleSetType(TypeImageAssetId) // Warn. Con::warnf("(TypeImageAssetId) - Cannot set multiple args to a single asset."); } + +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// REFACTOR +//----------------------------------------------------------------------------- + +IMPLEMENT_STRUCT(AssetPtr, AssetPtrImageAsset,, "") +END_IMPLEMENT_STRUCT + +ConsoleType(ImageAssetPtr, TypeImageAssetPtrRefactor, AssetPtr, "") + + +ConsoleGetType(TypeImageAssetPtrRefactor) +{ + // Fetch asset Id. + return (*((AssetPtr*)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* pAssetPtr = dynamic_cast*>((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) { AssetQuery query; @@ -262,168 +315,162 @@ U32 ImageAsset::getAssetById(StringTableEntry assetId, AssetPtr* 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(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(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(previewFilename); - previewFilename = previewAsset->getImagePath(); + previewFilename = previewAsset->getImageFile(); } } @@ -802,5 +907,3 @@ void GuiInspectorTypeImageAssetId::consoleInit() ConsoleBaseType::getType(TypeImageAssetId)->setInspectorFieldType("GuiInspectorTypeImageAssetId"); } - -#endif diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 027dfbac1..75ea87803 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -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 mResourceMap; - typedef Signal ImageAssetChanged; - ImageAssetChanged mChangeSignal; - - typedef Signal 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); static StringTableEntry getAssetIdByFilename(StringTableEntry fileName); static U32 getAssetById(StringTableEntry assetId, AssetPtr* imageAsset); static U32 getAssetById(String assetId, AssetPtr* 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(obj)->setImageFileName(data); return false; } - static StringTableEntry getImageFileName(void* obj, StringTableEntry data) { return static_cast(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(obj)->setImageFile(data); return false; } + static const char* getImageFile(void* obj, StringTableEntry data) { return static_cast(obj)->getImageFile(); } + static bool writeImageFile(void* obj, StringTableEntry pFieldName) { return static_cast(obj)->getImageFile() != StringTable->EmptyString(); } + + // Gen mips? + static bool setGenMips(void* obj, StringTableEntry index, StringTableEntry data) { static_cast(obj)->setGenMips(dAtob(data)); return false; } + static bool writeGenMips(void* obj, StringTableEntry pFieldName) { return static_cast(obj)->getGenMips() == true; } + + // Texture Is Hdr? + static bool setTextureHDR(void* obj, StringTableEntry index, StringTableEntry data) { static_cast(obj)->setTextureHDR(dAtob(data)); return false; } + static bool writeTextureHDR(void* obj, StringTableEntry pFieldName) { return static_cast(obj)->getTextureHDR() == true; } }; DefineConsoleType(TypeImageAssetPtr, ImageAsset) DefineConsoleType(TypeImageAssetId, String) +DECLARE_STRUCT(AssetPtr) +DefineConsoleType(TypeImageAssetPtrRefactor, AssetPtr ) + 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 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 get##name##Asset(void) { return m##name##Asset; } \ + static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast(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 diff --git a/Engine/source/T3D/assets/LevelAsset.cpp b/Engine/source/T3D/assets/LevelAsset.cpp index 98bb2cc5c..1bfee7394 100644 --- a/Engine/source/T3D/assets/LevelAsset.cpp +++ b/Engine/source/T3D/assets/LevelAsset.cpp @@ -230,7 +230,7 @@ StringTableEntry LevelAsset::getPreviewImagePath(void) const { if (mPreviewImageAsset.notNull() && mPreviewImageAsset->isAssetValid()) { - return mPreviewImageAsset->getImagePath(); + return mPreviewImageAsset->getImageFile(); } return StringTable->EmptyString(); diff --git a/Engine/source/T3D/assets/assetImporter.cpp b/Engine/source/T3D/assets/assetImporter.cpp index 58d956ef5..3f0e514df 100644 --- a/Engine/source/T3D/assets/assetImporter.cpp +++ b/Engine/source/T3D/assets/assetImporter.cpp @@ -1877,7 +1877,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem) { //got a match! ImageAsset* foundImageAsset = AssetDatabase.acquireAsset(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(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 diff --git a/Engine/source/afx/ce/afxZodiac.cpp b/Engine/source/afx/ce/afxZodiac.cpp index 5d9f310ef..383bbcc15 100644 --- a/Engine/source/afx/ce/afxZodiac.cpp +++ b/Engine/source/afx/ce/afxZodiac.cpp @@ -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__)); } } diff --git a/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp b/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp index e2ef9d344..9738cc25c 100644 --- a/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp +++ b/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp @@ -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; } } diff --git a/Engine/source/gui/core/guiTypes.cpp b/Engine/source/gui/core/guiTypes.cpp index 528ea5425..5c1e11359 100644 --- a/Engine/source/gui/core/guiTypes.cpp +++ b/Engine/source/gui/core/guiTypes.cpp @@ -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 diff --git a/Engine/source/gui/core/guiTypes.h b/Engine/source/gui/core/guiTypes.h index a96dd92f1..759b857bc 100644 --- a/Engine/source/gui/core/guiTypes.h +++ b/Engine/source/gui/core/guiTypes.h @@ -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()) diff --git a/Engine/source/materials/materialDefinition.cpp b/Engine/source/materials/materialDefinition.cpp index c9a09bd0d..3084ce2f4 100644 --- a/Engine/source/materials/materialDefinition.cpp +++ b/Engine/source/materials/materialDefinition.cpp @@ -674,7 +674,7 @@ void Material::_mapMaterial() } else if (!mDiffuseMapAsset->isNull()) { - mMapTo = mDiffuseMapAsset[0]->getImageFileName(); + mMapTo = mDiffuseMapAsset[0]->getImageFile(); } } } diff --git a/Engine/source/math/mMathFn.h b/Engine/source/math/mMathFn.h index 1c65604a1..9f84b37df 100644 --- a/Engine/source/math/mMathFn.h +++ b/Engine/source/math/mMathFn.h @@ -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_