Changeset - r14280:9e2593121da6
[Not reviewed]
master
0 9 0
frosch - 14 years ago 2010-01-17 01:01:56
frosch@openttd.org
(svn r18842) -Codechange: Rename SPRITE_MODIFIER_USE_OFFSET to SPRITE_MODIFIER_CUSTOM_SPRITE, invert its meaning, and also use it for industry/house layouts instead of IS_CUSTOM_SPRITE().
9 files changed with 20 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -1130,49 +1130,51 @@ static ChangeInfoResult StationChangeInf
 
				statspec->renderdata = CallocT<DrawTileSprites>(statspec->tiles);
 
				statspec->copied_renderdata = false;
 

	
 
				for (uint t = 0; t < statspec->tiles; t++) {
 
					DrawTileSprites *dts = &statspec->renderdata[t];
 
					uint seq_count = 0;
 

	
 
					dts->seq = NULL;
 
					dts->ground.sprite = grf_load_word(&buf);
 
					dts->ground.pal = grf_load_word(&buf);
 
					if (dts->ground.sprite == 0) continue;
 
					if (HasBit(dts->ground.pal, 15)) {
 
						/* Use sprite from Action 1 */
 
						ClrBit(dts->ground.pal, 15);
 
						SetBit(dts->ground.sprite, SPRITE_MODIFIER_USE_OFFSET);
 
						SetBit(dts->ground.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE);
 
					}
 

	
 
					MapSpriteMappingRecolour(&dts->ground);
 

	
 
					while (buf < *bufp + len) {
 
						/* no relative bounding box support */
 
						dts->seq = ReallocT(const_cast<DrawTileSeqStruct *>(dts->seq), ++seq_count);
 
						DrawTileSeqStruct *dtss = const_cast<DrawTileSeqStruct *>(&dts->seq[seq_count - 1]);
 

	
 
						dtss->delta_x = grf_load_byte(&buf);
 
						if ((byte) dtss->delta_x == 0x80) break;
 
						dtss->delta_y = grf_load_byte(&buf);
 
						dtss->delta_z = grf_load_byte(&buf);
 
						dtss->size_x = grf_load_byte(&buf);
 
						dtss->size_y = grf_load_byte(&buf);
 
						dtss->size_z = grf_load_byte(&buf);
 
						dtss->image.sprite = grf_load_word(&buf);
 
						dtss->image.pal = grf_load_word(&buf);
 

	
 
						/* Remap flags as ours collide */
 
						if (HasBit(dtss->image.pal, 15)) {
 
							ClrBit(dtss->image.pal, 15);
 
							SetBit(dtss->image.sprite, SPRITE_MODIFIER_USE_OFFSET);
 
						} else {
 
							/* Use sprite from Action 1 (yes, this is inverse to above) */
 
							SetBit(dtss->image.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE);
 
						}
 

	
 
						MapSpriteMappingRecolour(&dtss->image);
 
					}
 
				}
 
				break;
 

	
 
			case 0x0A: { // Copy sprite layout
 
				byte srcid = grf_load_byte(&buf);
 
				const StationSpec *srcstatspec = _cur_grffile->stations[srcid];
 

	
 
				statspec->tiles = srcstatspec->tiles;
 
@@ -2928,24 +2930,25 @@ static void NewSpriteGroup(byte *buf, si
 
					if (HasBit(group->dts->ground.pal, 15)) {
 
						/* Bit 31 set means this is a custom sprite, so rewrite it to the
 
						 * last spriteset defined. */
 
						uint spriteset = GB(group->dts->ground.sprite, 0, 14);
 
						if (num_spriteset_ents == 0 || spriteset >= num_spritesets) {
 
							grfmsg(1, "NewSpriteGroup: Spritelayout uses undefined custom spriteset %d", spriteset);
 
							group->dts->ground.sprite = SPR_IMG_QUERY;
 
							group->dts->ground.pal = PAL_NONE;
 
						} else {
 
							SpriteID sprite = _cur_grffile->spriteset_start + spriteset * num_spriteset_ents;
 
							SB(group->dts->ground.sprite, 0, SPRITE_WIDTH, sprite);
 
							ClrBit(group->dts->ground.pal, 15);
 
							SetBit(group->dts->ground.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE);
 
						}
 
					}
 

	
 
					group->dts->seq = CallocT<DrawTileSeqStruct>(num_building_sprites + 1);
 

	
 
					for (i = 0; i < num_building_sprites; i++) {
 
						DrawTileSeqStruct *seq = const_cast<DrawTileSeqStruct*>(&group->dts->seq[i]);
 

	
 
						seq->image.sprite = grf_load_word(&buf);
 
						seq->image.pal    = grf_load_word(&buf);
 
						seq->delta_x = grf_load_byte(&buf);
 
						seq->delta_y = grf_load_byte(&buf);
 
@@ -2955,24 +2958,25 @@ static void NewSpriteGroup(byte *buf, si
 
						if (HasBit(seq->image.pal, 15)) {
 
							/* Bit 31 set means this is a custom sprite, so rewrite it to the
 
							 * last spriteset defined. */
 
							uint spriteset = GB(seq->image.sprite, 0, 14);
 
							if (num_spriteset_ents == 0 || spriteset >= num_spritesets) {
 
								grfmsg(1, "NewSpriteGroup: Spritelayout uses undefined custom spriteset %d", spriteset);
 
								seq->image.sprite = SPR_IMG_QUERY;
 
								seq->image.pal = PAL_NONE;
 
							} else {
 
								SpriteID sprite = _cur_grffile->spriteset_start + spriteset * num_spriteset_ents;
 
								SB(seq->image.sprite, 0, SPRITE_WIDTH, sprite);
 
								ClrBit(seq->image.pal, 15);
 
								SetBit(seq->image.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE);
 
							}
 
						}
 

	
 
						if (type > 0) {
 
							seq->delta_z = grf_load_byte(&buf);
 
							if ((byte)seq->delta_z == 0x80) continue;
 
						}
 

	
 
						seq->size_x = grf_load_byte(&buf);
 
						seq->size_y = grf_load_byte(&buf);
 
						seq->size_z = grf_load_byte(&buf);
 
					}
src/newgrf_commons.cpp
Show inline comments
 
@@ -330,32 +330,33 @@ uint32 GetNearbyTileInformation(TileInde
 
 * @param dts Sprite and subsprites to draw
 
 * @param to The transparancy bit that toggles drawing of these sprites
 
 * @param stage The construction stage (0-3)
 
 * @param default_palette The default recolour sprite to use (typically company colour resp. random industry/house colour)
 
 */
 
void DrawTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, byte stage, SpriteID default_palette)
 
{
 
	const DrawTileSeqStruct *dtss;
 
	foreach_draw_tile_seq(dtss, dts->seq) {
 
		if (GB(dtss->image.sprite, 0, SPRITE_WIDTH) == 0) continue;
 

	
 
		SpriteID image = dtss->image.sprite;
 
		SpriteID pal   = dtss->image.pal;
 

	
 
		/* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */
 
		if (IsInvisibilitySet(to) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return;
 

	
 
		if (IS_CUSTOM_SPRITE(image)) image += stage;
 
		if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
 
			image += stage;
 
		}
 

	
 
		pal = SpriteLayoutPaletteTransform(image, pal, default_palette);
 
		SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette);
 

	
 
		if ((byte)dtss->delta_z != 0x80) {
 
			AddSortableSpriteToDraw(
 
				image, pal,
 
				ti->x + dtss->delta_x, ti->y + dtss->delta_y,
 
				dtss->size_x, dtss->size_y,
 
				dtss->size_z, ti->z + dtss->delta_z,
 
				!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to)
 
			);
 
		} else {
 
			/* For industries and houses delta_x and delta_y are unsigned */
 
			AddChildSpriteScreen(image, pal, (byte)dtss->delta_x, (byte)dtss->delta_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to));
src/newgrf_house.cpp
Show inline comments
 
@@ -406,25 +406,25 @@ static void DrawTileLayout(const TileInf
 
	SpriteID palette = hs->random_colour[TileHash2Bit(ti->x, ti->y)] + PALETTE_RECOLOUR_START;
 
	if (HasBit(hs->callback_mask, CBM_HOUSE_COLOUR)) {
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, Town::GetByTile(ti->tile), ti->tile);
 
		if (callback != CALLBACK_FAILED) {
 
			/* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
 
			palette = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
 
		}
 
	}
 

	
 
	SpriteID image = dts->ground.sprite;
 
	SpriteID pal   = dts->ground.pal;
 

	
 
	if (IS_CUSTOM_SPRITE(image)) image += stage;
 
	if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) image += stage;
 

	
 
	if (GB(image, 0, SPRITE_WIDTH) != 0) {
 
		DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
 
	}
 

	
 
	DrawTileSeq(ti, dts, TO_HOUSES, stage, palette);
 
}
 

	
 
void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
 
{
 
	const HouseSpec *hs = HouseSpec::Get(house_id);
 
	const SpriteGroup *group;
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -164,25 +164,25 @@ static void NewIndustryTileResolver(Reso
 

	
 
	const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
 
	res->grffile         = (its != NULL ? its->grf_prop.grffile : NULL);
 
}
 

	
 
static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte rnd_colour, byte stage, IndustryGfx gfx)
 
{
 
	const DrawTileSprites *dts = group->dts;
 

	
 
	SpriteID image = dts->ground.sprite;
 
	SpriteID pal   = dts->ground.pal;
 

	
 
	if (IS_CUSTOM_SPRITE(image)) image += stage;
 
	if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) image += stage;
 

	
 
	if (GB(image, 0, SPRITE_WIDTH) != 0) {
 
		/* If the ground sprite is the default flat water sprite, draw also canal/river borders
 
		 * Do not do this if the tile's WaterClass is 'land'. */
 
		if (image == SPR_FLAT_WATER_TILE && IsIndustryTileOnWater(ti->tile)) {
 
			DrawWaterClassGround(ti);
 
		} else {
 
			DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, GENERAL_SPRITE_COLOUR(rnd_colour)));
 
		}
 
	}
 

	
 
	DrawTileSeq(ti, dts, TO_INDUSTRIES, stage, GENERAL_SPRITE_COLOUR(rnd_colour));
src/newgrf_station.cpp
Show inline comments
 
@@ -891,25 +891,25 @@ bool DrawStationTile(int x, int y, RailT
 
		uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0x2110000, 0, statspec, NULL, INVALID_TILE);
 
		if (callback != CALLBACK_FAILED) tile = callback;
 
	}
 

	
 
	if (statspec->renderdata == NULL) {
 
		sprites = GetStationTileLayout(STATION_RAIL, tile + axis);
 
	} else {
 
		sprites = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : (uint)axis];
 
	}
 

	
 
	SpriteID image = sprites->ground.sprite;
 
	SpriteID pal = sprites->ground.pal;
 
	if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
 
	if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
 
		image += GetCustomStationGroundRelocation(statspec, NULL, INVALID_TILE);
 
		image += rti->custom_ground_offset;
 
	} else {
 
		image += rti->total_offset;
 
	}
 

	
 
	DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
 

	
 
	DrawCommonTileSeqInGUI(x, y, sprites, rti->total_offset, relocation, palette);
 

	
 
	return true;
 
}
src/sprite.cpp
Show inline comments
 
