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

OpenTTD Source 14.1

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 static bool MockLoadNextSprite(int load_index)
19 {
20 static Sprite *sprite = (Sprite *)AllocSprite(sizeof(*sprite));
21
22 bool is_mapgen = IsMapgenSpriteID(load_index);
23
24 SpriteCache *sc = AllocateSpriteCache(load_index);
25 sc->file = nullptr;
26 sc->file_pos = 0;
27 sc->ptr = sprite;
28 sc->lru = 0;
29 sc->id = 0;
30 sc->type = is_mapgen ? SpriteType::MapGen : SpriteType::Normal;
31 sc->warned = false;
32 sc->control_flags = 0;
33
34 /* Fill with empty sprites up until the default sprite count. */
35 return (uint)load_index < SPR_OPENTTD_BASE + OPENTTD_SPRITE_COUNT;
36 }
37
38 void MockGfxLoadSprites()
39 {
40 /* Force blitter 'null'. This is necessary for GfxInitSpriteMem() to function. */
41 BlitterFactory::SelectBlitter("null");
42
43 GfxInitSpriteMem();
44
45 int load_index = 0;
46 while (MockLoadNextSprite(load_index)) {
47 load_index++;
48 }
49 }
BlitterFactory::SelectBlitter
static Blitter * SelectBlitter(const std::string &name)
Find the requested blitter and return its class.
Definition: factory.hpp:96
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
byte control_flags
Control flags, see SpriteCacheCtrlFlags.
Definition: spritecache_internal.h:31
SpriteCache::file
SpriteFile * file
The file the sprite in this entry can be found in.
Definition: spritecache_internal.h:26
SpriteType::MapGen
@ MapGen
Special sprite for the map generator.
SpriteCache
Definition: spritecache_internal.h:23
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
SPR_OPENTTD_BASE
static const SpriteID SPR_OPENTTD_BASE
Extra graphic spritenumbers.
Definition: sprites.h:56
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17
SpriteType::Normal
@ Normal
The most basic (normal) sprite.