Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Region-based pathfinder for ships (#10543)
- Loading branch information
Showing
18 changed files
with
1,073 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ add_files( | |
follow_track.hpp | ||
pathfinder_func.h | ||
pathfinder_type.h | ||
water_regions.h | ||
water_regions.cpp | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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 water_regions.h Handles dividing the water in the map into regions to assist pathfinding. */ | ||
|
||
#ifndef WATER_REGIONS_H | ||
#define WATER_REGIONS_H | ||
|
||
#include "tile_type.h" | ||
#include "map_func.h" | ||
|
||
using TWaterRegionPatchLabel = uint8_t; | ||
using TWaterRegionIndex = uint; | ||
|
||
constexpr int WATER_REGION_EDGE_LENGTH = 16; | ||
constexpr int WATER_REGION_NUMBER_OF_TILES = WATER_REGION_EDGE_LENGTH * WATER_REGION_EDGE_LENGTH; | ||
|
||
/** | ||
* Describes a single interconnected patch of water within a particular water region. | ||
*/ | ||
struct WaterRegionPatchDesc | ||
{ | ||
int x; ///< The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis | ||
int y; ///< The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis | ||
TWaterRegionPatchLabel label; ///< Unique label identifying the patch within the region | ||
|
||
bool operator==(const WaterRegionPatchDesc &other) const { return x == other.x && y == other.y && label == other.label; } | ||
bool operator!=(const WaterRegionPatchDesc &other) const { return !(*this == other); } | ||
}; | ||
|
||
|
||
/** | ||
* Describes a single square water region. | ||
*/ | ||
struct WaterRegionDesc | ||
{ | ||
int x; ///< The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis | ||
int y; ///< The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis | ||
|
||
WaterRegionDesc(const int x, const int y) : x(x), y(y) {} | ||
WaterRegionDesc(const WaterRegionPatchDesc &water_region_patch) : x(water_region_patch.x), y(water_region_patch.y) {} | ||
|
||
bool operator==(const WaterRegionDesc &other) const { return x == other.x && y == other.y; } | ||
bool operator!=(const WaterRegionDesc &other) const { return !(*this == other); } | ||
}; | ||
|
||
TWaterRegionIndex GetWaterRegionIndex(const WaterRegionDesc &water_region); | ||
|
||
TileIndex GetWaterRegionCenterTile(const WaterRegionDesc &water_region); | ||
|
||
WaterRegionDesc GetWaterRegionInfo(TileIndex tile); | ||
WaterRegionPatchDesc GetWaterRegionPatchInfo(TileIndex tile); | ||
|
||
void InvalidateWaterRegion(TileIndex tile); | ||
|
||
using TVisitWaterRegionPatchCallBack = std::function<void(const WaterRegionPatchDesc &)>; | ||
void VisitWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, TVisitWaterRegionPatchCallBack &callback); | ||
|
||
void InitializeWaterRegions(); | ||
|
||
struct WaterRegionSaveLoadInfo | ||
{ | ||
bool initialized; | ||
}; | ||
|
||
std::vector<WaterRegionSaveLoadInfo> GetWaterRegionSaveLoadInfo(); | ||
void LoadWaterRegions(const std::vector<WaterRegionSaveLoadInfo> &save_load_info); | ||
|
||
#endif /* WATER_REGIONS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,7 @@ add_files( | |
yapf_rail.cpp | ||
yapf_road.cpp | ||
yapf_ship.cpp | ||
yapf_ship_regions.h | ||
yapf_ship_regions.cpp | ||
yapf_type.hpp | ||
) |
Oops, something went wrong.