OpenTTD Source 20250826-master-gd3d25a39a0
mock_spritecache.cpp
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#include "../stdafx.h"
11
12#include "../blitter/factory.hpp"
13#include "../core/math_func.hpp"
14#include "../spritecache.h"
15#include "../spritecache_internal.h"
16#include "../table/sprites.h"
17
18#include "../safeguards.h"
19
20static bool MockLoadNextSprite(SpriteID load_index)
21{
23 allocator.Allocate<Sprite>(sizeof(Sprite));
24
25 bool is_mapgen = IsMapgenSpriteID(load_index);
26
27 SpriteCache *sc = AllocateSpriteCache(load_index);
28 sc->file = nullptr;
29 sc->file_pos = 0;
30 sc->ptr = std::move(allocator.data);
31 sc->length = static_cast<uint32_t>(allocator.size);
32 sc->lru = 0;
33 sc->id = 0;
34 sc->type = is_mapgen ? SpriteType::MapGen : SpriteType::Normal;
35 sc->warned = false;
36 sc->control_flags = {};
37
38 /* Fill with empty sprites up until the default sprite count. */
39 return load_index < SPR_OPENTTD_BASE + OPENTTD_SPRITE_COUNT;
40}
41
42void MockGfxLoadSprites()
43{
44 /* Force blitter 'null'. This is necessary for GfxInitSpriteMem() to function. */
46
47 GfxInitSpriteMem();
48
49 SpriteID load_index = 0;
50 while (MockLoadNextSprite(load_index)) {
51 load_index++;
52 }
53}
static Blitter * SelectBlitter(std::string_view name)
Find the requested blitter and return its class.
Definition factory.hpp:96
T * Allocate(size_t size)
Allocate memory for a sprite.
SpriteAllocator that allocates memory via a unique_ptr array.
Definition spritecache.h:20
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ MapGen
Special sprite for the map generator.
@ Normal
The most basic (normal) sprite.
static const SpriteID SPR_OPENTTD_BASE
Extra graphic spritenumbers.
Definition sprites.h:56
uint32_t length
Length of sprite data.
bool warned
True iff the user has been warned about incorrect use of this sprite.
SpriteCacheCtrlFlags control_flags
Control flags, see SpriteCacheCtrlFlags.
SpriteType type
In some cases a single sprite is misused by two NewGRFs. Once as real sprite and once as recolour spr...
SpriteFile * file
The file the sprite in this entry can be found in.
Data structure describing a sprite.