Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
b71d0dfb
Commit
b71d0dfb
authored
Jul 28, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimizes sprite performance by minimizing the number of calls to action controllers
parent
bc496459
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
8 deletions
+36
-8
node.dart
packages/flutter/example/game/lib/node.dart
+4
-3
sprite_box.dart
packages/flutter/example/game/lib/sprite_box.dart
+32
-5
No files found.
packages/flutter/example/game/lib/node.dart
View file @
b71d0dfb
...
@@ -65,6 +65,7 @@ class Node {
...
@@ -65,6 +65,7 @@ class Node {
ActionController
get
actions
{
ActionController
get
actions
{
if
(
_actions
==
null
)
{
if
(
_actions
==
null
)
{
_actions
=
new
ActionController
();
_actions
=
new
ActionController
();
if
(
_spriteBox
!=
null
)
_spriteBox
.
_actionControllers
=
null
;
}
}
return
_actions
;
return
_actions
;
}
}
...
@@ -201,7 +202,7 @@ class Node {
...
@@ -201,7 +202,7 @@ class Node {
child
.
_spriteBox
=
this
.
_spriteBox
;
child
.
_spriteBox
=
this
.
_spriteBox
;
_childrenLastAddedOrder
+=
1
;
_childrenLastAddedOrder
+=
1
;
child
.
_addedOrder
=
_childrenLastAddedOrder
;
child
.
_addedOrder
=
_childrenLastAddedOrder
;
if
(
_spriteBox
!=
null
)
_spriteBox
.
_
eventTargets
=
null
;
if
(
_spriteBox
!=
null
)
_spriteBox
.
_
registerNode
(
child
)
;
}
}
/// Removes a child from this node.
/// Removes a child from this node.
...
@@ -212,7 +213,7 @@ class Node {
...
@@ -212,7 +213,7 @@ class Node {
if
(
_children
.
remove
(
child
))
{
if
(
_children
.
remove
(
child
))
{
child
.
_parent
=
null
;
child
.
_parent
=
null
;
child
.
_spriteBox
=
null
;
child
.
_spriteBox
=
null
;
if
(
_spriteBox
!=
null
)
_spriteBox
.
_
eventTargets
=
null
;
if
(
_spriteBox
!=
null
)
_spriteBox
.
_
deregisterNode
(
child
)
;
}
}
}
}
...
@@ -234,7 +235,7 @@ class Node {
...
@@ -234,7 +235,7 @@ class Node {
}
}
_children
=
[];
_children
=
[];
_childrenNeedSorting
=
false
;
_childrenNeedSorting
=
false
;
if
(
_spriteBox
!=
null
)
_spriteBox
.
_
eventTargets
=
null
;
if
(
_spriteBox
!=
null
)
_spriteBox
.
_
deregisterNode
(
null
)
;
}
}
void
_sortChildren
()
{
void
_sortChildren
()
{
...
...
packages/flutter/example/game/lib/sprite_box.dart
View file @
b71d0dfb
...
@@ -71,6 +71,8 @@ class SpriteBox extends RenderBox {
...
@@ -71,6 +71,8 @@ class SpriteBox extends RenderBox {
List
<
Node
>
_eventTargets
;
List
<
Node
>
_eventTargets
;
List
<
ActionController
>
_actionControllers
;
Rect
_visibleArea
;
Rect
_visibleArea
;
Rect
get
visibleArea
{
Rect
get
visibleArea
{
...
@@ -131,6 +133,18 @@ class SpriteBox extends RenderBox {
...
@@ -131,6 +133,18 @@ class SpriteBox extends RenderBox {
_callSpriteBoxPerformedLayout
(
_rootNode
);
_callSpriteBoxPerformedLayout
(
_rootNode
);
}
}
// Adding and removing nodes
_registerNode
(
Node
node
)
{
_actionControllers
=
null
;
_eventTargets
=
null
;
}
_deregisterNode
(
Node
node
)
{
_actionControllers
=
null
;
_eventTargets
=
null
;
}
// Event handling
// Event handling
void
_addEventTargets
(
Node
node
,
List
<
Node
>
eventTargets
)
{
void
_addEventTargets
(
Node
node
,
List
<
Node
>
eventTargets
)
{
...
@@ -342,19 +356,32 @@ class SpriteBox extends RenderBox {
...
@@ -342,19 +356,32 @@ class SpriteBox extends RenderBox {
// if (_numFrames % 60 == 0)
// if (_numFrames % 60 == 0)
// print("delta: $delta fps: $_frameRate");
// print("delta: $delta fps: $_frameRate");
_runActions
(
_rootNode
,
delta
);
_runActions
(
delta
);
_callUpdate
(
_rootNode
,
delta
);
_callUpdate
(
_rootNode
,
delta
);
// Schedule next update
_scheduleTick
();
_scheduleTick
();
// Make sure the node graph is redrawn
markNeedsPaint
();
markNeedsPaint
();
}
}
void
_runActions
(
Node
node
,
double
dt
)
{
void
_runActions
(
double
dt
)
{
if
(
node
.
_actions
!=
null
)
{
if
(
_actionControllers
==
null
)
{
node
.
_actions
.
step
(
dt
);
_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
--)
{
for
(
int
i
=
node
.
children
.
length
-
1
;
i
>=
0
;
i
--)
{
Node
child
=
node
.
children
[
i
];
Node
child
=
node
.
children
[
i
];
_
runActions
(
child
,
dt
);
_
addActionControllers
(
child
,
controllers
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment