first finished TileFont::Registry/Unregistry functions. but it not test.
This commit is contained in:
parent
18b00d40fe
commit
cbd3598ebb
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit fbb3c6d13c17d9d5d6e2fba16f1a9614c5c9cf26
|
Subproject commit d4459cf4cd00f324f46fdb80522b8eb3c0beaea0
|
@ -3,103 +3,12 @@
|
|||||||
|
|
||||||
#include<hgl/graph/TileData.h>
|
#include<hgl/graph/TileData.h>
|
||||||
#include<hgl/graph/font/FontSource.h>
|
#include<hgl/graph/font/FontSource.h>
|
||||||
|
#include<hgl/type/ResPool.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
template<typename T> struct RefData
|
|
||||||
{
|
|
||||||
int ref_count;
|
|
||||||
T data;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
RefData(const T &value)
|
|
||||||
{
|
|
||||||
ref_count=1;
|
|
||||||
data=value;
|
|
||||||
}
|
|
||||||
};//template<typename T> struct RefData
|
|
||||||
|
|
||||||
template<typename T> class DataPool
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
DataPool();
|
|
||||||
virtual ~DataPool()=default;
|
|
||||||
|
|
||||||
virtual bool Acquire(T &)=0;
|
|
||||||
virtual void Release(const T)=0;
|
|
||||||
};//
|
|
||||||
|
|
||||||
template<typename K,typename V> class ResPool
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
|
|
||||||
using ActiveItem=RefData<V>;
|
|
||||||
|
|
||||||
DataPool<V> *pool;
|
|
||||||
|
|
||||||
MapObject<K,ActiveItem> active_items; ///<活跃的数据
|
|
||||||
Map<K,V> idle_items; ///<引用计数为0的
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
ResPool(DataPool<V> *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<typename K,typename V> class ResPool
|
|
||||||
|
|
||||||
using TileResPool=ResPool<u32char,TileObject *>;
|
using TileResPool=ResPool<u32char,TileObject *>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,8 +20,7 @@ namespace hgl
|
|||||||
FontSource *source;
|
FontSource *source;
|
||||||
TileData *tile_data;
|
TileData *tile_data;
|
||||||
|
|
||||||
DataPool<TileObject *> *to_pool;
|
TileResPool to_res;
|
||||||
TileResPool *to_res;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -6,31 +6,6 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
namespace
|
|
||||||
{
|
|
||||||
using TileObjectPointer=TileObject *;
|
|
||||||
|
|
||||||
class TileObjectPool:public DataPool<TileObjectPointer>
|
|
||||||
{
|
|
||||||
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<TileObjectPointer>
|
|
||||||
}//namespace
|
|
||||||
|
|
||||||
TileFont::TileFont(TileData *td,FontSource *fs)
|
TileFont::TileFont(TileData *td,FontSource *fs)
|
||||||
{
|
{
|
||||||
tile_data=td;
|
tile_data=td;
|
||||||
@ -40,16 +15,10 @@ namespace hgl
|
|||||||
source=fs;
|
source=fs;
|
||||||
source->RefAcquire(this);
|
source->RefAcquire(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
to_pool=new TileObjectPool(tile_data);
|
|
||||||
to_res=new TileResPool(to_pool);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TileFont::~TileFont()
|
TileFont::~TileFont()
|
||||||
{
|
{
|
||||||
delete to_res;
|
|
||||||
delete to_pool;
|
|
||||||
|
|
||||||
if(source)
|
if(source)
|
||||||
source->RefRelease(this);
|
source->RefRelease(this);
|
||||||
|
|
||||||
@ -70,14 +39,57 @@ namespace hgl
|
|||||||
|
|
||||||
for(uint i=0;i<ch_list.GetCount();i++)
|
for(uint i=0;i<ch_list.GetCount();i++)
|
||||||
{
|
{
|
||||||
if(!to_res->Get(*cp,to))
|
if(!to_res.KeyExist(*cp))
|
||||||
new_chars.Add(*cp);
|
new_chars.Add(*cp);
|
||||||
|
|
||||||
cp++;
|
cp++;
|
||||||
}
|
}
|
||||||
|
|
||||||
tile_data->BeginCommit();
|
if(new_chars.GetCount()>tile_data->GetFreeCount()) //剩余空间不够了
|
||||||
tile_data->EndCommit();
|
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;i<ch_list.GetCount();i++)
|
||||||
|
{
|
||||||
|
if(!to_res.Get(*cp,to))
|
||||||
|
{
|
||||||
|
bmp=source->GetCharBitmap(*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;i<ch_list.GetCount();i++)
|
||||||
|
{
|
||||||
|
to_res.Get(*cp,to);
|
||||||
|
++cp;
|
||||||
|
|
||||||
|
*tp=to->uv_float;
|
||||||
|
++tp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,6 +98,13 @@ namespace hgl
|
|||||||
*/
|
*/
|
||||||
void TileFont::Unregistry(const List<u32char> &ch_list)
|
void TileFont::Unregistry(const List<u32char> &ch_list)
|
||||||
{
|
{
|
||||||
|
const u32char *cp=ch_list.GetData();
|
||||||
|
|
||||||
|
for(uint i=0;i<ch_list.GetCount();i++)
|
||||||
|
{
|
||||||
|
to_res.Release(*cp);
|
||||||
|
++cp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user