ScummVM API documentation
obstacles.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 
22 #ifndef BLADERUNNER_OBSTACLES_H
23 #define BLADERUNNER_OBSTACLES_H
24 
25 #include "bladerunner/rect_float.h"
26 #include "bladerunner/vector.h"
27 
28 namespace BladeRunner {
29 
30 class BladeRunnerEngine;
31 class SaveFileReadStream;
32 class SaveFileWriteStream;
33 
34 class Obstacles {
35  static const int kVertexCount = 150;
36  static const int kPolygonCount = 50;
37  static const int kPolygonVertexCount = 160;
38  static const int kMaxPathSize = 500;
39 
40  enum VertexType {
41  BOTTOM_LEFT,
42  TOP_LEFT,
43  TOP_RIGHT,
44  BOTTOM_RIGHT
45  };
46 
47  struct LineSegment {
48  Vector2 start;
49  Vector2 end;
50  };
51 
52  struct Polygon {
53  bool isPresent;
54  int verticeCount;
55  RectFloat rect;
56  Vector2 vertices[kPolygonVertexCount];
57  VertexType vertexType[kPolygonVertexCount];
58 
59  Polygon() : isPresent(false), verticeCount(0), vertexType()
60  {}
61  };
62 
63  BladeRunnerEngine *_vm;
64 
65  Polygon *_polygons;
66  Polygon *_polygonsBackup;
67  Vector2 *_path;
68  int _pathSize;
69  int _count;
70  bool _backup;
71 
72  static bool lineLineIntersection(LineSegment a, LineSegment b, Vector2 *intersectionPoint);
73  static bool linePolygonIntersection(LineSegment lineA, VertexType lineAType, Polygon *polyB, Vector2 *intersectionPoint, int *intersectionIndex, int pathLengthSinceLastIntersection);
74 
75  bool mergePolygons(Polygon &polyA, Polygon &PolyB);
76 
77 public:
79  ~Obstacles();
80 
81  void clear();
82  void add(RectFloat rect);
83  void add(float x0, float z0, float x1, float z1) { add(RectFloat(x0, z0, x1, z1)); }
84  int findEmptyPolygon() const;
85  static float getLength(float x0, float z0, float x1, float z1);
86  bool findNextWaypoint(const Vector3 &from, const Vector3 &to, Vector3 *next);
87 
88  bool findIntersectionNearest(int polygonIndex, Vector2 from, Vector2 to,
89  int *outVertexIndex, float *outDistance, Vector2 *out) const;
90  bool findIntersectionFarthest(int polygonIndex, Vector2 from, Vector2 to,
91  int *outVertexIndex, float *outDistance, Vector2 *out) const;
92 
93  float pathTotalDistance(const Vector2 *path, int pathSize, Vector2 from, Vector2 to) const;
94  bool findPolygonVerticeByXZ(int *polygonIndex, int *verticeIndex, int *verticeCount, float x, float z) const;
95  bool findPolygonVerticeByXZWithinTolerance(float x, float z, int *polygonIndex, int *verticeIndex, int startSearchFromPolygonIdx) const;
96 
97  void clearPath();
98  int buildNegativePath(int polyIndex, int vertStartIndex, Vector2 startPos, int vertEndIndex, Vector2 endPos, Vector2 *path, int pathCapacity, bool *pathBlocked);
99  int buildPositivePath(int polyIndex, int vertStartIndex, Vector2 startPos, int vertEndIndex, Vector2 endPos, Vector2 *path, int pathCapacity, bool *pathBlocked);
100 
101  bool verticesCanIntersect(int lineType0, int lineType1, float x0, float y0, float x1, float y1) const;
102  bool findFarthestAvailablePathVertex(Vector2 *path, int pathSize, Vector3 start, Vector3 *next) const;
103 
104  void backup();
105  void restore();
106  void reset();
107 
108  void draw();
109  void save(SaveFileWriteStream &f);
110  void load(SaveFileReadStream &f);
111 };
112 
113 } // End of namespace BladeRunner
114 
115 #endif
Definition: savefile.h:88
Definition: obstacles.h:34
Definition: actor.h:31
Definition: savefile.h:113
Definition: vector.h:29
Definition: vector.h:47
Definition: rect_float.h:32
Definition: bladerunner.h:113