OpenTTD Source: src/spritecache_internal.h Source File

OpenTTD Source 15.0-beta1

spritecache_internal.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10#ifndef SPRITECACHE_INTERNAL_H
11#define SPRITECACHE_INTERNAL_H
12
13#include "stdafx.h"
14
15#include "core/math_func.hpp"
16#include "gfx_type.h"
17#include "spriteloader/spriteloader.hpp"
18
19#include "table/sprites.h"
20
21/* These declarations are internal to spritecache but need to be exposed for unit-tests. */
22
23 struct SpriteCache {
24 void *ptr;
25 size_t file_pos;
26 SpriteFile *file;
27 uint32_t length;
28 uint32_t id;
29 int16_t lru;
30 SpriteType type;
31 bool warned;
32 uint8_t control_flags;
33};
34
36 class CacheSpriteAllocator : public SpriteAllocator {
37protected:
38 void *AllocatePtr(size_t size) override;
39};
40
41inline bool IsMapgenSpriteID(SpriteID sprite)
42{
43 return IsInsideMM(sprite, SPR_MAPGEN_BEGIN, SPR_MAPGEN_END);
44}
45
46 SpriteCache *AllocateSpriteCache(uint index);
47
48#endif /* SPRITECACHE_INTERNAL_H */
CacheSpriteAllocator
SpriteAllocator that allocates memory from the sprite cache.
Definition spritecache_internal.h:36
CacheSpriteAllocator::AllocatePtr
void * AllocatePtr(size_t size) override
Allocate memory for a sprite.
Definition spritecache.cpp:855
SpriteAllocator
Interface for something that can allocate memory for a sprite.
Definition spriteloader.hpp:88
SpriteFile
RandomAccessFile with some extra information specific for sprite files.
Definition sprite_file_type.hpp:19
gfx_type.h
Types related to the graphics and/or input devices.
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:18
SpriteType
SpriteType
Types of sprites that might be loaded.
Definition gfx_type.h:312
math_func.hpp
Integer math functions.
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition math_func.hpp:268
spriteloader.hpp
Base for loading sprites.
sprites.h
This file contains all sprite-related enums and defines.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
SpriteCache
Definition spritecache_internal.h:23
SpriteCache::control_flags
uint8_t control_flags
Control flags, see SpriteCacheCtrlFlags.
Definition spritecache_internal.h:32
SpriteCache::length
uint32_t length
Length of sprite data.
Definition spritecache_internal.h:27
SpriteCache::warned
bool warned
True iff the user has been warned about incorrect use of this sprite.
Definition spritecache_internal.h:31
SpriteCache::type
SpriteType type
In some cases a single sprite is misused by two NewGRFs. Once as real sprite and once as recolour spr...
Definition spritecache_internal.h:30
SpriteCache::file
SpriteFile * file
The file the sprite in this entry can be found in.
Definition spritecache_internal.h:26