mail[Wesnoth-commits] r43217 - in /trunk/src: ./ whiteboard/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by gabrielmorin on June 07, 2010 - 02:25:
Author: gabba
Date: Mon Jun  7 02:25:22 2010
New Revision: 43217

URL: http://svn.gna.org/viewcvs/wesnoth?rev=43217&view=rev
Log:
Moved actions collection from manager to new class side_actions.
This will allow manager to hold one side_actions object per side.

Added:
    trunk/src/whiteboard/side_actions.cpp
      - copied, changed from r43216, trunk/src/whiteboard/manager.cpp
    trunk/src/whiteboard/side_actions.hpp
      - copied, changed from r43216, trunk/src/whiteboard/manager.hpp
Modified:
    trunk/src/CMakeLists.txt
    trunk/src/Makefile.am
    trunk/src/SConscript
    trunk/src/whiteboard/find_visitor.cpp
    trunk/src/whiteboard/find_visitor.hpp
    trunk/src/whiteboard/manager.cpp
    trunk/src/whiteboard/manager.hpp

Modified: trunk/src/CMakeLists.txt
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/CMakeLists.txt?rev=43217&r1=43216&r2=43217&view=diff
==============================================================================
--- trunk/src/CMakeLists.txt (original)
+++ trunk/src/CMakeLists.txt Mon Jun  7 02:25:22 2010
@@ -446,6 +446,7 @@
     whiteboard/move.cpp
     whiteboard/find_visitor.cpp
     whiteboard/mapbuilder_visitor.cpp
+    whiteboard/side_actions.cpp
     whiteboard/validate_visitor.cpp
     whiteboard/visitor.cpp
     widgets/combo.cpp

Modified: trunk/src/Makefile.am
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/Makefile.am?rev=43217&r1=43216&r2=43217&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Mon Jun  7 02:25:22 2010
@@ -275,6 +275,7 @@
        whiteboard/manager.cpp \
        whiteboard/find_visitor.cpp \
        whiteboard/mapbuilder_visitor.cpp \
+       whiteboard/side_actions.cpp \
        whiteboard/validate_visitor.cpp \
        whiteboard/visitor.cpp \
        widgets/combo.cpp \

Modified: trunk/src/SConscript
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/SConscript?rev=43217&r1=43216&r2=43217&view=diff
==============================================================================
--- trunk/src/SConscript (original)
+++ trunk/src/SConscript Mon Jun  7 02:25:22 2010
@@ -260,6 +260,7 @@
     whiteboard/move.cpp
     whiteboard/find_visitor.cpp
     whiteboard/mapbuilder_visitor.cpp
+    whiteboard/side_actions.cpp
     whiteboard/validate_visitor.cpp
     whiteboard/visitor.cpp
     widgets/combo.cpp

Modified: trunk/src/whiteboard/find_visitor.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/find_visitor.cpp?rev=43217&r1=43216&r2=43217&view=diff
==============================================================================
--- trunk/src/whiteboard/find_visitor.cpp (original)
+++ trunk/src/whiteboard/find_visitor.cpp Mon Jun  7 02:25:22 2010
@@ -17,6 +17,7 @@
  */
 
 #include "find_visitor.hpp"
+#include "manager.hpp"
 #include "move.hpp"
 
 #include "foreach.hpp"
@@ -42,12 +43,11 @@
        }
 }
 
