From: <axl...@us...> - 2008-12-31 15:02:39
|
Revision: 127 http://hgengine.svn.sourceforge.net/hgengine/?rev=127&view=rev Author: axlecrusher Date: 2008-12-31 15:02:36 +0000 (Wed, 31 Dec 2008) Log Message: ----------- instance models and change m_isLoaded to m_isInstanced, make the factory set the IsInstanced flag Modified Paths: -------------- Mercury2/scenegraph.xml Mercury2/src/HGMDLModel.cpp Mercury2/src/HGMDLModel.h Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/scenegraph.xml =================================================================== --- Mercury2/scenegraph.xml 2008-12-31 05:04:06 UTC (rev 126) +++ Mercury2/scenegraph.xml 2008-12-31 15:02:36 UTC (rev 127) @@ -26,4 +26,10 @@ <asset type="hgmdlmodel" file="beerhall.hgmdl"/> </node> </node> + <node type="rotatornode" movz="-2" movx="2" scalex="0.05" scaley="0.05" scalez="0.05" > + <node type="renderablenode"> + <asset type="texture" file="test.bmp"/> + <asset type="hgmdlmodel" file="beerhall.hgmdl"/> + </node> + </node> </SceneGraph> Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2008-12-31 05:04:06 UTC (rev 126) +++ Mercury2/src/HGMDLModel.cpp 2008-12-31 15:02:36 UTC (rev 127) @@ -2,20 +2,20 @@ REGISTER_ASSET_TYPE(HGMDLModel); +HGMDLModel::HGMDLModel() + :MercuryAsset() +{ +} + +HGMDLModel::~HGMDLModel() +{ + REMOVE_ASSET_INSTANCE(HGMDLModel, m_path); +} + void HGMDLModel::LoadFromXML(const XMLNode& node) { - if ( !node.Attribute("file").empty() ) - { - //FILE* f = fopen( node.Attribute("file").c_str(), "rb" ); - MercuryFile * f = FILEMAN.Open( node.Attribute("file") ); - if( !f ) - { - printf( "Could not open file: \"%s\" for model\n", node.Attribute("file").c_str() ); - return; - } - LoadModel( f ); - delete f; - } + MString path = node.Attribute("file"); + LoadHGMDL( path ); } void HGMDLModel::LoadModel(MercuryFile* hgmdl) @@ -59,8 +59,27 @@ m_meshes[i]->Render(node); } +void HGMDLModel::LoadHGMDL( const MString& path ) +{ + if ( m_isInstanced ) return; + if ( !path.empty() ) + { + ADD_ASSET_INSTANCE(HGMDLModel, path, this); + m_path = path; + MercuryFile * f = FILEMAN.Open( path ); + if( !f ) + { + printf( "Could not open file: \"%s\" for model\n", path.c_str() ); + return; + } + LoadModel( f ); + delete f; + } +} + HGMDLModel* HGMDLModel::Generate() { + printf("new HGMDL\n"); return new HGMDLModel(); } Modified: Mercury2/src/HGMDLModel.h =================================================================== --- Mercury2/src/HGMDLModel.h 2008-12-31 05:04:06 UTC (rev 126) +++ Mercury2/src/HGMDLModel.h 2008-12-31 15:02:36 UTC (rev 127) @@ -10,6 +10,8 @@ class HGMDLModel : public MercuryAsset { public: + HGMDLModel(); + ~HGMDLModel(); virtual void LoadFromXML(const XMLNode& node); @@ -19,6 +21,9 @@ virtual void Render(MercuryNode* node); private: + void LoadHGMDL( const MString& path ); + + MString m_path; std::vector< MAutoPtr< HGMDLMesh > > m_meshes; }; Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2008-12-31 05:04:06 UTC (rev 126) +++ Mercury2/src/MercuryAsset.cpp 2008-12-31 15:02:36 UTC (rev 127) @@ -1,6 +1,12 @@ #include <MercuryAsset.h> #include <RenderableNode.h> +MercuryAsset::MercuryAsset() + :m_isInstanced(false) +{ +} + + void MercuryAsset::Init(MercuryNode* node) { RenderableNode* rn; @@ -47,6 +53,7 @@ void AssetFactory::AddAssetInstance(const MString& key, MercuryAsset* asset) { + asset->IsInstanced(true); m_assetInstances[key] = asset; } @@ -54,7 +61,10 @@ { std::map<MString, MercuryAsset*>::iterator asset = m_assetInstances.find(key); if ( asset != m_assetInstances.end() ) + { m_assetInstances.erase( asset ); + printf("removed asset %s\n", key.c_str()); + } } std::map<MString, MercuryAsset*> AssetFactory::m_assetInstances; Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2008-12-31 05:04:06 UTC (rev 126) +++ Mercury2/src/MercuryAsset.h 2008-12-31 15:02:36 UTC (rev 127) @@ -9,6 +9,7 @@ class MercuryAsset : public RefBase { public: + MercuryAsset(); virtual ~MercuryAsset() {}; virtual void Init(MercuryNode* node); @@ -19,6 +20,10 @@ ///Loads an asset from an XMLAsset representing itself virtual void LoadFromXML(const XMLNode& node) {}; + + inline void IsInstanced(bool b) { m_isInstanced = b; } + protected: + bool m_isInstanced; }; class AssetFactory Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2008-12-31 05:04:06 UTC (rev 126) +++ Mercury2/src/Texture.cpp 2008-12-31 15:02:36 UTC (rev 127) @@ -12,7 +12,7 @@ REGISTER_ASSET_TYPE(Texture); Texture::Texture() - :m_raw(NULL),m_textureID(0),m_isLoaded(false) + :MercuryAsset(), m_raw(NULL),m_textureID(0) { if (!m_initTextureSuccess) { @@ -94,7 +94,6 @@ void Texture::LoadFromXML(const XMLNode& node) { - if (m_isLoaded) return; LoadImage( node.Attribute("file") ); } @@ -121,11 +120,11 @@ void Texture::LoadImage(const MString& path) { + if (m_isInstanced) return; if ( !path.empty() ) { - m_isLoaded = true; + ADD_ASSET_INSTANCE(Texture, path, this); m_filename = path; - ADD_ASSET_INSTANCE(Texture, m_filename, this); RawImageData* d = ImageLoader::GetInstance().LoadImage( m_filename ); if (d) LoadFromRaw( d ); } Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2008-12-31 05:04:06 UTC (rev 126) +++ Mercury2/src/Texture.h 2008-12-31 15:02:36 UTC (rev 127) @@ -37,7 +37,6 @@ static unsigned short m_activeTextures; MString m_filename; - bool m_isLoaded; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |