Changeset - r27106:2d95beb51290
[Not reviewed]
cmake/scripts/SquirrelExport.cmake
Show inline comments
 
@@ -329,19 +329,19 @@ foreach(LINE IN LISTS SOURCE_LINES)
 

	
 
            reset_reader()
 
            continue()
 
        endif()
 

	
 
        string(APPEND SQUIRREL_EXPORT "\n")
 
        string(APPEND SQUIRREL_EXPORT "\ntemplate <> const char *GetClassName<${CLS}, ST_${APIUC}>() { return \"${API_CLS}\"; }")
 
        string(APPEND SQUIRREL_EXPORT "\ntemplate <> const char *GetClassName<${CLS}, ScriptType::${APIUC}>() { return \"${API_CLS}\"; }")
 
        string(APPEND SQUIRREL_EXPORT "\n")
 

	
 
        # Then do the registration functions of the class.
 
        string(APPEND SQUIRREL_EXPORT "\nvoid SQ${API_CLS}_Register(Squirrel *engine)")
 
        string(APPEND SQUIRREL_EXPORT "\n{")
 
        string(APPEND SQUIRREL_EXPORT "\n	DefSQClass<${CLS}, ST_${APIUC}> SQ${API_CLS}(\"${API_CLS}\");")
 
        string(APPEND SQUIRREL_EXPORT "\n	DefSQClass<${CLS}, ScriptType::${APIUC}> SQ${API_CLS}(\"${API_CLS}\");")
 
        if("${SUPER_CLS}" STREQUAL "Text" OR "${SUPER_CLS}" STREQUAL "ScriptObject" OR "${SUPER_CLS}" STREQUAL "AIAbstractiveList::Valuator")
 
            string(APPEND SQUIRREL_EXPORT "\n	SQ${API_CLS}.PreRegister(engine);")
 
        else()
 
            string(APPEND SQUIRREL_EXPORT "\n	SQ${API_CLS}.PreRegister(engine, \"${API_SUPER_CLS}\");")
 
        endif()
 
        if(NOT "${SUPER_CLS}" MATCHES "^ScriptEvent")
src/ai/ai_info.cpp
Show inline comments
 
@@ -29,18 +29,18 @@ static bool CheckAPIVersion(const char *
 
	return versions.find(api_version) != versions.end();
 
}
 

	
 
#if defined(_WIN32)
 
#undef GetClassName
 
#endif /* _WIN32 */
 
template <> const char *GetClassName<AIInfo, ST_AI>() { return "AIInfo"; }
 
template <> const char *GetClassName<AIInfo, ScriptType::AI>() { return "AIInfo"; }
 

	
 
/* static */ void AIInfo::RegisterAPI(Squirrel *engine)
 
{
 
	/* Create the AIInfo class, and add the RegisterAI function */
 
	DefSQClass<AIInfo, ST_AI> SQAIInfo("AIInfo");
 
	DefSQClass<AIInfo, ScriptType::AI> SQAIInfo("AIInfo");
 
	SQAIInfo.PreRegister(engine);
 
	SQAIInfo.AddConstructor<void (AIInfo::*)(), 1>(engine, "x");
 
	SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddSetting, "AddSetting");
 
	SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddLabels, "AddLabels");
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_NONE, "CONFIG_NONE");
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_RANDOM, "CONFIG_RANDOM");
src/blitter/32bpp_optimized.cpp
Show inline comments
 
@@ -290,13 +290,13 @@ template <bool Tpal_to_rgb> Sprite *Blit
 
	/* lengths of streams */
 
	uint32 lengths[ZOOM_LVL_COUNT][2];
 

	
 
	ZoomLevel zoom_min;
 
	ZoomLevel zoom_max;
 

	
 
	if (sprite->type == ST_FONT) {
 
	if (sprite->type == SpriteType::Font) {
 
		zoom_min = ZOOM_LVL_NORMAL;
 
		zoom_max = ZOOM_LVL_NORMAL;
 
	} else {
 
		zoom_min = _settings_client.gui.zoom_min;
 
		zoom_max = _settings_client.gui.zoom_max;
 
		if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_MAX;
src/blitter/32bpp_sse2.cpp
Show inline comments
 
@@ -25,13 +25,13 @@ Sprite *Blitter_32bppSSE_Base::Encode(co
 
	/* First uint32 of a line = the number of transparent pixels from the left.
 
	 * Second uint32 of a line = the number of transparent pixels from the right.
 
	 * Then all RGBA then all MV.
 
	 */
 
	ZoomLevel zoom_min = ZOOM_LVL_NORMAL;
 
	ZoomLevel zoom_max = ZOOM_LVL_NORMAL;
 
	if (sprite->type != ST_FONT) {
 
	if (sprite->type != SpriteType::Font) {
 
		zoom_min = _settings_client.gui.zoom_min;
 
		zoom_max = _settings_client.gui.zoom_max;
 
		if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_MAX;
 
	}
 

	
 
	/* Calculate sizes and allocate. */
src/blitter/40bpp_anim.cpp
Show inline comments
 
@@ -351,25 +351,25 @@ void Blitter_40bppAnim::DrawColourMappin
 
				anim++;
 
			}
 
			udst = udst - width + _screen.pitch;
 
			anim = anim - width + _screen.pitch;
 
		} while (--height);
 
	} else if (pal == PALETTE_NEWSPAPER) {
 
		const uint8 *remap = GetNonSprite(pal, ST_RECOLOUR) + 1;
 
		const uint8 *remap = GetNonSprite(pal, SpriteType::Recolour) + 1;
 
		do {
 
			for (int i = 0; i != width; i++) {
 
				if (*anim == 0) *udst = MakeGrey(*udst);
 
				*anim = remap[*anim];
 
				udst++;
 
				anim++;
 
			}
 
			udst = udst - width + _screen.pitch;
 
			anim = anim - width + _screen.pitch;
 
		} while (--height);
 
	} else {
 
		const uint8 *remap = GetNonSprite(pal, ST_RECOLOUR) + 1;
 
		const uint8 *remap = GetNonSprite(pal, SpriteType::Recolour) + 1;
 
		do {
 
			for (int i = 0; i != width; i++) {
 
				*anim = remap[*anim];
 
				anim++;
 
			}
 
			anim = anim - width + _screen.pitch;
src/blitter/8bpp_base.cpp
Show inline comments
 
@@ -13,13 +13,13 @@
 
#include "common.hpp"
 

	
 
#include "../safeguards.h"
 

	
 
void Blitter_8bppBase::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)
 
{
 
	const uint8 *ctab = GetNonSprite(pal, ST_RECOLOUR) + 1;
 
	const uint8 *ctab = GetNonSprite(pal, SpriteType::Recolour) + 1;
 

	
 
	do {
 
		for (int i = 0; i != width; i++) *((uint8 *)dst + i) = ctab[((uint8 *)dst)[i]];
 
		dst = (uint8 *)dst + _screen.pitch;
 
	} while (--height);
 
}
src/blitter/8bpp_optimized.cpp
Show inline comments
 
@@ -124,13 +124,13 @@ Sprite *Blitter_8bppOptimized::Encode(co
 
	/* Make memory for all zoom-levels */
 
	uint memory = sizeof(SpriteData);
 

	
 
	ZoomLevel zoom_min;
 
	ZoomLevel zoom_max;
 

	
 
	if (sprite->type == ST_FONT) {
 
	if (sprite->type == SpriteType::Font) {
 
		zoom_min = ZOOM_LVL_NORMAL;
 
		zoom_max = ZOOM_LVL_NORMAL;
 
	} else {
 
		zoom_min = _settings_client.gui.zoom_min;
 
		zoom_max = _settings_client.gui.zoom_max;
 
		if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_MAX;
src/cargo_type.h
Show inline comments
 
@@ -141,16 +141,16 @@ public:
 
		return count;
 
	}
 
};
 

	
 

	
 
/** Types of cargo source and destination */
 
enum SourceType : byte {
 
	ST_INDUSTRY,     ///< Source/destination is an industry
 
	ST_TOWN,         ///< Source/destination is a town
 
	ST_HEADQUARTERS, ///< Source/destination are company headquarters
 
enum class SourceType : byte {
 
	Industry,     ///< Source/destination is an industry
 
	Town,         ///< Source/destination is a town
 
	Headquarters, ///< Source/destination are company headquarters
 
};
 

	
 
typedef uint16 SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
 
static const SourceID INVALID_SOURCE = 0xFFFF; ///< Invalid/unknown index of source
 

	
 
#endif /* CARGO_TYPE_H */
src/cargomonitor.cpp
Show inline comments
 
@@ -121,19 +121,19 @@ void AddCargoDelivery(CargoID cargo_type
 
{
 
	if (amount == 0) return;
 

	
 
	if (src != INVALID_SOURCE) {
 
		/* Handle pickup update. */
 
		switch (src_type) {
 
			case ST_INDUSTRY: {
 
			case SourceType::Industry: {
 
				CargoMonitorID num = EncodeCargoIndustryMonitor(company, cargo_type, src);
 
				CargoMonitorMap::iterator iter = _cargo_pickups.find(num);
 
				if (iter != _cargo_pickups.end()) iter->second += amount;
 
				break;
 
			}
 
			case ST_TOWN: {
 
			case SourceType::Town: {
 
				CargoMonitorID num = EncodeCargoTownMonitor(company, cargo_type, src);
 
				CargoMonitorMap::iterator iter = _cargo_pickups.find(num);
 
				if (iter != _cargo_pickups.end()) iter->second += amount;
 
				break;
 
			}
 
			default: break;
src/cargopacket.cpp
Show inline comments
 
@@ -23,13 +23,13 @@ INSTANTIATE_POOL_METHODS(CargoPacket)
 

	
 
/**
 
 * Create a new packet for savegame loading.
 
 */
 
CargoPacket::CargoPacket()
 
{
 
	this->source_type = ST_INDUSTRY;
 
	this->source_type = SourceType::Industry;
 
	this->source_id   = INVALID_SOURCE;
 
}
 

	
 
/**
 
 * Creates a new cargo packet.
 
 * @param source      Source station of the packet.
src/cargopacket.h
Show inline comments
 
@@ -63,13 +63,13 @@ private:
 
public:
 
	/** Maximum number of items in a single cargo packet. */
 
	static const uint16 MAX_COUNT = UINT16_MAX;
 

	
 
	CargoPacket();
 
	CargoPacket(StationID source, TileIndex source_xy, uint16 count, SourceType source_type, SourceID source_id);
 
	CargoPacket(uint16 count, byte days_in_transit, StationID source, TileIndex source_xy, TileIndex loaded_at_xy, Money feeder_share = 0, SourceType source_type = ST_INDUSTRY, SourceID source_id = INVALID_SOURCE);
 
	CargoPacket(uint16 count, byte days_in_transit, StationID source, TileIndex source_xy, TileIndex loaded_at_xy, Money feeder_share = 0, SourceType source_type = SourceType::Industry, SourceID source_id = INVALID_SOURCE);
 

	
 
	/** Destroy the packet. */
 
	~CargoPacket() { }
 

	
 
	CargoPacket *Split(uint new_size);
 
	void Merge(CargoPacket *cp);
src/economy.cpp
Show inline comments
 
@@ -1084,13 +1084,13 @@ static uint DeliverGoodsToIndustry(const
 
		ind->incoming_cargo_waiting[cargo_index] += amount;
 
		ind->last_cargo_accepted_at[cargo_index] = _date;
 
		num_pieces -= amount;
 
		accepted += amount;
 

	
 
		/* Update the cargo monitor. */
 
		AddCargoDelivery(cargo_type, company, amount, ST_INDUSTRY, source, st, ind->index);
 
		AddCargoDelivery(cargo_type, company, amount, SourceType::Industry, source, st, ind->index);
 
	}
 

	
 
	return accepted;
 
}
 

	
 
/**
 
@@ -1110,13 +1110,13 @@ static Money DeliverGoods(int num_pieces
 
{
 
	assert(num_pieces > 0);
 

	
 
	Station *st = Station::Get(dest);
 

	
 
	/* Give the goods to the industry. */
 
	uint accepted_ind = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src_type == ST_INDUSTRY ? src : INVALID_INDUSTRY, company->index);
 
	uint accepted_ind = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src_type == SourceType::Industry ? src : INVALID_INDUSTRY, company->index);
 

	
 
	/* If this cargo type is always accepted, accept all */
 
	uint accepted_total = HasBit(st->always_accepted, cargo_type) ? num_pieces : accepted_ind;
 

	
 
	/* Update station statistics */
 
	if (accepted_total > 0) {
src/fontcache/freetypefontcache.cpp
Show inline comments
 
@@ -238,13 +238,13 @@ const Sprite *FreeTypeFontCache::Interna
 
	/* Limit glyph size to prevent overflows later on. */
 
	if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) usererror("Font glyph is too large");
 

	
 
	/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
 
	SpriteLoader::Sprite sprite;
 
	sprite.AllocateData(ZOOM_LVL_NORMAL, static_cast<size_t>(width) * height);
 
	sprite.type = ST_FONT;
 
	sprite.type = SpriteType::Font;
 
	sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
 
	sprite.width = width;
 
	sprite.height = height;
 
	sprite.x_offs = slot->bitmap_left;
 
	sprite.y_offs = this->ascender - slot->bitmap_top;
 

	
src/fontcache/spritefontcache.cpp
Show inline comments
 
@@ -110,20 +110,20 @@ void SpriteFontCache::ClearFontCache()
 
}
 

	
 
const Sprite *SpriteFontCache::GetGlyph(GlyphID key)
 
{
 
	SpriteID sprite = this->GetUnicodeGlyph(key);
 
	if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
 
	return GetSprite(sprite, ST_FONT);
 
	return GetSprite(sprite, SpriteType::Font);
 
}
 

	
 
uint SpriteFontCache::GetGlyphWidth(GlyphID key)
 
{
 
	SpriteID sprite = this->GetUnicodeGlyph(key);
 
	if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
 
	return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + ScaleSpriteTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
 
	return SpriteExists(sprite) ? GetSprite(sprite, SpriteType::Font)->width + ScaleSpriteTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
 
}
 

	
 
bool SpriteFontCache::GetDrawGlyphShadow()
 
{
 
	return false;
 
}
src/fontcache/truetypefontcache.cpp
Show inline comments
 
@@ -138,13 +138,13 @@ const Sprite *TrueTypeFontCache::GetGlyp
 
#undef CP___
 
			static const SpriteLoader::Sprite builtin_questionmark = {
 
				10, // height
 
				8,  // width
 
				0,  // x_offs
 
				0,  // y_offs
 
				ST_FONT,
 
				SpriteType::Font,
 
				SCC_PAL,
 
				builtin_questionmark_data
 
			};
 

	
 
			Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(&builtin_questionmark, SimpleSpriteAlloc);
 
			assert(spr != nullptr);
src/game/game_info.cpp
Show inline comments
 
@@ -27,18 +27,18 @@ static bool CheckAPIVersion(const char *
 
	return versions.find(api_version) != versions.end();
 
}
 

	
 
#if defined(_WIN32)
 
#undef GetClassName
 
#endif /* _WIN32 */
 
template <> const char *GetClassName<GameInfo, ST_GS>() { return "GSInfo"; }
 
template <> const char *GetClassName<GameInfo, ScriptType::GS>() { return "GSInfo"; }
 

	
 
/* static */ void GameInfo::RegisterAPI(Squirrel *engine)
 
{
 
	/* Create the GSInfo class, and add the RegisterGS function */
 
	DefSQClass<GameInfo, ST_GS> SQGSInfo("GSInfo");
 
	DefSQClass<GameInfo, ScriptType::GS> SQGSInfo("GSInfo");
 
	SQGSInfo.PreRegister(engine);
 
	SQGSInfo.AddConstructor<void (GameInfo::*)(), 1>(engine, "x");
 
	SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddSetting, "AddSetting");
 
	SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddLabels, "AddLabels");
 
	SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_NONE, "CONFIG_NONE");
 
	SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_RANDOM, "CONFIG_RANDOM");
src/gfx.cpp
Show inline comments
 
@@ -71,13 +71,13 @@ int _gui_scale_cfg;                     
 
 * This rectangle defines the area which should be repaint by the video driver.
 
 *
 
 * @ingroup dirty
 
 */
 
static Rect _invalid_rect;
 
static const byte *_colour_remap_ptr;
 
static byte _string_colourremap[3]; ///< Recoloursprite for stringdrawing. The grf loader ensures that #ST_FONT sprites only use colours 0 to 2.
 
static byte _string_colourremap[3]; ///< Recoloursprite for stringdrawing. The grf loader ensures that #SpriteType::Font sprites only use colours 0 to 2.
 

	
 
static const uint DIRTY_BLOCK_HEIGHT   = 8;
 
static const uint DIRTY_BLOCK_WIDTH    = 64;
 

	
 
static uint _dirty_bytes_per_line = 0;
 
static byte *_dirty_blocks = nullptr;
 
@@ -989,13 +989,13 @@ void DrawCharCentered(WChar c, const Rec
 
 * @param zoom The zoom level applicable to the sprite.
 
 * @return Sprite size in pixels.
 
 * @note The size assumes (0, 0) as top-left coordinate and ignores any part of the sprite drawn at the left or above that position.
 
 */
 
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
 
{
 
	const Sprite *sprite = GetSprite(sprid, ST_NORMAL);
 
	const Sprite *sprite = GetSprite(sprid, SpriteType::Normal);
 

	
 
	if (offset != nullptr) {
 
		offset->x = UnScaleByZoom(sprite->x_offs, zoom);
 
		offset->y = UnScaleByZoom(sprite->y_offs, zoom);
 
	}
 

	
 
@@ -1029,23 +1029,23 @@ static BlitterMode GetBlitterMode(Palett
 
 * @param sub  If available, draw only specified part of the sprite
 
 */
 
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
 
{
 
	SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
 
	if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
 
		_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
 
		GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite);
 
		_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
 
		GfxMainBlitterViewport(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_TRANSPARENT, sub, real_sprite);
 
	} else if (pal != PAL_NONE) {
 
		if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
 
			SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
 
		} else {
 
			_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
 
			_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
 
		}
 
		GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite);
 
		GfxMainBlitterViewport(GetSprite(real_sprite, SpriteType::Normal), x, y, GetBlitterMode(pal), sub, real_sprite);
 
	} else {
 
		GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite);
 
		GfxMainBlitterViewport(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_NORMAL, sub, real_sprite);
 
	}
 
}
 

	
 
/**
 
 * Draw a sprite, not in a viewport
 
 * @param img  Image number to draw
 
@@ -1056,23 +1056,23 @@ void DrawSpriteViewport(SpriteID img, Pa
 
 * @param zoom Zoom level of sprite
 
 */
 
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
 
{
 
	SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
 
	if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
 
		_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
 
		GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite, zoom);
 
		_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
 
		GfxMainBlitter(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_TRANSPARENT, sub, real_sprite, zoom);
 
	} else if (pal != PAL_NONE) {
 
		if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
 
			SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
 
		} else {
 
			_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
 
			_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
 
		}
 
		GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite, zoom);
 
		GfxMainBlitter(GetSprite(real_sprite, SpriteType::Normal), x, y, GetBlitterMode(pal), sub, real_sprite, zoom);
 
	} else {
 
		GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite, zoom);
 
		GfxMainBlitter(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_NORMAL, sub, real_sprite, zoom);
 
	}
 
}
 

	
 
