mail[Wesnoth-commits] r43301 - in /trunk/src/whiteboard: manager.cpp manager.hpp move.cpp side_actions.cpp


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

Header


Content

Posted by gabrielmorin on June 12, 2010 - 08:04:
Author: gabba
Date: Sat Jun 12 08:04:35 2010
New Revision: 43301

URL: http://svn.gna.org/viewcvs/wesnoth?rev=43301&view=rev
Log:
Whiteboard:
- moved to std::auto_ptr for some variables to ensure proper deletion on 
manager "death".
- fixed infamous off-by-one error with the team indexes
- made manager noncopyable
- use more forward declarations and less includes in manager.hpp

Modified:
    trunk/src/whiteboard/manager.cpp
    trunk/src/whiteboard/manager.hpp
    trunk/src/whiteboard/move.cpp
    trunk/src/whiteboard/side_actions.cpp

Modified: trunk/src/whiteboard/manager.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.cpp?rev=43301&r1=43300&r2=43301&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.cpp (original)
+++ trunk/src/whiteboard/manager.cpp Sat Jun 12 08:04:35 2010
@@ -19,6 +19,7 @@
 #include "manager.hpp"
 
 #include "action.hpp"
+#include "mapbuilder_visitor.hpp"
 
 #include "arrow.hpp"
 #include "foreach.hpp"
@@ -28,17 +29,28 @@
 
 namespace wb {
 
-manager::manager(): active_(false), move_arrow_(NULL)
+manager::manager():
+               active_(false),
+               mapbuilder_(NULL),
+               move_arrow_(NULL),
+               fake_unit_(NULL)
+{
+}
+
+manager::~manager()
 {
 }
 
 void manager::apply_temp_modifiers()
 {
        mapbuilder_.reset(new mapbuilder_visitor(*resources::units));
-       team& current_team = 
(*resources::teams)[resources::controller->current_side()];
-       const action_set& actions = current_team.get_side_actions().actions();
-       foreach (action_ptr action, actions)
+       int current_side = resources::controller->current_side();
+       team& current_team = (*resources::teams)[current_side - 1];
+       side_actions& side_actions = current_team.get_side_actions();
+       const action_set& actions = side_actions.actions();
+       foreach (const action_ptr &action, actions)
        {
+               assert(action);
                action->accept(*mapbuilder_);
        }
 }
@@ -54,10 +66,10 @@
        route_ = steps;
        if (route_.size() > 1)
        {
-               if (move_arrow_ == NULL)
+               if (move_arrow_.get() == NULL)
                {
                        display *screen = (display*) resources::screen;
-                       move_arrow_ = new arrow(screen);
+                       move_arrow_.reset(new arrow(screen));
                        move_arrow_->set_color("white");
                        move_arrow_->set_alpha(0.5);
                        screen->add_arrow(*move_arrow_);
@@ -70,7 +82,7 @@
 void manager::create_move_from_route(unit& subject)
 {
        int current_side = resources::controller->current_side();
-       team& current_team = (*resources::teams)[current_side];
+       team& current_team = (*resources::teams)[current_side - 1];
 
        LOG_WB << "Creating move for unit " << subject.name() << " [" << 
subject.id() << "]"
                        << " from " << subject.get_location()
@@ -78,9 +90,9 @@
 
        move_arrow_->set_color(team::get_side_color_index(current_side));
 
-       current_team.get_side_actions().queue_move(subject, route_.back(), 
*move_arrow_);
-       //ownership of the arrow transferred to the new move action
-       move_arrow_ = NULL;
+       current_team.get_side_actions().queue_move(subject, route_.back(),
+                       *(move_arrow_.release()) /* ownership of the arrow 
transferred to the new move action */);
+
 }
 
 } // end namespace wb

Modified: trunk/src/whiteboard/manager.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.hpp?rev=43301&r1=43300&r2=43301&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.hpp (original)
+++ trunk/src/whiteboard/manager.hpp Sat Jun 12 08:04:35 2010
@@ -19,12 +19,11 @@
 #ifndef WB_MANAGER_HPP_
 #define WB_MANAGER_HPP_
 
-#include "mapbuilder_visitor.hpp"
-
 #include "map_location.hpp"
 
-#include <boost/scoped_ptr.hpp>
+#include <boost/noncopyable.hpp>
 
+#include <memory>
 #include <vector>
 
 class arrow;
@@ -32,14 +31,17 @@
 
 namespace wb {
 
+class mapbuilder_visitor;
+
 /**
  * This class holds and manages all of the whiteboard's planned actions.
  */
-class manager
+class manager : private boost::noncopyable
 {
 public:
 
        manager();
+       ~manager();
 
        /**
         * Determine whether the whiteboard is activated.
@@ -70,11 +72,12 @@
         */
        bool active_;
 
-       boost::scoped_ptr<mapbuilder_visitor> mapbuilder_;
+       std::auto_ptr<mapbuilder_visitor> mapbuilder_;
 
        std::vector<map_location> route_;
 
-       arrow* move_arrow_;
+       std::auto_ptr<arrow> move_arrow_;
+       std::auto_ptr<unit> fake_unit_;
 };
 
 } // end namespace wb

Modified: trunk/src/whiteboard/move.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.cpp?rev=43301&r1=43300&r2=43301&view=diff
==============================================================================
--- trunk/src/whiteboard/move.cpp (original)
+++ trunk/src/whiteboard/move.cpp Sat Jun 12 08:04:35 2010
@@ -27,7 +27,10 @@
 namespace wb {
 
 move::move(unit& subject, const map_location& target_hex, arrow& arrow)
-: unit_(subject), orig_hex_(subject.get_location()), dest_hex_(target_hex), 
arrow_(arrow)
+: unit_(subject),
+  orig_hex_(subject.get_location()),
+  dest_hex_(target_hex),
+  arrow_(arrow)
 {
 }
 

Modified: trunk/src/whiteboard/side_actions.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.cpp?rev=43301&r1=43300&r2=43301&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.cpp (original)
+++ trunk/src/whiteboard/side_actions.cpp Sat Jun 12 08:04:35 2010
@@ -23,15 +23,12 @@
 namespace wb
 {
 
-side_actions::side_actions()
+side_actions::side_actions(): actions_()
 {
-       // TODO Auto-generated constructor stub
-
 }
 
 side_actions::~side_actions()
 {
-       // TODO Auto-generated destructor stub
 }
 
 const action_set& side_actions::actions() const
@@ -44,7 +41,6 @@
        action_ptr action(new move(subject, target_hex, arrow));
        assert(index < end());
        actions_.insert(actions_.begin() + index, action);
-
 }
 
 void side_actions::queue_move(unit& subject, const map_location& target_hex, 
arrow& arrow)




Related Messages


Powered by MHonArc, Updated Sat Jun 12 08:40:11 2010