mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 06:15:04 +00:00
(svn r18846) -Codechange: Merge DrawTileSeq into DrawCommonTileSeq.
This commit is contained in:
parent
830af8ee77
commit
24e0945bc4
@ -19,7 +19,6 @@
|
||||
#include "newgrf_commons.h"
|
||||
#include "station_map.h"
|
||||
#include "tree_map.h"
|
||||
#include "viewport_func.h"
|
||||
#include "core/mem_func.hpp"
|
||||
|
||||
/** Constructor of generic class
|
||||
@ -323,43 +322,3 @@ uint32 GetNearbyTileInformation(TileIndex tile)
|
||||
byte terrain_type = GetTerrainType(tile) << 2 | (tile_type == MP_WATER ? 1 : 0) << 1;
|
||||
return tile_type << 24 | z << 16 | terrain_type << 8 | tileh;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a building 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 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;
|
||||
|
||||
/* 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 (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
|
||||
image += stage;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,6 @@
|
||||
#define NEWGRF_COMMONS_H
|
||||
|
||||
#include "tile_cmd.h"
|
||||
#include "transparency.h"
|
||||
#include "sprite.h"
|
||||
|
||||
/**
|
||||
* Maps an entity id stored on the map to a GRF file.
|
||||
@ -107,6 +105,4 @@ uint32 GetTerrainType(TileIndex tile);
|
||||
TileIndex GetNearbyTile(byte parameter, TileIndex tile);
|
||||
uint32 GetNearbyTileInformation(TileIndex tile);
|
||||
|
||||
void DrawTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, byte stage, SpriteID default_palette);
|
||||
|
||||
#endif /* NEWGRF_COMMONS_H */
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "company_base.h"
|
||||
#include "town.h"
|
||||
#include "core/random_func.hpp"
|
||||
#include "sprite.h"
|
||||
|
||||
static BuildingCounts<uint32> _building_counts;
|
||||
static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
|
||||
@ -421,7 +422,7 @@ static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *grou
|
||||
DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
|
||||
}
|
||||
|
||||
DrawTileSeq(ti, dts, TO_HOUSES, stage, palette);
|
||||
DrawNewGRFTileSeq(ti, dts, TO_HOUSES, stage, palette);
|
||||
}
|
||||
|
||||
void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "command_func.h"
|
||||
#include "animated_tile_func.h"
|
||||
#include "water.h"
|
||||
#include "sprite.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
@ -185,7 +186,7 @@ static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGro
|
||||
}
|
||||
}
|
||||
|
||||
DrawTileSeq(ti, dts, TO_INDUSTRIES, stage, GENERAL_SPRITE_COLOUR(rnd_colour));
|
||||
DrawNewGRFTileSeq(ti, dts, TO_INDUSTRIES, stage, GENERAL_SPRITE_COLOUR(rnd_colour));
|
||||
}
|
||||
|
||||
uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
|
||||
|
@ -909,7 +909,7 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID
|
||||
|
||||
DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
|
||||
|
||||
DrawCommonTileSeqInGUI(x, y, sprites, rti->total_offset, relocation, palette);
|
||||
DrawRailTileSeqInGUI(x, y, sprites, rti->total_offset, relocation, palette);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "company_base.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "table/sprites.h"
|
||||
#include "table/railtypes.h"
|
||||
#include "table/track_land.h"
|
||||
|
||||
@ -1981,7 +1982,7 @@ static void DrawTile_Track(TileInfo *ti)
|
||||
if (HasCatenaryDrawn(GetRailType(ti->tile))) DrawCatenary(ti);
|
||||
|
||||
/* No NewGRF depots, so no relocation */
|
||||
DrawCommonTileSeq(ti, dts, TO_BUILDINGS, rti->total_offset, 0, _drawtile_track_palette);
|
||||
DrawRailTileSeq(ti, dts, TO_BUILDINGS, rti->total_offset, 0, _drawtile_track_palette);
|
||||
}
|
||||
DrawBridgeMiddle(ti);
|
||||
}
|
||||
@ -1999,7 +2000,7 @@ void DrawTrainDepotSprite(int x, int y, int dir, RailType railtype)
|
||||
SpriteID palette = COMPANY_SPRITE_COLOUR(_local_company);
|
||||
|
||||
DrawSprite(image, PAL_NONE, x, y);
|
||||
DrawCommonTileSeqInGUI(x, y, dts, offset, 0, palette);
|
||||
DrawRailTileSeqInGUI(x, y, dts, offset, 0, palette);
|
||||
}
|
||||
|
||||
static uint GetSlopeZ_Track(TileIndex tile, uint x, uint y)
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "company_base.h"
|
||||
#include "core/random_func.hpp"
|
||||
|
||||
#include "table/sprites.h"
|
||||
#include "table/strings.h"
|
||||
|
||||
/**
|
||||
@ -1223,7 +1222,7 @@ static void DrawTile_Road(TileInfo *ti)
|
||||
}
|
||||
|
||||
DrawGroundSprite(dts->ground.sprite, PAL_NONE);
|
||||
DrawCommonTileSeq(ti, dts, TO_BUILDINGS, 0, 0, palette);
|
||||
DrawOrigTileSeq(ti, dts, TO_BUILDINGS, palette);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1239,7 +1238,7 @@ void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
|
||||
y += 17;
|
||||
|
||||
DrawSprite(dts->ground.sprite, PAL_NONE, x, y);
|
||||
DrawCommonTileSeqInGUI(x, y, dts, 0, 0, palette);
|
||||
DrawOrigTileSeqInGUI(x, y, dts, palette);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,13 +26,17 @@
|
||||
* @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)
|
||||
* @param child_offset_is_unsigned Whether child sprite offsets are interpreted signed or unsigned
|
||||
*/
|
||||
void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette)
|
||||
void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette, bool child_offset_is_unsigned)
|
||||
{
|
||||
const DrawTileSeqStruct *dtss;
|
||||
foreach_draw_tile_seq(dtss, dts->seq) {
|
||||
SpriteID image = dtss->image.sprite;
|
||||
|
||||
/* TTD sprite 0 means no sprite */
|
||||
if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) continue;
|
||||
|
||||
/* 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;
|
||||
|
||||
@ -49,8 +53,9 @@ void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, Transpare
|
||||
!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));
|
||||
int offs_x = child_offset_is_unsigned ? (uint8)dtss->delta_x : dtss->delta_x;
|
||||
int offs_y = child_offset_is_unsigned ? (uint8)dtss->delta_y : dtss->delta_y;
|
||||
AddChildSpriteScreen(image, pal, offs_x, offs_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -63,14 +68,19 @@ void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, Transpare
|
||||
* @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)
|
||||
* @param child_offset_is_unsigned Whether child sprite offsets are interpreted signed or unsigned
|
||||
*/
|
||||
void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, 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 child_offset_is_unsigned)
|
||||
{
|
||||
const DrawTileSeqStruct *dtss;
|
||||
Point child_offset = {0, 0};
|
||||
|
||||
foreach_draw_tile_seq(dtss, dts->seq) {
|
||||
SpriteID image = dtss->image.sprite;
|
||||
|
||||
/* TTD sprite 0 means no sprite */
|
||||
if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) continue;
|
||||
|
||||
image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset);
|
||||
|
||||
SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette);
|
||||
@ -83,8 +93,9 @@ void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig
|
||||
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);
|
||||
int offs_x = child_offset_is_unsigned ? (uint8)dtss->delta_x : dtss->delta_x;
|
||||
int offs_y = child_offset_is_unsigned ? (uint8)dtss->delta_y : dtss->delta_y;
|
||||
DrawSprite(image, pal, x + child_offset.x + offs_x, y + child_offset.y + offs_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
49
src/sprite.h
49
src/sprite.h
@ -59,10 +59,53 @@ 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);
|
||||
void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette, bool child_offset_is_unsigned);
|
||||
void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette, bool child_offset_is_unsigned);
|
||||
|
||||
bool SkipSpriteData(byte type, uint16 num);
|
||||
/**
|
||||
* Draw tile sprite sequence on tile with railroad specifics.
|
||||
* @param total_offset Spriteoffset from normal rail to current railtype.
|
||||
* @param newgrf_offset Startsprite of the Action1 to use.
|
||||
*/
|
||||
static inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, SpriteID default_palette)
|
||||
{
|
||||
DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw tile sprite sequence in GUI with railroad specifics.
|
||||
* @param total_offset Spriteoffset from normal rail to current railtype.
|
||||
* @param newgrf_offset Startsprite of the Action1 to use.
|
||||
*/
|
||||
static inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, SpriteID default_palette)
|
||||
{
|
||||
DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw TTD sprite sequence on tile.
|
||||
*/
|
||||
static inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, SpriteID default_palette)
|
||||
{
|
||||
DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw TTD sprite sequence in GUI.
|
||||
*/
|
||||
static inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, SpriteID default_palette)
|
||||
{
|
||||
DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw NewGRF industrytile or house sprite layout
|
||||
* @param stage Sprite inside the Action1 spritesets to use, i.e. construction stage.
|
||||
*/
|
||||
static inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, SpriteID default_palette)
|
||||
{
|
||||
DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOUR to a palette entry of a sprite layout entry
|
||||
|
@ -44,6 +44,7 @@ void GfxInitSpriteMem();
|
||||
void IncreaseSpriteLRU();
|
||||
|
||||
bool LoadNextSprite(int load_index, byte file_index, uint file_sprite_id);
|
||||
bool SkipSpriteData(byte type, uint16 num);
|
||||
void DupSprite(SpriteID old_spr, SpriteID new_spr);
|
||||
|
||||
#endif /* SPRITECACHE_H */
|
||||
|
@ -2455,7 +2455,7 @@ static void DrawTile_Station(TileInfo *ti)
|
||||
total_offset = 0;
|
||||
}
|
||||
|
||||
DrawCommonTileSeq(ti, t, TO_BUILDINGS, total_offset, relocation, palette);
|
||||
DrawRailTileSeq(ti, t, TO_BUILDINGS, total_offset, relocation, palette);
|
||||
}
|
||||
|
||||
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image)
|
||||
@ -2477,7 +2477,7 @@ void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, Ro
|
||||
}
|
||||
|
||||
/* Default waypoint has no railtype specific sprites */
|
||||
DrawCommonTileSeqInGUI(x, y, t, st == STATION_WAYPOINT ? 0 : total_offset, 0, pal);
|
||||
DrawRailTileSeqInGUI(x, y, t, st == STATION_WAYPOINT ? 0 : total_offset, 0, pal);
|
||||
}
|
||||
|
||||
static uint GetSlopeZ_Station(TileIndex tile, uint x, uint y)
|
||||
|
Loading…
Reference in New Issue
Block a user