OpenTTD Source 20250312-master-gcdcc6b491d
viewport_kdtree.h
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10#ifndef VIEWPORT_KDTREE_H
11#define VIEWPORT_KDTREE_H
12
13#include "core/kdtree.hpp"
14#include "viewport_type.h"
15#include "station_base.h"
16#include "town_type.h"
17#include "signs_base.h"
18
20 enum ItemType : uint16_t {
21 VKI_STATION,
22 VKI_WAYPOINT,
23 VKI_TOWN,
24 VKI_SIGN,
25 };
26 ItemType type;
27 std::variant<StationID, TownID, SignID> id;
28 int32_t center;
29 int32_t top;
30
31 bool operator== (const ViewportSignKdtreeItem &other) const
32 {
33 if (this->type != other.type) return false;
34 return this->id == other.id;
35 }
36
37 bool operator< (const ViewportSignKdtreeItem &other) const
38 {
39 if (this->type != other.type) return this->type < other.type;
40 return this->id < other.id;
41 }
42
43 static ViewportSignKdtreeItem MakeStation(StationID id);
44 static ViewportSignKdtreeItem MakeWaypoint(StationID id);
45 static ViewportSignKdtreeItem MakeTown(TownID id);
46 static ViewportSignKdtreeItem MakeSign(SignID id);
47};
48
50 inline int32_t operator()(const ViewportSignKdtreeItem &item, int dim)
51 {
52 return (dim == 0) ? item.center : item.top;
53 }
54};
55
57extern ViewportSignKdtree _viewport_sign_kdtree;
58
59void RebuildViewportKdtree();
60
61#endif
K-dimensional tree, specialised for 2-dimensional space.
Definition kdtree.hpp:35
K-d tree template specialised for 2-dimensional Manhattan geometry.
Base class for signs.
Base classes/functions for stations.
Types related to towns.
Types related to viewports.