2009-08-21 20:21:05 +00: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 15:11:33 +00:00
|
|
|
/** @file spritecache.h Functions to cache sprites in memory. */
|
2007-04-04 01:35:16 +00:00
|
|
|
|
2005-02-10 05:43:30 +00:00
|
|
|
#ifndef SPRITECACHE_H
|
|
|
|
#define SPRITECACHE_H
|
|
|
|
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "gfx_type.h"
|
2021-01-16 15:43:27 +00:00
|
|
|
#include "spriteloader/spriteloader.hpp"
|
2007-12-23 10:56:02 +00:00
|
|
|
|
2009-06-26 23:20:32 +00:00
|
|
|
/** Data structure describing a sprite. */
|
2007-03-07 12:11:48 +00:00
|
|
|
struct Sprite {
|
2011-11-24 12:38:48 +00:00
|
|
|
uint16 height; ///< Height of the sprite.
|
|
|
|
uint16 width; ///< Width of the sprite.
|
|
|
|
int16 x_offs; ///< Number of pixels to shift the sprite to the right.
|
|
|
|
int16 y_offs; ///< Number of pixels to shift the sprite downwards.
|
|
|
|
byte data[]; ///< Sprite data.
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-02-10 12:14:38 +00:00
|
|
|
|
2022-09-21 10:37:11 +00: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 10:40:29 +00:00
|
|
|
extern uint _sprite_cache_size;
|
|
|
|
|
2011-01-14 15:34:33 +00:00
|
|
|
typedef void *AllocatorProc(size_t size);
|
|
|
|
|
2021-01-16 15:43:31 +00:00
|
|
|
void *SimpleSpriteAlloc(size_t size);
|
2021-01-16 15:43:27 +00:00
|
|
|
void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator = nullptr, SpriteEncoder *encoder = nullptr);
|
2006-04-16 11:26:23 +00:00
|
|
|
bool SpriteExists(SpriteID sprite);
|
2005-02-13 08:12:03 +00:00
|
|
|
|
2010-04-25 16:27:30 +00:00
|
|
|
SpriteType GetSpriteType(SpriteID sprite);
|
2021-04-14 15:20:39 +00:00
|
|
|
SpriteFile *GetOriginFile(SpriteID sprite);
|
2020-01-26 12:45:51 +00:00
|
|
|
uint32 GetSpriteLocalID(SpriteID sprite);
|
2021-04-14 15:20:39 +00:00
|
|
|
uint GetSpriteCountForFile(const std::string &filename, SpriteID begin, SpriteID end);
|
2010-04-25 16:27:30 +00:00
|
|
|
uint GetMaxSpriteID();
|
|
|
|
|
|
|
|
|
2008-09-02 15:20:38 +00:00
|
|
|
static inline const Sprite *GetSprite(SpriteID sprite, SpriteType type)
|
2005-02-13 08:12:03 +00:00
|
|
|
{
|
2008-09-02 15:20:38 +00:00
|
|
|
assert(type != ST_RECOLOUR);
|
|
|
|
return (Sprite*)GetRawSprite(sprite, type);
|
2005-02-13 08:12:03 +00:00
|
|
|
}
|
|
|
|
|
2008-09-02 15:20:38 +00:00
|
|
|
static inline const byte *GetNonSprite(SpriteID sprite, SpriteType type)
|
2005-02-13 08:12:03 +00:00
|
|
|
{
|
2008-09-02 15:20:38 +00:00
|
|
|
assert(type == ST_RECOLOUR);
|
|
|
|
return (byte*)GetRawSprite(sprite, type);
|
2005-02-13 08:12:03 +00:00
|
|
|
}
|
2005-02-10 05:43:30 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void GfxInitSpriteMem();
|
2011-11-24 12:26:44 +00:00
|
|
|
void GfxClearSpriteCache();
|
2007-03-07 11:47:46 +00:00
|
|
|
void IncreaseSpriteLRU();
|
2005-02-10 05:43:30 +00:00
|
|
|
|
2021-04-14 15:20:39 +00:00
|
|
|
SpriteFile &OpenCachedSpriteFile(const std::string &filename, Subdirectory subdir, bool palette_remap);
|
|
|
|
|
|
|
|
void ReadGRFSpriteOffsets(SpriteFile &file);
|
2012-02-04 13:29:04 +00:00
|
|
|
size_t GetGRFSpriteOffset(uint32 id);
|
2021-04-14 15:20:39 +00:00
|
|
|
bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id);
|
|
|
|
bool SkipSpriteData(SpriteFile &file, byte type, uint16 num);
|
2007-01-10 18:56:51 +00:00
|
|
|
void DupSprite(SpriteID old_spr, SpriteID new_spr);
|
2005-08-14 18:10:18 +00:00
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
#endif /* SPRITECACHE_H */
|