|
8 | 8 |
|
9 | 9 | import Foundation |
10 | 10 |
|
| 11 | +@globalActor |
11 | 12 | public actor RenderBlackboard { |
12 | | - static let blackboard = RenderBlackboard() |
13 | | - private var mappings = [ObjectIdentifier : any Sendable]() |
| 13 | + public static let shared = RenderBlackboard() |
| 14 | + |
| 15 | + @RenderBlackboard static var mappings = [ObjectIdentifier : any Sendable]() |
14 | 16 |
|
15 | 17 | public init() { |
16 | 18 |
|
17 | 19 | } |
18 | 20 |
|
19 | | - public func add<T: Sendable>(_ obj: T) { |
| 21 | + @RenderBlackboard |
| 22 | + public static func add<T: Sendable>(_ obj: T) { |
20 | 23 | self.mappings[ObjectIdentifier(T.self)] = obj |
21 | 24 | } |
22 | 25 |
|
23 | | - public func remove<T: Sendable>(_ obj: T) { |
| 26 | + @RenderBlackboard |
| 27 | + public static func remove<T: Sendable>(_ obj: T) { |
24 | 28 | self.mappings[ObjectIdentifier(T.self)] = nil |
25 | 29 | } |
26 | 30 |
|
27 | | - public func remove<T: Sendable>(type: T.Type) { |
| 31 | + @RenderBlackboard |
| 32 | + public static func remove<T: Sendable>(type: T.Type) { |
28 | 33 | self.mappings[ObjectIdentifier(type)] = nil |
29 | 34 | } |
30 | 35 |
|
31 | | - public func get<T: Sendable>(_ type: T.Type) -> T { |
| 36 | + @RenderBlackboard |
| 37 | + public static func get<T: Sendable>(_ type: T.Type) -> T { |
32 | 38 | guard let item = self.mappings[ObjectIdentifier(type)] else { |
33 | 39 | fatalError("No item in blackboard of type \(type).") |
34 | 40 | } |
35 | 41 | return item as! T |
36 | 42 | } |
37 | 43 |
|
38 | | - public func tryGet<T: Sendable>(_ type: T.Type) -> T? { |
| 44 | + @RenderBlackboard |
| 45 | + public static func tryGet<T: Sendable>(_ type: T.Type) -> T? { |
39 | 46 | return self.mappings[ObjectIdentifier(type)] as! T? |
40 | 47 | } |
41 | 48 |
|
42 | | - public func has<T: Sendable>(_ type: T.Type) -> Bool { |
| 49 | + @RenderBlackboard |
| 50 | + public static func has<T: Sendable>(_ type: T.Type) -> Bool { |
43 | 51 | return self.mappings[ObjectIdentifier(type)] != nil |
44 | 52 | } |
45 | 53 |
|
46 | | - public func clear() { |
| 54 | + @RenderBlackboard |
| 55 | + public static func clear() { |
47 | 56 | self.mappings.removeAll(keepingCapacity: true) |
48 | 57 | } |
49 | 58 | } |
|
0 commit comments