Changeset - r14277:5e0779a82f30
[Not reviewed]
master
0 5 0
frosch - 14 years ago 2010-01-16 22:44:03
frosch@openttd.org
(svn r18839) -Codechange: Detriplicate drawing of spritelayouts in the GUI.
5 files changed with 52 insertions and 51 deletions:
0 comments (0 inline, 0 general)
src/newgrf_station.cpp
Show inline comments
 
@@ -8,13 +8,12 @@
 
 */
 

	
 
/** @file newgrf_station.cpp Functions for dealing with station classes and custom stations. */
 

	
 
#include "stdafx.h"
 
#include "variables.h"
 
#include "landscape.h"
 
#include "debug.h"
 
#include "station_base.h"
 
#include "waypoint_base.h"
 
#include "roadstop_base.h"
 
#include "newgrf_cargo.h"
 
#include "newgrf_commons.h"
 
@@ -25,13 +24,12 @@
 
#include "newgrf_town.h"
 
#include "date_func.h"
 
#include "company_func.h"
 
#include "animated_tile_func.h"
 
#include "functions.h"
 
#include "tunnelbridge_map.h"
 
#include "spritecache.h"
 
#include "newgrf.h"
 
#include "core/random_func.hpp"
 

	
 
#include "table/strings.h"
 

	
 
static StationClass _station_classes[STAT_CLASS_MAX];
 
@@ -877,70 +875,44 @@ void DeallocateSpecFromStation(BaseStati
 
 * @return True if the tile was drawn (allows for fallback to default graphic)
 
 */
 
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
 
{
 
	const StationSpec *statspec;
 
	const DrawTileSprites *sprites;
 
	const DrawTileSeqStruct *seq;
 
	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
 
	SpriteID relocation;
 
	SpriteID image;
 
	SpriteID palette = COMPANY_SPRITE_COLOUR(_local_company);
 
	uint tile = 2;
 

	
 
	statspec = GetCustomStationSpec(sclass, station);
 
	if (statspec == NULL) return false;
 

	
 
	relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE);
 
	uint relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE);
 

	
 
	if (HasBit(statspec->callback_mask, CBM_STATION_SPRITE_LAYOUT)) {
 
		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];
 
	}
 

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

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

	
 
	Point child_offset = {0, 0};
 

	
 
	foreach_draw_tile_seq(seq, sprites->seq) {
 
		image = seq->image.sprite;
 
		if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
 
			image += rti->total_offset;
 
		} else {
 
			image += relocation;
 
		}
 

	
 
		pal = SpriteLayoutPaletteTransform(image, seq->image.pal, palette);
 

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

	
 
			const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
 
			child_offset.x = pt.x + spr->x_offs;
 
			child_offset.y = pt.y + spr->y_offs;
 
		} else {
 
			/* For stations and original spritelayouts delta_x and delta_y are signed */
 
			DrawSprite(image, pal, x + child_offset.x + seq->delta_x, y + child_offset.y + seq->delta_y);
 
		}
 
	}
 
	DrawCommonTileSeqInGUI(x, y, sprites, rti->total_offset, relocation, palette);
 

	
 
	return true;
 
}
 

	
 

	
 
const StationSpec *GetStationSpec(TileIndex t)
src/rail_cmd.cpp
Show inline comments
 
@@ -1983,34 +1983,26 @@ static void DrawTile_Track(TileInfo *ti)
 
		/* No NewGRF depots, so no relocation */
 
		DrawCommonTileSeq(ti, dts, TO_BUILDINGS, rti->total_offset, 0, _drawtile_track_palette);
 
	}
 
	DrawBridgeMiddle(ti);
 
}
 

	
 

	
 
static void DrawTileSequence(int x, int y, SpriteID ground, const DrawTileSeqStruct *dtss, uint32 offset)
 
{
 
	SpriteID palette = COMPANY_SPRITE_COLOUR(_local_company);
 

	
 
	DrawSprite(ground, PAL_NONE, x, y);
 
	for (; dtss->image.sprite != 0; dtss++) {
 
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
 
		SpriteID image = dtss->image.sprite + offset;
 

	
 
		DrawSprite(image, HasBit(image, PALETTE_MODIFIER_COLOUR) ? palette : PAL_NONE, x + pt.x, y + pt.y);
 
	}
 
}
 

	
 
