Optimize rotated solid masks some more

stable-5.1
Peter Wortmann 2009-09-19 23:20:32 +02:00
parent e650a595f2
commit 7ed1264518
3 changed files with 31 additions and 20 deletions

View File

@ -130,22 +130,24 @@ void C4SolidMask::Put(bool fCauseInstability, C4TargetRect *pClipRect, bool fRes
MaskPutRect.Hgt = Min<int32_t>(ystart + MatBuffPitch, GBackHgt) - MaskPutRect.y;
}
// go through clipping rect
FIXED yfoo = itofix(pClipRect->ty - MatBuffPitch/2);
const FIXED y0 = itofix(pClipRect->ty - MatBuffPitch/2);
const FIXED x0 = itofix(pClipRect->tx - MatBuffPitch/2);
iTy=pClipRect->y;
int w = pForObject->SolidMask.Wdt;
int h = pForObject->SolidMask.Hgt;
FIXED ya = y0 * Ma2;
FIXED yb = y0 * Mb2;
for(ycnt = 0; ycnt < pClipRect->Hgt; ycnt++)
{
FIXED yfooa = yfoo * Ma2;
FIXED yfoob = yfoo * Mb2;
C4Fixed xfoo = itofix(pClipRect->tx - MatBuffPitch/2);
iTx=pClipRect->x;
int i = (ycnt + pClipRect->ty) * MatBuffPitch + pClipRect->tx;
FIXED xa = x0 * Ma1;
FIXED xb = x0 * Mb1;
for(xcnt = 0; xcnt < pClipRect->Wdt; xcnt++)
{
// calc position in solidmask buffer
int iMx = fixtoi(xfoo * Ma1 + yfooa) + w / 2;
int iMy = fixtoi(xfoo * Mb1 + yfoob) + h / 2;
int iMx = fixtoi(xa + ya) + w / 2;
int iMy = fixtoi(xb + yb) + h / 2;
// in bounds? and solidmask?
if(iMx >= 0 && iMy >= 0 && iMx < w && iMy < h && pSolidMask[iMy*iPitch+iMx])
{
@ -165,10 +167,10 @@ void C4SolidMask::Put(bool fCauseInstability, C4TargetRect *pClipRect, bool fRes
else if (!MaskPut)
// mark pix as unused in buf
pSolidMaskMatBuff[i+xcnt] = MCVehic;
xfoo += 1;
xa += Ma1; xb += Mb1;
++iTx;
}
yfoo += 1;
ya += Ma2; yb += Mb2;
++iTy;
}
}

View File

@ -43,7 +43,8 @@
// activate to switch to classic fixed-point math
#define USE_FIXED 1
#define inline GNUC_ALWAYS_INLINE
#define inline ALWAYS_INLINE
#define FIXED_EMULATE_64BIT
// note: C4Fixed has to be defined even though it isn't used
// any more. It is used to convert old-format fixed values
@ -53,7 +54,7 @@
extern long SineTable[9001]; // external table of sine values
#endif
// fixpoint shift
// fixpoint shift (check 64 bit emulation before changing!)
#define FIXED_SHIFT 16
// fixpoint factor
#define FIXED_FPF int32_t(1 << FIXED_SHIFT)
@ -146,7 +147,15 @@ class C4Fixed
}
inline C4Fixed &operator *= (const C4Fixed &fVal2)
{
#ifndef FIXED_EMULATE_64BIT
val = int32_t( (int64_t(val) * fVal2.val) / FIXED_FPF );
#else
int32_t x0 = val & (FIXED_FPF - 1),
x1 = val >> FIXED_SHIFT;
int32_t y0 = fVal2.val & (FIXED_FPF - 1),
y1 = fVal2.val >> FIXED_SHIFT;
val = x0*y0/FIXED_FPF + x0*y1 + x1*y0 + x1*y1*FIXED_FPF;
#endif
return *this;
}
inline C4Fixed &operator *= (int32_t iVal2)
@ -184,10 +193,10 @@ class C4Fixed
inline C4Fixed &operator += (int32_t iVal2) { return operator += (C4Fixed(iVal2)); }
inline C4Fixed &operator -= (int32_t iVal2) { return operator -= (C4Fixed(iVal2)); }
inline C4Fixed operator + (C4Fixed fVal2) const { return C4Fixed(*this) += fVal2; }
inline C4Fixed operator - (C4Fixed fVal2) const { return C4Fixed(*this) -= fVal2; }
inline C4Fixed operator * (C4Fixed fVal2) const { return C4Fixed(*this) *= fVal2; }
inline C4Fixed operator / (C4Fixed fVal2) const { return C4Fixed(*this) /= fVal2; }
inline C4Fixed operator + (const C4Fixed &fVal2) const { return C4Fixed(*this) += fVal2; }
inline C4Fixed operator - (const C4Fixed &fVal2) const { return C4Fixed(*this) -= fVal2; }
inline C4Fixed operator * (const C4Fixed &fVal2) const { return C4Fixed(*this) *= fVal2; }
inline C4Fixed operator / (const C4Fixed &fVal2) const { return C4Fixed(*this) /= fVal2; }
inline C4Fixed operator + (int32_t iVal2) const { return C4Fixed(*this) += iVal2; }
inline C4Fixed operator - (int32_t iVal2) const { return C4Fixed(*this) -= iVal2; }
@ -267,8 +276,8 @@ inline C4Fixed itofix(int32_t x) { return C4Fixed(x); }
inline C4Fixed itofix(int32_t x, int32_t prec) { return C4Fixed(x, prec); }
// additional functions
inline FIXED Sin(FIXED fAngle) { return fAngle.sin_deg(); }
inline FIXED Cos(FIXED fAngle) { return fAngle.cos_deg(); }
inline FIXED Sin(const FIXED &fAngle) { return fAngle.sin_deg(); }
inline FIXED Cos(const FIXED &fAngle) { return fAngle.cos_deg(); }
inline FIXED FIXED100(int x) { return itofix(x, 100); }
//inline FIXED FIXED256(int x) { return itofix(x, 256); }
inline FIXED FIXED256(int x) { C4Fixed r; r.val = x * FIXED_FPF / 256; return r; }
@ -299,10 +308,10 @@ inline int fixtoi(FIXED x)
}
// conversion
inline int fixtoi(FIXED x, int32_t prec) { return fixtoi(x*prec); }
inline int fixtoi(const FIXED &x, int32_t prec) { return fixtoi(x*prec); }
inline FIXED itofix(int x) { return static_cast<FIXED>(x); }
inline FIXED itofix(int x, int prec) { return static_cast<FIXED>(x) / prec; }
inline float fixtof(FIXED x) { return x; }
inline float fixtof(const FIXED &x) { return x; }
inline FIXED ftofix(float x) { return x; }
// additional functions

View File

@ -105,11 +105,11 @@ typedef ptrdiff_t ssize_t;
// Allow checks for correct printf-usage
#define GNUC_FORMAT_ATTRIBUTE __attribute__ ((format (printf, 1, 2)))
#define GNUC_FORMAT_ATTRIBUTE_O __attribute__ ((format (printf, 2, 3)))
#define GNUC_ALWAYS_INLINE inline __attribute__ ((always_inline))
#define ALWAYS_INLINE inline __attribute__ ((always_inline))
#else
#define GNUC_FORMAT_ATTRIBUTE
#define GNUC_FORMAT_ATTRIBUTE_O
#define GNUC_ALWAYS_INLINE inline
#define ALWAYS_INLINE __forceinline
#endif
// Temporary-To-Reference-Fix