2018-01-28 14:48:02 -06:00
# pragma once
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
2021-07-19 01:07:08 -05:00
# pragma once
2018-01-28 14:48:02 -06:00
# ifndef _ASSET_BASE_H_
# include "assets/assetBase.h"
# endif
# ifndef _ASSET_DEFINITION_H_
# include "assets/assetDefinition.h"
# endif
# ifndef _STRINGUNIT_H_
# include "string/stringUnit.h"
# endif
# ifndef _ASSET_FIELD_TYPES_H_
# include "assets/assetFieldTypes.h"
# endif
2020-03-19 09:47:38 -05:00
# ifndef _ASSET_PTR_H_
# include "assets/assetPtr.h"
# endif
2018-01-28 14:48:02 -06:00
# include "gfx/bitmap/gBitmap.h"
# include "gfx/gfxTextureHandle.h"
2021-07-19 01:07:08 -05:00
# include "sim/netConnection.h"
# include <string>
2020-10-10 22:48:13 -05:00
2018-01-28 14:48:02 -06:00
//-----------------------------------------------------------------------------
class ImageAsset : public AssetBase
{
typedef AssetBase Parent ;
2020-02-17 00:32:50 -06:00
public :
/// The different types of image use cases
enum ImageTypes
{
Albedo = 0 ,
Normal = 1 ,
2020-09-30 13:51:12 -05:00
ORMConfig = 2 ,
2020-02-17 00:32:50 -06:00
GUI = 3 ,
Roughness = 4 ,
AO = 5 ,
Metalness = 6 ,
Glow = 7 ,
Particle = 8 ,
Decal = 9 ,
2020-04-15 12:15:12 -05:00
Cubemap = 10 ,
2020-05-11 02:30:58 -05:00
ImageTypeCount = 11
2020-02-17 00:32:50 -06:00
} ;
2021-07-19 01:07:08 -05:00
static StringTableEntry smNoImageAssetFallback ;
2020-02-17 00:32:50 -06:00
protected :
2018-01-28 14:48:02 -06:00
StringTableEntry mImageFileName ;
2020-08-09 01:32:27 -05:00
StringTableEntry mImagePath ;
2018-01-28 14:48:02 -06:00
bool mIsValidImage ;
bool mUseMips ;
bool mIsHDRImage ;
2020-02-17 00:32:50 -06:00
ImageTypes mImageType ;
2021-07-19 01:07:08 -05:00
HashMap < GFXTextureProfile * , GFXTexHandle > mResourceMap ;
typedef Signal < void ( ) > ImageAssetChanged ;
ImageAssetChanged mChangeSignal ;
typedef Signal < void ( S32 index ) > ImageAssetArrayChanged ;
ImageAssetArrayChanged mChangeArraySignal ;
2020-03-19 09:47:38 -05:00
2018-01-28 14:48:02 -06:00
public :
ImageAsset ( ) ;
virtual ~ ImageAsset ( ) ;
2021-07-19 01:07:08 -05:00
/// Set up some global script interface stuff.
static void consoleInit ( ) ;
2018-01-28 14:48:02 -06:00
/// Engine.
static void initPersistFields ( ) ;
virtual void copyTo ( SimObject * object ) ;
/// Declare Console Object.
DECLARE_CONOBJECT ( ImageAsset ) ;
2021-07-19 01:07:08 -05:00
void _onResourceChanged ( const Torque : : Path & path ) ;
ImageAssetChanged & getChangedSignal ( ) { return mChangeSignal ; }
ImageAssetArrayChanged & getChangedArraySignal ( ) { return mChangeArraySignal ; }
void setImageFileName ( StringTableEntry pScriptFile ) ;
2019-05-04 11:49:42 -05:00
inline StringTableEntry getImageFileName ( void ) const { return mImageFileName ; } ;
2018-01-28 14:48:02 -06:00
2020-08-09 01:32:27 -05:00
inline StringTableEntry getImagePath ( void ) const { return mImagePath ; } ;
2018-01-28 14:48:02 -06:00
bool isValid ( ) { return mIsValidImage ; }
2021-07-19 01:07:08 -05:00
const GBitmap & getImage ( ) ;
GFXTexHandle getTexture ( GFXTextureProfile * requestedProfile ) ;
2020-03-19 09:47:38 -05:00
2021-07-19 01:07:08 -05:00
StringTableEntry getImageInfo ( ) ;
2018-01-28 14:48:02 -06:00
2021-07-19 01:07:08 -05:00
static StringTableEntry getImageTypeNameFromType ( ImageTypes type ) ;
static ImageTypes getImageTypeFromName ( StringTableEntry name ) ;
2020-05-11 02:30:58 -05:00
void setImageType ( ImageTypes type ) { mImageType = type ; }
2021-07-19 01:07:08 -05:00
ImageTypes getImageType ( ) { return mImageType ; }
2020-05-11 02:30:58 -05:00
2021-07-19 01:07:08 -05:00
static U32 getAssetByFilename ( StringTableEntry fileName , AssetPtr < ImageAsset > * imageAsset ) ;
2020-10-10 22:48:13 -05:00
static StringTableEntry getAssetIdByFilename ( StringTableEntry fileName ) ;
2021-07-19 01:07:08 -05:00
static U32 getAssetById ( StringTableEntry assetId , AssetPtr < ImageAsset > * imageAsset ) ;
static U32 getAssetById ( String assetId , AssetPtr < ImageAsset > * imageAsset ) { return getAssetById ( assetId . c_str ( ) , imageAsset ) ; } ;
2020-07-11 16:20:10 -05:00
2018-01-28 14:48:02 -06:00
protected :
virtual void initializeAsset ( void ) ;
virtual void onAssetRefresh ( void ) ;
2021-07-19 01:07:08 -05:00
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 ( ) ; }
2019-05-04 11:49:42 -05:00
2018-01-28 14:48:02 -06:00
void loadImage ( ) ;
} ;
DefineConsoleType ( TypeImageAssetPtr , ImageAsset )
2020-10-10 22:48:13 -05:00
DefineConsoleType ( TypeImageAssetId , String )
2018-01-28 14:48:02 -06:00
2020-02-17 00:32:50 -06:00
typedef ImageAsset : : ImageTypes ImageAssetType ;
DefineEnumType ( ImageAssetType ) ;
2021-07-19 01:07:08 -05:00
# pragma region Singular Asset Macros
//Singular assets
/// <Summary>
/// Declares an image asset
/// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions
/// </Summary>
# define DECLARE_IMAGEASSET(className, name, changeFunc, profile) public: \
GFXTexHandle m # # name = NULL ; \
StringTableEntry m # # name # # Name ; \
StringTableEntry m # # name # # AssetId ; \
AssetPtr < ImageAsset > m # # name # # Asset ; \
GFXTextureProfile * m # # name # # Profile = & profile ; \
public : \
const StringTableEntry get # # name # # File ( ) const { return m # # name # # Name ; } \
void set # # name # # File ( const FileName & _in ) { m # # name # # Name = StringTable - > insert ( _in . c_str ( ) ) ; } \
const AssetPtr < ImageAsset > & get # # name # # Asset ( ) const { return m # # name # # Asset ; } \
void set # # name # # Asset ( const AssetPtr < ImageAsset > & _in ) { m # # name # # Asset = _in ; } \
\
bool _set # # name ( StringTableEntry _in ) \
{ \
if ( m # # name # # AssetId ! = _in | | m # # name # # Name ! = _in ) \
{ \
if ( m # # name # # Asset . notNull ( ) ) \
{ \
m # # name # # Asset - > getChangedSignal ( ) . remove ( this , & className : : changeFunc ) ; \
} \
2021-08-29 17:41:20 -05:00
if ( _in = = NULL | | _in = = StringTable - > EmptyString ( ) ) \
2021-07-19 01:07:08 -05:00
{ \
m # # name # # Name = StringTable - > EmptyString ( ) ; \
m # # name # # AssetId = StringTable - > EmptyString ( ) ; \
m # # name # # Asset = NULL ; \
m # # name . free ( ) ; \
m # # name = NULL ; \
return true ; \
} \
else if ( _in [ 0 ] = = ' $ ' | | _in [ 0 ] = = ' # ' ) \
{ \
m # # name # # Name = _in ; \
m # # name # # AssetId = StringTable - > EmptyString ( ) ; \
m # # name # # Asset = NULL ; \
m # # name . free ( ) ; \
m # # name = NULL ; \
return true ; \
} \
\
if ( AssetDatabase . isDeclaredAsset ( _in ) ) \
{ \
m # # name # # AssetId = _in ; \
\
U32 assetState = ImageAsset : : getAssetById ( m # # name # # AssetId , & m # # name # # Asset ) ; \
\
if ( ImageAsset : : Ok = = assetState ) \
{ \
m # # name # # Name = StringTable - > EmptyString ( ) ; \
} \
} \
else \
{ \
StringTableEntry assetId = ImageAsset : : getAssetIdByFilename ( _in ) ; \
if ( assetId ! = StringTable - > EmptyString ( ) ) \
{ \
m # # name # # AssetId = assetId ; \
if ( ImageAsset : : getAssetById ( m # # name # # AssetId , & m # # name # # Asset ) = = ImageAsset : : Ok ) \
{ \
m # # name # # Name = StringTable - > EmptyString ( ) ; \
} \
} \
else \
{ \
m # # name # # Name = _in ; \
m # # name # # AssetId = StringTable - > EmptyString ( ) ; \
m # # name # # Asset = NULL ; \
} \
} \
} \
if ( get # # name ( ) ! = StringTable - > EmptyString ( ) & & m # # name # # Name ! = StringTable - > insert ( " texhandle " ) ) \
{ \
if ( m # # name # # Asset . notNull ( ) ) \
{ \
m # # name # # Asset - > getChangedSignal ( ) . notify ( this , & className : : changeFunc ) ; \
} \
\
m # # name . set ( get # # name ( ) , m # # name # # Profile , avar ( " %s() - mTextureObject (line %d) " , __FUNCTION__ , __LINE__ ) ) ; \
} \
else \
{ \
m # # name . free ( ) ; \
m # # name = NULL ; \
} \
\
if ( get # # name ( ) = = StringTable - > EmptyString ( ) ) \
return true ; \
\
if ( m # # name # # Asset . notNull ( ) & & m # # name # # Asset - > getStatus ( ) ! = ImageAsset : : Ok ) \
{ \
Con : : errorf ( " %s(%s)::_set%s() - image asset failure \" %s \" due to [%s] " , macroText ( className ) , getName ( ) , macroText ( name ) , _in , ImageAsset : : getAssetErrstrn ( m # # name # # Asset - > getStatus ( ) ) . c_str ( ) ) ; \
return false ; \
} \
2021-08-29 18:32:44 -05:00
else if ( m # # name ) \
2021-07-19 01:07:08 -05:00
{ \
Con : : errorf ( " %s(%s)::_set%s() - Couldn't load image \" %s \" " , macroText ( className ) , getName ( ) , macroText ( name ) , _in ) ; \
return false ; \
} \
return true ; \
} \
\
const StringTableEntry get # # name ( ) const \
{ \
if ( m # # name # # Asset & & ( m # # name # # Asset - > getImageFileName ( ) ! = StringTable - > EmptyString ( ) ) ) \
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 ( ) ) \
return StringTable - > insert ( Platform : : makeRelativePathName ( m # # name # # Name , Platform : : getMainDotCsDir ( ) ) ) ; \
else \
return StringTable - > EmptyString ( ) ; \
} \
GFXTexHandle get # # name # # Resource ( ) \
{ \
return m # # name ; \
}
2020-10-10 22:48:13 -05:00
2021-07-19 01:07:08 -05:00
# define DECLARE_IMAGEASSET_SETGET(className, name)\
static bool _set # # name # # Data ( void * obj , const char * index , const char * data ) \
{ \
bool ret = false ; \
className * object = static_cast < className * > ( obj ) ; \
ret = object - > _set # # name ( StringTable - > insert ( data ) ) ; \
return ret ; \
}
# define DECLARE_IMAGEASSET_NET_SETGET(className, name, bitmask)\
static bool _set # # name # # Data ( void * obj , const char * index , const char * data ) \
{ \
bool ret = false ; \
className * object = static_cast < className * > ( obj ) ; \
ret = object - > _set # # name ( StringTable - > insert ( data ) ) ; \
if ( ret ) \
object - > setMaskBits ( bitmask ) ; \
return ret ; \
}
# define DEF_IMAGEASSET_BINDS(className,name)\
DefineEngineMethod ( className , get # # name , const char * , ( ) , , " get name " ) \
{ \
return object - > get # # name ( ) ; \
} \
DefineEngineMethod ( className , get # # name # # Asset , const char * , ( ) , , assetText ( name , asset reference ) ) \
{ \
return object - > m # # name # # AssetId ; \
} \
DefineEngineMethod ( className , set # # name , bool , ( const char * map ) , , assetText ( name , assignment . first tries asset then flat file . ) ) \
{ \
return object - > _set # # name ( StringTable - > insert ( map ) ) ; \
}
2020-10-10 22:48:13 -05:00
2021-07-19 01:07:08 -05:00
# define INIT_IMAGEASSET(name) \
m # # name # # Name = StringTable - > EmptyString ( ) ; \
m # # name # # AssetId = StringTable - > EmptyString ( ) ; \
m # # name # # Asset = NULL ;
2020-10-10 22:48:13 -05:00
2021-07-19 01:07:08 -05:00
# ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
2020-10-10 22:48:13 -05:00
2021-07-19 01:07:08 -05:00
# define INITPERSISTFIELD_IMAGEASSET(name, consoleClass, docs) \
addProtectedField ( # name , TypeImageFilename , Offset ( m # # name # # Name , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , assetDoc ( name , docs ) ) ; \
addProtectedField ( assetText ( name , Asset ) , TypeImageAssetId , Offset ( m # # name # # AssetId , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , assetDoc ( name , asset docs . ) ) ;
2020-10-10 22:48:13 -05:00
2021-07-19 01:07:08 -05:00
# else
# define INITPERSISTFIELD_IMAGEASSET(name, consoleClass, docs) \
addProtectedField ( # name , TypeImageFilename , Offset ( m # # name # # Name , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , assetDoc ( name , docs ) , AbstractClassRep : : FIELD_HideInInspectors ) ; \
addProtectedField ( assetText ( name , Asset ) , TypeImageAssetId , Offset ( m # # name # # AssetId , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , assetDoc ( name , asset docs . ) ) ;
2020-10-10 22:48:13 -05:00
2021-07-19 01:07:08 -05:00
# endif // SHOW_LEGACY_FILE_FIELDS
# define CLONE_IMAGEASSET(name) \
m # # name # # Name = other . m # # name # # Name ; \
m # # name # # AssetId = other . m # # name # # AssetId ; \
m # # name # # Asset = other . m # # name # # Asset ;
# define LOAD_IMAGEASSET(name)\
if ( m # # name # # AssetId ! = StringTable - > EmptyString ( ) ) \
2020-10-12 04:43:47 -05:00
{ \
2021-07-19 01:07:08 -05:00
S32 assetState = ImageAsset : : getAssetById ( m # # name # # AssetId , & m # # name # # Asset ) ; \
if ( assetState = = ImageAsset : : Ok ) \
2020-10-12 04:43:47 -05:00
{ \
2021-07-19 01:07:08 -05:00
m # # name # # Name = StringTable - > EmptyString ( ) ; \
2020-10-12 04:43:47 -05:00
} \
2021-07-19 01:07:08 -05:00
else Con : : warnf ( " Warning: %s::LOAD_IMAGEASSET(%s)-%s " , mClassName , m # # name # # AssetId , ImageAsset : : getAssetErrstrn ( assetState ) . c_str ( ) ) ; \
2020-10-12 04:43:47 -05:00
}
2020-09-30 13:50:23 -05:00
2021-07-19 01:07:08 -05:00
# define PACKDATA_IMAGEASSET(name)\
if ( stream - > writeFlag ( m # # name # # Asset . notNull ( ) ) ) \
{ \
stream - > writeString ( m # # name # # Asset . getAssetId ( ) ) ; \
_set # # name ( m # # name # # AssetId ) ; \
} \
else \
stream - > writeString ( m # # name # # Name ) ;
2020-06-25 23:33:01 -05:00
2021-07-19 01:07:08 -05:00
# define UNPACKDATA_IMAGEASSET(name)\
if ( stream - > readFlag ( ) ) \
{ \
m # # name # # AssetId = stream - > readSTString ( ) ; \
} \
else \
m # # name # # Name = stream - > readSTString ( ) ;
# define PACK_IMAGEASSET(netconn, name)\
if ( stream - > writeFlag ( m # # name # # Asset . notNull ( ) ) ) \
{ \
NetStringHandle assetIdStr = m # # name # # Asset . getAssetId ( ) ; \
netconn - > packNetStringHandleU ( stream , assetIdStr ) ; \
} \
else \
stream - > writeString ( m # # name # # Name ) ;
# define UNPACK_IMAGEASSET(netconn, name)\
if ( stream - > readFlag ( ) ) \
{ \
m # # name # # AssetId = StringTable - > insert ( netconn - > unpackNetStringHandleU ( stream ) . getString ( ) ) ; \
_set # # name ( m # # name # # AssetId ) ; \
} \
else \
m # # name # # Name = stream - > readSTString ( ) ;
# pragma endregion
# pragma region Arrayed Asset Macros
//Arrayed Assets
# define DECLARE_IMAGEASSET_ARRAY(className, name, profile, max) public: \
static const U32 sm # # name # # Count = max ; \
GFXTexHandle m # # name [ max ] ; \
StringTableEntry m # # name # # Name [ max ] ; \
StringTableEntry m # # name # # AssetId [ max ] ; \
AssetPtr < ImageAsset > m # # name # # Asset [ max ] ; \
GFXTextureProfile * m # # name # # Profile = & profile ; \
public : \
const StringTableEntry get # # name # # File ( const U32 & index ) const { return m # # name # # Name [ index ] ; } \
void set # # name # # File ( const FileName & _in , const U32 & index ) { m # # name # # Name [ index ] = StringTable - > insert ( _in . c_str ( ) ) ; } \
const AssetPtr < ImageAsset > & get # # name # # Asset ( const U32 & index ) const { return m # # name # # Asset [ index ] ; } \
void set # # name # # Asset ( const AssetPtr < ImageAsset > & _in , const U32 & index ) { m # # name # # Asset [ index ] = _in ; } \
\
bool _set # # name ( StringTableEntry _in , const U32 & index ) \
{ \
if ( m # # name # # AssetId [ index ] ! = _in | | m # # name # # Name [ index ] ! = _in ) \
2020-10-12 04:43:47 -05:00
{ \
2021-07-19 01:07:08 -05:00
if ( index > = sm # # name # # Count | | index < 0 ) \
return false ; \
2021-08-29 17:41:20 -05:00
if ( _in = = NULL | | _in = = StringTable - > EmptyString ( ) ) \
2021-07-19 01:07:08 -05:00
{ \
m # # name # # Name [ index ] = StringTable - > EmptyString ( ) ; \
m # # name # # AssetId [ index ] = StringTable - > EmptyString ( ) ; \
m # # name # # Asset [ index ] = NULL ; \
m # # name [ index ] . free ( ) ; \
m # # name [ index ] = NULL ; \
return true ; \
} \
else if ( _in [ 0 ] = = ' $ ' | | _in [ 0 ] = = ' # ' ) \
{ \
m # # name # # Name [ index ] = _in ; \
m # # name # # AssetId [ index ] = StringTable - > EmptyString ( ) ; \
m # # name # # Asset [ index ] = NULL ; \
m # # name [ index ] . free ( ) ; \
m # # name [ index ] = NULL ; \
return true ; \
} \
\
if ( AssetDatabase . isDeclaredAsset ( _in ) ) \
{ \
m # # name # # AssetId [ index ] = _in ; \
\
U32 assetState = ImageAsset : : getAssetById ( m # # name # # AssetId [ index ] , & m # # name # # Asset [ index ] ) ; \
\
if ( ImageAsset : : Ok = = assetState ) \
{ \
m # # name # # Name [ index ] = StringTable - > EmptyString ( ) ; \
} \
} \
else \
{ \
StringTableEntry assetId = ImageAsset : : getAssetIdByFilename ( _in ) ; \
if ( assetId ! = StringTable - > EmptyString ( ) ) \
{ \
m # # name # # AssetId [ index ] = assetId ; \
if ( ImageAsset : : getAssetById ( m # # name # # AssetId [ index ] , & m # # name # # Asset [ index ] ) = = ImageAsset : : Ok ) \
{ \
m # # name # # Name [ index ] = StringTable - > EmptyString ( ) ; \
} \
} \
else \
{ \
m # # name # # Name [ index ] = _in ; \
m # # name # # AssetId [ index ] = StringTable - > EmptyString ( ) ; \
m # # name # # Asset [ index ] = NULL ; \
} \
} \
} \
if ( get # # name ( index ) ! = StringTable - > EmptyString ( ) & & m # # name # # Name [ index ] ! = StringTable - > insert ( " texhandle " ) ) \
{ \
m # # name [ index ] . set ( get # # name ( index ) , m # # name # # Profile , avar ( " %s() - mTextureObject (line %d) " , __FUNCTION__ , __LINE__ ) ) ; \
} \
else \
{ \
m # # name [ index ] . free ( ) ; \
m # # name [ index ] = NULL ; \
} \
\
if ( get # # name ( index ) = = StringTable - > EmptyString ( ) ) \
return true ; \
\
if ( m # # name # # Asset [ index ] . notNull ( ) & & m # # name # # Asset [ index ] - > getStatus ( ) ! = ImageAsset : : Ok ) \
{ \
Con : : errorf ( " %s(%s)::_set%s(%i) - image asset failure \" %s \" due to [%s] " , macroText ( className ) , getName ( ) , macroText ( name ) , index , _in , ImageAsset : : getAssetErrstrn ( m # # name # # Asset [ index ] - > getStatus ( ) ) . c_str ( ) ) ; \
return false ; \
} \
else if ( bool ( m # # name [ index ] ) = = NULL ) \
{ \
Con : : errorf ( " %s(%s)::_set%s(%i) - Couldn't load image \" %s \" " , macroText ( className ) , getName ( ) , macroText ( name ) , index , _in ) ; \
return false ; \
2020-10-12 04:43:47 -05:00
} \
return true ; \
} \
2021-07-19 01:07:08 -05:00
\
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 ( ) ) ; \
else if ( m # # name # # AssetId [ index ] ! = StringTable - > EmptyString ( ) ) \
return m # # name # # AssetId [ index ] ; \
else if ( m # # name # # Name [ index ] ! = StringTable - > EmptyString ( ) ) \
return StringTable - > insert ( Platform : : makeRelativePathName ( m # # name # # Name [ index ] , Platform : : getMainDotCsDir ( ) ) ) ; \
else \
return StringTable - > EmptyString ( ) ; \
} \
GFXTexHandle get # # name # # Resource ( const U32 & index ) \
{ \
if ( index > = sm # # name # # Count | | index < 0 ) \
return nullptr ; \
return m # # name [ index ] ; \
}
# define DECLARE_IMAGEASSET_ARRAY_SETGET(className, name)\
static bool _set # # name # # Data ( void * obj , const char * index , const char * data ) \
{ \
if ( ! index ) return false ; \
U32 idx = dAtoi ( index ) ; \
if ( idx > = sm # # name # # Count ) \
return false ; \
bool ret = false ; \
className * object = static_cast < className * > ( obj ) ; \
ret = object - > _set # # name ( StringTable - > insert ( data ) , idx ) ; \
return ret ; \
}
# define DECLARE_IMAGEASSET_ARRAY_NET_SETGET(className, name, bitmask)\
static bool _set # # name # # Data ( void * obj , const char * index , const char * data ) \
{ \
if ( ! index ) return false ; \
U32 idx = dAtoi ( index ) ; \
if ( idx > = sm # # name # # Count ) \
return false ; \
bool ret = false ; \
className * object = static_cast < className * > ( obj ) ; \
ret = object - > _set # # name ( StringTable - > insert ( data ) , idx ) ; \
if ( ret ) \
object - > setMaskBits ( bitmask ) ; \
return ret ; \
}
# define DEF_IMAGEASSET_ARRAY_BINDS(className,name)\
DefineEngineMethod ( className , get # # name , const char * , ( S32 index ) , , " get name " ) \
{ \
return object - > get # # name ( index ) ; \
} \
DefineEngineMethod ( className , get # # name # # Asset , const char * , ( S32 index ) , , assetText ( name , asset reference ) ) \
{ \
if ( index > = className : : sm # # name # # Count | | index < 0 ) \
return " " ; \
return object - > m # # name # # AssetId [ index ] ; \
} \
DefineEngineMethod ( className , set # # name , bool , ( const char * map , S32 index ) , , assetText ( name , assignment . first tries asset then flat file . ) ) \
{ \
return object - > _set # # name ( StringTable - > insert ( map ) , index ) ; \
2020-10-12 04:43:47 -05:00
}
2021-07-19 01:07:08 -05:00
# define INIT_IMAGEASSET_ARRAY(name, index) \
2021-07-20 20:05:49 -05:00
{ \
2021-07-19 01:07:08 -05:00
m # # name # # Name [ index ] = StringTable - > EmptyString ( ) ; \
m # # name # # AssetId [ index ] = StringTable - > EmptyString ( ) ; \
2021-07-20 20:05:49 -05:00
m # # name # # Asset [ index ] = NULL ; \
}
2021-07-19 01:07:08 -05:00
# ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
# define INITPERSISTFIELD_IMAGEASSET_ARRAY(name, arraySize, consoleClass, docs) \
addProtectedField ( # name , TypeImageFilename , Offset ( m # # name # # Name , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , arraySize , assetDoc ( name , docs ) ) ; \
addProtectedField ( assetText ( name , Asset ) , TypeImageAssetId , Offset ( m # # name # # AssetId , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , arraySize , assetDoc ( name , asset docs . ) ) ;
# else
# define INITPERSISTFIELD_IMAGEASSET_ARRAY(name, arraySize, consoleClass, docs) \
addProtectedField ( # name , TypeImageFilename , Offset ( m # # name # # Name , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , arraySize , assetDoc ( name , docs ) , AbstractClassRep : : FIELD_HideInInspectors ) ; \
addProtectedField ( assetText ( name , Asset ) , TypeImageAssetId , Offset ( m # # name # # AssetId , consoleClass ) , _set # # name # # Data , & defaultProtectedGetFn , arraySize , assetDoc ( name , asset docs . ) ) ;
2018-01-28 14:48:02 -06:00
# endif
2021-07-19 01:07:08 -05:00
# define CLONE_IMAGEASSET_ARRAY(name, index) \
2021-07-20 20:05:49 -05:00
{ \
2021-07-19 01:07:08 -05:00
m # # name # # Name [ index ] = other . m # # name # # Name [ index ] ; \
m # # name # # AssetId [ index ] = other . m # # name # # AssetId [ index ] ; \
2021-07-20 20:05:49 -05:00
m # # name # # Asset [ index ] = other . m # # name # # Asset [ index ] ; \
}
2021-07-19 01:07:08 -05:00
# define LOAD_IMAGEASSET_ARRAY(name, index)\
if ( m # # name # # AssetId [ index ] ! = StringTable - > EmptyString ( ) ) \
{ \
S32 assetState = ImageAsset : : getAssetById ( m # # name # # AssetId [ index ] , & m # # name # # Asset [ index ] ) ; \
if ( assetState = = ImageAsset : : Ok ) \
{ \
m # # name # # Name [ index ] = StringTable - > EmptyString ( ) ; \
} \
else Con : : warnf ( " Warning: %s::LOAD_IMAGEASSET(%s)-%s " , mClassName , m # # name # # AssetId [ index ] , ImageAsset : : getAssetErrstrn ( assetState ) . c_str ( ) ) ; \
}
# define PACKDATA_IMAGEASSET_ARRAY(name, index)\
if ( stream - > writeFlag ( m # # name # # Asset [ index ] . notNull ( ) ) ) \
{ \
stream - > writeString ( m # # name # # Asset [ index ] . getAssetId ( ) ) ; \
} \
else \
stream - > writeString ( m # # name # # Name [ index ] ) ;
# define UNPACKDATA_IMAGEASSET_ARRAY(name, index)\
if ( stream - > readFlag ( ) ) \
{ \
m # # name # # AssetId [ index ] = stream - > readSTString ( ) ; \
_set # # name ( m # # name # # AssetId [ index ] , index ) ; \
} \
else \
m # # name # # Name [ index ] = stream - > readSTString ( ) ;
# define PACK_IMAGEASSET_ARRAY(netconn, name, index)\
if ( stream - > writeFlag ( m # # name # # Asset [ index ] . notNull ( ) ) ) \
{ \
NetStringHandle assetIdStr = m # # name # # Asset [ index ] . getAssetId ( ) ; \
netconn - > packNetStringHandleU ( stream , assetIdStr ) ; \
} \
else \
stream - > writeString ( m # # name # # Name [ index ] ) ;
# define UNPACK_IMAGEASSET_ARRAY(netconn, name, index)\
if ( stream - > readFlag ( ) ) \
{ \
m # # name # # AssetId [ index ] = StringTable - > insert ( netconn - > unpackNetStringHandleU ( stream ) . getString ( ) ) ; \
_set # # name ( m # # name # # AssetId [ index ] , index ) ; \
} \
else \
m # # name # # Name [ index ] = stream - > readSTString ( ) ;
# pragma endregion