Skip to content

Commit f30eb88

Browse files
committed
Fix cached geometry ambiguity
1 parent 08e5595 commit f30eb88

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

Sources/GateEngine/Resources/Geometry/Geometry.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ public extension Geometry {
9292

9393
public init(path: String, options: GeometryImporterOptions = .none) {
9494
let resourceManager = Game.unsafeShared.resourceManager
95-
self.cacheKey = resourceManager.geometryCacheKey(path: path, options: options)
95+
self.cacheKey = resourceManager.geometryCacheKey(path: path, kind: .geometry, options: options)
9696
self.defaultCacheHint = .until(minutes: 5)
9797
resourceManager.incrementReference(self.cacheKey)
9898
}
9999

100100
internal init(optionalRawGeometry rawGeometry: RawGeometry?, immediate: Bool = false) {
101101
let resourceManager = Game.unsafeShared.resourceManager
102-
self.cacheKey = resourceManager.geometryCacheKey(rawGeometry: rawGeometry, immediate: immediate)
102+
self.cacheKey = resourceManager.geometryCacheKey(rawGeometry: rawGeometry, kind: .geometry, immediate: immediate)
103103
self.defaultCacheHint = .whileReferenced
104104
resourceManager.incrementReference(self.cacheKey)
105105
}
@@ -206,7 +206,13 @@ extension RawGeometry {
206206
extension ResourceManager.Cache {
207207
@usableFromInline
208208
struct GeometryKey: Hashable, Sendable, CustomStringConvertible {
209+
enum Kind: Hashable {
210+
case geometry
211+
case lines
212+
case points
213+
}
209214
let requestedPath: String
215+
let kind: Kind
210216
let geometryOptions: GeometryImporterOptions
211217

212218
@usableFromInline
@@ -248,8 +254,8 @@ extension ResourceManager {
248254
}
249255
}
250256

251-
@MainActor func geometryCacheKey(path: String, options: GeometryImporterOptions) -> Cache.GeometryKey {
252-
let key = Cache.GeometryKey(requestedPath: path, geometryOptions: options)
257+
@MainActor func geometryCacheKey(path: String, kind: Cache.GeometryKey.Kind, options: GeometryImporterOptions) -> Cache.GeometryKey {
258+
let key = Cache.GeometryKey(requestedPath: path, kind: kind, geometryOptions: options)
253259
if cache.geometries[key] == nil {
254260
cache.geometries[key] = Cache.GeometryCache()
255261
Game.unsafeShared.resourceManager.incrementLoading(path: key.requestedPath)
@@ -282,9 +288,9 @@ extension ResourceManager {
282288
return key
283289
}
284290

285-
@MainActor func geometryCacheKey(rawGeometry geometry: RawGeometry?, immediate: Bool) -> Cache.GeometryKey {
291+
@MainActor func geometryCacheKey(rawGeometry geometry: RawGeometry?, kind: Cache.GeometryKey.Kind, immediate: Bool) -> Cache.GeometryKey {
286292
let path = "$\(rawCacheIDGenerator.generateID())"
287-
let key = Cache.GeometryKey(requestedPath: path, geometryOptions: .none)
293+
let key = Cache.GeometryKey(requestedPath: path, kind: kind, geometryOptions: .none)
288294
if cache.geometries[key] == nil {
289295
cache.geometries[key] = Cache.GeometryCache()
290296
if let geometry = geometry {

Sources/GateEngine/Resources/Geometry/Lines.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extension RawLines {
8787

8888
extension ResourceManager {
8989
@MainActor func linesCacheKey(path: String, options: GeometryImporterOptions) -> Cache.GeometryKey {
90-
let key = Cache.GeometryKey(requestedPath: path, geometryOptions: options)
90+
let key = Cache.GeometryKey(requestedPath: path, kind: .lines, geometryOptions: options)
9191
if cache.geometries[key] == nil {
9292
cache.geometries[key] = Cache.GeometryCache()
9393
Game.shared.resourceManager.incrementLoading(path: key.requestedPath)
@@ -123,7 +123,7 @@ extension ResourceManager {
123123

124124
@MainActor func linesCacheKey(rawLines lines: RawLines?) -> Cache.GeometryKey {
125125
let path = "$\(rawCacheIDGenerator.generateID())"
126-
let key = Cache.GeometryKey(requestedPath: path, geometryOptions: .none)
126+
let key = Cache.GeometryKey(requestedPath: path, kind: .lines, geometryOptions: .none)
127127
if cache.geometries[key] == nil {
128128
cache.geometries[key] = Cache.GeometryCache()
129129
if let lines = lines {

Sources/GateEngine/Resources/Geometry/Points.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extension RawPoints {
8686

8787
extension ResourceManager {
8888
@MainActor func pointsCacheKey(path: String, options: GeometryImporterOptions) -> Cache.GeometryKey {
89-
let key = Cache.GeometryKey(requestedPath: path, geometryOptions: options)
89+
let key = Cache.GeometryKey(requestedPath: path, kind: .points, geometryOptions: options)
9090
if cache.geometries[key] == nil {
9191
cache.geometries[key] = Cache.GeometryCache()
9292
Game.shared.resourceManager.incrementLoading(path: key.requestedPath)
@@ -122,7 +122,7 @@ extension ResourceManager {
122122

123123
@MainActor func pointsCacheKey(rawPoints points: RawPoints?) -> Cache.GeometryKey {
124124
let path = "$\(rawCacheIDGenerator.generateID())"
125-
let key = Cache.GeometryKey(requestedPath: path, geometryOptions: .none)
125+
let key = Cache.GeometryKey(requestedPath: path, kind: .points, geometryOptions: .none)
126126
if cache.geometries[key] == nil {
127127
cache.geometries[key] = Cache.GeometryCache()
128128
if let points {

0 commit comments

Comments
 (0)