Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix infinite loop and rare crash
  • Loading branch information
cswinter committed Mar 17, 2019
1 parent b3a82da commit 7f9abcd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Expand Up @@ -216,8 +216,10 @@ class MultiplayerServer(
context.system.scheduler.scheduleOnce(10 minutes, new Runnable {
override def run(): Unit = {
if (!hasStartedMatchmaking(rawConnection)) {
context.stop(rawConnection)
context.stop(websocketActor)
if (context != null) {
context.stop(rawConnection)
context.stop(websocketActor)
}
connectionInfo -= connection.websocketActor
}
}
Expand Down
Expand Up @@ -33,7 +33,7 @@ class TightCollisionTest extends FlatSpec with Matchers {
val runFor10Steps = Future {
simulator.run(10)
}
Await.result(runFor10Steps, 1.seconds)
Await.result(runFor10Steps, 5.seconds)
}

// TODO: fix this bug and enable test
Expand Down
Expand Up @@ -25,6 +25,7 @@ private[core] class ComputedDroneDynamics(
private[drone] var isStunned: Boolean = false
private var oldPos = pos
private var oldOrientation = orientation
private var collisionCount = 0;


def setPosition(value: Vector2): Unit = pos = value
Expand Down Expand Up @@ -93,6 +94,7 @@ private[core] class ComputedDroneDynamics(
}

def recomputeVelocity(): Unit = {
collisionCount = 0
velocity =
if (isStunned) {
if (velocity.length <= maxSpeed * 0.10f) {
Expand Down Expand Up @@ -138,6 +140,8 @@ private[core] class ComputedDroneDynamics(
if (dx <= dy && xCollisionPossible) velocity = velocity.copy(_x = -velocity.x)
else velocity = velocity.copy(_y = -velocity.y)
isStunned = true
collisionCount += 1
if (collisionCount > 20) velocity = Vector2.Null
}

override def handleObjectCollision(other: ConstantVelocityDynamics): Unit = {
Expand All @@ -155,6 +159,9 @@ private[core] class ComputedDroneDynamics(
isStunned = true
other.isStunned = true

collisionCount += 1
if (collisionCount > 20) velocity = Vector2.Null

drone.collidedWith(other.drone)
other.drone.collidedWith(drone)
case missile: MissileDynamics =>
Expand Down

0 comments on commit 7f9abcd

Please sign in to comment.