commit
a6d04d4c51
6
main.go
6
main.go
|
@ -20,13 +20,14 @@ import (
|
||||||
var (
|
var (
|
||||||
imgPath = flag.String("image", "", "Filepath of an image to flut")
|
imgPath = flag.String("image", "", "Filepath of an image to flut")
|
||||||
ránAddr = flag.String("rán", "", "Start RPC server to distribute jobs, listening on the given address/port")
|
ránAddr = flag.String("rán", "", "Start RPC server to distribute jobs, listening on the given address/port")
|
||||||
hevringAddr = flag.String("hevring", "", "Connect to PRC server at given address/port")
|
hevringAddr = flag.String("hevring", "", "Connect to RPC server at given address/port")
|
||||||
address = flag.String("host", ":1234", "Target server address")
|
address = flag.String("host", ":1234", "Target server address")
|
||||||
connections = flag.Int("connections", 4, "Number of simultaneous connections. Each connection posts a subimage")
|
connections = flag.Int("connections", 4, "Number of simultaneous connections. Each connection posts a subimage")
|
||||||
x = flag.Int("x", 0, "Offset of posted image from left border")
|
x = flag.Int("x", 0, "Offset of posted image from left border")
|
||||||
y = flag.Int("y", 0, "Offset of posted image from top border")
|
y = flag.Int("y", 0, "Offset of posted image from top border")
|
||||||
order = flag.String("order", "rtl", "Draw order (shuffle, ltr, rtl, ttb, btt)")
|
order = flag.String("order", "rtl", "Draw order (shuffle, ltr, rtl, ttb, btt)")
|
||||||
fetchImgPath = flag.String("fetch", "", "Enable fetching the screen area to the given local file, updating it each second")
|
fetchImgPath = flag.String("fetch", "", "Enable fetching the screen area to the given local file, updating it each second")
|
||||||
|
hevringImgPath = flag.String("hevring-preview", "", "Write the current task image to the given PNG file")
|
||||||
cpuprofile = flag.String("cpuprofile", "", "Destination file for CPU Profile")
|
cpuprofile = flag.String("cpuprofile", "", "Destination file for CPU Profile")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -83,7 +84,8 @@ func taskFromFlags(stop chan bool, wg *sync.WaitGroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if startClient {
|
if startClient {
|
||||||
rpc.ConnectHevring(hev, stop, wg)
|
hevring := rpc.ConnectHevring(hev, stop, wg)
|
||||||
|
hevring.PreviewPath = *hevringImgPath
|
||||||
}
|
}
|
||||||
|
|
||||||
if fetchImg {
|
if fetchImg {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
|
@ -9,9 +10,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/SpeckiJ/Hochwasser/pixelflut"
|
"github.com/SpeckiJ/Hochwasser/pixelflut"
|
||||||
|
"github.com/SpeckiJ/Hochwasser/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConnectHevring(ránAddress string, stop chan bool, wg *sync.WaitGroup) {
|
func ConnectHevring(ránAddress string, stop chan bool, wg *sync.WaitGroup) *Hevring {
|
||||||
h := new(Hevring)
|
h := new(Hevring)
|
||||||
rpc.Register(h)
|
rpc.Register(h)
|
||||||
|
|
||||||
|
@ -23,6 +25,18 @@ func ConnectHevring(ránAddress string, stop chan bool, wg *sync.WaitGroup) {
|
||||||
go rpc.ServeConn(conn)
|
go rpc.ServeConn(conn)
|
||||||
fmt.Printf("[hevring] awaiting task from Rán\n")
|
fmt.Printf("[hevring] awaiting task from Rán\n")
|
||||||
|
|
||||||
|
// print performance
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
if pixelflut.PerformanceReporter.Enabled {
|
||||||
|
fmt.Println(pixelflut.PerformanceReporter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// add listener to stop the task, if this hevring should stop
|
||||||
|
// (either because Rán told us so, or we received an interrupt)
|
||||||
h.quit = stop
|
h.quit = stop
|
||||||
h.wg = wg
|
h.wg = wg
|
||||||
h.wg.Add(1)
|
h.wg.Add(1)
|
||||||
|
@ -35,12 +49,15 @@ func ConnectHevring(ránAddress string, stop chan bool, wg *sync.WaitGroup) {
|
||||||
}
|
}
|
||||||
h.wg.Done()
|
h.wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
type Hevring struct {
|
type Hevring struct {
|
||||||
|
PreviewPath string
|
||||||
task pixelflut.FlutTask
|
task pixelflut.FlutTask
|
||||||
taskQuit chan bool
|
taskQuit chan bool // if closed, task is stopped.
|
||||||
quit chan bool
|
quit chan bool // if closed, kills this hevring
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +80,8 @@ func (h *Hevring) Flut(task pixelflut.FlutTask, reply *FlutAck) error {
|
||||||
h.taskQuit = make(chan bool)
|
h.taskQuit = make(chan bool)
|
||||||
|
|
||||||
go pixelflut.Flut(task, h.taskQuit, nil)
|
go pixelflut.Flut(task, h.taskQuit, nil)
|
||||||
|
go h.savePreview(task.Img)
|
||||||
|
|
||||||
reply.Ok = true
|
reply.Ok = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -99,3 +118,13 @@ func (h *Hevring) Die(x int, reply *FlutAck) error {
|
||||||
reply.Ok = true
|
reply.Ok = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h Hevring) savePreview(img image.Image) {
|
||||||
|
if h.PreviewPath != "" && img != nil {
|
||||||
|
err := render.WriteImage(h.PreviewPath, img)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("[hevring] unable to write preview: %s\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue