Skip to content

Commit e2942c3

Browse files
committed
Feature/Parity: Kill patches on world resize
1 parent 3992933 commit e2942c3

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

engine/src/main/coffee/engine/core/patch.coffee

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,20 @@ module.exports =
8686

8787
# (() => Any) => Unit
8888
ask: (f) ->
89-
@world.selfManager.askAgent(f)(this)
90-
if @world.selfManager.self().isDead?()
91-
return DeathInterrupt
89+
if not @isDead()
90+
@world.selfManager.askAgent(f)(this)
91+
if @world.selfManager.self().isDead?()
92+
return DeathInterrupt
93+
else
94+
throw exceptions.runtime("That patch is dead.", "ask")
9295
return
9396

9497
# [Result] @ (() => Result) => Result
9598
projectionBy: (f) ->
96-
@world.selfManager.askAgent(f)(this)
99+
if not @isDead()
100+
@world.selfManager.askAgent(f)(this)
101+
else
102+
throw exceptions.runtime("That patch is dead.", "of")
97103

98104
# () => PatchSet
99105
getNeighbors: ->
@@ -156,13 +162,23 @@ module.exports =
156162
compare: (x) ->
157163
Comparator.numericCompare(@id, x.id)
158164

159-
# Unit -> Unit
165+
# () => Boolean
160166
isDead: ->
161-
false
167+
@id is -1
168+
169+
# A patch cannot really die, but on a world resize old patches can stick around in variables, so they need to have a
170+
# way to get gone. -Jeremy B November 2025
171+
# () => Unit
172+
_die: ->
173+
@id = -1
174+
return
162175

163176
# () => String
164177
toString: ->
165-
"(#{@getName()})"
178+
if not @isDead()
179+
"(#{@getName()})"
180+
else
181+
"nobody"
166182

167183
# () => Unit
168184
reset: ->

engine/src/main/coffee/engine/core/world.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ module.exports =
335335

336336
# () => Unit
337337
_createPatches: ->
338+
@_patches.forEach( (patch) ->
339+
patch._die()
340+
return
341+
)
342+
338343
nested =
339344
for y in [@topology.maxPycor..@topology.minPycor]
340345
for x in [@topology.minPxcor..@topology.maxPxcor]

0 commit comments

Comments
 (0)