diff options
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/graphics.cpp | 16 | ||||
-rw-r--r-- | src/render/mobileopengl2graphics.cpp | 2 | ||||
-rw-r--r-- | src/render/mobileopenglgraphics.cpp | 8 | ||||
-rw-r--r-- | src/render/modernopenglgraphics.cpp | 2 | ||||
-rw-r--r-- | src/render/sdl2graphics.cpp | 152 | ||||
-rw-r--r-- | src/render/sdl2softwaregraphics.cpp | 242 | ||||
-rw-r--r-- | src/render/sdlgraphics.cpp | 282 | ||||
-rw-r--r-- | src/render/shaders/shadersmanager.cpp | 4 | ||||
-rw-r--r-- | src/render/surfacegraphics.cpp | 36 |
9 files changed, 372 insertions, 372 deletions
diff --git a/src/render/graphics.cpp b/src/render/graphics.cpp index 5052b7489..d01813fb3 100644 --- a/src/render/graphics.cpp +++ b/src/render/graphics.cpp @@ -281,15 +281,15 @@ bool Graphics::setOpenGLMode() restrict2 int w1 = 0; int h1 = 0; SDL_GetWindowSize(mWindow, &w1, &h1); - mRect.w = static_cast<int32_t>(w1 / mScale); - mRect.h = static_cast<int32_t>(h1 / mScale); + mRect.w = CAST_S32(w1 / mScale); + mRect.h = CAST_S32(h1 / mScale); createGLContext(); #else // USE_SDL2 createGLContext(); - mRect.w = static_cast<uint16_t>(mWindow->w / mScale); - mRect.h = static_cast<uint16_t>(mWindow->h / mScale); + mRect.w = CAST_U16(mWindow->w / mScale); + mRect.h = CAST_U16(mWindow->h / mScale); #endif // USE_SDL2 @@ -514,8 +514,8 @@ bool Graphics::resizeScreen(const int width, #ifdef USE_SDL2 endDraw(); - mRect.w = static_cast<int32_t>(width / mScale); - mRect.h = static_cast<int32_t>(height / mScale); + mRect.w = CAST_S32(width / mScale); + mRect.h = CAST_S32(height / mScale); mWidth = width / mScale; mHeight = height / mScale; mActualWidth = width; @@ -545,8 +545,8 @@ bool Graphics::resizeScreen(const int width, #ifdef __native_client__ if (mOpenGL != RENDER_SOFTWARE) { - mRect.w = static_cast<int32_t>(width / mScale); - mRect.h = static_cast<int32_t>(height / mScale); + mRect.w = CAST_S32(width / mScale); + mRect.h = CAST_S32(height / mScale); mWidth = width / mScale; mHeight = height / mScale; mActualWidth = width; diff --git a/src/render/mobileopengl2graphics.cpp b/src/render/mobileopengl2graphics.cpp index 262c50408..69c4c741c 100644 --- a/src/render/mobileopengl2graphics.cpp +++ b/src/render/mobileopengl2graphics.cpp @@ -1268,7 +1268,7 @@ void MobileOpenGL2Graphics::finalize(ImageVertexes *restrict const vert) std::vector<GLuint> &vbos = ogl.mVbo; std::vector<GLuint>::const_iterator ivbo; - const int sz = static_cast<int>(floatTexPool.size()); + const int sz = CAST_S32(floatTexPool.size()); vbos.resize(sz); mglGenBuffers(sz, &vbos[0]); diff --git a/src/render/mobileopenglgraphics.cpp b/src/render/mobileopenglgraphics.cpp index 36a0ae787..f703ff667 100644 --- a/src/render/mobileopenglgraphics.cpp +++ b/src/render/mobileopenglgraphics.cpp @@ -1165,10 +1165,10 @@ void MobileOpenGLGraphics::drawNet(const int x1, const int y1, const GLshort xs2 = static_cast<GLshort>(x2); const GLshort ys1 = static_cast<GLshort>(y1); const GLshort ys2 = static_cast<GLshort>(y2); - const int16_t width1 = static_cast<int16_t>(width); - const int16_t height1 = static_cast<int16_t>(height); + const int16_t width1 = CAST_S16(width); + const int16_t height1 = CAST_S16(height); - for (int16_t y = static_cast<int16_t>(y1); y < y2; y += height1) + for (int16_t y = CAST_S16(y1); y < y2; y += height1) { mShortVertArray[vp + 0] = xs1; mShortVertArray[vp + 1] = y; @@ -1184,7 +1184,7 @@ void MobileOpenGLGraphics::drawNet(const int x1, const int y1, } } - for (int16_t x = static_cast<int16_t>(x1); x < x2; x += width1) + for (int16_t x = CAST_S16(x1); x < x2; x += width1) { mShortVertArray[vp + 0] = x; mShortVertArray[vp + 1] = ys1; diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp index 0fee827be..b82b93276 100644 --- a/src/render/modernopenglgraphics.cpp +++ b/src/render/modernopenglgraphics.cpp @@ -1262,7 +1262,7 @@ void ModernOpenGLGraphics::finalize(ImageVertexes *restrict const vert) std::vector<GLuint> &vbos = ogl.mVbo; std::vector<GLuint>::const_iterator ivbo; - const int sz = static_cast<int>(intTexPool.size()); + const int sz = CAST_S32(intTexPool.size()); vbos.resize(sz); mglGenBuffers(sz, &vbos[0]); /* diff --git a/src/render/sdl2graphics.cpp b/src/render/sdl2graphics.cpp index 79747522d..58e636a54 100644 --- a/src/render/sdl2graphics.cpp +++ b/src/render/sdl2graphics.cpp @@ -113,18 +113,18 @@ static int FakeSDL_RenderCopy(SDL_Renderer *restrict const renderer, #define setRenderDrawColor(mColor) \ SDL_SetRenderDrawColor(mRenderer, \ - static_cast<uint8_t>(mColor.r), \ - static_cast<uint8_t>(mColor.g), \ - static_cast<uint8_t>(mColor.b), \ - static_cast<uint8_t>(mColor.a)) + CAST_U8(mColor.r), \ + CAST_U8(mColor.g), \ + CAST_U8(mColor.b), \ + CAST_U8(mColor.a)) #define defRectFromArea(rect, area) \ const SDL_Rect rect = \ { \ - static_cast<int32_t>(area.x), \ - static_cast<int32_t>(area.y), \ - static_cast<int32_t>(area.width), \ - static_cast<int32_t>(area.height) \ + CAST_S32(area.x), \ + CAST_S32(area.y), \ + CAST_S32(area.width), \ + CAST_S32(area.height) \ } SDLGraphics::SDLGraphics() : @@ -155,17 +155,17 @@ void SDLGraphics::drawRescaledImage(const Image *restrict const image, const SDL_Rect &bounds = image->mBounds; const SDL_Rect srcRect = { - static_cast<int32_t>(bounds.x), - static_cast<int32_t>(bounds.y), - static_cast<int32_t>(bounds.w), - static_cast<int32_t>(bounds.h) + CAST_S32(bounds.x), + CAST_S32(bounds.y), + CAST_S32(bounds.w), + CAST_S32(bounds.h) }; const SDL_Rect dstRect = { - static_cast<int32_t>(dstX + top.xOffset), - static_cast<int32_t>(dstY + top.yOffset), - static_cast<int32_t>(desiredWidth), - static_cast<int32_t>(desiredHeight) + CAST_S32(dstX + top.xOffset), + CAST_S32(dstY + top.yOffset), + CAST_S32(desiredWidth), + CAST_S32(desiredHeight) }; MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); @@ -192,18 +192,18 @@ void SDLGraphics::drawImageInline(const Image *restrict const image, const SDL_Rect &bounds = image->mBounds; const SDL_Rect srcRect = { - static_cast<int32_t>(bounds.x), - static_cast<int32_t>(bounds.y), - static_cast<int32_t>(bounds.w), - static_cast<int32_t>(bounds.h) + CAST_S32(bounds.x), + CAST_S32(bounds.y), + CAST_S32(bounds.w), + CAST_S32(bounds.h) }; const SDL_Rect dstRect = { - static_cast<int32_t>(dstX + top.xOffset), - static_cast<int32_t>(dstY + top.yOffset), - static_cast<int32_t>(bounds.w), - static_cast<int32_t>(bounds.h) + CAST_S32(dstX + top.xOffset), + CAST_S32(dstY + top.yOffset), + CAST_S32(bounds.w), + CAST_S32(bounds.h) }; MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); @@ -230,18 +230,18 @@ void SDLGraphics::drawImageCached(const Image *restrict const image, const SDL_Rect &bounds = image->mBounds; const SDL_Rect srcRect = { - static_cast<int32_t>(bounds.x), - static_cast<int32_t>(bounds.y), - static_cast<int32_t>(bounds.w), - static_cast<int32_t>(bounds.h) + CAST_S32(bounds.x), + CAST_S32(bounds.y), + CAST_S32(bounds.w), + CAST_S32(bounds.h) }; const SDL_Rect dstRect = { - static_cast<int32_t>(x + top.xOffset), - static_cast<int32_t>(y + top.yOffset), - static_cast<int32_t>(bounds.w), - static_cast<int32_t>(bounds.h) + CAST_S32(x + top.xOffset), + CAST_S32(y + top.yOffset), + CAST_S32(bounds.w), + CAST_S32(bounds.h) }; MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); @@ -273,21 +273,21 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image, SDL_Rect dstRect; SDL_Rect srcRect; - srcRect.x = static_cast<int32_t>(bounds.x); - srcRect.y = static_cast<int32_t>(bounds.y); + srcRect.x = CAST_S32(bounds.x); + srcRect.y = CAST_S32(bounds.y); for (int py = 0; py < h; py += ih) { const int dh = (py + ih >= h) ? h - py : ih; - dstRect.y = static_cast<int32_t>(py + yOffset); - srcRect.h = static_cast<int32_t>(dh); - dstRect.h = static_cast<int32_t>(dh); + dstRect.y = CAST_S32(py + yOffset); + srcRect.h = CAST_S32(dh); + dstRect.h = CAST_S32(dh); for (int px = 0; px < w; px += iw) { const int dw = (px + iw >= w) ? w - px : iw; - dstRect.x = static_cast<int32_t>(px + xOffset); - srcRect.w = static_cast<int32_t>(dw); - dstRect.w = static_cast<int32_t>(dw); + dstRect.x = CAST_S32(px + xOffset); + srcRect.w = CAST_S32(dw); + dstRect.w = CAST_S32(dw); MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); } @@ -331,21 +331,21 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image, SDL_Rect dstRect; SDL_Rect srcRect; - srcRect.x = static_cast<int32_t>(bounds.x); - srcRect.y = static_cast<int32_t>(bounds.y); + srcRect.x = CAST_S32(bounds.x); + srcRect.y = CAST_S32(bounds.y); for (int py = 0; py < h; py += ih) { const int dh = (py + ih >= h) ? h - py : ih; - dstRect.y = static_cast<int32_t>(py + yOffset); - srcRect.h = static_cast<int32_t>(dh); - dstRect.h = static_cast<int32_t>(dh); + dstRect.y = CAST_S32(py + yOffset); + srcRect.h = CAST_S32(dh); + dstRect.h = CAST_S32(dh); for (int px = 0; px < w; px += iw) { const int dw = (px + iw >= w) ? w - px : iw; - dstRect.x = static_cast<int32_t>(px + xOffset); - srcRect.w = static_cast<int32_t>(dw); - dstRect.w = static_cast<int32_t>(dw); + dstRect.x = CAST_S32(px + xOffset); + srcRect.w = CAST_S32(dw); + dstRect.w = CAST_S32(dw); MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); } @@ -387,21 +387,21 @@ void SDLGraphics::drawRescaledPattern(const Image *restrict const image, SDL_Rect dstRect; SDL_Rect srcRect; - srcRect.x = static_cast<int32_t>(bounds.x); - srcRect.y = static_cast<int32_t>(bounds.y); + srcRect.x = CAST_S32(bounds.x); + srcRect.y = CAST_S32(bounds.y); for (int py = 0; py < h; py += ih) { const int dh = (py + ih >= h) ? h - py : ih; - dstRect.y = static_cast<int32_t>(py + yOffset); - srcRect.h = static_cast<int32_t>(dh); - dstRect.h = static_cast<int32_t>(dh); + dstRect.y = CAST_S32(py + yOffset); + srcRect.h = CAST_S32(dh); + dstRect.h = CAST_S32(dh); for (int px = 0; px < w; px += iw) { const int dw = (px + iw >= w) ? w - px : iw; - dstRect.x = static_cast<int32_t>(px + xOffset); - srcRect.w = static_cast<int32_t>(dw); - dstRect.w = static_cast<int32_t>(dw); + dstRect.x = CAST_S32(px + xOffset); + srcRect.w = CAST_S32(dw); + dstRect.w = CAST_S32(dw); MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); } @@ -454,14 +454,14 @@ void SDLGraphics::calcPatternInline(ImageVertexes *restrict const vert, DoubleRect *const r = new DoubleRect(); SDL_Rect &dstRect = r->dst; SDL_Rect &srcRect = r->src; - srcRect.x = static_cast<int32_t>(srcX); - srcRect.y = static_cast<int32_t>(srcY); - srcRect.w = static_cast<int32_t>(dw); - srcRect.h = static_cast<int32_t>(dh); - dstRect.x = static_cast<int32_t>(dstX); - dstRect.y = static_cast<int32_t>(dstY); - dstRect.w = static_cast<int32_t>(dw); - dstRect.h = static_cast<int32_t>(dh); + srcRect.x = CAST_S32(srcX); + srcRect.y = CAST_S32(srcY); + srcRect.w = CAST_S32(dw); + srcRect.h = CAST_S32(dh); + dstRect.x = CAST_S32(dstX); + dstRect.y = CAST_S32(dstY); + dstRect.w = CAST_S32(dw); + dstRect.h = CAST_S32(dh); vert->sdl.push_back(r); } @@ -527,14 +527,14 @@ void SDLGraphics::calcTileSDL(ImageVertexes *restrict const vert, SDL_Rect &dstRect = rect->dst; SDL_Rect &srcRect = rect->src; - srcRect.x = static_cast<int32_t>(bounds.x); - srcRect.y = static_cast<int32_t>(bounds.y); - srcRect.w = static_cast<int32_t>(bounds.w); - srcRect.h = static_cast<int32_t>(bounds.h); - dstRect.x = static_cast<int32_t>(x); - dstRect.y = static_cast<int32_t>(y); - dstRect.w = static_cast<int32_t>(bounds.w); - dstRect.h = static_cast<int32_t>(bounds.h); + srcRect.x = CAST_S32(bounds.x); + srcRect.y = CAST_S32(bounds.y); + srcRect.w = CAST_S32(bounds.w); + srcRect.h = CAST_S32(bounds.h); + dstRect.x = CAST_S32(x); + dstRect.y = CAST_S32(y); + dstRect.w = CAST_S32(bounds.w); + dstRect.h = CAST_S32(bounds.h); vert->sdl.push_back(rect); } @@ -637,10 +637,10 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2 const ClipRect &top = mClipStack.top(); const SDL_Rect rect = { - static_cast<int32_t>(rectangle.x + top.xOffset), - static_cast<int32_t>(rectangle.y + top.yOffset), - static_cast<int32_t>(rectangle.width), - static_cast<int32_t>(rectangle.height) + CAST_S32(rectangle.x + top.xOffset), + CAST_S32(rectangle.y + top.yOffset), + CAST_S32(rectangle.width), + CAST_S32(rectangle.height) }; setRenderDrawColor(mColor); diff --git a/src/render/sdl2softwaregraphics.cpp b/src/render/sdl2softwaregraphics.cpp index eb6633598..9a61f94ca 100644 --- a/src/render/sdl2softwaregraphics.cpp +++ b/src/render/sdl2softwaregraphics.cpp @@ -51,10 +51,10 @@ static unsigned int *cB = nullptr; #define defRectFromArea(rect, area) \ const SDL_Rect rect = \ { \ - static_cast<int32_t>(area.x), \ - static_cast<int32_t>(area.y), \ - static_cast<int32_t>(area.width), \ - static_cast<int32_t>(area.height) \ + CAST_S32(area.x), \ + CAST_S32(area.y), \ + CAST_S32(area.width), \ + CAST_S32(area.height) \ } SDL2SoftwareGraphics::SDL2SoftwareGraphics() : @@ -93,16 +93,16 @@ void SDL2SoftwareGraphics::drawRescaledImage(const Image *restrict const image, SDL_Rect srcRect = { - static_cast<int16_t>(bounds.x), - static_cast<int16_t>(bounds.y), - static_cast<uint16_t>(bounds.w), - static_cast<uint16_t>(bounds.h) + CAST_S16(bounds.x), + CAST_S16(bounds.y), + CAST_U16(bounds.w), + CAST_U16(bounds.h) }; SDL_Rect dstRect = { - static_cast<int16_t>(dstX + top.xOffset), - static_cast<int16_t>(dstY + top.yOffset), + CAST_S16(dstX + top.xOffset), + CAST_S16(dstY + top.yOffset), 0, 0 }; @@ -140,7 +140,7 @@ void SDL2SoftwareGraphics::drawImageInline(const Image *restrict const image, if (srcX < 0) { w += srcX; - dstX -= static_cast<int16_t>(srcX); + dstX -= CAST_S16(srcX); srcX = 0; } const int maxw = src->w - srcX; @@ -150,7 +150,7 @@ void SDL2SoftwareGraphics::drawImageInline(const Image *restrict const image, if (srcY < 0) { h += srcY; - dstY -= static_cast<int16_t>(srcY); + dstY -= CAST_S16(srcY); srcY = 0; } const int maxh = src->h - srcY; @@ -164,7 +164,7 @@ void SDL2SoftwareGraphics::drawImageInline(const Image *restrict const image, if (dx > 0) { w -= dx; - dstX += static_cast<int16_t>(dx); + dstX += CAST_S16(dx); srcX += dx; } dx = dstX + w - clipX - clip->w; @@ -175,7 +175,7 @@ void SDL2SoftwareGraphics::drawImageInline(const Image *restrict const image, if (dy > 0) { h -= dy; - dstY += static_cast<int16_t>(dy); + dstY += CAST_S16(dy); srcY += dy; } dy = dstY + h - clipY - clip->h; @@ -186,18 +186,18 @@ void SDL2SoftwareGraphics::drawImageInline(const Image *restrict const image, { SDL_Rect srcRect = { - static_cast<int16_t>(srcX), - static_cast<int16_t>(srcY), - static_cast<uint16_t>(w), - static_cast<uint16_t>(h) + CAST_S16(srcX), + CAST_S16(srcY), + CAST_U16(w), + CAST_U16(h) }; SDL_Rect dstRect = { - static_cast<int16_t>(dstX), - static_cast<int16_t>(dstY), - static_cast<uint16_t>(w), - static_cast<uint16_t>(h) + CAST_S16(dstX), + CAST_S16(dstY), + CAST_U16(w), + CAST_U16(h) }; SDL_LowerBlit(src, &srcRect, mSurface, &dstRect); @@ -233,7 +233,7 @@ void SDL2SoftwareGraphics::drawImageCached(const Image *restrict const image, if (srcX < 0) { w += srcX; - x -= static_cast<int16_t>(srcX); + x -= CAST_S16(srcX); srcX = 0; } const int maxw = src->w - srcX; @@ -243,7 +243,7 @@ void SDL2SoftwareGraphics::drawImageCached(const Image *restrict const image, if (srcY < 0) { h += srcY; - y -= static_cast<int16_t>(srcY); + y -= CAST_S16(srcY); srcY = 0; } const int maxh = src->h - srcY; @@ -257,7 +257,7 @@ void SDL2SoftwareGraphics::drawImageCached(const Image *restrict const image, if (dx > 0) { w -= dx; - x += static_cast<int16_t>(dx); + x += CAST_S16(dx); srcX += dx; } dx = x + w - clipX - clip->w; @@ -268,7 +268,7 @@ void SDL2SoftwareGraphics::drawImageCached(const Image *restrict const image, if (dy > 0) { h -= dy; - y += static_cast<int16_t>(dy); + y += CAST_S16(dy); srcY += dy; } dy = y + h - clipY - clip->h; @@ -279,18 +279,18 @@ void SDL2SoftwareGraphics::drawImageCached(const Image *restrict const image, { SDL_Rect srcRect = { - static_cast<int16_t>(srcX), - static_cast<int16_t>(srcY), - static_cast<uint16_t>(w), - static_cast<uint16_t>(h) + CAST_S16(srcX), + CAST_S16(srcY), + CAST_U16(w), + CAST_U16(h) }; SDL_Rect dstRect = { - static_cast<int16_t>(x), - static_cast<int16_t>(y), - static_cast<uint16_t>(w), - static_cast<uint16_t>(h) + CAST_S16(x), + CAST_S16(y), + CAST_U16(w), + CAST_U16(h) }; SDL_LowerBlit(src, &srcRect, mSurface, &dstRect); @@ -335,7 +335,7 @@ void SDL2SoftwareGraphics::drawPatternCached(const Image *restrict const image, if (y2 < 0) { h2 += y2; - dstY -= static_cast<int16_t>(y2); + dstY -= CAST_S16(y2); y2 = 0; } const int maxh = src->h - y2; @@ -346,7 +346,7 @@ void SDL2SoftwareGraphics::drawPatternCached(const Image *restrict const image, if (dy > 0) { h2 -= dy; - dstY += static_cast<int16_t>(dy); + dstY += CAST_S16(dy); y2 += dy; } dy = dstY + h2 - clipY - clip->h; @@ -364,7 +364,7 @@ void SDL2SoftwareGraphics::drawPatternCached(const Image *restrict const image, if (x2 < 0) { w2 += x2; - dstX -= static_cast<int16_t>(x2); + dstX -= CAST_S16(x2); x2 = 0; } const int maxw = src->w - x2; @@ -375,7 +375,7 @@ void SDL2SoftwareGraphics::drawPatternCached(const Image *restrict const image, if (dx > 0) { w2 -= dx; - dstX += static_cast<int16_t>(dx); + dstX += CAST_S16(dx); x2 += dx; } dx = dstX + w2 - clipX - clip->w; @@ -386,18 +386,18 @@ void SDL2SoftwareGraphics::drawPatternCached(const Image *restrict const image, { SDL_Rect srcRect = { - static_cast<int16_t>(x2), - static_cast<int16_t>(y2), - static_cast<uint16_t>(w2), - static_cast<uint16_t>(h2) + CAST_S16(x2), + CAST_S16(y2), + CAST_U16(w2), + CAST_U16(h2) }; SDL_Rect dstRect = { - static_cast<int16_t>(dstX), - static_cast<int16_t>(dstY), - static_cast<uint16_t>(w2), - static_cast<uint16_t>(h2) + CAST_S16(dstX), + CAST_S16(dstY), + CAST_U16(w2), + CAST_U16(h2) }; SDL_LowerBlit(src, &srcRect, mSurface, &dstRect); @@ -458,7 +458,7 @@ void SDL2SoftwareGraphics::drawPatternInline(const Image *restrict const image, if (y2 < 0) { h2 += y2; - dstY -= static_cast<int16_t>(y2); + dstY -= CAST_S16(y2); y2 = 0; } const int maxh = src->h - y2; @@ -469,7 +469,7 @@ void SDL2SoftwareGraphics::drawPatternInline(const Image *restrict const image, if (dy > 0) { h2 -= dy; - dstY += static_cast<int16_t>(dy); + dstY += CAST_S16(dy); y2 += dy; } dy = dstY + h2 - clipY - clip->h; @@ -487,7 +487,7 @@ void SDL2SoftwareGraphics::drawPatternInline(const Image *restrict const image, if (x2 < 0) { w2 += x2; - dstX -= static_cast<int16_t>(x2); + dstX -= CAST_S16(x2); x2 = 0; } const int maxw = src->w - x2; @@ -498,7 +498,7 @@ void SDL2SoftwareGraphics::drawPatternInline(const Image *restrict const image, if (dx > 0) { w2 -= dx; - dstX += static_cast<int16_t>(dx); + dstX += CAST_S16(dx); x2 += dx; } dx = dstX + w2 - clipX - clip->w; @@ -509,18 +509,18 @@ void SDL2SoftwareGraphics::drawPatternInline(const Image *restrict const image, { SDL_Rect srcRect = { - static_cast<int16_t>(x2), - static_cast<int16_t>(y2), - static_cast<uint16_t>(w2), - static_cast<uint16_t>(h2) + CAST_S16(x2), + CAST_S16(y2), + CAST_U16(w2), + CAST_U16(h2) }; SDL_Rect dstRect = { - static_cast<int16_t>(dstX), - static_cast<int16_t>(dstY), - static_cast<uint16_t>(w2), - static_cast<uint16_t>(h2) + CAST_S16(dstX), + CAST_S16(dstY), + CAST_U16(w2), + CAST_U16(h2) }; SDL_LowerBlit(src, &srcRect, mSurface, &dstRect); @@ -578,16 +578,16 @@ void SDL2SoftwareGraphics::drawRescaledPattern(const Image * SDL_Rect srcRect = { - static_cast<int16_t>(srcX), - static_cast<int16_t>(srcY), - static_cast<uint16_t>(dw), - static_cast<uint16_t>(dh) + CAST_S16(srcX), + CAST_S16(srcY), + CAST_U16(dw), + CAST_U16(dh) }; SDL_Rect dstRect = { - static_cast<int16_t>(dstX), - static_cast<int16_t>(dstY), + CAST_S16(dstX), + CAST_S16(dstY), 0, 0 }; @@ -646,13 +646,13 @@ void SDL2SoftwareGraphics::calcPatternInline(ImageVertexes * DoubleRect *const r = new DoubleRect(); SDL_Rect &srcRect = r->src; - srcRect.x = static_cast<int16_t>(srcX); - srcRect.y = static_cast<int16_t>(srcY); - srcRect.w = static_cast<uint16_t>(dw); - srcRect.h = static_cast<uint16_t>(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<int16_t>(dstX); - dstRect.y = static_cast<int16_t>(dstY); + dstRect.x = CAST_S16(dstX); + dstRect.y = CAST_S16(dstY); if (SDL_FakeUpperBlit(image->mSDLSurface, &srcRect, mSurface, &dstRect) == 1) @@ -721,12 +721,12 @@ void SDL2SoftwareGraphics::calcTileSDL(ImageVertexes *restrict const vert, const SDL_Rect &bounds = image->mBounds; DoubleRect *rect = new DoubleRect(); - rect->src.x = static_cast<int16_t>(bounds.x); - rect->src.y = static_cast<int16_t>(bounds.y); - rect->src.w = static_cast<uint16_t>(bounds.w); - rect->src.h = static_cast<uint16_t>(bounds.h); - rect->dst.x = static_cast<int16_t>(x + top.xOffset); - rect->dst.y = static_cast<int16_t>(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, mSurface, &rect->dst) == 1) { @@ -856,7 +856,7 @@ int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const if (srcx < 0) { w += srcx; - dstrect->x -= static_cast<int16_t>(srcx); + dstrect->x -= CAST_S16(srcx); srcx = 0; } int maxw = src->w - srcx; @@ -868,7 +868,7 @@ int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const if (srcy < 0) { h += srcy; - dstrect->y -= static_cast<int16_t>(srcy); + dstrect->y -= CAST_S16(srcy); srcy = 0; } int maxh = src->h - srcy; @@ -882,7 +882,7 @@ int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const if (dx > 0) { w -= dx; - dstrect->x += static_cast<int16_t>(dx); + dstrect->x += CAST_S16(dx); srcx += dx; } dx = dstrect->x + w - clipX - clip->w; @@ -893,7 +893,7 @@ int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const if (dy > 0) { h -= dy; - dstrect->y += static_cast<int16_t>(dy); + dstrect->y += CAST_S16(dy); srcy += dy; } dy = dstrect->y + h - clipY - clip->h; @@ -904,13 +904,13 @@ int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const { if (srcrect) { - srcrect->x = static_cast<int16_t>(srcx); - srcrect->y = static_cast<int16_t>(srcy); - srcrect->w = static_cast<int16_t>(w); - srcrect->h = static_cast<int16_t>(h); + srcrect->x = CAST_S16(srcx); + srcrect->y = CAST_S16(srcy); + srcrect->w = CAST_S16(w); + srcrect->h = CAST_S16(h); } - dstrect->w = static_cast<int16_t>(w); - dstrect->h = static_cast<int16_t>(h); + dstrect->w = CAST_S16(w); + dstrect->h = CAST_S16(h); return 1; // return SDL_LowerBlit(src, &sr, dst, dstrect); @@ -949,8 +949,8 @@ void SDL2SoftwareGraphics::fillRectangle(const Rect &restrict rectangle) const int bpp = mSurface->format->BytesPerPixel; const uint32_t pixel = SDL_MapRGB(mSurface->format, - static_cast<uint8_t>(mColor.r), static_cast<uint8_t>(mColor.g), - static_cast<uint8_t>(mColor.b)); + CAST_U8(mColor.r), CAST_U8(mColor.g), + CAST_U8(mColor.b)); switch (bpp) { @@ -960,7 +960,7 @@ void SDL2SoftwareGraphics::fillRectangle(const Rect &restrict rectangle) uint8_t *const p = static_cast<uint8_t *>(mSurface->pixels) + y * mSurface->pitch; for (x = x1; x < x2; x++) - *(p + x) = static_cast<uint8_t>(pixel); + *(p + x) = CAST_U8(pixel); } break; case 2: @@ -972,9 +972,9 @@ void SDL2SoftwareGraphics::fillRectangle(const Rect &restrict rectangle) { uint8_t *const p = p0 + x * 2; *reinterpret_cast<uint16_t *>(p) = SDLAlpha16( - static_cast<uint16_t>(pixel), + CAST_U16(pixel), *reinterpret_cast<uint16_t *>(p), - static_cast<uint8_t>(mColor.a), mSurface->format); + CAST_U8(mColor.a), mSurface->format); } } break; @@ -993,13 +993,13 @@ void SDL2SoftwareGraphics::fillRectangle(const Rect &restrict rectangle) { uint8_t *const p = p0 + x * 3; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - p[2] = static_cast<uint8_t>((p[2] * ca + cb) >> 8); - p[1] = static_cast<uint8_t>((p[1] * ca + cg) >> 8); - p[0] = static_cast<uint8_t>((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<uint8_t>((p[0] * ca + cb) >> 8); - p[1] = static_cast<uint8_t>((p[1] * ca + cg) >> 8); - p[2] = static_cast<uint8_t>((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 } } @@ -1103,10 +1103,10 @@ void SDL2SoftwareGraphics::fillRectangle(const Rect &restrict rectangle) { defRectFromArea(rect, area); const uint32_t color = SDL_MapRGBA(mSurface->format, - static_cast<int8_t>(mColor.r), - static_cast<int8_t>(mColor.g), - static_cast<int8_t>(mColor.b), - static_cast<int8_t>(mColor.a)); + CAST_S8(mColor.r), + CAST_S8(mColor.g), + CAST_S8(mColor.b), + CAST_S8(mColor.a)); SDL_FillRect(mSurface, &rect, color); } } @@ -1210,20 +1210,20 @@ void SDL2SoftwareGraphics::drawHLine(int x1, int y, int x2) restrict2 + y * mSurface->pitch + x1 * bpp; const uint32_t pixel = SDL_MapRGB(mSurface->format, - static_cast<uint8_t>(mColor.r), - static_cast<uint8_t>(mColor.g), - static_cast<uint8_t>(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<uint8_t>(pixel); + *(p++) = CAST_U8(pixel); break; case 2: { uint16_t* q = reinterpret_cast<uint16_t*>(p); - const uint16_t pixel1 = static_cast<uint16_t>(pixel); + const uint16_t pixel1 = CAST_U16(pixel); for (; x1 <= x2; ++x1) *(q++) = pixel1; break; @@ -1231,9 +1231,9 @@ void SDL2SoftwareGraphics::drawHLine(int x1, int y, int x2) restrict2 case 3: { - const uint8_t b0 = static_cast<uint8_t>((pixel >> 16) & 0xff); - const uint8_t b1 = static_cast<uint8_t>((pixel >> 8) & 0xff); - const uint8_t b2 = static_cast<uint8_t>(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) { @@ -1259,8 +1259,8 @@ void SDL2SoftwareGraphics::drawHLine(int x1, int y, int x2) restrict2 uint32_t *q = reinterpret_cast<uint32_t*>(p); if (mAlpha) { - unsigned char a = static_cast<unsigned char>(mColor.a); - unsigned char a1 = static_cast<unsigned char>(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; @@ -1335,9 +1335,9 @@ void SDL2SoftwareGraphics::drawVLine(int x, int y1, int y2) restrict2 + y1 * mSurface->pitch + x * bpp; const uint32_t pixel = SDL_MapRGB(mSurface->format, - static_cast<uint8_t>(mColor.r), - static_cast<uint8_t>(mColor.g), - static_cast<uint8_t>(mColor.b)); + CAST_U8(mColor.r), + CAST_U8(mColor.g), + CAST_U8(mColor.b)); const int pitch = mSurface->pitch; switch (bpp) @@ -1345,7 +1345,7 @@ void SDL2SoftwareGraphics::drawVLine(int x, int y1, int y2) restrict2 case 1: for (; y1 <= y2; ++y1) { - *p = static_cast<uint8_t>(pixel); + *p = CAST_U8(pixel); p += pitch; } break; @@ -1354,16 +1354,16 @@ void SDL2SoftwareGraphics::drawVLine(int x, int y1, int y2) restrict2 for (; y1 <= y2; ++ y1) { *reinterpret_cast<uint16_t*>(p) - = static_cast<uint16_t>(pixel); + = CAST_U16(pixel); p += pitch; } break; case 3: { - const uint8_t b0 = static_cast<uint8_t>((pixel >> 16) & 0xff); - const uint8_t b1 = static_cast<uint8_t>((pixel >> 8) & 0xff); - const uint8_t b2 = static_cast<uint8_t>(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) { @@ -1388,8 +1388,8 @@ void SDL2SoftwareGraphics::drawVLine(int x, int y1, int y2) restrict2 { if (mAlpha) { - unsigned char a = static_cast<unsigned char>(mColor.a); - unsigned char a1 = static_cast<unsigned char>(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; 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<int16_t>(bounds.x), - static_cast<int16_t>(bounds.y), - static_cast<uint16_t>(bounds.w), - static_cast<uint16_t>(bounds.h) + CAST_S16(bounds.x), + CAST_S16(bounds.y), + CAST_U16(bounds.w), + CAST_U16(bounds.h) }; SDL_Rect dstRect = { - static_cast<int16_t>(dstX + top.xOffset), - static_cast<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(srcX), - static_cast<int16_t>(srcY), - static_cast<uint16_t>(w), - static_cast<uint16_t>(h) + CAST_S16(srcX), + CAST_S16(srcY), + CAST_U16(w), + CAST_U16(h) }; SDL_Rect dstRect = { - static_cast<int16_t>(dstX), - static_cast<int16_t>(dstY), - static_cast<uint16_t>(w), - static_cast<uint16_t>(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<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(srcX), - static_cast<int16_t>(srcY), - static_cast<uint16_t>(w), - static_cast<uint16_t>(h) + CAST_S16(srcX), + CAST_S16(srcY), + CAST_U16(w), + CAST_U16(h) }; SDL_Rect dstRect = { - static_cast<int16_t>(x), - static_cast<int16_t>(y), - static_cast<uint16_t>(w), - static_cast<uint16_t>(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<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(x2), - static_cast<int16_t>(y2), - static_cast<uint16_t>(w2), - static_cast<uint16_t>(h2) + CAST_S16(x2), + CAST_S16(y2), + CAST_U16(w2), + CAST_U16(h2) }; SDL_Rect dstRect = { - static_cast<int16_t>(dstX), - static_cast<int16_t>(dstY), - static_cast<uint16_t>(w2), - static_cast<uint16_t>(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<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(x2), - static_cast<int16_t>(y2), - static_cast<uint16_t>(w2), - static_cast<uint16_t>(h2) + CAST_S16(x2), + CAST_S16(y2), + CAST_U16(w2), + CAST_U16(h2) }; SDL_Rect dstRect = { - static_cast<int16_t>(dstX), - static_cast<int16_t>(dstY), - static_cast<uint16_t>(w2), - static_cast<uint16_t>(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<int16_t>(srcX), - static_cast<int16_t>(srcY), - static_cast<uint16_t>(dw), - static_cast<uint16_t>(dh) + CAST_S16(srcX), + CAST_S16(srcY), + CAST_U16(dw), + CAST_U16(dh) }; SDL_Rect dstRect = { - static_cast<int16_t>(dstX), - static_cast<int16_t>(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<int16_t>(srcX); - srcRect.y = static_cast<int16_t>(srcY); - srcRect.w = static_cast<uint16_t>(dw); - srcRect.h = static_cast<uint16_t>(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<int16_t>(dstX); - dstRect.y = static_cast<int16_t>(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<int16_t>(bounds.x); - rect->src.y = static_cast<int16_t>(bounds.y); - rect->src.w = static_cast<uint16_t>(bounds.w); - rect->src.h = static_cast<uint16_t>(bounds.h); - rect->dst.x = static_cast<int16_t>(x + top.xOffset); - rect->dst.y = static_cast<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(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<int16_t>(srcx); - srcrect->y = static_cast<int16_t>(srcy); - srcrect->w = static_cast<int16_t>(w); - srcrect->h = static_cast<int16_t>(h); - dstrect->w = static_cast<int16_t>(w); - dstrect->h = static_cast<int16_t>(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<uint8_t>(mColor.r), static_cast<uint8_t>(mColor.g), - static_cast<uint8_t>(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<uint8_t *>(mWindow->pixels) - + static_cast<size_t>(y * mWindow->pitch); + + CAST_SIZE(y * mWindow->pitch); for (int x = x1; x < x2; x++) { - *(p + static_cast<size_t>(x)) - = static_cast<uint8_t>(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<uint8_t *>(mWindow->pixels) - + static_cast<size_t>(y * mWindow->pitch); + + CAST_SIZE(y * mWindow->pitch); for (int x = x1; x < x2; x++) { - uint8_t *const p = p0 + static_cast<size_t>(x * 2); + uint8_t *const p = p0 + CAST_SIZE(x * 2); *reinterpret_cast<uint16_t *>(p) = SDLAlpha16( - static_cast<uint16_t>(pixel), + CAST_U16(pixel), *reinterpret_cast<uint16_t *>(p), - static_cast<uint8_t>(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<uint8_t *>(mWindow->pixels) - + static_cast<size_t>(y * mWindow->pitch); + + CAST_SIZE(y * mWindow->pitch); for (int x = x1; x < x2; x++) { - uint8_t *const p = p0 + static_cast<size_t>(x * 3); + uint8_t *const p = p0 + CAST_SIZE(x * 3); #if SDL_BYTEORDER == SDL_BIG_ENDIAN - p[2] = static_cast<uint8_t>((p[2] * ca + cb) >> 8); - p[1] = static_cast<uint8_t>((p[1] * ca + cg) >> 8); - p[0] = static_cast<uint8_t>((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<uint8_t>((p[0] * ca + cb) >> 8); - p[1] = static_cast<uint8_t>((p[1] * ca + cg) >> 8); - p[2] = static_cast<uint8_t>((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<uint32_t*>( static_cast<uint8_t*>(mWindow->pixels) - + static_cast<size_t>(y * mWindow->pitch)); + + CAST_SIZE(y * mWindow->pitch)); for (int x = x1; x < x2; x++) { - uint32_t *const p = p0 + static_cast<size_t>(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<int16_t>(area.x), - static_cast<int16_t>(area.y), - static_cast<uint16_t>(area.width), - static_cast<uint16_t>(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<int8_t>(mColor.r), - static_cast<int8_t>(mColor.g), - static_cast<int8_t>(mColor.b), - static_cast<int8_t>(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<int16_t>(carea.x), - static_cast<int16_t>(carea.y), - static_cast<uint16_t>(carea.width), - static_cast<uint16_t>(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<int16_t>(carea.x), - static_cast<int16_t>(carea.y), - static_cast<uint16_t>(carea.width), - static_cast<uint16_t>(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<uint8_t*>(mWindow->pixels) - + static_cast<size_t>(y * mWindow->pitch + x1 * bpp); + + CAST_SIZE(y * mWindow->pitch + x1 * bpp); const uint32_t pixel = SDL_MapRGB(mWindow->format, - static_cast<uint8_t>(mColor.r), - static_cast<uint8_t>(mColor.g), - static_cast<uint8_t>(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<uint8_t>(pixel); + *(p++) = CAST_U8(pixel); break; case 2: { uint16_t* q = reinterpret_cast<uint16_t*>(p); - const uint16_t pixel1 = static_cast<uint16_t>(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<uint8_t>((pixel >> 16) & 0xff); - const uint8_t b1 = static_cast<uint8_t>((pixel >> 8) & 0xff); - const uint8_t b2 = static_cast<uint8_t>(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<uint32_t*>(p); if (mAlpha) { - unsigned char a = static_cast<unsigned char>(mColor.a); - unsigned char a1 = static_cast<unsigned char>(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<uint8_t*>(mWindow->pixels) - + static_cast<size_t>(y1 * mWindow->pitch + x * bpp); + + CAST_SIZE(y1 * mWindow->pitch + x * bpp); const uint32_t pixel = SDL_MapRGB(mWindow->format, - static_cast<uint8_t>(mColor.r), - static_cast<uint8_t>(mColor.g), - static_cast<uint8_t>(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<uint8_t>(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<uint16_t*>(p) - = static_cast<uint16_t>(pixel); + = CAST_U16(pixel); p += pitch; } break; case 3: { - const uint8_t b0 = static_cast<uint8_t>((pixel >> 16) & 0xff); - const uint8_t b1 = static_cast<uint8_t>((pixel >> 8) & 0xff); - const uint8_t b2 = static_cast<uint8_t>(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<unsigned char>(mColor.a); - unsigned char a1 = static_cast<unsigned char>(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<uint16_t>(mWindow->w); - mRect.h = static_cast<uint16_t>(mWindow->h); + mRect.w = CAST_U16(mWindow->w); + mRect.h = CAST_U16(mWindow->h); return videoInfo(); } diff --git a/src/render/shaders/shadersmanager.cpp b/src/render/shaders/shadersmanager.cpp index d24405927..753cca93d 100644 --- a/src/render/shaders/shadersmanager.cpp +++ b/src/render/shaders/shadersmanager.cpp @@ -56,7 +56,7 @@ Shader *ShadersManager::createShader(const unsigned int type, return new Shader(shaderId); GLint len = 0; mglGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &len); - char *buf = new char[static_cast<size_t>(len) + 1]; + char *buf = new char[CAST_SIZE(len) + 1]; mglGetShaderInfoLog(shaderId, len, &len, buf); buf[len] = 0; logger->log("Shader '%s' compilation error: %s", fileName.c_str(), buf); @@ -113,7 +113,7 @@ ShaderProgram *ShadersManager::createProgram(const std::string &vertex, GLint len = 0; mglGetProgramiv(programId, GL_INFO_LOG_LENGTH, &len); - char *buf = new char[static_cast<size_t>(len) + 1]; + char *buf = new char[CAST_SIZE(len) + 1]; mglGetProgramInfoLog(programId, len, &len, buf); buf[len] = 0; logger->log("Program '%s, %s' compilation error: %s", diff --git a/src/render/surfacegraphics.cpp b/src/render/surfacegraphics.cpp index bc730920b..d3083dd5c 100644 --- a/src/render/surfacegraphics.cpp +++ b/src/render/surfacegraphics.cpp @@ -51,12 +51,12 @@ void SurfaceGraphics::drawImage(const Image *restrict const image, const SDL_Rect &imageRect = image->mBounds; SDL_Rect dstRect; SDL_Rect srcRect; - dstRect.x = static_cast<int16_t>(dstX); - dstRect.y = static_cast<int16_t>(dstY); - srcRect.x = static_cast<int16_t>(imageRect.x); - srcRect.y = static_cast<int16_t>(imageRect.y); - srcRect.w = static_cast<uint16_t>(imageRect.w); - srcRect.h = static_cast<uint16_t>(imageRect.h); + dstRect.x = CAST_S16(dstX); + dstRect.y = CAST_S16(dstY); + srcRect.x = CAST_S16(imageRect.x); + srcRect.y = CAST_S16(imageRect.y); + srcRect.w = CAST_U16(imageRect.w); + srcRect.h = CAST_U16(imageRect.h); #ifdef USE_SDL2 SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect); @@ -84,12 +84,12 @@ void SurfaceGraphics::copyImage(const Image *restrict const image, const SDL_Rect &imageRect = image->mBounds; SDL_Rect dstRect; SDL_Rect srcRect; - dstRect.x = static_cast<int16_t>(dstX); - dstRect.y = static_cast<int16_t>(dstY); - srcRect.x = static_cast<int16_t>(imageRect.x); - srcRect.y = static_cast<int16_t>(imageRect.y); - srcRect.w = static_cast<uint16_t>(imageRect.w); - srcRect.h = static_cast<uint16_t>(imageRect.h); + dstRect.x = CAST_S16(dstX); + dstRect.y = CAST_S16(dstY); + srcRect.x = CAST_S16(imageRect.x); + srcRect.y = CAST_S16(imageRect.y); + srcRect.w = CAST_U16(imageRect.w); + srcRect.h = CAST_U16(imageRect.h); #ifdef USE_SDL2 // probably need change some flags @@ -111,12 +111,12 @@ void SurfaceGraphics::drawImageCached(const Image *restrict const image, SDL_Rect dstRect; SDL_Rect srcRect; - dstRect.x = static_cast<int16_t>(x); - dstRect.y = static_cast<int16_t>(y); - srcRect.x = static_cast<int16_t>(rect.x); - srcRect.y = static_cast<int16_t>(rect.y); - srcRect.w = static_cast<uint16_t>(rect.w); - srcRect.h = static_cast<uint16_t>(rect.h); + dstRect.x = CAST_S16(x); + dstRect.y = CAST_S16(y); + srcRect.x = CAST_S16(rect.x); + srcRect.y = CAST_S16(rect.y); + srcRect.w = CAST_U16(rect.w); + srcRect.h = CAST_U16(rect.h); #ifdef USE_SDL2 SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect); |