OpenTTD Source 20250331-master-g3c15e0c889
newgrf_act12.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#include "../debug.h"
12#include "../fontcache.h"
13#include "newgrf_bytereader.h"
14#include "newgrf_internal.h"
15
16#include "../safeguards.h"
17
19static void LoadFontGlyph(ByteReader &buf)
20{
21 /* <12> <num_def> <font_size> <num_char> <base_char>
22 *
23 * B num_def Number of definitions
24 * B font_size Size of font (0 = normal, 1 = small, 2 = large, 3 = mono)
25 * B num_char Number of consecutive glyphs
26 * W base_char First character index */
27
28 uint8_t num_def = buf.ReadByte();
29
30 for (uint i = 0; i < num_def; i++) {
31 FontSize size = (FontSize)buf.ReadByte();
32 uint8_t num_char = buf.ReadByte();
33 uint16_t base_char = buf.ReadWord();
34
35 if (size >= FS_END) {
36 GrfMsg(1, "LoadFontGlyph: Size {} is not supported, ignoring", size);
37 }
38
39 GrfMsg(7, "LoadFontGlyph: Loading {} glyph(s) at 0x{:04X} for size {}", num_char, base_char, size);
40
41 for (uint c = 0; c < num_char; c++) {
42 if (size < FS_END) SetUnicodeGlyph(size, base_char + c, _cur.spriteid);
43 _cur.nfo_line++;
44 LoadNextSprite(_cur.spriteid++, *_cur.file, _cur.nfo_line);
45 }
46 }
47}
48
50static void SkipAct12(ByteReader &buf)
51{
52 /* <12> <num_def> <font_size> <num_char> <base_char>
53 *
54 * B num_def Number of definitions
55 * B font_size Size of font (0 = normal, 1 = small, 2 = large)
56 * B num_char Number of consecutive glyphs
57 * W base_char First character index */
58
59 uint8_t num_def = buf.ReadByte();
60
61 for (uint i = 0; i < num_def; i++) {
62 /* Ignore 'size' byte */
63 buf.ReadByte();
64
65 /* Sum up number of characters */
66 _cur.skip_sprites += buf.ReadByte();
67
68 /* Ignore 'base_char' word */
69 buf.ReadWord();
70 }
71
72 GrfMsg(3, "SkipAct12: Skipping {} sprites", _cur.skip_sprites);
73}
74
75template <> void GrfActionHandler<0x12>::FileScan(ByteReader &buf) { SkipAct12(buf); }
76template <> void GrfActionHandler<0x12>::SafetyScan(ByteReader &buf) { SkipAct12(buf); }
77template <> void GrfActionHandler<0x12>::LabelScan(ByteReader &buf) { SkipAct12(buf); }
78template <> void GrfActionHandler<0x12>::Init(ByteReader &buf) { SkipAct12(buf); }
79template <> void GrfActionHandler<0x12>::Reserve(ByteReader &buf) { SkipAct12(buf); }
80template <> void GrfActionHandler<0x12>::Activation(ByteReader &buf) { LoadFontGlyph(buf); }
Class to read from a NewGRF file.
uint16_t ReadWord()
Read a single Word (16 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
void SetUnicodeGlyph(FontSize size, char32_t key, SpriteID sprite)
Map a SpriteID to the font size and key.
Definition fontcache.h:152
FontSize
Available font sizes.
Definition gfx_type.h:244
static void SkipAct12(ByteReader &buf)
Action 0x12 (SKIP)
static void LoadFontGlyph(ByteReader &buf)
Action 0x12.
NewGRF buffer reader definition.
NewGRF internal processing state.
bool LoadNextSprite(SpriteID load_index, SpriteFile &file, uint file_sprite_id)
Load a real or recolour sprite.
GRF action handler.
SpriteFile * file
File of currently processed GRF file.
uint32_t nfo_line
Currently processed pseudo sprite number in the GRF.
SpriteID spriteid
First available SpriteID for loading realsprites.
int skip_sprites
Number of pseudo sprites to skip before processing the next one. (-1 to skip to end of file)