4 Commits
v1 ... master

Author SHA1 Message Date
Paul Liverman III
b433ddc889 slight improvement 2017-07-26 23:25:45 -07:00
/Fox --develop
9215842cc8 Update README.md 2017-07-26 23:21:15 -07:00
Paul Liverman III
eb128e3ecc fixed some derpy stuff and implemented lower bounds on depth and step size 2017-07-26 23:10:29 -07:00
Paul Liverman III
8869727321 scaling mostly working 2017-07-26 23:08:50 -07:00
3 changed files with 79 additions and 92 deletions

View File

@@ -4,31 +4,33 @@ Graphical profiler for Love2D >= 0.9.2
Originally by devfirefly, heavily modified by Guard13007.
Note that a lot of functionality is undocumented right now, and that some functionality doesn't work as originally intended (such as setting the position and scale of the profiler). The default settings should get you going pretty easily, the key thing to maybe change is calling the constructor with a table with its own `scale` value.
# Usage
1) Require the file:
```lua
local piefiller = require("piefiller")
local Piefiller = require("piefiller")
```
2) Make a new instance of piefiller:
```lua
local Pie = piefiller:new()
local pie = Piefiller()
```
3) Attach the piefiller to the part of your application that you want to monitor (love.update and love.draw typically are good places):
```lua
function love.update()
Pie:attach()
pie:attach()
-- do something
Pie:detach()
pie:detach()
end
```
4) Draw the output and pass key events to your piefiller:
```lua
function love.draw()
Pie:draw()
pie:draw()
end
function love.keypressed(key)
Pie:keypressed(key)
pie:keypressed(key)
end
```
5) With sufficient output, press the `E` key to output to file. Example output:
@@ -78,13 +80,13 @@ show_profiler
To redefine only one of the keys:
```lua
piefiller:setKey(command, key)
pie:setKey(command, key)
```
example:
```lua
piefiller:setKey("increase_depth","up")
pie:setKey("increase_depth","up")
```
To redefine all of the keys:
@@ -92,12 +94,12 @@ To redefine all of the keys:
table = {
"increase_depth" = "up"
}
piefiller:setKey(table)
pie:setKey(table)
```
# For your own interpretation
If you wish to interpret the data on your own use `piefiller:unpack()`.
If you wish to interpret the data on your own use `pie:unpack()`.
Output is a table as such:
```lua

View File

@@ -38,6 +38,7 @@ function love.draw()
profiler:draw()
-- temporary
love.graphics.setColor(255, 255, 255, 255)
love.graphics.line(w/2, 0, w/2, h)
love.graphics.line(0, h/2, w, h/2)
end
@@ -61,3 +62,13 @@ function love.keypressed(key)
profiler:keypressed(key)
end
function love.wheelmoved(x, y)
if y < 0 then
-- up
profiler.scale = profiler.scale - 0.1
else
-- down
profiler.scale = profiler.scale + 0.1
end
end

View File

