Changeset - r27659:efb2f4024b6e
[Not reviewed]
master
0 2 0
Johannes E. Krause - 12 months ago 2023-06-27 10:46:14
j.k@eclipso.de
Add: show fallback sprites with debuglevel sprite=4
2 files changed with 6 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/gfxinit.cpp
Show inline comments
 
@@ -204,24 +204,25 @@ static void LoadSpriteTables()
 
		default: break;
 
	}
 
	FillGRFDetails(extra, false, BASESET_DIR);
 
	ClrBit(extra->flags, GCF_INIT_ONLY);
 

	
 
	extra->next = top;
 
	master->next = extra;
 
	_grfconfig = master;
 

	
 
	LoadNewGRF(SPR_NEWGRFS_BASE, 2);
 

	
 
	uint total_extra_graphics = SPR_NEWGRFS_BASE - SPR_OPENTTD_BASE;
 
	Debug(sprite, 4, "Checking sprites from fallback grf");
 
	_missing_extra_graphics = GetSpriteCountForFile(master_filename, SPR_OPENTTD_BASE, SPR_NEWGRFS_BASE);
 
	Debug(sprite, 1, "{} extra sprites, {} from baseset, {} from fallback", total_extra_graphics, total_extra_graphics - _missing_extra_graphics, _missing_extra_graphics);
 

	
 
	/* The original baseset extra graphics intentionally make use of the fallback graphics.
 
	 * Let's say everything which provides less than 500 sprites misses the rest intentionally. */
 
	if (500 + _missing_extra_graphics > total_extra_graphics) _missing_extra_graphics = 0;
 

	
 
	/* Free and remove the top element. */
 
	delete extra;
 
	delete master;
 
	_grfconfig = top;
 
}
src/spritecache.cpp
Show inline comments
 
@@ -196,25 +196,28 @@ uint32 GetSpriteLocalID(SpriteID sprite)
 
 * @param end First sprite not in range.
 
 * @return Number of sprites.
 
 */
 
uint GetSpriteCountForFile(const std::string &filename, SpriteID begin, SpriteID end)
 
{
 
	SpriteFile *file = GetCachedSpriteFileByName(filename);
 
	if (file == nullptr) return 0;
 

	
 
	uint count = 0;
 
	for (SpriteID i = begin; i != end; i++) {
 
		if (SpriteExists(i)) {
 
			SpriteCache *sc = GetSpriteCache(i);
 
			if (sc->file == file) count++;
 
			if (sc->file == file) {
 
				count++;
 
				Debug(sprite, 4, "Sprite: {}", i);
 
			}
 
		}
 
	}
 
	return count;
 
}
 

	
 
/**
 
 * Get a reasonable (upper bound) estimate of the maximum
 
 * SpriteID used in OpenTTD; there will be no sprites with
 
 * a higher SpriteID, although there might be up to roughly
 
 * a thousand unused SpriteIDs below this number.
 
 * @note It's actually the number of spritecache items.
 
 * @return maximum SpriteID
 
@@ -722,25 +725,25 @@ static size_t GetSpriteCacheUsage()
 
	}
 

	
 
	return tot_size;
 
}
 

	
 

	
 
void IncreaseSpriteLRU()
 
{
 
	/* Increase all LRU values */
 
	if (_sprite_lru_counter > 16384) {
 
		SpriteID i;
 

	
 
		Debug(sprite, 3, "Fixing lru {}, inuse={}", _sprite_lru_counter, GetSpriteCacheUsage());
 
		Debug(sprite, 5, "Fixing lru {}, inuse={}", _sprite_lru_counter, GetSpriteCacheUsage());
 

	
 
		for (i = 0; i != _spritecache_items; i++) {
 
			SpriteCache *sc = GetSpriteCache(i);
 
			if (sc->ptr != nullptr) {
 
				if (sc->lru >= 0) {
 
					sc->lru = -1;
 
				} else if (sc->lru != -32768) {
 
					sc->lru--;
 
				}
 
			}
 
		}
 
		_sprite_lru_counter = 0;
0 comments (0 inline, 0 general)