Compare commits
9 Commits
Author | SHA1 | Date |
---|---|---|
|
11d493bb14 | 2 years ago |
|
76b489b424 | 2 years ago |
|
09c3956cb9 | 2 years ago |
|
88f50f8724 | 3 years ago |
|
e76f34e0fb | 3 years ago |
|
cbf2354d1e | 3 years ago |
|
ed33ca27c3 | 3 years ago |
|
f9eca425b6 | 3 years ago |
|
b91af019b4 | 3 years ago |
20 changed files with 98 additions and 103 deletions
@ -1,16 +0,0 @@ |
|||||||
package main |
|
||||||
|
|
||||||
import ( |
|
||||||
"flag" |
|
||||||
) |
|
||||||
|
|
||||||
var ( |
|
||||||
orderMessage string = "Order: Replace -> Retrieve -> Remove\n" |
|
||||||
) |
|
||||||
|
|
||||||
var ( |
|
||||||
cmdlnBeatmap = flag.String("beatmap", "", `Specifies a certain beatmap. |
|
||||||
If set to non "" - the program will search for given name and perform the magic |
|
||||||
provided in settings if successful`) |
|
||||||
showOrder = flag.Bool("showOrder", false, "Prints an order in which functions are performed on a beatmap") |
|
||||||
) |
|
@ -1,51 +0,0 @@ |
|||||||
package main |
|
||||||
|
|
||||||
import ( |
|
||||||
"sync" |
|
||||||
) |
|
||||||
|
|
||||||
// a basic implementation of a concurrent worker
|
|
||||||
func worker(jobs <-chan job, results chan result, WG *sync.WaitGroup) { |
|
||||||
defer WG.Done() |
|
||||||
for job := range jobs { |
|
||||||
var successful, failed uint = 0, 0 |
|
||||||
|
|
||||||
// the order is: Replace->Retrieve->Remove (if all 3 options are enabled)
|
|
||||||
if job.replacementImagePath != "" { |
|
||||||
s, f := job.beatmap.ReplaceBackgrounds(job.replacementImagePath) |
|
||||||
successful += s |
|
||||||
failed += f |
|
||||||
} |
|
||||||
if job.retrievementPath != "" { |
|
||||||
s, f := job.beatmap.RetrieveBackgrounds(job.retrievementPath) |
|
||||||
successful += s |
|
||||||
failed += f |
|
||||||
} |
|
||||||
if job.remove == true { |
|
||||||
s, f := job.beatmap.RemoveBackgrounds() |
|
||||||
successful += s |
|
||||||
failed += f |
|
||||||
} |
|
||||||
|
|
||||||
results <- result{ |
|
||||||
beatmapName: job.beatmap.Name, |
|
||||||
numberOfDiffs: uint(len(job.beatmap.Diffs)), |
|
||||||
successful: successful, |
|
||||||
failed: failed, |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
func workerPool(jobs chan job, results chan result, numOfWorkers int, WG *sync.WaitGroup) { |
|
||||||
// check if there are less jobs than workers
|
|
||||||
if numOfWorkers > len(jobs) { |
|
||||||
numOfWorkers = len(jobs) |
|
||||||
} |
|
||||||
|
|
||||||
// replacing backgrounds for each beatmap concurrently
|
|
||||||
for i := 0; i < numOfWorkers; i++ { |
|
||||||
WG.Add(1) |
|
||||||
go worker(jobs, results, WG) |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue