2
DebugPerformance = DebugInstrument:extend
13
onNew = function (self)
14
self.bars = self:add(Group:new())
17
onUpdate = function (self, elapsed)
18
self._sampleTimer = self._sampleTimer + elapsed
19
local fps = math.floor(1 / elapsed + 0.5)
20
self.title.text = 'FPS (' .. fps .. ', average ' .. self.average .. ')'
22
if self._sampleTimer > self.sampleInterval then
23
-- record fps and percent of desired fps
25
table.insert(self.samples, fps)
26
table.insert(self.samples, fps / the.app.fps)
28
if #self.samples > self.numSamples * 2 then
29
table.remove(self.samples, 1)
30
table.remove(self.samples, 1)
37
for i = 1, #self.samples, 2 do
38
sum = sum + self.samples[i]
41
self.average = math.floor(sum / #self.samples * 2 + 0.5)
43
-- sync bars and title bar
45
local barHeight = self.contentHeight - 2 * self.spacing
47
for i, bar in ipairs(self._sampleBars) do
48
local percent = self.samples[i * 2]
51
bar.distort.y = percent
54
-- blend yellow to green
55
bar.fill = {255 * (1 - (percent / 2)), 255, 0}
57
-- blend red to yellow
58
-- 510 * percent = 255 * percent / 2
59
bar.fill = {255, 510 * percent, 0}
70
onResize = function (self, x, y, width, height)
71
local oldSamples = self.numSamples
73
self.y = y + self.spacing
75
self.numSamples = math.floor(width - 2 * self.spacing) / 2
77
if self.numSamples ~= oldSamples then
80
while #self.bars.sprites > 0 do
81
self.bars:remove(self.bars.sprites[1])
84
for i = 1, self.numSamples do
85
self._sampleBars[i] = self.bars:add(Fill:new
90
height = height - self.spacing * 2,
91
origin = { y = height - self.spacing * 2 },
92
distort = { x = 1, y = 0 },
93
fill = {255, 255, 255},