From 9a374711fd0a749dcf847965652d38afae40da86 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 24 Dec 2020 01:48:04 -0800 Subject: [PATCH] Don't access point coordinates when hashing. For some reason this is crazy expensive. Turn time goes from 1.7 seconds to 1 second with this change. --- game/navmesh.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/game/navmesh.py b/game/navmesh.py index 2a2ca6b4..2b0fdd81 100644 --- a/game/navmesh.py +++ b/game/navmesh.py @@ -47,21 +47,15 @@ class NavPoint: return Point(self.point.x, self.point.y) def __hash__(self) -> int: - return hash((self.poly.ident, int(self.point.x), int(self.point.y))) + return hash(self.poly.ident) def __eq__(self, other: object) -> bool: if not isinstance(other, NavPoint): return False - # The int comparisons here aren't really correct, but the units here are - # meters and even approximate floating point comparisons can cause - # issues when these are used in sets or maps. For our purposes, two - # waypoints within a meter of each other might as well be identical for - # the purposes of path finding, so not an issue. - if int(self.point.x) != int(other.point.x): - return False - if int(self.point.y) != int(other.point.y): + if not self.point.almost_equals(other.point): return False + return self.poly == other.poly def __str__(self) -> str: