Commit 0041182d authored by Viktor Lidholt's avatar Viktor Lidholt

Optimizes sprites by replacing save/restore by caching the total matrix

parent 54803998
...@@ -37,6 +37,7 @@ class Node { ...@@ -37,6 +37,7 @@ class Node {
int _addedOrder; int _addedOrder;
int _childrenLastAddedOrder = 0; int _childrenLastAddedOrder = 0;
bool _childrenNeedSorting = false; bool _childrenNeedSorting = false;
Matrix4 _savedTotalMatrix;
/// Decides if the node and its children is currently paused. /// Decides if the node and its children is currently paused.
/// ///
...@@ -414,7 +415,7 @@ class Node { ...@@ -414,7 +415,7 @@ class Node {
} }
void _prePaint(PaintingCanvas canvas) { void _prePaint(PaintingCanvas canvas) {
canvas.save(); _savedTotalMatrix = canvas.getTotalMatrix();
// Get the transformation matrix and apply transform // Get the transformation matrix and apply transform
canvas.concat(transformMatrix.storage); canvas.concat(transformMatrix.storage);
...@@ -465,7 +466,7 @@ class Node { ...@@ -465,7 +466,7 @@ class Node {
} }
void _postPaint(PaintingCanvas canvas) { void _postPaint(PaintingCanvas canvas) {
canvas.restore(); canvas.setMatrix(_savedTotalMatrix);
} }
// Receiving update calls // Receiving update calls
......
...@@ -65,7 +65,8 @@ class Sprite extends NodeWithSize { ...@@ -65,7 +65,8 @@ class Sprite extends NodeWithSize {
} }
void paint(PaintingCanvas canvas) { void paint(PaintingCanvas canvas) {
canvas.save(); // Store old matrix
Matrix4 savedMatrix = canvas.getTotalMatrix();
// Account for pivot point // Account for pivot point
applyTransformForPivot(canvas); applyTransformForPivot(canvas);
...@@ -107,8 +108,10 @@ class Sprite extends NodeWithSize { ...@@ -107,8 +108,10 @@ class Sprite extends NodeWithSize {
} else { } else {
// Paint a red square for missing texture // Paint a red square for missing texture
canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height), canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height),
new Paint()..color = const Color.fromARGB(255, 255, 0, 0)); new Paint()..color = new Color.fromARGB(255, 255, 0, 0));
} }
canvas.restore();
// Restore matrix
canvas.setMatrix(savedMatrix);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment