ScummVM API documentation
region.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/*
23 * This code is based on Broken Sword 2.5 engine
24 *
25 * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
26 *
27 * Licensed under GNU GPL v2
28 *
29 */
30
31#ifndef SWORD25_REGION_H
32#define SWORD25_REGION_H
33
34#include "sword25/kernel/common.h"
35#include "sword25/kernel/persistable.h"
36#include "sword25/math/vertex.h"
37#include "sword25/math/polygon.h"
38#include "common/rect.h"
39
40namespace Sword25 {
41
51class Region : public Persistable {
52protected:
60
61 Region(InputPersistenceBlock &reader, uint handle);
62
63public:
64 enum REGION_TYPE {
65 RT_REGION,
66 RT_WALKREGION
67 };
68
69 static uint create(REGION_TYPE type);
70 static uint create(InputPersistenceBlock &reader, uint handle = 0);
71
72 ~Region() override;
73
82 virtual bool init(const Polygon &contour, const Common::Array<Polygon> *pHoles = NULL);
83
84 //
85 // Exploratory Methods
86 //
87
93 bool isValid() const {
94 return _valid;
95 }
96
100 const Vertex &getPosition() const {
101 return _position;
102 }
103
107 int getPosX() const {
108 return _position.x;
109 }
110
114 int getPosY() const {
115 return _position.y;
116 }
117
123 bool isPointInRegion(const Vertex &vertex) const;
124
131 bool isPointInRegion(int x, int y) const;
132
136 const Polygon &getContour() const {
137 return _polygons[0];
138 }
139
143 int getHoleCount() const {
144 return static_cast<int>(_polygons.size() - 1);
145 }
146
153 inline const Polygon &getHole(uint i) const;
154
164
169
170 bool isLineOfSight(const Vertex &a, const Vertex &b) const;
171
172 //
173 // Manipulation Methods
174 //
175
181 virtual void setPos(int x, int y);
182
187 void setPosX(int x);
188
193 void setPosY(int y);
194
195 //
196 // Manipulation Methods
197 //
198
199 bool persist(OutputPersistenceBlock &writer) override;
200 bool unpersist(InputPersistenceBlock &reader) override;
201
202protected:
204 REGION_TYPE _type;
206 bool _valid;
210 // the array is the contour, all others are the holes
214
219
227 Vertex findClosestPointOnLine(const Vertex &lineStart, const Vertex &lineEnd, const Vertex point) const;
228};
229
230inline const Polygon &Region::getHole(uint i) const {
231 assert(i < _polygons.size() - 1);
232 return _polygons[i + 1];
233}
234
235} // End of namespace Sword25
236
237#endif
Definition: array.h:52
Definition: inputpersistenceblock.h:40
Definition: outputpersistenceblock.h:39
Definition: persistable.h:39
Eine Polygonklasse.
Definition: polygon.h:46
Definition: region.h:51
const Polygon & getContour() const
Definition: region.h:136
bool isPointInRegion(int x, int y) const
void updateBoundingBox()
virtual void setPos(int x, int y)
void setPosY(int y)
bool isPointInRegion(const Vertex &vertex) const
int getPosX() const
Definition: region.h:107
Vertex _position
This vertex is the position of the region.
Definition: region.h:208
Common::Array< Polygon > _polygons
This array contains all the polygons that define the region. The first element of.
Definition: region.h:211
int getPosY() const
Definition: region.h:114
virtual bool init(const Polygon &contour, const Common::Array< Polygon > *pHoles=NULL)
Vertex findClosestRegionPoint(const Vertex &point) const
bool _valid
This variable indicates whether the current object state is valid.
Definition: region.h:206
bool isValid() const
Definition: region.h:93
Common::Rect _boundingBox
The bounding box for the region.
Definition: region.h:213
const Vertex & getPosition() const
Definition: region.h:100
Vertex findClosestPointOnLine(const Vertex &lineStart, const Vertex &lineEnd, const Vertex point) const
REGION_TYPE _type
This specifies the type of object.
Definition: region.h:204
const Polygon & getHole(uint i) const
Definition: region.h:230
Vertex getCentroid() const
void setPosX(int x)
int getHoleCount() const
Definition: region.h:143
Definition: vertex.h:52
Definition: console.h:27
T y
Definition: rect.h:49
T x
Definition: rect.h:48
Definition: rect.h:536