Author: boucman
Date: Mon May 19 23:03:40 2008
New Revision: 26727

URL: http://svn.gna.org/viewcvs/wesnoth?rev=26727&view=rev
Log:
use the same mechanism for invalidation for unit particle and other particles

Modified:
    trunk/src/unit.cpp
    trunk/src/unit_animation.cpp
    trunk/src/unit_animation.hpp
    trunk/src/unit_frame.cpp
    trunk/src/unit_frame.hpp

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=26727&r1=26726&r2=26727&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Mon May 19 23:03:40 2008
@@ -1890,69 +1890,49 @@
 {
        std::set<gamemap::location> over;
 
-       if (state_ == STATE_STANDING) {
-               // Standing units only overlaps if height is adjusted
-               int height_adjust = 
map_->get_terrain_info(map_->get_terrain(loc)).unit_height_adjust();
-               if (is_flying() && height_adjust < 0) height_adjust = 0;
-
-               if (height_adjust > 0) {
-                       
over.insert(loc.get_direction(gamemap::location::NORTH));
-                       
over.insert(loc.get_direction(gamemap::location::NORTH_WEST));
-                       
over.insert(loc.get_direction(gamemap::location::NORTH_EAST));
-               } else if (height_adjust < 0) {
-                       
over.insert(loc.get_direction(gamemap::location::SOUTH));
-                       
over.insert(loc.get_direction(gamemap::location::SOUTH_WEST));
-                       
over.insert(loc.get_direction(gamemap::location::SOUTH_EAST));
-               }
-       } else {
-               // Animated units overlaps adjacent hexes
-               gamemap::location arr[6];
-               get_adjacent_tiles(loc, arr);
-               for (unsigned int i = 0; i < 6; i++) {
-                       over.insert(arr[i]);
-               }
-       }
-
        // Very early calls, anim not initialized yet
-       frame_parameters params; 
-       game_display * disp =  game_display::get_singleton();
-       const gamemap & map = disp->get_map();
-       const t_translation::t_terrain terrain = map.get_terrain(loc);
-       const terrain_type& terrain_info = map.get_terrain_info(terrain);
-       if(!params.submerge) params.submerge=   is_flying() ? 0.0 : 
terrain_info.unit_submerge();
-
-       if(invisible(loc,disp->get_units(),disp->get_teams()) &&
-                       params.highlight_ratio > 0.5) {
-               params.highlight_ratio = 0.5;
-       }
-       if(loc == disp->selected_hex() && params.highlight_ratio == 1.0) {
-               params.highlight_ratio = 1.5;
-       }
-       int height_adjust = static_cast<int>(terrain_info.unit_height_adjust() 
* disp->get_zoom_factor());
-       if (is_flying() && height_adjust < 0) {
-               height_adjust = 0;
-       }
-       params.y -= height_adjust;
-       params.halo_y -= height_adjust;
-       if (utils::string_bool(get_state("poisoned")) ){
-               params.blend_with = disp->rgb(0,255,0);
-               params.blend_ratio = 0.25;
-       }
-
-       frame_parameters adjusted_params;
-       if(anim_) adjusted_params = anim_->get_current_params(params);
-
-       // Invalidate adjacent neighbours if we don't stay in our hex
-       if(adjusted_params.offset != 0) {
-               gamemap::location::DIRECTION dir = (adjusted_params.offset > 0) 
? facing_ : loc.get_opposite_dir(facing_);
-               gamemap::location adj_loc = loc.get_direction(dir);
-               over.insert(adj_loc);
-               gamemap::location arr[6];
-               get_adjacent_tiles(adj_loc, arr);
-               for (unsigned int i = 0; i < 6; i++) {
-                       over.insert(arr[i]);
-               }
-       }
+       if(get_animation()) {
+               frame_parameters params; 
+               game_display * disp =  game_display::get_singleton();
+               const gamemap & map = disp->get_map();
+               const t_translation::t_terrain terrain = map.get_terrain(loc);
+               const terrain_type& terrain_info = 
map.get_terrain_info(terrain);
+               if(!params.submerge) params.submerge=   is_flying() ? 0.0 : 
terrain_info.unit_submerge();
+
+               if(invisible(loc,disp->get_units(),disp->get_teams()) &&
+                               params.highlight_ratio > 0.5) {
+                       params.highlight_ratio = 0.5;
+               }
+               if(loc == disp->selected_hex() && params.highlight_ratio == 
1.0) {
+                       params.highlight_ratio = 1.5;
+               }
+               int height_adjust = 
static_cast<int>(terrain_info.unit_height_adjust() * disp->get_zoom_factor());
+               if (is_flying() && height_adjust < 0) {
+                       height_adjust = 0;
+               }
+               params.y -= height_adjust;
+               params.halo_y -= height_adjust;
+               if (utils::string_bool(get_state("poisoned")) ){
+                       params.blend_with = disp->rgb(0,255,0);
+                       params.blend_ratio = 0.25;
+               }
+               params.image_mod = image_mods();
+
+               frame_parameters adjusted_params= 
anim_->get_current_params(params);
+               // Invalidate adjacent neighbours if we don't stay in our hex
+               if(adjusted_params.offset != 0) {
+                       gamemap::location::DIRECTION dir = 
(adjusted_params.offset > 0) ? facing_ : loc.get_opposite_dir(facing_);
+                       gamemap::location adj_loc = loc.get_direction(dir);
+                       over.insert(adj_loc);
+                       gamemap::location arr[6];
+                       get_adjacent_tiles(adj_loc, arr);
+                       for (unsigned int i = 0; i < 6; i++) {
+                               over.insert(arr[i]);
+                       }
+               }
+               get_animation()->invalidate(params);
+       }
+
 
        if (abilities_affects_adjacent())
        {
@@ -1962,7 +1942,6 @@
                        over.insert(arr[i]);
                }
        }