/**
 
 * The code for setting up the blitter mode and sprite information before finally drawing the sprite.
 
 * @param sprite The sprite to draw.
 
@@ -1217,13 +1217,13 @@ std::unique_ptr<uint32[]> DrawSpriteToRg
 

	
 
	Blitter *blitter = BlitterFactory::GetCurrentBlitter();
 
	if (blitter->GetScreenDepth() != 8 && blitter->GetScreenDepth() != 32) return nullptr;
 

	
 
	/* Gather information about the sprite to write, reserve memory */
 
	const SpriteID real_sprite = GB(spriteId, 0, SPRITE_WIDTH);
 
	const Sprite *sprite = GetSprite(real_sprite, ST_NORMAL);
 
	const Sprite *sprite = GetSprite(real_sprite, SpriteType::Normal);
 
	Dimension dim = GetSpriteSize(real_sprite, nullptr, zoom);
 
	size_t dim_size = static_cast<size_t>(dim.width) * dim.height;
 
	std::unique_ptr<uint32[]> result(new uint32[dim_size]);
 
	/* Set buffer to fully transparent. */
 
	MemSetT(result.get(), 0, dim_size);
 

	
 
@@ -1840,13 +1840,13 @@ void UpdateCursorSize()
 
	/* Ignore setting any cursor before the sprites are loaded. */
 
	if (GetMaxSpriteID() == 0) return;
 

	
 
	static_assert(lengthof(_cursor.sprite_seq) == lengthof(_cursor.sprite_pos));
 
	assert(_cursor.sprite_count <= lengthof(_cursor.sprite_seq));
 
	for (uint i = 0; i < _cursor.sprite_count; ++i) {
 
		const Sprite *p = GetSprite(GB(_cursor.sprite_seq[i].sprite, 0, SPRITE_WIDTH), ST_NORMAL);
 
		const Sprite *p = GetSprite(GB(_cursor.sprite_seq[i].sprite, 0, SPRITE_WIDTH), SpriteType::Normal);
 
		Point offs, size;
 
		offs.x = UnScaleGUI(p->x_offs) + _cursor.sprite_pos[i].x;
 
		offs.y = UnScaleGUI(p->y_offs) + _cursor.sprite_pos[i].y;
 
		size.x = UnScaleGUI(p->width);
 
		size.y = UnScaleGUI(p->height);
 

	
src/gfx_type.h
Show inline comments
 
@@ -302,18 +302,18 @@ enum PaletteType {
 
	PAL_WINDOWS,    ///< Use the Windows palette.
 
	PAL_AUTODETECT, ///< Automatically detect the palette based on the graphics pack.
 
	MAX_PAL = 2,    ///< The number of palettes.
 
};
 

	
 
/** Types of sprites that might be loaded */
 
enum SpriteType : byte {
 
	ST_NORMAL   = 0,      ///< The most basic (normal) sprite
 
	ST_MAPGEN   = 1,      ///< Special sprite for the map generator
 
	ST_FONT     = 2,      ///< A sprite used for fonts
 
	ST_RECOLOUR = 3,      ///< Recolour sprite
 
	ST_INVALID  = 4,      ///< Pseudosprite or other unusable sprite, used only internally
 
enum class SpriteType : byte {
 
	Normal   = 0,      ///< The most basic (normal) sprite
 
	MapGen   = 1,      ///< Special sprite for the map generator
 
	Font     = 2,      ///< A sprite used for fonts
 
	Recolour = 3,      ///< Recolour sprite
 
	Invalid  = 4,      ///< Pseudosprite or other unusable sprite, used only internally
 
};
 

	
 
/**
 
 * The number of milliseconds per game tick.
 
 * The value 27 together with a day length of 74 ticks makes one day 1998 milliseconds, almost exactly 2 seconds.
 
 * With a 2 second day, one standard month is 1 minute, and one standard year is slightly over 12 minutes.
src/industry_cmd.cpp
Show inline comments
 
@@ -194,14 +194,14 @@ Industry::~Industry()
 
	DecIndustryTypeCount(this->type);
 

	
 
	DeleteIndustryNews(this->index);
 
	CloseWindowById(WC_INDUSTRY_VIEW, this->index);
 
	DeleteNewGRFInspectWindow(GSF_INDUSTRIES, this->index);
 

	
 
	DeleteSubsidyWith(ST_INDUSTRY, this->index);
 
	CargoPacket::InvalidateAllFrom(ST_INDUSTRY, this->index);
 
	DeleteSubsidyWith(SourceType::Industry, this->index);
 
	CargoPacket::InvalidateAllFrom(SourceType::Industry, this->index);
 

	
 
	for (Station *st : this->stations_near) {
 
		st->RemoveIndustryToDeliver(this);
 
	}
 
}
 

	
 
@@ -543,13 +543,13 @@ static bool TransportIndustryGoods(TileI
 

	
 
			/* fluctuating economy? */
 
			if (EconomyIsInRecession()) cw = (cw + 1) / 2;
 

	
 
			i->this_month_production[j] += cw;
 

	
 
			uint am = MoveGoodsToStation(i->produced_cargo[j], cw, ST_INDUSTRY, i->index, &i->stations_near, i->exclusive_consumer);
 
			uint am = MoveGoodsToStation(i->produced_cargo[j], cw, SourceType::Industry, i->index, &i->stations_near, i->exclusive_consumer);
 
			i->this_month_transported[j] += am;
 

	
 
			moved_cargo |= (am != 0);
 
		}
 
	}
 

	
