Torque3D/Engine/source/assets/assetPtr.h
JeffR 9c654d7932 - Fixes the display of the preview in the MaterialAsset fields
- Hides the special-case direct filepath field for ShapeAsset persist fields macro
- Shifts the handling of TSStatics so the shape instance will load materials on the server as well as the client. This opens gameplay options as well as allowing rebaking of meshes functionality more easily
- Expands AssetBase's isValidAsset utility function to actually check validity instead of just returning true
- Adds isValid utility function to AssetPtr
- Added new field flag that makes the field not write out to file
- Removed legacy iconBitmap field from GuiIconButtonCtrl because it was causing errors
- Fixed group filtering check of guiInspector to ignore case
- Removed unneeded isFile checks for common datablock script files in Prototyping module script
- Removed test datablocks from Prototyping module
- Removed unnecessary container control from AssetBrowser
- Adjusted preview regen logic of AssetBrowser so it doesn't trip if you're simply resizing the window
- Fixed issue where row-vs-column layout logic for AssetBrowser when resizing window was fiddly
- Added handling for when Dragging and Dropping datablock from AssetBrowser to spawn, it'll prompt if it spawns the actual object, or a spawnsphere that spawns said object. In the event of an PlayerData will also prompt if it should spawn an AIPlayer
- Added ability to take a TSStatic that uses a baked down mesh and are able to restore it to the cache prefab, or trigger and in-place rebake to refresh it if something has changed in the original contents via RMB menu on the scene tree
- Added ability to explode prefab to RMB menu on scene tree
- Added ability to convert selection to prefab or bake to mesh in RMB menu on scene tree
- Tweaked sizing of the DatablockEditorCreatePrompt window to not have cut off elements and easier to see/work with
- Added sanity check to datablock editor creation
- Fixed preview display of material in Decal Editor
- Made compositeTextureEditor use the cached preview of images
- Fixed sizing/spacing of gui selection dropdown as well as resolution dropdown of GuiEditor
- Fixes MaterialEditor to properly save the group collapse state when editing
- Adds ability to in-flow edit and create datablocks in the NavMesh Editor for the testing panel, and makes the datablock dropdown searchable
- Fixed issue where opening the ShapeEditor via the edit button on a ShapeAsset field would cause the action buttons on the top bar to not show
- Fixed error in shape editor where when exiting it was erroneously checking for a clear value of -1 rather than 0
- Removed unneeded top tabbook and tab page for main editor panel
- Fixed issue where reset button of TerrainBrush Softness Curve editor didn't actually reset
- Resized Object Builder window to not cut off elements and have enough width to show more data
- Added a TypeCommand field type to Object Builder and changed spawnscript field of SpawnSphere to use it rather than a simple text edit field
- Allow SpawnSphere in ObjectBuilder to be passed in spawn class and spawn datablock default info
- Injects button to controllable objects when Inspecting them to make it easy to toggle if you're in control of it or not
-
2025-08-25 23:35:28 -05:00

186 lines
5.9 KiB
C++

