OpenTTD Source  12.0-beta2
spriteloader.hpp
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 SPRITELOADER_HPP
11 #define SPRITELOADER_HPP
12 
13 #include "../core/alloc_type.hpp"
14 #include "../core/enum_type.hpp"
15 #include "../gfx_type.h"
16 #include "sprite_file_type.hpp"
17 
18 struct Sprite;
19 typedef void *AllocatorProc(size_t size);
20 
23  SCC_RGB = 1 << 0,
24  SCC_ALPHA = 1 << 1,
25  SCC_PAL = 1 << 2,
27 };
29 
30 
31 class SpriteLoader {
32 public:
34  struct CommonPixel {
35  uint8 r;
36  uint8 g;
37  uint8 b;
38  uint8 a;
39  uint8 m;
40  };
41 
48  struct Sprite {
49  uint16 height;
50  uint16 width;
51  int16 x_offs;
52  int16 y_offs;
56 
62  void AllocateData(ZoomLevel zoom, size_t size) { this->data = Sprite::buffer[zoom].ZeroAllocate(size); }
63  private:
66  };
67 
77  virtual uint8 LoadSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp) = 0;
78 
79  virtual ~SpriteLoader() { }
80 };
81 
84 public:
85 
86  virtual ~SpriteEncoder() { }
87 
91  virtual bool Is32BppSupported() = 0;
92 
96  virtual Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) = 0;
97 
102  virtual uint GetSpriteAlignment()
103  {
104  return 0;
105  }
106 };
107 #endif /* SPRITELOADER_HPP */
SpriteLoader::CommonPixel::m
uint8 m
Remap-channel.
Definition: spriteloader.hpp:39
SCC_PAL
@ SCC_PAL
Sprite has palette data.
Definition: spriteloader.hpp:25
SpriteLoader::CommonPixel::r
uint8 r
Red-channel.
Definition: spriteloader.hpp:35
ReusableBuffer< SpriteLoader::CommonPixel >
SpriteLoader::Sprite::AllocateData
void AllocateData(ZoomLevel zoom, size_t size)
Allocate the sprite data of this sprite.
Definition: spriteloader.hpp:62
SpriteLoader
Interface for the loader of our sprites.
Definition: spriteloader.hpp:31
ZOOM_LVL_COUNT
@ ZOOM_LVL_COUNT
Number of zoom levels.
Definition: zoom_type.h:32
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:21
SpriteEncoder::Encode
virtual Sprite * Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)=0
Convert a sprite from the loader to our own format.
SpriteLoader::Sprite::data
SpriteLoader::CommonPixel * data
The sprite itself.
Definition: spriteloader.hpp:55
SpriteLoader::Sprite::type
SpriteType type
The sprite type.
Definition: spriteloader.hpp:53
SpriteEncoder::GetSpriteAlignment
virtual uint GetSpriteAlignment()
Get the value which the height and width on a sprite have to be aligned by.
Definition: spriteloader.hpp:102
SpriteLoader::CommonPixel
Definition of a common pixel in OpenTTD's realm.
Definition: spriteloader.hpp:34
sprite_file_type.hpp
SpriteLoader::Sprite::x_offs
int16 x_offs
The x-offset of where the sprite will be drawn.
Definition: spriteloader.hpp:51
SpriteEncoder
Interface for something that can encode a sprite.
Definition: spriteloader.hpp:83
SpriteLoader::Sprite::colours
SpriteColourComponent colours
The colour components of the sprite with useful information.
Definition: spriteloader.hpp:54
SpriteFile
RandomAccessFile with some extra information specific for sprite files.
Definition: sprite_file_type.hpp:19
SCC_RGB
@ SCC_RGB
Sprite has RGB.
Definition: spriteloader.hpp:23
SpriteEncoder::Is32BppSupported
virtual bool Is32BppSupported()=0
Can the sprite encoder make use of RGBA sprites?
SpriteLoader::CommonPixel::b
uint8 b
Blue-channel.
Definition: spriteloader.hpp:37
SpriteLoader::Sprite::width
uint16 width
Width of the sprite.
Definition: spriteloader.hpp:50
SCC_MASK
@ SCC_MASK
Mask of valid colour bits.
Definition: spriteloader.hpp:26
SpriteType
SpriteType
Types of sprites that might be loaded.
Definition: gfx_type.h:301
SCC_ALPHA
@ SCC_ALPHA
Sprite has alpha.
Definition: spriteloader.hpp:24
SpriteLoader::Sprite
Structure for passing information from the sprite loader to the blitter.
Definition: spriteloader.hpp:48
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
SpriteLoader::CommonPixel::g
uint8 g
Green-channel.
Definition: spriteloader.hpp:36
SpriteLoader::CommonPixel::a
uint8 a
Alpha-channel.
Definition: spriteloader.hpp:38
SpriteLoader::Sprite::y_offs
int16 y_offs
The y-offset of where the sprite will be drawn.
Definition: spriteloader.hpp:52
SpriteLoader::Sprite::height
uint16 height
Height of the sprite.
Definition: spriteloader.hpp:49
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17
SpriteColourComponent
SpriteColourComponent
The different colour components a sprite can have.
Definition: spriteloader.hpp:22