Skip to content

Commit 6c78819

Browse files
committed
Remove BrushCacheImpl::unique_id
1 parent fcae3fa commit 6c78819

2 files changed

Lines changed: 3 additions & 73 deletions

File tree

node-graph/nodes/brush/src/brush_cache.rs

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@ use core_types::table::TableRow;
66
use raster_types::CPU;
77
use raster_types::Raster;
88
use std::collections::HashMap;
9-
use std::hash::Hash;
10-
use std::hash::Hasher;
11-
use std::sync::atomic::{AtomicU64, Ordering};
129
use std::sync::{Arc, Mutex};
1310

14-
// TODO: This is a temporary hack, be sure to not reuse this when the brush system is replaced/rewritten.
15-
static NEXT_BRUSH_CACHE_IMPL_ID: AtomicU64 = AtomicU64::new(0);
16-
17-
#[derive(Clone, Debug)]
11+
#[derive(Clone, Debug, Default)]
1812
struct BrushCacheImpl {
19-
unique_id: u64,
2013
// The full previous input that was cached.
2114
prev_input: Vec<BrushStroke>,
2215

@@ -89,35 +82,6 @@ impl BrushCacheImpl {
8982
}
9083
}
9184

92-
impl Default for BrushCacheImpl {
93-
fn default() -> Self {
94-
Self {
95-
unique_id: new_unique_id(),
96-
prev_input: Vec::new(),
97-
background: Default::default(),
98-
blended_image: Default::default(),
99-
last_stroke_texture: Default::default(),
100-
brush_texture_cache: HashMap::new(),
101-
}
102-
}
103-
}
104-
105-
impl PartialEq for BrushCacheImpl {
106-
fn eq(&self, other: &Self) -> bool {
107-
self.unique_id == other.unique_id
108-
}
109-
}
110-
111-
impl Hash for BrushCacheImpl {
112-
fn hash<H: Hasher>(&self, state: &mut H) {
113-
self.unique_id.hash(state);
114-
}
115-
}
116-
117-
fn new_unique_id() -> u64 {
118-
NEXT_BRUSH_CACHE_IMPL_ID.fetch_add(1, Ordering::SeqCst)
119-
}
120-
12185
#[derive(Clone, Debug, Default)]
12286
pub struct BrushPlan {
12387
pub strokes: Vec<BrushStroke>,
@@ -126,43 +90,9 @@ pub struct BrushPlan {
12690
pub first_stroke_point_skip: usize,
12791
}
12892

129-
#[derive(Debug, Default)]
93+
#[derive(Debug, Default, Clone)]
13094
pub struct BrushCache(Arc<Mutex<BrushCacheImpl>>);
13195

132-
// A bit of a cursed implementation to work around the current node system.
133-
// The original object is a 'prototype' that when cloned gives you a independent
134-
// new object. Any further clones however are all the same underlying cache object.
135-
impl Clone for BrushCache {
136-
fn clone(&self) -> Self {
137-
Self(Arc::new(Mutex::new(self.0.lock().unwrap().clone())))
138-
}
139-
}
140-
141-
impl PartialEq for BrushCache {
142-
fn eq(&self, other: &Self) -> bool {
143-
if Arc::ptr_eq(&self.0, &other.0) {
144-
return true;
145-
}
146-
147-
let s = self.0.lock().unwrap();
148-
let o = other.0.lock().unwrap();
149-
150-
*s == *o
151-
}
152-
}
153-
154-
impl Hash for BrushCache {
155-
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
156-
self.0.lock().unwrap().hash(state);
157-
}
158-
}
159-
160-
impl graphene_hash::CacheHash for BrushCache {
161-
fn cache_hash<H: core::hash::Hasher>(&self, state: &mut H) {
162-
core::hash::Hash::hash(&self.0.lock().unwrap().unique_id, state);
163-
}
164-
}
165-
16696
impl BrushCache {
16797
pub fn compute_brush_plan(&self, background: TableRow<Raster<CPU>>, input: &[BrushStroke]) -> BrushPlan {
16898
let mut inner = self.0.lock().unwrap();

node-graph/nodes/brush/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub mod brush;
2-
pub mod brush_cache;
2+
mod brush_cache;
33
pub mod brush_stroke;
44

55
pub mod migrations {

0 commit comments

Comments
 (0)