minigame: fix ice game physics simulation & crashes

This commit is contained in:
John Cote 2020-01-07 20:15:13 -05:00
parent 2ace6ce632
commit 78dc55419a
3 changed files with 23 additions and 12 deletions

View file

@ -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:

View file

@ -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)):

View file

@ -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