Game Development Reference
In-Depth Information
After saving
camera.rb
and running the game without profiling, you will notice a
significant speedup. Hypothesis was correct, checking visibility is more expensive than
simply rendering it. That means we can throw away
Camera#can_view?
and calls to it.
But before doing that, let's profile once again:
Profiling results after short-circuiting
Camera#can_view?
We can see
Camera#can_view?
is still in top 3, so we will remove
if
camera.can_view?(map_x, map_y, tile)
from
Map#draw
and for now keep
it like this:
class
Map
# ...
def
draw
(camera)
@map
.
each
do
|
x, row
|
row
.
each
do
|
y, val
|
tile
=
@map
[
x
][
y
]
map_x
=
x
*
TILE_SIZE
map_y
=
y
*
TILE_SIZE
tile
.
draw(map_x, map_y,
0
)
end
end
end
# ...
end
After completely removing
Camera#can_view?
, profiling session looks like dead-end
- no more low hanging fruits on top:
Profiling results after removing
Camera#can_view?