Author: boucman
Date: Sat May 16 19:50:19 2009
New Revision: 35659
URL: http://svn.gna.org/viewcvs/wesnoth?rev=35659&view=rev
Log:
commit all my pending perf improvements, there is too much stuff lying around I
need to save all that
Modified:
trunk/src/unit.cpp
trunk/src/unit.hpp
trunk/src/unit_animation.cpp
trunk/src/unit_animation.hpp
Modified: trunk/src/unit.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=35659&r1=35658&r2=35659&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Sat May 16 19:50:19 2009
@@ -2076,29 +2076,15 @@
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 (get_state(STATE_POISONED) ){
- params.blend_with = disp->rgb(0,255,0);
- params.blend_ratio = 0.25;
- }
params.image_mod = image_mods();
- //get_animation()->update_last_draw_time();
- frame_parameters adjusted_params=
get_animation()->get_current_params(params);
result |= get_animation()->invalidate(params);
}
@@ -3020,22 +3006,6 @@
return *this;
}
-void unit::refresh(const game_display &disp,const map_location &loc)
-{
- if (state_ == STATE_FORGET && anim_ &&
anim_->animation_finished_potential()) {
- set_standing(loc);
- return;
- }
- if (state_ != STATE_STANDING || get_current_animation_tick() <
next_idling_
- || incapacitated())
- return;
- if (get_current_animation_tick() > next_idling_ + 1000) {
- // prevent all units animating at the same time
- set_standing(loc);
- } else {
- set_idling(disp, loc);
- }
-}
unit_movement_resetter::unit_movement_resetter(unit &u, bool operate) :
u_(u), moves_(u.movement_)
Modified: trunk/src/unit.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=35659&r1=35658&r2=35659&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Sat May 16 19:50:19 2009
@@ -26,8 +26,8 @@
#include "unit_types.hpp"
#include "unit_map.hpp"
#include "variable.hpp"
-
-class game_display;
+#include "game_display.hpp"
+
class gamestatus;
class game_state;
class config_writer;
@@ -145,7 +145,25 @@
void end_turn();
void new_scenario();
/** Called on every draw */
- void refresh(const game_display& disp,const map_location& loc);
+ void refresh(const game_display& disp,const map_location& loc) {
+ if (state_ != STATE_STANDING || get_current_animation_tick() <
next_idling_ || incapacitated())
+ return;
+ if (state_ == STATE_FORGET && anim_ &&
anim_->animation_finished_potential()) {
+ set_standing(loc);
+ return;
+ }
+ if (get_current_animation_tick() > next_idling_ + 1000) {
+ // prevent all units animating at the same time
+ if (disp.idle_anim()) {
+ next_idling_ = get_current_animation_tick()
+ + static_cast<int>((20000 + rand() %
20000) * disp.idle_anim_rate());
+ } else {
+ next_idling_ = INT_MAX;
+ }
+ } else {
+ set_idling(disp, loc);
+ }
+ }
bool take_hit(int damage) { hit_points_ -= damage; return hit_points_
<= 0; }
void heal(int amount);
Modified: trunk/src/unit_animation.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_animation.cpp?rev=35659&r1=35658&r2=35659&view=diff
==============================================================================
--- trunk/src/unit_animation.cpp (original)
+++ trunk/src/unit_animation.cpp Sat May 16 19:50:19 2009
@@ -130,6 +130,7 @@
src_(),
dst_(),
invalidated_(false),
+ play_offscreen_(true),
overlaped_hex_()
{
add_frame(frame.duration(),frame,!frame.does_not_change());
@@ -151,7 +152,10 @@
sub_anims_(),
unit_anim_(cfg,frame_string),
src_(),
- dst_()
+ dst_(),
+ invalidated_(false),
+ play_offscreen_(true),
+ overlaped_hex_()
{
// if(!cfg["debug"].empty()) printf("DEBUG WML:
FINAL\n%s\n\n",cfg.debug().c_str());
foreach (const config::any_child &fr, cfg.all_children_range())
@@ -207,6 +211,7 @@
foreach (const config &filter, cfg.child_range("filter_second_attack"))
{
secondary_attack_filter_.push_back(filter);
}
+ play_offscreen_=utils::string_bool(cfg["offscreen"],true);
}
@@ -333,6 +338,7 @@
tmp_anim = *itor;
tmp_anim.event_ = utils::split("standing");
+ tmp_anim.play_offscreen_ = false;
animations.push_back(tmp_anim);
tmp_anim = *itor;
@@ -477,6 +483,7 @@
foreach (config &anim, expanded_cfg.child_range("standing_anim"))
{
anim["apply_to"] = "standing,default";
+ if (anim["offscreen"].empty()) anim["offscreen"] = "no";
if (anim["layer"].empty()) anim["layer"] = default_layer;
animations.push_back(unit_animation(anim));
}
@@ -485,6 +492,7 @@
foreach (config &anim, expanded_cfg.child_range("idle_anim"))
{
anim["apply_to"] = "idling";
+ if (anim["offscreen"].empty()) anim["offscreen"] = "no";
if (anim["layer"].empty()) anim["layer"] = default_layer;
animations.push_back(unit_animation(anim));
}
@@ -680,6 +688,14 @@
return false;
}
+bool unit_animation::particule::need_minimal_update() const
+{
+ if(get_current_frame_begin_time() != last_frame_begin_time_ ) {
+ return true;
+ }
+ return false;
+}
+
unit_animation::particule::particule(
const config& cfg, const std::string frame_string ) :
animated<unit_frame>(),
@@ -715,6 +731,19 @@
std::map<std::string,particule>::const_iterator anim_itor
=sub_anims_.begin();
for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
if(anim_itor->second.need_update()) return true;
+ }
+ return false;
+}
+
+bool unit_animation::need_minimal_update() const
+{
+ if(!play_offscreen_) {
+ return false;
+ }
+ if(unit_anim_.need_minimal_update()) return true;
+ std::map<std::string,particule>::const_iterator anim_itor
=sub_anims_.begin();
+ for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
+ if(anim_itor->second.need_minimal_update()) return true;
}
return false;
}
@@ -826,24 +855,33 @@
{
if(invalidated_) return false;
game_display*disp = game_display::get_singleton();
+ bool complete_redraw =disp->tile_nearly_on_screen(src_) ||
disp->tile_nearly_on_screen(dst_);
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;
+ if(complete_redraw) {
+ 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());
+ }
+ } else {
+ // off screen animations only invalidate their own hex,
no propagation,
+ // but we stil need this to play sounds
+ overlaped_hex_.insert(src_);
+ }
+
+ }
+ if(complete_redraw) {
+ if( need_update()) {
+ disp->invalidate(overlaped_hex_);
+ invalidated_ = true;
+ return true;
+ } else {
+ invalidated_ =
disp->propagate_invalidation(overlaped_hex_);
+ return invalidated_;
+ }
} 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()) {
+ if(need_minimal_update()) {
disp->invalidate(overlaped_hex_);
invalidated_ = true;
return true;
@@ -852,6 +890,9 @@
}
}
}
+
+
+
void unit_animation::particule::redraw(const frame_parameters& value,const
map_location &src, const map_location &dst, const bool primary)
{
const unit_frame& current_frame= get_current_frame();
Modified: trunk/src/unit_animation.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_animation.hpp?rev=35659&r1=35658&r2=35659&view=diff
==============================================================================
--- trunk/src/unit_animation.hpp (original)
+++ trunk/src/unit_animation.hpp Sat May 16 19:50:19 2009
@@ -47,6 +47,7 @@
void add_frame(int duration, const unit_frame& value,bool
force_change =false){ unit_anim_.add_frame(duration,value,force_change) ; };
bool need_update() const;
+ bool need_minimal_update() const;
bool animation_finished() const;
bool animation_finished_potential() const;
void update_last_draw_time();
@@ -84,6 +85,7 @@
explicit particule(const config& cfg,const std::string
frame_string ="frame");
virtual ~particule();
bool need_update() const;
+ bool need_minimal_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);
std::set<map_location> get_overlaped_hex(const
frame_parameters& value,const map_location &src, const map_location &dst, const
bool primary = false);
@@ -117,6 +119,7 @@
map_location dst_;
// optimisation
bool invalidated_;
+ bool play_offscreen_;
std::set<map_location> overlaped_hex_;
};
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits