optimization
This commit is contained in:
parent
9bb36c990d
commit
285e8c9182
4 changed files with 57 additions and 69 deletions
|
|
@ -98,30 +98,28 @@ void Window::LogTiming() {
|
|||
}
|
||||
#endif
|
||||
|
||||
bool Overlaps(const ScaleData& rect1, const ScaleData& rect2) {
|
||||
return !(rect1.x + rect1.width <= rect2.x || rect2.x + rect2.width <= rect1.x || rect1.y + rect1.height <= rect2.y || rect2.y + rect2.height <= rect1.y);
|
||||
}
|
||||
|
||||
ScaleData MergeRects(const ScaleData& rect1, const ScaleData& rect2) {
|
||||
ScaleData merged;
|
||||
merged.x = std::min(rect1.x, rect2.x);
|
||||
merged.y = std::min(rect1.y, rect2.y);
|
||||
merged.width = std::max(rect1.x + rect1.width, rect2.x + rect2.width) - merged.x;
|
||||
merged.height = std::max(rect1.y + rect1.height, rect2.y + rect2.height) - merged.y;
|
||||
return merged;
|
||||
}
|
||||
void Window::AddDirtyRect(ScaleData scale) {
|
||||
ClipRect rect {
|
||||
.left = std::max(scale.x, std::int_fast32_t(0)),
|
||||
.right = std::min(scale.x + scale.width, width),
|
||||
.top = std::max(scale.y, std::int_fast32_t(0)),
|
||||
.bottom = std::min(scale.y + scale.height, height),
|
||||
};
|
||||
|
||||
void Window::AddDirtyRect(ScaleData rect) {
|
||||
bool merged = false;
|
||||
for (auto& existingRect : dirtyRects) {
|
||||
if (Overlaps(existingRect, rect)) {
|
||||
existingRect = MergeRects(existingRect, rect);
|
||||
merged = true;
|
||||
break;
|
||||
if (rect.left >= rect.right || rect.top >= rect.bottom) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ClipRect& existingRect : dirtyRects) {
|
||||
if (rect.left <= existingRect.right && rect.right >= existingRect.left && rect.top <= existingRect.bottom && rect.bottom >= existingRect.top) {
|
||||
existingRect.left = std::min(existingRect.left, rect.left);
|
||||
existingRect.right = std::max(existingRect.right, rect.right);
|
||||
existingRect.top = std::min(existingRect.top, rect.top);
|
||||
existingRect.bottom = std::max(existingRect.bottom, rect.bottom);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!merged) {
|
||||
dirtyRects.push_back(rect);
|
||||
}
|
||||
dirtyRects.push_back(rect);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue