OpenTTD Source: src/tests/mock_spritecache.cpp Source File

OpenTTD Source 15.3

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