mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Optimizes sprite performance by minimizing the number of calls to action controllers
This commit is contained in:
parent
cb5a2e1751
commit
d9ed5494ee
@ -65,6 +65,7 @@ class Node {
|
||||
ActionController get actions {
|
||||
if (_actions == null) {
|
||||
_actions = new ActionController();
|
||||
if (_spriteBox != null) _spriteBox._actionControllers = null;
|
||||
}
|
||||
return _actions;
|
||||
}
|
||||
@ -201,7 +202,7 @@ class Node {
|
||||
child._spriteBox = this._spriteBox;
|
||||
_childrenLastAddedOrder += 1;
|
||||
child._addedOrder = _childrenLastAddedOrder;
|
||||
if (_spriteBox != null) _spriteBox._eventTargets = null;
|
||||
if (_spriteBox != null) _spriteBox._registerNode(child);
|
||||
}
|
||||
|
||||
/// Removes a child from this node.
|
||||
@ -212,7 +213,7 @@ class Node {
|
||||
if (_children.remove(child)) {
|
||||
child._parent = null;
|
||||
child._spriteBox = null;
|
||||
if (_spriteBox != null) _spriteBox._eventTargets = null;
|
||||
if (_spriteBox != null) _spriteBox._deregisterNode(child);
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,7 +235,7 @@ class Node {
|
||||
}
|
||||
_children = [];
|
||||
_childrenNeedSorting = false;
|
||||
if (_spriteBox != null) _spriteBox._eventTargets = null;
|
||||
if (_spriteBox != null) _spriteBox._deregisterNode(null);
|
||||
}
|
||||
|
||||
void _sortChildren() {
|
||||
|
||||
@ -71,6 +71,8 @@ class SpriteBox extends RenderBox {
|
||||
|
||||
List<Node> _eventTargets;
|
||||
|
||||
List<ActionController> _actionControllers;
|
||||
|
||||
Rect _visibleArea;
|
||||
|
||||
Rect get visibleArea {
|
||||
@ -131,6 +133,18 @@ class SpriteBox extends RenderBox {
|
||||
_callSpriteBoxPerformedLayout(_rootNode);
|
||||
}
|
||||
|
||||
// Adding and removing nodes
|
||||
|
||||
_registerNode(Node node) {
|
||||
_actionControllers = null;
|
||||
_eventTargets = null;
|
||||
}
|
||||
|
||||
_deregisterNode(Node node) {
|
||||
_actionControllers = null;
|
||||
_eventTargets = null;
|
||||
}
|
||||
|
||||
// Event handling
|
||||
|
||||
void _addEventTargets(Node node, List<Node> eventTargets) {
|
||||
@ -342,19 +356,32 @@ class SpriteBox extends RenderBox {
|
||||
// if (_numFrames % 60 == 0)
|
||||
// print("delta: $delta fps: $_frameRate");
|
||||
|
||||
_runActions(_rootNode, delta);
|
||||
_runActions(delta);
|
||||
_callUpdate(_rootNode, delta);
|
||||
|
||||
// Schedule next update
|
||||
_scheduleTick();
|
||||
|
||||
// Make sure the node graph is redrawn
|
||||
markNeedsPaint();
|
||||
}
|
||||
|
||||
void _runActions(Node node, double dt) {
|
||||
if (node._actions != null) {
|
||||
node._actions.step(dt);
|
||||
void _runActions(double dt) {
|
||||
if (_actionControllers == null) {
|
||||
_actionControllers = [];
|
||||
_addActionControllers(_rootNode, _actionControllers);
|
||||
}
|
||||
for (ActionController actions in _actionControllers) {
|
||||
actions.step(dt);
|
||||
}
|
||||
}
|
||||
|
||||
void _addActionControllers(Node node, List<ActionController> controllers) {
|
||||
if (node._actions != null) controllers.add(node._actions);
|
||||
|
||||
for (int i = node.children.length - 1; i >= 0; i--) {
|
||||
Node child = node.children[i];
|
||||
_runActions(child, dt);
|
||||
_addActionControllers(child, controllers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user