Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset Handling Refactor - For 4.2 #1343

Open
wants to merge 15 commits into
base: development
Choose a base branch
from
Prev Previous commit
Next Next commit
all DECLARE_IMAGEASSET refactored
  • Loading branch information
marauder2k7 committed Jan 23, 2025
commit fa8110ce8f87367f7a60db6fbb963ee64cfd39e4
17 changes: 5 additions & 12 deletions Engine/source/T3D/accumulationVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,17 @@ AccumulationVolume::AccumulationVolume()
mObjToWorld.identity();
mWorldToObj.identity();

// Accumulation Texture.
INIT_ASSET(Texture);

resetWorldBox();
}

AccumulationVolume::~AccumulationVolume()
{
mTexture = nullptr;
}

void AccumulationVolume::initPersistFields()
{
docsURL;
addProtectedField("textureAsset", TypeImageAssetId, Offset(mTextureAssetId, AccumulationVolume),
&_setTexture, &defaultProtectedGetFn, "Accumulation texture.");
addProtectedField( "texture", TypeStringFilename, Offset( mTextureName, AccumulationVolume ),
&_setTexture, &defaultProtectedGetFn, "Accumulation texture." );
INITPERSISTFIELD_IMAGEASSET_REFACTOR(Texture, AccumulationVolume, "Accumulation texture.")

Parent::initPersistFields();
}
Expand Down Expand Up @@ -236,7 +229,7 @@ U32 AccumulationVolume::packUpdate( NetConnection *connection, U32 mask, BitStre

if (stream->writeFlag(mask & InitialUpdateMask))
{
PACK_ASSET(connection, Texture);
PACK_ASSET_REFACTOR(connection, Texture);
}

return retMask;
Expand All @@ -248,7 +241,7 @@ void AccumulationVolume::unpackUpdate( NetConnection *connection, BitStream *str

if (stream->readFlag())
{
UNPACK_ASSET(connection, Texture);
UNPACK_ASSET_REFACTOR(connection, Texture);
//setTexture(mTextureName);
}
}
Expand Down Expand Up @@ -307,7 +300,7 @@ void AccumulationVolume::refreshVolumes()
if ( object.isNull() ) continue;

if ( volume->containsPoint(object->getPosition()) )
object->mAccuTex = volume->getTextureResource();
object->mAccuTex = volume->getTexture();
}
}
}
Expand Down Expand Up @@ -341,6 +334,6 @@ void AccumulationVolume::updateObject(SceneObject* object)
if ( volume.isNull() ) continue;

if ( volume->containsPoint(object->getPosition()) )
object->mAccuTex = volume->getTextureResource();
object->mAccuTex = volume->getTexture();
}
}
5 changes: 1 addition & 4 deletions Engine/source/T3D/accumulationVolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ class AccumulationVolume : public ScenePolyhedralSpace
// SceneSpace.
void _renderObject( ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat ) override;

DECLARE_IMAGEASSET(AccumulationVolume, Texture, onTextureChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_NET_SETGET(AccumulationVolume, Texture, -1);

void onTextureChanged() {}
DECLARE_IMAGEASSET_NET_REFACTOR(AccumulationVolume, Texture, GFXStaticTextureSRGBProfile, -1)

public:

Expand Down
2 changes: 1 addition & 1 deletion Engine/source/T3D/assets/ImageAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ const char* ImageAsset::getImageInfo()
return "";
}

DefineEngineMethod(ImageAsset, getImageFile, const char*, (), ,
DefineEngineMethod(ImageAsset, getImagePath, const char*, (), ,
"Gets the image filepath of this asset.\n"
"@return File path of the image file.")
{
Expand Down
32 changes: 32 additions & 0 deletions Engine/source/T3D/assets/ImageAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,38 @@ public:
m##name##Asset = _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 DECLARE_IMAGEASSET_NET_REFACTOR(className, name, profile, mask) \
private: \
AssetPtr<ImageAsset> m##name##Asset; \
public: \
void _set##name(StringTableEntry _in){ \
if(m##name##Asset.getAssetId() == _in) \
return; \
\
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry imageAssetId = ImageAsset::smNoImageAssetFallback; \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
imageAssetId = query.mAssetList[0]; \
} \
m##name##Asset = imageAssetId; \
} \
else \
{ \
m##name##Asset = _in; \
} \
setMaskBits(mask); \
}; \
\
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; } \
Expand Down
46 changes: 46 additions & 0 deletions Engine/source/T3D/assets/assetMacroHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,52 @@ if (m##name##AssetId != StringTable->EmptyString())\
m##name##Asset = other.m##name##Asset;\
m##name = other.m##name

// copy constructor refactor
#define CLONE_ASSET_REFACTOR(name) \
m##name##Asset = other.m##name##Asset;\

//network send - datablock refactor
#define PACKDATA_ASSET_REFACTOR(name)\
if (stream->writeFlag(m##name##Asset.notNull()))\
{\
stream->writeString(m##name##Asset.getAssetId());\
}

//network recieve - datablock
#define UNPACKDATA_ASSET_REFACTOR(name)\
if (stream->readFlag())\
{\
_set##name(stream->readSTString());\
}

//network send - object-instance
#define PACK_ASSET_REFACTOR(netconn, name)\
if (stream->writeFlag(m##name##Asset.notNull()))\
{\
NetStringHandle assetIdStr = m##name##Asset.getAssetId();\
netconn->packNetStringHandleU(stream, assetIdStr);\
}

//network recieve - object-instance
#define UNPACK_ASSET_REFACTOR(netconn, name)\
if (stream->readFlag())\
{\
_set##name(netconn->unpackNetStringHandleU(stream).getString());\
}

#define DEF_ASSET_BINDS_REFACTOR(className,name)\
DefineEngineMethod(className, get##name, StringTableEntry, (), , "get name")\
{\
return object->get##name##Asset()->getImageFile(); \
}\
DefineEngineMethod(className, get##name##Asset, StringTableEntry, (), , assetText(name, asset reference))\
{\
return object->_get##name(); \
}\
DefineEngineMethod(className, set##name, void, (const char* assetName), , assetText(name,assignment. first tries asset then flat file.))\
{\
object->_set##name(StringTable->insert(assetName));\
}
// addProtectedField acessors
#define DECLARE_ASSET_SETGET(className, name)\
static bool _set##name##Data(void* obj, const char* index, const char* data)\
Expand Down
34 changes: 9 additions & 25 deletions Engine/source/T3D/fx/particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ ParticleData::ParticleData()
animTexFramesString = NULL; // string of animation frame indices
animTexUVs = NULL; // array of tile vertex UVs

INIT_ASSET(Texture);
INIT_ASSET(TextureExt);

constrain_pos = false;
start_angle = 0.0f;
angle_variance = 0.0f;
Expand All @@ -149,12 +146,7 @@ void ParticleData::initPersistFields()
{
docsURL;
addGroup("Basic");
addProtectedField("textureName", TYPEID< StringTableEntry >(), Offset(mTextureName, ParticleData), _setTextureData, defaultProtectedGetFn,
"Texture file to use for this particle.", AbstractClassRep::FIELD_HideInInspectors);
addField("animTexName", TYPEID< StringTableEntry >(), Offset(mTextureName, ParticleData),
"@brief Texture file to use for this particle if animateTexture is true.\n\n"
"Deprecated. Use textureName instead.", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_IMAGEASSET(Texture, ParticleData, "Texture to use for this particle.");
INITPERSISTFIELD_IMAGEASSET_REFACTOR(Texture, ParticleData, "Texture to use for this particle.");
addField("useInvAlpha", TYPEID< bool >(), Offset(useInvAlpha, ParticleData),
"@brief Controls how particles blend with the scene.\n\n"
"If true, particles blend like ParticleBlendStyle NORMAL, if false, "
Expand Down Expand Up @@ -239,8 +231,7 @@ void ParticleData::initPersistFields()
endGroup("Over Time");

addGroup("AFX");
addProtectedField("textureExtName", TypeFilename, Offset(mTextureExtName, ParticleData), _setTextureExtData, &defaultProtectedGetFn, "", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_IMAGEASSET(TextureExt, ParticleData, "");
INITPERSISTFIELD_IMAGEASSET_REFACTOR(TextureExt, ParticleData, "");
addField("constrainPos", TypeBool, Offset(constrain_pos, ParticleData));
addField("angle", TypeF32, Offset(start_angle, ParticleData));
addField("angleVariance", TypeF32, Offset(angle_variance, ParticleData));
Expand Down Expand Up @@ -305,7 +296,7 @@ void ParticleData::packData(BitStream* stream)
stream->writeFloat( times[i], 8);
}

PACKDATA_ASSET(Texture);
PACKDATA_ASSET_REFACTOR(Texture);

for (i = 0; i < 4; i++)
mathWrite(*stream, texCoords[i]);
Expand All @@ -319,7 +310,7 @@ void ParticleData::packData(BitStream* stream)
stream->writeInt(framesPerSec, 8);
}

PACKDATA_ASSET(TextureExt);
PACKDATA_ASSET_REFACTOR(TextureExt);

stream->writeFlag(constrain_pos);
stream->writeFloat(start_angle/360.0f, 11);
Expand Down Expand Up @@ -390,7 +381,7 @@ void ParticleData::unpackData(BitStream* stream)
times[i] = stream->readFloat(8);
}

UNPACKDATA_ASSET(Texture);
UNPACKDATA_ASSET_REFACTOR(Texture);

for (i = 0; i < 4; i++)
mathRead(*stream, &texCoords[i]);
Expand All @@ -403,7 +394,7 @@ void ParticleData::unpackData(BitStream* stream)
framesPerSec = stream->readInt(8);
}

UNPACKDATA_ASSET(TextureExt);
UNPACKDATA_ASSET_REFACTOR(TextureExt);

constrain_pos = stream->readFlag();
start_angle = 360.0f*stream->readFloat(11);
Expand Down Expand Up @@ -698,13 +689,6 @@ bool ParticleData::reload(char errorBuffer[256])
{
bool error = false;

StringTableEntry particleTex = getTexture();

if (!_setTexture(particleTex))
{
dSprintf(errorBuffer, 256, "Missing particle texture: %s", particleTex);
}

/*
numFrames = 0;
for( S32 i=0; i<PDC_MAX_TEX; i++ )
Expand Down Expand Up @@ -775,12 +759,12 @@ ParticleData::ParticleData(const ParticleData& other, bool temp_clone) : SimData
animTexFramesString = other.animTexFramesString;
animTexFrames = other.animTexFrames; // -- parsed from animTexFramesString

CLONE_ASSET(Texture);
CLONE_ASSET_REFACTOR(Texture);

spinBias = other.spinBias;
randomizeSpinDir = other.randomizeSpinDir;

CLONE_ASSET(TextureExt);
CLONE_ASSET_REFACTOR(TextureExt);

constrain_pos = other.constrain_pos;
start_angle = other.start_angle;
Expand Down Expand Up @@ -816,4 +800,4 @@ void ParticleData::onPerformSubstitutions()
reload(errorBuffer);
}

DEF_ASSET_BINDS(ParticleData, Texture);
DEF_ASSET_BINDS_REFACTOR(ParticleData, Texture);
8 changes: 2 additions & 6 deletions Engine/source/T3D/fx/particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,11 @@ class ParticleData : public SimDataBlock
StringTableEntry animTexFramesString;
Vector<U8> animTexFrames;

DECLARE_IMAGEASSET(ParticleData, Texture, onImageChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(ParticleData, Texture);
DECLARE_IMAGEASSET_REFACTOR(ParticleData, Texture, GFXStaticTextureSRGBProfile)

static bool protectedSetSizes(void* object, const char* index, const char* data);
static bool protectedSetTimes(void* object, const char* index, const char* data);

void onImageChanged() {}

public:
ParticleData();
~ParticleData();
Expand All @@ -117,8 +114,7 @@ class ParticleData : public SimDataBlock
F32 spinBias;
bool randomizeSpinDir;
public:
DECLARE_IMAGEASSET(ParticleData, TextureExt, onImageChanged, GFXStaticTextureSRGBProfile);
DECLARE_ASSET_SETGET(ParticleData, TextureExt);
DECLARE_IMAGEASSET_REFACTOR(ParticleData, TextureExt,GFXStaticTextureSRGBProfile)

bool constrain_pos;
F32 start_angle;
Expand Down
6 changes: 3 additions & 3 deletions Engine/source/T3D/fx/particleEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,11 @@ bool ParticleEmitterData::preload(bool server, String &errorStr)
// otherwise, check that all particles refer to the same texture
else if (particleDataBlocks.size() > 1)
{
StringTableEntry txr_name = particleDataBlocks[0]->getTexture();
StringTableEntry txr_name = particleDataBlocks[0]->getTextureAsset()->getImageFile();
for (S32 i = 1; i < particleDataBlocks.size(); i++)
{
// warn if particle textures are inconsistent
if (particleDataBlocks[i]->getTexture() != txr_name)
if (particleDataBlocks[i]->getTextureAsset()->getImageFile() != txr_name)
{
Con::warnf(ConsoleLogEntry::General, "ParticleEmitterData(%s) particles reference different textures.", getName());
break;
Expand Down Expand Up @@ -1227,7 +1227,7 @@ void ParticleEmitter::prepRenderImage(SceneRenderState* state)
if (mDataBlock->textureHandle)
ri->diffuseTex = &*(mDataBlock->textureHandle);
else
ri->diffuseTex = &*(part_list_head.next->dataBlock->getTextureResource());
ri->diffuseTex = &*(part_list_head.next->dataBlock->getTexture());

ri->softnessDistance = mDataBlock->softnessDistance;

Expand Down
Loading