From 0f1d127726ee30aaefd8a47ab1becf6eec077949 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Thu, 17 Jan 2019 17:01:06 +0100 Subject: [PATCH] blitz3d/cachedtexture: Rename class to Factory, Rep to CachedTexture --- blitz3d/cachedtexture.cpp | 38 +++++++++++++++++++------------------- blitz3d/cachedtexture.h | 22 +++++++++++----------- blitz3d/texture.cpp | 4 ++-- blitz3d/texture.h | 2 +- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/blitz3d/cachedtexture.cpp b/blitz3d/cachedtexture.cpp index 9c8cd98..88e02b3 100644 --- a/blitz3d/cachedtexture.cpp +++ b/blitz3d/cachedtexture.cpp @@ -7,17 +7,17 @@ int active_texs; extern gxRuntime *gx_runtime; extern gxGraphics *gx_graphics; -set CachedTexture::rep_set; +set CachedTextureFactory::rep_set; static string path; -struct CachedTexture::Rep{ +struct CachedTextureFactory::CachedTexture{ int ref_cnt; string file; int flags,w,h,first; vector frames; - Rep( int w,int h,int flags,int cnt ): + CachedTexture( int w,int h,int flags,int cnt ): ref_cnt(1),flags(flags),w(w),h(h),first(0){ ++active_texs; while( cnt-->0 ){ @@ -27,7 +27,7 @@ struct CachedTexture::Rep{ } } - Rep( const string &f,int flags,int w,int h,int first,int cnt ): + CachedTexture( const string &f,int flags,int w,int h,int first,int cnt ): ref_cnt(1),file(f),flags(flags),w(w),h(h),first(first){ ++active_texs; if( !(flags & gxCanvas::CANVAS_TEX_CUBE) ){ @@ -87,16 +87,16 @@ struct CachedTexture::Rep{ gx_graphics->freeCanvas( t ); } - ~Rep(){ + ~CachedTexture(){ --active_texs; for( int k=0;kfreeCanvas( frames[k] ); } }; -CachedTexture::Rep *CachedTexture::findRep( const string &f,int flags,int w,int h,int first,int cnt ){ - set::const_iterator it; +CachedTextureFactory::CachedTexture *CachedTextureFactory::findRep( const string &f,int flags,int w,int h,int first,int cnt ){ + set::const_iterator it; for( it=rep_set.begin();it!=rep_set.end();++it ){ - Rep *rep=*it; + CachedTexture *rep=*it; if( rep->file==f && rep->flags==flags && rep->w==w && rep->h==h && rep->first==first && rep->frames.size()==cnt ){ ++rep->ref_cnt;return rep; } @@ -104,17 +104,17 @@ CachedTexture::Rep *CachedTexture::findRep( const string &f,int flags,int w,int return 0; } -CachedTexture::CachedTexture( int w,int h,int flags,int cnt ): -rep(new Rep(w,h,flags,cnt)){ +CachedTextureFactory::CachedTextureFactory( int w,int h,int flags,int cnt ): +rep(new CachedTexture(w,h,flags,cnt)){ } -CachedTexture::CachedTexture( const string &f_,int flags,int w,int h,int first,int cnt ){ +CachedTextureFactory::CachedTextureFactory( const string &f_,int flags,int w,int h,int first,int cnt ){ string f=f_; if( f.substr(0,2)==".\\" ) f=f.substr(2); if( path.size() ){ string t=path+tolower( filenamefile( f ) ); if( rep=findRep( t,flags,w,h,first,cnt ) ) return; - rep=new Rep( t,flags,w,h,first,cnt ); + rep=new CachedTexture( t,flags,w,h,first,cnt ); if( rep->frames.size() ){ rep_set.insert( rep ); return; @@ -123,23 +123,23 @@ CachedTexture::CachedTexture( const string &f_,int flags,int w,int h,int first,i } string t=tolower( fullfilename( f ) ); if( rep=findRep( t,flags,w,h,first,cnt ) ) return; - rep=new Rep( t,flags,w,h,first,cnt ); + rep=new CachedTexture( t,flags,w,h,first,cnt ); rep_set.insert( rep ); } -CachedTexture::CachedTexture( const CachedTexture &t ): +CachedTextureFactory::CachedTextureFactory( const CachedTextureFactory &t ): rep(t.rep){ ++rep->ref_cnt; } -CachedTexture::~CachedTexture(){ +CachedTextureFactory::~CachedTextureFactory(){ if( !--rep->ref_cnt ){ rep_set.erase( rep ); delete rep; } } -CachedTexture &CachedTexture::operator=( const CachedTexture &t ){ +CachedTextureFactory &CachedTextureFactory::operator=( const CachedTextureFactory &t ){ ++t.rep->ref_cnt; if( !--rep->ref_cnt ){ rep_set.erase( rep ); @@ -149,15 +149,15 @@ CachedTexture &CachedTexture::operator=( const CachedTexture &t ){ return *this; } -string CachedTexture::getName()const{ +string CachedTextureFactory::getName()const{ return rep->file; } -const vector &CachedTexture::getFrames()const{ +const vector &CachedTextureFactory::getFrames()const{ return rep->frames; } -void CachedTexture::setPath( const string &t ){ +void CachedTextureFactory::setPath( const string &t ){ path=tolower(t); if( int sz=path.size() ){ if( path[sz-1]!='/' && path[sz-1]!='\\' ) path+='\\'; diff --git a/blitz3d/cachedtexture.h b/blitz3d/cachedtexture.h index aed667a..2241867 100644 --- a/blitz3d/cachedtexture.h +++ b/blitz3d/cachedtexture.h @@ -4,30 +4,30 @@ #include "../gxruntime/gxcanvas.h" -class CachedTexture{ +class CachedTextureFactory{ public: - CachedTexture( int w,int h,int flags,int cnt ); - CachedTexture( const string &f,int flags,int w,int h,int first,int cnt ); - CachedTexture( const CachedTexture &t ); - ~CachedTexture(); + CachedTextureFactory( int w,int h,int flags,int cnt ); + CachedTextureFactory( const string &f,int flags,int w,int h,int first,int cnt ); + CachedTextureFactory( const CachedTextureFactory &t ); + ~CachedTextureFactory(); - CachedTexture &operator=( const CachedTexture &t ); + CachedTextureFactory &operator=( const CachedTextureFactory &t ); string getName()const; const vector &getFrames()const; - bool operator<( const CachedTexture &t )const{ return rep rep_set; + static set rep_set; }; #endif diff --git a/blitz3d/texture.cpp b/blitz3d/texture.cpp index 8e12e6a..2ba1c7b 100644 --- a/blitz3d/texture.cpp +++ b/blitz3d/texture.cpp @@ -32,7 +32,7 @@ static int filterFile(const string &t, int flags) { struct Texture::Rep { int ref_cnt; - CachedTexture cached_tex; + CachedTextureFactory cached_tex; vector tex_frames; int tex_blend, tex_flags; @@ -154,7 +154,7 @@ int Texture::getCanvasFlags()const { return rep && rep->tex_frames.size() ? rep->tex_frames[0]->getFlags() : 0; } -CachedTexture *Texture::getCachedTexture()const { +CachedTextureFactory *Texture::getCachedTexture()const { return rep ? &rep->cached_tex : 0; } diff --git a/blitz3d/texture.h b/blitz3d/texture.h index 0d2a09e..8aeed77 100644 --- a/blitz3d/texture.h +++ b/blitz3d/texture.h @@ -30,7 +30,7 @@ public: const gxScene::Matrix *getMatrix()const; int getBlend()const; int getFlags()const; - CachedTexture *getCachedTexture()const; + CachedTextureFactory *getCachedTexture()const; bool isTransparent()const; bool operator<( const Texture &t )const;