From 31668b8f944e24a0acf02d7bacbb6ca47882e872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guilloux?= Date: Wed, 31 Aug 2022 12:52:13 +0200 Subject: [PATCH 1/4] Fix #9914, 86818e5: prevent more useless pathfinder run for blocked vehicles (#9917) --- src/roadveh_cmd.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 27900a2c8e..69e92f789f 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1280,9 +1280,12 @@ again: Direction new_dir = RoadVehGetSlidingDirection(v, x, y); if (v->IsFrontEngine()) { - Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir); + const Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir); if (u != nullptr) { v->cur_speed = u->First()->cur_speed; + /* We might be blocked, prevent pathfinding rerun as we already know where we are heading to. */ + v->path.tile.push_front(tile); + v->path.td.push_front(dir); return false; } } @@ -1392,15 +1395,15 @@ again: int y = TileY(v->tile) * TILE_SIZE + rdp[turn_around_start_frame].y; Direction new_dir = RoadVehGetSlidingDirection(v, x, y); - if (v->IsFrontEngine() && RoadVehFindCloseTo(v, x, y, new_dir) != nullptr) { - /* We are blocked. */ - v->cur_speed = 0; - if (!v->path.empty()) { - /* Prevent pathfinding rerun as we already know where we are heading to. */ + if (v->IsFrontEngine()) { + const Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir); + if (u != nullptr) { + v->cur_speed = u->First()->cur_speed; + /* We might be blocked, prevent pathfinding rerun as we already know where we are heading to. */ v->path.tile.push_front(v->tile); v->path.td.push_front(dir); + return false; } - return false; } uint32 r = VehicleEnterTile(v, v->tile, x, y); From 2fe8a257ac03a7b14dff28ca59b62114f9d2339d Mon Sep 17 00:00:00 2001 From: Aaron Katzin Date: Wed, 31 Aug 2022 17:11:34 +0300 Subject: [PATCH 2/4] Add: [Actions] Ubuntu Jammy Jellyfish (22.04) build for releases (#9881) --- .github/workflows/release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f3e9829f8a..8221770e15 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -377,6 +377,9 @@ jobs: - container_image: "ubuntu:20.04" bundle_name: "focal" compiler: "g++" + - container_image: "ubuntu:22.04" + bundle_name: "jammy" + compiler: "g++" - container_image: "debian:buster" bundle_name: "buster" compiler: "g++" From 9529703cab79f114ca2bf788a0543d4b3d835f62 Mon Sep 17 00:00:00 2001 From: frosch Date: Thu, 1 Sep 2022 18:13:43 +0200 Subject: [PATCH 3/4] Codechange: When checking industry placement conditions, perform cheap checks first. (#9987) 1. Built-in checks on industry level. 2. Built-in checks on industry tiles. 3. NewGRF-defined checks on industry level. 4. NewGRF-defined checks on industry tiles. --- src/industry_cmd.cpp | 106 +++++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 385a952b60..b81ba18604 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1429,18 +1429,12 @@ bool IsSlopeRefused(Slope current, Slope refused) * Are the tiles of the industry free? * @param tile Position to check. * @param layout Industry tiles table. - * @param layout_index The index of the layout to build/fund * @param type Type of the industry. - * @param initial_random_bits The random bits the industry is going to have after construction. - * @param founder Industry founder - * @param creation_type The circumstances the industry is created under. - * @param[out] custom_shape_check Perform custom check for the site. * @return Failed or succeeded command. */ -static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileLayout &layout, size_t layout_index, int type, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check = nullptr) +static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileLayout &layout, IndustryType type) { - bool refused_slope = false; - bool custom_shape = false; + IndustryBehaviour ind_behav = GetIndustrySpec(type)->behaviour; for (const IndustryTileLayoutTile &it : layout) { IndustryGfx gfx = GetTranslatedIndustryTileID(it.gfx); @@ -1462,20 +1456,9 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil const IndustryTileSpec *its = GetIndustryTileSpec(gfx); - IndustryBehaviour ind_behav = GetIndustrySpec(type)->behaviour; - /* Perform land/water check if not disabled */ if (!HasBit(its->slopes_refused, 5) && ((HasTileWaterClass(cur_tile) && IsTileOnWater(cur_tile)) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE); - if (HasBit(its->callback_mask, CBM_INDT_SHAPE_CHECK)) { - custom_shape = true; - CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, layout_index, initial_random_bits, founder, creation_type); - if (ret.Failed()) return ret; - } else { - Slope tileh = GetTileSlope(cur_tile); - refused_slope |= IsSlopeRefused(tileh, its->slopes_refused); - } - if ((ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) || // Tile must be a house ((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) && IsTileType(cur_tile, MP_HOUSE))) { // Tile is allowed to be a house (and it is a house) if (!IsTileType(cur_tile, MP_HOUSE)) { @@ -1491,12 +1474,50 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil } else { /* Clear the tiles, but do not affect town ratings */ CommandCost ret = Command::Do(DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, cur_tile); - if (ret.Failed()) return ret; } } } + return CommandCost(); +} + +/** + * Check slope requirements for industry tiles. + * @param tile Position to check. + * @param layout Industry tiles table. + * @param layout_index The index of the layout to build/fund + * @param type Type of the industry. + * @param initial_random_bits The random bits the industry is going to have after construction. + * @param founder Industry founder + * @param creation_type The circumstances the industry is created under. + * @param[out] custom_shape_check Perform custom check for the site. + * @return Failed or succeeded command. + */ +static CommandCost CheckIfIndustryTileSlopes(TileIndex tile, const IndustryTileLayout &layout, size_t layout_index, int type, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check = nullptr) +{ + bool refused_slope = false; + bool custom_shape = false; + + for (const IndustryTileLayoutTile &it : layout) { + IndustryGfx gfx = GetTranslatedIndustryTileID(it.gfx); + TileIndex cur_tile = TileAddWrap(tile, it.ti.x, it.ti.y); + assert(IsValidTile(cur_tile)); // checked before in CheckIfIndustryTilesAreFree + + if (gfx != GFX_WATERTILE_SPECIALCHECK) { + const IndustryTileSpec *its = GetIndustryTileSpec(gfx); + + if (HasBit(its->callback_mask, CBM_INDT_SHAPE_CHECK)) { + custom_shape = true; + CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, layout_index, initial_random_bits, founder, creation_type); + if (ret.Failed()) return ret; + } else { + Slope tileh = GetTileSlope(cur_tile); + refused_slope |= IsSlopeRefused(tileh, its->slopes_refused); + } + } + } + if (custom_shape_check != nullptr) *custom_shape_check = custom_shape; /* It is almost impossible to have a fully flat land in TG, so what we @@ -1929,28 +1950,11 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do { assert(layout_index < indspec->layouts.size()); const IndustryTileLayout &layout = indspec->layouts[layout_index]; - bool custom_shape_check = false; *ip = nullptr; - std::vector object_areas(_cleared_object_areas); - CommandCost ret = CheckIfIndustryTilesAreFree(tile, layout, layout_index, type, random_initial_bits, founder, creation_type, &custom_shape_check); - _cleared_object_areas = object_areas; - if (ret.Failed()) return ret; - - if (HasBit(GetIndustrySpec(type)->callback_mask, CBM_IND_LOCATION)) { - ret = CheckIfCallBackAllowsCreation(tile, type, layout_index, random_var8f, random_initial_bits, founder, creation_type); - } else { - ret = _check_new_industry_procs[indspec->check_proc](tile); - } - if (ret.Failed()) return ret; - - if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && - !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, DC_NO_WATER, layout, type)) { - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); - } - - ret = CheckIfFarEnoughFromConflictingIndustry(tile, type); + /* 1. Cheap: Built-in checks on industry level. */ + CommandCost ret = CheckIfFarEnoughFromConflictingIndustry(tile, type); if (ret.Failed()) return ret; Town *t = nullptr; @@ -1961,6 +1965,30 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do ret = CheckIfIndustryIsAllowed(tile, type, t); if (ret.Failed()) return ret; + /* 2. Built-in checks on industry tiles. */ + std::vector object_areas(_cleared_object_areas); + ret = CheckIfIndustryTilesAreFree(tile, layout, type); + _cleared_object_areas = object_areas; + if (ret.Failed()) return ret; + + /* 3. NewGRF-defined checks on industry level. */ + if (HasBit(GetIndustrySpec(type)->callback_mask, CBM_IND_LOCATION)) { + ret = CheckIfCallBackAllowsCreation(tile, type, layout_index, random_var8f, random_initial_bits, founder, creation_type); + } else { + ret = _check_new_industry_procs[indspec->check_proc](tile); + } + if (ret.Failed()) return ret; + + /* 4. Expensive: NewGRF-defined checks on industry tiles. */ + bool custom_shape_check = false; + ret = CheckIfIndustryTileSlopes(tile, layout, layout_index, type, random_initial_bits, founder, creation_type, &custom_shape_check); + if (ret.Failed()) return ret; + + if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && + !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, DC_NO_WATER, layout, type)) { + return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + } + if (!Industry::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_INDUSTRIES); if (flags & DC_EXEC) { From c839950791e3adee28e5e21730b35b100bb95451 Mon Sep 17 00:00:00 2001 From: dP Date: Thu, 1 Sep 2022 19:15:07 +0300 Subject: [PATCH 4/4] Cleanup: Remove duplicate command_type.h include (#9986) --- src/goal_cmd.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/goal_cmd.h b/src/goal_cmd.h index 5be2044e21..e57d9b185c 100644 --- a/src/goal_cmd.h +++ b/src/goal_cmd.h @@ -10,7 +10,6 @@ #ifndef GOAL_CMD_H #define GOAL_CMD_H -#include "command_type.h" #include "command_type.h" #include "goal_type.h"