diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 4635a3223..4a90cabdb 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -618,7 +618,8 @@ public: 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 DECLARE_IMAGEASSET_NET_REFACTOR(className, name, profile, mask) \ + +#define DECLARE_IMAGEASSET_NET_REFACTOR(className, name, profile, mask) \ private: \ AssetPtr m##name##Asset; \ public: \ @@ -647,7 +648,8 @@ public: 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;} + 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.)); @@ -683,6 +685,39 @@ public: AssetPtr get##name##Asset(const U32& index) { return m##name##Asset[index]; } \ static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;} + +#define DECLARE_IMAGEASSET_ARRAY_NET_REFACTOR(className, name, profile, max, mask) \ +private: \ + AssetPtr m##name##Asset[max]; \ +public: \ + void _set##name(StringTableEntry _in, const U32& index){ \ + if(m##name##Asset[index].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[index] = imageAssetId; \ + } \ + else \ + { \ + m##name##Asset[index] = _in; \ + } \ + setMaskBits(mask); \ + }; \ + \ + inline StringTableEntry _get##name(const U32& index) const { return m##name##Asset[index].getAssetId(); } \ + GFXTexHandle get##name(const U32& index) { return m##name##Asset[index].notNull() ? m##name##Asset[index]->getTexture(&profile) : NULL; } \ + AssetPtr get##name##Asset(const U32& index) { return m##name##Asset[index]; } \ + static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;} + + #define INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(name, arraySize, consoleClass, docs) \ addProtectedField(assetText(name, Asset), TypeImageAssetPtrRefactor, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.)); diff --git a/Engine/source/T3D/assets/assetMacroHelpers.h b/Engine/source/T3D/assets/assetMacroHelpers.h index e706883b1..ebe777bf0 100644 --- a/Engine/source/T3D/assets/assetMacroHelpers.h +++ b/Engine/source/T3D/assets/assetMacroHelpers.h @@ -88,7 +88,7 @@ if (m##name##AssetId != StringTable->EmptyString())\ //network send - datablock #define PACKDATA_ASSET_ARRAY_REFACTOR(name, max)\ -for (i = 0; i < max; i++)\ +for (U32 i = 0; i < max; i++)\ {\ if (stream->writeFlag(m##name##Asset[i].notNull()))\ {\ @@ -98,7 +98,7 @@ for (i = 0; i < max; i++)\ //network recieve - datablock #define UNPACKDATA_ASSET_ARRAY_REFACTOR(name, max)\ -for (i = 0; i < max; i++)\ +for (U32 i = 0; i < max; i++)\ {\ if (stream->readFlag())\ {\ @@ -106,6 +106,27 @@ for (i = 0; i < max; i++)\ }\ } +//network send - object-instance +#define PACK_ASSET_ARRAY_REFACTOR(netconn, name, max)\ +for (U32 i = 0; i < max; i++)\ +{\ + if (stream->writeFlag(m##name##Asset[i].notNull()))\ + {\ + NetStringHandle assetIdStr = m##name##Asset[i].getAssetId();\ + netconn->packNetStringHandleU(stream, assetIdStr);\ + }\ +} + +//network recieve - object-instance +#define UNPACK_ASSET_ARRAY_REFACTOR(netconn, name, max)\ +for (U32 i = 0; i < max; i++)\ +{\ + if (stream->readFlag())\ + {\ + m##name##Asset[i] = StringTable->insert(netconn->unpackNetStringHandleU(stream).getString());\ + }\ +} + #define DEF_ASSET_BINDS_REFACTOR(className,name)\ DefineEngineMethod(className, get##name, StringTableEntry, (), , "get name")\ {\ diff --git a/Engine/source/T3D/fx/splash.cpp b/Engine/source/T3D/fx/splash.cpp index 205575672..1cc697d07 100644 --- a/Engine/source/T3D/fx/splash.cpp +++ b/Engine/source/T3D/fx/splash.cpp @@ -183,6 +183,8 @@ void SplashData::packData(BitStream* stream) stream->writeRangedU32(explosion->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast); } + PACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX); + S32 i; for( i=0; iwrite( times[i] ); } - - PACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX); } //-------------------------------------------------------------------------- @@ -236,6 +236,8 @@ void SplashData::unpackData(BitStream* stream) explosionId = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast ); } + UNPACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX); + U32 i; for( i=0; iread( ×[i] ); } - - UNPACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX); } //-------------------------------------------------------------------------- diff --git a/Engine/source/environment/basicClouds.cpp b/Engine/source/environment/basicClouds.cpp index b4b7a9765..2d3945c1d 100644 --- a/Engine/source/environment/basicClouds.cpp +++ b/Engine/source/environment/basicClouds.cpp @@ -98,9 +98,6 @@ BasicClouds::BasicClouds() mTexOffset[0].set( 0.5f, 0.5f ); mTexOffset[1].set( 0.5f, 0.5f ); mTexOffset[2].set( 0.5f, 0.5f ); - - for (U32 i=0; i< TEX_COUNT;i++) - INIT_IMAGEASSET_ARRAY(Texture, GFXStaticTextureSRGBProfile, i); } IMPLEMENT_CO_NETOBJECT_V1( BasicClouds ); @@ -177,7 +174,7 @@ void BasicClouds::initPersistFields() addField( "layerEnabled", TypeBool, Offset( mLayerEnabled, BasicClouds ), TEX_COUNT, "Enable or disable rendering of this layer." ); - INITPERSISTFIELD_IMAGEASSET_ARRAY(Texture, TEX_COUNT, BasicClouds, "Texture for this layer."); + INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(Texture, TEX_COUNT, BasicClouds, "Texture for this layer."); addField( "texScale", TypeF32, Offset( mTexScale, BasicClouds ), TEX_COUNT, "Texture repeat for this layer." ); @@ -215,12 +212,11 @@ U32 BasicClouds::packUpdate( NetConnection *conn, U32 mask, BitStream *stream ) { U32 retMask = Parent::packUpdate( conn, mask, stream ); + PACK_ASSET_ARRAY_REFACTOR(conn, Texture, TEX_COUNT) + for ( U32 i = 0; i < TEX_COUNT; i++ ) { stream->writeFlag( mLayerEnabled[i] ); - - PACK_ASSET_ARRAY(conn, Texture, i); - stream->write( mTexScale[i] ); mathWrite( *stream, mTexDirection[i] ); stream->write( mTexSpeed[i] ); @@ -236,12 +232,11 @@ void BasicClouds::unpackUpdate( NetConnection *conn, BitStream *stream ) { Parent::unpackUpdate( conn, stream ); + UNPACK_ASSET_ARRAY_REFACTOR(conn, Texture, TEX_COUNT) + for ( U32 i = 0; i < TEX_COUNT; i++ ) { mLayerEnabled[i] = stream->readFlag(); - - UNPACK_ASSET_ARRAY(conn, Texture, i); - stream->read( &mTexScale[i] ); mathRead( *stream, &mTexDirection[i] ); stream->read( &mTexSpeed[i] ); @@ -315,14 +310,14 @@ void BasicClouds::renderObject( ObjectRenderInst *ri, SceneRenderState *state, B for ( U32 i = 0; i < TEX_COUNT; i++ ) { - if ( !mLayerEnabled[i] ) + if ( !mLayerEnabled[i] || mTextureAsset[i].isNull()) continue; mShaderConsts->setSafe( mTexScaleSC, mTexScale[i] ); mShaderConsts->setSafe( mTexDirectionSC, mTexDirection[i] * mTexSpeed[i] ); mShaderConsts->setSafe( mTexOffsetSC, mTexOffset[i] ); - GFX->setTexture( mDiffuseMapSC->getSamplerRegister(), mTexture[i] ); + GFX->setTexture( mDiffuseMapSC->getSamplerRegister(), getTexture(i) ); GFX->setVertexBuffer( mVB[i] ); GFX->drawIndexedPrimitive( GFXTriangleList, 0, 0, smVertCount, 0, smTriangleCount ); @@ -337,13 +332,11 @@ void BasicClouds::_initTexture() { for ( U32 i = 0; i < TEX_COUNT; i++ ) { - if ( !mLayerEnabled[i] ) + if ( mLayerEnabled[i] && mTextureAsset[i].notNull()) { - mTexture[i] = NULL; - continue; + // load the resource. + getTexture(i); } - - _setTexture(getTexture(i), i); } } diff --git a/Engine/source/environment/basicClouds.h b/Engine/source/environment/basicClouds.h index bd67d1362..8157212ff 100644 --- a/Engine/source/environment/basicClouds.h +++ b/Engine/source/environment/basicClouds.h @@ -94,9 +94,8 @@ protected: static U32 smVertCount; static U32 smTriangleCount; - DECLARE_IMAGEASSET_ARRAY(BasicClouds, Texture, TEX_COUNT, onTextureChanged); - DECLARE_IMAGEASSET_ARRAY_NET_SETGET(BasicClouds, Texture, -1); - void onTextureChanged() {} + DECLARE_IMAGEASSET_ARRAY_NET_REFACTOR(BasicClouds, Texture, GFXStaticTextureSRGBProfile, TEX_COUNT, -1) + GFXStateBlockRef mStateblock; GFXShaderRef mShader; diff --git a/Engine/source/gui/editor/guiMenuBar.cpp b/Engine/source/gui/editor/guiMenuBar.cpp index e71ce80e6..399fc916d 100644 --- a/Engine/source/gui/editor/guiMenuBar.cpp +++ b/Engine/source/gui/editor/guiMenuBar.cpp @@ -515,10 +515,22 @@ void GuiMenuBar::processTick() void GuiMenuBar::insert(SimObject* pObject, S32 pos) { - PopupMenu* menu = dynamic_cast(pObject); + PopupMenu* menu = nullptr; + if (pObject != nullptr) + { + menu = dynamic_cast(pObject); + } + if (menu == nullptr) { - Con::errorf("GuiMenuBar::insert() - attempted to insert non-popupMenu object: %d", pObject->getId()); + if (pObject != nullptr) + { + Con::errorf("GuiMenuBar::insert() - attempted to insert non-popupMenu object: %d", pObject->getId()); + } + else + { + Con::errorf("GuiMenuBar::insert() - attempted to insert a nullptr object."); + } return; } @@ -541,10 +553,22 @@ void GuiMenuBar::insert(SimObject* pObject, S32 pos) void GuiMenuBar::remove(SimObject* pObject) { - PopupMenu* menu = dynamic_cast(pObject); + PopupMenu* menu = nullptr; + if (pObject != nullptr) + { + menu = dynamic_cast(pObject); + } + if (menu == nullptr) { - Con::errorf("GuiMenuBar::remove() - attempted to remove non-popupMenu object: %d", pObject->getId()); + if (pObject != nullptr) + { + Con::errorf("GuiMenuBar::insert() - attempted to insert non-popupMenu object: %d", pObject->getId()); + } + else + { + Con::errorf("GuiMenuBar::insert() - attempted to insert a nullptr object."); + } return; }