From: Ricardo Cruz Date: Tue, 19 Oct 2004 17:48:23 +0000 (+0000) Subject: Mirror actions now cache the horizontal flipped Surfaces, rather than flipping them... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=60e60d04f92c75700aaa9d9c9da4316176467dcf;p=supertux.git Mirror actions now cache the horizontal flipped Surfaces, rather than flipping them during blitting. It wastes more memory, but the problem is that SDL fontend got considered slower, especially when a vertical flipping was done at the same time (ie. Bad Guy falling facing right). SVN-Revision: 2035 --- diff --git a/lib/special/sprite.cpp b/lib/special/sprite.cpp index 82639166e..b7df947bd 100644 --- a/lib/special/sprite.cpp +++ b/lib/special/sprite.cpp @@ -56,7 +56,6 @@ Sprite::~Sprite() for(std::vector::iterator i_sur = i_act->second->surfaces.begin(); i_sur != i_act->second->surfaces.end(); ++i_sur) { - if(!i_act->second->mirror) delete *i_sur; } delete i_act->second; @@ -86,26 +85,30 @@ Sprite::parse_action(LispReader& lispreader) for(std::vector::iterator i = action->surfaces.begin(); i < action->surfaces.end(); i++) { - (*i)->apply_mask(Color(mask_color)); + (*i)->apply_filter(MASK_FILTER, Color(mask_color)); } } - action->mirror = false; std::string mirror_action; lispreader.read_string("mirror-action", mirror_action); if(!mirror_action.empty()) { - action->mirror = true; Action* act_tmp = get_action(mirror_action); if(act_tmp == NULL) std::cerr << "Warning: Could not mirror action. Action not found\n" "Mirror actions must be defined after the real one!\n"; else - action->surfaces = act_tmp->surfaces; + { + for(int i = 0; i < act_tmp->surfaces.size(); i++) + { + Surface* surface = new Surface(sdl_surface_from_sdl_surface( + act_tmp->surfaces[i]->impl->get_sdl_surface(), true), true); + surface->apply_filter(HORIZONTAL_FLIP_FILTER); + action->surfaces.push_back(surface); + } + } } - - // Load images - if(!action->mirror) + else // Load images { std::vector images; if(!lispreader.read_string_vector("images", images)) @@ -270,8 +273,7 @@ Sprite::draw(DrawingContext& context, const Vector& pos, int layer, << "/" << get_action_name() << std::endl; else context.draw_surface(action->surfaces[(int)frame], - pos - Vector(action->x_offset, action->y_offset), layer + action->z_order, - action->mirror ? drawing_effect | HORIZONTAL_FLIP : drawing_effect); + pos - Vector(action->x_offset, action->y_offset), layer + action->z_order, drawing_effect); } void @@ -286,8 +288,7 @@ Sprite::draw_part(DrawingContext& context, const Vector& source, const Vector& s << "/" << get_action_name() << std::endl; else context.draw_surface_part(action->surfaces[(int)frame], source, size, - pos - Vector(action->x_offset, action->y_offset), layer + action->z_order, - action->mirror ? drawing_effect | HORIZONTAL_FLIP : drawing_effect); + pos - Vector(action->x_offset, action->y_offset), layer + action->z_order, drawing_effect); } int diff --git a/lib/special/sprite.h b/lib/special/sprite.h index 15ee35b99..8239f49a0 100644 --- a/lib/special/sprite.h +++ b/lib/special/sprite.h @@ -50,7 +50,7 @@ namespace SuperTux /** Mirror is used to avoid duplicating left and right side sprites */ - bool mirror; +// bool mirror; std::vector surfaces; };