Branchwell

PulseCanvas / app · pulsecanvas.ai / scripts / ProjectMPackSmoke.swift

Raw 2.0 KB on 0e4fe45e403a1b6b5a57aa68addd681995d37722
1import Foundation
2import Metal
3struct PackPreset: Codable { let path: String; let title: String }
4@main struct PackSmoke {
5 static func main() throws {
6 guard let device = MTLCreateSystemDefaultDevice() else {fatalError("Metal unavailable")}
7 let root = URL(fileURLWithPath:"Sources/PulseCanvas/Resources/ProjectM")
8 let presets = try JSONDecoder().decode([PackPreset].self, from: Data(contentsOf:root.appendingPathComponent("catalog.json")))
9 let report = try JSONSerialization.jsonObject(with:Data(contentsOf:root.appendingPathComponent("compatibility-report.json"))) as! [String:Any]
10 precondition(presets.count == report["retained"] as! Int)
11 let engine = try ProjectMEngine()
12 var failures: [String] = [], clock: Double = 0
13 let pcm = (0..<2048).map {Float(sin(Double($0 / 2) * 0.13) * 0.8)}
14 let started = Date()
15 for (index, preset) in presets.enumerated() {
16 do {
17 _ = try engine.frame(preset: root.appendingPathComponent("Presets/"+preset.path), texturePaths:[root.appendingPathComponent("Presets/"+preset.path).deletingLastPathComponent(),root.appendingPathComponent("Textures")],device:device,width:128,height:72,time:clock,sourceTime:clock,pcm:pcm,chaos:1)
18 } catch {failures.append(preset.path+": "+error.localizedDescription)}
19 clock += 1.0 / 60
20 if index % 100 == 0 {print("Checked \(index+1)/\(presets.count), failures \(failures.count), elapsed \(Int(Date().timeIntervalSince(started)))s"); fflush(stdout)}
21 }
22 let receipt: [String:Any] = ["presets":presets.count,"loadedAndRendered":presets.count-failures.count,"failures":failures,"elapsedSeconds":Date().timeIntervalSince(started)]
23 try JSONSerialization.data(withJSONObject:receipt,options:[.prettyPrinted,.sortedKeys]).write(to: URL(fileURLWithPath:".build/validation/projectm-pack-receipt.json"))
24 print("Finished",presets.count,"effects; load failures",failures.count)
25 }
26}