Shortcut C4Surface::GetTexAt for unsplit texture

In the very common case where the C4Surface only uses a single texture
to store its data, a lot of work GetTexAt is actually unnecessary. Split
it up so we can inline the fast path and only fallback to the slow path
when the surface is split up into multiple textures.
alternate-lights
Nicolas Hake 2015-02-22 17:06:35 +01:00
parent 32ecf51029
commit 72beae8100
2 changed files with 16 additions and 9 deletions

View File

@ -563,15 +563,11 @@ bool C4Surface::Unlock()
return true;
}
bool C4Surface::GetTexAt(C4TexRef **ppTexRef, int &rX, int &rY)
bool C4Surface::GetTexAtImpl(C4TexRef **ppTexRef, int &rX, int &rY)
{
// texture present?
if (textures.empty()) return false;
// get pos
int iX=rX/iTexSize;
int iY=rY/iTexSize;
// clip
if (iX<0 || iY<0 || iX>=iTexX || iY>=iTexY) return false;
// get texture by pos
*ppTexRef = &textures[iY*iTexX + iX];
// adjust pos

View File

@ -97,7 +97,7 @@ protected:
bool Attached;
bool fPrimary;
bool IsSingleSurface() { return iTexX*iTexY==1; } // return whether surface is not split
bool IsSingleSurface() const { return iTexX*iTexY==1; } // return whether surface is not split
public:
void SetBackground() { fIsBackground = true; }
@ -106,7 +106,17 @@ public:
void ClearBoxDw(int iX, int iY, int iWdt, int iHgt);
bool Unlock();
bool Lock();
bool GetTexAt(C4TexRef **ppTexRef, int &rX, int &rY); // get texture and adjust x/y
bool GetTexAt(C4TexRef **ppTexRef, int &rX, int &rY) // get texture and adjust x/y
{
if (textures.empty()) return false;
if (rX < 0 || rY < 0 || rX >= Wdt || rY >= Hgt) return false;
if (IsSingleSurface())
{
*ppTexRef = &textures[0];
return true;
}
return GetTexAtImpl(ppTexRef, rX, rY);
}
bool GetLockTexAt(C4TexRef **ppTexRef, int &rX, int &rY); // get texture; ensure it's locked and adjust x/y
DWORD GetPixDw(int iX, int iY, bool fApplyModulation); // get 32bit-px
bool IsPixTransparent(int iX, int iY); // is pixel's alpha value <= 0x7f?
@ -146,12 +156,13 @@ public:
void SetClr(DWORD toClr) { ClrByOwnerClr=toClr; }
DWORD GetClr() { return ClrByOwnerClr; }
bool CopyBytes(BYTE *pImageData); // assumes an array of wdt*hgt*bitdepth/8 and copies data directly from it
protected:
private:
void MapBytes(BYTE *bpMap);
bool ReadBytes(BYTE **lpbpData, void *bpTarget, int iSize);
bool CreateTextures(int MaxTextureSize = 0); // create ppTex-array
void FreeTextures(); // free ppTex-array if existant
// C4Surface *Duplicate(); // create identical copy
bool GetTexAtImpl(C4TexRef **ppTexRef, int &rX, int &rY);
friend class C4Draw;
friend class C4Pattern;