Implement custom sprite detection with new sprite mechanism
This commit is contained in:
@@ -42,21 +42,14 @@ static const SpriteID * const _landscape_spriteindexes[] = {
|
|||||||
_landscape_spriteindexes_toyland,
|
_landscape_spriteindexes_toyland,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** file index of first user-added GRF file */
|
|
||||||
int _first_user_grf_file_index;
|
|
||||||
int _opengfx_grf_file_index;
|
|
||||||
int _progsig_grf_file_index;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an old fashioned GRF file.
|
* Load an old fashioned GRF file.
|
||||||
* @param filename The name of the file to open.
|
* @param filename The name of the file to open.
|
||||||
* @param load_index The offset of the first sprite.
|
* @param load_index The offset of the first sprite.
|
||||||
* @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.
|
|
||||||
*/
|
*/
|
||||||
static uint LoadGrfFile(const char *filename, uint load_index, bool needs_palette_remap)
|
static SpriteFile &LoadGrfFile(const char *filename, uint load_index, bool needs_palette_remap)
|
||||||
{
|
{
|
||||||
uint load_index_org = load_index;
|
|
||||||
uint sprite_id = 0;
|
uint sprite_id = 0;
|
||||||
|
|
||||||
SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
|
SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
|
||||||
@@ -81,7 +74,7 @@ static uint LoadGrfFile(const char *filename, uint load_index, bool needs_palett
|
|||||||
}
|
}
|
||||||
DEBUG(sprite, 2, "Currently %i sprites are loaded", load_index);
|
DEBUG(sprite, 2, "Currently %i sprites are loaded", load_index);
|
||||||
|
|
||||||
return load_index - load_index_org;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -176,8 +169,8 @@ static void LoadSpriteTables()
|
|||||||
LoadGrfFile(used_set->files[GFT_BASE].filename, 0, PAL_DOS != used_set->palette);
|
LoadGrfFile(used_set->files[GFT_BASE].filename, 0, PAL_DOS != used_set->palette);
|
||||||
|
|
||||||
/* Progsignal sprites. */
|
/* Progsignal sprites. */
|
||||||
//_progsig_grf_file_index = i;
|
SpriteFile &progsig_file = LoadGrfFile("progsignals.grf", SPR_PROGSIGNAL_BASE, false);
|
||||||
LoadGrfFile("progsignals.grf", SPR_PROGSIGNAL_BASE, false);
|
progsig_file.flags |= SFF_PROGSIG;
|
||||||
|
|
||||||
/* Fill duplicate programmable pre-signal graphics sprite block */
|
/* Fill duplicate programmable pre-signal graphics sprite block */
|
||||||
for (uint i = 0; i < PROGSIGNAL_SPRITE_COUNT; i++) {
|
for (uint i = 0; i < PROGSIGNAL_SPRITE_COUNT; i++) {
|
||||||
@@ -264,17 +257,6 @@ static void LoadSpriteTables()
|
|||||||
* Let's say everything which provides less than 500 sprites misses the rest intentionally. */
|
* Let's say everything which provides less than 500 sprites misses the rest intentionally. */
|
||||||
if (500 + _missing_extra_graphics > total_extra_graphics) _missing_extra_graphics = 0;
|
if (500 + _missing_extra_graphics > total_extra_graphics) _missing_extra_graphics = 0;
|
||||||
|
|
||||||
//_first_user_grf_file_index = i + 1;
|
|
||||||
//_opengfx_grf_file_index = -1;
|
|
||||||
for (GRFConfig *c = master; c != nullptr; c = c->next) {
|
|
||||||
if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND || HasBit(c->flags, GCF_INIT_ONLY)) continue;
|
|
||||||
if (c->ident.grfid == BSWAP32(0xFF4F4701)) {
|
|
||||||
/* Detect OpenGFX GRF ID */
|
|
||||||
//_opengfx_grf_file_index = index;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Free and remove the top element. */
|
/* Free and remove the top element. */
|
||||||
delete extra;
|
delete extra;
|
||||||
delete master;
|
delete master;
|
||||||
|
@@ -10014,7 +10014,10 @@ void LoadNewGRFFile(GRFConfig *config, GrfLoadingStage stage, Subdirectory subdi
|
|||||||
SpriteFile temporarySpriteFile(filename, subdir, needs_palette_remap);
|
SpriteFile temporarySpriteFile(filename, subdir, needs_palette_remap);
|
||||||
LoadNewGRFFileFromFile(config, stage, temporarySpriteFile);
|
LoadNewGRFFileFromFile(config, stage, temporarySpriteFile);
|
||||||
} else {
|
} else {
|
||||||
LoadNewGRFFileFromFile(config, stage, OpenCachedSpriteFile(filename, subdir, needs_palette_remap));
|
SpriteFile &file = OpenCachedSpriteFile(filename, subdir, needs_palette_remap);
|
||||||
|
LoadNewGRFFileFromFile(config, stage, file);
|
||||||
|
file.flags |= SFF_USERGRF;
|
||||||
|
if (config->ident.grfid == BSWAP32(0xFF4F4701)) file.flags |= SFF_OGFX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2630,17 +2630,15 @@ void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track track, Sign
|
|||||||
sprite = SPR_PROGSIGNAL_BASE + 16 + image * 2 + condition;
|
sprite = SPR_PROGSIGNAL_BASE + 16 + image * 2 + condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int _progsig_grf_file_index;
|
SpriteFile *file = GetOriginFile(sprite);
|
||||||
//is_custom_sprite = (int) GetOriginFileSlot(sprite) != _progsig_grf_file_index;
|
is_custom_sprite = !(file != nullptr && file->flags & SFF_PROGSIG);
|
||||||
} else {
|
} else {
|
||||||
/* Normal electric signals are stored in a different sprite block than all other signals. */
|
/* Normal electric signals are stored in a different sprite block than all other signals. */
|
||||||
sprite = (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) ? SPR_ORIGINAL_SIGNALS_BASE : SPR_SIGNALS_BASE - 16;
|
sprite = (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) ? SPR_ORIGINAL_SIGNALS_BASE : SPR_SIGNALS_BASE - 16;
|
||||||
sprite += type * 16 + variant * 64 + image * 2 + condition + (IsSignalSpritePBS(type) ? 64 : 0);
|
sprite += type * 16 + variant * 64 + image * 2 + condition + (IsSignalSpritePBS(type) ? 64 : 0);
|
||||||
|
|
||||||
int origin_slot = 0; //GetOriginFileSlot(sprite);
|
SpriteFile *file = GetOriginFile(sprite);
|
||||||
extern int _first_user_grf_file_index;
|
is_custom_sprite = file != nullptr && (file->flags & SFF_USERGRF) && !(file->flags & SFF_OGFX);
|
||||||
extern int _opengfx_grf_file_index;
|
|
||||||
is_custom_sprite = origin_slot != _opengfx_grf_file_index && (origin_slot >= _first_user_grf_file_index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_custom_sprite && show_restricted && _settings_client.gui.show_restricted_signal_default && !HasBit(rti->ctrl_flags, RTCF_RESTRICTEDSIG)) {
|
if (is_custom_sprite && show_restricted && _settings_client.gui.show_restricted_signal_default && !HasBit(rti->ctrl_flags, RTCF_RESTRICTEDSIG)) {
|
||||||
|
@@ -12,15 +12,26 @@
|
|||||||
|
|
||||||
#include "../random_access_file_type.h"
|
#include "../random_access_file_type.h"
|
||||||
|
|
||||||
|
enum SpriteFileFlags : uint8 {
|
||||||
|
SFF_NONE = 0,
|
||||||
|
SFF_USERGRF = 1 << 0,
|
||||||
|
SFF_OGFX = 1 << 1,
|
||||||
|
SFF_PROGSIG = 1 << 2,
|
||||||
|
};
|
||||||
|
DECLARE_ENUM_AS_BIT_SET(SpriteFileFlags)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RandomAccessFile with some extra information specific for sprite files.
|
* RandomAccessFile with some extra information specific for sprite files.
|
||||||
* It automatically detects and stores the container version upload opening the file.
|
* It automatically detects and stores the container version upload opening the file.
|
||||||
*/
|
*/
|
||||||
class SpriteFile : public RandomAccessFile {
|
class SpriteFile : public RandomAccessFile {
|
||||||
|
size_t content_begin; ///< The begin of the content of the sprite file, i.e. after the container metadata.
|
||||||
bool palette_remap; ///< Whether or not a remap of the palette is required for this file.
|
bool palette_remap; ///< Whether or not a remap of the palette is required for this file.
|
||||||
byte container_version; ///< Container format of the sprite file.
|
byte 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.
|
|
||||||
public:
|
public:
|
||||||
|
SpriteFileFlags flags = SFF_NONE;
|
||||||
|
|
||||||
SpriteFile(const std::string &filename, Subdirectory subdir, bool palette_remap);
|
SpriteFile(const std::string &filename, Subdirectory subdir, bool palette_remap);
|
||||||
SpriteFile(const SpriteFile&) = delete;
|
SpriteFile(const SpriteFile&) = delete;
|
||||||
void operator=(const SpriteFile&) = delete;
|
void operator=(const SpriteFile&) = delete;
|
||||||
|
Reference in New Issue
Block a user