2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file spritecache.h Functions to cache sprites in memory. */
|
2007-04-04 03:35:16 +02:00
|
|
|
|
2005-02-10 06:43:30 +01:00
|
|
|
#ifndef SPRITECACHE_H
|
|
|
|
#define SPRITECACHE_H
|
|
|
|
|
2007-12-23 11:56:02 +01:00
|
|
|
#include "gfx_type.h"
|
2021-01-16 16:43:27 +01:00
|
|
|
#include "spriteloader/spriteloader.hpp"
|
2007-12-23 11:56:02 +01:00
|
|
|
|
2009-06-27 01:20:32 +02:00
|
|
|
/** Data structure describing a sprite. */
|
2007-03-07 13:11:48 +01:00
|
|
|
struct Sprite {
|
2023-05-08 19:01:06 +02:00
|
|
|
uint16_t height; ///< Height of the sprite.
|
|
|
|
uint16_t width; ///< Width of the sprite.
|
|
|
|
int16_t x_offs; ///< Number of pixels to shift the sprite to the right.
|
|
|
|
int16_t y_offs; ///< Number of pixels to shift the sprite downwards.
|
2011-11-24 13:38:48 +01:00
|
|
|
byte data[]; ///< Sprite data.
|
2007-03-07 13:11:48 +01:00
|
|
|
};
|
2005-02-10 13:14:38 +01:00
|
|
|
|
2022-09-21 12:37:11 +02:00
|
|
|
enum SpriteCacheCtrlFlags {
|
|
|
|
SCCF_ALLOW_ZOOM_MIN_1X_PAL = 0, ///< Allow use of sprite min zoom setting at 1x in palette mode.
|
|
|
|
SCCF_ALLOW_ZOOM_MIN_1X_32BPP = 1, ///< Allow use of sprite min zoom setting at 1x in 32bpp mode.
|
|
|
|
SCCF_ALLOW_ZOOM_MIN_2X_PAL = 2, ///< Allow use of sprite min zoom setting at 2x in palette mode.
|
|
|
|
SCCF_ALLOW_ZOOM_MIN_2X_32BPP = 3, ///< Allow use of sprite min zoom setting at 2x in 32bpp mode.
|
|
|
|
};
|
|
|
|
|
2007-06-05 12:40:29 +02:00
|
|
|
extern uint _sprite_cache_size;
|
|
|
|
|
2011-01-14 16:34:33 +01:00
|
|
|
typedef void *AllocatorProc(size_t size);
|
|
|
|
|
2021-01-16 16:43:31 +01:00
|
|
|
void *SimpleSpriteAlloc(size_t size);
|
2021-01-16 16:43:27 +01:00
|
|
|
void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator = nullptr, SpriteEncoder *encoder = nullptr);
|
2006-04-16 13:26:23 +02:00
|
|
|
bool SpriteExists(SpriteID sprite);
|
2005-02-13 09:12:03 +01:00
|
|
|
|
2010-04-25 18:27:30 +02:00
|
|
|
SpriteType GetSpriteType(SpriteID sprite);
|
2021-04-14 17:20:39 +02:00
|
|
|
SpriteFile *GetOriginFile(SpriteID sprite);
|
2023-05-08 19:01:06 +02:00
|
|
|
uint32_t GetSpriteLocalID(SpriteID sprite);
|
2021-04-14 17:20:39 +02:00
|
|
|
uint GetSpriteCountForFile(const std::string &filename, SpriteID begin, SpriteID end);
|
2010-04-25 18:27:30 +02:00
|
|
|
uint GetMaxSpriteID();
|
|
|
|
|
|
|
|
|
2024-01-06 12:19:27 +01:00
|
|
|
inline const Sprite *GetSprite(SpriteID sprite, SpriteType type)
|
2005-02-13 09:12:03 +01:00
|
|
|
{
|
2023-04-16 21:00:55 +02:00
|
|
|
assert(type != SpriteType::Recolour);
|
2008-09-02 17:20:38 +02:00
|
|
|
return (Sprite*)GetRawSprite(sprite, type);
|
2005-02-13 09:12:03 +01:00
|
|
|
}
|
|
|
|
|
2024-01-06 12:19:27 +01:00
|
|
|
inline const byte *GetNonSprite(SpriteID sprite, SpriteType type)
|
2005-02-13 09:12:03 +01:00
|
|
|
{
|
2023-04-16 21:00:55 +02:00
|
|
|
assert(type == SpriteType::Recolour);
|
2008-09-02 17:20:38 +02:00
|
|
|
return (byte*)GetRawSprite(sprite, type);
|
2005-02-13 09:12:03 +01:00
|
|
|
}
|
2005-02-10 06:43:30 +01:00
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
void GfxInitSpriteMem();
|
2011-11-24 13:26:44 +01:00
|
|
|
void GfxClearSpriteCache();
|
2023-04-17 00:14:03 +02:00
|
|
|
void GfxClearFontSpriteCache();
|
2007-03-07 12:47:46 +01:00
|
|
|
void IncreaseSpriteLRU();
|
2005-02-10 06:43:30 +01:00
|
|
|
|
2021-04-14 17:20:39 +02:00
|
|
|
SpriteFile &OpenCachedSpriteFile(const std::string &filename, Subdirectory subdir, bool palette_remap);
|
|
|
|
|
|
|
|
void ReadGRFSpriteOffsets(SpriteFile &file);
|
2023-05-08 19:01:06 +02:00
|
|
|
size_t GetGRFSpriteOffset(uint32_t id);
|
2021-04-14 17:20:39 +02:00
|
|
|
bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id);
|
2023-05-08 19:01:06 +02:00
|
|
|
bool SkipSpriteData(SpriteFile &file, byte type, uint16_t num);
|
2007-01-10 19:56:51 +01:00
|
|
|
void DupSprite(SpriteID old_spr, SpriteID new_spr);
|
2005-08-14 20:10:18 +02:00
|
|
|
|
2005-09-18 22:56:44 +02:00
|
|
|
#endif /* SPRITECACHE_H */
|