From cbd3598ebb38a5d0955ff58be22250e5de2a391d Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 1 Aug 2020 19:38:43 +0800 Subject: [PATCH] first finished TileFont::Registry/Unregistry functions. but it not test. --- CMCore | 2 +- inc/hgl/graph/font/TileFont.h | 96 +------------------------------- src/SceneGraph/font/TileFont.cpp | 87 ++++++++++++++++++----------- 3 files changed, 56 insertions(+), 129 deletions(-) diff --git a/CMCore b/CMCore index fbb3c6d1..d4459cf4 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit fbb3c6d13c17d9d5d6e2fba16f1a9614c5c9cf26 +Subproject commit d4459cf4cd00f324f46fdb80522b8eb3c0beaea0 diff --git a/inc/hgl/graph/font/TileFont.h b/inc/hgl/graph/font/TileFont.h index 63fc071b..883f5d5b 100644 --- a/inc/hgl/graph/font/TileFont.h +++ b/inc/hgl/graph/font/TileFont.h @@ -3,103 +3,12 @@ #include #include +#include namespace hgl { namespace graph { - template struct RefData - { - int ref_count; - T data; - - public: - - RefData(const T &value) - { - ref_count=1; - data=value; - } - };//template struct RefData - - template class DataPool - { - public: - - DataPool(); - virtual ~DataPool()=default; - - virtual bool Acquire(T &)=0; - virtual void Release(const T)=0; - };// - - template class ResPool - { - protected: - - using ActiveItem=RefData; - - DataPool *pool; - - MapObject active_items; ///<活跃的数据 - Map idle_items; ///<引用计数为0的 - - public: - - ResPool(DataPool *dp):pool(dp){} - virtual ~ResPool()=default; - - bool Get(const K &key,V &value) - { - ActiveItem *ai; - - if(active_items.Get(key,ai)) //在活跃列表中找 - { - ++ai->ref_count; - value=ai->data; - return(true); - } - - if(idle_items.Get(key,value)) //在限制列表中找 - { - active_items.Add(key,new ActiveItem(value)); - return(true); - } - - return(false); - } - - bool Create(const K &key,V &value) - { - if(!pool->Acquire(value)) - return(false); - - active_items.Add(key,new ActiveItem(value)); - return(true); - } - - void Release(const K &key) - { - int pos; - ActiveItem *ai; - - pos=active_items.GetValueAndSerial(key,ai); - - if(pos>0) - { - --ai->ref_count; - - if(ai->ref_count==0) - { - idle_items.Add(ai->data); - active_items.DeleteBySerial(pos); - } - - return; - } - } - };//template class ResPool - using TileResPool=ResPool; /** @@ -111,8 +20,7 @@ namespace hgl FontSource *source; TileData *tile_data; - DataPool *to_pool; - TileResPool *to_res; + TileResPool to_res; public: diff --git a/src/SceneGraph/font/TileFont.cpp b/src/SceneGraph/font/TileFont.cpp index 74c6f0ad..009f1b98 100644 --- a/src/SceneGraph/font/TileFont.cpp +++ b/src/SceneGraph/font/TileFont.cpp @@ -6,31 +6,6 @@ namespace hgl { namespace graph { - namespace - { - using TileObjectPointer=TileObject *; - - class TileObjectPool:public DataPool - { - TileData *tile_data; - - public: - - TileObjectPool(TileData *td):tile_data(td){} - - bool Acquire(TileObjectPointer &top) override - { - top=tile_data->Acquire(); - - return(top); - } - - void Release(TileObjectPointer) override - { - } - };//class TileObjectPool:public DataPool - }//namespace - TileFont::TileFont(TileData *td,FontSource *fs) { tile_data=td; @@ -40,16 +15,10 @@ namespace hgl source=fs; source->RefAcquire(this); } - - to_pool=new TileObjectPool(tile_data); - to_res=new TileResPool(to_pool); } TileFont::~TileFont() { - delete to_res; - delete to_pool; - if(source) source->RefRelease(this); @@ -70,14 +39,57 @@ namespace hgl for(uint i=0;iGet(*cp,to)) + if(!to_res.KeyExist(*cp)) new_chars.Add(*cp); cp++; } - tile_data->BeginCommit(); - tile_data->EndCommit(); + if(new_chars.GetCount()>tile_data->GetFreeCount()) //剩余空间不够了 + return(false); + + rs.ClearData(); + rs.SetCount(ch_list.GetCount()); + + FontBitmap *bmp; + TileUVFloat *tp=rs.GetData(); + cp=ch_list.GetData(); + + if(new_chars.GetCount()) + { + tile_data->BeginCommit(); + for(uint i=0;iGetCharBitmap(*cp); + to=tile_data->Commit( bmp->data, + bmp->metrics_info.w*bmp->metrics_info.h, + bmp->metrics_info.w,bmp->metrics_info.h); + + to_res.Add(*cp,to); + } + + ++cp; + + *tp=to->uv_float; + ++tp; + } + tile_data->EndCommit(); + } + else + { + for(uint i=0;iuv_float; + ++tp; + } + } + + return(true); } /** @@ -86,6 +98,13 @@ namespace hgl */ void TileFont::Unregistry(const List &ch_list) { + const u32char *cp=ch_list.GetData(); + + for(uint i=0;i