From f457ec5027eec37d3734190601399da0af68d12e Mon Sep 17 00:00:00 2001 From: neoraider Date: Tue, 19 Feb 2008 22:19:02 +0000 Subject: zoomedit: Rooms can now be connected to portals. --- Room.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'Room.h') 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 > vertices; std::vector 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(new RoomVertexDirect(v))); + addEdge(); + } + + void addVertex(LevelVertex &v) { + size_t s = v.connect(); + + if(s == v.getId()) { + vertices.push_back(SharedPtr(new RoomVertexIndirect(v))); + addEdge(); + } + else { + if(vertices.empty()) { + LevelVertex v2(v.getProvider(), s, v.getParent()); + + vertices.push_back(SharedPtr(new RoomVertexIndirect(v2))); + vertices.push_back(SharedPtr(new RoomVertexIndirect(v))); + } + else { + LevelVertex v2(v.getProvider(), s, v.getParent()); + + vertices.push_back(SharedPtr(new RoomVertexIndirect(v))); + addEdge(); + vertices.push_back(SharedPtr(new RoomVertexIndirect(v2))); + } + } + } + + void close() { + if(!edges.empty()) + edges.push_back(Edge(edges.back().getVertex2(), edges.front().getVertex1())); + } Polygon getPolygon() const { Polygon polygon; -- cgit v1.2.3