int _Height(Node *root)
	{
		if (NULL == root)
			return 0;
		if (NULL == root->pLeft && NULL == root->pRight)
			return 1;

		int left = _Height(root->pLeft);
		int right = _Height(root->pRight);
		
		return left > right ? left + 1 : right + 1;
	}
Пример #2
0
void ETextureThumbnail::Draw(HDC hdc, const Irect& R)
{
     if(0==m_Pixels.size())
     {
        u32                 image_w, image_h, image_a;
        xr_string fn_img    = EFS.ChangeFileExt(m_Name.c_str(),".tga");
        string_path fn;
        FS.update_path       (fn,_textures_,fn_img.c_str());

        if( !FS.exist(fn) )
        {
          fn_img    = EFS.ChangeFileExt(m_Name.c_str(),".dds");
          FS.update_path(fn,_game_textures_,fn_img.c_str());

          if( !FS.exist( fn ) )
          {
               ELog.Msg(mtError,"Can't make preview for texture '%s'.",m_Name.c_str());
               return;
          }
        }

        U32Vec data;
        u32 w, h, a;
        if (!Surface_Load(fn,data,image_w,image_h,image_a))
        {
               ELog.Msg(mtError,"Can't make preview for texture '%s'.",m_Name.c_str());
               return;
        }
        ImageLib.MakeThumbnailImage(this,data.begin(),image_w,image_h,image_a);
     }

	if (Valid())
        {
        Irect r;
        r.x1 = R.x1+1; 
        r.y1 = R.y1+1;
        r.x2 = R.x2-1; 
        r.y2 = R.y2-1;
        if (_Width()!=_Height())	FHelper.FillRect(hdc,r,0x00000000);
        if (_Width()>_Height())
        {
                r.y2 -= r.height()-iFloor(r.height()*float(_Height())/float(_Width()));
        }else
        {
                r.x2 -= r.width()-iFloor(r.width()*float(_Width())/float(_Height()));
        }
        inherited::Draw(hdc,r);
    }
}
Пример #3
0
int ETextureThumbnail::MemoryUsage()
{
	int mem_usage = _Width()*_Height()*4;
    switch (m_TexParams.fmt){
    case STextureParams::tfDXT1:
    case STextureParams::tfADXT1: 	mem_usage/=6; break;
    case STextureParams::tfDXT3:
    case STextureParams::tfDXT5: 	mem_usage/=4; break;
    case STextureParams::tf4444:
    case STextureParams::tf1555:
    case STextureParams::tf565: 	mem_usage/=2; break;
    case STextureParams::tfRGBA:	break;
    }
    string_path fn;
    FS.update_path	(fn,_game_textures_,EFS.ChangeFileExt(m_Name.c_str(),".seq").c_str());
    if (FS.exist(fn))
    {
        string128		buffer;
        IReader* F		= FS.r_open(0,fn);
        F->r_string		(buffer,sizeof(buffer));
        int cnt = 0;
        while (!F->eof()){
            F->r_string(buffer,sizeof(buffer));
            cnt++;
        }
        FS.r_close		(F);
        mem_usage *= cnt?cnt:1;
    }
    return mem_usage;
}
Пример #4
0
double Terrain::Height(R3Point pos) {
    double x = ((pos.X() + TERRAIN_SIZE / 2) / (TERRAIN_SIZE)) * params.heightMap->Width();
    double y = ((pos.Z() + TERRAIN_SIZE / 2) / (TERRAIN_SIZE)) * params.heightMap->Height();

    if (x < 0) x = 0;
    if (y < 0) y = 0;
    if (x > params.heightMap->Width() - 1) x = params.heightMap->Width() - 1;
    if (y > params.heightMap->Width() - 1) y = params.heightMap->Width() - 1;

    double fx = x - floor(x);
    double fy = y - floor(y);

    double a = (1 - fx) * _Height(x,     y) + fx * _Height(x + 1,     y);
    double b = (1 - fx) * _Height(x, y + 1) + fx * _Height(x + 1, y + 1);

    return a + fy * (b - a);
}
Пример #5
0
void ETextureThumbnail::FillInfo(PropItemVec& items)
{                                                                         
	STextureParams& F			= m_TexParams;
    PHelper().CreateCaption		(items, "Format",					get_token_name(tfmt_token,F.fmt));
    PHelper().CreateCaption		(items, "Type",						get_token_name(ttype_token,F.type));
    PHelper().CreateCaption		(items, "Width",					shared_str().sprintf("%d",_Width()));
    PHelper().CreateCaption		(items, "Height",					shared_str().sprintf("%d",_Height()));
    PHelper().CreateCaption		(items, "Alpha",					_Alpha()?"on":"off");
}
	int Height()
	{
		return _Height(pRoot);
	}