| 79 | } |
| 80 | |
| 81 | BitmapRef Sprite::Refresh(Rect& rect) { |
| 82 | if (zoom_x_effect == 1.0 && zoom_y_effect == 1.0 && angle_effect == 0.0 && waver_effect_depth == 0) { |
| 83 | // Prevent effect sprite creation when not in the viewport |
| 84 | // TODO: Out of bounds math adjustments for zoom, angle and waver |
| 85 | // but even without this will catch most of the cases |
| 86 | if (Rect(x - ox, y - oy, GetWidth(), GetHeight()).IsOutOfBounds(Rect(0, 0, Player::screen_width, Player::screen_height))) { |
| 87 | return BitmapRef(); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | rect.Adjust(bitmap->GetWidth(), bitmap->GetHeight()); |
| 92 | |
| 93 | bool no_tone = tone_effect == Tone(); |
| 94 | bool no_flash = flash_effect.alpha == 0; |
| 95 | bool no_flip = !flipx_effect && !flipy_effect; |
| 96 | bool no_effects = no_tone && no_flash && no_flip; |
| 97 | bool effects_changed = tone_effect != current_tone || |
| 98 | flash_effect != current_flash || |
| 99 | flipx_effect != current_flip_x || |
| 100 | flipy_effect != current_flip_y; |
| 101 | bool effects_rect_changed = rect != bitmap_effects_src_rect; |
| 102 | |
| 103 | if (no_effects || effects_changed || effects_rect_changed || bitmap_changed) { |
| 104 | bitmap_effects.reset(); |
| 105 | } |
| 106 | |
| 107 | if (no_effects) { |
| 108 | return bitmap; |
| 109 | } else if (bitmap_effects) { |
| 110 | return bitmap_effects; |
| 111 | } else { |
| 112 | current_tone = tone_effect; |
| 113 | current_flash = flash_effect; |
| 114 | current_flip_x = flipx_effect; |
| 115 | current_flip_y = flipy_effect; |
| 116 | |
| 117 | bitmap_effects = Cache::SpriteEffect(bitmap, rect, flipx_effect, flipy_effect, current_tone, current_flash); |
| 118 | bitmap_effects_src_rect = rect; |
| 119 | |
| 120 | return bitmap_effects; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | void Sprite::SetBitmap(BitmapRef const& nbitmap) { |
| 125 | bitmap = nbitmap; |
no test coverage detected