mirror of https://github.com/OpenTTD/OpenTTD
(svn r22449) [1.1] -Backport from trunk:
- Feature: [NewGRF] Allow to filter by town of the current industry when using industry variable 0x68 [FS#4591] (r22434) - Change: Improve the speed of YAPF by tweaking hash tables size (r22351, r22350, r22348)release/1.1
parent
704a361ada
commit
829a2c201d
|
@ -1074,6 +1074,7 @@
|
|||
<ClInclude Include="..\src\pathfinder\yapf\yapf_node.hpp" />
|
||||
<ClInclude Include="..\src\pathfinder\yapf\yapf_node_rail.hpp" />
|
||||
<ClInclude Include="..\src\pathfinder\yapf\yapf_node_road.hpp" />
|
||||
<ClInclude Include="..\src\pathfinder\yapf\yapf_node_ship.hpp" />
|
||||
<ClCompile Include="..\src\pathfinder\yapf\yapf_rail.cpp" />
|
||||
<ClCompile Include="..\src\pathfinder\yapf\yapf_road.cpp" />
|
||||
<ClCompile Include="..\src\pathfinder\yapf\yapf_ship.cpp" />
|
||||
|
|
|
@ -2442,6 +2442,9 @@
|
|||
<ClInclude Include="..\src\pathfinder\yapf\yapf_node_road.hpp">
|
||||
<Filter>YAPF</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\pathfinder\yapf\yapf_node_ship.hpp">
|
||||
<Filter>YAPF</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\src\pathfinder\yapf\yapf_rail.cpp">
|
||||
<Filter>YAPF</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
@ -3662,6 +3662,10 @@
|
|||
RelativePath=".\..\src\pathfinder\yapf\yapf_node_road.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\pathfinder\yapf\yapf_node_ship.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\pathfinder\yapf\yapf_rail.cpp"
|
||||
>
|
||||
|
|
|
@ -3659,6 +3659,10 @@
|
|||
RelativePath=".\..\src\pathfinder\yapf\yapf_node_road.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\pathfinder\yapf\yapf_node_ship.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\pathfinder\yapf\yapf_rail.cpp"
|
||||
>
|
||||
|
|
|
@ -875,6 +875,7 @@ pathfinder/yapf/yapf_destrail.hpp
|
|||
pathfinder/yapf/yapf_node.hpp
|
||||
pathfinder/yapf/yapf_node_rail.hpp
|
||||
pathfinder/yapf/yapf_node_road.hpp
|
||||
pathfinder/yapf/yapf_node_ship.hpp
|
||||
pathfinder/yapf/yapf_rail.cpp
|
||||
pathfinder/yapf/yapf_road.cpp
|
||||
pathfinder/yapf/yapf_ship.cpp
|
||||
|
|
|
@ -145,20 +145,15 @@ protected:
|
|||
*/
|
||||
typedef CHashTableSlotT<Titem_> Slot;
|
||||
|
||||
Slot *m_slots; // here we store our data (array of blobs)
|
||||
Slot m_slots[Tcapacity]; // here we store our data (array of blobs)
|
||||
int m_num_items; // item counter
|
||||
|
||||
public:
|
||||
/* default constructor */
|
||||
FORCEINLINE CHashTableT()
|
||||
FORCEINLINE CHashTableT() : m_num_items(0)
|
||||
{
|
||||
/* construct all slots */
|
||||
m_slots = new Slot[Tcapacity];
|
||||
m_num_items = 0;
|
||||
}
|
||||
|
||||
~CHashTableT() {delete [] m_slots; m_num_items = 0; m_slots = NULL;}
|
||||
|
||||
protected:
|
||||
/** static helper - return hash for the given key modulo number of slots */
|
||||
FORCEINLINE static int CalcHash(const Tkey& key)
|
||||
|
@ -180,7 +175,7 @@ public:
|
|||
FORCEINLINE int Count() const {return m_num_items;}
|
||||
|
||||
/** simple clear - forget all items - used by CSegmentCostCacheT.Flush() */
|
||||
FORCEINLINE void Clear() const {for (int i = 0; i < Tcapacity; i++) m_slots[i].Clear();}
|
||||
FORCEINLINE void Clear() {for (int i = 0; i < Tcapacity; i++) m_slots[i].Clear();}
|
||||
|
||||
/** const item search */
|
||||
const Titem_ *Find(const Tkey& key) const
|
||||
|
|
|
@ -106,10 +106,11 @@ static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Indust
|
|||
* function.
|
||||
* @param param_setID parameter given to the callback, which is the set id, or the local id, in our terminology
|
||||
* @param layout_filter on what layout do we filter?
|
||||
* @param town_filter Do we filter on the same town as the current industry?
|
||||
* @param current Industry for which the inquiry is made
|
||||
* @return the formatted answer to the callback : rr(reserved) cc(count) dddd(manhattan distance of closest sister)
|
||||
*/
|
||||
static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout_filter, const Industry *current)
|
||||
static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout_filter, bool town_filter, const Industry *current)
|
||||
{
|
||||
uint32 GrfID = GetRegister(0x100); ///< Get the GRFID of the definition to look for in register 100h
|
||||
IndustryType ind_index;
|
||||
|
@ -135,7 +136,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
|
|||
/* If the industry type is invalid, there is none and the closest is far away. */
|
||||
if (ind_index >= NUM_INDUSTRYTYPES) return 0 | 0xFFFF;
|
||||
|
||||
if (layout_filter == 0) {
|
||||
if (layout_filter == 0 && !town_filter) {
|
||||
/* If the filter is 0, it could be because none was specified as well as being really a 0.
|
||||
* In either case, just do the regular var67 */
|
||||
closest_dist = GetClosestIndustry(current->location.tile, ind_index, current);
|
||||
|
@ -145,7 +146,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
|
|||
* Unfortunately, we have to do it manually */
|
||||
const Industry *i;
|
||||
FOR_ALL_INDUSTRIES(i) {
|
||||
if (i->type == ind_index && i != current && i->selected_layout == layout_filter) {
|
||||
if (i->type == ind_index && i != current && (i->selected_layout == layout_filter || layout_filter == 0) && (!town_filter || i->town == current->town)) {
|
||||
closest_dist = min(closest_dist, DistanceManhattan(current->location.tile, i->location.tile));
|
||||
count++;
|
||||
}
|
||||
|
@ -264,7 +265,16 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
|
|||
/* Count of industry, distance of closest instance
|
||||
* 68 is the same as 67, but with a filtering on selected layout */
|
||||
case 0x67:
|
||||
case 0x68: return GetCountAndDistanceOfClosestInstance(parameter, variable == 0x68 ? GB(GetRegister(0x101), 0, 8) : 0, industry);
|
||||
case 0x68: {
|
||||
byte layout_filter = 0;
|
||||
bool town_filter = false;
|
||||
if (variable == 0x68) {
|
||||
uint32 reg = GetRegister(0x101);
|
||||
layout_filter = GB(reg, 0, 8);
|
||||
town_filter = HasBit(reg, 8);
|
||||
}
|
||||
return GetCountAndDistanceOfClosestInstance(parameter, layout_filter, town_filter, industry);
|
||||
}
|
||||
|
||||
/* Get a variable from the persistent storage */
|
||||
case 0x7C: return industry->psa.Get(parameter);
|
||||
|
|
|
@ -81,21 +81,4 @@ struct CYapfNodeT {
|
|||
}
|
||||
};
|
||||
|
||||
/** Yapf Node for ships */
|
||||
template <class Tkey_>
|
||||
struct CYapfShipNodeT
|
||||
: CYapfNodeT<Tkey_, CYapfShipNodeT<Tkey_> >
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
/* now define two major node types (that differ by key type) */
|
||||
typedef CYapfShipNodeT<CYapfNodeKeyExitDir> CYapfShipNodeExitDir;
|
||||
typedef CYapfShipNodeT<CYapfNodeKeyTrackDir> CYapfShipNodeTrackDir;
|
||||
|
||||
/* Default NodeList types */
|
||||
typedef CNodeList_HashTableT<CYapfShipNodeExitDir , 14, 16> CShipNodeListExitDir;
|
||||
typedef CNodeList_HashTableT<CYapfShipNodeTrackDir, 16, 20> CShipNodeListTrackDir;
|
||||
|
||||
|
||||
#endif /* YAPF_NODE_HPP */
|
||||
|
|
|
@ -291,7 +291,7 @@ typedef CYapfRailNodeT<CYapfNodeKeyExitDir> CYapfRailNodeExitDir;
|
|||
typedef CYapfRailNodeT<CYapfNodeKeyTrackDir> CYapfRailNodeTrackDir;
|
||||
|
||||
/* Default NodeList types */
|
||||
typedef CNodeList_HashTableT<CYapfRailNodeExitDir , 10, 12> CRailNodeListExitDir;
|
||||
typedef CNodeList_HashTableT<CYapfRailNodeTrackDir, 12, 16> CRailNodeListTrackDir;
|
||||
typedef CNodeList_HashTableT<CYapfRailNodeExitDir , 8, 10> CRailNodeListExitDir;
|
||||
typedef CNodeList_HashTableT<CYapfRailNodeTrackDir, 8, 10> CRailNodeListTrackDir;
|
||||
|
||||
#endif /* YAPF_NODE_RAIL_HPP */
|
||||
|
|
|
@ -35,7 +35,7 @@ typedef CYapfRoadNodeT<CYapfNodeKeyExitDir> CYapfRoadNodeExitDir;
|
|||
typedef CYapfRoadNodeT<CYapfNodeKeyTrackDir> CYapfRoadNodeTrackDir;
|
||||
|
||||
/* Default NodeList types */
|
||||
typedef CNodeList_HashTableT<CYapfRoadNodeExitDir , 8, 12> CRoadNodeListExitDir;
|
||||
typedef CNodeList_HashTableT<CYapfRoadNodeTrackDir, 10, 14> CRoadNodeListTrackDir;
|
||||
typedef CNodeList_HashTableT<CYapfRoadNodeExitDir , 8, 10> CRoadNodeListExitDir;
|
||||
typedef CNodeList_HashTableT<CYapfRoadNodeTrackDir, 8, 10> CRoadNodeListTrackDir;
|
||||
|
||||
#endif /* YAPF_NODE_ROAD_HPP */
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* 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 yapf_node_ship.hpp Node tailored for ship pathfinding. */
|
||||
|
||||
#ifndef YAPF_NODE_SHIP_HPP
|
||||
#define YAPF_NODE_SHIP_HPP
|
||||
|
||||
/** Yapf Node for ships */
|
||||
template <class Tkey_>
|
||||
struct CYapfShipNodeT
|
||||
: CYapfNodeT<Tkey_, CYapfShipNodeT<Tkey_> >
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
/* now define two major node types (that differ by key type) */
|
||||
typedef CYapfShipNodeT<CYapfNodeKeyExitDir> CYapfShipNodeExitDir;
|
||||
typedef CYapfShipNodeT<CYapfNodeKeyTrackDir> CYapfShipNodeTrackDir;
|
||||
|
||||
/* Default NodeList types */
|
||||
typedef CNodeList_HashTableT<CYapfShipNodeExitDir , 10, 12> CShipNodeListExitDir;
|
||||
typedef CNodeList_HashTableT<CYapfShipNodeTrackDir, 10, 12> CShipNodeListTrackDir;
|
||||
|
||||
|
||||
#endif /* YAPF_NODE_SHIP_HPP */
|
|
@ -13,6 +13,7 @@
|
|||
#include "../../ship.h"
|
||||
|
||||
#include "yapf.hpp"
|
||||
#include "yapf_node_ship.hpp"
|
||||
|
||||
/** Node Follower module of YAPF for ships */
|
||||
template <class Types>
|
||||
|
|
Loading…
Reference in New Issue