From 7a3f1b4247e95b7a90f8544bdb1b46e0d5fbba08 Mon Sep 17 00:00:00 2001 From: Josh Aune Date: Tue, 20 Oct 2015 12:51:40 -0600 Subject: [PATCH] movement.is_moving works, add event 'movement_follow_path_done' --- spockbot/plugins/helpers/movement.py | 11 ++++++++--- spockbot/plugins/helpers/pathfinding.py | 20 +++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/spockbot/plugins/helpers/movement.py b/spockbot/plugins/helpers/movement.py index 8551053..42c9da6 100644 --- a/spockbot/plugins/helpers/movement.py +++ b/spockbot/plugins/helpers/movement.py @@ -4,10 +4,14 @@ directions. """ +import logging + from spockbot.plugins.base import PluginBase, pl_announce from spockbot.plugins.tools.event import EVENT_UNREGISTER from spockbot.vector import Vector3 +logger = logging.getLogger('spockbot') + class MovementCore(object): def __init__(self, plug): @@ -19,7 +23,9 @@ def stop(self): @property def is_moving(self): - return self.__plug.path_nodes is not None + is_processing = self.__plug.pathfinding.is_processing + is_moving = self.__plug.path_nodes is not None + return (is_moving or is_processing) @property def current_path(self): @@ -83,6 +89,7 @@ def path_cb(self, result): def follow_path(self, _, __): if not self.path_nodes: self.movement.stop() + self.event.emit('movement_follow_path_done') return EVENT_UNREGISTER target = self.path_nodes[0] jumped = False @@ -91,5 +98,3 @@ def follow_path(self, _, __): jumped = True if self.physics.move_target(target) or jumped: self.path_nodes.popleft() - if not self.path_nodes: - self.movement.stop() diff --git a/spockbot/plugins/helpers/pathfinding.py b/spockbot/plugins/helpers/pathfinding.py index c7c930a..671d2f6 100644 --- a/spockbot/plugins/helpers/pathfinding.py +++ b/spockbot/plugins/helpers/pathfinding.py @@ -4,6 +4,7 @@ """ import collections +import logging from spockbot.mcdata import blocks, constants as const from spockbot.mcdata.utils import BoundingBox @@ -14,6 +15,7 @@ from spockbot.plugins.tools.event import EVENT_UNREGISTER from spockbot.vector import Vector3 +logger = logging.getLogger('spockbot') FOUND_VALID_PATH = 0x01 TIMEOUT_REACHED = 0x02 @@ -22,8 +24,13 @@ class PathfindingCore(object): - def __init__(self, start_path): - self.pathfind = start_path + def __init__(self, plug): + self.__plug = plug + self.pathfind = plug.start_path + + @property + def is_processing(self): + return self.__plug.path_job is not None class Path(object): @@ -68,7 +75,7 @@ def __init__(self, ploader, settings): self.col = MTVTest( self.world, BoundingBox(const.PLAYER_WIDTH, const.PLAYER_HEIGHT) ) - ploader.provides('Pathfinding', PathfindingCore(self.start_path)) + ploader.provides('Pathfinding', PathfindingCore(self)) def build_list_from_node(self, node): ret = collections.deque() @@ -92,12 +99,15 @@ def do_job(self, _=None, __=None): path, scb, fcb = self.path_job ret = self.pathfind(path) if ret == FOUND_VALID_PATH: - self.path_job = None scb(self.build_list_from_node(path.result)) + # Unset path_job after scb in order to plug race in + # movment.is_moving test + self.path_job = None return EVENT_UNREGISTER elif ret == NO_VALID_PATH and fcb: - self.path_job = None fcb(None) + self.path_job = None + return EVENT_UNREGISTER def pathfind(self, path): while path.open_list and self.timers.get_timeout():