-action_set find_visitor::find_actions_of(const unit& unit)
+action_set find_visitor::find_actions_of(const unit& unit, action_set 
actions)
 {
        search_target_ = &unit;
        found_ = false;
        search_result_.clear();
-       action_set actions = manager::instance().get_actions();
        foreach (action_ptr a, actions)
        {
                a->accept(*this);
@@ -55,12 +55,11 @@
        return search_result_;
 }
 
-action_ptr find_visitor::find_first_action_of(const unit& unit)
+action_ptr find_visitor::find_first_action_of(const unit& unit, action_set 
actions)
 {
        search_target_ = &unit;
        found_ = false;
        search_result_.clear();
-       action_set actions = manager::instance().get_actions();
        foreach (action_ptr a, actions)
        {
                a->accept(*this);

Modified: trunk/src/whiteboard/find_visitor.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/find_visitor.hpp?rev=43217&r1=43216&r2=43217&view=diff
==============================================================================
--- trunk/src/whiteboard/find_visitor.hpp (original)
+++ trunk/src/whiteboard/find_visitor.hpp Mon Jun  7 02:25:22 2010
@@ -20,7 +20,7 @@
 #define WB_FIND_VISITOR_HPP_
 
 #include "visitor.hpp"
-#include "manager.hpp"
+#include "side_actions.hpp"
 
 class unit;
 
@@ -38,8 +38,8 @@
 
        virtual void visit_move(move& move);
 
-       virtual action_set find_actions_of(const unit& unit);
-       virtual action_ptr find_first_action_of(const unit& unit);
+       virtual action_set find_actions_of(const unit& unit, action_set 
actions);
+       virtual action_ptr find_first_action_of(const unit& unit, action_set 
actions);
 
 private:
        bool found_;

Modified: trunk/src/whiteboard/manager.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.cpp?rev=43217&r1=43216&r2=43217&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.cpp (original)
+++ trunk/src/whiteboard/manager.cpp Mon Jun  7 02:25:22 2010
@@ -17,14 +17,12 @@
  */
 
 #include "manager.hpp"
-#include "action.hpp"
-#include "move.hpp"
 
 namespace wb {
 
 manager* manager::instance_ = NULL;
 
-manager::manager(): planning_mode_(false)
+manager::manager(): active_(false)
 {
 
 }
@@ -43,80 +41,4 @@
        return *instance_;
 }
 
-const action_set& manager::get_actions() const
-{
-       return actions_;
-}
-
-void manager::insert_move(unit& subject, const map_location& target_hex, 
arrow& arrow, size_t index)
-{
-       action_ptr action(new move(subject, target_hex, arrow));
-       assert(index < end());
-       actions_.insert(actions_.begin() + index, action);
-
-}
-
-void manager::queue_move(unit& subject, const map_location& target_hex, 
arrow& arrow)
-{
-       insert_move(subject, target_hex, arrow, end());
-}
-
-void manager::move_earlier(size_t index, size_t increment)
-{
-       move_in_queue(index, - (int) increment);
-}
-
-void manager::move_later(size_t index, size_t increment)
-{
-       move_in_queue(index, (int) increment);
-}
-
-void manager::remove_action(size_t index)
-{
-       assert(!actions_.empty());
-       assert(index < end());
-
-       action_set::iterator position = actions_.begin()+index;
-       if (position < actions_.end())
-       {
-               actions_.erase(position);
-       }
-}
-
-/*
- * Utility function to move actions around the queue.
- * Positive increment = move toward back of the queue and later execution.
- * Negative increment = move toward front of the queue and earlier execution.
- */
-void manager::move_in_queue(size_t index, int increment)
-{
-       assert(!actions_.empty());
-       assert(index < end());
-       if (actions_.empty() || index >= end())
-       {
-               return;
-       }
-
-       action_set::iterator position;
-       position = actions_.begin() + index;
-
-       assert(index + increment < end());
-       if (index + increment >= end())
-       {
-               increment = int(end()) - index;
-       }
-
-       assert(int(index) + increment >= 0);
-       if (int(index) + increment < 0)
-       {
-               increment = -index;
-       }
-
-       action_ptr action = *position;
-       action_set::iterator after = actions_.erase(position);
-       //be careful, previous iterators have just been invalidated by erase()
-       action_set::iterator destination = after + increment;
-       actions_.insert(destination, action);
-}
-
 } // end namespace wb

Modified: trunk/src/whiteboard/manager.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.hpp?rev=43217&r1=43216&r2=43217&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.hpp (original)
+++ trunk/src/whiteboard/manager.hpp Mon Jun  7 02:25:22 2010
@@ -19,23 +19,11 @@
 #ifndef WB_MANAGER_HPP_
 #define WB_MANAGER_HPP_
 
-#include "map_location.hpp"
-
-#include <deque>
+#include <vector>
 
 #include <boost/noncopyable.hpp>
-#include <boost/shared_ptr.hpp>
-
-class unit;
-class arrow;
 
 namespace wb {
-
-class action;
-class move;
-
-typedef boost::shared_ptr<action> action_ptr;
-typedef std::deque<action_ptr> action_set;
 
 /**
  * This class holds and manages all of the whiteboard's planned actions.
@@ -54,71 +42,21 @@
        /**
         * Determine whether the whiteboard is activated.
         */
-       bool active(){ return planning_mode_; }
+       bool active(){ return active_; }
 
-       void set_active(bool active){ planning_mode_ = active; }
-
-       const action_set& get_actions() const;
-
-       /**
-        * Returns the index for the first (executed earlier) action within 
the actions set.
-        */
-       size_t begin() {return 0; }
-
-       /**
-        * Returns the index for the position *after* the last executed 
action within the actions set.
-        */
-       size_t end() { return actions_.size(); }
-
-       /**
-        * Inserts a move at the specified index. The begin() and end() 
functions might prove useful here.
-        */
-       void insert_move(unit& subject, const map_location& target_hex, 
arrow& arrow, size_t index);
-
-       /**
-        * Inserts a move to be executed last (i.e. at the back of the queue)
-        */
-       void queue_move(unit& subject, const map_location& target_hex, arrow& 
arrow);
-
-       /**
-        * Moves an action earlier in the execution order (i.e. at the front 
of the queue),
-        * by the specified increment.
-        * If the increment is too large, the action will be simply moved at 
the earliest position.
-        */
-       void move_earlier(size_t index, size_t increment);
-
-       /**
-        * Moves an action later in the execution order (i.e. at the back of 
the queue),
-        * by the specified increment.
-        * If the increment is too large, the action will be simply moved at 
the latest position.
-        */
-       void move_later(size_t index, size_t increment);
-
-       /**
-        * Deletes the action at the specified index. The begin() and end() 
functions might prove useful here.
-        * If the index doesn't exist, the function does nothing.
-        */
-       void remove_action(size_t index);
+       void set_active(bool active){ active_ = active; }
 
 private:
        /// Singleton -> private constructor
        manager();
-
-       /**
-        * Utility function to move actions around the queue.
-        * Positive increment = move toward back of the queue and later 
execution.
-        * Negative increment = move toward front of the queue and earlier 
execution.
-        */
-       void move_in_queue(size_t index, int increment);
 
        static manager* instance_;
 
        /**
         * Tracks whether the whiteboard is active.
         */
-       bool planning_mode_;
+       bool active_;
 
-       action_set actions_;
 };
 
 } // end namespace wb

Copied: trunk/src/whiteboard/side_actions.cpp (from r43216, 
trunk/src/whiteboard/manager.cpp)
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.cpp?p2=trunk/src/whiteboard/side_actions.cpp&p1=trunk/src/whiteboard/manager.cpp&r1=43216&r2=43217&rev=43217&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.cpp (original)
+++ trunk/src/whiteboard/side_actions.cpp Mon Jun  7 02:25:22 2010
@@ -13,42 +13,33 @@
  */
 
 /**
- * @file manager.cpp
+ * @file side_actions.cpp
  */
 
-#include "manager.hpp"
+#include "side_actions.hpp"
 #include "action.hpp"
 #include "move.hpp"
 
-namespace wb {
+namespace wb
+{
 
-manager* manager::instance_ = NULL;
-
-manager::manager(): planning_mode_(false)
+side_actions::side_actions()
 {
+       // TODO Auto-generated constructor stub
 
 }
 
-manager::~manager()
+side_actions::~side_actions()
 {
-
+       // TODO Auto-generated destructor stub
 }
 
-manager& manager::instance()
-{
-       if (instance_ == NULL)
-       {
-               instance_ = new manager;
-       }
-       return *instance_;
-}
-
-const action_set& manager::get_actions() const
+const action_set& side_actions::get_actions() const
 {
        return actions_;
 }
 
-void manager::insert_move(unit& subject, const map_location& target_hex, 
arrow& arrow, size_t index)
+void side_actions::insert_move(unit& subject, const map_location& 
target_hex, arrow& arrow, size_t index)
 {
        action_ptr action(new move(subject, target_hex, arrow));
        assert(index < end());
@@ -56,22 +47,22 @@
 
 }
 
-void manager::queue_move(unit& subject, const map_location& target_hex, 
arrow& arrow)
+void side_actions::queue_move(unit& subject, const map_location& target_hex, 
arrow& arrow)
 {
        insert_move(subject, target_hex, arrow, end());
 }
 
-void manager::move_earlier(size_t index, size_t increment)
+void side_actions::move_earlier(size_t index, size_t increment)
 {
        move_in_queue(index, - (int) increment);
 }
 
-void manager::move_later(size_t index, size_t increment)
+void side_actions::move_later(size_t index, size_t increment)
 {
        move_in_queue(index, (int) increment);
 }
 
-void manager::remove_action(size_t index)
+void side_actions::remove_action(size_t index)
 {
        assert(!actions_.empty());
        assert(index < end());
@@ -88,7 +79,7 @@
  * Positive increment = move toward back of the queue and later execution.
  * Negative increment = move toward front of the queue and earlier execution.
  */
-void manager::move_in_queue(size_t index, int increment)
+void side_actions::move_in_queue(size_t index, int increment)
 {
        assert(!actions_.empty());
        assert(index < end());
@@ -119,4 +110,5 @@
        actions_.insert(destination, action);
 }
 
-} // end namespace wb
+
+}

Copied: trunk/src/whiteboard/side_actions.hpp (from r43216, 
trunk/src/whiteboard/manager.hpp)
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.hpp?p2=trunk/src/whiteboard/side_actions.hpp&p1=trunk/src/whiteboard/manager.hpp&r1=43216&r2=43217&rev=43217&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.hpp (original)
+++ trunk/src/whiteboard/side_actions.hpp Mon Jun  7 02:25:22 2010
@@ -13,23 +13,23 @@
  */
 
 /**
- * @file manager.hpp
+ * @file side_actions.hpp
  */
 
-#ifndef WB_MANAGER_HPP_
-#define WB_MANAGER_HPP_
+#ifndef WB_SIDE_ACTIONS_HPP_
+#define WB_SIDE_ACTIONS_HPP_
 
 #include "map_location.hpp"
 
 #include <deque>
 
-#include <boost/noncopyable.hpp>
 #include <boost/shared_ptr.hpp>
 
 class unit;
 class arrow;
 
-namespace wb {
+namespace wb
+{
 
 class action;
 class move;
@@ -37,26 +37,11 @@
 typedef boost::shared_ptr<action> action_ptr;
 typedef std::deque<action_ptr> action_set;
 
-/**
- * This class holds and manages all of the whiteboard's planned actions.
- */
-class manager : private boost::noncopyable // Singleton -> Non-copyable
+class side_actions
 {
 public:
-
-       virtual ~manager();
-
-       /**
-        * Get the singleton instance.
-        */
-       static manager& instance();
-
-       /**
-        * Determine whether the whiteboard is activated.
-        */
-       bool active(){ return planning_mode_; }
-
-       void set_active(bool active){ planning_mode_ = active; }
+       side_actions();
+       virtual ~side_actions();
 
        const action_set& get_actions() const;
 
@@ -101,9 +86,6 @@
        void remove_action(size_t index);
 
 private:
-       /// Singleton -> private constructor
-       manager();
-
        /**
         * Utility function to move actions around the queue.
         * Positive increment = move toward back of the queue and later 
execution.
@@ -111,16 +93,9 @@
         */
        void move_in_queue(size_t index, int increment);
 
-       static manager* instance_;
-
-       /**
-        * Tracks whether the whiteboard is active.
-        */
-       bool planning_mode_;
-
        action_set actions_;
 };
 
-} // end namespace wb
+}
 
-#endif /* WB_MANAGER_HPP_ */
+#endif /* WB_SIDE_ACTIONS_HPP_ */




Related Messages


Powered by MHonArc, Updated Mon Jun 07 02:40:28 2010