@@ -63,9 +63,9 @@ function piefiller:new(settings)
self.timer = 0
self.depth = 2
self.small = false
self.x = 0.5
self.y = 0.5
self.scale = 0.5
self.x = 0
self.y = 0
self.scale = 0.4
self.font = love.graphics.newFont(16 / self.scale)
self.visible = true
self.step = 1
@@ -221,7 +221,11 @@ end
function piefiller:getText(v)
if self.small then
return tostring(math.ceil(v.prc)).."% "..tostring(v.src)..":"..tostring(v.def)
if v.src:sub(1,1) == "@" then
return tostring(math.ceil(v.prc)).."% "..tostring(v.src:sub(2))..":"..tostring(v.def)
else
return tostring(math.ceil(v.prc)).."% "..tostring(v.src)..":"..tostring(v.def)
end
else
if v.src:sub(1,1) == "@" then
return tostring(math.ceil(v.prc)).."% "..tostring(v.name)..tostring(v.src)..":"..tostring(v.def)
@@ -239,37 +243,37 @@ function piefiller:draw(args)
local loading
local oldFont = love.graphics.getFont()
local oldLineJoin = love.graphics.getLineJoin()
local args = args or {}
local rad = args.radius
local mode = args.mode or "list" -- "original" for the original style
local pi = math.pi
local arc = love.graphics.arc
local w,h = love.graphics.getDimensions()
if not args.radius then
if mode == "list" then
rad = h * self.scale - 2 / self.scale
elseif mode == "original" then
rad = 200
end
end
local args = args or {}
local rad = args.radius or (h * self.scale - 2 / self.scale)
local mode = args.mode or "original" -- "original" for the original style
love.graphics.push()
love.graphics.translate(self.x * w - w/2, self.y * h - h/2)
love.graphics.translate(self.x, self.y)
love.graphics.scale(self.scale)
love.graphics.setLineJoin("bevel")
love.graphics.setFont(self.font)
local cx = w/2 + (rad*2 - w)/2 + 2 / self.scale
local cy = h * self.scale
local maxLength = 0
for i,v in ipairs(self.parsed) do
local s = self.font:getWidth(self:getText(v))
if s > maxLength then maxLength = s end
end
setColor(self.background)
love.graphics.rectangle("fill", 0, 0, w, h)
love.graphics.rectangle("fill", 0, 0, cx * 2 + 2 / self.scale + maxLength, cy * 2)
if self.parsed and self.totaltime > 0 then
local lastangle = 0
for i,v in ipairs(self.parsed) do
local color = v.color
local cx,cy = w/2,h/2
local angle = math.rad(3.6*v.prc)
setColor(color)
arc("fill",cx,cy,rad,lastangle,lastangle + angle)
@@ -280,72 +284,38 @@ function piefiller:draw(args)
lastangle = lastangle + angle
end
love.graphics.circle("line", w/2, h/2, rad) -- make sure there is an outer white border
love.graphics.circle("line", cx, cy, rad) -- make sure there is an outer white border
if mode == "list" then
local x = w/2 + rad + 2 / self.scale
local y = h/2 - rad
local x = cx + rad + 2 / self.scale
local y = cy - rad
love.graphics.print("Depth: "..self.depth.." Step: "..self.step, x, y)
y = y + self.font:getHeight()
local sorted = {}
for i,v in ipairs(self.parsed) do
sorted[i] = {i, v.prc}
end
table.sort(sorted,function(a,b)
return a[2] > b[2]
end)
for _,i in ipairs(sorted) do
local v = self.parsed[i[1]]
local color = v.color
local txt = self:getText(v)
setColor(color)
love.graphics.print(txt, x, y)
y = y + self.font:getHeight()
end
elseif mode == "original" then
local font = love.graphics.getFont()
lastangle = 0
for i,v in ipairs(self.parsed) do
local color = v.color
local cx,cy = w/2,h/2
local angle = math.rad(3.6*v.prc)
local x = cx + rad * math.cos(lastangle + angle/2)
local y = cy + rad * math.sin(lastangle + angle/2)
local txt = self:getText(v)
local fw = font:getWidth(txt)
local sx = 1
if cx < x then
sx = -1
fw = 0
end
if cy + rad/2 < y then
y = y + font:getHeight()
elseif cy + rad/2 > y then
y = y - font:getHeight()
end
love.graphics.print(txt,((x) + (-(fw+20))*sx),y)
lastangle = lastangle + angle
end
setColor()
local t = "Depth: "..self.depth.." with step: "..self.step
local fw = self.font:getWidth(t)
local fh = self.font:getHeight()
love.graphics.print(t,w/2 - fw/2,(fh+5)) -- TODO re-position this
if loading then
t = "Loading..."
fw = self.font:getWidth(t)
love.graphics.print("Loading...",w/2 - fw/2,h/2)
end
else
error("Invalid draw mode. Should be 'list' or 'original'.")
local sorted = {}
for i,v in ipairs(self.parsed) do
sorted[i] = {i, v.prc}
end
table.sort(sorted,function(a,b)
return a[2] > b[2]
end)
for _,i in ipairs(sorted) do
local v = self.parsed[i[1]]
local color = v.color
local txt = self:getText(v)
setColor(color)
love.graphics.print(txt, x, y)
y = y + self.font:getHeight()
end
else
loading = true
-- REFACTOR
setColor()
local t = "Loading..."
local fh = self.font:getHeight()
fw = self.font:getWidth(t)
love.graphics.print("Loading...", w/2 - fw/2, h/2)
-- END
end
-- our timing is handled in draw... why? My guess is because we aren't called in update
@@ -376,13 +346,17 @@ function piefiller:keypressed(key)
self.depth = self.depth + 1
elseif command == "decrease_depth" then
self:reset()
self.depth = self.depth - 1
if self.depth > 1 then
self.depth = self.depth - 1
end
elseif command == "increase_step_size" then
self:reset()
self.step = self.step - 1
self.step = self.step + 1
elseif command == "decrease_step_size" then
self:reset()
self.step = self.step +1
if self.step > 0 then
self.step = self.step - 1
end
elseif command == "shorten_names" then
self.small = not self.small
elseif command == "show_hidden" then