Update to 12.0-beta1

This commit is contained in:
dP
2021-08-15 14:57:29 +03:00
parent ac7d3eba75
commit 9df4f2c4fc
666 changed files with 61302 additions and 20466 deletions

View File

@@ -26,9 +26,6 @@
#include "safeguards.h"
/** Whether the given NewGRFs must get a palette remap from windows to DOS or not. */
bool _palette_remap_grf[MAX_FILE_SLOTS];
#include "table/landscape_sprite.h"
/** Offsets for loading the different "replacement" sprites in the files. */
@@ -42,35 +39,35 @@ static const SpriteID * const _landscape_spriteindexes[] = {
* Load an old fashioned GRF file.
* @param filename The name of the file to open.
* @param load_index The offset of the first sprite.
* @param file_index The Fio offset to load the file in.
* @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, int file_index)
static uint LoadGrfFile(const char *filename, uint load_index, bool needs_palette_remap)
{
uint load_index_org = load_index;
uint sprite_id = 0;
FioOpenFile(file_index, filename, BASESET_DIR);
SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
DEBUG(sprite, 2, "Reading grf-file '%s'", filename);
Debug(sprite, 2, "Reading grf-file '{}'", filename);
byte container_ver = GetGRFContainerVersion();
byte container_ver = file.GetContainerVersion();
if (container_ver == 0) usererror("Base grf '%s' is corrupt", filename);
ReadGRFSpriteOffsets(container_ver);
ReadGRFSpriteOffsets(file);
if (container_ver >= 2) {
/* Read compression. */
byte compression = FioReadByte();
byte compression = file.ReadByte();
if (compression != 0) usererror("Unsupported compression format");
}
while (LoadNextSprite(load_index, file_index, sprite_id, container_ver)) {
while (LoadNextSprite(load_index, file, sprite_id)) {
load_index++;
sprite_id++;
if (load_index >= MAX_SPRITES) {
usererror("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files.");
}
}
DEBUG(sprite, 2, "Currently %i sprites are loaded", load_index);
Debug(sprite, 2, "Currently {} sprites are loaded", load_index);
return load_index - load_index_org;
}
@@ -79,24 +76,24 @@ static uint LoadGrfFile(const char *filename, uint load_index, int file_index)
* Load an old fashioned GRF file to replace already loaded sprites.
* @param filename The name of the file to open.
* @param index_tbl The offsets of each of the sprites.
* @param file_index The Fio offset to load the file in.
* @param needs_palette_remap Whether the colours in the GRF file need a palette remap.
* @return The number of loaded sprites.
*/
static void LoadGrfFileIndexed(const char *filename, const SpriteID *index_tbl, int file_index)
static void LoadGrfFileIndexed(const char *filename, const SpriteID *index_tbl, bool needs_palette_remap)
{
uint start;
uint sprite_id = 0;
FioOpenFile(file_index, filename, BASESET_DIR);
SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
DEBUG(sprite, 2, "Reading indexed grf-file '%s'", filename);
Debug(sprite, 2, "Reading indexed grf-file '{}'", filename);
byte container_ver = GetGRFContainerVersion();
byte container_ver = file.GetContainerVersion();
if (container_ver == 0) usererror("Base grf '%s' is corrupt", filename);
ReadGRFSpriteOffsets(container_ver);
ReadGRFSpriteOffsets(file);
if (container_ver >= 2) {
/* Read compression. */
byte compression = FioReadByte();
byte compression = file.ReadByte();
if (compression != 0) usererror("Unsupported compression format");
}
@@ -104,8 +101,7 @@ static void LoadGrfFileIndexed(const char *filename, const SpriteID *index_tbl,
uint end = *index_tbl++;
do {
bool b = LoadNextSprite(start, file_index, sprite_id, container_ver);
(void)b; // Unused without asserts
[[maybe_unused]] bool b = LoadNextSprite(start, file, sprite_id);
assert(b);
sprite_id++;
} while (++start <= end);
@@ -123,7 +119,7 @@ void CheckExternalFiles()
const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
DEBUG(grf, 1, "Using the %s base graphics set", used_set->name.c_str());
Debug(grf, 1, "Using the {} base graphics set", used_set->name);
static const size_t ERROR_MESSAGE_LENGTH = 256;
static const size_t MISSING_FILE_MESSAGE_LENGTH = 128;
@@ -162,12 +158,9 @@ void CheckExternalFiles()
/** Actually load the sprite tables. */
static void LoadSpriteTables()
{
memset(_palette_remap_grf, 0, sizeof(_palette_remap_grf));
uint i = FIRST_GRF_SLOT;
const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
_palette_remap_grf[i] = (PAL_DOS != used_set->palette);
LoadGrfFile(used_set->files[GFT_BASE].filename, 0, i++);
LoadGrfFile(used_set->files[GFT_BASE].filename, 0, PAL_DOS != used_set->palette);
/*
* The second basic file always starts at the given location and does
@@ -175,8 +168,7 @@ static void LoadSpriteTables()
* has a few sprites less. However, we do not care about those missing
* sprites as they are not shown anyway (logos in intro game).
*/
_palette_remap_grf[i] = (PAL_DOS != used_set->palette);
LoadGrfFile(used_set->files[GFT_LOGOS].filename, 4793, i++);
LoadGrfFile(used_set->files[GFT_LOGOS].filename, 4793, PAL_DOS != used_set->palette);
/*
* Load additional sprites for climates other than temperate.
@@ -184,11 +176,10 @@ static void LoadSpriteTables()
* and the ground sprites.
*/
if (_settings_game.game_creation.landscape != LT_TEMPERATE) {
_palette_remap_grf[i] = (PAL_DOS != used_set->palette);
LoadGrfFileIndexed(
used_set->files[GFT_ARCTIC + _settings_game.game_creation.landscape - 1].filename,
_landscape_spriteindexes[_settings_game.game_creation.landscape - 1],
i++
PAL_DOS != used_set->palette
);
}
@@ -203,7 +194,8 @@ static void LoadSpriteTables()
GRFConfig *top = _grfconfig;
/* Default extra graphics */
GRFConfig *master = new GRFConfig("OPENTTD.GRF");
static const char *master_filename = "OPENTTD.GRF";
GRFConfig *master = new GRFConfig(master_filename);
master->palette |= GRFP_GRF_DOS;
FillGRFDetails(master, false, BASESET_DIR);
ClrBit(master->flags, GCF_INIT_ONLY);
@@ -227,11 +219,11 @@ static void LoadSpriteTables()
master->next = extra;
_grfconfig = master;
LoadNewGRF(SPR_NEWGRFS_BASE, i, 2);
LoadNewGRF(SPR_NEWGRFS_BASE, 2);
uint total_extra_graphics = SPR_NEWGRFS_BASE - SPR_OPENTTD_BASE;
_missing_extra_graphics = GetSpriteCountForSlot(i, SPR_OPENTTD_BASE, SPR_NEWGRFS_BASE);
DEBUG(sprite, 1, "%u extra sprites, %u from baseset, %u from fallback", total_extra_graphics, total_extra_graphics - _missing_extra_graphics, _missing_extra_graphics);
_missing_extra_graphics = GetSpriteCountForFile(master_filename, SPR_OPENTTD_BASE, SPR_NEWGRFS_BASE);
Debug(sprite, 1, "{} extra sprites, {} from baseset, {} from fallback", total_extra_graphics, total_extra_graphics - _missing_extra_graphics, _missing_extra_graphics);
/* The original baseset extra graphics intentionally make use of the fallback graphics.
* Let's say everything which provides less than 500 sprites misses the rest intentionally. */
@@ -249,10 +241,10 @@ static void RealChangeBlitter(const char *repl_blitter)
const char *cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
if (strcmp(cur_blitter, repl_blitter) == 0) return;
DEBUG(driver, 1, "Switching blitter from '%s' to '%s'... ", cur_blitter, repl_blitter);
Debug(driver, 1, "Switching blitter from '{}' to '{}'... ", cur_blitter, repl_blitter);
Blitter *new_blitter = BlitterFactory::SelectBlitter(repl_blitter);
if (new_blitter == nullptr) NOT_REACHED();
DEBUG(driver, 1, "Successfully switched to %s.", repl_blitter);
Debug(driver, 1, "Successfully switched to {}.", repl_blitter);
if (!VideoDriver::GetInstance()->AfterBlitterChange()) {
/* Failed to switch blitter, let's hope we can return to the old one. */
@@ -263,7 +255,7 @@ static void RealChangeBlitter(const char *repl_blitter)
VideoDriver::GetInstance()->ClearSystemSprites();
ClearFontCache();
GfxClearSpriteCache();
ReInitAllWindows();
ReInitAllWindows(false);
}
/**
@@ -345,13 +337,13 @@ void CheckBlitter()
ClearFontCache();
GfxClearSpriteCache();
ReInitAllWindows();
ReInitAllWindows(false);
}
/** Initialise and load all the sprites. */
void GfxLoadSprites()
{
DEBUG(sprite, 2, "Loading sprite set %d", _settings_game.game_creation.landscape);
Debug(sprite, 2, "Loading sprite set {}", _settings_game.game_creation.landscape);
SwitchNewGRFBlitter();
VideoDriver::GetInstance()->ClearSystemSprites();