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
bd5b9566
Commit
bd5b9566
authored
Aug 07, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #492 from vlidholt/master
Improvements to game performance tests
parents
a0c9ebc0
e691a63e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
12 deletions
+114
-12
test_performance.dart
packages/flutter/example/game/test_performance.dart
+114
-12
No files found.
packages/flutter/example/game/test_performance.dart
View file @
bd5b9566
...
...
@@ -56,7 +56,7 @@ class TestApp extends App {
class
TestPerformance
extends
NodeWithSize
{
final
int
numFramesPerTest
=
100
;
final
int
numTests
=
3
;
final
int
numTests
=
5
;
TestPerformance
()
:
super
(
new
Size
(
1024.0
,
1024.0
))
{
}
...
...
@@ -73,7 +73,7 @@ class TestPerformance extends NodeWithSize {
int
totalTestTime
=
currentTime
-
testStartTime
;
double
millisPerFrame
=
totalTestTime
.
toDouble
()
/
numFramesPerTest
.
toDouble
();
print
(
"
TEST
${test - 1}
fps:
${1.0 / (millisPerFrame / 1000
)}
"
);
print
(
"
- RESULT fps:
${(1.0 / (millisPerFrame / 1000)).toStringAsFixed(1)}
millis/frame:
${millisPerFrame.round(
)}
"
);
// Clear test
removeAllChildren
();
...
...
@@ -81,8 +81,11 @@ class TestPerformance extends NodeWithSize {
if
(
test
<
numTests
)
{
// Start new test
print
(
"TEST
$test
STARTING"
);
setupTest
(
test
);
PerformanceTest
perfTest
=
createTest
(
test
);
addChild
(
perfTest
);
print
(
"TEST
${test + 1}
/
$numTests
STARTING:
${perfTest.name}
"
);
testStartTime
=
new
DateTime
.
now
().
millisecondsSinceEpoch
;
}
test
++;
...
...
@@ -90,21 +93,34 @@ class TestPerformance extends NodeWithSize {
frame
++;
}
void
setup
Test
(
int
n
)
{
PerformanceTest
create
Test
(
int
n
)
{
if
(
test
==
0
)
{
// Test atlas performance
addChild
(
new
TestPerformanceAtlas
()
);
return
new
TestPerformanceAtlas
(
);
}
else
if
(
test
==
1
)
{
// Test
sprite
performance
addChild
(
new
TestPerformanceSprites
()
);
// Test
atlas
performance
return
new
TestPerformanceAtlas2
(
);
}
else
if
(
test
==
2
)
{
// Test sprite performance
return
new
TestPerformanceSprites
();
}
else
if
(
test
==
3
)
{
// Test sprite performance
return
new
TestPerformanceSprites2
();
}
else
if
(
test
==
4
)
{
// Test particle performance
addChild
(
new
TestPerformanceParticles
()
);
return
new
TestPerformanceParticles
(
);
}
return
null
;
}
}
class
TestPerformanceParticles
extends
Node
{
abstract
class
PerformanceTest
extends
Node
{
String
get
name
;
}
class
TestPerformanceParticles
extends
PerformanceTest
{
String
get
name
=>
"64 particle systems"
;
final
grid
=
8
;
TestPerformanceParticles
()
{
for
(
int
x
=
0
;
x
<
grid
;
x
++)
{
...
...
@@ -130,7 +146,9 @@ class TestPerformanceParticles extends Node {
}
}
class
TestPerformanceSprites
extends
Node
{
class
TestPerformanceSprites
extends
PerformanceTest
{
String
get
name
=>
"1001 sprites (24% offscreen)"
;
final
int
grid
=
100
;
TestPerformanceSprites
()
{
...
...
@@ -157,7 +175,38 @@ class TestPerformanceSprites extends Node {
}
}
class
TestPerformanceAtlas
extends
Node
{
class
TestPerformanceSprites2
extends
PerformanceTest
{
String
get
name
=>
"1001 sprites (24% offscreen never added)"
;
final
int
grid
=
100
;
TestPerformanceSprites2
()
{
for
(
int
x
=
12
;
x
<
grid
-
12
;
x
++)
{
for
(
int
y
=
0
;
y
<
grid
;
y
++)
{
Sprite
sprt
=
new
Sprite
(
_spriteSheet
[
"asteroid_big_1.png"
]);
sprt
.
scale
=
1.0
;
sprt
.
position
=
new
Point
(
x
*
1024.0
/
(
grid
-
1
),
y
*
1024.0
/
(
grid
-
1
));
addChild
(
sprt
);
//sprt.actions.run(new ActionRepeatForever(new ActionTween((a) => sprt.rotation = a, 0.0, 360.0, 1.0)));
}
}
Sprite
sprt
=
new
Sprite
(
_spriteSheet
[
"asteroid_big_1.png"
]);
sprt
.
position
=
new
Point
(
512.0
,
512.0
);
addChild
(
sprt
);
}
void
update
(
double
dt
)
{
for
(
Sprite
sprt
in
children
)
{
sprt
.
rotation
+=
1
;
}
}
}
class
TestPerformanceAtlas
extends
PerformanceTest
{
String
get
name
=>
"1001 rects drawAtlas (24% offscreen)"
;
final
int
grid
=
100
;
double
rotation
=
0.0
;
...
...
@@ -207,3 +256,56 @@ class TestPerformanceAtlas extends Node {
return
new
sky
.
RSTransform
(
scos
,
ssin
,
tx
,
ty
);
}
}
class
TestPerformanceAtlas2
extends
PerformanceTest
{
String
get
name
=>
"1001 rects drawAtlas (24% offscreen never added)"
;
final
int
grid
=
100
;
double
rotation
=
0.0
;
List
<
Rect
>
rects
=
[];
Paint
cachedPaint
=
new
Paint
()
..
setFilterQuality
(
sky
.
FilterQuality
.
low
)
..
isAntiAlias
=
false
;
TestPerformanceAtlas2
()
{
for
(
int
x
=
12
;
x
<
grid
-
12
;
x
++)
{
for
(
int
y
=
0
;
y
<
grid
;
y
++)
{
rects
.
add
(
_spriteSheet
[
"asteroid_big_1.png"
].
frame
);
}
}
rects
.
add
(
_spriteSheet
[
"asteroid_big_1.png"
].
frame
);
}
void
paint
(
PaintingCanvas
canvas
)
{
// Setup transforms
List
<
sky
.
RSTransform
>
transforms
=
[];
for
(
int
x
=
12
;
x
<
grid
-
12
;
x
++)
{
for
(
int
y
=
0
;
y
<
grid
;
y
++)
{
double
xPos
=
x
*
1024.0
/
(
grid
-
1
);
double
yPos
=
y
*
1024.0
/
(
grid
-
1
);
transforms
.
add
(
createTransform
(
xPos
,
yPos
,
rects
[
0
].
size
.
width
/
2.0
,
rects
[
0
].
size
.
height
/
2.0
,
rotation
,
1.0
));
}
}
transforms
.
add
(
createTransform
(
512.0
,
512.0
,
rects
[
0
].
size
.
width
/
2.0
,
rects
[
0
].
size
.
height
/
2.0
,
rotation
,
1.0
));
// Draw atlas
Rect
cullRect
=
spriteBox
.
visibleArea
;
canvas
.
drawAtlas
(
_spriteSheet
.
image
,
transforms
,
rects
,
null
,
null
,
cullRect
,
cachedPaint
);
}
void
update
(
double
dt
)
{
rotation
+=
1.0
;
}
sky
.
RSTransform
createTransform
(
double
x
,
double
y
,
double
ax
,
double
ay
,
double
rot
,
double
scale
)
{
double
scos
=
math
.
cos
(
convertDegrees2Radians
(
rot
))
*
scale
;
double
ssin
=
math
.
sin
(
convertDegrees2Radians
(
rot
))
*
scale
;
double
tx
=
x
+
-
scos
*
ax
+
ssin
*
ay
;
double
ty
=
y
+
-
ssin
*
ax
-
scos
*
ay
;
return
new
sky
.
RSTransform
(
scos
,
ssin
,
tx
,
ty
);
}
}
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