update TileFont codes
This commit is contained in:
parent
1f80f793ac
commit
18b00d40fe
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit 5866f9238750b11ddd925d51201da788cb234d7e
|
||||
Subproject commit fbb3c6d13c17d9d5d6e2fba16f1a9614c5c9cf26
|
@ -12,12 +12,15 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
using TileUVPixel=RectScope2i;
|
||||
using TileUVFloat=RectScope2d;
|
||||
|
||||
struct TileObject
|
||||
{
|
||||
int col,row; //当前tile在整个纹理中的tile位置
|
||||
|
||||
RectScope2i uv_pixel; //以象素为单位的tile位置和尺寸
|
||||
RectScope2d uv_float; //以浮点为单位的tile位置和尺寸
|
||||
TileUVPixel uv_pixel; //以象素为单位的tile位置和尺寸
|
||||
TileUVFloat uv_float; //以浮点为单位的tile位置和尺寸
|
||||
};//struct TileObject
|
||||
|
||||
/**
|
||||
@ -69,6 +72,8 @@ namespace hgl
|
||||
|
||||
TileObject *Commit(const void *,const uint,const int=-1,const int=-1); ///<提交一个Tile
|
||||
TileObject *Commit(BitmapData *bmp){return this->Commit(bmp->data,bmp->total_bytes,bmp->width,bmp->height);}///<提交一个Tile
|
||||
|
||||
TileObject *Acquire(); ///<请求一个Tile
|
||||
bool Change(TileObject *,const void *,const uint,const int=-1,const int=-1); ///<更改一个Tile的数据内容
|
||||
|
||||
int EndCommit();
|
||||
|
@ -3,27 +3,104 @@
|
||||
|
||||
#include<hgl/graph/TileData.h>
|
||||
#include<hgl/graph/font/FontSource.h>
|
||||
#include<hgl/type/ResPoolManage.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class TileObjectPool
|
||||
template<typename T> struct RefData
|
||||
{
|
||||
TileData *tile_data;
|
||||
int ref_count;
|
||||
T data;
|
||||
|
||||
public:
|
||||
|
||||
TileObject *Acquire();
|
||||
void Release(TileObject *);
|
||||
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:
|
||||
|
||||
TileObjectPool(TileData *td):tile_data(td);
|
||||
};
|
||||
ResPool(DataPool<V> *dp):pool(dp){}
|
||||
virtual ~ResPool()=default;
|
||||
|
||||
using TileObjectManage=_ResPoolManage<u32char,TileObject *,TileObjectPool>;
|
||||
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 *>;
|
||||
|
||||
/**
|
||||
* Tile字符管理<br>
|
||||
@ -34,8 +111,8 @@ namespace hgl
|
||||
FontSource *source;
|
||||
TileData *tile_data;
|
||||
|
||||
TileObjectPool *tile_pool;
|
||||
TileObjectManage *ch_tile_pool;
|
||||
DataPool<TileObject *> *to_pool;
|
||||
TileResPool *to_res;
|
||||
|
||||
public:
|
||||
|
||||
@ -47,7 +124,7 @@ namespace hgl
|
||||
TileFont(TileData *td,FontSource *fs);
|
||||
virtual ~TileFont();
|
||||
|
||||
bool Registry(List<RectScope2f> &,const List<u32char> &); ///<注册要使用的字符
|
||||
bool Registry(List<TileUVFloat> &,const List<u32char> &); ///<注册要使用的字符
|
||||
void Unregistry(const List<u32char> &); ///<注销要使用的字符
|
||||
};//class TileFont
|
||||
}//namespace graph
|
||||
|
@ -147,6 +147,16 @@ namespace hgl
|
||||
return(obj);
|
||||
}
|
||||
|
||||
TileObject *TileData::Acquire()
|
||||
{
|
||||
TileObject *obj;
|
||||
|
||||
if(!to_pool.Get(obj))
|
||||
return(nullptr);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个Tile
|
||||
* @param obj 要删除的Tile的对象指针
|
||||
|
@ -6,13 +6,30 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
TileObject *TileObjectPool::Acquire()
|
||||
namespace
|
||||
{
|
||||
}
|
||||
using TileObjectPointer=TileObject *;
|
||||
|
||||
void TileObjectPool::Release(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)
|
||||
{
|
||||
@ -21,22 +38,22 @@ namespace hgl
|
||||
if(fs)
|
||||
{
|
||||
source=fs;
|
||||
source->RefAcquire(this);
|
||||
source->RefAcquire(this);
|
||||
}
|
||||
|
||||
tile_pool=new TileObjectPool(tile_data);
|
||||
ch_tile_pool=new TileObjectManage(tile_pool);
|
||||
to_pool=new TileObjectPool(tile_data);
|
||||
to_res=new TileResPool(to_pool);
|
||||
}
|
||||
|
||||
TileFont::~TileFont()
|
||||
{
|
||||
delete ch_tile_pool;
|
||||
delete tile_pool;
|
||||
delete to_res;
|
||||
delete to_pool;
|
||||
|
||||
if(source)
|
||||
source->RefRelease(this);
|
||||
|
||||
SAFE_CLEAR(tile_data);
|
||||
delete tile_data;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,9 +61,23 @@ namespace hgl
|
||||
* @param rs 每个字符在纹理中的UV坐标
|
||||
* @param ch_list 要注册的字符列表
|
||||
*/
|
||||
bool TileFont::Registry(List<RectScope2f> &rs,const List<u32char> &ch_list)
|
||||
bool TileFont::Registry(List<TileUVFloat> &rs,const List<u32char> &ch_list)
|
||||
{
|
||||
|
||||
const u32char *cp=ch_list.GetData();
|
||||
TileObject *to;
|
||||
|
||||
List<u32char> new_chars;
|
||||
|
||||
for(uint i=0;i<ch_list.GetCount();i++)
|
||||
{
|
||||
if(!to_res->Get(*cp,to))
|
||||
new_chars.Add(*cp);
|
||||
|
||||
cp++;
|
||||
}
|
||||
|
||||
tile_data->BeginCommit();
|
||||
tile_data->EndCommit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user