Author: boucman
Date: Mon May 11 23:04:37 2009
New Revision: 35577
URL: http://svn.gna.org/viewcvs/wesnoth?rev=35577&view=rev
Log:
various animation optimisation (cache result of overlap calculation + better
initialization of image::locator)
Modified:
trunk/src/display.hpp
trunk/src/unit_animation.cpp
trunk/src/unit_animation.hpp
trunk/src/unit_frame.cpp
trunk/src/unit_frame.hpp
Modified: trunk/src/display.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.hpp?rev=35577&r1=35576&r2=35577&view=diff
==============================================================================
--- trunk/src/display.hpp (original)
+++ trunk/src/display.hpp Mon May 11 23:04:37 2009
@@ -286,6 +286,14 @@
* defaults to no action, overriden by derived classes
*/
virtual void invalidate_animations_location(const map_location&
/*loc*/) {}
+
+ /**
+ * What hex are currently invalidated (read only)
+ * used for some fine grained invalidation algorithm which need
recurstion
+ */
+ const std::set<map_location> & get_invalidated() { return invalidated_;
}
+
+
const gamemap& get_map() const { return *map_; }
Modified: trunk/src/unit_animation.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_animation.cpp?rev=35577&r1=35576&r2=35577&view=diff
==============================================================================
--- trunk/src/unit_animation.cpp (original)
+++ trunk/src/unit_animation.cpp Mon May 11 23:04:37 2009
@@ -21,6 +21,7 @@
#include "halo.hpp"
#include "map.hpp"
#include "unit.hpp"
+#include <algorithm>
struct tag_name_manager {
tag_name_manager() : names() {
@@ -127,7 +128,9 @@
sub_anims_(),
unit_anim_(start_time),
src_(),
- dst_()
+ dst_(),
+ invalidated_(false),
+ overlaped_hex_()
{
add_frame(frame.duration(),frame,!frame.does_not_change());
}
@@ -683,8 +686,7 @@
accelerate(true),
parameters_(cfg,frame_string),
halo_id_(0),
- last_frame_begin_time_(0),
- invalidated_(false)
+ last_frame_begin_time_(0)
{
config::const_child_itors range = cfg.child_range(frame_string+"frame");
starting_frame_time_=INT_MAX;
@@ -812,6 +814,8 @@
void unit_animation::redraw(const frame_parameters& value)
{
+ invalidated_=false;
+ overlaped_hex_ = std::set<map_location>();
std::map<std::string,particule>::iterator anim_itor =sub_anims_.begin();
unit_anim_.redraw(value,src_,dst_,true);
for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
@@ -820,18 +824,36 @@
}
bool unit_animation::invalidate(const frame_parameters& value)
{
-
- bool result = false;
- std::map<std::string,particule>::iterator anim_itor =sub_anims_.begin();
- result |= unit_anim_.invalidate(value,src_,dst_,true);
- for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
- result |= anim_itor->second.invalidate(value,src_,dst_);
- }
- return result;
+ if(invalidated_) return false;
+ game_display*disp = game_display::get_singleton();
+ if(overlaped_hex_.empty()) {
+ std::map<std::string,particule>::iterator anim_itor
=sub_anims_.begin();
+ overlaped_hex_ =
unit_anim_.get_overlaped_hex(value,src_,dst_,true);
+ for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
+ std::set<map_location> tmp =
anim_itor->second.get_overlaped_hex(value,src_,dst_,true);
+ overlaped_hex_.insert(tmp.begin(),tmp.end());
+ }
+ }
+ if(need_update() ) {
+ disp->invalidate(overlaped_hex_);
+ invalidated_ = true;
+ return true;
+ } else {
+ std::vector<map_location> intersection;
+ set_intersection(overlaped_hex_.begin(),overlaped_hex_.end(),
+
disp->get_invalidated().begin(),disp->get_invalidated().end(),
+ std::back_inserter(intersection));
+ if(!intersection.empty()) {
+ disp->invalidate(overlaped_hex_);
+ invalidated_ = true;
+ return true;
+ } else {
+ return false;
+ }
+ }
}
void unit_animation::particule::redraw(const frame_parameters& value,const
map_location &src, const map_location &dst, const bool primary)
{
- invalidated_=false;
const unit_frame& current_frame= get_current_frame();
const frame_parameters default_val =
parameters_.parameters(get_animation_time() -get_begin_time());
if(get_current_frame_begin_time() != last_frame_begin_time_ ) {
@@ -841,13 +863,12 @@
current_frame.redraw(get_current_frame_time(),false,src,dst,&halo_id_,default_val,value,primary);
}
}
-bool unit_animation::particule::invalidate(const frame_parameters& value,const
map_location &src, const map_location &dst, const bool primary )
-{
- if(invalidated_) return false;
+std::set<map_location> unit_animation::particule::get_overlaped_hex(const
frame_parameters& value,const map_location &src, const map_location &dst, const
bool primary )
+{
const unit_frame& current_frame= get_current_frame();
const frame_parameters default_val =
parameters_.parameters(get_animation_time() -get_begin_time());
- invalidated_ =
current_frame.invalidate(need_update(),get_current_frame_time(),src,dst,default_val,value,primary);
- return invalidated_;
+ return
current_frame.get_overlaped_hex(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=35577&r1=35576&r2=35577&view=diff
==============================================================================
--- trunk/src/unit_animation.hpp (original)
+++ trunk/src/unit_animation.hpp Mon May 11 23:04:37 2009
@@ -22,6 +22,7 @@
#include <climits>
#include <string>
#include <vector>
+#include <set>
class attack_type;
class game_display;
@@ -78,15 +79,14 @@
accelerate(true),
parameters_(),
halo_id_(0),
- last_frame_begin_time_(0),
- invalidated_(false)
+ last_frame_begin_time_(0)
{};
explicit particule(const config& cfg,const std::string
frame_string ="frame");
virtual ~particule();
bool need_update() const;
void override(int start_time,int duration, const
std::string highlight="", const std::string blend_ratio ="",Uint32 blend_color
= 0,const std::string offset="",const std::string layer="");
void redraw( const frame_parameters& value,const
map_location &src, const map_location &dst, const bool primary=false);
- bool invalidate(const frame_parameters& value,const
map_location &src, const map_location &dst, const bool primary = false);
+ std::set<map_location> get_overlaped_hex(const
frame_parameters& value,const map_location &src, const map_location &dst, const
bool primary = false);
void start_animation(int start_time, 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;
@@ -96,8 +96,6 @@
frame_builder parameters_;
int halo_id_;
int last_frame_begin_time_;
- // optimisation
- bool invalidated_;
};
t_translation::t_list terrain_types_;
@@ -117,6 +115,9 @@
/* these are drawing parameters, but for efficiancy reason they
are in the anim and not in the particle */
map_location src_;
map_location dst_;
+ // optimisation
+ bool invalidated_;
+ std::set<map_location> overlaped_hex_;
};
class unit_animator
Modified: trunk/src/unit_frame.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_frame.cpp?rev=35577&r1=35576&r2=35577&view=diff
==============================================================================
--- trunk/src/unit_frame.cpp (original)
+++ trunk/src/unit_frame.cpp Mon May 11 23:04:37 2009
@@ -155,8 +155,8 @@
#include "unit_frame.hpp"
frame_parameters::frame_parameters() :
- image(""),
- image_diagonal(""),
+ image(),
+ image_diagonal(),
image_mod(""),
halo(""),
halo_x(0),
@@ -179,8 +179,8 @@
{}
frame_builder::frame_builder() :
- image_(image::locator()),
- image_diagonal_(image::locator()),
+ image_(),
+ image_diagonal_(),
image_mod_(""),
halo_(""),
halo_x_(""),
@@ -201,8 +201,8 @@
{}
frame_builder::frame_builder(const config& cfg,const std::string&
frame_string) :
- image_(image::locator()),
- image_diagonal_(image::locator()),
+ image_(),
+ image_diagonal_(),
image_mod_(""),
halo_(""),
halo_x_(""),
@@ -498,7 +498,7 @@
}
}
}
-bool unit_frame::invalidate(const bool force,const int frame_time,const
map_location & src,const map_location & dst,const frame_parameters &
animation_val,const frame_parameters & engine_val,const bool primary) const
+std::set<map_location> unit_frame::get_overlaped_hex(const int
frame_time,const map_location & src,const map_location & dst,const
frame_parameters & animation_val,const frame_parameters & engine_val,const bool
primary) const
{
game_display* disp = game_display::get_singleton();
const int xsrc = disp->get_location_x(src);
@@ -521,11 +521,9 @@
// we always invalidate our own hex because we need to be called at
redraw time even
// if we don't draw anything in the hex itself
- bool result = false;
+ std::set<map_location> result;
if(tmp_offset==0 && current_data.x == 0 && current_data.y == 0 &&
image::is_in_hex(image_loc)) {
- if(force || need_update()) {
- result |= disp->invalidate(src);
- }
+ result.insert(src);
} else {
surface image;
if(!image_loc.is_void() && image_loc.get_filename() != "") { //
invalid diag image, or not diagonal
@@ -540,19 +538,16 @@
// check if our underlying hexes are invalidated
// if we need to update ourselve because we changed,
invalidate our hexes
// and return whether or not our hexs was invalidated
- if(force || need_update() ||
disp->rectangle_need_update(r)) {
- // invalidate ouself to be called at redraw time
- result |= disp->invalidate(src);
- result |=
disp->invalidate_visible_locations_in_rect(r);
- }
+ // invalidate ouself to be called at redraw time
+ result.insert(src);
+ display::rect_of_hexes underlying_hex =
disp->hexes_under_rect(r);
+
result.insert(underlying_hex.begin(),underlying_hex.end());
} else {
// we have no "redraw surface" but we still need to
invalidate our own hex
// in case we have a halo and/or sound that needs a
redraw
- if(force || need_update() ){
- // invalidate ouself to be called at redraw time
- result |= disp->invalidate(src);
- result |= disp->invalidate(dst);
- }
+ // invalidate ouself to be called at redraw time
+ result.insert(src);
+ result.insert(dst);
}
}
return result;
Modified: trunk/src/unit_frame.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_frame.hpp?rev=35577&r1=35576&r2=35577&view=diff
==============================================================================
--- trunk/src/unit_frame.hpp (original)
+++ trunk/src/unit_frame.hpp Mon May 11 23:04:37 2009
@@ -29,6 +29,7 @@
#include <string>
#include <vector>
+#include <set>
class progressive_string {
public:
@@ -152,7 +153,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();};
- bool invalidate(const bool force,const int frame_time,const
map_location & src,const map_location & dst,const frame_parameters &
animation_val,const frame_parameters & engine_val,const bool primary) const;
+ std::set<map_location> get_overlaped_hex(const int
frame_time,const map_location & src,const map_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