OpenTTD Source: SpriteFile Class Reference

OpenTTD Source 15.0-RC2

Public Member Functions | Private Attributes
SpriteFile Class Reference

RandomAccessFile with some extra information specific for sprite files. More...

`#include <sprite_file_type.hpp>`

Inheritance diagram for SpriteFile:

## Public Member Functions
| SpriteFile (const std::string &filename, Subdirectory subdir, bool palette_remap)
| Create the SpriteFile.
| SpriteFile (const SpriteFile &)=delete
void | operator= (const SpriteFile &)=delete
bool | NeedsPaletteRemap () const
| Whether a palette remap is needed when loading sprites from this file.
uint8_t | GetContainerVersion () const
| Get the version number of container type used by the file.
void | SeekToBegin ()
| Seek to the begin of the content, i.e.
Public Member Functions inherited from RandomAccessFile
| RandomAccessFile (std::string_view filename, Subdirectory subdir)
| Create the RandomAccesFile.
| RandomAccessFile (const RandomAccessFile &)=delete
void | operator= (const RandomAccessFile &)=delete
const std::string & | GetFilename () const
| Get the filename of the opened file with the path from the SubDirectory and the extension.
const std::string & | GetSimplifiedFilename () const
| Get the simplified filename of the opened file.
size_t | GetPos () const
| Get position in the file.
size_t | GetStartPos () const
size_t | GetEndPos () const
void | SeekTo (size_t pos, int mode)
| Seek in the current file.
bool | AtEndOfFile () const
| Test if we have reached the end of the file.
uint8_t | ReadByte ()
| Read a byte from the file.
uint16_t | ReadWord ()
| Read a word (16 bits) from the file (in low endian format).
uint32_t | ReadDword ()
| Read a double word (32 bits) from the file (in low endian format).
void | ReadBlock (void *ptr, size_t size)
| Read a block.
void | SkipBytes (size_t n)
| Skip n bytes ahead in the file.

## Private Attributes
bool | palette_remap
| Whether or not a remap of the palette is required for this file.
uint8_t | container_version
| Container format of the sprite file.
size_t | content_begin
| The begin of the content of the sprite file, i.e. after the container metadata.

## Detailed Description

RandomAccessFile with some extra information specific for sprite files.

It automatically detects and stores the container version upload opening the file.

Definition at line 19 of file sprite_file_type.hpp.

## Constructor & Destructor Documentation

## ◆ SpriteFile()

SpriteFile::SpriteFile | ( | const std::string & | filename,
|  | Subdirectory | subdir,
|  | bool | palette_remap
| ) |  |

Create the SpriteFile.

Parameters

  filename | Name of the file at the disk.
  subdir | The sub directory to search this file in.
  palette_remap | Whether a palette remap needs to be performed for this file.

Definition at line 46 of file sprite_file.cpp.

References container_version, content_begin, GetGRFContainerVersion(), and RandomAccessFile::GetPos().

## Member Function Documentation

## ◆ GetContainerVersion()

uint8_t SpriteFile::GetContainerVersion | ( |  | ) | const
| inline

Get the version number of container type used by the file.

Returns
  The version.

Definition at line 38 of file sprite_file_type.hpp.

References container_version.

Referenced by LoadGrfFile(), LoadGrfFileIndexed(), LoadGRFSound(), LoadNewGRFFileFromFile(), LoadNextSprite(), ReadGRFSpriteOffsets(), and ReadSprite().

## ◆ NeedsPaletteRemap()

bool SpriteFile::NeedsPaletteRemap | ( |  | ) | const
| inline

Whether a palette remap is needed when loading sprites from this file.

Returns
  True when needed, otherwise false.

Definition at line 32 of file sprite_file_type.hpp.

References palette_remap.

Referenced by DecodeSingleSprite(), and ReadRecolourSprite().

## ◆ SeekToBegin()

void SpriteFile::SeekToBegin | ( |  | ) |
| inline

Seek to the begin of the content, i.e.

the position just after the container version has been determined.

Definition at line 43 of file sprite_file_type.hpp.

References RandomAccessFile::SeekTo().

Referenced by OpenCachedSpriteFile().

## Field Documentation

## ◆ container_version

uint8_t SpriteFile::container_version
| private

Container format of the sprite file.

Definition at line 21 of file sprite_file_type.hpp.

Referenced by GetContainerVersion(), and SpriteFile().

## ◆ content_begin

size_t SpriteFile::content_begin
| private

The begin of the content of the sprite file, i.e. after the container metadata.

Definition at line 22 of file sprite_file_type.hpp.

Referenced by SpriteFile().

## ◆ palette_remap

bool SpriteFile::palette_remap
| private

Whether or not a remap of the palette is required for this file.

Definition at line 20 of file sprite_file_type.hpp.

Referenced by NeedsPaletteRemap().

The documentation for this class was generated from the following files:

- src/spriteloader/sprite_file_type.hpp
- src/spriteloader/sprite_file.cpp