summaryrefslogtreecommitdiffstats
path: root/Room.h
diff options
context:
space:
mode:
Diffstat (limited to 'Room.h')
-rw-r--r--Room.h85
1 files changed, 73 insertions, 12 deletions
diff --git a/Room.h b/Room.h
index 6a5f15d..fb67ac5 100644
--- a/Room.h
+++ b/Room.h
@@ -11,19 +11,73 @@
class Room : public LevelObject, private VertexProvider, private EdgeProvider {
private:
- Polygon polygon;
+ class RoomVertex {
+ public:
+ virtual const Vertex& operator*() const = 0;
+ const Vertex* operator->() {return &**this;}
+
+ virtual ~RoomVertex() {}
+
+ virtual const Vertex& operator+=(const Vertex &v) {return **this;}
+ virtual const Vertex& operator-=(const Vertex &v) {return **this;}
+
+ virtual void setLocation(float x, float y) {}
+ };
+
+ class RoomVertexDirect : public RoomVertex {
+ private:
+ Vertex vertex;
+
+ public:
+ RoomVertexDirect(const Vertex &v) : vertex(v) {}
+
+ virtual const Vertex& operator*() const {
+ return vertex;
+ }
+
+ virtual const Vertex& operator+=(const Vertex &v) {
+ vertex += v;
+ return vertex;
+ }
+ virtual const Vertex& operator-=(const Vertex &v) {
+ vertex -= v;
+ return vertex;
+ }
+
+ virtual void setLocation(float x, float y) {
+ vertex.setLocation(x, y);
+ }
+ };
+
+ class RoomVertexIndirect : public RoomVertex {
+ private:
+ LevelVertex vertex;
+
+ public:
+ RoomVertexIndirect(const LevelVertex &v) : vertex(v) {}
+
+ virtual const Vertex& operator*() const {
+ return *vertex;
+ }
+ };
+
+
std::string name;
float height;
+ std::vector<SharedPtr<RoomVertex> > vertices;
std::vector<Edge> edges;
public:
Room() {height = 10;}
Room(std::string name) {this->name = name; height = 10;}
- Room(const Room &room) : name(room.name), height(room.height) {
- for(Polygon::const_iterator v = room.polygon.begin(); v != room.polygon.end(); v++)
- addVertex(*v);
+ Room(const Room &room) : name(room.name), height(room.height), vertices(room.vertices) {
+ for(std::vector<Edge>::const_iterator edge = room.edges.begin(); edge != room.edges.end(); edge++) {
+ LevelVertex v1(this, edge->getVertex1().getId(), this);
+ LevelVertex v2(this, edge->getVertex2().getId(), this);
+ edges.push_back(Edge(v1, v2));
+ }
}
const Room& operator=(const Room &room);
@@ -37,9 +91,16 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
void addVertex(Vertex v);
- const Polygon& getPolygon() const {return polygon;}
+ Polygon getPolygon() const {
+ Polygon polygon;
+
+ for(std::vector<SharedPtr<RoomVertex> >::const_iterator v = vertices.begin(); v != vertices.end(); v++)
+ polygon.push_back(***v);
+
+ return polygon;
+ }
- virtual bool hit(const Vertex &v) const {return polygon.contains(v);}
+ virtual bool hit(const Vertex &v) const {return getPolygon().contains(v);}
virtual int getPriority() const {return 0;}
virtual std::vector<SharedPtr<LevelObject> > getChildren();
@@ -53,8 +114,8 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
virtual void move(float x, float y) {
Vertex m(x, y);
- for(Polygon::iterator v = polygon.begin(); v != polygon.end(); v++)
- *v += m;
+ for(std::vector<SharedPtr<RoomVertex> >::iterator v = vertices.begin(); v != vertices.end(); v++)
+ **v += m;
}
virtual bool canRotate() const {return true;}
@@ -62,15 +123,15 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
virtual void rotate(Vertex m, float a);
virtual const Vertex* getVertex(size_t id) const {
- return &polygon[id];
+ return &**vertices[id];
}
virtual size_t getVertexCount() const {
- return polygon.size();
+ return vertices.size();
}
virtual void moveVertex(size_t id, float x, float y) {
- polygon[id] += Vertex(x, y);
+ *vertices[id] += Vertex(x, y);
}
virtual void rotateVertex(size_t id, Vertex m, float a) {
@@ -87,7 +148,7 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
virtual void moveEdge(size_t id, float x, float y) {
moveVertex(id, x, y);
- moveVertex((id+1)%polygon.size(), x, y);
+ moveVertex((id+1)%vertices.size(), x, y);
}
virtual void rotateEdge(size_t id, Vertex m, float a) {