From 78dc55419a2752f57864274f7353cdef0e2864d0 Mon Sep 17 00:00:00 2001 From: John Cote Date: Tue, 7 Jan 2020 20:15:13 -0500 Subject: [PATCH] minigame: fix ice game physics simulation & crashes --- toontown/minigame/DistributedIceGame.py | 7 +++--- toontown/minigame/DistributedIceGameAI.py | 3 ++- toontown/minigame/MinigamePhysicsWorldBase.py | 25 +++++++++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/toontown/minigame/DistributedIceGame.py b/toontown/minigame/DistributedIceGame.py index 1c2e81f..c3f336d 100644 --- a/toontown/minigame/DistributedIceGame.py +++ b/toontown/minigame/DistributedIceGame.py @@ -11,6 +11,7 @@ from toontown.minigame import DistributedIceWorld from toontown.minigame import IceGameGlobals from toontown.minigame import MinigameAvatarScorePanel from toontown.minigame import IceTreasure +import functools class DistributedIceGame(DistributedMinigame.DistributedMinigame, DistributedIceWorld.DistributedIceWorld): notify = directNotify.newCategory('DistributedIceGame') @@ -428,7 +429,7 @@ class DistributedIceGame(DistributedMinigame.DistributedMinigame, DistributedIce else: return 0 - sortedByDistance.sort(cmp=compareDistance) + sortedByDistance.sort(key=functools.cmp_to_key(compareDistance)) self.scoreMovie = Sequence() curScale = 0.01 curTime = 0 @@ -1033,8 +1034,8 @@ class DistributedIceGame(DistributedMinigame.DistributedMinigame, DistributedIce def postStep(self): DistributedIceWorld.DistributedIceWorld.postStep(self) - for count in range(self.colCount): - c0, c1 = self.getOrderedContacts(count) + for entry in self.colEntries: + c0, c1 = self.getOrderedContacts(entry) if c1 in self.tireCollideIds: tireIndex = self.tireCollideIds.index(c1) if c0 in self.tireCollideIds: diff --git a/toontown/minigame/DistributedIceGameAI.py b/toontown/minigame/DistributedIceGameAI.py index 1d6e61a..609943a 100644 --- a/toontown/minigame/DistributedIceGameAI.py +++ b/toontown/minigame/DistributedIceGameAI.py @@ -6,6 +6,7 @@ from toontown.minigame import DistributedMinigameAI from toontown.minigame import MinigameGlobals from toontown.minigame import IceGameGlobals from toontown.ai.ToonBarrier import ToonBarrier +import functools class DistributedIceGameAI(DistributedMinigameAI.DistributedMinigameAI): notify = directNotify.newCategory('DistributedIceGameAI') @@ -174,7 +175,7 @@ class DistributedIceGameAI(DistributedMinigameAI.DistributedMinigameAI): else: return 0 - sortedByDistance.sort(cmp=compareDistance) + sortedByDistance.sort(key=functools.cmp_to_key(compareDistance)) self.scoresAsList = [] totalPointsAdded = 0 for index in range(len(self.avIdList)): diff --git a/toontown/minigame/MinigamePhysicsWorldBase.py b/toontown/minigame/MinigamePhysicsWorldBase.py index 863c6e6..4051515 100644 --- a/toontown/minigame/MinigamePhysicsWorldBase.py +++ b/toontown/minigame/MinigamePhysicsWorldBase.py @@ -41,6 +41,9 @@ class MinigamePhysicsWorldBase: self.useQuickStep = False self.deterministic = True self.numStepsInSimulateTask = 0 + self.collisionEventName = 'ode-collision-%s' % id(self) + self.space.setCollisionEvent(self.collisionEventName) + self.accept(self.collisionEventName, self.__handleCollision) def delete(self): self.notify.debug('Max Collision Count was %s' % self.maxColCount) @@ -85,6 +88,7 @@ class MinigamePhysicsWorldBase: self.space.destroy() self.world = None self.space = None + self.ignore(self.collisionEventName) return def setupSimulation(self): @@ -133,8 +137,14 @@ class MinigamePhysicsWorldBase: else: pandaNodePathGeom.setPos(0.0, 0.0, -100.0) + def __handleCollision(self, entry): + self.colEntries.append(entry) + def simulate(self): - self.colCount = self.space.autoCollide() + self.colEntries = [] + self.space.autoCollide() + eventMgr.doEvents() + self.colCount = len(self.colEntries) if self.maxColCount < self.colCount: self.maxColCount = self.colCount self.notify.debug('New Max Collision Count %s' % self.maxColCount) @@ -156,11 +166,10 @@ class MinigamePhysicsWorldBase: pandaNodePathGeom.setPos(odeBody.getPosition()) pandaNodePathGeom.setQuat(Quat(odeBody.getQuaternion()[0], odeBody.getQuaternion()[1], odeBody.getQuaternion()[2], odeBody.getQuaternion()[3])) - def getOrderedContacts(self, count): - c0 = self.space.getContactId(count, 0) - c1 = self.space.getContactId(count, 1) + def getOrderedContacts(self, entry): + c0 = self.space.getCollideId(entry.getGeom1()) + c1 = self.space.getCollideId(entry.getGeom2()) if c0 > c1: - chold = c1 - c1 = c0 - c0 = chold - return (c0, c1) + return c1, c0 + else: + return c0, c1