| 254 | } |
| 255 | |
| 256 | static ZoomLevels LoadSpriteV2(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, SpriteCacheCtrlFlags control_flags, ZoomLevels &avail_8bpp, ZoomLevels &avail_32bpp) |
| 257 | { |
| 258 | static const ZoomLevel zoom_lvl_map[6] = {ZoomLevel::Normal, ZoomLevel::In4x, ZoomLevel::In2x, ZoomLevel::Out2x, ZoomLevel::Out4x, ZoomLevel::Out8x}; |
| 259 | |
| 260 | /* Is the sprite not present/stripped in the GRF? */ |
| 261 | if (file_pos == SIZE_MAX) return {}; |
| 262 | |
| 263 | /* Open the right file and go to the correct position */ |
| 264 | file.SeekTo(file_pos, SEEK_SET); |
| 265 | |
| 266 | uint32_t id = file.ReadDword(); |
| 267 | |
| 268 | ZoomLevels loaded_sprites; |
| 269 | do { |
| 270 | int64_t num = file.ReadDword(); |
| 271 | size_t start_pos = file.GetPos(); |
| 272 | uint8_t type = file.ReadByte(); |
| 273 | |
| 274 | /* Type 0xFF indicates either a colourmap or some other non-sprite info; we do not handle them here. */ |
| 275 | if (type == 0xFF) return {}; |
| 276 | |
| 277 | SpriteComponents colour{type}; |
| 278 | /* Mask out colour component information from type. */ |
| 279 | type &= ~SpriteComponents::MASK; |
| 280 | |
| 281 | uint8_t zoom = file.ReadByte(); |
| 282 | |
| 283 | bool is_wanted_colour_depth = (colour.Any() && (load_32bpp ? colour != SpriteComponent::Palette : colour == SpriteComponent::Palette)); |
| 284 | bool is_wanted_zoom_lvl; |
| 285 | |
| 286 | if (sprite_type != SpriteType::MapGen) { |
| 287 | if (zoom < lengthof(zoom_lvl_map)) { |
| 288 | ZoomLevel zoom_lvl = zoom_lvl_map[zoom]; |
| 289 | if (colour == SpriteComponent::Palette) avail_8bpp.Set(zoom_lvl); |
| 290 | if (colour != SpriteComponent::Palette) avail_32bpp.Set(zoom_lvl); |
| 291 | |
| 292 | is_wanted_zoom_lvl = true; |
| 293 | ZoomLevel zoom_min = sprite_type == SpriteType::Font ? ZoomLevel::Min : _settings_client.gui.sprite_zoom_min; |
| 294 | if (zoom_min >= ZoomLevel::In2x && |
| 295 | control_flags.Test(load_32bpp ? SpriteCacheCtrlFlag::AllowZoomMin2x32bpp : SpriteCacheCtrlFlag::AllowZoomMin2xPal) && zoom_lvl < ZoomLevel::In2x) { |
| 296 | is_wanted_zoom_lvl = false; |
| 297 | } |
| 298 | if (zoom_min >= ZoomLevel::Normal && |
| 299 | control_flags.Test(load_32bpp ? SpriteCacheCtrlFlag::AllowZoomMin1x32bpp : SpriteCacheCtrlFlag::AllowZoomMin1xPal) && zoom_lvl < ZoomLevel::Normal) { |
| 300 | is_wanted_zoom_lvl = false; |
| 301 | } |
| 302 | } else { |
| 303 | is_wanted_zoom_lvl = false; |
| 304 | } |
| 305 | } else { |
| 306 | is_wanted_zoom_lvl = (zoom == 0); |
| 307 | } |
| 308 | |
| 309 | if (is_wanted_colour_depth && is_wanted_zoom_lvl) { |
| 310 | ZoomLevel zoom_lvl = (sprite_type != SpriteType::MapGen) ? zoom_lvl_map[zoom] : ZoomLevel::Min; |
| 311 | |
| 312 | if (loaded_sprites.Test(zoom_lvl)) { |
| 313 | /* We already have this zoom level, skip sprite. */ |
no test coverage detected