Industry: Determine which tiles in industry layouts are not animated
Do not set these as animated tiles for new industries
This commit is contained in:
@@ -271,6 +271,7 @@ add_files(
|
||||
newgrf_industries.h
|
||||
newgrf_industrytiles.cpp
|
||||
newgrf_industrytiles.h
|
||||
newgrf_industrytiles_analysis.h
|
||||
newgrf_newsignals.cpp
|
||||
newgrf_newsignals.h
|
||||
newgrf_object.cpp
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include "thread.h"
|
||||
#include "tgp.h"
|
||||
#include "signal_func.h"
|
||||
#include "newgrf_industrytiles.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
@@ -318,6 +319,7 @@ void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_setti
|
||||
InitialiseExtraAspectsVariable();
|
||||
LoadStringWidthTable();
|
||||
AnalyseEngineCallbacks();
|
||||
AnalyseIndustryTileSpriteGroups();
|
||||
|
||||
/* Re-init the windowing system */
|
||||
ResetWindowSystem();
|
||||
|
@@ -1948,6 +1948,9 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
|
||||
/* Plant the tiles */
|
||||
|
||||
uint64 anim_inhibit_mask = indspec->layout_anim_masks[layout_index];
|
||||
|
||||
uint gfx_idx = 0;
|
||||
for (const IndustryTileLayoutTile &it : layout) {
|
||||
TileIndex cur_tile = tile + ToTileIndexDiff(it.ti);
|
||||
|
||||
@@ -1968,7 +1971,11 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
/* it->gfx is stored in the map. But the translated ID cur_gfx is the interesting one */
|
||||
IndustryGfx cur_gfx = GetTranslatedIndustryTileID(it.gfx);
|
||||
const IndustryTileSpec *its = GetIndustryTileSpec(cur_gfx);
|
||||
if (its->animation.status != ANIM_STATUS_NO_ANIMATION) AddAnimatedTile(cur_tile);
|
||||
if (its->animation.status != ANIM_STATUS_NO_ANIMATION) {
|
||||
if (gfx_idx >= 64 || !HasBit(anim_inhibit_mask, gfx_idx)) AddAnimatedTile(cur_tile);
|
||||
}
|
||||
|
||||
gfx_idx++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -106,6 +106,7 @@ using IndustryTileLayout = std::vector<IndustryTileLayoutTile>;
|
||||
*/
|
||||
struct IndustrySpec {
|
||||
std::vector<IndustryTileLayout> layouts; ///< List of possible tile layouts for the industry
|
||||
std::vector<uint64> layout_anim_masks; ///< Animation inhibit masks for tile layouts for the industry
|
||||
uint8 cost_multiplier; ///< Base construction cost multiplier.
|
||||
uint32 removal_cost_multiplier; ///< Base removal cost multiplier.
|
||||
uint32 prospecting_chance; ///< Chance prospecting succeeds
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include "command_func.h"
|
||||
#include "water.h"
|
||||
#include "newgrf_animation_base.h"
|
||||
#include "newgrf_industrytiles_analysis.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
@@ -390,3 +391,71 @@ void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
|
||||
DoReseedIndustry(ind, reseed_industry);
|
||||
}
|
||||
|
||||
void AnalyseIndustryTileSpriteGroups()
|
||||
{
|
||||
for (IndustrySpec &spec : _industry_specs) {
|
||||
const uint layout_count = (uint)spec.layouts.size();
|
||||
spec.layout_anim_masks.clear();
|
||||
spec.layout_anim_masks.resize(layout_count);
|
||||
|
||||
IndustryTileLayout layout;
|
||||
for (uint idx = 0; idx < layout_count; idx++) {
|
||||
btree::btree_set<IndustryGfx> seen_gfx;
|
||||
layout.clear();
|
||||
for (IndustryTileLayoutTile it : spec.layouts[idx]) {
|
||||
if (it.gfx == 0xFF) continue;
|
||||
|
||||
IndustryGfx gfx = GetTranslatedIndustryTileID(it.gfx);
|
||||
layout.push_back({ it.ti, gfx });
|
||||
seen_gfx.insert(gfx);
|
||||
if (layout.size() == 64) break;
|
||||
}
|
||||
|
||||
/* Layout now contains the translated tile layout with gaps removed, up to a maximum of 64 tiles */
|
||||
|
||||
uint64 anim_mask = 0;
|
||||
|
||||
uint64 to_check = UINT64_MAX >> (64 - layout.size());
|
||||
|
||||
while (to_check != 0) {
|
||||
uint64 current = 0;
|
||||
uint i = FindFirstBit(to_check);
|
||||
IndustryGfx gfx = layout[i].gfx;
|
||||
for (; i < layout.size(); i++) {
|
||||
if (gfx == layout[i].gfx) SetBit(current, i);
|
||||
}
|
||||
to_check &= ~current;
|
||||
|
||||
const IndustryTileSpec &tilespec = _industry_tile_specs[gfx];
|
||||
if (tilespec.grf_prop.spritegroup[0] == nullptr) continue;
|
||||
|
||||
if (HasBit(tilespec.callback_mask, CBID_INDTILE_ANIM_NEXT_FRAME)) {
|
||||
/* There may be sound effects, or custom animation start/stop behaviour, don't inhibit */
|
||||
continue;
|
||||
}
|
||||
|
||||
anim_mask |= current;
|
||||
|
||||
AnalyseCallbackOperationIndustryTileData data;
|
||||
data.layout = &layout;
|
||||
data.check_mask = current;
|
||||
data.result_mask = &anim_mask;
|
||||
data.layout_index = idx + 1;
|
||||
data.anim_state_at_offset = false;
|
||||
|
||||
AnalyseCallbackOperation op;
|
||||
op.mode = ACOM_INDUSTRY_TILE;
|
||||
op.data.indtile = &data;
|
||||
tilespec.grf_prop.spritegroup[0]->AnalyseCallbacks(op);
|
||||
|
||||
if (data.anim_state_at_offset) {
|
||||
/* Give up: use of get anim state of offset tiles */
|
||||
anim_mask = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spec.layout_anim_masks[idx] = anim_mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -76,4 +76,6 @@ enum IndustryTileTrigger {
|
||||
void TriggerIndustryTile(TileIndex t, IndustryTileTrigger trigger);
|
||||
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger);
|
||||
|
||||
void AnalyseIndustryTileSpriteGroups();
|
||||
|
||||
#endif /* NEWGRF_INDUSTRYTILES_H */
|
||||
|
23
src/newgrf_industrytiles_analysis.h
Normal file
23
src/newgrf_industrytiles_analysis.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file newgrf_industrytiles_analysis.h NewGRF handling of industry tiles: analysis. */
|
||||
|
||||
#ifndef NEWGRF_INDUSTRYTILES_ANALYSIS_H
|
||||
#define NEWGRF_INDUSTRYTILES_ANALYSIS_H
|
||||
|
||||
#include "industrytype.h"
|
||||
|
||||
struct AnalyseCallbackOperationIndustryTileData {
|
||||
const IndustryTileLayout *layout;
|
||||
uint64 check_mask;
|
||||
uint64 *result_mask;
|
||||
uint8 layout_index;
|
||||
bool anim_state_at_offset;
|
||||
};
|
||||
|
||||
#endif /* NEWGRF_INDUSTRYTILES_ANALYSIS_H */
|
@@ -16,6 +16,7 @@
|
||||
#include "newgrf_cache_check.h"
|
||||
#include "string_func.h"
|
||||
#include "newgrf_extension.h"
|
||||
#include "newgrf_industrytiles_analysis.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
@@ -285,6 +286,8 @@ void DeterministicSpriteGroup::AnalyseCallbacks(AnalyseCallbackOperation &op) co
|
||||
return;
|
||||
}
|
||||
|
||||
if (op.mode == ACOM_INDUSTRY_TILE && op.data.indtile->anim_state_at_offset) return;
|
||||
|
||||
auto check_1A_range = [&]() -> bool {
|
||||
if (this->GroupMayBeBypassed()) {
|
||||
/* Not clear why some GRFs do this, perhaps a way of commenting out a branch */
|
||||
@@ -423,6 +426,81 @@ void DeterministicSpriteGroup::AnalyseCallbacks(AnalyseCallbackOperation &op) co
|
||||
op.callbacks_used |= SGCU_CB36_SPEED_RAILTYPE;
|
||||
return;
|
||||
}
|
||||
if (op.mode == ACOM_INDUSTRY_TILE && adjust.variable == 0xC) {
|
||||
if (adjust.shift_num == 0 && (adjust.and_mask & 0xFF) == 0xFF && adjust.type == DSGA_TYPE_NONE) {
|
||||
/* Callback switch, skip to the default/graphics chain */
|
||||
for (const auto &range : this->ranges) {
|
||||
if (range.low == 0) {
|
||||
if (range.group != nullptr) range.group->AnalyseCallbacks(op);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this->default_group != nullptr) this->default_group->AnalyseCallbacks(op);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (op.mode == ACOM_INDUSTRY_TILE && adjust.variable == 0x44 && this->var_scope == VSG_SCOPE_PARENT) {
|
||||
if (adjust.shift_num == 0 && (adjust.and_mask & 0xFF) == 0xFF && adjust.type == DSGA_TYPE_NONE) {
|
||||
/* Layout index switch */
|
||||
for (const auto &range : this->ranges) {
|
||||
if (range.low <= op.data.indtile->layout_index && op.data.indtile->layout_index <= range.high) {
|
||||
if (range.group != nullptr) range.group->AnalyseCallbacks(op);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this->default_group != nullptr) this->default_group->AnalyseCallbacks(op);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (op.mode == ACOM_INDUSTRY_TILE && adjust.variable == 0x43 && this->var_scope == VSG_SCOPE_SELF) {
|
||||
if (adjust.shift_num == 0 && adjust.and_mask == 0xFFFF && adjust.type == DSGA_TYPE_NONE) {
|
||||
/* Relative position switch */
|
||||
uint64 default_mask = op.data.indtile->check_mask;
|
||||
for (const auto &range : this->ranges) {
|
||||
if (range.high - range.low < 32) {
|
||||
uint64 new_check_mask = 0;
|
||||
for (uint i = range.low; i <= range.high; i++) {
|
||||
int16 x = i & 0xFF;
|
||||
int16 y = (i >> 8) & 0xFF;
|
||||
for (uint bit : SetBitIterator<uint, uint64>(op.data.indtile->check_mask)) {
|
||||
const TileIndexDiffC &ti = (*(op.data.indtile->layout))[bit].ti;
|
||||
if (ti.x == x && ti.y == y) {
|
||||
SetBit(new_check_mask, bit);
|
||||
}
|
||||
}
|
||||
}
|
||||
default_mask &= ~new_check_mask;
|
||||
if (range.group != nullptr) {
|
||||
AnalyseCallbackOperationIndustryTileData data = *(op.data.indtile);
|
||||
data.check_mask = new_check_mask;
|
||||
|
||||
AnalyseCallbackOperation sub_op;
|
||||
sub_op.mode = ACOM_INDUSTRY_TILE;
|
||||
sub_op.data.indtile = &data;
|
||||
range.group->AnalyseCallbacks(sub_op);
|
||||
|
||||
if (data.anim_state_at_offset) {
|
||||
op.data.indtile->anim_state_at_offset = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (range.group != nullptr) range.group->AnalyseCallbacks(op);
|
||||
}
|
||||
}
|
||||
if (this->default_group != nullptr) {
|
||||
AnalyseCallbackOperationIndustryTileData data = *(op.data.indtile);
|
||||
data.check_mask = default_mask;
|
||||
|
||||
AnalyseCallbackOperation sub_op;
|
||||
sub_op.mode = ACOM_INDUSTRY_TILE;
|
||||
sub_op.data.indtile = &data;
|
||||
|
||||
this->default_group->AnalyseCallbacks(sub_op);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto &adjust : this->adjusts) {
|
||||
if (op.mode == ACOM_CB_VAR && adjust.variable == 0xC) {
|
||||
@@ -436,6 +514,14 @@ void DeterministicSpriteGroup::AnalyseCallbacks(AnalyseCallbackOperation &op) co
|
||||
if (adjust.variable == 0x7E && adjust.subroutine != nullptr) {
|
||||
adjust.subroutine->AnalyseCallbacks(op);
|
||||
}
|
||||
if (op.mode == ACOM_INDUSTRY_TILE && this->var_scope == VSG_SCOPE_SELF && (adjust.variable == 0x44 || (adjust.variable == 0x61 && adjust.parameter == 0))) {
|
||||
*(op.data.indtile->result_mask) &= ~op.data.indtile->check_mask;
|
||||
return;
|
||||
}
|
||||
if (op.mode == ACOM_INDUSTRY_TILE && ((this->var_scope == VSG_SCOPE_SELF && adjust.variable == 0x61) || (this->var_scope == VSG_SCOPE_PARENT && adjust.variable == 0x63))) {
|
||||
op.data.indtile->anim_state_at_offset = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!this->calculated_result) {
|
||||
for (const auto &range : this->ranges) {
|
||||
|
@@ -54,8 +54,11 @@ enum AnalyseCallbackOperationMode {
|
||||
ACOM_CB36_PROP,
|
||||
ACOM_FIND_CB_RESULT,
|
||||
ACOM_CB36_SPEED,
|
||||
ACOM_INDUSTRY_TILE,
|
||||
};
|
||||
|
||||
struct AnalyseCallbackOperationIndustryTileData;
|
||||
|
||||
struct AnalyseCallbackOperation {
|
||||
struct FindCBResultData {
|
||||
uint16 callback;
|
||||
@@ -70,6 +73,7 @@ struct AnalyseCallbackOperation {
|
||||
bool cb_result_found = false;
|
||||
union {
|
||||
FindCBResultData cb_result;
|
||||
AnalyseCallbackOperationIndustryTileData *indtile;
|
||||
} data;
|
||||
};
|
||||
|
||||
|
@@ -69,6 +69,7 @@
|
||||
#include "../infrastructure_func.h"
|
||||
#include "../event_logs.h"
|
||||
#include "../newgrf_object.h"
|
||||
#include "../newgrf_industrytiles.h"
|
||||
|
||||
|
||||
#include "saveload_internal.h"
|
||||
@@ -950,6 +951,7 @@ bool AfterLoadGame()
|
||||
}
|
||||
|
||||
AfterLoadEngines();
|
||||
AnalyseIndustryTileSpriteGroups();
|
||||
|
||||
/* Update all vehicles */
|
||||
AfterLoadVehicles(true);
|
||||
@@ -4138,6 +4140,7 @@ void ReloadNewGRFData()
|
||||
/* reload vehicles */
|
||||
ResetVehicleHash();
|
||||
AfterLoadEngines();
|
||||
AnalyseIndustryTileSpriteGroups();
|
||||
AfterLoadVehicles(false);
|
||||
StartupEngines();
|
||||
GroupStatistics::UpdateAfterLoad();
|
||||
|
@@ -1127,7 +1127,7 @@ enum IndustryTypes {
|
||||
|
||||
#define MI(tbl, sndc, snd, d, pc, ai1, ai2, ai3, ai4, ag1, ag2, ag3, ag4, col, \
|
||||
c1, c2, c3, proc, p1, r1, p2, r2, m, a1, im1, a2, im2, a3, im3, pr, clim, bev, in, intx, s1, s2, s3) \
|
||||
{tbl, d, 0, pc, {c1, c2, c3}, proc, \
|
||||
{tbl, {}, d, 0, pc, {c1, c2, c3}, proc, \
|
||||
{p1, p2, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID}, \
|
||||
{r1, r2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, m, \
|
||||
{a1, a2, a3, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID}, \
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include "../waypoint_base.h"
|
||||
#include "../string_func_extra.h"
|
||||
#include "../newgrf_extension.h"
|
||||
#include "../animated_tile.h"
|
||||
|
||||
/* Helper for filling property tables */
|
||||
#define NIP(prop, base, variable, type, name) { name, (ptrdiff_t)cpp_offsetof(base, variable), cpp_sizeof(base, variable), prop, type }
|
||||
@@ -626,7 +627,7 @@ class NIHIndustryTile : public NIHelper {
|
||||
{
|
||||
char buffer[1024];
|
||||
output.print("Debug Info:");
|
||||
seprintf(buffer, lastof(buffer), " Gfx Index: %u", GetIndustryGfx(index));
|
||||
seprintf(buffer, lastof(buffer), " Gfx Index: %u, animated tile: %d", GetIndustryGfx(index), _animated_tiles.find(index) != _animated_tiles.end());
|
||||
output.print(buffer);
|
||||
const IndustryTileSpec *indts = GetIndustryTileSpec(GetIndustryGfx(index));
|
||||
if (indts) {
|
||||
@@ -822,6 +823,12 @@ class NIHIndustry : public NIHelper {
|
||||
seprintf(buffer, lastof(buffer), " Counter production interval: %u", ScaleQuantity(INDUSTRY_PRODUCE_TICKS, -_settings_game.economy.industry_cargo_scale_factor));
|
||||
output.print(buffer);
|
||||
}
|
||||
seprintf(buffer, lastof(buffer), " Number of layouts: %u", (uint)indsp->layouts.size());
|
||||
output.print(buffer);
|
||||
for (size_t i = 0; i < indsp->layout_anim_masks.size(); i++) {
|
||||
seprintf(buffer, lastof(buffer), " Layout anim inhibit mask %u: " OTTD_PRINTFHEX64, (uint)i, indsp->layout_anim_masks[i]);
|
||||
output.print(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user