From 0700f6c11bb057667b59fdb75df9f01cda71042f Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Sat, 2 Jan 2021 15:51:13 +0100 Subject: [PATCH] update some comments --- pixelflut/commands.go | 5 ++--- pixelflut/flut.go | 7 ++----- pixelflut/net.go | 6 ++++-- render/text.go | 2 -- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pixelflut/commands.go b/pixelflut/commands.go index ea86878..db0c388 100644 --- a/pixelflut/commands.go +++ b/pixelflut/commands.go @@ -3,7 +3,6 @@ package pixelflut import ( "fmt" "image" - "image/color" "math/rand" ) @@ -66,7 +65,7 @@ func commandsFromImage(img *image.NRGBA, order RenderOrder, offset image.Point) x, y = y, x } - c := img.At(x, y).(color.NRGBA) + c := img.NRGBAAt(x, y) if c.A == 0 { continue } @@ -79,7 +78,7 @@ func commandsFromImage(img *image.NRGBA, order RenderOrder, offset image.Point) cmd = fmt.Sprintf("PX %d %d %.2x%.2x%.2x\n", x+offset.X, y+offset.Y, c.R, c.G, c.B) } - cmds[numCmds] = []byte(cmd) + cmds[numCmds] = []byte(cmd) // @speed: conversion to []byte costs an extra allocation.. numCmds++ } } diff --git a/pixelflut/flut.go b/pixelflut/flut.go index 1d470b3..7cba65f 100644 --- a/pixelflut/flut.go +++ b/pixelflut/flut.go @@ -22,7 +22,7 @@ type FlutTaskOpts struct { MaxConns int Offset image.Point Paused bool - RGBSplit bool + RGBSplit bool // @cleanup: replace with `FX: []Effect` RandOffset bool RenderOrder RenderOrder } @@ -74,10 +74,7 @@ const ( Shuffle = 0b100 ) -// Flut asynchronously sends the given image to pixelflut server at `address` -// using `conns` connections. Pixels are sent column wise, unless `shuffle` -// is set. Stops when stop is closed. -// @cleanup: use FlutTask{} as arg +// Flut asynchronously executes the given FlutTask, until `stop` is closed. func Flut(t FlutTask, stop chan bool, wg *sync.WaitGroup) { if !t.IsFlutable() { return // @robustness: actually return an error here? diff --git a/pixelflut/net.go b/pixelflut/net.go index a9974d2..3d39690 100644 --- a/pixelflut/net.go +++ b/pixelflut/net.go @@ -92,8 +92,8 @@ func initPerfReporter() *Performance { return r } -// bombAddress writes the given message via plain TCP to the given address, -// as fast as possible, until stop is closed. retries with exponential backoff on network errors. +// bombAddress opens a TCP connection to `address`, and writes `message` repeatedly, until `stop` is closed. +// It retries with exponential backoff on network errors. func bombAddress(message []byte, address string, maxOffsetX, maxOffsetY int, stop chan bool, wg *sync.WaitGroup) { wg.Add(1) defer wg.Done() @@ -125,6 +125,8 @@ func bombAddress(message []byte, address string, maxOffsetX, maxOffsetY int, sto } } +// bombConn writes the given message to the given connection in a tight loop, until `stop` is closed. +// Does no transformation on the given message, so make sure packet splitting / nagle works. func bombConn(message []byte, maxOffsetX, maxOffsetY int, conn net.Conn, stop chan bool) error { PerformanceReporter.connsReporter <- 1 defer func() { PerformanceReporter.connsReporter <- -1 }() diff --git a/render/text.go b/render/text.go index f48e02a..84a7853 100644 --- a/render/text.go +++ b/render/text.go @@ -17,14 +17,12 @@ func pt(p fixed.Point26_6) image.Point { } func RenderText(text string, scale int, texture, bgTex image.Image) *image.NRGBA { - // @incomplete: draw with texture via Drawer.Src face := basicfont.Face7x13 stringBounds, _ := font.BoundString(face, text) b := image.Rectangle{pt(stringBounds.Min), pt(stringBounds.Max)} img := image.NewNRGBA(b) - // fill with black bg if bgTex != nil { draw.Draw(img, b, bgTex, image.Point{}, draw.Src) }