OpenTTD Source: src/newgrf/newgrf_act12.cpp Source File

OpenTTD Source 15.0-RC2

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