4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file spriteloader.hpp Base for loading sprites. */
12 #ifndef SPRITELOADER_HPP
13 #define SPRITELOADER_HPP
15 #include "../core/alloc_type.hpp"
16 #include "../gfx_type.h"
18 /** Interface for the loader of our sprites. */
21 /** Definition of a common pixel in OpenTTD's realm. */
23 uint8 r
; ///< Red-channel
24 uint8 g
; ///< Green-channel
25 uint8 b
; ///< Blue-channel
26 uint8 a
; ///< Alpha-channel
27 uint8 m
; ///< Remap-channel
31 * Structure for passing information from the sprite loader to the blitter.
32 * You can only use this struct once at a time when using AllocateData to
33 * allocate the memory as that will always return the same memory address.
34 * This to prevent thousands of malloc + frees just to load a sprite.
37 uint16 height
; ///< Height of the sprite
38 uint16 width
; ///< Width of the sprite
39 int16 x_offs
; ///< The x-offset of where the sprite will be drawn
40 int16 y_offs
; ///< The y-offset of where the sprite will be drawn
41 SpriteType type
; ///< The sprite type
42 SpriteLoader::CommonPixel
*data
; ///< The sprite itself
45 * Allocate the sprite data of this sprite.
46 * @param zoom Zoom level to allocate the data for.
47 * @param size the minimum size of the data field.
49 void AllocateData(ZoomLevel zoom
, size_t size
) { this->data
= Sprite::buffer
[zoom
].ZeroAllocate(size
); }
51 /** Allocated memory to pass sprite data around */
52 static ReusableBuffer
<SpriteLoader::CommonPixel
> buffer
[ZOOM_LVL_COUNT
];
56 * Load a sprite from the disk and return a sprite struct which is the same for all loaders.
57 * @param[out] sprite The sprites to fill with data.
58 * @param file_slot The file "descriptor" of the file we read from.
59 * @param file_pos The position within the file the image begins.
60 * @param sprite_type The type of sprite we're trying to load.
61 * @param load_32bpp True if 32bpp sprites should be loaded, false for a 8bpp sprite.
62 * @return Bit mask of the zoom levels successfully loaded or 0 if no sprite could be loaded.
64 virtual uint8
LoadSprite(SpriteLoader::Sprite
*sprite
, uint8 file_slot
, size_t file_pos
, SpriteType sprite_type
, bool load_32bpp
) = 0;
66 virtual ~SpriteLoader() { }
69 #endif /* SPRITELOADER_HPP */