diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index d1a8fbf7ce..f8f1d79f3d 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -683,6 +683,10 @@ RelativePath=".\..\src\sound.cpp" > + + diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj index f9e234b2b1..8c9c4962e5 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -680,6 +680,10 @@ RelativePath=".\..\src\sound.cpp" > + + diff --git a/source.list b/source.list index 9baf3ad134..d8a9603b61 100644 --- a/source.list +++ b/source.list @@ -58,6 +58,7 @@ settings.cpp signal.cpp signs.cpp sound.cpp +sprite.cpp spritecache.cpp station.cpp string.cpp diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h index 6ace3d0dac..92546d7e8b 100644 --- a/src/newgrf_commons.h +++ b/src/newgrf_commons.h @@ -18,8 +18,6 @@ #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 @@ -109,45 +107,6 @@ 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 */ diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index f9d433b2ea..f1e74e9995 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -19,7 +19,6 @@ #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" @@ -1982,7 +1981,7 @@ 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); } diff --git a/src/sprite.cpp b/src/sprite.cpp new file mode 100644 index 0000000000..1edaa29095 --- /dev/null +++ b/src/sprite.cpp @@ -0,0 +1,58 @@ +/* $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 . + */ + +/** @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)); + } + } +} diff --git a/src/sprite.h b/src/sprite.h index 20aa5b5d37..c0d37d9ce0 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -13,6 +13,9 @@ #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])) @@ -65,6 +68,47 @@ 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); + 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 */ diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 721bf9d2ff..e3e0411957 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -23,7 +23,6 @@ #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" @@ -2456,48 +2455,7 @@ static void DrawTile_Station(TileInfo *ti) 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) diff --git a/src/station_func.h b/src/station_func.h index 99aa47e5fd..2a2d8314db 100644 --- a/src/station_func.h +++ b/src/station_func.h @@ -17,7 +17,6 @@ #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); @@ -35,8 +34,6 @@ 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);