Skip to content

Commit

Permalink
Fix tilemap culling (axmolengine#2403)
Browse files Browse the repository at this point in the history
* Fix tilemap culling having twice the width and height

* revert changes to old one

* remove unneeded debug crumps [skip ci]

* fix TMX culling final

remove a pesky content scale factor multiplication
  • Loading branch information
DelinWorks authored Feb 18, 2025
1 parent cae9640 commit f8fa5a8
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions core/2d/FastTMXLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,17 @@ void FastTMXLayer::draw(Renderer* renderer, const Mat4& transform, uint32_t flag
updateTotalQuads();

auto cam = Camera::getVisitingCamera();
if (flags != 0 || _dirty || _quadsDirty || !_cameraPositionDirty.fuzzyEquals(cam->getPosition(), _tileSet->_tileSize.x) ||
if (flags != 0 || _dirty || _quadsDirty ||
!_cameraPositionDirty.fuzzyEquals(cam->getPosition(), _tileSet->_tileSize.x) ||
_cameraZoomDirty != cam->getZoom())
{
_cameraPositionDirty = cam->getPosition();
auto zoom = _cameraZoomDirty = cam->getZoom();
Vec2 s = _director->getVisibleSize();
const Vec2& anchor = getAnchorPoint();
auto rect = Rect(cam->getPositionX() - s.width * zoom * (anchor.x == 0.0f ? 0.5f : anchor.x),
cam->getPositionY() - s.height * zoom * (anchor.y == 0.0f ? 0.5f : anchor.y),
s.width * zoom, s.height * zoom);

rect.origin.x -= _tileSet->_tileSize.x;
rect.origin.y -= _tileSet->_tileSize.y;
rect.size.x += s.x * zoom / 2 + _tileSet->_tileSize.x * zoom;
rect.size.y += s.y * zoom / 2 + _tileSet->_tileSize.y * zoom;
auto zoom = _cameraZoomDirty = cam->getZoom();
Vec2 s = _director->getVisibleSize();
const Vec2& anchor = getAnchorPoint();
auto rect = Rect(cam->getPositionX() - s.width * zoom * (anchor.x == 0.0f ? 0.5f : anchor.x),
cam->getPositionY() - s.height * zoom * (anchor.y == 0.0f ? 0.5f : anchor.y), s.width * zoom,
s.height * zoom);

Mat4 inv = transform;
inv.inverse();
Expand Down Expand Up @@ -177,7 +173,7 @@ void FastTMXLayer::draw(Renderer* renderer, const Mat4& transform, uint32_t flag

void FastTMXLayer::updateTiles(const Rect& culledRect)
{
Rect visibleTiles = Rect(culledRect.origin, culledRect.size * _director->getContentScaleFactor());
Rect visibleTiles = Rect(culledRect.origin, culledRect.size);
Vec2 mapTileSize = AX_SIZE_PIXELS_TO_POINTS(_mapTileSize);
Vec2 tileSize = AX_SIZE_PIXELS_TO_POINTS(_tileSet->_tileSize);
Mat4 nodeToTileTransform = _tileToNodeTransform.getInversed();
Expand Down

0 comments on commit f8fa5a8

Please sign in to comment.