Changeset - r21173:fe6d7c0f0218
[Not reviewed]
master
0 2 0
rubidium - 10 years ago 2014-01-13 18:17:17
rubidium@openttd.org
(svn r26259) -Codechange: add and maintain some general flags about sprites to prevent unneeded execution of expensive code (MJP)
2 files changed with 31 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/blitter/32bpp_sse2.cpp
Show inline comments
 
@@ -54,25 +54,33 @@ Sprite *Blitter_32bppSSE_Base::Encode(co
 
	dst_sprite->height = sprite->height;
 
	dst_sprite->width  = sprite->width;
 
	dst_sprite->x_offs = sprite->x_offs;
 
	dst_sprite->y_offs = sprite->y_offs;
 
	memcpy(dst_sprite->data, &sd, sizeof(SpriteData));
 

	
 
	/* Copy colours. */
 
	/* Copy colours and determine flags. */
 
	bool has_remap = false;
 
	bool has_anim = false;
 
	bool has_translucency = false;
 
	for (ZoomLevel z = zoom_min; z <= zoom_max; z++) {
 
		const SpriteLoader::Sprite *src_sprite = &sprite[z];
 
		const SpriteLoader::CommonPixel *src = (const SpriteLoader::CommonPixel *) src_sprite->data;
 
		Colour *dst_rgba_line = (Colour *) &dst_sprite->data[sizeof(SpriteData) + sd.infos[z].sprite_offset];
 
		MapValue *dst_mv = (MapValue *) &dst_sprite->data[sizeof(SpriteData) + sd.infos[z].mv_offset];
 
		for (uint y = src_sprite->height; y != 0; y--) {
 
			Colour *dst_rgba = dst_rgba_line + META_LENGTH;
 
			for (uint x = src_sprite->width; x != 0; x--) {
 
				if (src->a != 0) {
 
					dst_rgba->a = src->a;
 
					if (src->a != 0 && src->a != 255) has_translucency = true;
 
					dst_mv->m = src->m;
 
					if (src->m != 0) {
 
						/* Do some accounting for flags. */
 
						has_remap = true;
 
						if (src->m >= PALETTE_ANIM_START) has_anim = true;
 

	
 
						/* Get brightest value (or default brightness if it's a black pixel). */
 
						const uint8 rgb_max = max(src->r, max(src->g, src->b));
 
						dst_mv->v = (rgb_max == 0) ? Blitter_32bppBase::DEFAULT_BRIGHTNESS : rgb_max;
 

	
 
						/* Pre-convert the mapping channel to a RGB value. */
 
						const Colour colour = AdjustBrightneSSE(Blitter_32bppBase::LookupColourInPalette(src->m), dst_mv->v);
 
@@ -116,10 +124,17 @@ Sprite *Blitter_32bppSSE_Base::Encode(co
 
				dst_rgba--;
 
			}
 
			(*nb_right).data = nb_pix_transp;
 
		}
 
	}
 

	
 
	/* Store sprite flags. */
 
	sd.flags = SF_NONE;
 
	if (has_translucency) sd.flags |= SF_TRANSLUCENT;
 
	if (!has_remap) sd.flags |= SF_NO_REMAP;
 
	if (!has_anim) sd.flags |= SF_NO_ANIM;
 
	memcpy(dst_sprite->data, &sd, sizeof(SpriteData));
 

	
 
	return dst_sprite;
 
}
 

	
 
#endif /* WITH_SSE */
src/blitter/32bpp_sse2.hpp
Show inline comments
 
@@ -46,27 +46,42 @@ public:
 
	enum BlockType {
 
		BT_EVEN, ///< An even number of pixels in the width; no need for a special case for the last pixel.
 
		BT_ODD,  ///< An odd number of pixels in the width; special case for the last pixel.
 
		BT_NONE, ///< No specialisation for either case.
 
	};
 

	
 
	/** Helper for using specialised functions designed to prevent whenever it's possible things like:
 
	 *  - IO (reading video buffer),
 
	 *  - calculations (alpha blending),
 
	 *  - heavy branching (remap lookups and animation buffer handling).
 
	 */
 
	enum SpriteFlags {
 
		SF_NONE        = 0,
 
		SF_TRANSLUCENT = 1 << 1, ///< The sprite has at least 1 translucent pixel.
 
		SF_NO_REMAP    = 1 << 2, ///< The sprite has no remappable colour pixel.
 
		SF_NO_ANIM     = 1 << 3, ///< The sprite has no palette animated pixel.
 
	};
 

	
 
	/** Data stored about a (single) sprite. */
 
	struct SpriteInfo {
 
		uint32 sprite_offset;    ///< The offset to the sprite data.
 
		uint32 mv_offset;        ///< The offset to the map value data.
 
		uint16 sprite_line_size; ///< The size of a single line (pitch).
 
		uint16 sprite_width;     ///< The width of the sprite.
 
	};
 
	struct SpriteData {
 
		SpriteFlags flags;
 
		SpriteInfo infos[ZOOM_LVL_COUNT];
 
		byte data[]; ///< Data, all zoomlevels.
 
	};
 

	
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
 
};
 

	
 
DECLARE_ENUM_AS_BIT_SET(Blitter_32bppSSE_Base::SpriteFlags);
 

	
 
/** The SSE2 32 bpp blitter (without palette animation). */
 
class Blitter_32bppSSE2 : public Blitter_32bppSimple, public Blitter_32bppSSE_Base {
 
public:
 
	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 
	template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last>
 
	void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
0 comments (0 inline, 0 general)