src/landscape.cpp
Show inline comments
 
@@ -814,13 +814,13 @@ static const byte _genterrain_tbl_2[5] =
 

	
 
static void GenerateTerrain(int type, uint flag)
 
{
 
	uint32 r = Random();
 

	
 
	/* Choose one of the templates from the graphics file. */
 
	const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + SPR_MAPGEN_BEGIN, ST_MAPGEN);
 
	const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + SPR_MAPGEN_BEGIN, SpriteType::MapGen);
 
	if (templ == nullptr) usererror("Map generator sprites could not be loaded");
 

	
 
	/* Chose a random location to apply the template to. */
 
	uint x = r & Map::MaxX();
 
	uint y = (r >> Map::LogX()) & Map::MaxY();
 

	
src/main_gui.cpp
Show inline comments
 
@@ -543,13 +543,13 @@ void ShowSelectGameWindow();
 
/**
 
 * Initialise the default colours (remaps and the likes), and load the main windows.
 
 */
 
void SetupColoursAndInitialWindow()
 
{
 
	for (uint i = 0; i != 16; i++) {
 
		const byte *b = GetNonSprite(PALETTE_RECOLOUR_START + i, ST_RECOLOUR);
 
		const byte *b = GetNonSprite(PALETTE_RECOLOUR_START + i, SpriteType::Recolour);
 

	
 
		assert(b);
 
		memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
 
	}
 

	
 
	new MainWindow(&_main_window_desc);
src/newgrf_debug_gui.cpp
Show inline comments
 
@@ -838,18 +838,18 @@ struct SpriteAlignerWindow : Window {
 
		this->FinishInitNested(wno);
 

	
 
		this->SetWidgetLoweredState(WID_SA_CENTRE, SpriteAlignerWindow::centre);
 
		this->SetWidgetLoweredState(WID_SA_CROSSHAIR, SpriteAlignerWindow::crosshair);
 

	
 
		/* Oh yes, we assume there is at least one normal sprite! */
 
		while (GetSpriteType(this->current_sprite) != ST_NORMAL) this->current_sprite++;
 
		while (GetSpriteType(this->current_sprite) != SpriteType::Normal) this->current_sprite++;
 
	}
 

	
 
	void SetStringParameters(int widget) const override
 
	{
 
		const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL);
 
		const Sprite *spr = GetSprite(this->current_sprite, SpriteType::Normal);
 
		switch (widget) {
 
			case WID_SA_CAPTION:
 
				SetDParam(0, this->current_sprite);
 
				SetDParamStr(1, GetOriginFile(this->current_sprite)->GetSimplifiedFilename());
 
				break;
 

	
 
@@ -898,13 +898,13 @@ struct SpriteAlignerWindow : Window {
 

	
 
	void DrawWidget(const Rect &r, int widget) const override
 
	{
 
		switch (widget) {
 
			case WID_SA_SPRITE: {
 
				/* Center the sprite ourselves */
 
				const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL);
 
				const Sprite *spr = GetSprite(this->current_sprite, SpriteType::Normal);
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				int x;
 
				int y;
 
				if (SpriteAlignerWindow::centre) {
 
					x = -UnScaleGUI(spr->x_offs) + (ir.Width() - UnScaleGUI(spr->width)) / 2;
 
					y = -UnScaleGUI(spr->y_offs) + (ir.Height() - UnScaleGUI(spr->height)) / 2;
 
@@ -946,24 +946,24 @@ struct SpriteAlignerWindow : Window {
 
	void OnClick(Point pt, int widget, int click_count) override
 
	{
 
		switch (widget) {
 
			case WID_SA_PREVIOUS:
 
				do {
 
					this->current_sprite = (this->current_sprite == 0 ? GetMaxSpriteID() :  this->current_sprite) - 1;
 
				} while (GetSpriteType(this->current_sprite) != ST_NORMAL);
 
				} while (GetSpriteType(this->current_sprite) != SpriteType::Normal);
 
				this->SetDirty();
 
				break;
 

	
 
			case WID_SA_GOTO:
 
				ShowQueryString(STR_EMPTY, STR_SPRITE_ALIGNER_GOTO_CAPTION, 7, this, CS_NUMERAL, QSF_NONE);
 
				break;
 

	
 
			case WID_SA_NEXT:
 
				do {
 
					this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID();
 
				} while (GetSpriteType(this->current_sprite) != ST_NORMAL);
 
				} while (GetSpriteType(this->current_sprite) != SpriteType::Normal);
 
				this->SetDirty();
 
				break;
 

	
 
			case WID_SA_PICKER:
 
				this->LowerWidget(WID_SA_PICKER);
 
				_newgrf_debug_sprite_picker.mode = SPM_WAIT_CLICK;
 
@@ -974,13 +974,13 @@ struct SpriteAlignerWindow : Window {
 
				const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
 
				int step_size = nwid->resize_y;
 

	
 
				uint i = this->vscroll->GetPosition() + (pt.y - nwid->pos_y) / step_size;
 
				if (i < _newgrf_debug_sprite_picker.sprites.size()) {
 
					SpriteID spr = _newgrf_debug_sprite_picker.sprites[i];
 
					if (GetSpriteType(spr) == ST_NORMAL) this->current_sprite = spr;
 
					if (GetSpriteType(spr) == SpriteType::Normal) this->current_sprite = spr;
 
				}
 
				this->SetDirty();
 
				break;
 
			}
 

	
 
			case WID_SA_UP:
 
@@ -997,13 +997,13 @@ struct SpriteAlignerWindow : Window {
 
				 * cache. If that's not the case, just let the NewGRF developer
 
				 * increase the cache size instead of storing thousands of offsets
 
				 * for the incredibly small chance that it's actually going to be
 
				 * used by someone and the sprite cache isn't big enough for that
 
				 * particular NewGRF developer.
 
				 */
 
				Sprite *spr = const_cast<Sprite *>(GetSprite(this->current_sprite, ST_NORMAL));
 
				Sprite *spr = const_cast<Sprite *>(GetSprite(this->current_sprite, SpriteType::Normal));
 

	
 
				/* Remember the original offsets of the current sprite, if not already in mapping. */
 
				if (!(this->offs_start_map.Contains(this->current_sprite))) {
 
					this->offs_start_map.Insert(this->current_sprite, XyOffs(spr->x_offs, spr->y_offs));
 
				}
 
				switch (widget) {
 
@@ -1042,13 +1042,13 @@ struct SpriteAlignerWindow : Window {
 
	void OnQueryTextFinished(char *str) override
 
	{
 
		if (StrEmpty(str)) return;
 

	
 
		this->current_sprite = atoi(str);
 
		if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0;
 
		while (GetSpriteType(this->current_sprite) != ST_NORMAL) {
 
		while (GetSpriteType(this->current_sprite) != SpriteType::Normal) {
 
			this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID();
 
		}
 
		this->SetDirty();
 
	}
 

	
 
	/**
src/object_cmd.cpp
Show inline comments
 
@@ -585,13 +585,13 @@ static CommandCost ClearTile_Object(Tile
 
	switch (type) {
 
		case OBJECT_HQ: {
 
			Company *c = Company::Get(GetTileOwner(tile));
 
			if (flags & DC_EXEC) {
 
				c->location_of_HQ = INVALID_TILE; // reset HQ position
 
				SetWindowDirty(WC_COMPANY, c->index);
 
				CargoPacket::InvalidateAllFrom(ST_HEADQUARTERS, c->index);
 
				CargoPacket::InvalidateAllFrom(SourceType::Headquarters, c->index);
 
			}
 

	
 
			/* cost of relocating company is 1% of company value */
 
			cost = CommandCost(EXPENSES_CONSTRUCTION, CalculateCompanyValue(c) / 100);
 
			break;
 
		}
 
@@ -683,22 +683,22 @@ static void TileLoop_Object(TileIndex ti
 

	
 
	uint r = Random();
 
	/* Top town buildings generate 250, so the top HQ type makes 256. */
 
	if (GB(r, 0, 8) < (256 / 4 / (6 - level))) {
 
		uint amt = GB(r, 0, 8) / 8 / 4 + 1;
 
		if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
 
		MoveGoodsToStation(CT_PASSENGERS, amt, ST_HEADQUARTERS, GetTileOwner(tile), stations.GetStations());
 
		MoveGoodsToStation(CT_PASSENGERS, amt, SourceType::Headquarters, GetTileOwner(tile), stations.GetStations());
 
	}
 

	
 
	/* Top town building generates 90, HQ can make up to 196. The
 
	 * proportion passengers:mail is about the same as in the acceptance
 
	 * equations. */
 
	if (GB(r, 8, 8) < (196 / 4 / (6 - level))) {
 
		uint amt = GB(r, 8, 8) / 8 / 4 + 1;
 
		if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
 
		MoveGoodsToStation(CT_MAIL, amt, ST_HEADQUARTERS, GetTileOwner(tile), stations.GetStations());
 
		MoveGoodsToStation(CT_MAIL, amt, SourceType::Headquarters, GetTileOwner(tile), stations.GetStations());
 
	}
 
}
 

	
 

	
 
static TrackStatus GetTileTrackStatus_Object(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
 
{
src/os/macosx/font_osx.cpp
Show inline comments
 
@@ -284,13 +284,13 @@ const Sprite *CoreTextFontCache::Interna
 

	
 
	/* Limit glyph size to prevent overflows later on. */
 
	if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) usererror("Font glyph is too large");
 

	
 
	SpriteLoader::Sprite sprite;
 
	sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
 
	sprite.type = ST_FONT;
 
	sprite.type = SpriteType::Font;
 
	sprite.colours = (use_aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
 
	sprite.width = width;
 
	sprite.height = height;
 
	sprite.x_offs = (int16)std::round(CGRectGetMinX(bounds));
 
	sprite.y_offs = this->ascender - (int16)std::ceil(CGRectGetMaxY(bounds));
 

	
src/os/windows/font_win32.cpp
Show inline comments
 
@@ -453,13 +453,13 @@ void Win32FontCache::ClearFontCache()
 
	byte *bmp = new byte[size];
 
	GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
 

	
 
	/* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */
 
	SpriteLoader::Sprite sprite;
 
	sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
 
	sprite.type = ST_FONT;
 
	sprite.type = SpriteType::Font;
 
	sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
 
	sprite.width = width;
 
	sprite.height = height;
 
	sprite.x_offs = gm.gmptGlyphOrigin.x;
 
	sprite.y_offs = this->ascender - gm.gmptGlyphOrigin.y;
 

	
src/saveload/afterload.cpp
Show inline comments
 
@@ -2251,25 +2251,25 @@ bool AfterLoadGame()
 
				s->awarded = INVALID_COMPANY; // not awarded to anyone
 
				const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
 
				switch (cs->town_effect) {
 
					case TE_PASSENGERS:
 
					case TE_MAIL:
 
						/* Town -> Town */
 
						s->src_type = s->dst_type = ST_TOWN;
 
						s->src_type = s->dst_type = SourceType::Town;
 
						if (Town::IsValidID(s->src) && Town::IsValidID(s->dst)) continue;
 
						break;
 
					case TE_GOODS:
 
					case TE_FOOD:
 
						/* Industry -> Town */
 
						s->src_type = ST_INDUSTRY;
 
						s->dst_type = ST_TOWN;
 
						s->src_type = SourceType::Industry;
 
						s->dst_type = SourceType::Town;
 
						if (Industry::IsValidID(s->src) && Town::IsValidID(s->dst)) continue;
 
						break;
 
					default:
 
						/* Industry -> Industry */
 
						s->src_type = s->dst_type = ST_INDUSTRY;
 
						s->src_type = s->dst_type = SourceType::Industry;
 
						if (Industry::IsValidID(s->src) && Industry::IsValidID(s->dst)) continue;
 
						break;
 
				}
 
			} else {
 
				/* Do our best for awarded subsidies. The original source or destination industry
 
				 * can't be determined anymore for awarded subsidies, so invalidate them.
 
@@ -2281,13 +2281,13 @@ bool AfterLoadGame()
 
					case TE_MAIL: {
 
						/* Town -> Town */
 
						const Station *ss = Station::GetIfValid(s->src);
 
						const Station *sd = Station::GetIfValid(s->dst);
 
						if (ss != nullptr && sd != nullptr && ss->owner == sd->owner &&
 
								Company::IsValidID(ss->owner)) {
 
							s->src_type = s->dst_type = ST_TOWN;
 
							s->src_type = s->dst_type = SourceType::Town;
 
							s->src = ss->town->index;
 
							s->dst = sd->town->index;
 
							s->awarded = ss->owner;
 
							continue;
 
						}
 
						break;
src/script/api/ai/ai_controller.hpp.sq
Show inline comments
 
@@ -4,17 +4,17 @@
 
 * 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/>.
 
 */
 

	
 
#include "../script_controller.hpp"
 

	
 
template <> const char *GetClassName<ScriptController, ST_AI>() { return "AIController"; }
 
template <> const char *GetClassName<ScriptController, ScriptType::AI>() { return "AIController"; }
 

	
 
void SQAIController_Register(Squirrel *engine)
 
{
 
	DefSQClass<ScriptController, ST_AI> SQAIController("AIController");
 
	DefSQClass<ScriptController, ScriptType::AI> SQAIController("AIController");
 
	SQAIController.PreRegister(engine);
 

	
 
	SQAIController.DefSQStaticMethod(engine, &ScriptController::GetTick,           "GetTick",           1, ".");
 
	SQAIController.DefSQStaticMethod(engine, &ScriptController::GetOpsTillSuspend, "GetOpsTillSuspend", 1, ".");
 
	SQAIController.DefSQStaticMethod(engine, &ScriptController::SetCommandDelay,   "SetCommandDelay",   2, ".i");
 
	SQAIController.DefSQStaticMethod(engine, &ScriptController::Sleep,             "Sleep",             2, ".i");
src/script/api/game/game_controller.hpp.sq
Show inline comments
 
@@ -4,17 +4,17 @@
 
 * 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/>.
 
 */
 

	
 
#include "../script_controller.hpp"
 

	
 
template <> const char *GetClassName<ScriptController, ST_GS>() { return "GSController"; }
 
template <> const char *GetClassName<ScriptController, ScriptType::GS>() { return "GSController"; }
 

	
 
void SQGSController_Register(Squirrel *engine)
 
{
 
	DefSQClass<ScriptController, ST_GS> SQGSController("GSController");
 
	DefSQClass<ScriptController, ScriptType::GS> SQGSController("GSController");
 
	SQGSController.PreRegister(engine);
 

	
 
	SQGSController.DefSQStaticMethod(engine, &ScriptController::GetTick,           "GetTick",           1, ".");
 
	SQGSController.DefSQStaticMethod(engine, &ScriptController::GetOpsTillSuspend, "GetOpsTillSuspend", 1, ".");
 
	SQGSController.DefSQStaticMethod(engine, &ScriptController::SetCommandDelay,   "SetCommandDelay",   2, ".i");
 
	SQGSController.DefSQStaticMethod(engine, &ScriptController::Sleep,             "Sleep",             2, ".i");
src/script/api/script_subsidy.hpp
Show inline comments
 
@@ -22,13 +22,13 @@ public:
 
	/**
 
	 * Enumeration for source and destination of a subsidy.
 
	 * @note The list of values may grow in future.
 
	 */
 
	enum SubsidyParticipantType {
 
		/* Values are important, as they represent the internal state of the game.
 
		 *  It is originally named SourceType. ST_HEADQUARTERS is intentionally
 
		 *  It is originally named SourceType. SourceType::Headquarters is intentionally
 
		 *  left out, as it cannot be used for Subsidies. */
 
		SPT_INDUSTRY =    0, ///< Subsidy participant is an industry
 
		SPT_TOWN     =    1, ///< Subsidy participant is a town
 
		SPT_INVALID  = 0xFF, ///< Invalid/unknown participant type
 
	};
 

	
src/script/squirrel.hpp
Show inline comments
 
@@ -10,15 +10,15 @@
 
#ifndef SQUIRREL_HPP
 
#define SQUIRREL_HPP
 

	
 
#include <squirrel.h>
 

	
 
/** The type of script we're working with, i.e. for who is it? */
 
enum ScriptType {
 
	ST_AI, ///< The script is for AI scripts.
 
	ST_GS, ///< The script is for Game scripts.
 
enum class ScriptType {
 
	AI, ///< The script is for AI scripts.
 
	GS, ///< The script is for Game scripts.
 
};
 

	
 
struct ScriptAllocator;
 

	
 
class Squirrel {
 
	friend class ScriptAllocatorScope;
src/sprite.cpp
Show inline comments
 
@@ -116,13 +116,13 @@ void DrawCommonTileSeqInGUI(int x, int y
 
		pal = SpriteLayoutPaletteTransform(image, pal, default_palette);
 

	
 
		if (dtss->IsParentSprite()) {
 
			Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
 
			DrawSprite(image, pal, x + UnScaleGUI(pt.x), y + UnScaleGUI(pt.y));
 

	
 
			const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
 
			const Sprite *spr = GetSprite(image & SPRITE_MASK, SpriteType::Normal);
 
			child_offset.x = UnScaleGUI(pt.x + spr->x_offs);
 
			child_offset.y = UnScaleGUI(pt.y + spr->y_offs);
 
		} else {
 
			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 + ScaleSpriteTrad(offs_x), y + child_offset.y + ScaleSpriteTrad(offs_y));
src/spritecache.cpp
Show inline comments
 
@@ -159,13 +159,13 @@ bool SpriteExists(SpriteID id)
 
 * Get the sprite type of a given sprite.
 
 * @param sprite The sprite to look at.
 
 * @return the type of sprite.
 
 */
 
SpriteType GetSpriteType(SpriteID sprite)
 
{
 
	if (!SpriteExists(sprite)) return ST_INVALID;
 
	if (!SpriteExists(sprite)) return SpriteType::Invalid;
 
	return GetSpriteCache(sprite)->type;
 
}
 

	
 
/**
 
 * Get the SpriteFile of a given sprite.
 
 * @param sprite The sprite to look at.
 
@@ -458,38 +458,38 @@ static void *ReadSprite(const SpriteCach
 
	/* Use current blitter if no other sprite encoder is given. */
 
	if (encoder == nullptr) encoder = BlitterFactory::GetCurrentBlitter();
 

	
 
	SpriteFile &file = *sc->file;
 
	size_t file_pos = sc->file_pos;
 

	
 
	assert(sprite_type != ST_RECOLOUR);
 
	assert(IsMapgenSpriteID(id) == (sprite_type == ST_MAPGEN));
 
	assert(sprite_type != SpriteType::Recolour);
 
	assert(IsMapgenSpriteID(id) == (sprite_type == SpriteType::MapGen));
 
	assert(sc->type == sprite_type);
 

	
 
	Debug(sprite, 9, "Load sprite {}", id);
 

	
 
	SpriteLoader::Sprite sprite[ZOOM_LVL_COUNT];
 
	uint8 sprite_avail = 0;
 
	sprite[ZOOM_LVL_NORMAL].type = sprite_type;
 

	
 
	SpriteLoaderGrf sprite_loader(file.GetContainerVersion());
 
	if (sprite_type != ST_MAPGEN && encoder->Is32BppSupported()) {
 
	if (sprite_type != SpriteType::MapGen && encoder->Is32BppSupported()) {
 
		/* Try for 32bpp sprites first. */
 
		sprite_avail = sprite_loader.LoadSprite(sprite, file, file_pos, sprite_type, true, sc->control_flags);
 
	}
 
	if (sprite_avail == 0) {
 
		sprite_avail = sprite_loader.LoadSprite(sprite, file, file_pos, sprite_type, false, sc->control_flags);
 
	}
 

	
 
	if (sprite_avail == 0) {
 
		if (sprite_type == ST_MAPGEN) return nullptr;
 
		if (sprite_type == SpriteType::MapGen) return nullptr;
 
		if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't load the fallback sprite. What should I do?");
 
		return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator, encoder);
 
		return (void*)GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator, encoder);
 
	}
 

	
 
	if (sprite_type == ST_MAPGEN) {
 
	if (sprite_type == SpriteType::MapGen) {
 
		/* Ugly hack to work around the problem that the old landscape
 
		 *  generator assumes that those sprites are stored uncompressed in
 
		 *  the memory, and they are only read directly by the code, never
 
		 *  send to the blitter. So do not send it to the blitter (which will
 
		 *  result in a data array in the format the blitter likes most), but
 
		 *  extract the data directly and store that as sprite.
 
@@ -513,16 +513,16 @@ static void *ReadSprite(const SpriteCach
 

	
 
		return s;
 
	}
 

	
 
	if (!ResizeSprites(sprite, sprite_avail, encoder)) {
 
		if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't resize the fallback sprite. What should I do?");
 
		return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator, encoder);
 
		return (void*)GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator, encoder);
 
	}
 

	
 
	if (sprite->type == ST_FONT && ZOOM_LVL_GUI != ZOOM_LVL_NORMAL) {
 
	if (sprite->type == SpriteType::Font && ZOOM_LVL_GUI != ZOOM_LVL_NORMAL) {
 
		/* Make ZOOM_LVL_NORMAL be ZOOM_LVL_GUI */
 
		sprite[ZOOM_LVL_NORMAL].width  = sprite[ZOOM_LVL_GUI].width;
 
		sprite[ZOOM_LVL_NORMAL].height = sprite[ZOOM_LVL_GUI].height;
 
		sprite[ZOOM_LVL_NORMAL].x_offs = sprite[ZOOM_LVL_GUI].x_offs;
 
		sprite[ZOOM_LVL_NORMAL].y_offs = sprite[ZOOM_LVL_GUI].y_offs;
 
		sprite[ZOOM_LVL_NORMAL].data   = sprite[ZOOM_LVL_GUI].data;
 
@@ -626,13 +626,13 @@ bool LoadNextSprite(int load_index, Spri
 
		/* Some NewGRF files have "empty" pseudo-sprites which are 1
 
		 * byte long. Catch these so the sprites won't be displayed. */
 
		if (num == 1) {
 
			file.ReadByte();
 
			return false;
 
		}
 
		type = ST_RECOLOUR;
 
		type = SpriteType::Recolour;
 
		data = ReadRecolourSprite(file, num);
 
	} else if (file.GetContainerVersion() >= 2 && grf_type == 0xFD) {
 
		if (num != 4) {
 
			/* Invalid sprite section include, ignore. */
 
			file.SkipBytes(num);
 
			return false;
 
@@ -642,31 +642,31 @@ bool LoadNextSprite(int load_index, Spri
 
		if (iter != _grf_sprite_offsets.end()) {
 
			file_pos = iter->second.file_pos;
 
			control_flags = iter->second.control_flags;
 
		} else {
 
			file_pos = SIZE_MAX;
 
		}
 
		type = ST_NORMAL;
 
		type = SpriteType::Normal;
 
	} else {
 
		file.SkipBytes(7);
 
		type = SkipSpriteData(file, grf_type, num - 8) ? ST_NORMAL : ST_INVALID;
 
		type = SkipSpriteData(file, grf_type, num - 8) ? SpriteType::Normal : SpriteType::Invalid;
 
		/* Inline sprites are not supported for container version >= 2. */
 
		if (file.GetContainerVersion() >= 2) return false;
 
	}
 

	
 
	if (type == ST_INVALID) return false;
 
	if (type == SpriteType::Invalid) return false;
 

	
 
	if (load_index >= MAX_SPRITES) {
 
		usererror("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES);
 
	}
 

	
 
	bool is_mapgen = IsMapgenSpriteID(load_index);
 

	
 
	if (is_mapgen) {
 
		if (type != ST_NORMAL) usererror("Uhm, would you be so kind not to load a NewGRF that changes the type of the map generator sprites?");
 
		type = ST_MAPGEN;
 
		if (type != SpriteType::Normal) usererror("Uhm, would you be so kind not to load a NewGRF that changes the type of the map generator sprites?");
 
		type = SpriteType::MapGen;
 
	}
 

	
 
	SpriteCache *sc = AllocateSpriteCache(load_index);
 
	sc->file = &file;
 
	sc->file_pos = file_pos;
 
	sc->ptr = data;
 
@@ -825,13 +825,13 @@ static void DeleteEntryFromSpriteCache()
 

	
 
	Debug(sprite, 3, "DeleteEntryFromSpriteCache, inuse={}", GetSpriteCacheUsage());
 

	
 
	cur_lru = 0xffff;
 
	for (SpriteID i = 0; i != _spritecache_items; i++) {
 
		SpriteCache *sc = GetSpriteCache(i);
 
		if (sc->type != ST_RECOLOUR && sc->ptr != nullptr && sc->lru < cur_lru) {
 
		if (sc->type != SpriteType::Recolour && sc->ptr != nullptr && sc->lru < cur_lru) {
 
			cur_lru = sc->lru;
 
			best = i;
 
		}
 
	}
 

	
 
	/* Display an error message and die, in case we found no sprite at all.
 
@@ -885,49 +885,49 @@ void *SimpleSpriteAlloc(size_t size)
 
{
 
	return MallocT<byte>(size);
 
}
 

	
 
/**
 
 * Handles the case when a sprite of different type is requested than is present in the SpriteCache.
 
 * For ST_FONT sprites, it is normal. In other cases, default sprite is loaded instead.
 
 * For SpriteType::Font sprites, it is normal. In other cases, default sprite is loaded instead.
 
 * @param sprite ID of loaded sprite
 
 * @param requested requested sprite type
 
 * @param sc the currently known sprite cache for the requested sprite
 
 * @return fallback sprite
 
 * @note this function will do usererror() in the case the fallback sprite isn't available
 
 */
 
static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, SpriteCache *sc, AllocatorProc *allocator)
 
{
 
	static const char * const sprite_types[] = {
 
		"normal",        // ST_NORMAL
 
		"map generator", // ST_MAPGEN
 
		"character",     // ST_FONT
 
		"recolour",      // ST_RECOLOUR
 
		"normal",        // SpriteType::Normal
 
		"map generator", // SpriteType::MapGen
 
		"character",     // SpriteType::Font
 
		"recolour",      // SpriteType::Recolour
 
	};
 

	
 
	SpriteType available = sc->type;
 
	if (requested == ST_FONT && available == ST_NORMAL) {
 
		if (sc->ptr == nullptr) sc->type = ST_FONT;
 
	if (requested == SpriteType::Font && available == SpriteType::Normal) {
 
		if (sc->ptr == nullptr) sc->type = SpriteType::Font;
 
		return GetRawSprite(sprite, sc->type, allocator);
 
	}
 

	
 
	byte warning_level = sc->warned ? 6 : 0;
 
	sc->warned = true;
 
	Debug(sprite, warning_level, "Tried to load {} sprite #{} as a {} sprite. Probable cause: NewGRF interference", sprite_types[available], sprite, sprite_types[requested]);
 
	Debug(sprite, warning_level, "Tried to load {} sprite #{} as a {} sprite. Probable cause: NewGRF interference", sprite_types[static_cast<byte>(available)], sprite, sprite_types[static_cast<byte>(requested)]);
 

	
 
	switch (requested) {
 
		case ST_NORMAL:
 
		case SpriteType::Normal:
 
			if (sprite == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non-normal sprite?");
 
			FALLTHROUGH;
 
		case ST_FONT:
 
			return GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator);
 
		case ST_RECOLOUR:
 
		case SpriteType::Font:
 
			return GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator);
 
		case SpriteType::Recolour:
 
			if (sprite == PALETTE_TO_DARK_BLUE) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'PALETTE_TO_DARK_BLUE' sprite a non-remap sprite?");
 
			return GetRawSprite(PALETTE_TO_DARK_BLUE, ST_RECOLOUR, allocator);
 
		case ST_MAPGEN:
 
			/* this shouldn't happen, overriding of ST_MAPGEN sprites is checked in LoadNextSprite()
 
			return GetRawSprite(PALETTE_TO_DARK_BLUE, SpriteType::Recolour, allocator);
 
		case SpriteType::MapGen:
 
			/* this shouldn't happen, overriding of SpriteType::MapGen sprites is checked in LoadNextSprite()
 
			 * (the only case the check fails is when these sprites weren't even loaded...) */
 
		default:
 
			NOT_REACHED();
 
	}
 
}
 

	
 
@@ -939,14 +939,14 @@ static void *HandleInvalidSpriteRequest(
 
 * @param allocator Allocator function to use. Set to nullptr to use the usual sprite cache.
 
 * @param encoder Sprite encoder to use. Set to nullptr to use the currently active blitter.
 
 * @return Sprite raw data
 
 */
 
void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator, SpriteEncoder *encoder)
 
{
 
	assert(type != ST_MAPGEN || IsMapgenSpriteID(sprite));
 
	assert(type < ST_INVALID);
 
	assert(type != SpriteType::MapGen || IsMapgenSpriteID(sprite));
 
	assert(type < SpriteType::Invalid);
 

	
 
	if (!SpriteExists(sprite)) {
 
		Debug(sprite, 1, "Tried to load non-existing sprite #{}. Probable cause: Wrong/missing NewGRFs", sprite);
 

	
 
		/* SPR_IMG_QUERY is a BIG FAT RED ? */
 
		sprite = SPR_IMG_QUERY;
 
@@ -1039,13 +1039,13 @@ void GfxInitSpriteMem()
 
 */
 
void GfxClearSpriteCache()
 
{
 
	/* Clear sprite ptr for all cached items */
 
	for (uint i = 0; i != _spritecache_items; i++) {
 
		SpriteCache *sc = GetSpriteCache(i);
 
		if (sc->type != ST_RECOLOUR && sc->ptr != nullptr) DeleteEntryFromSpriteCache(i);
 
		if (sc->type != SpriteType::Recolour && sc->ptr != nullptr) DeleteEntryFromSpriteCache(i);
 
	}
 

	
 
	VideoDriver::GetInstance()->ClearSystemSprites();
 
}
 

	
 
/* static */ ReusableBuffer<SpriteLoader::CommonPixel> SpriteLoader::Sprite::buffer[ZOOM_LVL_COUNT];
src/spritecache.h
Show inline comments
 
@@ -43,19 +43,19 @@ uint32 GetSpriteLocalID(SpriteID sprite)
 
uint GetSpriteCountForFile(const std::string &filename, SpriteID begin, SpriteID end);
 
uint GetMaxSpriteID();
 

	
 

	
 
static inline const Sprite *GetSprite(SpriteID sprite, SpriteType type)
 
{
 
	assert(type != ST_RECOLOUR);
 
	assert(type != SpriteType::Recolour);
 
	return (Sprite*)GetRawSprite(sprite, type);
 
}
 

	
 
static inline const byte *GetNonSprite(SpriteID sprite, SpriteType type)
 
{
 
	assert(type == ST_RECOLOUR);
 
	assert(type == SpriteType::Recolour);
 
	return (byte*)GetRawSprite(sprite, type);
 
}
 

	
 
void GfxInitSpriteMem();
 
void GfxClearSpriteCache();
 
void IncreaseSpriteLRU();
src/spriteloader/grf.cpp
Show inline comments
 
@@ -161,14 +161,14 @@ bool DecodeSingleSprite(SpriteLoader::Sp
 
						data->g = *dest++;
 
						data->b = *dest++;
 
					}
 
					data->a = (colour_fmt & SCC_ALPHA) ? *dest++ : 0xFF;
 
					if (colour_fmt & SCC_PAL) {
 
						switch (sprite_type) {
 
							case ST_NORMAL: data->m = file.NeedsPaletteRemap() ? _palmap_w2d[*dest] : *dest; break;
 
							case ST_FONT:   data->m = std::min<uint>(*dest, 2u); break;
 
							case SpriteType::Normal: data->m = file.NeedsPaletteRemap() ? _palmap_w2d[*dest] : *dest; break;
 
							case SpriteType::Font:   data->m = std::min<uint>(*dest, 2u); break;
 
							default:        data->m = *dest; break;
 
						}
 
						/* Magic blue. */
 
						if (colour_fmt == SCC_PAL && *dest == 0) data->a = 0x00;
 
						dest++;
 
					}
 
@@ -198,14 +198,14 @@ bool DecodeSingleSprite(SpriteLoader::Sp
 
				sprite->data[i].g = *pixel++;
 
				sprite->data[i].b = *pixel++;
 
			}
 
			sprite->data[i].a = (colour_fmt & SCC_ALPHA) ? *pixel++ : 0xFF;
 
			if (colour_fmt & SCC_PAL) {
 
				switch (sprite_type) {
 
					case ST_NORMAL: sprite->data[i].m = file.NeedsPaletteRemap() ? _palmap_w2d[*pixel] : *pixel; break;
 
					case ST_FONT:   sprite->data[i].m = std::min<uint>(*pixel, 2u); break;
 
					case SpriteType::Normal: sprite->data[i].m = file.NeedsPaletteRemap() ? _palmap_w2d[*pixel] : *pixel; break;
 
					case SpriteType::Font:   sprite->data[i].m = std::min<uint>(*pixel, 2u); break;
 
					default:        sprite->data[i].m = *pixel; break;
 
				}
 
				/* Magic blue. */
 
				if (colour_fmt == SCC_PAL && *pixel == 0) sprite->data[i].a = 0x00;
 
				pixel++;
 
			}
 
@@ -227,13 +227,13 @@ uint8 LoadSpriteV1(SpriteLoader::Sprite 
 
	int num = file.ReadWord();
 
	byte type = file.ReadByte();
 

	
 
	/* Type 0xFF indicates either a colourmap or some other non-sprite info; we do not handle them here */
 
	if (type == 0xFF) return 0;
 

	
 
	ZoomLevel zoom_lvl = (sprite_type != ST_MAPGEN) ? ZOOM_LVL_OUT_4X : ZOOM_LVL_NORMAL;
 
	ZoomLevel zoom_lvl = (sprite_type != SpriteType::MapGen) ? ZOOM_LVL_OUT_4X : ZOOM_LVL_NORMAL;
 

	
 
	sprite[zoom_lvl].height = file.ReadByte();
 
	sprite[zoom_lvl].width  = file.ReadWord();
 
	sprite[zoom_lvl].x_offs = file.ReadWord();
 
	sprite[zoom_lvl].y_offs = file.ReadWord();
 
	sprite[zoom_lvl].colours = SCC_PAL;
 
@@ -276,13 +276,13 @@ uint8 LoadSpriteV2(SpriteLoader::Sprite 
 
		byte colour = type & SCC_MASK;
 
		byte zoom = file.ReadByte();
 

	
 
		bool is_wanted_colour_depth = (colour != 0 && (load_32bpp ? colour != SCC_PAL : colour == SCC_PAL));
 
		bool is_wanted_zoom_lvl;
 

	
 
		if (sprite_type != ST_MAPGEN) {
 
		if (sprite_type != SpriteType::MapGen) {
 
			if (zoom < lengthof(zoom_lvl_map)) {
 
				is_wanted_zoom_lvl = true;
 
				if (_settings_client.gui.sprite_zoom_min >= ZOOM_LVL_OUT_2X &&
 
						HasBit(control_flags, load_32bpp ? SCCF_ALLOW_ZOOM_MIN_2X_32BPP : SCCF_ALLOW_ZOOM_MIN_2X_PAL) && zoom_lvl_map[zoom] < ZOOM_LVL_OUT_2X) {
 
					is_wanted_zoom_lvl = false;
 
				}
 
@@ -295,13 +295,13 @@ uint8 LoadSpriteV2(SpriteLoader::Sprite 
 
			}
 
		} else {
 
			is_wanted_zoom_lvl = (zoom == 0);
 
		}
 

	
 
		if (is_wanted_colour_depth && is_wanted_zoom_lvl) {
 
			ZoomLevel zoom_lvl = (sprite_type != ST_MAPGEN) ? zoom_lvl_map[zoom] : ZOOM_LVL_NORMAL;
 
			ZoomLevel zoom_lvl = (sprite_type != SpriteType::MapGen) ? zoom_lvl_map[zoom] : ZOOM_LVL_NORMAL;
 

	
 
			if (HasBit(loaded_sprites, zoom_lvl)) {
 
				/* We already have this zoom level, skip sprite. */
 
				Debug(sprite, 1, "Ignoring duplicate zoom level sprite {} from {}", id, file.GetSimplifiedFilename());
 
				file.SkipBytes(num - 2);
 
				continue;
src/station_gui.cpp
Show inline comments
 
@@ -828,23 +828,23 @@ enum SortOrder {
 
	SO_DESCENDING,
 
	SO_ASCENDING
 
};
 

	
 
class CargoDataEntry;
 

	
 
enum CargoSortType {
 
	ST_AS_GROUPING,    ///< by the same principle the entries are being grouped
 
	ST_COUNT,          ///< by amount of cargo
 
	ST_STATION_STRING, ///< by station name
 
	ST_STATION_ID,     ///< by station id
 
	ST_CARGO_ID,       ///< by cargo id
 
enum class CargoSortType : byte {
 
	AsGrouping,    ///< by the same principle the entries are being grouped
 
	Count,         ///< by amount of cargo
 
	StationString, ///< by station name
 
	StationID,     ///< by station id
 
	CargoID,       ///< by cargo id
 
};
 

	
 
class CargoSorter {
 
public:
 
	CargoSorter(CargoSortType t = ST_STATION_ID, SortOrder o = SO_ASCENDING) : type(t), order(o) {}
 
	CargoSorter(CargoSortType t = CargoSortType::StationID, SortOrder o = SO_ASCENDING) : type(t), order(o) {}
 
	CargoSortType GetSortType() {return this->type;}
 
	bool operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
 

	
 
private:
 
	CargoSortType type;
 
	SortOrder order;
 
@@ -1009,13 +1009,13 @@ private:
 

	
 
CargoDataEntry::CargoDataEntry() :
 
	parent(nullptr),
 
	station(INVALID_STATION),
 
	num_children(0),
 
	count(0),
 
	children(new CargoDataSet(CargoSorter(ST_CARGO_ID)))
 
	children(new CargoDataSet(CargoSorter(CargoSortType::CargoID)))
 
{}
 

	
 
CargoDataEntry::CargoDataEntry(CargoID cargo, uint count, CargoDataEntry *parent) :
 
	parent(parent),
 
	cargo(cargo),
 
	num_children(0),
 
@@ -1098,13 +1098,13 @@ CargoDataEntry *CargoDataEntry::InsertOr
 
	CargoDataSet::iterator i = this->children->find(&tmp);
 
	if (i == this->children->end()) {
 
		IncrementSize();
 
		return *(this->children->insert(new CargoDataEntry(child_id, 0, this)).first);
 
	} else {
 
		CargoDataEntry *ret = *i;
 
		assert(this->children->value_comp().GetSortType() != ST_COUNT);
 
		assert(this->children->value_comp().GetSortType() != CargoSortType::Count);
 
		return ret;
 
	}
 
}
 

	
 
/**
 
 * Update the count for this entry and propagate the change to the parent entry
 
@@ -1135,27 +1135,27 @@ void CargoDataEntry::Resort(CargoSortTyp
 

	
 
CargoDataEntry *CargoDataEntry::Retrieve(CargoDataSet::iterator i) const
 
{
 
	if (i == this->children->end()) {
 
		return nullptr;
 
	} else {
 
		assert(this->children->value_comp().GetSortType() != ST_COUNT);
 
		assert(this->children->value_comp().GetSortType() != CargoSortType::Count);
 
		return *i;
 
	}
 
}
 

	
 
bool CargoSorter::operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const
 
{
 
	switch (this->type) {
 
		case ST_STATION_ID:
 
		case CargoSortType::StationID:
 
			return this->SortId<StationID>(cd1->GetStation(), cd2->GetStation());
 
		case ST_CARGO_ID:
 
		case CargoSortType::CargoID:
 
			return this->SortId<CargoID>(cd1->GetCargo(), cd2->GetCargo());
 
		case ST_COUNT:
 
		case CargoSortType::Count:
 
			return this->SortCount(cd1, cd2);
 
		case ST_STATION_STRING:
 
		case CargoSortType::StationString:
 
			return this->SortStation(cd1->GetStation(), cd2->GetStation());
 
		default:
 
			NOT_REACHED();
 
	}
 
}
 

	
 
@@ -1265,13 +1265,13 @@ struct StationViewWindow : public Window
 

	
 
	static const StringID _sort_names[];  ///< Names of the sorting options in the dropdown.
 
	static const StringID _group_names[]; ///< Names of the grouping options in the dropdown.
 

	
 
	/**
 
	 * Sort types of the different 'columns'.
 
	 * In fact only ST_COUNT and ST_AS_GROUPING are active and you can only
 
	 * In fact only CargoSortType::Count and CargoSortType::AsGrouping are active and you can only
 
	 * sort all the columns in the same way. The other options haven't been
 
	 * included in the GUI due to lack of space.
 
	 */
 
	CargoSortType sortings[NUM_COLUMNS];
 

	
 
	/** Sort order (ascending/descending) for the 'columns'. */
 
@@ -1295,13 +1295,13 @@ struct StationViewWindow : public Window
 
		this->CreateNestedTree();
 
		this->vscroll = this->GetScrollbar(WID_SV_SCROLLBAR);
 
		/* Nested widget tree creation is done in two steps to ensure that this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS) exists in UpdateWidgetSize(). */
 
		this->FinishInitNested(window_number);
 

	
 
		this->groupings[0] = GR_CARGO;
 
		this->sortings[0] = ST_AS_GROUPING;
 
		this->sortings[0] = CargoSortType::AsGrouping;
 
		this->SelectGroupBy(_settings_client.gui.station_gui_group_order);
 
		this->SelectSortBy(_settings_client.gui.station_gui_sort_by);
 
		this->sort_orders[0] = SO_ASCENDING;
 
		this->SelectSortOrder((SortOrder)_settings_client.gui.station_gui_sort_order);
 
		this->owner = Station::Get(window_number)->owner;
 
	}
 
@@ -1712,18 +1712,18 @@ struct StationViewWindow : public Window
 
	 * @param column Current "column" being drawn.
 
	 * @param cargo Current cargo being drawn (if cargo column has been passed).
 
	 * @return row (in "pos" counting) after the one we have last drawn to.
 
	 */
 
	int DrawEntries(CargoDataEntry *entry, const Rect &r, int pos, int maxrows, int column, CargoID cargo = CT_INVALID)
 
	{
 
		if (this->sortings[column] == ST_AS_GROUPING) {
 
		if (this->sortings[column] == CargoSortType::AsGrouping) {
 
			if (this->groupings[column] != GR_CARGO) {
 
				entry->Resort(ST_STATION_STRING, this->sort_orders[column]);
 
				entry->Resort(CargoSortType::StationString, this->sort_orders[column]);
 
			}
 
		} else {
 
			entry->Resort(ST_COUNT, this->sort_orders[column]);
 
			entry->Resort(CargoSortType::Count, this->sort_orders[column]);
 
		}
 
		for (CargoDataSet::iterator i = entry->Begin(); i != entry->End(); ++i) {
 
			CargoDataEntry *cd = *i;
 

	
 
			Grouping grouping = this->groupings[column];
 
			if (grouping == GR_CARGO) cargo = cd->GetCargo();
 
@@ -1937,13 +1937,13 @@ struct StationViewWindow : public Window
 
			case WID_SV_SORT_BY: {
 
				/* The initial selection is composed of current mode and
 
				 * sorting criteria for columns 1, 2, and 3. Column 0 is always
 
				 * sorted by cargo ID. The others can theoretically be sorted
 
				 * by different things but there is no UI for that. */
 
				ShowDropDownMenu(this, _sort_names,
 
						this->current_mode * 2 + (this->sortings[1] == ST_COUNT ? 1 : 0),
 
						this->current_mode * 2 + (this->sortings[1] == CargoSortType::Count ? 1 : 0),
 
						WID_SV_SORT_BY, 0, 0);
 
				break;
 
			}
 

	
 
			case WID_SV_GROUP_BY: {
 
				ShowDropDownMenu(this, _group_names, this->grouping_index, WID_SV_GROUP_BY, 0, 0);
 
@@ -1977,25 +1977,25 @@ struct StationViewWindow : public Window
 
	void SelectSortBy(int index)
 
	{
 
		_settings_client.gui.station_gui_sort_by = index;
 
		switch (_sort_names[index]) {
 
			case STR_STATION_VIEW_WAITING_STATION:
 
				this->current_mode = MODE_WAITING;
 
				this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_AS_GROUPING;
 
				this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::AsGrouping;
 
				break;
 
			case STR_STATION_VIEW_WAITING_AMOUNT:
 
				this->current_mode = MODE_WAITING;
 
				this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_COUNT;
 
				this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::Count;
 
				break;
 
			case STR_STATION_VIEW_PLANNED_STATION:
 
				this->current_mode = MODE_PLANNED;
 
				this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_AS_GROUPING;
 
				this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::AsGrouping;
 
				break;
 
			case STR_STATION_VIEW_PLANNED_AMOUNT:
 
				this->current_mode = MODE_PLANNED;
 
				this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_COUNT;
 
				this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::Count;
 
				break;
 
			default:
 
				NOT_REACHED();
 
		}
 
		/* Display the current sort variant */
 
		this->GetWidget<NWidgetCore>(WID_SV_SORT_BY)->widget_data = _sort_names[index];
src/subsidy.cpp
Show inline comments
 
@@ -79,30 +79,30 @@ std::pair<NewsReferenceType, NewsReferen
 

	
 
	/* Always use the plural form of the cargo name - trying to decide between plural or singular causes issues for translations */
 
	const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
 
	SetDParam(parameter_offset, cs->name);
 

	
 
	switch (s->src_type) {
 
		case ST_INDUSTRY:
 
		case SourceType::Industry:
 
			reftype1 = NR_INDUSTRY;
 
			SetDParam(parameter_offset + 1, STR_INDUSTRY_NAME);
 
			break;
 
		case ST_TOWN:
 
		case SourceType::Town:
 
			reftype1 = NR_TOWN;
 
			SetDParam(parameter_offset + 1, STR_TOWN_NAME);
 
			break;
 
		default: NOT_REACHED();
 
	}
 
	SetDParam(parameter_offset + 2, s->src);
 

	
 
	switch (s->dst_type) {
 
		case ST_INDUSTRY:
 
		case SourceType::Industry:
 
			reftype2 = NR_INDUSTRY;
 
			SetDParam(parameter_offset + 4, STR_INDUSTRY_NAME);
 
			break;
 
		case ST_TOWN:
 
		case SourceType::Town:
 
			reftype2 = NR_TOWN;
 
			SetDParam(parameter_offset + 4, STR_TOWN_NAME);
 
			break;
 
		default: NOT_REACHED();
 
	}
 
	SetDParam(parameter_offset + 5, s->dst);
 
@@ -121,14 +121,14 @@ std::pair<NewsReferenceType, NewsReferen
 
 * @param index index of town/industry
 
 * @param flag flag to set
 
 */
 
static inline void SetPartOfSubsidyFlag(SourceType type, SourceID index, PartOfSubsidy flag)
 
{
 
	switch (type) {
 
		case ST_INDUSTRY: Industry::Get(index)->part_of_subsidy |= flag; return;
 
		case ST_TOWN:   Town::Get(index)->cache.part_of_subsidy |= flag; return;
 
		case SourceType::Industry: Industry::Get(index)->part_of_subsidy |= flag; return;
 
		case SourceType::Town:   Town::Get(index)->cache.part_of_subsidy |= flag; return;
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/** Perform a full rebuild of the subsidies cache. */
 
void RebuildSubsidisedSourceAndDestinationCache()
 
@@ -193,14 +193,14 @@ static bool CheckSubsidyDuplicate(CargoI
 
 * @param dst_type Type of \a dst.
 
 * @param dst      Index of destination.
 
 * @return True if they are inside the distance limit.
 
 */
 
static bool CheckSubsidyDistance(SourceType src_type, SourceID src, SourceType dst_type, SourceID dst)
 
{
 
	TileIndex tile_src = (src_type == ST_TOWN) ? Town::Get(src)->xy : Industry::Get(src)->location.tile;
 
	TileIndex tile_dst = (dst_type == ST_TOWN) ? Town::Get(dst)->xy : Industry::Get(dst)->location.tile;
 
	TileIndex tile_src = (src_type == SourceType::Town) ? Town::Get(src)->xy : Industry::Get(src)->location.tile;
 
	TileIndex tile_dst = (dst_type == SourceType::Town) ? Town::Get(dst)->xy : Industry::Get(dst)->location.tile;
 

	
 
	return (DistanceManhattan(tile_src, tile_dst) <= SUBSIDY_MAX_DISTANCE);
 
}
 

	
 
/**
 
 * Creates a subsidy with the given parameters.
 
@@ -247,26 +247,26 @@ CommandCost CmdCreateSubsidy(DoCommandFl
 

	
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 

	
 
	if (cid >= NUM_CARGO || !::CargoSpec::Get(cid)->IsValid()) return CMD_ERROR;
 

	
 
	switch (src_type) {
 
		case ST_TOWN:
 
		case SourceType::Town:
 
			if (!Town::IsValidID(src)) return CMD_ERROR;
 
			break;
 
		case ST_INDUSTRY:
 
		case SourceType::Industry:
 
			if (!Industry::IsValidID(src)) return CMD_ERROR;
 
			break;
 
		default:
 
			return CMD_ERROR;
 
	}
 
	switch (dst_type) {
 
		case ST_TOWN:
 
		case SourceType::Town:
 
			if (!Town::IsValidID(dst)) return CMD_ERROR;
 
			break;
 
		case ST_INDUSTRY:
 
		case SourceType::Industry:
 
			if (!Industry::IsValidID(dst)) return CMD_ERROR;
 
			break;
 
		default:
 
			return CMD_ERROR;
 
	}
 

	
 
@@ -294,15 +294,15 @@ bool FindSubsidyPassengerRoute()
 
	const Town *dst = Town::GetRandom();
 
	if (dst->cache.population < SUBSIDY_PAX_MIN_POPULATION || src == dst) {
 
		return false;
 
	}
 

	
 
	if (DistanceManhattan(src->xy, dst->xy) > SUBSIDY_MAX_DISTANCE) return false;
 
	if (CheckSubsidyDuplicate(CT_PASSENGERS, ST_TOWN, src->index, ST_TOWN, dst->index)) return false;
 
	if (CheckSubsidyDuplicate(CT_PASSENGERS, SourceType::Town, src->index, SourceType::Town, dst->index)) return false;
 

	
 
	CreateSubsidy(CT_PASSENGERS, ST_TOWN, src->index, ST_TOWN, dst->index);
 
	CreateSubsidy(CT_PASSENGERS, SourceType::Town, src->index, SourceType::Town, dst->index);
 

	
 
	return true;
 
}
 

	
 
bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src);
 

	
 
@@ -312,13 +312,13 @@ bool FindSubsidyCargoDestination(CargoID
 
 * @return True iff the subsidy was created.
 
 */
 
bool FindSubsidyTownCargoRoute()
 
{
 
	if (!Subsidy::CanAllocateItem()) return false;
 

	
 
	SourceType src_type = ST_TOWN;
 
	SourceType src_type = SourceType::Town;
 

	
 
	/* Select a random town. */
 
	const Town *src_town = Town::GetRandom();
 
	if (src_town->cache.population < SUBSIDY_CARGO_MIN_POPULATION) return false;
 

	
 
	/* Calculate the produced cargo of houses around town center. */
 
@@ -370,13 +370,13 @@ bool FindSubsidyTownCargoRoute()
 
 * @return True iff the subsidy was created.
 
 */
 
bool FindSubsidyIndustryCargoRoute()
 
{
 
	if (!Subsidy::CanAllocateItem()) return false;
 

	
 
	SourceType src_type = ST_INDUSTRY;
 
	SourceType src_type = SourceType::Industry;
 

	
 
	/* Select a random industry. */
 
	const Industry *src_ind = Industry::GetRandom();
 
	if (src_ind == nullptr) return false;
 

	
 
	uint trans, total;
 
@@ -421,17 +421,17 @@ bool FindSubsidyIndustryCargoRoute()
 
 * @param src      Index of source.
 
 * @return True iff the subsidy was created.
 
 */
 
bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src)
 
{
 
	/* Choose a random destination. */
 
	SourceType dst_type = Chance16(1, 2) ? ST_TOWN : ST_INDUSTRY;
 
	SourceType dst_type = Chance16(1, 2) ? SourceType::Town : SourceType::Industry;
 

	
 
	SourceID dst;
 
	switch (dst_type) {
 
		case ST_TOWN: {
 
		case SourceType::Town: {
 
			/* Select a random town. */
 
			const Town *dst_town = Town::GetRandom();
 

	
 
			/* Calculate cargo acceptance of houses around town center. */
 
			CargoArray town_cargo_accepted;
 
			TileArea ta = TileArea(dst_town->xy, 1, 1).Expand(SUBSIDY_TOWN_CARGO_RADIUS);
 
@@ -445,13 +445,13 @@ bool FindSubsidyCargoDestination(CargoID
 
			if (town_cargo_accepted[cid] < 8) return false;
 

	
 
			dst = dst_town->index;
 
			break;
 
		}
 

	
 
		case ST_INDUSTRY: {
 
		case SourceType::Industry: {
 
			/* Select a random industry. */
 
			const Industry *dst_ind = Industry::GetRandom();
 
			if (dst_ind == nullptr) return false;
 

	
 
			/* The industry must accept the cargo */
 
			bool valid = std::find(dst_ind->accepts_cargo, endof(dst_ind->accepts_cargo), cid) != endof(dst_ind->accepts_cargo);
 
@@ -562,28 +562,28 @@ static IntervalTimer<TimerGameCalendar> 
 
 */
 
bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type, SourceID src, const Station *st)
 
{
 
	/* If the source isn't subsidised, don't continue */
 
	if (src == INVALID_SOURCE) return false;
 
	switch (src_type) {
 
		case ST_INDUSTRY:
 
		case SourceType::Industry:
 
			if (!(Industry::Get(src)->part_of_subsidy & POS_SRC)) return false;
 
			break;
 
		case ST_TOWN:
 
		case SourceType::Town:
 
			if (!(Town::Get(src)->cache.part_of_subsidy & POS_SRC)) return false;
 
			break;
 
		default: return false;
 
	}
 

	
 
	/* Remember all towns near this station (at least one house in its catchment radius)
 
	 * which are destination of subsidised path. Do that only if needed */
 
	std::vector<const Town *> towns_near;
 
	if (!st->rect.IsEmpty()) {
 
		for (const Subsidy *s : Subsidy::Iterate()) {
 
			/* Don't create the cache if there is no applicable subsidy with town as destination */
 
			if (s->dst_type != ST_TOWN) continue;
 
			if (s->dst_type != SourceType::Town) continue;
 
			if (s->cargo_type != cargo_type || s->src_type != src_type || s->src != src) continue;
 
			if (s->IsAwarded() && s->awarded != company) continue;
 

	
 
			BitmapTileIterator it(st->catchment_tiles);
 
			for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
 
				if (!IsTileType(tile, MP_HOUSE)) continue;
 
@@ -598,22 +598,22 @@ bool CheckSubsidised(CargoID cargo_type,
 

	
 
	/* Check if there's a (new) subsidy that applies. There can be more subsidies triggered by this delivery!
 
	 * Think about the case that subsidies are A->B and A->C and station has both B and C in its catchment area */
 
	for (Subsidy *s : Subsidy::Iterate()) {
 
		if (s->cargo_type == cargo_type && s->src_type == src_type && s->src == src && (!s->IsAwarded() || s->awarded == company)) {
 
			switch (s->dst_type) {
 
				case ST_INDUSTRY:
 
				case SourceType::Industry:
 
					for (const auto &i : st->industries_near) {
 
						if (s->dst == i.industry->index) {
 
							assert(i.industry->part_of_subsidy & POS_DST);
 
							subsidised = true;
 
							if (!s->IsAwarded()) s->AwardTo(company);
 
						}
 
					}
 
					break;
 
				case ST_TOWN:
 
				case SourceType::Town:
 
					for (const Town *tp : towns_near) {
 
						if (s->dst == tp->index) {
 
							assert(tp->cache.part_of_subsidy & POS_DST);
 
							subsidised = true;
 
							if (!s->IsAwarded()) s->AwardTo(company);
 
						}
src/subsidy_base.h
Show inline comments
 
@@ -20,14 +20,14 @@ extern SubsidyPool _subsidy_pool;
 

	
 
/** Struct about subsidies, offered and awarded */
 
struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> {
 
	CargoID cargo_type;  ///< Cargo type involved in this subsidy, CT_INVALID for invalid subsidy
 
	uint16 remaining;    ///< Remaining months when this subsidy is valid
 
	CompanyID awarded;   ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone
 
	SourceType src_type; ///< Source of subsidised path (ST_INDUSTRY or ST_TOWN)
 
	SourceType dst_type; ///< Destination of subsidised path (ST_INDUSTRY or ST_TOWN)
 
	SourceType src_type; ///< Source of subsidised path (SourceType::Industry or SourceType::Town)
 
	SourceType dst_type; ///< Destination of subsidised path (SourceType::Industry or SourceType::Town)
 
	SourceID src;        ///< Index of source. Either TownID or IndustryID
 
	SourceID dst;        ///< Index of destination. Either TownID or IndustryID
 

	
 
	/**
 
	 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
 
	 */
src/subsidy_gui.cpp
Show inline comments
 
@@ -74,24 +74,24 @@ struct SubsidyListWindow : Window {
 

	
 
	void HandleClick(const Subsidy *s)
 
	{
 
		/* determine src coordinate for subsidy and try to scroll to it */
 
		TileIndex xy;
 
		switch (s->src_type) {
 
			case ST_INDUSTRY: xy = Industry::Get(s->src)->location.tile; break;
 
			case ST_TOWN:     xy =     Town::Get(s->src)->xy; break;
 
			case SourceType::Industry: xy = Industry::Get(s->src)->location.tile; break;
 
			case SourceType::Town:     xy =     Town::Get(s->src)->xy; break;
 
			default: NOT_REACHED();
 
		}
 

	
 
		if (_ctrl_pressed || !ScrollMainWindowToTile(xy)) {
 
			if (_ctrl_pressed) ShowExtraViewportWindow(xy);
 

	
 
			/* otherwise determine dst coordinate for subsidy and scroll to it */
 
			switch (s->dst_type) {
 
				case ST_INDUSTRY: xy = Industry::Get(s->dst)->location.tile; break;
 
				case ST_TOWN:     xy =     Town::Get(s->dst)->xy; break;
 
				case SourceType::Industry: xy = Industry::Get(s->dst)->location.tile; break;
 
				case SourceType::Town:     xy =     Town::Get(s->dst)->xy; break;
 
				default: NOT_REACHED();
 
			}
 

	
 
			if (_ctrl_pressed) {
 
				ShowExtraViewportWindow(xy);
 
			} else {
src/town_cmd.cpp
Show inline comments
 
@@ -142,15 +142,15 @@ Town::~Town()
 
		}
 
	}
 

	
 
	/* Clear the persistent storage list. */
 
	this->psa_list.clear();
 

	
 
	DeleteSubsidyWith(ST_TOWN, this->index);
 
	DeleteSubsidyWith(SourceType::Town, this->index);
 
	DeleteNewGRFInspectWindow(GSF_FAKE_TOWNS, this->index);
 
	CargoPacket::InvalidateAllFrom(ST_TOWN, this->index);
 
	CargoPacket::InvalidateAllFrom(SourceType::Town, this->index);
 
	MarkWholeScreenDirty();
 
}
 

	
 

	
 
/**
 
 * Invalidating of the "nearest town cache" has to be done
 
@@ -563,13 +563,13 @@ static void TileLoop_Town(TileIndex tile
 
			CargoID cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grf_prop.grffile);
 
			if (cargo == CT_INVALID) continue;
 

	
 
			uint amt = GB(callback, 0, 8);
 
			if (amt == 0) continue;
 

	
 
			uint moved = MoveGoodsToStation(cargo, amt, ST_TOWN, t->index, stations.GetStations());
 
			uint moved = MoveGoodsToStation(cargo, amt, SourceType::Town, t->index, stations.GetStations());
 

	
 
			const CargoSpec *cs = CargoSpec::Get(cargo);
 
			t->supplied[cs->Index()].new_max += amt;
 
			t->supplied[cs->Index()].new_act += moved;
 
		}
 
	} else {
 
@@ -578,21 +578,21 @@ static void TileLoop_Town(TileIndex tile
 
				/* Original (quadratic) cargo generation algorithm */
 
				if (GB(r, 0, 8) < hs->population) {
 
					uint amt = GB(r, 0, 8) / 8 + 1;
 

	
 
					if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
 
					t->supplied[CT_PASSENGERS].new_max += amt;
 
					t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amt, ST_TOWN, t->index, stations.GetStations());
 
					t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amt, SourceType::Town, t->index, stations.GetStations());
 
				}
 

	
 
				if (GB(r, 8, 8) < hs->mail_generation) {
 
					uint amt = GB(r, 8, 8) / 8 + 1;
 

	
 
					if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
 
					t->supplied[CT_MAIL].new_max += amt;
 
					t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amt, ST_TOWN, t->index, stations.GetStations());
 
					t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amt, SourceType::Town, t->index, stations.GetStations());
 
				}
 
				break;
 

	
 
			case TCGM_BITCOUNT:
 
				/* Binomial distribution per tick, by a series of coin flips */
 
				/* Reduce generation rate to a 1/4, using tile bits to spread out distribution.
 
@@ -603,22 +603,22 @@ static void TileLoop_Town(TileIndex tile
 
					uint32 genmask = (genmax >= 32) ? 0xFFFFFFFF : ((1 << genmax) - 1);
 
					/* Mask random value by potential pax and count number of actual pax */
 
					uint amt = CountBits(r & genmask);
 
					/* Adjust and apply */
 
					if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
 
					t->supplied[CT_PASSENGERS].new_max += amt;
 
					t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amt, ST_TOWN, t->index, stations.GetStations());
 
					t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amt, SourceType::Town, t->index, stations.GetStations());
 

	
 
					/* Do the same for mail, with a fresh random */
 
					r = Random();
 
					genmax = (hs->mail_generation + 7) / 8;
 
					genmask = (genmax >= 32) ? 0xFFFFFFFF : ((1 << genmax) - 1);
 
					amt = CountBits(r & genmask);
 
					if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
 
					t->supplied[CT_MAIL].new_max += amt;
 
					t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amt, ST_TOWN, t->index, stations.GetStations());
 
					t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amt, SourceType::Town, t->index, stations.GetStations());
 
				}
 
				break;
 

	
 
			default:
 
				NOT_REACHED();
 
		}
src/vehicle.cpp
Show inline comments
 
@@ -99,13 +99,13 @@ INSTANTIATE_POOL_METHODS(Vehicle)
 
 * @param[out] bounds Shared bounds.
 
 */
 
void VehicleSpriteSeq::GetBounds(Rect *bounds) const
 
{
 
	bounds->left = bounds->top = bounds->right = bounds->bottom = 0;
 
	for (uint i = 0; i < this->count; ++i) {
 
		const Sprite *spr = GetSprite(this->seq[i].sprite, ST_NORMAL);
 
		const Sprite *spr = GetSprite(this->seq[i].sprite, SpriteType::Normal);
 
		if (i == 0) {
 
			bounds->left = spr->x_offs;
 
			bounds->top  = spr->y_offs;
 
			bounds->right  = spr->width  + spr->x_offs - 1;
 
			bounds->bottom = spr->height + spr->y_offs - 1;
 
		} else {
src/video/opengl.cpp
Show inline comments
 
@@ -1111,13 +1111,13 @@ void OpenGLBackend::PopulateCursorCache(
 
	for (uint i = 0; i < _cursor.sprite_count; ++i) {
 
		this->cursor_sprite_seq[i] = _cursor.sprite_seq[i];
 
		this->cursor_sprite_pos[i] = _cursor.sprite_pos[i];
 
		SpriteID sprite = _cursor.sprite_seq[i].sprite;
 

	
 
		if (!this->cursor_cache.Contains(sprite)) {
 
			Sprite *old = this->cursor_cache.Insert(sprite, (Sprite *)GetRawSprite(sprite, ST_NORMAL, &SimpleSpriteAlloc, this));
 
			Sprite *old = this->cursor_cache.Insert(sprite, (Sprite *)GetRawSprite(sprite, SpriteType::Normal, &SimpleSpriteAlloc, this));
 
			if (old != nullptr) {
 
				OpenGLSprite *gl_sprite = (OpenGLSprite *)old->data;
 
				gl_sprite->~OpenGLSprite();
 
				free(old);
 
			}
 
		}
 
@@ -1269,16 +1269,16 @@ void OpenGLBackend::ReleaseAnimBuffer(co
 
/* virtual */ Sprite *OpenGLBackend::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
 
{
 
	/* Allocate and construct sprite data. */
 
	Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(OpenGLSprite));
 

	
 
	OpenGLSprite *gl_sprite = (OpenGLSprite *)dest_sprite->data;
 
	new (gl_sprite) OpenGLSprite(sprite->width, sprite->height, sprite->type == ST_FONT ? 1 : ZOOM_LVL_COUNT, sprite->colours);
 
	new (gl_sprite) OpenGLSprite(sprite->width, sprite->height, sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_COUNT, sprite->colours);
 

	
 
	/* Upload texture data. */
 
	for (int i = 0; i < (sprite->type == ST_FONT ? 1 : ZOOM_LVL_COUNT); i++) {
 
	for (int i = 0; i < (sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_COUNT); i++) {
 
		gl_sprite->Update(sprite[i].width, sprite[i].height, i, sprite[i].data);
 
	}
 

	
 
	dest_sprite->height = sprite->height;
 
	dest_sprite->width  = sprite->width;
 
	dest_sprite->x_offs = sprite->x_offs;
 
@@ -1307,13 +1307,13 @@ void OpenGLBackend::RenderOglSprite(Open
 
		_glBindTexture(GL_TEXTURE_1D, OpenGLSprite::pal_tex);
 
		if (pal != this->last_sprite_pal) {
 
			/* Different remap palette in use, update texture. */
 
			_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, OpenGLSprite::pal_pbo);
 
			_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
 

	
 
			_glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, 256, GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1);
 
			_glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, 256, GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1);
 
			_glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 256, GL_RED, GL_UNSIGNED_BYTE, nullptr);
 

	
 
			_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
 

	
 
			this->last_sprite_pal = pal;
 
		}
src/viewport.cpp
Show inline comments
 
@@ -622,13 +622,13 @@ void OffsetGroundSprite(int x, int y)
 
 * @param z position z of the sprite.
 
 * @param sub Only draw a part of the sprite.
 
 */
 
static void AddCombinedSprite(SpriteID image, PaletteID pal, int x, int y, int z, const SubSprite *sub)
 
{
 
	Point pt = RemapCoords(x, y, z);
 
	const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
 
	const Sprite *spr = GetSprite(image & SPRITE_MASK, SpriteType::Normal);
 

	
 
	if (pt.x + spr->x_offs >= _vd.dpi.left + _vd.dpi.width ||
 
			pt.x + spr->x_offs + spr->width <= _vd.dpi.left ||
 
			pt.y + spr->y_offs >= _vd.dpi.top + _vd.dpi.height ||
 
			pt.y + spr->y_offs + spr->height <= _vd.dpi.top)
 
		return;
 
@@ -688,13 +688,13 @@ void AddSortableSpriteToDraw(SpriteID im
 
	if (image == SPR_EMPTY_BOUNDING_BOX) {
 
		left = tmp_left = RemapCoords(x + w          , y + bb_offset_y, z + bb_offset_z).x;
 
		right           = RemapCoords(x + bb_offset_x, y + h          , z + bb_offset_z).x + 1;
 
		top  = tmp_top  = RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz         ).y;
 
		bottom          = RemapCoords(x + w          , y + h          , z + bb_offset_z).y + 1;
 
	} else {
 
		const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
 
		const Sprite *spr = GetSprite(image & SPRITE_MASK, SpriteType::Normal);
 
		left = tmp_left = (pt.x += spr->x_offs);
 
		right           = (pt.x +  spr->width );
 
		top  = tmp_top  = (pt.y += spr->y_offs);
 
		bottom          = (pt.y +  spr->height);
 
	}
 

	
0 comments (0 inline, 0 general)