summaryrefslogtreecommitdiffstats
path: root/Room.h
diff options
context:
space:
mode:
Diffstat (limited to 'Room.h')
-rw-r--r--Room.h47
1 files changed, 46 insertions, 1 deletions
diff --git a/Room.h b/Room.h
index fb67ac5..e7e7ffb 100644
--- a/Room.h
+++ b/Room.h
@@ -39,6 +39,7 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
vertex += v;
return vertex;
}
+
virtual const Vertex& operator-=(const Vertex &v) {
vertex -= v;
return vertex;
@@ -68,6 +69,18 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
std::vector<SharedPtr<RoomVertex> > vertices;
std::vector<Edge> edges;
+ void addEdge() {
+ if(vertices.size() < 2)
+ return;
+
+ if(vertices.size() == 2) {
+ edges.push_back(Edge(LevelVertex(this, 0, this), LevelVertex(this, 1, this)));
+ return;
+ }
+
+ edges.push_back(Edge(LevelVertex(this, vertices.size()-2, this), LevelVertex(this, vertices.size()-1, this)));
+ }
+
public:
Room() {height = 10;}
Room(std::string name) {this->name = name; height = 10;}
@@ -89,7 +102,39 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
float getHeight() const {return height;}
void setHeight(float height) {this->height = height;}
- void addVertex(Vertex v);
+ void addVertex(Vertex v) {
+ vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexDirect(v)));
+ addEdge();
+ }
+
+ void addVertex(LevelVertex &v) {
+ size_t s = v.connect();
+
+ if(s == v.getId()) {
+ vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexIndirect(v)));
+ addEdge();
+ }
+ else {
+ if(vertices.empty()) {
+ LevelVertex v2(v.getProvider(), s, v.getParent());
+
+ vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexIndirect(v2)));
+ vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexIndirect(v)));
+ }
+ else {
+ LevelVertex v2(v.getProvider(), s, v.getParent());
+
+ vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexIndirect(v)));
+ addEdge();
+ vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexIndirect(v2)));
+ }
+ }
+ }
+
+ void close() {
+ if(!edges.empty())
+ edges.push_back(Edge(edges.back().getVertex2(), edges.front().getVertex1()));
+ }
Polygon getPolygon() const {
Polygon polygon;