diff options
author | neoraider <devnull@localhost> | 2008-02-19 23:19:02 +0100 |
---|---|---|
committer | neoraider <devnull@localhost> | 2008-02-19 23:19:02 +0100 |
commit | f457ec5027eec37d3734190601399da0af68d12e (patch) | |
tree | b8ee2c2d39fea69b05c6e4824dbd8fab2d87f6b9 /Room.h | |
parent | 2687501f215ec7ffd939801f171d25ea30b02c55 (diff) | |
download | zoomedit-f457ec5027eec37d3734190601399da0af68d12e.tar zoomedit-f457ec5027eec37d3734190601399da0af68d12e.zip |
zoomedit: Rooms can now be connected to portals.
Diffstat (limited to 'Room.h')
-rw-r--r-- | Room.h | 47 |
1 files changed, 46 insertions, 1 deletions
@@ -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; |