mirror of https://github.com/OpenTTD/OpenTTD
Codefix: Use SpriteID when passing sprite IDs. (#13037)
parent
e1697a6ad1
commit
e076aaf740
|
@ -43,10 +43,10 @@ static const SpriteID * const _landscape_spriteindexes[] = {
|
||||||
* @param needs_palette_remap Whether the colours in the GRF file need a palette remap.
|
* @param needs_palette_remap Whether the colours in the GRF file need a palette remap.
|
||||||
* @return The number of loaded sprites.
|
* @return The number of loaded sprites.
|
||||||
*/
|
*/
|
||||||
static uint LoadGrfFile(const std::string &filename, uint load_index, bool needs_palette_remap)
|
static uint LoadGrfFile(const std::string &filename, SpriteID load_index, bool needs_palette_remap)
|
||||||
{
|
{
|
||||||
uint load_index_org = load_index;
|
SpriteID load_index_org = load_index;
|
||||||
uint sprite_id = 0;
|
SpriteID sprite_id = 0;
|
||||||
|
|
||||||
SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
|
SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
|
||||||
|
|
||||||
|
|
|
@ -6469,7 +6469,7 @@ static void GraphicsNew(ByteReader &buf)
|
||||||
|
|
||||||
for (; num > 0; num--) {
|
for (; num > 0; num--) {
|
||||||
_cur.nfo_line++;
|
_cur.nfo_line++;
|
||||||
int load_index = (replace == 0 ? _cur.spriteid++ : replace++);
|
SpriteID load_index = (replace == 0 ? _cur.spriteid++ : replace++);
|
||||||
LoadNextSprite(load_index, *_cur.file, _cur.nfo_line);
|
LoadNextSprite(load_index, *_cur.file, _cur.nfo_line);
|
||||||
if (dup_oneway_sprites) {
|
if (dup_oneway_sprites) {
|
||||||
DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_N_OFFSET);
|
DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_N_OFFSET);
|
||||||
|
@ -7084,7 +7084,7 @@ static void SpriteReplace(ByteReader &buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint j = 0; j < num_sprites; j++) {
|
for (uint j = 0; j < num_sprites; j++) {
|
||||||
int load_index = first_sprite + j;
|
SpriteID load_index = first_sprite + j;
|
||||||
_cur.nfo_line++;
|
_cur.nfo_line++;
|
||||||
LoadNextSprite(load_index, *_cur.file, _cur.nfo_line); // XXX
|
LoadNextSprite(load_index, *_cur.file, _cur.nfo_line); // XXX
|
||||||
|
|
||||||
|
@ -10014,7 +10014,7 @@ static void AfterLoadGRFs()
|
||||||
* @param load_index The offset for the first sprite to add.
|
* @param load_index The offset for the first sprite to add.
|
||||||
* @param num_baseset Number of NewGRFs at the front of the list to look up in the baseset dir instead of the newgrf dir.
|
* @param num_baseset Number of NewGRFs at the front of the list to look up in the baseset dir instead of the newgrf dir.
|
||||||
*/
|
*/
|
||||||
void LoadNewGRF(uint load_index, uint num_baseset)
|
void LoadNewGRF(SpriteID load_index, uint num_baseset)
|
||||||
{
|
{
|
||||||
/* In case of networking we need to "sync" the start values
|
/* In case of networking we need to "sync" the start values
|
||||||
* so all NewGRFs are loaded equally. For this we use the
|
* so all NewGRFs are loaded equally. For this we use the
|
||||||
|
|
|
@ -196,7 +196,7 @@ inline bool HasGrfMiscBit(GrfMiscBit bit)
|
||||||
extern GRFLoadedFeatures _loaded_newgrf_features;
|
extern GRFLoadedFeatures _loaded_newgrf_features;
|
||||||
|
|
||||||
void LoadNewGRFFile(struct GRFConfig *config, GrfLoadingStage stage, Subdirectory subdir, bool temporary);
|
void LoadNewGRFFile(struct GRFConfig *config, GrfLoadingStage stage, Subdirectory subdir, bool temporary);
|
||||||
void LoadNewGRF(uint load_index, uint num_baseset);
|
void LoadNewGRF(SpriteID load_index, uint num_baseset);
|
||||||
void ReloadNewGRFData(); // in saveload/afterload.cpp
|
void ReloadNewGRFData(); // in saveload/afterload.cpp
|
||||||
void ResetNewGRFData();
|
void ResetNewGRFData();
|
||||||
void ResetPersistentNewGRFData();
|
void ResetPersistentNewGRFData();
|
||||||
|
|
|
@ -573,7 +573,7 @@ void ReadGRFSpriteOffsets(SpriteFile &file)
|
||||||
|
|
||||||
/* Loop over all sprite section entries and store the file
|
/* Loop over all sprite section entries and store the file
|
||||||
* offset for each newly encountered ID. */
|
* offset for each newly encountered ID. */
|
||||||
uint32_t id, prev_id = 0;
|
SpriteID id, prev_id = 0;
|
||||||
while ((id = file.ReadDword()) != 0) {
|
while ((id = file.ReadDword()) != 0) {
|
||||||
if (id != prev_id) {
|
if (id != prev_id) {
|
||||||
_grf_sprite_offsets[prev_id] = offset;
|
_grf_sprite_offsets[prev_id] = offset;
|
||||||
|
@ -615,7 +615,7 @@ void ReadGRFSpriteOffsets(SpriteFile &file)
|
||||||
* @param container_version Container version of the GRF.
|
* @param container_version Container version of the GRF.
|
||||||
* @return True if a valid sprite was loaded, false on any error.
|
* @return True if a valid sprite was loaded, false on any error.
|
||||||
*/
|
*/
|
||||||
bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id)
|
bool LoadNextSprite(SpriteID load_index, SpriteFile &file, uint file_sprite_id)
|
||||||
{
|
{
|
||||||
size_t file_pos = file.GetPos();
|
size_t file_pos = file.GetPos();
|
||||||
|
|
||||||
|
@ -661,7 +661,7 @@ bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id)
|
||||||
|
|
||||||
if (type == SpriteType::Invalid) return false;
|
if (type == SpriteType::Invalid) return false;
|
||||||
|
|
||||||
if (static_cast<uint>(load_index) >= MAX_SPRITES) {
|
if (load_index >= MAX_SPRITES) {
|
||||||
UserError("Tried to load too many sprites (#{}; max {})", load_index, MAX_SPRITES);
|
UserError("Tried to load too many sprites (#{}; max {})", load_index, MAX_SPRITES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ std::span<const std::unique_ptr<SpriteFile>> GetCachedSpriteFiles();
|
||||||
|
|
||||||
void ReadGRFSpriteOffsets(SpriteFile &file);
|
void ReadGRFSpriteOffsets(SpriteFile &file);
|
||||||
size_t GetGRFSpriteOffset(uint32_t id);
|
size_t GetGRFSpriteOffset(uint32_t id);
|
||||||
bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id);
|
bool LoadNextSprite(SpriteID load_index, SpriteFile &file, uint file_sprite_id);
|
||||||
bool SkipSpriteData(SpriteFile &file, uint8_t type, uint16_t num);
|
bool SkipSpriteData(SpriteFile &file, uint8_t type, uint16_t num);
|
||||||
void DupSprite(SpriteID old_spr, SpriteID new_spr);
|
void DupSprite(SpriteID old_spr, SpriteID new_spr);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include "../spritecache_internal.h"
|
#include "../spritecache_internal.h"
|
||||||
#include "../table/sprites.h"
|
#include "../table/sprites.h"
|
||||||
|
|
||||||
static bool MockLoadNextSprite(int load_index)
|
static bool MockLoadNextSprite(SpriteID load_index)
|
||||||
{
|
{
|
||||||
SimpleSpriteAllocator allocator;
|
SimpleSpriteAllocator allocator;
|
||||||
static Sprite *sprite = allocator.Allocate<Sprite>(sizeof(*sprite));
|
static Sprite *sprite = allocator.Allocate<Sprite>(sizeof(*sprite));
|
||||||
|
@ -33,7 +33,7 @@ static bool MockLoadNextSprite(int load_index)
|
||||||
sc->control_flags = 0;
|
sc->control_flags = 0;
|
||||||
|
|
||||||
/* Fill with empty sprites up until the default sprite count. */
|
/* Fill with empty sprites up until the default sprite count. */
|
||||||
return (uint)load_index < SPR_OPENTTD_BASE + OPENTTD_SPRITE_COUNT;
|
return load_index < SPR_OPENTTD_BASE + OPENTTD_SPRITE_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MockGfxLoadSprites()
|
void MockGfxLoadSprites()
|
||||||
|
@ -43,7 +43,7 @@ void MockGfxLoadSprites()
|
||||||
|
|
||||||
GfxInitSpriteMem();
|
GfxInitSpriteMem();
|
||||||
|
|
||||||
int load_index = 0;
|
SpriteID load_index = 0;
|
||||||
while (MockLoadNextSprite(load_index)) {
|
while (MockLoadNextSprite(load_index)) {
|
||||||
load_index++;
|
load_index++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue