mail[Wesnoth-commits] r44422 - 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 July 20, 2010 - 09:52:
Author: gabba
Date: Tue Jul 20 09:52:19 2010
New Revision: 44422

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44422&view=rev
Log:
Whiteboard: went back to using a pointer instead of looking up the selected 
unit in the unit map every time.

Modified:
    trunk/src/mouse_events.cpp
    trunk/src/whiteboard/highlight_visitor.cpp
    trunk/src/whiteboard/highlight_visitor.hpp
    trunk/src/whiteboard/manager.cpp
    trunk/src/whiteboard/manager.hpp

Modified: trunk/src/mouse_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.cpp?rev=44422&r1=44421&r2=44422&view=diff
==============================================================================
--- trunk/src/mouse_events.cpp (original)
+++ trunk/src/mouse_events.cpp Tue Jul 20 09:52:19 2010
@@ -461,7 +461,7 @@
        //see if we're trying to do a attack or move-and-attack
        if((!browse || resources::whiteboard->is_active()) && 
!commands_disabled && attack_from.valid()) {
                if (resources::whiteboard->is_active()) {
-                       if  (resources::whiteboard->has_selected_hex()) {
+                       if  (resources::whiteboard->has_selected_unit()) {
                                // Unselect the current hex, and create 
planned attack for whiteboard
                                selected_hex_ = map_location();
                                gui().select_hex(map_location());

Modified: trunk/src/whiteboard/highlight_visitor.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/highlight_visitor.cpp?rev=44422&r1=44421&r2=44422&view=diff
==============================================================================
--- trunk/src/whiteboard/highlight_visitor.cpp (original)
+++ trunk/src/whiteboard/highlight_visitor.cpp Tue Jul 20 09:52:19 2010
@@ -163,6 +163,17 @@
        return main_highlight_.lock();
 }
 
+unit* highlight_visitor::get_selection_target()
+{
+//     unit* unit = NULL;
+//     if(action_ptr action = main_highlight_.lock())
+//     {
+//             unit = action->get_unit();
+//     }
+//     return unit;
+       return owner_unit_;
+}
+
 void highlight_visitor::visit_move(move_ptr move)
 {
        switch (mode_)

Modified: trunk/src/whiteboard/highlight_visitor.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/highlight_visitor.hpp?rev=44422&r1=44421&r2=44422&view=diff
==============================================================================
--- trunk/src/whiteboard/highlight_visitor.hpp (original)
+++ trunk/src/whiteboard/highlight_visitor.hpp Tue Jul 20 09:52:19 2010
@@ -48,6 +48,7 @@
        action_ptr get_execute_target();
        action_ptr get_delete_target();
        action_ptr get_bump_target();
+       unit* get_selection_target();
 
        virtual void visit_move(move_ptr move);
        virtual void visit_attack(attack_ptr attack);

Modified: trunk/src/whiteboard/manager.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.cpp?rev=44422&r1=44421&r2=44422&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.cpp (original)
+++ trunk/src/whiteboard/manager.cpp Tue Jul 20 09:52:19 2010
@@ -62,7 +62,7 @@
                steps_(),
                move_arrow_(),
                fake_unit_(),
-               selected_hex_(),
+               selected_unit_(NULL),
                planned_unit_map_active_(false),
                executing_actions_(false)
 {
@@ -212,37 +212,33 @@
 {
        //FIXME: Detect if a WML event is executing, and if so, avoid 
modifying the unit map during that time.
        // Acting otherwise causes a crash.
-       if (!selected_hex_.valid() && highlighter_)
+       if (!selected_unit_ && highlighter_)
        {
                highlighter_->set_mouseover_hex(hex);
                highlighter_->highlight();
        }
 }
 
-void manager::on_select_hex(const map_location& hex)
-{
-       selected_hex_ = hex;
-       unit* selected_unit;
-       {
-               scoped_planned_unit_map planned_unit_map;
-               selected_unit = this->selected_unit();
-       }
+void manager::on_select_hex(const map_location& /*TODO remove this parameter 
if proves useless */)
+{
        erase_temp_move();
-       if (!(selected_unit && selected_unit->side() == 
resources::screen->viewing_side()))
-       {
-               selected_hex_ = map_location();
-       }
-       else
-       {
-               LOG_WB << "Selected unit " << selected_unit->name() << " [" 
<< selected_unit->id() << "]\n";
-       }
+       selected_unit_ = highlighter_->get_selection_target();
+       if (selected_unit_)
+       {
+               LOG_WB << "Selected unit " << selected_unit_->name() << " [" 
<< selected_unit_->id() << "]\n";
+       }
+       //assert(selected_unit_->side() != resources::screen->viewing_side());
 }
 
 void manager::on_deselect_hex()
 {
        erase_temp_move();
-       selected_hex_ = map_location();
-       LOG_WB << "Deselecting unit\n";
+       if (selected_unit_)
+       {
+               LOG_WB << "Deselecting unit" << selected_unit_->name() << " 
[" << selected_unit_->id() << "]\n";
+       }
+       selected_unit_ = NULL;
+
 }
 
 void manager::create_temp_move()
@@ -272,9 +268,9 @@
        {
                route_.reset(new pathfind::marked_route()); //empty route
        }
-       else if (unit* subject_unit = selected_unit())
-       {
-               assert(subject_unit->side() == 
resources::screen->viewing_side());
+       else if (selected_unit_)
+       {
+               assert(selected_unit_->side() == 
resources::screen->viewing_side());
                route_.reset(new pathfind::marked_route(route));
                //NOTE: route_.steps.back() = dst, and route_.steps.front() = 
src
 
@@ -291,7 +287,7 @@
                if (!fake_unit_)
                {
                        // Create temp ghost unit
-                       fake_unit_.reset(new unit(*subject_unit), 
wb::manager::fake_unit_deleter());
+                       fake_unit_.reset(new unit(*selected_unit_), 
wb::manager::fake_unit_deleter());
                        
resources::screen->place_temporary_unit(fake_unit_.get());
                        fake_unit_->set_ghosted(false);
                }
@@ -396,8 +392,8 @@
 
                action_ptr action;
                side_actions::iterator it;
-               if (selected_unit() &&
-                               (it = 
viewer_actions()->find_first_action_of(*selected_unit())) != 
viewer_actions()->end())
+               if (selected_unit_ &&
+                               (it = 
viewer_actions()->find_first_action_of(*selected_unit_)) != 
viewer_actions()->end())
                {
                        executing_actions_ = true;
                        viewer_actions()->execute(it);
@@ -428,8 +424,8 @@
 
                action_ptr action;
                side_actions::iterator it;
-               if (selected_unit() &&
-                               (it = 
viewer_actions()->find_first_action_of(*selected_unit())) != 
viewer_actions()->end())
+               if (selected_unit_ &&
+                               (it = 
viewer_actions()->find_first_action_of(*selected_unit_)) != 
viewer_actions()->end())
                {
                        viewer_actions()->remove_action(it);
                }
@@ -493,11 +489,6 @@
     }
 }
 
-unit* manager::selected_unit()
-{
-       return find_future_unit(selected_hex_);
-}
-
 scoped_planned_unit_map::scoped_planned_unit_map()
 :has_planned_unit_map_(resources::whiteboard->has_planned_unit_map())
 {

Modified: trunk/src/whiteboard/manager.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.hpp?rev=44422&r1=44421&r2=44422&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.hpp (original)
+++ trunk/src/whiteboard/manager.hpp Tue Jul 20 09:52:19 2010
@@ -88,7 +88,7 @@
        /** Informs whether an arrow is being displayed for move creation 
purposes */
        bool has_temp_move() const { return route_; }
        /** Informs whether the whiteboard tracks a selected unit */
-       bool has_selected_hex() const { return selected_hex_.valid(); }
+       bool has_selected_unit() const { return selected_unit_; }
 
        void erase_temp_move();
 
@@ -118,8 +118,6 @@
        };
 
 private:
-       unit* selected_unit();
-
        ///Tracks whether the whiteboard is active.
        bool active_;
        bool inverted_behavior_;
@@ -134,7 +132,7 @@
        arrow_ptr move_arrow_;
        fake_unit_ptr fake_unit_;
 
-       map_location selected_hex_;
+       unit* selected_unit_;
 
        bool planned_unit_map_active_;
        /** Track whenever we're modifying actions, to avoid dual execution 
etc. */




Related Messages


Powered by MHonArc, Updated Tue Jul 20 10:00:13 2010