diff --git a/src/etc-internal.h b/src/etc-internal.h index da40cb7..2d3e547 100644 --- a/src/etc-internal.h +++ b/src/etc-internal.h @@ -93,17 +93,20 @@ struct Vec2i } }; -struct IntRect +struct IntRect : SDL_Rect { - int x, y, w, h; - IntRect() - : x(0), y(0), w(0), h(0) - {} + { + x = y = w = h = 0; + } IntRect(int x, int y, int w, int h) - : x(x), y(y), w(w), h(h) - {} + { + this->x = x; + this->y = y; + this->w = w; + this->h = h; + } bool operator==(const IntRect &other) const { diff --git a/src/tileatlasvx.cpp b/src/tileatlasvx.cpp index 45fab3a..7a5f48c 100644 --- a/src/tileatlasvx.cpp +++ b/src/tileatlasvx.cpp @@ -270,6 +270,19 @@ createShadowSet() return surf; } +static void doBlit(Bitmap *bm, const IntRect &src, const Vec2i &dst) +{ + /* Translate tile to pixel units */ + IntRect _src(src.x*32, src.y*32, src.w*32, src.h*32); + Vec2i _dst(dst.x*32, dst.y*32); + IntRect bmr(0, 0, bm->width(), bm->height()); + + if (!SDL_IntersectRect(&_src, &bmr, &_src)) + return; + + GLMeta::blitRectangle(_src, _dst); +} + void build(TEXFBO &tf, Bitmap *bitmaps[BM_COUNT]) { assert(tf.width == ATLASVX_W && tf.height == ATLASVX_H); @@ -296,13 +309,9 @@ void build(TEXFBO &tf, Bitmap *bitmaps[BM_COUNT]) GLMeta::blitSource(bm->getGLTypes()); \ for (size_t i = 0; i < blits##part##N; ++i) \ {\ - IntRect src = blits##part[i].src; \ - int w = std::min(bm->width(), src.w*32); \ - int h = std::min(bm->height(), src.h*32); \ - src = IntRect(src.x*32, src.y*32, w, h); \ - Vec2i dst = blits##part[i].dst; \ - dst = Vec2i(dst.x*32, dst.y*32); \ - GLMeta::blitRectangle(src, dst); \ + const IntRect &src = blits##part[i].src; \ + const Vec2i &dst = blits##part[i].dst; \ + doBlit(bm, src, dst); \ } \ }