增加TileData

This commit is contained in:
2020-06-20 19:40:09 +08:00
parent d4bee40b78
commit c2a751bf68
4 changed files with 118 additions and 71 deletions

View File

@@ -0,0 +1,63 @@
#include<hgl/graph/TileData.h>
namespace hgl
{
namespace graph
{
namespace
{
void AnalyseSize(int &fw,int &fh,const int w,const int h,const int count,const int max_texture_size)
{
int total,tw,th,t;
fw=fh=0;
tw=max_texture_size;
while(tw>=w)
{
th=max_texture_size;
while(th>=h)
{
t=(tw/w)*(th/h);
if(!fw)
{
fw=tw;
fh=th;
total=t;
}
else
{
if(t==count)
{
//正好,就要这么大的
fw=tw;
fh=th;
return;
}
else
if(t>count) //要比要求的最大值大
{
if(t<total) //找到最接近最大值的
{
//比现在选中的更节省
fw=tw;
fh=th;
total=t;
}
}
}
th>>=1;
}
tw>>=1;
}
}//void AnalyseSize
}//namespace
}//namespace graph
}//namespace hgl