From f2f215fa91452e3a71845946b8cc2b48f88d2df9 Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Sat, 7 Feb 2026 18:57:32 +0300 Subject: [PATCH] Fixed bug with cache not updating --- include/Helpers/SCollision.hpp | 2 +- src/DrawingProgram/DrawingProgramCache.cpp | 31 ++++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/include/Helpers/SCollision.hpp b/include/Helpers/SCollision.hpp index 2a0591c..7ff6994 100644 --- a/include/Helpers/SCollision.hpp +++ b/include/Helpers/SCollision.hpp @@ -28,7 +28,7 @@ namespace SCollision { T width() const { return max.x() - min.x(); } T height() const { return max.y() - min.y(); } // Do not try to get intersection between AABBs unless you know they collide - AABB get_intersection_between_aabbs(const AABB& other) { + AABB get_intersection_between_aabbs(const AABB& other) const { return { cwise_vec_max(other.min, min), cwise_vec_min(other.max, max) diff --git a/src/DrawingProgram/DrawingProgramCache.cpp b/src/DrawingProgram/DrawingProgramCache.cpp index addf8d3..f8d1221 100644 --- a/src/DrawingProgram/DrawingProgramCache.cpp +++ b/src/DrawingProgram/DrawingProgramCache.cpp @@ -356,24 +356,27 @@ void DrawingProgramCache::allocate_window_cache_area() { } void DrawingProgramCache::update_window_cache_invalid_bounds(const DrawData& drawData) { - auto iBounds = windowCache.invalidBounds.value(); + auto invalidBound = windowCache.invalidBounds.value(); + if(SCollision::collide(invalidBound, drawData.cam.viewingAreaGenerousCollider)) { + auto iBounds = drawData.cam.viewingAreaGenerousCollider.get_intersection_between_aabbs(invalidBound); - SCollision::AABB cameraSpaceInvalidAABB = drawData.cam.c.world_collider_to_coords>(iBounds); - SCollision::AABB clipRectBoundAABB{cameraSpaceInvalidAABB.min - Vector2f{4, 4}, cameraSpaceInvalidAABB.max + Vector2f{4, 4}}; + SCollision::AABB cameraSpaceInvalidAABB = drawData.cam.c.world_collider_to_coords>(iBounds); + SCollision::AABB clipRectBoundAABB{cameraSpaceInvalidAABB.min - Vector2f{4, 4}, cameraSpaceInvalidAABB.max + Vector2f{4, 4}}; - SkIRect clipRect = SkIRect::MakeLTRB(clipRectBoundAABB.min.x(), - clipRectBoundAABB.min.y(), - clipRectBoundAABB.max.x(), - clipRectBoundAABB.max.y()); + SkIRect clipRect = SkIRect::MakeLTRB(clipRectBoundAABB.min.x(), + clipRectBoundAABB.min.y(), + clipRectBoundAABB.max.x(), + clipRectBoundAABB.max.y()); - SCollision::AABB clipRectBoundAABBWorld = drawData.cam.c.collider_to_world>(clipRectBoundAABB); + SCollision::AABB clipRectBoundAABBWorld = drawData.cam.c.collider_to_world>(clipRectBoundAABB); - SkCanvas* cacheCanvas = windowCache.surface->getCanvas(); - cacheCanvas->save(); - cacheCanvas->clipIRect(clipRect); - cacheCanvas->clear(SkColor4f{0, 0, 0, 0}); - draw_components_to_canvas(cacheCanvas, drawData, clipRectBoundAABBWorld); - cacheCanvas->restore(); + SkCanvas* cacheCanvas = windowCache.surface->getCanvas(); + cacheCanvas->save(); + cacheCanvas->clipIRect(clipRect); + cacheCanvas->clear(SkColor4f{0, 0, 0, 0}); + draw_components_to_canvas(cacheCanvas, drawData, clipRectBoundAABBWorld); + cacheCanvas->restore(); + } windowCache.invalidBounds = std::nullopt; }