void DrawTrainDepotSprite(int x, int y, int dir, RailType railtype)
 
{
 
	const DrawTileSprites *dts = &_depot_gfx_table[dir];
 
	SpriteID image = dts->ground.sprite;
 
	uint32 offset = GetRailTypeInfo(railtype)->total_offset;
 

	
 
	x += 33;
 
	y += 17;
 

	
 
	if (image != SPR_FLAT_GRASS_TILE) image += offset;
 
	DrawTileSequence(x + 33, y + 17, image, dts->seq, offset);
 
	SpriteID palette = COMPANY_SPRITE_COLOUR(_local_company);
 

	
 
	DrawSprite(image, PAL_NONE, x, y);
 
	DrawCommonTileSeqInGUI(x, y, dts, offset, 0, palette);
 
}
 

	
 
static uint GetSlopeZ_Track(TileIndex tile, uint x, uint y)
 
{
 
	uint z;
 
	Slope tileh = GetTileSlope(tile, &z);
src/sprite.cpp
Show inline comments
 
@@ -10,12 +10,14 @@
 
/** @file sprite.cpp Handling of sprites */
 

	
 
#include "stdafx.h"
 
#include "sprite.h"
 
#include "tile_cmd.h"
 
#include "viewport_func.h"
 
#include "landscape.h"
 
#include "spritecache.h"
 

	
 
#include "table/sprites.h"
 

	
 
/**
 
 * Draws a tile sprite sequence.
 
 * @param ti The tile to draw on
 
@@ -53,6 +55,44 @@ void DrawCommonTileSeq(const TileInfo *t
 
		} else {
 
			/* For stations and original spritelayouts delta_x and delta_y are signed */
 
			AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to));
 
		}
 
	}
 
}
 

	
 
/**
 
 * Draws a tile sprite sequence in the GUI
 
 * @param x X position to draw to
 
 * @param y Y position to draw to
 
 * @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)) {
 
			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);
 
			child_offset.x = pt.x + spr->x_offs;
 
			child_offset.y = pt.y + spr->y_offs;
 
		} else {
 
			/* For stations and original spritelayouts delta_x and delta_y are signed */
 
			DrawSprite(image, pal, x + child_offset.x + dtss->delta_x, y + child_offset.y + dtss->delta_y);
 
		}
 
	}
 
}
src/sprite.h
Show inline comments
 
@@ -66,12 +66,13 @@ struct DrawBuildingsTileStruct {
 
};
 

	
 
/** Iterate through all DrawTileSeqStructs in DrawTileSprites. */
 
#define foreach_draw_tile_seq(idx, list) for (idx = list; ((byte) idx->delta_x) != 0x80; idx++)
 

	
 
void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette);
 
void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette);
 

	
 
bool SkipSpriteData(byte type, uint16 num);
 

	
 
/**
 
 * Applies PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOUR to a palette entry of a sprite layout entry
 
 * @Note for ground sprites use #GroundSpritePaletteTransform
src/station_cmd.cpp
Show inline comments
 
@@ -2473,17 +2473,13 @@ void StationPickerDrawSprite(int x, int 
 
	DrawSprite(img + total_offset, HasBit(img, PALETTE_MODIFIER_COLOUR) ? pal : PAL_NONE, x, y);
 

	
 
	if (roadtype == ROADTYPE_TRAM) {
 
		DrawSprite(SPR_TRAMWAY_TRAM + (t->ground.sprite == SPR_ROAD_PAVED_STRAIGHT_X ? 1 : 0), PAL_NONE, x, y);
 
	}
 

	
 
	const DrawTileSeqStruct *dtss;
 
	foreach_draw_tile_seq(dtss, t->seq) {
 
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
 
		DrawSprite(dtss->image.sprite + total_offset, pal, x + pt.x, y + pt.y);
 
	}
 
	DrawCommonTileSeqInGUI(x, y, t, total_offset, 0, pal);
 
}
 

	
 
static uint GetSlopeZ_Station(TileIndex tile, uint x, uint y)
 
{
 
	return GetTileMaxZ(tile);
 
}
0 comments (0 inline, 0 general)