commit b8ec173466593611f68bd7da8ab074ffe265169d
parent 08fc4868fc1b2ecf69caddbfd35b8bf895563801
Author: glenda <glenda@kobeni>
Date: Sun, 7 Jan 2024 20:34:01 +0000
src/noise: add fps
Diffstat:
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/src/noise/dnoise.c b/src/noise/dnoise.c
@@ -31,7 +31,6 @@ void dn_init(void *)
void dn_draw(void *)
{
read(dns.f, dns.buf, dns.n);
- //loadimage(screen, screen->r, dns.buf, dns.n);
loadimage(dns.Ibuf, dns.Ibuf->r, dns.buf, dns.n);
draw(screen, screen->r, dns.Ibuf, nil, ZP);
}
diff --git a/src/noise/main.c b/src/noise/main.c
@@ -11,14 +11,35 @@
Scene *cs;
+struct FPSWidget {
+ char buf[256];
+ Image *img, *fg;
+ int count;
+ Rectangle r;
+} fps;
+
+long OT, NT, DT;
+
void
procdraw(void *v)
{
Scene *sp = v;
threadsetname("draw-loop");
+ OT = nsec();
for (;;) {
lockdisplay(display);
if (sp->draw != nil) sp->draw(sp->aux);
+ draw(screen, rectaddpt(fps.r, screen->r.min), fps.img, nil, ZP);
+ fps.count++;
+ NT = nsec();
+ DT = NT - OT;
+ if (DT >= 1000000000) {
+ OT = NT;
+ snprint(fps.buf, 256, "%d", fps.count);
+ fps.r.max.x = stringbg(fps.img, ZP, fps.fg, ZP, font,
+ fps.buf, display->black, ZP).x;
+ fps.count = 0;
+ }
flushimage(display, 1);
unlockdisplay(display);
yield();
@@ -38,6 +59,11 @@ threadmain(int, char **)
display->locking = 1;
mctl = initmouse(nil, screen);
+ fps.img = allocimage(display, Rect(0, 0, 512, font->height), RGB24, 0, DBlack);
+ fps.fg = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, DYellow);
+ fps.r = fps.img->r;
+ fps.r.max.x = 0;
+
draw(screen, screen->r, display->black, nil, ZP);
flushimage(display, Refnone);
unlockdisplay(display);