Created
July 3, 2017 23:48
-
-
Save hunterloftis/328f79c6c794d3352a248c37d2032b62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Start starts rendering based on CLI parameters | |
func (c Cli) Start() { | |
out := flag.String("out", "render.png", "Output png filename.") | |
concurrency := flag.Int("frames", runtime.NumCPU(), "Number of frames to combine.") | |
samples := flag.Float64("samples", math.Inf(1), "Average per pixel samples to take.") | |
heat := flag.String("heat", "", "Heatmap png filename.") | |
flag.Parse() | |
running := make(chan struct{}) | |
ch := make(chan os.Signal, 2) | |
signal.Notify(ch, os.Interrupt, syscall.SIGTERM) | |
go func() { <-ch; close(running) }() | |
fmt.Printf("Rendering (concurrency: %v, per pixel sample cutoff: %v)\n", *concurrency, *samples) | |
var results chan []float64 | |
for i := 0; i < *concurrency; i++ { | |
go c.sampler.Worker(i, running, results) // TODO: instantiate a worker ala https://play.golang.org/p/Sfx1JL_6K2 | |
} | |
for i := 0; i < *concurrency; i++ { | |
result := <-results | |
// TODO: add results to total | |
} | |
c.renderer.Write(c.sampler.Values(), *out) | |
if len(*heat) > 0 { | |
c.renderer.Write(c.sampler.Counts(), *heat) | |
} | |
fmt.Printf("\n -> %v\n", out) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment