From: <axl...@us...> - 2010-05-23 15:56:11
|
Revision: 748 http://hgengine.svn.sourceforge.net/hgengine/?rev=748&view=rev Author: axlecrusher Date: 2010-05-23 15:56:04 +0000 (Sun, 23 May 2010) Log Message: ----------- Change asset creation to generate keys BEFORE asking for the asset Modified Paths: -------------- Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryNode.cpp Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2010-05-23 12:38:12 UTC (rev 747) +++ Mercury2/src/MercuryAsset.cpp 2010-05-23 15:56:04 UTC (rev 748) @@ -154,14 +154,14 @@ return *instance; } -bool AssetFactory::RegisterFactoryCallback(const MString & type, MAutoPtr< MercuryAsset > (*functor)( const MString &, bool ) ) +bool AssetFactory::RegisterFactoryCallback(const MString & type, MAutoPtr< MercuryAsset > (*functor)( const MString &, bool, const XMLNode* n ) ) { MString t = ToUpper( type ); m_factoryCallbacks[t] = functor; return true; } -MAutoPtr<MercuryAsset> AssetFactory::Generate(const MString& type, const MString& key, bool bInstanced ) +MAutoPtr<MercuryAsset> AssetFactory::Generate(const MString& type, const MString& key, bool bInstanced, const XMLNode* n ) { MString t = ToUpper( type ); @@ -172,11 +172,11 @@ } printf( "Asset (%s) not found, generating\n", (t+key).c_str() ); - MAutoPtr< MercuryAsset > (**generator)( const MString &, bool ) = m_factoryCallbacks.get( t ); + MAutoPtr< MercuryAsset > (**generator)( const MString &, bool, const XMLNode* n ) = m_factoryCallbacks.get( t ); if( generator ) { - MAutoPtr< MercuryAsset > g = (**generator)(key, bInstanced); + MAutoPtr< MercuryAsset > g = (**generator)(key, bInstanced, n); AddAssetInstance( t+key, g.Ptr() ); g->slType = g->GetType(); return g; Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2010-05-23 12:38:12 UTC (rev 747) +++ Mercury2/src/MercuryAsset.h 2010-05-23 15:56:04 UTC (rev 748) @@ -78,6 +78,7 @@ virtual MercuryAssetInstance * MakeAssetInstance( MercuryNode * ParentNode ); + static MString GenKey(const MString& k, const XMLNode* n) { return k; } GENRTTI( MercuryAsset ); const char * slType; //Tricky - we need to know our type in the destructor. Don't touch this. @@ -145,9 +146,9 @@ { public: static AssetFactory& GetInstance(); - bool RegisterFactoryCallback(const MString& type, MAutoPtr< MercuryAsset > (*)( const MString &, bool ) ); + bool RegisterFactoryCallback(const MString& type, MAutoPtr< MercuryAsset > (*)( const MString &, bool, const XMLNode* ) ); - MAutoPtr<MercuryAsset> Generate(const MString& type, const MString& key, bool bInstanced = true ); + MAutoPtr<MercuryAsset> Generate(const MString& type, const MString& key, bool bInstanced = true, const XMLNode* n = NULL ); void AddAssetInstance(const MString& key, MercuryAsset* asset); void RemoveAssetInstance(const MString& key); @@ -155,7 +156,7 @@ private: MAutoPtr< MercuryAsset > LocateAsset( const MString& key ) { MAutoPtr< MercuryAsset > * a = m_assetInstances.get( key ); return a?(*a):0; } - MHash< MAutoPtr< MercuryAsset > (*)( const MString &, bool ) > m_factoryCallbacks; + MHash< MAutoPtr< MercuryAsset > (*)( const MString &, bool, const XMLNode* ) > m_factoryCallbacks; //the actual storage point is in MercuryAssetInstance MHash< MAutoPtr< MercuryAsset > > m_assetInstances; @@ -167,7 +168,7 @@ static InstanceCounter<AssetFactory> AFcounter("AssetFactory"); #define REGISTER_ASSET_TYPE(class)\ - MAutoPtr<MercuryAsset> FactoryFunct##class( const MString & key, bool bInstanced ) { return new class( key, bInstanced ); } \ + MAutoPtr<MercuryAsset> FactoryFunct##class( const MString & key, bool bInstanced, const XMLNode* n) { return new class( class::GenKey(key,n), bInstanced ); } \ bool GlobalRegisterSuccess##class = AssetFactory::GetInstance().RegisterFactoryCallback(#class, FactoryFunct##class); #define CLASS_HELPERS(baseClass)\ Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2010-05-23 12:38:12 UTC (rev 747) +++ Mercury2/src/MercuryNode.cpp 2010-05-23 15:56:04 UTC (rev 748) @@ -306,7 +306,8 @@ else if ( child.Name() == "asset" ) { MString key = child.Attribute("file"); - MAutoPtr< MercuryAsset > asset( AssetFactory::GetInstance().Generate( child.Attribute("type"), key ) ); + + MAutoPtr< MercuryAsset > asset( AssetFactory::GetInstance().Generate( child.Attribute("type"), key, true, &child ) ); if ( asset.IsValid() ) { asset->LoadFromXML( child ); Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2010-05-23 12:38:12 UTC (rev 747) +++ Mercury2/src/Texture.cpp 2010-05-23 15:56:04 UTC (rev 748) @@ -152,10 +152,10 @@ if( sNewKey == m_path && GetLoadState() != NONE ) return true; - if ( m_dynamic ) - MakeDynamic( 0, 0, RGBA, sNewKey ); + if ( !m_dynamic ) + LoadImagePath( sNewKey ); else - LoadImagePath( sNewKey ); +// MakeDynamic( 0, 0, RGBA, sNewKey ); if( sNewKey != m_path ) return MercuryAsset::ChangeKey( sNewKey ); @@ -320,6 +320,18 @@ LoadImagePath(m_path); } +MString Texture::GenKey(const MString& k, const XMLNode* n) +{ + bool dynamic = false; + if (n) + { + const XMLNode& node = *n; + LOAD_FROM_XML( "dynamic", dynamic, StrToBool ); + } + if (dynamic) return "DYNATEXT"+k; + return k; +} + MAutoPtr< Texture > Texture::LoadFromFile(const MString& path) { MAutoPtr< MercuryAsset > t( AssetFactory::GetInstance().Generate("Texture", path) ); Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2010-05-23 12:38:12 UTC (rev 747) +++ Mercury2/src/Texture.h 2010-05-23 15:56:04 UTC (rev 748) @@ -46,6 +46,8 @@ static void ApplyActiveTextures(uint16_t stride, uint8_t uvByteOffset); static void DisableUnusedTextures(); + static MString GenKey(const MString& k, const XMLNode* n); + void SetFilter( TextureFilterMode t ) { m_tFilterMode = t; } GENRTTI( Texture ); protected: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |