Changeset - r14275:c027409d8afb
[Not reviewed]
master
0 8 1
frosch - 14 years ago 2010-01-16 22:25:44
frosch@openttd.org
(svn r18837) -Codechange: Rename DrawStationTileSeq() to DrawCommonTileSeq() and move it to separate file.
9 files changed with 113 insertions and 89 deletions:
0 comments (0 inline, 0 general)
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -681,12 +681,16 @@
 
			</File>
 
			<File
 
				RelativePath=".\..\src\sound.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\sprite.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\spritecache.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\station.cpp"
 
				>
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -678,12 +678,16 @@
 
			</File>
 
			<File
 
				RelativePath=".\..\src\sound.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\sprite.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\spritecache.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\station.cpp"
 
				>
source.list
Show inline comments
 
@@ -55,12 +55,13 @@ screenshot.cpp
 
	sdl.cpp
 
#end
 
settings.cpp
 
signal.cpp
 
signs.cpp
 
sound.cpp
 
sprite.cpp
 
spritecache.cpp
 
station.cpp
 
string.cpp
 
strings.cpp
 
subsidy.cpp
 
texteff.cpp
src/newgrf_commons.h
Show inline comments
 
@@ -15,14 +15,12 @@
 
#define NEWGRF_COMMONS_H
 

	
 
#include "tile_cmd.h"
 
#include "transparency.h"
 
#include "sprite.h"
 

	
 
#include "table/sprites.h"
 

	
 
/**
 
 * Maps an entity id stored on the map to a GRF file.
 
 * Entities are objects used ingame (houses, industries, industry tiles) for
 
 * which we need to correlate the ids from the grf files with the ones in the
 
 * the savegames themselves.
 
 * An array of EntityIDMapping structs is saved with the savegame so
 
@@ -106,48 +104,9 @@ extern IndustryOverrideManager _industry
 
extern IndustryTileOverrideManager _industile_mngr;
 

	
 
uint32 GetTerrainType(TileIndex tile);
 
TileIndex GetNearbyTile(byte parameter, TileIndex tile);
 
uint32 GetNearbyTileInformation(TileIndex tile);
 

	
 
/**
 
 * Applies PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOUR to a palette entry of a sprite layout entry
 
 * @Note for ground sprites use #GroundSpritePaletteTransform
 
 * @Note Not useable for OTTD internal spritelayouts from table/xxx_land.h as PALETTE_MODIFIER_TRANSPARENT is only set
 
 *       when to use the default palette.
 
 *
 
 * @param image The sprite to draw
 
 * @param pal The palette from the sprite layout
 
 * @param default_pal The default recolour sprite to use (typically company colour resp. random industry/house colour)
 
 * @return The palette to use
 
 */
 
static inline SpriteID SpriteLayoutPaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal)
 
{
 
	if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOUR)) {
 
		return (pal != 0 ? pal : default_pal);
 
	} else {
 
		return PAL_NONE;
 
	}
 
}
 

	
 
/**
 
 * Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite
 
 * @Note Not useable for OTTD internal spritelayouts from table/xxx_land.h as PALETTE_MODIFIER_TRANSPARENT is only set
 
 *       when to use the default palette.
 
 *
 
 * @param image The sprite to draw
 
 * @param pal The palette from the sprite layout
 
 * @param default_pal The default recolour sprite to use (typically company colour resp. random industry/house colour)
 
 * @return The palette to use
 
 */
 
static inline SpriteID GroundSpritePaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal)
 
{
 
	if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
 
		return (pal != 0 ? pal : default_pal);
 
	} else {
 
		return PAL_NONE;
 
	}
 
}
 

	
 
void DrawTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, byte stage, SpriteID default_palette);
 

	
 
#endif /* NEWGRF_COMMONS_H */
src/rail_cmd.cpp
Show inline comments
 
@@ -16,13 +16,12 @@
 
#include "command_func.h"
 
#include "engine_base.h"
 
#include "depot_base.h"
 
#include "pathfinder/yapf/yapf_cache.h"
 
#include "newgrf_engine.h"
 
#include "landscape_type.h"
 
#include "newgrf_commons.h"
 
#include "train.h"
 
#include "variables.h"
 
#include "autoslope.h"
 
#include "water.h"
 
#include "tunnelbridge_map.h"
 
#include "window_func.h"
 
@@ -1979,13 +1978,13 @@ static void DrawTile_Track(TileInfo *ti)
 
			}
 
		}
 

	
 
		if (HasCatenaryDrawn(GetRailType(ti->tile))) DrawCatenary(ti);
 

	
 
		/* No NewGRF depots, so no relocation */
 
		DrawStationTileSeq(ti, dts, TO_BUILDINGS, rti->total_offset, 0, _drawtile_track_palette);
 
		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)
src/sprite.cpp
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file sprite.cpp Handling of sprites */
 

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

	
 
#include "table/sprites.h"
 

	
 
/**
 
 * Draws a tile sprite sequence.
 
 * @param ti The tile to draw on
 
 * @param dts Sprite and subsprites to draw
 
 * @param to The transparancy bit that toggles drawing of these sprites
 
 * @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 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)) {
 
			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,
 
				dtss->size_z, ti->z + dtss->delta_z,
 
				!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to)
 
			);
 
		} 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));
 
		}
 
	}
 
}
src/sprite.h
Show inline comments
 
@@ -10,12 +10,15 @@
 
/** @file sprite.h Base for drawing complex sprites. */
 

	
 
#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
 
@@ -62,9 +65,50 @@ struct DrawBuildingsTileStruct {
 
	byte draw_proc;  // this allows to specify a special drawing procedure.
 
};
 

	
 
/** 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);
 

	
 
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
 
 * @Note Not useable for OTTD internal spritelayouts from table/xxx_land.h as PALETTE_MODIFIER_TRANSPARENT is only set
 
 *       when to use the default palette.
 
 *
 
 * @param image The sprite to draw
 
 * @param pal The palette from the sprite layout
 
 * @param default_pal The default recolour sprite to use (typically company colour resp. random industry/house colour)
 
 * @return The palette to use
 
 */
 
static inline SpriteID SpriteLayoutPaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal)
 
{
 
	if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOUR)) {
 
		return (pal != 0 ? pal : default_pal);
 
	} else {
 
		return PAL_NONE;
 
	}
 
}
 

	
 
/**
 
 * Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite
 
 * @Note Not useable for OTTD internal spritelayouts from table/xxx_land.h as PALETTE_MODIFIER_TRANSPARENT is only set
 
 *       when to use the default palette.
 
 *
 
 * @param image The sprite to draw
 
 * @param pal The palette from the sprite layout
 
 * @param default_pal The default recolour sprite to use (typically company colour resp. random industry/house colour)
 
 * @return The palette to use
 
 */
 
static inline SpriteID GroundSpritePaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal)
 
{
 
	if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
 
		return (pal != 0 ? pal : default_pal);
 
	} else {
 
		return PAL_NONE;
 
	}
 
}
 

	
 
#endif /* SPRITE_H */
src/station_cmd.cpp
Show inline comments
 
@@ -20,13 +20,12 @@
 
#include "news_func.h"
 
#include "train.h"
 
#include "roadveh.h"
 
#include "industry.h"
 
#include "newgrf_cargo.h"
 
#include "newgrf_station.h"
 
#include "newgrf_commons.h"
 
#include "pathfinder/yapf/yapf_cache.h"
 
#include "road_internal.h" /* For drawing catenary/checking road removal */
 
#include "variables.h"
 
#include "autoslope.h"
 
#include "water.h"
 
#include "station_gui.h"
 
@@ -2453,54 +2452,13 @@ static void DrawTile_Station(TileInfo *t
 

	
 
	if (IsRailWaypoint(ti->tile)) {
 
		/* Don't offset the waypoint graphics; they're always the same. */
 
		total_offset = 0;
 
	}
 

	
 
	DrawStationTileSeq(ti, t, TO_BUILDINGS, total_offset, relocation, palette);
 
}
 

	
 
/**
 
 * Draws a station, waypoint or depot including all subsprites on a tile.
 
 * @param ti The tile to draw on
 
 * @param dts Sprite and subsprites to draw
 
 * @param to The transparancy bit that toggles drawing of these sprites
 
 * @param total_offset Sprite-Offset between the current railtype and normal rail
 
 * @param relocation Sprite-Offset for NewGRF defined stations
 
 * @param default_palette The default recolour sprite to use (typically company colour)
 
 */
 
void DrawStationTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 relocation, 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 (relocation == 0 || HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
 
			image += total_offset;
 
		} else {
 
			image += relocation;
 
		}
 

	
 
		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 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));
 
		}
 
	}
 
	DrawCommonTileSeq(ti, t, TO_BUILDINGS, total_offset, relocation, palette);
 
}
 

	
 
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image)
 
{
 
	int32 total_offset = 0;
 
	SpriteID pal = COMPANY_SPRITE_COLOUR(_local_company);
src/station_func.h
Show inline comments
 
@@ -14,13 +14,12 @@
 

	
 
#include "station_type.h"
 
#include "sprite.h"
 
#include "rail_type.h"
 
#include "road_type.h"
 
#include "cargo_type.h"
 
#include "transparency.h"
 
#include "company_type.h"
 

	
 
void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint radius);
 

	
 
void FindStationsAroundTiles(const TileArea &location, StationList *stations);
 

	
 
@@ -32,14 +31,12 @@ CargoArray GetAcceptanceAroundTiles(Tile
 

	
 
void UpdateStationAcceptance(Station *st, bool show_msg);
 

	
 
const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx);
 
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image);
 

	
 
void DrawStationTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 relocation, SpriteID default_palette);
 

	
 
bool HasStationInUse(StationID station, CompanyID company);
 

	
 
RoadStop *GetRoadStopByTile(TileIndex tile, RoadStopType type);
 
uint GetNumRoadStops(const Station *st, RoadStopType type);
 

	
 
void DeleteOilRig(TileIndex t);
0 comments (0 inline, 0 general)