Game Development Reference
In-Depth Information
now
=
Gosu
.
milliseconds
if
now
-
(
@caption_updated_at
|| 0
)
> 1000
$window
.
caption
=
'Tanks Prototype. '
<<
"[FPS:
#{
Gosu
.
fps
}
. "
<<
"Tank @
#{
@tank
.
x
.
round
}
:
#{
@tank
.
y
.
round
}
]"
@caption_updated_at
=
now
end
end
end
Now it's getting hard to get FPS to drop below 58, and profiling results show that there are
no more bottlenecks:
Profiling results for
PlayState
after introducing
Gosu::Window#caption
cache
We can now sleep well at night.
Profiling On Demand
When you develop a game, you may want to turn on profiling now and then. To avoid
commenting out or adding and removing profiling every time you want to do so, use this
trick:
# ...
require
'ruby-prof'
if
ENV
[
'ENABLE_PROFILING'
]
class
PlayState
<
GameState
# ...
def
enter
RubyProf
.
start
if
ENV
[
'ENABLE_PROFILING'
]
end
def
leave
if
ENV
[
'ENABLE_PROFILING'
]
result
=
RubyProf
.
stop
printer
=
RubyProf
::
FlatPrinter
.
new(result)
printer
.
print(
STDOUT
)
end
end