@@ -27,25 +27,25 @@
 
 * @param newgrf_offset Sprite-Offset for NewGRF defined sprites
 
 * @param default_palette The default recolour sprite to use (typically company colour)
 
 */
 
void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette)
 
{
 
	const DrawTileSeqStruct *dtss;
 
	foreach_draw_tile_seq(dtss, dts->seq) {
 
		SpriteID image = dtss->image.sprite;
 

	
 
		/* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */
 
		if (IsInvisibilitySet(to) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return;
 

	
 
		if (newgrf_offset == 0 || HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
 
		if (newgrf_offset == 0 || !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
 
			image += orig_offset;
 
		} else {
 
			image += newgrf_offset;
 
		}
 

	
 
		SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette);
 

	
 
		if ((byte)dtss->delta_z != 0x80) {
 
			AddSortableSpriteToDraw(
 
				image, pal,
 
				ti->x + dtss->delta_x, ti->y + dtss->delta_y,
 
				dtss->size_x, dtss->size_y,
 
@@ -66,25 +66,25 @@ void DrawCommonTileSeq(const TileInfo *t
 
 * @param dts Sprite and subsprites to draw
 
 * @param orig_offset Sprite-Offset for original sprites
 
 * @param newgrf_offset Sprite-Offset for NewGRF defined sprites
 
 * @param default_palette The default recolour sprite to use (typically company colour)
 
 */
 
void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette)
 
{
 
	const DrawTileSeqStruct *dtss;
 
	Point child_offset = {0, 0};
 

	
 
	foreach_draw_tile_seq(dtss, dts->seq) {
 
		SpriteID image = dtss->image.sprite;
 
		if (newgrf_offset == 0 || HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
 
		if (newgrf_offset == 0 || !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
 
			image += orig_offset;
 
		} else {
 
			image += newgrf_offset;
 
		}
 

	
 
		SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette);
 

	
 
		if ((byte)dtss->delta_z != 0x80) {
 
			Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
 
			DrawSprite(image, pal, x + pt.x, y + pt.y);
 

	
 
			const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
src/sprite.h
Show inline comments
 
@@ -11,33 +11,24 @@
 

	
 
#ifndef SPRITE_H
 
#define SPRITE_H
 

	
 
#include "gfx_type.h"
 
#include "transparency.h"
 

	
 
#include "table/sprites.h"
 

	
 
#define GENERAL_SPRITE_COLOUR(colour) ((colour) + PALETTE_RECOLOUR_START)
 
#define COMPANY_SPRITE_COLOUR(owner) (GENERAL_SPRITE_COLOUR(_company_colours[owner]))
 

	
 
/**
 
 * Whether a sprite comes from the original graphics files or a new grf file
 
 * (either supplied by OpenTTD or supplied by the user).
 
 *
 
 * @param sprite The sprite to check
 
 * @return True if it is a new sprite, or false if it is original.
 
 */
 
#define IS_CUSTOM_SPRITE(sprite) ((sprite) >= SPR_SIGNALS_BASE)
 

	
 
/* The following describes bunch of sprites to be drawn together in a single 3D
 
 * bounding box. Used especially for various multi-sprite buildings (like
 
 * depots or stations): */
 

	
 
/** A tile child sprite and palette to draw for stations etc, with 3D bounding box */
 
struct DrawTileSeqStruct {
 
	int8 delta_x; ///< \c 0x80 is sequence terminator
 
	int8 delta_y;
 
	int8 delta_z;
 
	byte size_x;
 
	byte size_y;
 
	byte size_z;
src/station_cmd.cpp
Show inline comments
 
@@ -2418,25 +2418,25 @@ static void DrawTile_Station(TileInfo *t
 
			assert(IsDock(ti->tile));
 
			TileIndex water_tile = ti->tile + TileOffsByDiagDir(GetDockDirection(ti->tile));
 
			WaterClass wc = GetWaterClass(water_tile);
 
			if (wc == WATER_CLASS_SEA) {
 
				DrawShoreTile(ti->tileh);
 
			} else {
 
				DrawClearLandTile(ti, 3);
 
			}
 
		}
 
	} else {
 
		SpriteID image = t->ground.sprite;
 
		SpriteID pal   = t->ground.pal;
 
		if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
 
		if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
 
			image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
 
			image += custom_ground_offset;
 
		} else {
 
			image += total_offset;
 
		}
 
		DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
 

	
 
		/* PBS debugging, draw reserved tracks darker */
 
		if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasStationRail(ti->tile) && HasStationReservation(ti->tile)) {
 
			const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
 
			DrawGroundSprite(GetRailStationAxis(ti->tile) == AXIS_X ? rti->base_sprites.single_x : rti->base_sprites.single_y, PALETTE_CRASH);
 
		}
src/table/sprites.h
Show inline comments
 
@@ -1410,41 +1410,42 @@ enum AnimCursors {
 
 * Bitmask setup. For the graphics system, 32 bits are used to define
 
 * the sprite to be displayed. This variable contains various information:<p>
 
 * <ul><li> SPRITE_WIDTH is the number of bits used for the actual sprite to be displayed.
 
 * This always starts at bit 0.</li>
 
 * <li> TRANSPARENT_BIT is the bit number which toggles sprite transparency</li>
 
 * <li> RECOLOUR_BIT toggles the recolouring system</li>
 
 * <li> PALETTE_SPRITE_WIDTH and PALETTE_SPRITE_START determine the position and number of
 
 * bits used for the recolouring process. For transparency, it must be 0x322.</li></ul>
 
 */
 
enum SpriteSetup {
 
	TRANSPARENT_BIT = 31,       ///< toggles transparency in the sprite
 
	RECOLOUR_BIT = 30,          ///< toggles recolouring in the sprite
 
	OFFSET_BIT = 29,
 
	CUSTOM_BIT = 29,
 
	OPAQUE_BIT = 28,
 

	
 
	PALETTE_WIDTH = 24,         ///< number of bits of the sprite containing the recolour palette
 
	SPRITE_WIDTH = 24,          ///< number of bits for the sprite number
 
};
 

	
 
/**
 
 * these masks change the colours of the palette for a sprite.
 
 * Apart from this bit, a sprite number is needed to define
 
 * the palette used for recolouring. This palette is stored
 
 * in the bits marked by PALETTE_SPRITE_MASK.
 
 * @note Do not modify this enum. Alter SpriteSetup instead
 
 * @see SpriteSetup
 
 */
 
enum Modifiers {
 
	SPRITE_MODIFIER_USE_OFFSET    = OFFSET_BIT,
 
	/** Set when a sprite originates from an Action 1 */
 
	SPRITE_MODIFIER_CUSTOM_SPRITE = CUSTOM_BIT,
 
	/** Set when a sprite must not ever be displayed transparently */
 
	SPRITE_MODIFIER_OPAQUE        = OPAQUE_BIT,
 
	/** when a sprite is to be displayed transparently, this bit needs to be set. */
 
	PALETTE_MODIFIER_TRANSPARENT  = TRANSPARENT_BIT,
 
	/** this bit is set when a recolouring process is in action */
 
	PALETTE_MODIFIER_COLOUR       = RECOLOUR_BIT,
 
};
 

	
 
/** Masks needed for sprite operations.
 
 * @note Do not modify this enum. Alter SpriteSetup instead
 
 * @see SpriteSetup */
 
enum SpriteMasks {
0 comments (0 inline, 0 general)