@@ -44,8 +44,8 @@ def __init__(self, scene):
44
44
# self.watched_types_count = {}
45
45
# self.watched_names_count = {}
46
46
47
- self .touched_this_frame = set ()
48
- self .touched_last_frame = set ()
47
+ self .touching_this_frame = set ()
48
+ self .touching_last_frame = set ()
49
49
self .collision_pairs = {}
50
50
51
51
self .id_to_noderef = {}
@@ -162,8 +162,8 @@ def _run_callbacks(self, sig, a, b, dt):
162
162
163
163
if sigfunc (sig , a_id , b_id , a , b , dt ):
164
164
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
167
167
168
168
ta = type (a )
169
169
tb = type (b )
@@ -231,10 +231,10 @@ def collisions_update(self, dt):
231
231
232
232
# reset all pair touch states
233
233
# for pair in self.touching:
234
- # pair.touched = False
234
+ # pair.touching = False
235
235
# self.touching.clear()
236
236
237
- self .touched_this_frame = set ()
237
+ self .touching_this_frame = set ()
238
238
239
239
scene = self .scene
240
240
with scene :
@@ -257,21 +257,25 @@ def collisions_update(self, dt):
257
257
bn = a .name
258
258
259
259
# 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 )
263
263
pair = self .collision_pairs .get (abkey , None )
264
264
if not pair :
265
265
pair = self .collision_pairs [abkey ] = Partitioner .CollisionPair (a ,b ,False )
266
+ self .touching_this_frame .add (pair ) # reset touch state next frame
266
267
if not pair .touching :
267
268
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
+
271
272
self ._run_callbacks (self .overlap , a , b , dt )
272
273
274
+ # if self.collision_pairs:
275
+ # import pdb; pdb.set_trace()
276
+
273
277
# 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 )
275
279
276
280
for pair in stopped_touching :
277
281
a = pair .objs [0 ]
@@ -285,7 +289,7 @@ def collisions_update(self, dt):
285
289
286
290
del self .collision_pairs [pair .ids ]
287
291
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
291
295
0 commit comments