//-----------------------------------------------------------------------------
// Copyright (c) 2013 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _ASSET_PTR_H_
#define _ASSET_PTR_H_
#ifndef _ASSET_MANAGER_H_
#include "assetManager.h"
#endif
//-----------------------------------------------------------------------------
class AssetPtrCallback
{
friend class AssetManager;
protected:
virtual void onAssetRefreshed( AssetPtrBase* pAssetPtrBase ) = 0;
};
//-----------------------------------------------------------------------------
class AssetPtrBase
{
public:
AssetPtrBase() {};
virtual ~AssetPtrBase()
{
// Un-register any notifications.
unregisterRefreshNotify();
};
/// Referencing.
virtual void clear( void ) = 0;
virtual void setAssetId( const char* pAssetId ) = 0;
virtual StringTableEntry getAssetId( void ) const = 0;
virtual StringTableEntry getAssetType( void ) const = 0;
virtual bool isAssetId( const char* pAssetId ) const = 0;
/// Validity.
virtual bool isNull( void ) const = 0;
virtual bool notNull( void ) const = 0;
/// Notification.
inline void registerRefreshNotify( AssetPtrCallback* pCallback )
{
// Sanity!
AssertFatal( AssetDatabase.isProperlyAdded(), "AssetPtrBase::registerRefreshNotify() - Cannot register an asset pointer with the asset system." );
// register refresh notify.
AssetDatabase.registerAssetPtrRefreshNotify( this, pCallback );
}
void unregisterRefreshNotify( void )
{
// Un-register the refresh notify if the asset system is available.
if ( AssetDatabase.isProperlyAdded() )
AssetDatabase.unregisterAssetPtrRefreshNotify( this );
}
};
//-----------------------------------------------------------------------------
template<typename T> class AssetPtr : public AssetPtrBase
{
private:
SimObjectPtr<T> mpAsset;
public:
AssetPtr() {}
AssetPtr( const char* pAssetId )
{
// Finish if this is an invalid asset Id.
if ( pAssetId == NULL || *pAssetId == 0 )
return;
// Acquire asset.
mpAsset = AssetDatabase.acquireAsset<T>( pAssetId );
}
AssetPtr( const AssetPtr<T>& assetPtr )
{
// Does the asset pointer have an asset?
if ( assetPtr.notNull() )
{
// Yes, so acquire the asset.
mpAsset = AssetDatabase.acquireAsset<T>( assetPtr->getAssetId() );
}
}
virtual ~AssetPtr()
{
// Do we have an asset?
if ( notNull() )
{
// Yes, so release it.
AssetDatabase.releaseAsset( mpAsset->getAssetId() );
}
}
/// Assignment.
AssetPtr<T>& operator=( const char* pAssetId )
{
// Do we have an asset?
if ( notNull() )
{
// Yes, so finish if the asset Id is already assigned.
if ( isAssetId( pAssetId ) )
return *this;
// No, so release it.
AssetDatabase.releaseAsset( mpAsset->getAssetId() );
}
// Is the asset Id at least okay to attempt to acquire the asset?
if ( pAssetId != NULL && *pAssetId != 0 )
{
// Yes, so acquire the asset.
mpAsset = AssetDatabase.acquireAsset<T>( pAssetId );
}
else
{
// No, so remove reference.
mpAsset = NULL;
}
// Return Reference.
return *this;
}
AssetPtr<T>& operator=( const AssetPtr<T>& assetPtr )
{
// Set asset pointer.
*this = assetPtr->getAssetId();
// Return Reference.
return *this;
}
/// Referencing.
void clear( void ) override
{
// Do we have an asset?
if ( notNull() )
{
// Yes, so release it.
AssetDatabase.releaseAsset( mpAsset->getAssetId() );
}
// Reset the asset reference.
mpAsset = NULL;
}
T* operator->( void ) const { return mpAsset; }
T& operator*( void ) const { return *mpAsset; }
operator T*( void ) const { return mpAsset; }
void setAssetId( const char* pAssetId ) override { *this = pAssetId; }
StringTableEntry getAssetId( void ) const override { return isNull() ? StringTable->EmptyString() : mpAsset->getAssetId(); }
StringTableEntry getAssetType(void) const override { return isNull() ? StringTable->EmptyString() : mpAsset->getClassName(); }
bool isAssetId( const char* pAssetId ) const override { return pAssetId == NULL ? isNull() : getAssetId() == StringTable->insert(pAssetId); }
/// Validity.
bool isNull( void ) const override { return mpAsset.isNull(); }
bool notNull( void ) const override { return !mpAsset.isNull(); }
bool isValid(void) const { return notNull() && static_cast<AssetBase*>(mpAsset.getObject())->isAssetValid(); }
};
#endif // _ASSET_PTR_H_