From 02afe58867f4bc37ad6bb467f161d7416a39bcbe Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Fri, 27 Jul 2007 10:35:48 +0200 Subject: [PATCH] Added logic in EngineEntity to ignore redundant notifications. --- src/entities/engineentity.cpp | 13 ++++++++++++- src/entities/engineentity.h | 6 ++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/entities/engineentity.cpp b/src/entities/engineentity.cpp index d2d6e9d..8a05cd5 100644 --- a/src/entities/engineentity.cpp +++ b/src/entities/engineentity.cpp @@ -21,6 +21,7 @@ EngineEntity::EngineEntity(VariantInfo* variant, const shared_ptr& game, i : Entity(game) , m_variant(variant) , m_side(side) +, m_last_index(0) , m_engine(engine) , m_dispatcher(group, this) { } @@ -30,6 +31,7 @@ void EngineEntity::executeMove(AbstractMove::Ptr move) { AbstractPosition::Ptr pos = ref->clone(); pos->move(move); m_game->add(move, pos); + m_last_index = m_game->index(); m_dispatcher.move(m_game->index()); } @@ -42,8 +44,17 @@ void EngineEntity::notifyEngineMove(const QString& move_str) { } void EngineEntity::notifyMove(const Index& index) { - if (m_side == -1 || m_game->position(index)->turn() == m_side) + if (index == m_last_index) { + // TODO: check for consistency and update if necessary + } + else if (index.prev() == m_last_index) { m_engine->sendMove(m_game->move(index), m_game->position(index.prev())); + m_last_index = index; + } + else { + // TODO: handle move notification in arbitrary indexes + WARNING("engine entity can't handle index " << index << " (m_last_index = " << m_last_index << ")"); + } } diff --git a/src/entities/engineentity.h b/src/entities/engineentity.h index c85f190..89cf745 100644 --- a/src/entities/engineentity.h +++ b/src/entities/engineentity.h @@ -11,11 +11,12 @@ #ifndef ENGINEENTITY_H #define ENGINEENTITY_H -#include "entity.h" #include "agent.h" +#include "agentgroup.h" #include "enginenotifier.h" +#include "entity.h" +#include "index.h" #include "tagua.h" -#include "agentgroup.h" class Engine; @@ -24,6 +25,7 @@ class EngineEntity : public Entity , public EngineNotifier { VariantInfo* m_variant; int m_side; + Index m_last_index; boost::shared_ptr m_engine; AgentGroupDispatcher m_dispatcher; -- 2.11.4.GIT