Disabled partial cache refresh for now due to many issues related to it, and also static images dont constantly require updating
This commit is contained in:
parent
0b72dd4ea9
commit
453f01b4c7
4 changed files with 54 additions and 47 deletions
|
|
@ -382,6 +382,7 @@ void DrawingProgram::add_file_to_canvas_by_path_execute(const std::string& fileP
|
||||||
img->d.imageID = imageID;
|
img->d.imageID = imageID;
|
||||||
img->commit_update(*this);
|
img->commit_update(*this);
|
||||||
uint64_t placement = components.client_list().size();
|
uint64_t placement = components.client_list().size();
|
||||||
|
std::cout << "tiger place: " << placement << std::endl;
|
||||||
auto objAdd = components.client_insert(placement, img);
|
auto objAdd = components.client_insert(placement, img);
|
||||||
img->client_send_place(*this);
|
img->client_send_place(*this);
|
||||||
add_undo_place_component(objAdd);
|
add_undo_place_component(objAdd);
|
||||||
|
|
|
||||||
|
|
@ -269,20 +269,23 @@ void DrawingProgramCache::invalidate_cache_at_optional_aabb_before_pos(const std
|
||||||
void DrawingProgramCache::invalidate_cache_at_aabb_before_pos(const SCollision::AABB<WorldScalar>& aabb, uint64_t placementToInvalidateAt) {
|
void DrawingProgramCache::invalidate_cache_at_aabb_before_pos(const SCollision::AABB<WorldScalar>& aabb, uint64_t placementToInvalidateAt) {
|
||||||
std::erase_if(nodesWithCachedSurfaces, [&](auto& n) {
|
std::erase_if(nodesWithCachedSurfaces, [&](auto& n) {
|
||||||
if(placementToInvalidateAt <= n->drawCache.value().lastDrawnComponentPlacement && SCollision::collide(aabb, n->bounds)) {
|
if(placementToInvalidateAt <= n->drawCache.value().lastDrawnComponentPlacement && SCollision::collide(aabb, n->bounds)) {
|
||||||
if(aabb.fully_contains_aabb(n->bounds)) {
|
//if(aabb.fully_contains_aabb(n->bounds)) {
|
||||||
|
// NOTE: For now, we will invalidate the entire cache when something needs updating
|
||||||
|
// Invalidating parts of the cache can lead to massive speed ups with eraser and GIFs, but it currently has accuracy issues
|
||||||
|
// related to determining what's been drawn last
|
||||||
n->drawCache = std::nullopt;
|
n->drawCache = std::nullopt;
|
||||||
return true;
|
return true;
|
||||||
}
|
//}
|
||||||
else {
|
//else {
|
||||||
auto& dCache = n->drawCache.value();
|
// auto& dCache = n->drawCache.value();
|
||||||
if(dCache.invalidBounds.has_value()) {
|
// if(dCache.invalidBounds.has_value()) {
|
||||||
auto& iBounds = dCache.invalidBounds.value();
|
// auto& iBounds = dCache.invalidBounds.value();
|
||||||
iBounds.include_aabb_in_bounds(aabb);
|
// iBounds.include_aabb_in_bounds(aabb);
|
||||||
iBounds = n->bounds.get_intersection_between_aabbs(iBounds);
|
// iBounds = n->bounds.get_intersection_between_aabbs(iBounds);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
dCache.invalidBounds = n->bounds.get_intersection_between_aabbs(aabb);
|
// dCache.invalidBounds = n->bounds.get_intersection_between_aabbs(aabb);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
@ -292,7 +295,7 @@ void DrawingProgramCache::refresh_all_draw_cache(const DrawData& drawData) {
|
||||||
std::deque<std::shared_ptr<DrawingProgramCacheBVHNode>> nodeFlatList; // We want to render children before parents, so that parents can make use of the cached children
|
std::deque<std::shared_ptr<DrawingProgramCacheBVHNode>> nodeFlatList; // We want to render children before parents, so that parents can make use of the cached children
|
||||||
traverse_bvh_run_function(drawData.cam.viewingAreaGenerousCollider, [&](std::shared_ptr<DrawingProgramCacheBVHNode> node, const std::vector<CollabListType::ObjectInfoPtr>& comps) {
|
traverse_bvh_run_function(drawData.cam.viewingAreaGenerousCollider, [&](std::shared_ptr<DrawingProgramCacheBVHNode> node, const std::vector<CollabListType::ObjectInfoPtr>& comps) {
|
||||||
if(node && node->coords.inverseScale <= drawData.cam.c.inverseScale) {
|
if(node && node->coords.inverseScale <= drawData.cam.c.inverseScale) {
|
||||||
if(!node->drawCache || node->drawCache.value().invalidBounds)
|
if(!node->drawCache /*|| node->drawCache.value().invalidBounds*/)
|
||||||
nodeFlatList.emplace_front(node);
|
nodeFlatList.emplace_front(node);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -330,45 +333,48 @@ void DrawingProgramCache::refresh_draw_cache(const std::shared_ptr<DrawingProgra
|
||||||
cacheDrawData.cam.set_viewing_area(bvhNode->resolution.cast<float>());
|
cacheDrawData.cam.set_viewing_area(bvhNode->resolution.cast<float>());
|
||||||
cacheDrawData.refresh_draw_optimizing_values();
|
cacheDrawData.refresh_draw_optimizing_values();
|
||||||
|
|
||||||
if(drawCache.invalidBounds) {
|
//if(drawCache.invalidBounds) {
|
||||||
auto& iBounds = drawCache.invalidBounds.value();
|
// auto& iBounds = drawCache.invalidBounds.value();
|
||||||
WorldVec bDim = bvhNode->bounds.dim();
|
// WorldVec bDim = bvhNode->bounds.dim();
|
||||||
|
|
||||||
Vector2f clipBoundMin{static_cast<float>((iBounds.min.x() - bvhNode->bounds.min.x()) / bDim.x()) * bvhNode->resolution.x(),
|
// Vector2f clipBoundMin{static_cast<float>((iBounds.min.x() - bvhNode->bounds.min.x()) / bDim.x()) * bvhNode->resolution.x(),
|
||||||
static_cast<float>((iBounds.min.y() - bvhNode->bounds.min.y()) / bDim.y()) * bvhNode->resolution.y()};
|
// static_cast<float>((iBounds.min.y() - bvhNode->bounds.min.y()) / bDim.y()) * bvhNode->resolution.y()};
|
||||||
Vector2f clipBoundMax{static_cast<float>((iBounds.max.x() - bvhNode->bounds.min.x()) / bDim.x()) * bvhNode->resolution.x(),
|
// Vector2f clipBoundMax{static_cast<float>((iBounds.max.x() - bvhNode->bounds.min.x()) / bDim.x()) * bvhNode->resolution.x(),
|
||||||
static_cast<float>((iBounds.max.y() - bvhNode->bounds.min.y()) / bDim.y()) * bvhNode->resolution.y()};
|
// static_cast<float>((iBounds.max.y() - bvhNode->bounds.min.y()) / bDim.y()) * bvhNode->resolution.y()};
|
||||||
|
|
||||||
SkIRect clipRect = SkIRect::MakeLTRB(clipBoundMin.x() - 2,
|
// SkIRect clipRect = SkIRect::MakeLTRB(clipBoundMin.x() - 2,
|
||||||
clipBoundMin.y() - 2,
|
// clipBoundMin.y() - 2,
|
||||||
clipBoundMax.x() + 2,
|
// clipBoundMax.x() + 2,
|
||||||
clipBoundMax.y() + 2);
|
// clipBoundMax.y() + 2);
|
||||||
|
|
||||||
SCollision::AABB<float> clipRectBoundAABB{clipBoundMin - Vector2f{4, 4}, clipBoundMax + Vector2f{4, 4}};
|
// SCollision::AABB<float> clipRectBoundAABB{clipBoundMin - Vector2f{4, 4}, clipBoundMax + Vector2f{4, 4}};
|
||||||
SCollision::AABB<WorldScalar> clipRectBoundAABBWorld{
|
// SCollision::AABB<WorldScalar> clipRectBoundAABBWorld{
|
||||||
bvhNode->coords.from_space(clipRectBoundAABB.min),
|
// bvhNode->coords.from_space(clipRectBoundAABB.min),
|
||||||
bvhNode->coords.from_space(clipRectBoundAABB.max)
|
// bvhNode->coords.from_space(clipRectBoundAABB.max)
|
||||||
};
|
// };
|
||||||
|
|
||||||
cacheCanvas->save();
|
// cacheCanvas->save();
|
||||||
cacheCanvas->clipIRect(clipRect);
|
// cacheCanvas->clipIRect(clipRect);
|
||||||
cacheCanvas->clear(SkColor4f{0, 0, 0, 0});
|
// cacheCanvas->clear(SkColor4f{0, 0, 0, 0});
|
||||||
uint64_t lastDrawnComponentPlacementNew = 0;
|
// uint64_t lastDrawnComponentPlacementNew = 0;
|
||||||
draw_components_to_canvas(cacheCanvas, cacheDrawData, {
|
// draw_components_to_canvas(cacheCanvas, cacheDrawData, {
|
||||||
.lastDrawnComponentPlacement = &lastDrawnComponentPlacementNew,
|
// .lastDrawnComponentPlacement = &lastDrawnComponentPlacementNew,
|
||||||
.drawBounds = clipRectBoundAABBWorld
|
// .drawBounds = clipRectBoundAABBWorld,
|
||||||
});
|
// .lastObjectPositionToDraw = drawCache.lastDrawnComponentPlacement
|
||||||
drawCache.lastDrawnComponentPlacement = std::max(lastDrawnComponentPlacementNew, drawCache.lastDrawnComponentPlacement);
|
// });
|
||||||
cacheCanvas->restore();
|
// // NOTE: We make sure that the last object position drawn remains the same, so we dont have to set it to a different value after we're done here
|
||||||
drawCache.invalidBounds = std::nullopt;
|
// // drawCache.lastDrawnComponentPlacement = std::max(lastDrawnComponentPlacementNew, drawCache.lastDrawnComponentPlacement);
|
||||||
}
|
// std::cout << drawCache.lastDrawnComponentPlacement << std::endl;
|
||||||
else {
|
// cacheCanvas->restore();
|
||||||
|
// drawCache.invalidBounds = std::nullopt;
|
||||||
|
//}
|
||||||
|
//else {
|
||||||
cacheCanvas->clear(SkColor4f{0, 0, 0, 0});
|
cacheCanvas->clear(SkColor4f{0, 0, 0, 0});
|
||||||
draw_components_to_canvas(cacheCanvas, cacheDrawData, {
|
draw_components_to_canvas(cacheCanvas, cacheDrawData, {
|
||||||
.lastDrawnComponentPlacement = &drawCache.lastDrawnComponentPlacement,
|
.lastDrawnComponentPlacement = &drawCache.lastDrawnComponentPlacement,
|
||||||
.drawBounds = drawCache.invalidBounds
|
//.drawBounds = drawCache.invalidBounds
|
||||||
});
|
});
|
||||||
}
|
//}
|
||||||
|
|
||||||
drawCache.lastRenderTime = std::chrono::steady_clock::now();
|
drawCache.lastRenderTime = std::chrono::steady_clock::now();
|
||||||
drawCache.attachedCache = this;
|
drawCache.attachedCache = this;
|
||||||
|
|
@ -399,7 +405,7 @@ void DrawingProgramCache::draw_components_to_canvas(SkCanvas* canvas, const Draw
|
||||||
std::vector<UncachedObjectToDraw> uncachedCompsToDraw;
|
std::vector<UncachedObjectToDraw> uncachedCompsToDraw;
|
||||||
|
|
||||||
traverse_bvh_run_function(optData.drawBounds.has_value() ? optData.drawBounds.value() : drawData.cam.viewingAreaGenerousCollider, [&](const std::shared_ptr<DrawingProgramCacheBVHNode>& node, const std::vector<CollabListType::ObjectInfoPtr>& comps) {
|
traverse_bvh_run_function(optData.drawBounds.has_value() ? optData.drawBounds.value() : drawData.cam.viewingAreaGenerousCollider, [&](const std::shared_ptr<DrawingProgramCacheBVHNode>& node, const std::vector<CollabListType::ObjectInfoPtr>& comps) {
|
||||||
if(node && node->drawCache && !node->drawCache.value().invalidBounds && node->coords.inverseScale <= drawData.cam.c.inverseScale) {
|
if(node && node->drawCache /*&& !node->drawCache.value().invalidBounds*/ && node->coords.inverseScale <= drawData.cam.c.inverseScale) {
|
||||||
cachedNodesToDraw.emplace_back(node);
|
cachedNodesToDraw.emplace_back(node);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ class DrawingProgramCacheBVHNode {
|
||||||
sk_sp<SkSurface> surface;
|
sk_sp<SkSurface> surface;
|
||||||
std::chrono::steady_clock::time_point lastRenderTime;
|
std::chrono::steady_clock::time_point lastRenderTime;
|
||||||
DrawingProgramCache* attachedCache;
|
DrawingProgramCache* attachedCache;
|
||||||
std::optional<SCollision::AABB<WorldScalar>> invalidBounds;
|
//std::optional<SCollision::AABB<WorldScalar>> invalidBounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::optional<DrawCacheData> drawCache;
|
std::optional<DrawCacheData> drawCache;
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ bool ImageResourceDisplay::update_draw() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageResourceDisplay::update(World& w) {
|
void ImageResourceDisplay::update(World& w) {
|
||||||
|
mustUpdateDraw = false;
|
||||||
if(frames.size() <= 1)
|
if(frames.size() <= 1)
|
||||||
return;
|
return;
|
||||||
currentTime += w.main.deltaTime * 1000.0;
|
currentTime += w.main.deltaTime * 1000.0;
|
||||||
mustUpdateDraw = false;
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
if(currentTime >= frames[frameIndex].duration) {
|
if(currentTime >= frames[frameIndex].duration) {
|
||||||
currentTime -= frames[frameIndex].duration;
|
currentTime -= frames[frameIndex].duration;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue