From 9fe21fcd8883b37bdc30224822e6e42afb35b8f0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 7 Feb 2016 16:18:13 +0300 Subject: Replace most static_cast to shorter versions from defines. --- src/render/sdlgraphics.cpp | 282 ++++++++++++++++++++++----------------------- 1 file changed, 141 insertions(+), 141 deletions(-) (limited to 'src/render/sdlgraphics.cpp') diff --git a/src/render/sdlgraphics.cpp b/src/render/sdlgraphics.cpp index 3e71937c6..0043d1ccc 100644 --- a/src/render/sdlgraphics.cpp +++ b/src/render/sdlgraphics.cpp @@ -78,16 +78,16 @@ void SDLGraphics::drawRescaledImage(const Image *restrict const image, SDL_Rect srcRect = { - static_cast(bounds.x), - static_cast(bounds.y), - static_cast(bounds.w), - static_cast(bounds.h) + CAST_S16(bounds.x), + CAST_S16(bounds.y), + CAST_U16(bounds.w), + CAST_U16(bounds.h) }; SDL_Rect dstRect = { - static_cast(dstX + top.xOffset), - static_cast(dstY + top.yOffset), + CAST_S16(dstX + top.xOffset), + CAST_S16(dstY + top.yOffset), 0, 0 }; @@ -125,7 +125,7 @@ void SDLGraphics::drawImageInline(const Image *restrict const image, if (srcX < 0) { w += srcX; - dstX -= static_cast(srcX); + dstX -= CAST_S16(srcX); srcX = 0; } const int maxw = src->w - srcX; @@ -135,7 +135,7 @@ void SDLGraphics::drawImageInline(const Image *restrict const image, if (srcY < 0) { h += srcY; - dstY -= static_cast(srcY); + dstY -= CAST_S16(srcY); srcY = 0; } const int maxh = src->h - srcY; @@ -149,7 +149,7 @@ void SDLGraphics::drawImageInline(const Image *restrict const image, if (dx > 0) { w -= dx; - dstX += static_cast(dx); + dstX += CAST_S16(dx); srcX += dx; } dx = dstX + w - clipX - clip->w; @@ -160,7 +160,7 @@ void SDLGraphics::drawImageInline(const Image *restrict const image, if (dy > 0) { h -= dy; - dstY += static_cast(dy); + dstY += CAST_S16(dy); srcY += dy; } dy = dstY + h - clipY - clip->h; @@ -171,18 +171,18 @@ void SDLGraphics::drawImageInline(const Image *restrict const image, { SDL_Rect srcRect = { - static_cast(srcX), - static_cast(srcY), - static_cast(w), - static_cast(h) + CAST_S16(srcX), + CAST_S16(srcY), + CAST_U16(w), + CAST_U16(h) }; SDL_Rect dstRect = { - static_cast(dstX), - static_cast(dstY), - static_cast(w), - static_cast(h) + CAST_S16(dstX), + CAST_S16(dstY), + CAST_U16(w), + CAST_U16(h) }; SDL_LowerBlit(src, &srcRect, mWindow, &dstRect); @@ -218,7 +218,7 @@ void SDLGraphics::drawImageCached(const Image *restrict const image, if (srcX < 0) { w += srcX; - x -= static_cast(srcX); + x -= CAST_S16(srcX); srcX = 0; } const int maxw = src->w - srcX; @@ -228,7 +228,7 @@ void SDLGraphics::drawImageCached(const Image *restrict const image, if (srcY < 0) { h += srcY; - y -= static_cast(srcY); + y -= CAST_S16(srcY); srcY = 0; } const int maxh = src->h - srcY; @@ -242,7 +242,7 @@ void SDLGraphics::drawImageCached(const Image *restrict const image, if (dx > 0) { w -= dx; - x += static_cast(dx); + x += CAST_S16(dx); srcX += dx; } dx = x + w - clipX - clip->w; @@ -253,7 +253,7 @@ void SDLGraphics::drawImageCached(const Image *restrict const image, if (dy > 0) { h -= dy; - y += static_cast(dy); + y += CAST_S16(dy); srcY += dy; } dy = y + h - clipY - clip->h; @@ -264,18 +264,18 @@ void SDLGraphics::drawImageCached(const Image *restrict const image, { SDL_Rect srcRect = { - static_cast(srcX), - static_cast(srcY), - static_cast(w), - static_cast(h) + CAST_S16(srcX), + CAST_S16(srcY), + CAST_U16(w), + CAST_U16(h) }; SDL_Rect dstRect = { - static_cast(x), - static_cast(y), - static_cast(w), - static_cast(h) + CAST_S16(x), + CAST_S16(y), + CAST_U16(w), + CAST_U16(h) }; SDL_LowerBlit(src, &srcRect, mWindow, &dstRect); @@ -318,7 +318,7 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image, if (y2 < 0) { h2 += y2; - dstY -= static_cast(y2); + dstY -= CAST_S16(y2); y2 = 0; } const int maxh = src->h - y2; @@ -329,7 +329,7 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image, if (dy > 0) { h2 -= dy; - dstY += static_cast(dy); + dstY += CAST_S16(dy); y2 += dy; } dy = dstY + h2 - clipY - clip->h; @@ -347,7 +347,7 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image, if (x2 < 0) { w2 += x2; - dstX -= static_cast(x2); + dstX -= CAST_S16(x2); x2 = 0; } const int maxw = src->w - x2; @@ -358,7 +358,7 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image, if (dx > 0) { w2 -= dx; - dstX += static_cast(dx); + dstX += CAST_S16(dx); x2 += dx; } dx = dstX + w2 - clipX - clip->w; @@ -369,18 +369,18 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image, { SDL_Rect srcRect = { - static_cast(x2), - static_cast(y2), - static_cast(w2), - static_cast(h2) + CAST_S16(x2), + CAST_S16(y2), + CAST_U16(w2), + CAST_U16(h2) }; SDL_Rect dstRect = { - static_cast(dstX), - static_cast(dstY), - static_cast(w2), - static_cast(h2) + CAST_S16(dstX), + CAST_S16(dstY), + CAST_U16(w2), + CAST_U16(h2) }; SDL_LowerBlit(src, &srcRect, mWindow, &dstRect); @@ -439,7 +439,7 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image, if (y2 < 0) { h2 += y2; - dstY -= static_cast(y2); + dstY -= CAST_S16(y2); y2 = 0; } const int maxh = src->h - y2; @@ -450,7 +450,7 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image, if (dy > 0) { h2 -= dy; - dstY += static_cast(dy); + dstY += CAST_S16(dy); y2 += dy; } dy = dstY + h2 - clipY - clip->h; @@ -468,7 +468,7 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image, if (x2 < 0) { w2 += x2; - dstX -= static_cast(x2); + dstX -= CAST_S16(x2); x2 = 0; } const int maxw = src->w - x2; @@ -479,7 +479,7 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image, if (dx > 0) { w2 -= dx; - dstX += static_cast(dx); + dstX += CAST_S16(dx); x2 += dx; } dx = dstX + w2 - clipX - clip->w; @@ -490,18 +490,18 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image, { SDL_Rect srcRect = { - static_cast(x2), - static_cast(y2), - static_cast(w2), - static_cast(h2) + CAST_S16(x2), + CAST_S16(y2), + CAST_U16(w2), + CAST_U16(h2) }; SDL_Rect dstRect = { - static_cast(dstX), - static_cast(dstY), - static_cast(w2), - static_cast(h2) + CAST_S16(dstX), + CAST_S16(dstY), + CAST_U16(w2), + CAST_U16(h2) }; SDL_LowerBlit(src, &srcRect, mWindow, &dstRect); @@ -557,16 +557,16 @@ void SDLGraphics::drawRescaledPattern(const Image *restrict const image, SDL_Rect srcRect = { - static_cast(srcX), - static_cast(srcY), - static_cast(dw), - static_cast(dh) + CAST_S16(srcX), + CAST_S16(srcY), + CAST_U16(dw), + CAST_U16(dh) }; SDL_Rect dstRect = { - static_cast(dstX), - static_cast(dstY), + CAST_S16(dstX), + CAST_S16(dstY), 0, 0 }; @@ -620,13 +620,13 @@ void SDLGraphics::calcPatternInline(ImageVertexes *restrict const vert, DoubleRect *const r = new DoubleRect(); SDL_Rect &srcRect = r->src; - srcRect.x = static_cast(srcX); - srcRect.y = static_cast(srcY); - srcRect.w = static_cast(dw); - srcRect.h = static_cast(dh); + srcRect.x = CAST_S16(srcX); + srcRect.y = CAST_S16(srcY); + srcRect.w = CAST_U16(dw); + srcRect.h = CAST_U16(dh); SDL_Rect &dstRect = r->dst; - dstRect.x = static_cast(dstX); - dstRect.y = static_cast(dstY); + dstRect.x = CAST_S16(dstX); + dstRect.y = CAST_S16(dstY); if (SDL_FakeUpperBlit(image->mSDLSurface, &srcRect, mWindow, &dstRect) == 1) @@ -698,12 +698,12 @@ void SDLGraphics::calcTileSDL(ImageVertexes *restrict const vert, const SDL_Rect &bounds = image->mBounds; DoubleRect *rect = new DoubleRect(); - rect->src.x = static_cast(bounds.x); - rect->src.y = static_cast(bounds.y); - rect->src.w = static_cast(bounds.w); - rect->src.h = static_cast(bounds.h); - rect->dst.x = static_cast(x + top.xOffset); - rect->dst.y = static_cast(y + top.yOffset); + rect->src.x = CAST_S16(bounds.x); + rect->src.y = CAST_S16(bounds.y); + rect->src.w = CAST_U16(bounds.w); + rect->src.h = CAST_U16(bounds.h); + rect->dst.x = CAST_S16(x + top.xOffset); + rect->dst.y = CAST_S16(y + top.yOffset); if (SDL_FakeUpperBlit(image->mSDLSurface, &rect->src, mWindow, &rect->dst) == 1) { @@ -837,7 +837,7 @@ int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const src, if (srcx < 0) { w += srcx; - dstrect->x -= static_cast(srcx); + dstrect->x -= CAST_S16(srcx); srcx = 0; } int maxw = src->w - srcx; @@ -849,7 +849,7 @@ int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const src, if (srcy < 0) { h += srcy; - dstrect->y -= static_cast(srcy); + dstrect->y -= CAST_S16(srcy); srcy = 0; } int maxh = src->h - srcy; @@ -863,7 +863,7 @@ int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const src, if (dx > 0) { w -= dx; - dstrect->x += static_cast(dx); + dstrect->x += CAST_S16(dx); srcx += dx; } dx = dstrect->x + w - clipX - clip->w; @@ -874,7 +874,7 @@ int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const src, if (dy > 0) { h -= dy; - dstrect->y += static_cast(dy); + dstrect->y += CAST_S16(dy); srcy += dy; } dy = dstrect->y + h - clipY - clip->h; @@ -883,12 +883,12 @@ int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const src, if (w > 0 && h > 0) { - srcrect->x = static_cast(srcx); - srcrect->y = static_cast(srcy); - srcrect->w = static_cast(w); - srcrect->h = static_cast(h); - dstrect->w = static_cast(w); - dstrect->h = static_cast(h); + srcrect->x = CAST_S16(srcx); + srcrect->y = CAST_S16(srcy); + srcrect->w = CAST_S16(w); + srcrect->h = CAST_S16(h); + dstrect->w = CAST_S16(w); + dstrect->h = CAST_S16(h); return 1; // return SDL_LowerBlit(src, &sr, dst, dstrect); @@ -925,8 +925,8 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2 const int bpp = mWindow->format->BytesPerPixel; const uint32_t pixel = SDL_MapRGB(mWindow->format, - static_cast(mColor.r), static_cast(mColor.g), - static_cast(mColor.b)); + CAST_U8(mColor.r), CAST_U8(mColor.g), + CAST_U8(mColor.b)); switch (bpp) { @@ -934,11 +934,11 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2 cilk_for (int y = y1; y < y2; y++) { uint8_t *const p = static_cast(mWindow->pixels) - + static_cast(y * mWindow->pitch); + + CAST_SIZE(y * mWindow->pitch); for (int x = x1; x < x2; x++) { - *(p + static_cast(x)) - = static_cast(pixel); + *(p + CAST_SIZE(x)) + = CAST_U8(pixel); } } break; @@ -946,14 +946,14 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2 cilk_for (int y = y1; y < y2; y++) { uint8_t *const p0 = static_cast(mWindow->pixels) - + static_cast(y * mWindow->pitch); + + CAST_SIZE(y * mWindow->pitch); for (int x = x1; x < x2; x++) { - uint8_t *const p = p0 + static_cast(x * 2); + uint8_t *const p = p0 + CAST_SIZE(x * 2); *reinterpret_cast(p) = SDLAlpha16( - static_cast(pixel), + CAST_U16(pixel), *reinterpret_cast(p), - static_cast(mColor.a), mWindow->format); + CAST_U8(mColor.a), mWindow->format); } } break; @@ -967,18 +967,18 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2 cilk_for (int y = y1; y < y2; y++) { uint8_t *const p0 = static_cast(mWindow->pixels) - + static_cast(y * mWindow->pitch); + + CAST_SIZE(y * mWindow->pitch); for (int x = x1; x < x2; x++) { - uint8_t *const p = p0 + static_cast(x * 3); + uint8_t *const p = p0 + CAST_SIZE(x * 3); #if SDL_BYTEORDER == SDL_BIG_ENDIAN - p[2] = static_cast((p[2] * ca + cb) >> 8); - p[1] = static_cast((p[1] * ca + cg) >> 8); - p[0] = static_cast((p[0] * ca + cr) >> 8); + p[2] = CAST_U8((p[2] * ca + cb) >> 8); + p[1] = CAST_U8((p[1] * ca + cg) >> 8); + p[0] = CAST_U8((p[0] * ca + cr) >> 8); #else - p[0] = static_cast((p[0] * ca + cb) >> 8); - p[1] = static_cast((p[1] * ca + cg) >> 8); - p[2] = static_cast((p[2] * ca + cr) >> 8); + p[0] = CAST_U8((p[0] * ca + cb) >> 8); + p[1] = CAST_U8((p[1] * ca + cg) >> 8); + p[2] = CAST_U8((p[2] * ca + cr) >> 8); #endif } } @@ -1059,10 +1059,10 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2 { uint32_t *const p0 = reinterpret_cast( static_cast(mWindow->pixels) - + static_cast(y * mWindow->pitch)); + + CAST_SIZE(y * mWindow->pitch)); for (int x = x1; x < x2; x++) { - uint32_t *const p = p0 + static_cast(x); + uint32_t *const p = p0 + CAST_SIZE(x); const uint32_t dst = *p; *p = cB[dst & bMask / bShift] | cG[(dst & gMask) / gShift] @@ -1082,17 +1082,17 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2 { SDL_Rect rect = { - static_cast(area.x), - static_cast(area.y), - static_cast(area.width), - static_cast(area.height) + CAST_S16(area.x), + CAST_S16(area.y), + CAST_U16(area.width), + CAST_U16(area.height) }; const uint32_t color = SDL_MapRGBA(mWindow->format, - static_cast(mColor.r), - static_cast(mColor.g), - static_cast(mColor.b), - static_cast(mColor.a)); + CAST_S8(mColor.r), + CAST_S8(mColor.g), + CAST_S8(mColor.b), + CAST_S8(mColor.a)); SDL_FillRect(mWindow, &rect, color); } } @@ -1113,10 +1113,10 @@ void SDLGraphics::pushClipArea(const Rect &restrict area) restrict2 const ClipRect &restrict carea = mClipStack.top(); const SDL_Rect rect = { - static_cast(carea.x), - static_cast(carea.y), - static_cast(carea.width), - static_cast(carea.height) + CAST_S16(carea.x), + CAST_S16(carea.y), + CAST_U16(carea.width), + CAST_U16(carea.height) }; SDL_SetClipRect(mWindow, &rect); } @@ -1131,10 +1131,10 @@ void SDLGraphics::popClipArea() restrict2 const ClipRect &restrict carea = mClipStack.top(); const SDL_Rect rect = { - static_cast(carea.x), - static_cast(carea.y), - static_cast(carea.width), - static_cast(carea.height) + CAST_S16(carea.x), + CAST_S16(carea.y), + CAST_U16(carea.width), + CAST_U16(carea.height) }; SDL_SetClipRect(mWindow, &rect); @@ -1205,23 +1205,23 @@ void SDLGraphics::drawHLine(int x1, int y, int x2) restrict2 SDL_LockSurface(mWindow); uint8_t *p = static_cast(mWindow->pixels) - + static_cast(y * mWindow->pitch + x1 * bpp); + + CAST_SIZE(y * mWindow->pitch + x1 * bpp); const uint32_t pixel = SDL_MapRGB(mWindow->format, - static_cast(mColor.r), - static_cast(mColor.g), - static_cast(mColor.b)); + CAST_U8(mColor.r), + CAST_U8(mColor.g), + CAST_U8(mColor.b)); switch (bpp) { case 1: for (; x1 <= x2; ++x1) - *(p++) = static_cast(pixel); + *(p++) = CAST_U8(pixel); break; case 2: { uint16_t* q = reinterpret_cast(p); - const uint16_t pixel1 = static_cast(pixel); + const uint16_t pixel1 = CAST_U16(pixel); for (; x1 <= x2; ++x1) *(q++) = pixel1; break; @@ -1229,9 +1229,9 @@ void SDLGraphics::drawHLine(int x1, int y, int x2) restrict2 case 3: { - const uint8_t b0 = static_cast((pixel >> 16) & 0xff); - const uint8_t b1 = static_cast((pixel >> 8) & 0xff); - const uint8_t b2 = static_cast(pixel & 0xff); + const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff); + const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff); + const uint8_t b2 = CAST_U8(pixel & 0xff); #if SDL_BYTEORDER == SDL_BIG_ENDIAN for (; x1 <= x2; ++x1) { @@ -1257,8 +1257,8 @@ void SDLGraphics::drawHLine(int x1, int y, int x2) restrict2 uint32_t *q = reinterpret_cast(p); if (mAlpha) { - unsigned char a = static_cast(mColor.a); - unsigned char a1 = static_cast(255U - a); + unsigned char a = CAST_U8(mColor.a); + unsigned char a1 = CAST_U8(255U - a); const int b0 = (pixel & 0xff) * a; const int g0 = (pixel & 0xff00) * a; const int r0 = (pixel & 0xff0000) * a; @@ -1330,12 +1330,12 @@ void SDLGraphics::drawVLine(int x, int y1, int y2) restrict2 SDL_LockSurface(mWindow); uint8_t *p = static_cast(mWindow->pixels) - + static_cast(y1 * mWindow->pitch + x * bpp); + + CAST_SIZE(y1 * mWindow->pitch + x * bpp); const uint32_t pixel = SDL_MapRGB(mWindow->format, - static_cast(mColor.r), - static_cast(mColor.g), - static_cast(mColor.b)); + CAST_U8(mColor.r), + CAST_U8(mColor.g), + CAST_U8(mColor.b)); const int pitch = mWindow->pitch; switch (bpp) @@ -1343,7 +1343,7 @@ void SDLGraphics::drawVLine(int x, int y1, int y2) restrict2 case 1: for (; y1 <= y2; ++y1) { - *p = static_cast(pixel); + *p = CAST_U8(pixel); p += pitch; } break; @@ -1352,16 +1352,16 @@ void SDLGraphics::drawVLine(int x, int y1, int y2) restrict2 for (; y1 <= y2; ++ y1) { *reinterpret_cast(p) - = static_cast(pixel); + = CAST_U16(pixel); p += pitch; } break; case 3: { - const uint8_t b0 = static_cast((pixel >> 16) & 0xff); - const uint8_t b1 = static_cast((pixel >> 8) & 0xff); - const uint8_t b2 = static_cast(pixel & 0xff); + const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff); + const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff); + const uint8_t b2 = CAST_U8(pixel & 0xff); #if SDL_BYTEORDER == SDL_BIG_ENDIAN for (; y1 <= y2; ++y1) { @@ -1386,8 +1386,8 @@ void SDLGraphics::drawVLine(int x, int y1, int y2) restrict2 { if (mAlpha) { - unsigned char a = static_cast(mColor.a); - unsigned char a1 = static_cast(255U - a); + unsigned char a = CAST_U8(mColor.a); + unsigned char a1 = CAST_U8(255U - a); const int b0 = (pixel & 0xff) * a; const int g0 = (pixel & 0xff00) * a; const int r0 = (pixel & 0xff0000) * a; @@ -1470,8 +1470,8 @@ bool SDLGraphics::setVideoMode(const int w, const int h, return false; } - mRect.w = static_cast(mWindow->w); - mRect.h = static_cast(mWindow->h); + mRect.w = CAST_U16(mWindow->w); + mRect.h = CAST_U16(mWindow->h); return videoInfo(); } -- cgit v1.2.3-60-g2f50