Skip to content

Commit b391bc7

Browse files
committed
fixed enter/leave collision
1 parent 3765ca8 commit b391bc7

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

qork/partitioner.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def __init__(self, scene):
4444
# self.watched_types_count = {}
4545
# self.watched_names_count = {}
4646

47-
self.touched_this_frame = set()
48-
self.touched_last_frame = set()
47+
self.touching_this_frame = set()
48+
self.touching_last_frame = set()
4949
self.collision_pairs = {}
5050

5151
self.id_to_noderef = {}
@@ -162,8 +162,8 @@ def _run_callbacks(self, sig, a, b, dt):
162162

163163
if sigfunc(sig, a_id, b_id, a, b, dt):
164164
return
165-
if sigfunc(sig, b_id, a_id, b, a, dt):
166-
return
165+
# if sigfunc(sig, b_id, a_id, b, a, dt):
166+
# return
167167

168168
ta = type(a)
169169
tb = type(b)
@@ -231,10 +231,10 @@ def collisions_update(self, dt):
231231

232232
# reset all pair touch states
233233
# for pair in self.touching:
234-
# pair.touched = False
234+
# pair.touching = False
235235
# self.touching.clear()
236236

237-
self.touched_this_frame = set()
237+
self.touching_this_frame = set()
238238

239239
scene = self.scene
240240
with scene:
@@ -257,21 +257,25 @@ def collisions_update(self, dt):
257257
bn = a.name
258258

259259
# collision pair enters a collision
260-
if id(a) < id(b):
261-
abkey = [a,b]
262-
abkey = tuple(map(lambda x: id(x), abkey))
260+
a_id, b_id = id(a), id(b)
261+
if a_id < b_id:
262+
abkey = (a_id, b_id)
263263
pair = self.collision_pairs.get(abkey, None)
264264
if not pair:
265265
pair = self.collision_pairs[abkey] = Partitioner.CollisionPair(a,b,False)
266+
self.touching_this_frame.add(pair) # reset touch state next frame
266267
if not pair.touching:
267268
pair.touching = True
268-
self.touched_this_frame.add(pair) # reset touch state next frame
269-
self._run_callbacks(self.enter, a, b, dt)
270-
269+
if not self._run_callbacks(self.enter, a, b, dt): # a b
270+
self._run_callbacks(self.enter, b, a, dt) # b a
271+
271272
self._run_callbacks(self.overlap, a, b, dt)
272273

274+
# if self.collision_pairs:
275+
# import pdb; pdb.set_trace()
276+
273277
# objects that just stopped touching
274-
stopped_touching = self.touched_last_frame.difference(self.touched_this_frame)
278+
stopped_touching = self.touching_last_frame.difference(self.touching_this_frame)
275279

276280
for pair in stopped_touching:
277281
a = pair.objs[0]
@@ -285,7 +289,7 @@ def collisions_update(self, dt):
285289

286290
del self.collision_pairs[pair.ids]
287291

288-
# cycle
289-
self.touched_last_frame = self.touched_this_frame.difference(stopped_touching)
290-
self.touched_this_frame = None
292+
# cycle this frame / last frame
293+
self.touching_last_frame = self.touching_this_frame
294+
self.touching_this_frame = None
291295

0 commit comments

Comments
 (0)