ScummVM API documentation
path.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  *
21  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, MojoTouch has
23  * exclusively licensed this code on March 23th, 2024, to be used in
24  * closed-source products.
25  * Therefore, any contributions (commits) to it will also be dual-licensed.
26  *
27  */
28 
29 #ifndef TOON_PATH_H
30 #define TOON_PATH_H
31 
32 #include "common/array.h"
33 #include "common/rect.h"
34 
35 #include "toon/toon.h"
36 
37 namespace Toon {
38 
39 // binary heap system for fast A*
41 public:
43  ~PathFindingHeap();
44 
45  void push(int16 x, int16 y, uint16 weight);
46  void pop(int16 *x, int16 *y, uint16 *weight);
47  void init(int32 size);
48  void clear();
49  void unload();
50  uint32 getCount() { return _count; }
51 
52 private:
53  struct HeapDataGrid {
54  int16 _x, _y;
55  uint16 _weight;
56  };
57 
58  HeapDataGrid *_data;
59 
60  uint32 _size;
61  uint32 _count;
62 };
63 
64 class PathFinding {
65 public:
66  PathFinding();
67  ~PathFinding();
68 
69  void init(Picture *mask);
70 
71  bool findPath(int16 x, int16 y, int16 destX, int16 destY);
72  bool findClosestWalkingPoint(int16 xx, int16 yy, int16 *fxx, int16 *fyy, int16 origX = -1, int16 origY = -1);
73  bool isWalkable(int16 x, int16 y);
74  bool isLikelyWalkable(int16 x, int16 y);
75  bool lineIsWalkable(int16 x, int16 y, int16 x2, int16 y2);
76  void walkLine(int16 x, int16 y, int16 x2, int16 y2);
77 
78  void resetBlockingRects() { _numBlockingRects = 0; }
79  void addBlockingRect(int16 x1, int16 y1, int16 x2, int16 y2);
80  void addBlockingEllipse(int16 x1, int16 y1, int16 w, int16 h);
81 
82  uint32 getPathNodeCount() const { return _tempPath.size(); }
83  int16 getPathNodeX(uint32 nodeId) const { return _tempPath[(_tempPath.size() - 1) - nodeId].x; }
84  int16 getPathNodeY(uint32 nodeId) const { return _tempPath[(_tempPath.size() - 1) - nodeId].y; }
85 
86 private:
87  static const uint8 kMaxBlockingRects = 16;
88 
89  Picture *_currentMask;
90 
91  PathFindingHeap *_heap;
92 
93  uint16 *_sq;
94  int16 _width;
95  int16 _height;
96 
98 
99  int16 _blockingRects[kMaxBlockingRects][5];
100  uint8 _numBlockingRects;
101 };
102 
103 } // End of namespace Toon
104 
105 #endif
Definition: anim.h:39
Definition: path.h:40
Definition: path.h:64
Definition: picture.h:43