-       if(get_animation()) get_animation()->invalidate(params);
 
        return over;
 }

Modified: trunk/src/unit_animation.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_animation.cpp?rev=26727&r1=26726&r2=26727&view=diff
==============================================================================
--- trunk/src/unit_animation.cpp (original)
+++ trunk/src/unit_animation.cpp Mon May 19 23:03:40 2008
@@ -743,6 +743,7 @@
 {
 
        std::map<std::string,particule>::const_iterator anim_itor 
=sub_anims_.begin();
+       unit_anim_.invalidate(value,true);
        for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
                anim_itor->second.invalidate(value);
        }
@@ -758,11 +759,11 @@
                
current_frame.redraw(get_current_frame_time(),false,src_,dst_,&halo_id_,default_val,value);
        }
 }
-void unit_animation::particule::invalidate(const frame_parameters& value) const
+void unit_animation::particule::invalidate(const frame_parameters& value,const 
bool primary ) const
 {
        const unit_frame& current_frame= get_current_frame();
        const frame_parameters default_val = 
parameters_.parameters(get_animation_time() -get_begin_time());
-       
current_frame.invalidate(get_current_frame_time(),src_,dst_,default_val,value);
+       
current_frame.invalidate(get_current_frame_time(),src_,dst_,default_val,value,primary);
 }
 
 unit_animation::particule::~particule()

Modified: trunk/src/unit_animation.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_animation.hpp?rev=26727&r1=26726&r2=26727&view=diff
==============================================================================
--- trunk/src/unit_animation.hpp (original)
+++ trunk/src/unit_animation.hpp Mon May 19 23:03:40 2008
@@ -83,7 +83,7 @@
                        bool need_update() const;
                        void override(int start_time,const std::string 
highlight="", const std::string blend_ratio ="",Uint32 blend_color = 0,const 
std::string offset="");
                        void redraw( const frame_parameters& value);
