Author: boucman
Date: Sun Apr 12 08:01:26 2009
New Revision: 34753
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34753&view=rev
Log:
add the in_hex optimization to 1.6, I thought I had already commited, sorry
about that
Modified:
branches/1.6/changelog
branches/1.6/src/display.cpp
branches/1.6/src/display.hpp
branches/1.6/src/image.cpp
branches/1.6/src/image.hpp
branches/1.6/src/sdl_utils.cpp
branches/1.6/src/sdl_utils.hpp
branches/1.6/src/unit_frame.cpp
branches/1.6/src/unit_frame.hpp
Modified: branches/1.6/changelog
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/changelog?rev=34753&r1=34752&r2=34753&view=diff
==============================================================================
--- branches/1.6/changelog (original)
+++ branches/1.6/changelog Sun Apr 12 08:01:26 2009
@@ -6,6 +6,9 @@
are not incapacitated (for example, it now ignores stoned units )
* Editor2:
* New feature: exporting of selection coordinates to system clipboard
+ * Engine Changes
+ * better detection of images fiting in a hex, should heavily reduce CPU
+ usage
* Graphics:
* New portrait for Orc Grunt, Dwarf Fighter (alternative), Goblin Spearman,
Ogre/Young Ogre, Trapper, Ranger
Modified: branches/1.6/src/display.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/display.cpp?rev=34753&r1=34752&r2=34753&view=diff
==============================================================================
--- branches/1.6/src/display.cpp (original)
+++ branches/1.6/src/display.cpp Sun Apr 12 08:01:26 2009
@@ -2327,6 +2327,14 @@
return false;
}
+bool display::hex_need_update(const map_location& loc) const
+{
+ if(invalidateAll_)
+ return true;
+
+ return invalidated_.find(loc) != invalidated_.end();
+}
+
void display::invalidate_animations() {
if (preferences::animate_map()) {
rect_of_hexes hexes = get_visible_hexes();
Modified: branches/1.6/src/display.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/display.hpp?rev=34753&r1=34752&r2=34753&view=diff
==============================================================================
--- branches/1.6/src/display.hpp (original)
+++ branches/1.6/src/display.hpp Sun Apr 12 08:01:26 2009
@@ -275,6 +275,9 @@
/** check if an hexes under the rectangle is invalidated */
bool rectangle_need_update(const SDL_Rect& rect) const;
+
+ /** check if an hex is invalidated */
+ bool hex_need_update(const map_location& loc) const;
/**
* Function to invalidate animated terrains which may have changed.
Modified: branches/1.6/src/image.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/image.cpp?rev=34753&r1=34752&r2=34753&view=diff
==============================================================================
--- branches/1.6/src/image.cpp (original)
+++ branches/1.6/src/image.cpp Sun Apr 12 08:01:26 2009
@@ -909,6 +909,19 @@
return res;
}
+bool is_in_hex(const locator& i_locator)
+{
+ const surface mask(get_image(game_config::terrain_mask_image,
UNSCALED));
+ const surface image(get_image(i_locator, UNSCALED));
+
+ bool res = in_mask_surface(image, mask);
+ //std::cout << "in_hex : " << i_locator.get_filename()
+ // << " " << (res ? "yes" : "no") << "\n";
+
+ return res;
+}
+
+
surface reverse_image(const surface& surf)
{
if(surf == NULL) {
Modified: branches/1.6/src/image.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/image.hpp?rev=34753&r1=34752&r2=34753&view=diff
==============================================================================
--- branches/1.6/src/image.hpp (original)
+++ branches/1.6/src/image.hpp Sun Apr 12 08:01:26 2009
@@ -257,6 +257,10 @@
///SDL_FreeSurface()
surface get_image(const locator& i_locator, TYPE type=UNSCALED);
+ ///function to check if an image fit into an hex
+ ///return false if the image has not the standard size.
+ bool is_in_hex(const locator& i_locator);
+
///function to reverse an image. The image MUST have originally been
returned from
///an image:: function. Returned images have the same semantics as for
get_image()
///and must be freed using SDL_FreeSurface()
Modified: branches/1.6/src/sdl_utils.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/sdl_utils.cpp?rev=34753&r1=34752&r2=34753&view=diff
==============================================================================
--- branches/1.6/src/sdl_utils.cpp (original)
+++ branches/1.6/src/sdl_utils.cpp Sun Apr 12 08:01:26 2009
@@ -992,6 +992,50 @@
//return create_optimized_surface(nsurf);
}
+bool in_mask_surface(surface const &surf, surface const &mask)
+{
+ if(surf == NULL || mask == NULL) {
+ return false;
+ }
+
+ if (surf->w != surf->w || surf->h != mask->h ) {
+ // not same size, consider it doesn't fit
+ return false;
+ }
+
+ surface nsurf = make_neutral_surface(surf);
+ surface nmask(make_neutral_surface(mask));
+
+ if(nsurf == NULL || nmask == NULL) {
+ std::cerr << "could not make neutral surface...\n";
+ return false;
+ }
+
+ {
+ surface_lock lock(nsurf);
+ surface_lock mlock(nmask);
+
+ Uint32* mbeg = mlock.pixels();
+ Uint32* mend = mbeg + nmask->w*nmask->h;
+ Uint32* beg = lock.pixels();
+ // no need for 'end', because both surfaces have same size
+
+ while(mbeg != mend) {
+ Uint8 malpha = (*mbeg) >> 24;
+ if(malpha == 0) {
+ Uint8 alpha = (*beg) >> 24;
+ if (alpha)
+ return false;
+ }
+ ++mbeg;
+ ++beg;
+ }
+ }
+
+ return true;
+}
+
+
surface blur_surface(surface const &surf, int depth, bool optimize)
{
if(surf == NULL) {
Modified: branches/1.6/src/sdl_utils.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/sdl_utils.hpp?rev=34753&r1=34752&r2=34753&view=diff
==============================================================================
--- branches/1.6/src/sdl_utils.hpp (original)
+++ branches/1.6/src/sdl_utils.hpp Sun Apr 12 08:01:26 2009
@@ -232,6 +232,9 @@
/** Applies a mask on a surface. */
surface mask_surface(surface const &surf, surface const &mask);
+/** Check if a surface fit into a mask */
+bool in_mask_surface(surface const &surf, surface const &mask);
+
/** Cross-fades a surface. */
surface blur_surface(surface const &surf, int depth = 1, bool optimize=true);
Modified: branches/1.6/src/unit_frame.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/unit_frame.cpp?rev=34753&r1=34752&r2=34753&view=diff
==============================================================================
--- branches/1.6/src/unit_frame.cpp (original)
+++ branches/1.6/src/unit_frame.cpp Sun Apr 12 08:01:26 2009
@@ -174,7 +174,9 @@
submerge_(""),
x_(""),
y_(""),
- drawing_layer_("")
+ drawing_layer_(""),
+ in_hex_(false),
+ diagonal_in_hex_(false)
{
image(image::locator(cfg[frame_string+"image"]),cfg[frame_string+"image_mod"]);
image_diagonal(image::locator(cfg[frame_string+"image_diagonal"]),cfg[frame_string+"image_mod"]);
@@ -230,18 +232,22 @@
result.x = x_.get_current_element(current_time);
result.y = y_.get_current_element(current_time);
result.drawing_layer =
drawing_layer_.get_current_element(current_time,display::LAYER_UNIT_DEFAULT-display::LAYER_UNIT_FIRST);
+ result.in_hex = in_hex_;
+ result.diagonal_in_hex = diagonal_in_hex_;
return result;
}
frame_builder & frame_builder::image(const image::locator image ,const
std::string & image_mod)
{
image_ = image;
image_mod_ = image_mod;
+ in_hex_ = is_in_hex(image);
return *this;
}
frame_builder & frame_builder::image_diagonal(const image::locator
image_diagonal,const std::string& image_mod)
{
image_diagonal_ = image_diagonal;
image_mod_ = image_mod;
+ diagonal_in_hex_ = is_in_hex(image_diagonal);
return *this;
}
frame_builder & frame_builder::sound(const std::string& sound)
@@ -465,13 +471,16 @@
const frame_parameters current_data =
merge_parameters(frame_time,animation_val,engine_val,primary);
double tmp_offset = current_data.offset;
int d2 = game_display::get_singleton()->hex_size() / 2;
+ bool image_fit_hex = false;
image::locator image_loc;
if(direction != map_location::NORTH && direction !=
map_location::SOUTH) {
image_loc = current_data.image_diagonal;
+ image_fit_hex = current_data.diagonal_in_hex;
}
if(image_loc.is_void() || image_loc.get_filename() == "") { // invalid
diag image, or not diagonal
image_loc = current_data.image;
+ image_fit_hex = current_data.in_hex;
}
surface image;
@@ -490,14 +499,22 @@
if (image != NULL) {
const int x = static_cast<int>(tmp_offset * xdst +
(1.0-tmp_offset) * xsrc)+current_data.x+d2-(image->w/2);
const int y = static_cast<int>(tmp_offset * ydst +
(1.0-tmp_offset) * ysrc)+current_data.y+d2-(image->h/2);
+ const SDL_Rect r = {x,y,image->w,image->h};
+ // check if the unit fit in a hex
+ bool in_hex = image_fit_hex && r.x==xsrc && r.y==ysrc
+ && r.w==disp->hex_size() &&
r.h==disp->hex_size();
+ // check if our underlying hexes are invalidated
+ bool rect_need_update = in_hex ?
+ disp->hex_need_update(src) :
disp->rectangle_need_update(r);
// if we need to update ourselve because we changed, invalidate
our hexes
// and return whether or not our hexs was invalidated
- const SDL_Rect r = {x,y,image->w,image->h};
- if(force || need_update() || disp->rectangle_need_update(r)){
+ if(force || need_update() || rect_need_update) {
// invalidate ouself to be called at redraw time
result |= disp->invalidate(src);
- // invalidate all hex we plan to overwrite
- result |= disp->invalidate_visible_locations_in_rect(r);
+ if(in_hex == false) {
+ // invalidate all hexes we plan to overwrite
+ result |=
disp->invalidate_visible_locations_in_rect(r);
+ }
}
} else {
// we have no "redraw surface" but we still need to invalidate
our own hex
@@ -529,14 +546,18 @@
/** engine provides a default image to use for the unit when none is
available */
result.image = current_val.image.is_void() ||
current_val.image.get_filename() == ""?animation_val.image:current_val.image;
+ result.in_hex = current_val.image.is_void() ||
current_val.image.get_filename() == ""?animation_val.in_hex:current_val.in_hex;
if(primary && ( result.image.is_void() ||
result.image.get_filename().empty())) {
result.image = engine_val.image;
+ result.in_hex = engine_val.in_hex;
}
/** engine provides a default image to use for the unit when none is
available */
result.image_diagonal = current_val.image_diagonal.is_void() ||
current_val.image_diagonal.get_filename() ==
""?animation_val.image_diagonal:current_val.image_diagonal;
+ result.diagonal_in_hex = current_val.image_diagonal.is_void() ||
current_val.image_diagonal.get_filename() ==
""?animation_val.diagonal_in_hex:current_val.diagonal_in_hex;
if(primary && ( result.image_diagonal.is_void() ||
result.image_diagonal.get_filename().empty())) {
result.image_diagonal = engine_val.image_diagonal;
+ result.diagonal_in_hex = engine_val.diagonal_in_hex;
}
/** engine provides a string for "stoned" and "team color"
modifications */
@@ -603,7 +624,9 @@
#ifdef LOW_MEM
if(primary) {
result.image= engine_val.image;
+ result.in_hex = engine_val.in_hex;
result.image_diagonal= engine_val.image;
+ result.diagonal_in_hex = engine_val.diagonal_in_hex;
}
#endif
return result;
Modified: branches/1.6/src/unit_frame.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/unit_frame.hpp?rev=34753&r1=34752&r2=34753&view=diff
==============================================================================
--- branches/1.6/src/unit_frame.hpp (original)
+++ branches/1.6/src/unit_frame.hpp Sun Apr 12 08:01:26 2009
@@ -85,7 +85,9 @@
submerge(0.0),
x(0),
y(0),
- drawing_layer(display::LAYER_UNIT_DEFAULT-display::LAYER_UNIT_FIRST)
+ drawing_layer(display::LAYER_UNIT_DEFAULT-display::LAYER_UNIT_FIRST),
+ in_hex(false),
+ diagonal_in_hex(false)
{};
image::locator image;
@@ -107,6 +109,8 @@
int x;
int y;
int drawing_layer;
+ bool in_hex;
+ bool diagonal_in_hex;
} ;
/**
* keep most parameters in a separate class to simplify handling of large
@@ -134,7 +138,9 @@
submerge_(""),
x_(""),
y_(""),
-
drawing_layer_(lexical_cast<std::string>(display::LAYER_UNIT_DEFAULT-display::LAYER_UNIT_FIRST))
+
drawing_layer_(lexical_cast<std::string>(display::LAYER_UNIT_DEFAULT-display::LAYER_UNIT_FIRST)),
+ in_hex_(false),
+ diagonal_in_hex_(false)
{};
frame_builder(const config& cfg,const std::string &frame_string
= "");
/** allow easy chained modifications will raised assert if used
after initialization */
@@ -178,7 +184,8 @@
progressive_int x_;
progressive_int y_;
progressive_int drawing_layer_;
-
+ bool in_hex_;
+ bool diagonal_in_hex_;
};
/** Describe a unit's animation sequence. */
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits