Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_34031325
engine
提交
b15dd6ac
E
engine
项目概览
qq_34031325
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b15dd6ac
编写于
7月 24, 2015
作者:
V
Viktor Lidholt
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #273 from vlidholt/master
Optimizations for Particle Systems
上级
a2887a83
6a8e4898
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
101 addition
and
25 deletion
+101
-25
sky/sdk/example/game/lib/color_secuence.dart
sky/sdk/example/game/lib/color_secuence.dart
+4
-6
sky/sdk/example/game/lib/particle_system.dart
sky/sdk/example/game/lib/particle_system.dart
+15
-19
sky/sdk/example/game/lib/sprites.dart
sky/sdk/example/game/lib/sprites.dart
+1
-0
sky/sdk/example/game/lib/util.dart
sky/sdk/example/game/lib/util.dart
+81
-0
未找到文件。
sky/sdk/example/game/lib/color_secuence.dart
浏览文件 @
b15dd6ac
...
...
@@ -24,13 +24,11 @@ class ColorSequence {
colors
=
new
List
<
Color
>();
colorStops
=
new
List
<
double
>.
from
(
sequence
.
colorStops
);
math
.
Random
rand
=
new
math
.
Random
();
for
(
Color
color
in
sequence
.
colors
)
{
int
aDelta
=
((
rand
.
next
Double
()
*
2.0
-
1.0
)
*
alphaVar
).
toInt
();
int
rDelta
=
((
rand
.
next
Double
()
*
2.0
-
1.0
)
*
redVar
).
toInt
();
int
gDelta
=
((
rand
.
next
Double
()
*
2.0
-
1.0
)
*
greenVar
).
toInt
();
int
bDelta
=
((
rand
.
next
Double
()
*
2.0
-
1.0
)
*
blueVar
).
toInt
();
int
aDelta
=
((
rand
om
Double
()
*
2.0
-
1.0
)
*
alphaVar
).
toInt
();
int
rDelta
=
((
rand
om
Double
()
*
2.0
-
1.0
)
*
redVar
).
toInt
();
int
gDelta
=
((
rand
om
Double
()
*
2.0
-
1.0
)
*
greenVar
).
toInt
();
int
bDelta
=
((
rand
om
Double
()
*
2.0
-
1.0
)
*
blueVar
).
toInt
();
int
aNew
=
(
color
.
alpha
+
aDelta
).
clamp
(
0
,
255
);
int
rNew
=
(
color
.
red
+
rDelta
).
clamp
(
0
,
255
);
...
...
sky/sdk/example/game/lib/particle_system.dart
浏览文件 @
b15dd6ac
...
...
@@ -80,8 +80,6 @@ class ParticleSystem extends Node {
// double _elapsedTime;
int
_numEmittedParticles
=
0
;
math
.
Random
_rand
;
ParticleSystem
(
this
.
texture
,
{
this
.
life
:
1.5
,
this
.
lifeVar
:
1.0
,
...
...
@@ -116,7 +114,6 @@ class ParticleSystem extends Node {
this
.
numParticlesToEmit
:
0
,
this
.
autoRemoveOnFinish
:
true
})
{
_particles
=
new
List
<
_Particle
>();
_rand
=
new
math
.
Random
();
_emitCounter
=
0.0
;
// _elapsedTime = 0.0;
if
(
gravity
==
null
)
gravity
=
new
Vector2
.
zero
();
...
...
@@ -124,6 +121,8 @@ class ParticleSystem extends Node {
}
void
update
(
double
dt
)
{
// TODO: Fix this (it's a temp fix for low framerates)
if
(
dt
>
0.1
)
dt
=
0.1
;
// Create new particles
double
rate
=
1.0
/
emissionRate
;
...
...
@@ -196,34 +195,34 @@ class ParticleSystem extends Node {
_Particle
particle
=
new
_Particle
();
// Time to live
particle
.
timeToLive
=
math
.
max
(
life
+
lifeVar
*
rand
Minus1To1
(),
0.0
);
particle
.
timeToLive
=
math
.
max
(
life
+
lifeVar
*
rand
omSignedDouble
(),
0.0
);
// Position
Point
srcPos
=
Point
.
origin
;
particle
.
pos
=
new
Vector2
(
srcPos
.
x
+
posVar
.
x
*
rand
Minus1To1
(),
srcPos
.
y
+
posVar
.
y
*
rand
Minus1To1
());
particle
.
pos
=
new
Vector2
(
srcPos
.
x
+
posVar
.
x
*
rand
omSignedDouble
(),
srcPos
.
y
+
posVar
.
y
*
rand
omSignedDouble
());
// Size
particle
.
size
=
math
.
max
(
startSize
+
startSizeVar
*
rand
Minus1To1
(),
0.0
);
double
endSizeFinal
=
math
.
max
(
endSize
+
endSizeVar
*
rand
Minus1To1
(),
0.0
);
particle
.
size
=
math
.
max
(
startSize
+
startSizeVar
*
rand
omSignedDouble
(),
0.0
);
double
endSizeFinal
=
math
.
max
(
endSize
+
endSizeVar
*
rand
omSignedDouble
(),
0.0
);
particle
.
deltaSize
=
(
endSizeFinal
-
particle
.
size
)
/
particle
.
timeToLive
;
// Rotation
particle
.
rotation
=
startRotation
+
startRotationVar
*
rand
Minus1To1
();
double
endRotationFinal
=
endRotation
+
endRotationVar
*
rand
Minus1To1
();
particle
.
rotation
=
startRotation
+
startRotationVar
*
rand
omSignedDouble
();
double
endRotationFinal
=
endRotation
+
endRotationVar
*
rand
omSignedDouble
();
particle
.
deltaRotation
=
(
endRotationFinal
-
particle
.
rotation
)
/
particle
.
timeToLive
;
// Direction
double
dirRadians
=
convertDegrees2Radians
(
direction
+
directionVar
*
rand
Minus1To1
());
double
dirRadians
=
convertDegrees2Radians
(
direction
+
directionVar
*
rand
omSignedDouble
());
Vector2
dirVector
=
new
Vector2
(
math
.
cos
(
dirRadians
),
math
.
sin
(
dirRadians
));
double
speedFinal
=
speed
+
speedVar
*
rand
Minus1To1
();
double
speedFinal
=
speed
+
speedVar
*
rand
omSignedDouble
();
particle
.
dir
=
dirVector
.
scale
(
speedFinal
);
// Radial acceleration
particle
.
radialAccel
=
radialAcceleration
+
radialAccelerationVar
*
rand
Minus1To1
();
particle
.
radialAccel
=
radialAcceleration
+
radialAccelerationVar
*
rand
omSignedDouble
();
// Tangential acceleration
particle
.
tangentialAccel
=
tangentialAcceleration
+
tangentialAccelerationVar
*
rand
Minus1To1
();
particle
.
tangentialAccel
=
tangentialAcceleration
+
tangentialAccelerationVar
*
rand
omSignedDouble
();
// Color
particle
.
colorPos
=
0.0
;
...
...
@@ -248,7 +247,7 @@ class ParticleSystem extends Node {
double
scos
;
double
ssin
;
if
(
rotateToMovement
)
{
double
extraRotation
=
m
ath
.
atan2
(
particle
.
dir
[
1
],
particle
.
dir
[
0
]);
double
extraRotation
=
GameM
ath
.
atan2
(
particle
.
dir
[
1
],
particle
.
dir
[
0
]);
scos
=
math
.
cos
(
convertDegrees2Radians
(
particle
.
rotation
)
+
extraRotation
)
*
particle
.
size
;
ssin
=
math
.
sin
(
convertDegrees2Radians
(
particle
.
rotation
)
+
extraRotation
)
*
particle
.
size
;
}
else
{
...
...
@@ -275,10 +274,7 @@ class ParticleSystem extends Node {
Paint
paint
=
new
Paint
()..
setTransferMode
(
transferMode
)
..
setFilterQuality
(
FilterQuality
.
low
)
// All Skia examples do this.
..
isAntiAlias
=
false
;
// Antialiasing breaks SkCanvas.drawAtlas?
return
canvas
.
drawAtlas
(
texture
.
image
,
transforms
,
rects
,
colors
,
canvas
.
drawAtlas
(
texture
.
image
,
transforms
,
rects
,
colors
,
TransferMode
.
modulate
,
null
,
paint
);
}
double
randMinus1To1
()
=>
_rand
.
nextDouble
()
*
2.0
-
1.0
;
}
sky/sdk/example/game/lib/sprites.dart
浏览文件 @
b15dd6ac
...
...
@@ -7,6 +7,7 @@ library sprites;
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:math'
as
math
;
import
'dart:typed_data'
;
import
'dart:sky'
;
import
'package:sky/animation/curves.dart'
;
...
...
sky/sdk/example/game/lib/util.dart
浏览文件 @
b15dd6ac
part of
sprites
;
math
.
Random
_random
=
new
math
.
Random
();
// Random methods
double
randomDouble
(
)
{
return
_random
.
nextDouble
();
}
double
randomSignedDouble
(
)
{
return
_random
.
nextDouble
()
*
2.0
-
1.0
;
}
int
randomInt
(
int
max
)
{
return
_random
.
nextInt
(
max
);
}
// atan2
class
_Atan2Constants
{
_Atan2Constants
()
{
for
(
int
i
=
0
;
i
<=
size
;
i
++)
{
double
f
=
i
.
toDouble
()
/
size
.
toDouble
();
ppy
[
i
]
=
math
.
atan
(
f
)
*
stretch
/
math
.
PI
;
ppx
[
i
]
=
stretch
*
0.5
-
ppy
[
i
];
pny
[
i
]
=
-
ppy
[
i
];
pnx
[
i
]
=
ppy
[
i
]
-
stretch
*
0.5
;
npy
[
i
]
=
stretch
-
ppy
[
i
];
npx
[
i
]
=
ppy
[
i
]
+
stretch
*
0.5
;
nny
[
i
]
=
ppy
[
i
]
-
stretch
;
nnx
[
i
]
=
-
stretch
*
0.5
-
ppy
[
i
];
}
}
static
const
int
size
=
1024
;
static
const
double
stretch
=
math
.
PI
;
static
const
int
ezis
=
-
size
;
final
Float64List
ppy
=
new
Float64List
(
size
+
1
);
final
Float64List
ppx
=
new
Float64List
(
size
+
1
);
final
Float64List
pny
=
new
Float64List
(
size
+
1
);
final
Float64List
pnx
=
new
Float64List
(
size
+
1
);
final
Float64List
npy
=
new
Float64List
(
size
+
1
);
final
Float64List
npx
=
new
Float64List
(
size
+
1
);
final
Float64List
nny
=
new
Float64List
(
size
+
1
);
final
Float64List
nnx
=
new
Float64List
(
size
+
1
);
}
class
GameMath
{
static
final
_Atan2Constants
_atan2
=
new
_Atan2Constants
();
static
double
atan2
(
double
y
,
double
x
)
{
if
(
x
>=
0
)
{
if
(
y
>=
0
)
{
if
(
x
>=
y
)
return
_atan2
.
ppy
[(
_Atan2Constants
.
size
*
y
/
x
+
0.5
).
floor
()];
else
return
_atan2
.
ppx
[(
_Atan2Constants
.
size
*
x
/
y
+
0.5
).
floor
()];
}
else
{
if
(
x
>=
-
y
)
return
_atan2
.
pny
[(
_Atan2Constants
.
ezis
*
y
/
x
+
0.5
).
floor
()];
else
return
_atan2
.
pnx
[(
_Atan2Constants
.
ezis
*
x
/
y
+
0.5
).
floor
()];
}
}
else
{
if
(
y
>=
0
)
{
if
(-
x
>=
y
)
return
_atan2
.
npy
[(
_Atan2Constants
.
ezis
*
y
/
x
+
0.5
).
floor
()];
else
return
_atan2
.
npx
[(
_Atan2Constants
.
ezis
*
x
/
y
+
0.5
).
floor
()];
}
else
{
if
(
x
<=
y
)
return
_atan2
.
nny
[(
_Atan2Constants
.
size
*
y
/
x
+
0.5
).
floor
()];
else
return
_atan2
.
nnx
[(
_Atan2Constants
.
size
*
x
/
y
+
0.5
).
floor
()];
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录