-                       void invalidate(const frame_parameters& value ) const;
+                       void invalidate(const frame_parameters& value, const 
bool primary = false) const;
                        void start_animation(int start_time,const 
gamemap::location& src,const  gamemap::location& dst, bool cycles=false);
                        const frame_parameters parameters(const 
frame_parameters & default_val,bool primary) const { return 
get_current_frame().merge_parameters(get_current_frame_time(),parameters_.parameters(get_animation_time()-get_begin_time()),default_val,primary);
 };
                        bool accelerate;

Modified: trunk/src/unit_frame.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_frame.cpp?rev=26727&r1=26726&r2=26727&view=diff
==============================================================================
--- trunk/src/unit_frame.cpp (original)
+++ trunk/src/unit_frame.cpp Mon May 19 23:03:40 2008
@@ -408,7 +408,7 @@
                }
        }
 }
-void unit_frame::invalidate(const int frame_time,const gamemap::location & 
src,const gamemap::location & dst,const frame_parameters & animation_val,const 
frame_parameters & engine_val) const
+void unit_frame::invalidate(const int frame_time,const gamemap::location & 
src,const gamemap::location & dst,const frame_parameters & animation_val,const 
frame_parameters & engine_val,const bool primary) const
 {
        const int xsrc = game_display::get_singleton()->get_location_x(src);
        const int ysrc = game_display::get_singleton()->get_location_y(src);
@@ -416,7 +416,7 @@
        const int ydst = game_display::get_singleton()->get_location_y(dst);
        const gamemap::location::DIRECTION direction = 
src.get_relative_dir(dst);
 
-       const frame_parameters current_data = 
merge_parameters(frame_time,animation_val,engine_val);
+       const frame_parameters current_data = 
merge_parameters(frame_time,animation_val,engine_val,primary);
        double tmp_offset = current_data.offset;
        //unused var - int d2 = game_display::get_singleton()->hex_size() / 2;
 
@@ -430,15 +430,24 @@
 
        surface image;
        if(!image_loc.is_void() && image_loc.get_filename() != "") { // invalid 
diag image, or not diagonal
+               //! TODO cache handling: here we will use the image again soon
+               // we should cache it here and release it (if needed) after 
redrawn
                image=image::get_image(image_loc,
                                image::SCALED_TO_ZOOM,
                                false
                                );
        }
        const int x = static_cast<int>(tmp_offset * xdst + (1.0-tmp_offset) * 
xsrc)+current_data.x;
-       const int y = static_cast<int>(tmp_offset * ydst + (1.0-tmp_offset) * 
ysrc)+current_data.x;
+       const int y = static_cast<int>(tmp_offset * ydst + (1.0-tmp_offset) * 
ysrc)+current_data.y;
        if (image != NULL) {
-               
game_display::get_singleton()->invalidate_zone(x,y,x+image->w,y+image->h);
+               //! optimization for most common case
+              if(x==xsrc && y == ysrc && 
+                              image->w  == 
game_display::get_singleton()->hex_size() &&
+                              image->h  == 
game_display::get_singleton()->hex_size()) {
+                      game_display::get_singleton()->invalidate(src);
+              } else {
+                      
game_display::get_singleton()->invalidate_zone(x,y,x+image->w,y+image->h);
+              }
 
        }
 }

Modified: trunk/src/unit_frame.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_frame.hpp?rev=26727&r1=26726&r2=26727&view=diff
==============================================================================
--- trunk/src/unit_frame.hpp (original)
+++ trunk/src/unit_frame.hpp Mon May 19 23:03:40 2008
@@ -179,7 +179,7 @@
                int duration() const { return builder_.duration();};
                bool does_not_change() const{ return 
builder_.does_not_change();};
                bool need_update() const{ return builder_.need_update();};
-               void invalidate(const int frame_time,const gamemap::location & 
src,const gamemap::location & dst,const frame_parameters & animation_val,const 
frame_parameters & engine_val) const;
+               void invalidate(const int frame_time,const gamemap::location & 
src,const gamemap::location & dst,const frame_parameters & animation_val,const 
frame_parameters & engine_val,const bool primary) const;
        private:
                frame_builder builder_;
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to