diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/polygon.cpp | 6 | ||||
-rw-r--r-- | common/polygon.h | 28 | ||||
-rw-r--r-- | common/shape.h | 2 | ||||
-rw-r--r-- | common/xmlparser.cpp | 2 | ||||
-rw-r--r-- | common/xmlparser.h | 9 |
5 files changed, 30 insertions, 17 deletions
diff --git a/common/polygon.cpp b/common/polygon.cpp index 4a41d127d5..c1332b0bc4 100644 --- a/common/polygon.cpp +++ b/common/polygon.cpp @@ -33,11 +33,11 @@ bool Polygon::contains(int16 x, int16 y) const { bool inside_flag = false; unsigned int pt; - const Point *vtx0 = &points[points.size() - 1]; - const Point *vtx1 = &points[0]; + const Point *vtx0 = &_points[_points.size() - 1]; + const Point *vtx1 = &_points[0]; yflag0 = (vtx0->y >= y); - for (pt = 0; pt < points.size(); pt++, vtx1++) { + for (pt = 0; pt < _points.size(); pt++, vtx1++) { yflag1 = (vtx1->y >= y); if (yflag0 != yflag1) { if (((vtx1->y - y) * (vtx0->x - vtx1->x) >= diff --git a/common/polygon.h b/common/polygon.h index af3e2fb900..e4a518193e 100644 --- a/common/polygon.h +++ b/common/polygon.h @@ -34,15 +34,14 @@ namespace Common { struct Polygon : public Shape { - Array<Point> points; Polygon() {} - Polygon(const Polygon& p) : Shape(), points(p.points), bound(p.bound) {} - Polygon(Array<Point> p) : points(p) { + Polygon(const Polygon& p) : Shape(), _points(p._points), _bound(p._bound) {} + Polygon(Array<Point> p) : _points(p) { if (p.empty()) return; - bound = Rect(p[0].x, p[0].y, p[0].x, p[0].y); + _bound = Rect(p[0].x, p[0].y, p[0].x, p[0].y); for (uint i = 1; i < p.size(); i++) { - bound.extend(Rect(p[i].x, p[i].y, p[i].x, p[i].y)); + _bound.extend(Rect(p[i].x, p[i].y, p[i].x, p[i].y)); } } Polygon(Point *p, int n) { @@ -53,14 +52,18 @@ struct Polygon : public Shape { virtual ~Polygon() {} void addPoint(const Point& p) { - points.push_back(p); - bound.extend(Rect(p.x, p.y, p.x, p.y)); + _points.push_back(p); + _bound.extend(Rect(p.x, p.y, p.x, p.y)); } void addPoint(int16 x, int16 y) { addPoint(Point(x,y)); } + uint getPointCount() { + return _points.size(); + } + /*! @brief check if given position is inside this polygon @param x the horizontal position to check @@ -81,8 +84,8 @@ struct Polygon : public Shape { } virtual void moveTo(int16 x, int16 y) { - int16 dx = x - ((bound.right + bound.left) / 2); - int16 dy = y - ((bound.bottom + bound.top) / 2); + int16 dx = x - ((_bound.right + _bound.left) / 2); + int16 dy = y - ((_bound.bottom + _bound.top) / 2); translate(dx, dy); } @@ -92,18 +95,19 @@ struct Polygon : public Shape { virtual void translate(int16 dx, int16 dy) { Array<Point>::iterator it; - for (it = points.begin(); it != points.end(); it++) { + for (it = _points.begin(); it != _points.end(); it++) { it->x += dx; it->y += dy; } } virtual Rect getBoundingRect() const { - return bound; + return _bound; } private: - Rect bound; + Array<Point> _points; + Rect _bound; }; } // end of namespace Common diff --git a/common/shape.h b/common/shape.h index 34df476718..981241eee5 100644 --- a/common/shape.h +++ b/common/shape.h @@ -31,7 +31,7 @@ namespace Common { -class Rect; +struct Rect; /*! @brief simple class for handling both 2D position and size diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 8ff93a4c59..3452db9e00 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -134,6 +134,8 @@ bool XMLParser::parse() { if (_text.ready() == false) return parserError("XML stream not ready for reading."); + cleanup(); + bool activeClosure = false; bool selfClosure = false; diff --git a/common/xmlparser.h b/common/xmlparser.h index fa1f10061a..167d04249c 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -63,7 +63,7 @@ public: _pos = idx; - return _stream->readSByte(); + return _stream->readByte(); } void loadStream(SeekableReadStream *s) { @@ -331,6 +331,13 @@ protected: return (*key == 0); } + /** + * Overload if your parser needs to support parsing the same file + * several times, so you can clean up the internal state of the + * parser before each parse. + */ + virtual void cleanup() {} + int _pos; /** Current position on the XML buffer. */ XMLStream _text; /** Buffer with the text being parsed */ Common::String _fileName; |