refactor: clean up

This commit is contained in:
dscyrescotti
2024-05-11 10:41:59 +07:00
parent 9c1398ce5e
commit a903a5eed3
3 changed files with 8 additions and 5 deletions

View File

@@ -20,7 +20,7 @@ final class Canvas: NSManagedObject, Identifiable {
let gridContext = GridContext() let gridContext = GridContext()
let viewPortContext = ViewPortContext() let viewPortContext = ViewPortContext()
let maximumZoomScale: CGFloat = 25 let maximumZoomScale: CGFloat = 28
let minimumZoomScale: CGFloat = 3.1 let minimumZoomScale: CGFloat = 3.1
var transform: simd_float4x4 = .init() var transform: simd_float4x4 = .init()
@@ -42,11 +42,11 @@ final class Canvas: NSManagedObject, Identifiable {
// MARK: - Actions // MARK: - Actions
extension Canvas { extension Canvas {
func load() { func load() {
state = .loading
let start = Date().formatted(.dateTime.minute().second().secondFraction(.fractional(5))) let start = Date().formatted(.dateTime.minute().second().secondFraction(.fractional(5)))
for stroke in graphicContext.strokes { for stroke in graphicContext.strokes {
if let stroke = stroke as? Stroke { if let stroke = stroke as? Stroke {
stroke.loadVertices() stroke.loadVertices()
NSLog("[Memola] - \(stroke.quads.count) quads")
} }
} }
let end = Date().formatted(.dateTime.minute().second().secondFraction(.fractional(5))) let end = Date().formatted(.dateTime.minute().second().secondFraction(.fractional(5)))

View File

@@ -85,9 +85,6 @@ extension Stroke: Drawable {
} }
func draw(device: MTLDevice, renderEncoder: MTLRenderCommandEncoder) { func draw(device: MTLDevice, renderEncoder: MTLRenderCommandEncoder) {
if isEmpty {
loadVertices()
}
guard !isEmpty else { return } guard !isEmpty else { return }
prepare(device: device) prepare(device: device)
renderEncoder.setFragmentTexture(texture, index: 0) renderEncoder.setFragmentTexture(texture, index: 0)

View File

@@ -19,6 +19,12 @@ class Persistence {
shared.persistentContainer.viewContext shared.persistentContainer.viewContext
}() }()
static var backgroundContext: NSManagedObjectContext = {
let context = shared.persistentContainer.newBackgroundContext()
context.automaticallyMergesChangesFromParent = true
return context
}()
private lazy var viewContext: NSManagedObjectContext = { private lazy var viewContext: NSManagedObjectContext = {
persistentContainer.viewContext persistentContainer.viewContext
}() }()