Skip to content

Commit

Permalink
Debug frame rates
Browse files Browse the repository at this point in the history
  • Loading branch information
esimov committed Jan 9, 2023
1 parent c017b0d commit 6199663
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

VERSION="1.0.1"
VERSION="0.1.0"
PROTECTED_MODE="no"

export GO15VENDOREXPERIMENT=1
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module github.com/esimov/gio-cloth

go 1.18
go 1.19

require gioui.org v0.0.0-20221216233230-5d1d1df2061c
require (
gioui.org v0.0.0-20230107005120-f8221bb2ab3a
github.com/loov/hrtime v1.0.3
)

require (
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
eliasnaur.com/font v0.0.0-20220124212145-832bb8fc08c3 h1:djFprmHZgrSepsHAIRMp5UJn3PzsoTg9drI+BDmif5Q=
gioui.org v0.0.0-20221216233230-5d1d1df2061c h1:5sweSGj5cjHLJgK4cGI5wNhghp/+JQF+MM0oen8HQA8=
gioui.org v0.0.0-20221216233230-5d1d1df2061c/go.mod h1:3lLo7xMHYnnHTrgKNNctBjEKKH3wQCO2Sn7ti5Jy8mU=
gioui.org v0.0.0-20230107005120-f8221bb2ab3a h1:bxNJ4/p+bHZVstsZDUo1cbxcETfT66N9lgbhMekqBHo=
gioui.org v0.0.0-20230107005120-f8221bb2ab3a/go.mod h1:3lLo7xMHYnnHTrgKNNctBjEKKH3wQCO2Sn7ti5Jy8mU=
gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 h1:AGDDxsJE1RpcXTAxPG2B4jrwVUJGFDjINIPi1jtO6pc=
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
Expand All @@ -13,6 +13,8 @@ github.com/benoitkugler/textlayout-testdata v0.1.1 h1:AvFxBxpfrQd8v55qH59mZOJOQj
github.com/benoitkugler/textlayout-testdata v0.1.1/go.mod h1:i/qZl09BbUOtd7Bu/W1CAubRwTWrEXWq6JwMkw8wYxo=
github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5 h1:iOA0HmtpANn48hX2nlDNMu0VVaNza35HJG0WeetBVzQ=
github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5/go.mod h1:/cmOXaoTiO+lbCwkTZBgCvevJpbFsZ5reXIpEJVh5MI=
github.com/loov/hrtime v1.0.3 h1:LiWKU3B9skJwRPUf0Urs9+0+OE3TxdMuiRPOTwR0gcU=
github.com/loov/hrtime v1.0.3/go.mod h1:yDY3Pwv2izeY4sq7YcPX/dtLwzg5NU1AxWuWxKwd0p0=
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 h1:sBdrWpxhGDdTAYNqbgBLAR+ULAPPhfgncLr1X0lyWtg=
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 h1:ryT6Nf0R83ZgD8WnFFdfI8wCeyqgdXWN4+CkFVNPAT0=
Expand Down
29 changes: 24 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ import (
"time"

"gioui.org/app"
"gioui.org/font/gofont"
"gioui.org/io/key"
"gioui.org/io/pointer"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/paint"
"gioui.org/unit"
"gioui.org/widget/material"

"github.com/loov/hrtime"
)

const (
Expand All @@ -26,12 +30,14 @@ const (

var (
cpuprofile string
debugFrame bool
f *os.File
err error
)

func main() {
flag.StringVar(&cpuprofile, "debug-cpuprofile", "", "write CPU profile to this file")
flag.BoolVar(&debugFrame, "debug-frame", false, "debug the Gio frame rates")
flag.Parse()

if cpuprofile != "" {
Expand Down Expand Up @@ -65,11 +71,13 @@ func loop(w *app.Window) error {
defer pprof.StopCPUProfile()
}

th := material.NewTheme(gofont.Collection())

col := color.NRGBA{R: 0x9a, G: 0x9a, B: 0x9a, A: 0xff}
mouse := &Mouse{maxScrollY: unit.Dp(200)}
isDragging := false

var clothW int = windowWidth * 1.2
var clothW int = windowWidth * 1.3
var clothH int = windowHeight * 0.4
cloth := NewCloth(clothW, clothH, 8, 0.99, col)

Expand All @@ -80,6 +88,7 @@ func loop(w *app.Window) error {
case system.DestroyEvent:
return e.Err
case system.FrameEvent:
start := hrtime.Now()
if cpuprofile != "" {
pprof.StartCPUProfile(f)
}
Expand Down Expand Up @@ -109,7 +118,6 @@ func loop(w *app.Window) error {
},
}.Add(gtx.Ops)

op.InvalidateOp{}.Add(gtx.Ops)
key.InputOp{
Tag: w,
Keys: key.NameEscape + "|" + key.NameCtrl + "|" + key.NameAlt + "|" + key.NameSpace,
Expand Down Expand Up @@ -181,13 +189,24 @@ func loop(w *app.Window) error {
}
}
}

fillBackground(gtx, color.NRGBA{R: 0xf2, G: 0xf2, B: 0xf2, A: 0xff})

cloth.Update(gtx, mouse, 0.015)
e.Frame(gtx.Ops)

w.Invalidate()
if debugFrame {
layout.Stack{}.Layout(gtx,
layout.Stacked(func(gtx layout.Context) layout.Dimensions {
op.Offset(image.Pt(10, 10)).Add(gtx.Ops)
return layout.E.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
m := material.Label(th, unit.Sp(15), hrtime.Since(start).String())
m.Color = color.NRGBA{R: 127, G: 0, B: 0, A: 255}
return m.Layout(gtx)
})
}))
}

op.InvalidateOp{}.Add(gtx.Ops)
e.Frame(gtx.Ops)
}
}
}
Expand Down

0 comments on commit 6199663

Please sign in to comment.