|
From: <axl...@us...> - 2010-01-11 22:31:14
|
Revision: 655
http://hgengine.svn.sourceforge.net/hgengine/?rev=655&view=rev
Author: axlecrusher
Date: 2010-01-11 22:31:04 +0000 (Mon, 11 Jan 2010)
Log Message:
-----------
ability for assets to reload if there is a newer version
Modified Paths:
--------------
Mercury2/src/FullscreenQuad.h
Mercury2/src/HGMDLModel.cpp
Mercury2/src/HGMDLModel.h
Mercury2/src/ImageLoader.cpp
Mercury2/src/MercuryAsset.cpp
Mercury2/src/MercuryAsset.h
Mercury2/src/MercuryVBO.h
Mercury2/src/Quad.h
Mercury2/src/RenderDeferredLights.h
Mercury2/src/Shader.cpp
Mercury2/src/Shader.h
Mercury2/src/StateChanger.h
Mercury2/src/Texture.cpp
Mercury2/src/Texture.h
Modified: Mercury2/src/FullscreenQuad.h
===================================================================
--- Mercury2/src/FullscreenQuad.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/FullscreenQuad.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -13,6 +13,10 @@
virtual void Render(const MercuryNode* node);
GENRTTI( FullscreenQuad );
+ protected:
+ virtual bool CheckForNewer() { return false; }
+ virtual void Reload() {};
+
private:
MercuryMatrix m_matrix;
};
Modified: Mercury2/src/HGMDLModel.cpp
===================================================================
--- Mercury2/src/HGMDLModel.cpp 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/HGMDLModel.cpp 2010-01-11 22:31:04 UTC (rev 655)
@@ -7,7 +7,7 @@
const uint16_t EXPCTMNRV = 3;
HGMDLModel::HGMDLModel( const MString & key, bool bInstanced )
- :MercuryAsset( key, bInstanced )
+ :MercuryAsset( key, bInstanced ), m_timeStamp( 0 )
{
}
@@ -17,12 +17,35 @@
void HGMDLModel::LoadFromXML(const XMLNode& node)
{
- MString path = node.Attribute("file");
+ LoadFromFile( node.Attribute("file") );
+ MercuryAsset::LoadFromXML( node );
+}
+
+
+void HGMDLModel::LoadFromFile(const MString& path)
+{
+ m_path = path;
ChangeKey( path );
+}
+
+bool HGMDLModel::CheckForNewer()
+{
+ uint32_t t = 0;
+ MercuryFile *f = FILEMAN.Open(m_path);
- MercuryAsset::LoadFromXML( node );
+ if (f)
+ {
+ t = f->GetModTime();
+ delete f;
+ }
+ return t != m_timeStamp;
}
+void HGMDLModel::Reload()
+{
+ LoadFromFile(m_path);
+}
+
void HGMDLModel::LoadModel(MercuryFile* hgmdl, HGMDLModel* model)
{
char fingerPrint[5];
Modified: Mercury2/src/HGMDLModel.h
===================================================================
--- Mercury2/src/HGMDLModel.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/HGMDLModel.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -12,6 +12,7 @@
~HGMDLModel();
virtual void LoadFromXML(const XMLNode& node);
+ void LoadFromFile(const MString& path);
static void LoadModel(MercuryFile* hgmdl, HGMDLModel* model);
@@ -21,11 +22,16 @@
virtual void Render(const MercuryNode* node);
GENRTTI( HGMDLModel );
protected:
+ virtual bool CheckForNewer();
+ virtual void Reload();
+
MVector< MAutoPtr< HGMDLMesh > > m_meshes;
private:
CLASS_HELPERS( MercuryAsset );
static void* LoaderThread(void* d);
+
+ uint32_t m_timeStamp;
};
Modified: Mercury2/src/ImageLoader.cpp
===================================================================
--- Mercury2/src/ImageLoader.cpp 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/ImageLoader.cpp 2010-01-11 22:31:04 UTC (rev 655)
@@ -56,11 +56,12 @@
if (i->first == t)
{
RawImageData* d = i->second(f);
- delete f;
+ SAFE_DELETE(f);
return d;
}
}
- delete f;
+
+ SAFE_DELETE(f);
return NULL;
}
Modified: Mercury2/src/MercuryAsset.cpp
===================================================================
--- Mercury2/src/MercuryAsset.cpp 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/MercuryAsset.cpp 2010-01-11 22:31:04 UTC (rev 655)
@@ -6,7 +6,7 @@
extern bool DOOCCLUSIONCULL;
MercuryAsset::MercuryAsset( const MString & key, bool bInstanced )
- :slType( 0 ), m_isInstanced(bInstanced), m_boundingVolume(NULL), m_path( key ), m_loadState(NONE), m_ignoreCull(false), m_iPasses( DEFAULT_PASSES )
+ :slType( 0 ), m_isInstanced(bInstanced), m_boundingVolume(NULL), m_path( key ), m_loadState(NONE), m_ignoreCull(false), m_iPasses( DEFAULT_PASSES ), m_lastNewerCheck(0)
{
}
@@ -53,6 +53,13 @@
void MercuryAsset::PreRender(const MercuryNode* node)
{
+ uint32_t t = time(0);
+ if ( CheckForNewer() && (m_lastNewerCheck < t) )
+ {
+ m_lastNewerCheck = t;
+ Reload();
+ }
+
/*
MercuryNode* n = const_cast<MercuryNode*>(node);
if ( m_boundingVolume )
Modified: Mercury2/src/MercuryAsset.h
===================================================================
--- Mercury2/src/MercuryAsset.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/MercuryAsset.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -84,14 +84,21 @@
protected:
void SetLoadState(LoadState ls); //thread safe
+ virtual bool CheckForNewer() = 0;
+ virtual void Reload() = 0;
+
bool m_isInstanced;
BoundingVolume* m_boundingVolume;
MString m_path;
+
private:
LoadState m_loadState;
MSemaphore m_lock;
bool m_ignoreCull;
unsigned short m_iPasses;
+
+ uint32_t m_lastNewerCheck;
+// uint32_t m_timeStamp; //creation timestamp of asset eg. file timestamp
};
/** This holds the per-instance data for each asset instance.
Modified: Mercury2/src/MercuryVBO.h
===================================================================
--- Mercury2/src/MercuryVBO.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/MercuryVBO.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -46,6 +46,10 @@
inline static void IncrementBatches() { ++m_vboBatches; }
GENRTTI( MercuryVBO );
+ protected:
+ virtual bool CheckForNewer() { return false; }
+ virtual void Reload() {};
+
private:
virtual void InitVBO();
static void* m_lastVBOrendered;
Modified: Mercury2/src/Quad.h
===================================================================
--- Mercury2/src/Quad.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/Quad.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -14,6 +14,9 @@
virtual bool ChangeKey( const MString & sDescription );
GENRTTI( Quad );
+ protected:
+ virtual bool CheckForNewer() { return false; }
+ virtual void Reload() {};
private:
bool m_bFlipV;
Modified: Mercury2/src/RenderDeferredLights.h
===================================================================
--- Mercury2/src/RenderDeferredLights.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/RenderDeferredLights.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -11,6 +11,9 @@
virtual void Render(const MercuryNode* node);
GENRTTI( RenderDeferredLights );
+ protected:
+ virtual bool CheckForNewer() { return false; }
+ virtual void Reload() {};
};
#endif
Modified: Mercury2/src/Shader.cpp
===================================================================
--- Mercury2/src/Shader.cpp 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/Shader.cpp 2010-01-11 22:31:04 UTC (rev 655)
@@ -384,16 +384,21 @@
return;
}
-void Shader::CheckForNewer( )
+void Shader::Reload()
{
+ DestroyShader( );
+ LoadShader( );
+}
+
+bool Shader::CheckForNewer()
+{
unsigned long iCurTimes[3];
GetTimeCodes( iCurTimes );
if( iCurTimes[0] != iTimeCode[0] || iCurTimes[1] != iTimeCode[1] || iCurTimes[2] != iTimeCode[2] )
- {
- DestroyShader( );
- LoadShader( );
- }
+ return true;
+
+ return false;
}
void Shader::GetTimeCodes( unsigned long * iOut )
Modified: Mercury2/src/Shader.h
===================================================================
--- Mercury2/src/Shader.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/Shader.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -90,6 +90,11 @@
///Explicitly get the OpenGL ProgramID in the event you need it for advanced techniques
unsigned int GetProgramID() { return iProgramID; }
inline static Shader* GetCurrentShader() { return CurrentShader; }
+
+ protected:
+ virtual bool CheckForNewer();
+ virtual void Reload();
+
private:
int32_t GetUniformLocation(const MString& n);
@@ -127,7 +132,7 @@
bool LinkShaders();
///Check for newer version of 'this' shader
- void CheckForNewer( );
+// void CheckForNewer( );
///Get the last modified time for sShaderName
/* This function takes on iOut as being where to put the last time the shader was modified.
Modified: Mercury2/src/StateChanger.h
===================================================================
--- Mercury2/src/StateChanger.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/StateChanger.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -64,6 +64,10 @@
virtual bool ChangeKey( const MString & sNewKey );
virtual bool LoadInternal( const MString & sFile );
GENRTTI( StateChanger );
+
+ protected:
+ virtual bool CheckForNewer() { return false; }
+ virtual void Reload() {};
private:
MVector< MAutoPtr< StateChange > > m_vStates;
Modified: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/Texture.cpp 2010-01-11 22:31:04 UTC (rev 655)
@@ -13,7 +13,7 @@
#define BUFFER_OFFSET(i) ((char*)NULL + (i))
Texture::Texture( const MString & key, bool bInstanced )
- :MercuryAsset( key, bInstanced ), m_raw(NULL),m_textureID(0),m_bDeleteRaw(true),m_dynamic(false), m_bClamp(true), m_tFilterMode(TF_LINEAR_MIPS)
+ :MercuryAsset( key, bInstanced ), m_raw(NULL),m_textureID(0),m_bDeleteRaw(true),m_dynamic(false), m_bClamp(true), m_tFilterMode(TF_LINEAR_MIPS), m_timeStamp(0)
{
if (!m_initTextureSuccess)
{
@@ -292,6 +292,27 @@
GLERRORCHECK;
}
+bool Texture::CheckForNewer()
+{
+ uint32_t timeStamp = m_timeStamp;
+
+ if (timeStamp == 0) return false;
+
+ MercuryFile *f = FILEMAN.Open(m_path);
+ if (f)
+ {
+ m_timeStamp = f->GetModTime();
+ delete f;
+ }
+
+ return timeStamp != m_timeStamp;
+}
+
+void Texture::Reload()
+{
+ LoadImagePath(m_path);
+}
+
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-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/Texture.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -47,9 +47,13 @@
static void DisableUnusedTextures();
void SetFilter( TextureFilterMode t ) { m_tFilterMode = t; }
+ GENRTTI( Texture );
+ protected:
+ virtual bool CheckForNewer();
+ virtual void Reload();
- GENRTTI( Texture );
private:
+
void LoadImagePath(const MString& path);
void BindTexture();
@@ -59,7 +63,7 @@
void Deactivate(uint32_t textureResource);
void InitiateBindCache();
-
+
RawImageData* m_raw;
uint32_t m_textureID;
@@ -75,7 +79,7 @@
bool m_dynamic;
bool m_bClamp;
TextureFilterMode m_tFilterMode;
-
+ uint32_t m_timeStamp;
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|