- Switched SBarInfo to floating point math.

SVN r2345 (trunk)
This commit is contained in:
Braden Obrzut 2010-05-30 00:12:46 +00:00
parent cd1104e80c
commit e848fa3c4c
1 changed files with 78 additions and 82 deletions

View File

@ -900,14 +900,14 @@ void Popup::close()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
inline void adjustRelCenter(const SBarInfoCoordinate &x, const SBarInfoCoordinate &y, int &outX, int &outY, const double &xScale, const double &yScale) inline void adjustRelCenter(const SBarInfoCoordinate &x, const SBarInfoCoordinate &y, double &outX, double &outY, const double &xScale, const double &yScale)
{ {
if(x.RelCenter()) if(x.RelCenter())
outX = *x + (int) (SCREENWIDTH/(hud_scale ? xScale*2 : 2)); outX = *x + (SCREENWIDTH/(hud_scale ? xScale*2 : 2));
else else
outX = *x; outX = *x;
if(y.RelCenter()) if(y.RelCenter())
outY = *y + (int) (SCREENHEIGHT/(hud_scale ? yScale*2 : 2)); outY = *y + (SCREENHEIGHT/(hud_scale ? yScale*2 : 2));
else else
outY = *y; outY = *y;
} }
@ -1110,59 +1110,57 @@ public:
if (texture == NULL) if (texture == NULL)
return; return;
double dx = *x;
double dy = *y;
if((offsetflags & SBarInfoCommand::CENTER) == SBarInfoCommand::CENTER) if((offsetflags & SBarInfoCommand::CENTER) == SBarInfoCommand::CENTER)
{ {
x -= (texture->GetScaledWidth()/2)-texture->LeftOffset; x -= (texture->GetScaledWidthDouble()/2.0)-texture->LeftOffset;
y -= (texture->GetScaledHeight()/2)-texture->TopOffset; y -= (texture->GetScaledHeightDouble()/2.0)-texture->TopOffset;
} }
x += xOffset; x += xOffset;
y += yOffset; y += yOffset;
int w, h; double w, h;
if(!fullScreenOffsets) if(!fullScreenOffsets)
{ {
fixed_t tmp = 0; double tmp = 0;
// I'll handle the conversion from fixed to int myself for more control dx += ST_X;
fixed_t fx = (x + ST_X).Coordinate() << FRACBITS; dy += ST_Y - (Scaled ? script->resH : 200) + script->height;
fixed_t fy = (y + ST_Y - (Scaled ? script->resH : 200) + script->height).Coordinate() << FRACBITS; w = forceWidth < 0 ? texture->GetScaledWidth() : forceWidth;
fixed_t fw = (forceWidth <= -1 ? texture->GetScaledWidth() : forceWidth) << FRACBITS; h = forceHeight < 0 ? texture->GetScaledHeight() : forceHeight;
fixed_t fh = (forceHeight <= -1 ? texture->GetScaledHeight() : forceHeight) << FRACBITS; double dcx = cx == 0 ? 0 : dx + ((double) cx / FRACUNIT) - texture->GetScaledLeftOffsetDouble();
fixed_t fcx = cx == 0 ? 0 : fx + cx - (texture->GetScaledLeftOffset() << FRACBITS); double dcy = cy == 0 ? 0 : dy + ((double) cy / FRACUNIT) - texture->GetScaledTopOffsetDouble();
fixed_t fcy = cy == 0 ? 0 : fy + cy - (texture->GetScaledTopOffset() << FRACBITS); double dcr = cr == 0 ? INT_MAX : dx + w - ((double) cr / FRACUNIT);
fixed_t fcr = fx + fw - cr; double dcb = cb == 0 ? INT_MAX : dy + h - ((double) cb / FRACUNIT);
fixed_t fcb = fy + fh - cb;
if(Scaled) if(Scaled)
{ {
if(cx != 0 || cy != 0) if(cx != 0 || cy != 0)
screen->VirtualToRealCoordsFixed(fcx, fcy, tmp, tmp, script->resW, script->resH, true); screen->VirtualToRealCoords(dcx, dcy, tmp, tmp, script->resW, script->resH, true);
if(cr != 0 || cb != 0 || clearDontDraw) if(cr != 0 || cb != 0 || clearDontDraw)
screen->VirtualToRealCoordsFixed(fcr, fcb, tmp, tmp, script->resW, script->resH, true); screen->VirtualToRealCoords(dcr, dcb, tmp, tmp, script->resW, script->resH, true);
screen->VirtualToRealCoordsFixed(fx, fy, fw, fh, script->resW, script->resH, true); screen->VirtualToRealCoords(dx, dy, w, h, script->resW, script->resH, true);
} }
else else
{ {
fy += (200 - script->resH)<<FRACBITS; dy += 200 - script->resH;
fcy += (200 - script->resH)<<FRACBITS; dcy += 200 - script->resH;
fcb += (200 - script->resH)<<FRACBITS; dcb += 200 - script->resH;
} }
// Round to nearest
w = (fw + (FRACUNIT>>1)) >> FRACBITS;
h = (fh + (FRACUNIT>>1)) >> FRACBITS;
cr = cr != 0 ? fcr >> FRACBITS : INT_MAX;
cb = cb != 0 ? fcb >> FRACBITS : INT_MAX;
if(clearDontDraw) if(clearDontDraw)
screen->Clear(MAX<fixed_t>(fx, fcx)>>FRACBITS, MAX<fixed_t>(fy, fcy)>>FRACBITS, fcr>>FRACBITS, fcb>>FRACBITS, GPalette.BlackIndex, 0); screen->Clear(static_cast<int>(MAX<double>(dx, dcx)), static_cast<int>(MAX<double>(dy, dcy)), static_cast<int>(dcr), static_cast<int>(dcb), GPalette.BlackIndex, 0);
else else
{ {
if(alphaMap) if(alphaMap)
{ {
screen->DrawTexture(texture, (fx >> FRACBITS), (fy >> FRACBITS), screen->DrawTexture(texture, dx, dy,
DTA_DestWidth, w, DTA_DestWidthF, w,
DTA_DestHeight, h, DTA_DestHeightF, h,
DTA_ClipLeft, fcx>>FRACBITS, DTA_ClipLeft, static_cast<int>(dcx),
DTA_ClipTop, fcy>>FRACBITS, DTA_ClipTop, static_cast<int>(dcy),
DTA_ClipRight, cr, DTA_ClipRight, static_cast<int>(dcr),
DTA_ClipBottom, cb, DTA_ClipBottom, static_cast<int>(dcb),
DTA_Translation, translate ? GetTranslation() : 0, DTA_Translation, translate ? GetTranslation() : 0,
DTA_ColorOverlay, dim ? DIM_OVERLAY : 0, DTA_ColorOverlay, dim ? DIM_OVERLAY : 0,
DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM, DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM,
@ -1173,13 +1171,13 @@ public:
} }
else else
{ {
screen->DrawTexture(texture, (fx >> FRACBITS), (fy >> FRACBITS), screen->DrawTexture(texture, dx, dy,
DTA_DestWidth, w, DTA_DestWidthF, w,
DTA_DestHeight, h, DTA_DestHeightF, h,
DTA_ClipLeft, fcx>>FRACBITS, DTA_ClipLeft, static_cast<int>(dcx),
DTA_ClipTop, fcy>>FRACBITS, DTA_ClipTop, static_cast<int>(dcy),
DTA_ClipRight, cr, DTA_ClipRight, static_cast<int>(dcr),
DTA_ClipBottom, cb, DTA_ClipBottom, static_cast<int>(dcb),
DTA_Translation, translate ? GetTranslation() : 0, DTA_Translation, translate ? GetTranslation() : 0,
DTA_ColorOverlay, dim ? DIM_OVERLAY : 0, DTA_ColorOverlay, dim ? DIM_OVERLAY : 0,
DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM, DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM,
@ -1190,7 +1188,7 @@ public:
} }
else else
{ {
int rx, ry, rcx=0, rcy=0, rcr=INT_MAX, rcb=INT_MAX; double rx, ry, rcx=0, rcy=0, rcr=INT_MAX, rcb=INT_MAX;
double xScale = !hud_scale ? 1.0 : (double) CleanXfac*320.0/(double) script->resW;//(double) SCREENWIDTH/(double) script->resW; double xScale = !hud_scale ? 1.0 : (double) CleanXfac*320.0/(double) script->resW;//(double) SCREENWIDTH/(double) script->resW;
double yScale = !hud_scale ? 1.0 : (double) CleanYfac*200.0/(double) script->resH;//(double) SCREENHEIGHT/(double) script->resH; double yScale = !hud_scale ? 1.0 : (double) CleanYfac*200.0/(double) script->resH;//(double) SCREENHEIGHT/(double) script->resH;
@ -1202,16 +1200,16 @@ public:
bool xright = rx < 0; bool xright = rx < 0;
bool ybot = ry < 0; bool ybot = ry < 0;
w = (forceWidth <= -1 ? texture->GetScaledWidth() : forceWidth); w = (forceWidth < 0 ? texture->GetScaledWidthDouble() : forceWidth);
h = (forceHeight <= -1 ? texture->GetScaledHeight() : forceHeight); h = (forceHeight < 0 ? texture->GetScaledHeightDouble() : forceHeight);
if(vid_fps && rx < 0 && ry >= 0) if(vid_fps && rx < 0 && ry >= 0)
ry += 10; ry += 10;
if(hud_scale) if(hud_scale)
{ {
rx = (int) (rx*xScale); rx *= xScale;
ry = (int) (ry*yScale); ry *= yScale;
w = (int) (w*xScale); w *= xScale;
h = (int) (h*yScale); h *= yScale;
} }
if(xright) if(xright)
rx = SCREENWIDTH + rx; rx = SCREENWIDTH + rx;
@ -1221,10 +1219,10 @@ public:
// Check for clipping // Check for clipping
if(cx != 0 || cy != 0 || cr != 0 || cb != 0) if(cx != 0 || cy != 0 || cr != 0 || cb != 0)
{ {
rcx = cx == 0 ? 0 : rx+(int) ((cx>>FRACBITS)*xScale); rcx = cx == 0 ? 0 : rx+(((double) cx/FRACUNIT)*xScale);
rcy = cy == 0 ? 0 : ry+(int) ((cy>>FRACBITS)*yScale); rcy = cy == 0 ? 0 : ry+(((double) cy/FRACUNIT)*yScale);
rcr = cr == 0 ? INT_MAX : rx+w-(int) ((cr>>FRACBITS)*xScale); rcr = cr == 0 ? INT_MAX : rx+w-(((double) cr/FRACUNIT)*xScale);
rcb = cb == 0 ? INT_MAX : ry+h-(int) ((cb>>FRACBITS)*yScale); rcb = cb == 0 ? INT_MAX : ry+h-(((double) cb/FRACUNIT)*yScale);
// Fix the clipping for fullscreenoffsets. // Fix the clipping for fullscreenoffsets.
/*if(ry < 0) /*if(ry < 0)
@ -1256,20 +1254,18 @@ public:
} }
if(clearDontDraw) if(clearDontDraw)
{ screen->Clear(static_cast<int>(rcx), static_cast<int>(rcy), static_cast<int>(MIN<double>(rcr, w)), static_cast<int>(MIN<double>(rcb, h)), GPalette.BlackIndex, 0);
screen->Clear(rcx, rcy, MIN<int>(rcr, w), MIN<int>(rcb, h), GPalette.BlackIndex, 0);
}
else else
{ {
if(alphaMap) if(alphaMap)
{ {
screen->DrawTexture(texture, rx, ry, screen->DrawTexture(texture, rx, ry,
DTA_DestWidth, w, DTA_DestWidthF, w,
DTA_DestHeight, h, DTA_DestHeightF, h,
DTA_ClipLeft, rcx, DTA_ClipLeft, static_cast<int>(rcx),
DTA_ClipTop, rcy, DTA_ClipTop, static_cast<int>(rcy),
DTA_ClipRight, rcr, DTA_ClipRight, static_cast<int>(rcr),
DTA_ClipBottom, rcb, DTA_ClipBottom, static_cast<int>(rcb),
DTA_Translation, translate ? GetTranslation() : 0, DTA_Translation, translate ? GetTranslation() : 0,
DTA_ColorOverlay, dim ? DIM_OVERLAY : 0, DTA_ColorOverlay, dim ? DIM_OVERLAY : 0,
DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM, DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM,
@ -1281,12 +1277,12 @@ public:
else else
{ {
screen->DrawTexture(texture, rx, ry, screen->DrawTexture(texture, rx, ry,
DTA_DestWidth, w, DTA_DestWidthF, w,
DTA_DestHeight, h, DTA_DestHeightF, h,
DTA_ClipLeft, rcx, DTA_ClipLeft, static_cast<int>(rcx),
DTA_ClipTop, rcy, DTA_ClipTop, static_cast<int>(rcy),
DTA_ClipRight, rcr, DTA_ClipRight, static_cast<int>(rcr),
DTA_ClipBottom, rcb, DTA_ClipBottom, static_cast<int>(rcb),
DTA_Translation, translate ? GetTranslation() : 0, DTA_Translation, translate ? GetTranslation() : 0,
DTA_ColorOverlay, dim ? DIM_OVERLAY : 0, DTA_ColorOverlay, dim ? DIM_OVERLAY : 0,
DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM, DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM,
@ -1300,8 +1296,8 @@ public:
void DrawString(FFont *font, const char* str, SBarInfoCoordinate x, SBarInfoCoordinate y, int xOffset, int yOffset, int alpha, bool fullScreenOffsets, EColorRange translation, int spacing=0, bool drawshadow=false) const void DrawString(FFont *font, const char* str, SBarInfoCoordinate x, SBarInfoCoordinate y, int xOffset, int yOffset, int alpha, bool fullScreenOffsets, EColorRange translation, int spacing=0, bool drawshadow=false) const
{ {
x += spacing; x += spacing;
int ax = *x; double ax = *x;
int ay = *y; double ay = *y;
double xScale = 1.0; double xScale = 1.0;
double yScale = 1.0; double yScale = 1.0;
@ -1337,17 +1333,17 @@ public:
if(script->spacingCharacter == '\0') //If we are monospaced lets use the offset if(script->spacingCharacter == '\0') //If we are monospaced lets use the offset
ax += (character->LeftOffset+1); //ignore x offsets since we adapt to character size ax += (character->LeftOffset+1); //ignore x offsets since we adapt to character size
int rx, ry, rw, rh; double rx, ry, rw, rh;
rx = ax + xOffset; rx = ax + xOffset;
ry = ay + yOffset; ry = ay + yOffset;
rw = character->GetScaledWidth(); rw = character->GetScaledWidthDouble();
rh = character->GetScaledHeight(); rh = character->GetScaledHeightDouble();
if(!fullScreenOffsets) if(!fullScreenOffsets)
{ {
rx += ST_X; rx += ST_X;
ry += ST_Y - (Scaled ? script->resH : 200) + script->height; ry += ST_Y - (Scaled ? script->resH : 200) + script->height;
if(Scaled) if(Scaled)
screen->VirtualToRealCoordsInt(rx, ry, rw, rh, script->resW, script->resH, true); screen->VirtualToRealCoords(rx, ry, rw, rh, script->resW, script->resH, true);
else else
{ {
ry += (200 - script->resH); ry += (200 - script->resH);
@ -1363,10 +1359,10 @@ public:
if(hud_scale) if(hud_scale)
{ {
rx = (int) (rx*xScale); rx *= xScale;
ry = (int) (ry*yScale); ry *= yScale;
rw = (int) (rw*xScale); rw *= xScale;
rh = (int) (rh*yScale); rh *= yScale;
} }
if(xright) if(xright)
rx = SCREENWIDTH + rx; rx = SCREENWIDTH + rx;
@ -1377,15 +1373,15 @@ public:
{ {
int salpha = fixed_t(((double) alpha / (double) FRACUNIT) * ((double) HR_SHADOW / (double) FRACUNIT) * FRACUNIT); int salpha = fixed_t(((double) alpha / (double) FRACUNIT) * ((double) HR_SHADOW / (double) FRACUNIT) * FRACUNIT);
screen->DrawTexture(character, rx+2, ry+2, screen->DrawTexture(character, rx+2, ry+2,
DTA_DestWidth, rw, DTA_DestWidthF, rw,
DTA_DestHeight, rh, DTA_DestHeightF, rh,
DTA_Alpha, salpha, DTA_Alpha, salpha,
DTA_FillColor, 0, DTA_FillColor, 0,
TAG_DONE); TAG_DONE);
} }
screen->DrawTexture(character, rx, ry, screen->DrawTexture(character, rx, ry,
DTA_DestWidth, rw, DTA_DestWidthF, rw,
DTA_DestHeight, rh, DTA_DestHeightF, rh,
DTA_Translation, font->GetColorTranslation(translation), DTA_Translation, font->GetColorTranslation(translation),
DTA_Alpha, alpha, DTA_Alpha, alpha,
TAG_DONE); TAG_DONE);