1. LWF
in
real
life:
「どうぶつフレンズ」の開発事例
David
Gavilan
david.gavilan@gree.net
GREE
2. Agenda
• About
“Animal
Days”
• About
LWF
• Texture
packing
• Common
boFlenecks
• Profiling
your
game
• InvesJgaJng
leaks
• OpJmizaJons
3.
4. Animal
Days
/
どうぶつフレンズ
• 2D
Game
• Current
plaOorm:
Android
2.2
and
up
• Categories:
City
building
&
breeding
simulaJon
• Main
tech
on
the
client
– Unity
3.5.7,
4.0
latest
(4.1
for
Profiling)
– LWF
– Webview
• Tools:
TexturePacker,
Xcode,
ADB
10. LWF
data
creaJon
• .fla/.swf
→
.lwf
– 1-‐step
script-‐based
conversion
→
can
be
easily
batched
– Can
customize
the
texture
and
data
loaders,
– Can
dynamically
change
the
Z-‐posiJon
of
the
movie
clips,
– …
and
more!
11. LWF
renderers
• DrawMeshRenderer
– For
a
given
frame,
•
N
movie
clips
=
N
meshes
=
N
draw
calls
– Slow,
but
there's
no
problem
with
Z-‐sorJng
– Separate
textures
for
each
clip
→
DrawMeshRenderer
• CombinedMeshRenderer
– For
a
given
frame,
• N
movie
clips
=
1
mesh
=
1
draw
call
– Faster,
but
Z-‐sorJng
works
per-‐object
– You
need
to
pack
all
your
texture
in
a
single
texture
atlas/sheet
13. Texture
packing
• Remember
this:
PACK
EVERYTHING
• We
use
TexturePacker:
hFp://www.codeandweb.com/texturepacker
14. Texture
sheets
♡
LWF
• Enables
CombinedMeshRenderer
– only
1
Draw
Call
per
LWF
object
(worst
case)
– if
the
objects
share
the
same
material,
they
can
also
be
dynamically
batched
(N
objects
in
1
Draw
Call)
16. Texture
sheets
♡
LWF
• If
you
have
problems
with
Z-‐sorJng
(need
to
place
parts
of
the
same
UI
before
and
behind
another
object),
you
can
always
easily
switch
back
to
DrawMeshRenderer
17. Texture
sheets
♡
Versioning
• Can
compare
the
changes
in
the
JSON
file
• With
one
glimpse
you
can
check
the
changes
in
one
asset
over
github
19. Texture
sheets
♡
ProducJon
• Awesome
for
controlling
your
texture
budget!
– For
rendering
and
for
bundling!
• Try
to
answer
these
quesJons:
– How
many
objects
can
we
render?
– How
much
space
is
taken
by
UI
elements?
– How
long
does
it
take
to
download
all
the
assets?
20. Texture
sheets
♡
ProducJon
• Once
you
decide
your
budget,
make
scripts
to
automaJcally
popup
warnings/errors:
21. Texture
sheets
♡
ProducJon
• Pack
all
your
texture
sheets
in
a
single
texture
for
visualizaJon
– Easily
detect
assets
using
too
much
space
– Good
to
check
the
amount
of
"empty
space"
– Good
to
explain
to
directors
and
arJsts
the
goods
and
wrongs
27. Common
boFlenecks
• Rendering
– For
a
2D
game,
fill-‐rate
is
probably
the
most
common
rendering
boFleneck
– Reduce
number
of
draw
calls
– Reduce
render
area
• Object
updates
– Update
only
when
necessary
• Network
access
– Reduce
data
size
→
smaller
textures
28. Profiling
your
game
• Pick
up
a
slow
device
– Even
if
you
target
a
high-‐spec
device,
in
slow
devices
the
boFlenecks
are
easier
to
spot
– Eg.
We
target
~Samsung
Galaxy
S2,
but
I
use
Sharp
IS03
for
profiling
32. Profiling:
Game
window
• Prepare
debugging
scripts
so
you
can
easily
debug
in
the
device,
even
without
Unity
Profiler
– Use
Time.deltaTime
to
create
a
simple
FPS
counter
– Create
a
custom
memory
profiler;
– it
doesn’t
need
to
be
fancy:
just
count
objects
36. Create
test
scenes
• Test
scenes
are
good
to
esJmate
the
maximum
amount
of
data/assets
we
can
handle/display
in
different
devices
• They
are
good
for
invesJgaJng
leaks
too
39. InvesJgaJng
leaks
with
adb
• adb
gives
you
important
informaJon!
(and
is
scriptable)
• Check
Pss
(ProporJonal
set
size:
the
amount
of
pages
a
process
has
in
memory)
• If
Pss
is
too
big,
the
OS
will
kill
your
app
→
check
for
low
memory
warnings
• Eg.
on
IS03,
~260MB
will
get
your
app
terminated
42. Replace
all
textures
• To
compute
texture
impact,
replace
all
textures
by
very
small
ones
(8×8)
43. Count
references
• For
non-‐Unity.Objects,
add
simple
counters
for
your
debugging
scripts
• If
the
destructor
is
never
called,
it
means
it
never
gets
GC'ed
!!
44. Nullify
everything
• Object
references
can
be
kept
in
memory
for
obscure
reasons
(mono?).
Eg.
using
the
argument
of
a
lambda
funcJon
inside
another
lambda
funcJon
• As
a
general
pracJce,
set
to
null
the
references
you
don't
need
anymore,
even
local
variables
and
pointers
to
callback
funcJons
48. OpJmizaJon:
Object
updates
• Don't
update
objects
outside
camera
view
• Limit
the
number
of
objects
that
can
be
updated/
animated
– Eg.
From
all
the
visible
characters,
the
LWF
update
is
called
for
N
at
most
– Change
N
depending
on
the
device
capabiliJes.
Eg.
Nhigh_spec
=
25;
Nlow_spec
=
12
• Be
polite
and
save
baFery
– Only
use
60fps
when
interacJng
(touching
screen)
49. Rendering:
limit
max
drawable
objects
• Check
FPS
on
the
device,
and
take
note
of
the
slow
scenes
• On
the
Editor,
check
the
number
of
draw
calls
for
those
scenes.
• Eg.
for
low-‐spec
devices,
set
a
more
restricJve
zoom-‐out
level
50. Rendering:
check
fill-‐rate
• If
Camera.Render
is
slow
even
for
simple
scenes,
reduce
the
resoluJon
of
the
backbuffer
(to
a
respectable
DPI)
51. Reduce
draw
calls
by
using
Z-‐layers
• If
possible,
place
all
the
LWF
that
share
the
same
material
far
from
others,
so
they
can
be
dynamically
batched
• Eg.
Our
bubbles
all
live
far
away
and
they
are
rendered
in
1
draw
call
52. …
when
aFaching
LWFs
• …
to
replace
a
movie
clip,
make
sure
the
clip
is
in
front
to
avoid
Z-‐sorJng
problems
when
using
CombinedMeshRenderer
3
draw
calls
Character
and
Rainbow
are
aFached
to
the
Flash
UI
53. Reduce
draw
calls
with
custom
2D
• Eg.
Use
point-‐sampled
textures
to
render
lines
and
grid
cells
55. Wrap-‐up
• For
2D
games,
Unity
&
LWF
make
a
perfect
match
• Use
Texture
sheets
everywhere
– Enable
faster
rendering
in
LWF
– Good
for
controlling
texture
budgets
– Good
for
visually
detect
problems
• When
profiling,
– Use
external
tools
to
detect
real
problems
in
devices
– Once
a
possible
problem
is
detected,
use
Unity
Editor
to
extract
as
much
informaJon
as
possible
and
for
quick
debugging
• "Animal
Days"
is
cute.
Please
play!