summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2008-02-19 23:19:02 +0100
committerneoraider <devnull@localhost>2008-02-19 23:19:02 +0100
commitf457ec5027eec37d3734190601399da0af68d12e (patch)
treeb8ee2c2d39fea69b05c6e4824dbd8fab2d87f6b9
parent2687501f215ec7ffd939801f171d25ea30b02c55 (diff)
downloadzoomedit-f457ec5027eec37d3734190601399da0af68d12e.tar
zoomedit-f457ec5027eec37d3734190601399da0af68d12e.zip
zoomedit: Rooms can now be connected to portals.
-rw-r--r--LevelVertex.h4
-rw-r--r--Portal.h5
-rw-r--r--Room.cpp24
-rw-r--r--Room.h47
-rw-r--r--ToolAddPolygon.cpp28
-rw-r--r--ToolAddRect.cpp1
-rw-r--r--VertexProvider.h4
7 files changed, 77 insertions, 36 deletions
diff --git a/LevelVertex.h b/LevelVertex.h
index b409ecf..066aaec 100644
--- a/LevelVertex.h
+++ b/LevelVertex.h
@@ -39,9 +39,9 @@ class LevelVertex : public LevelObject {
}
virtual bool canConnect() const {return provider->canConnectVertex(id);}
- virtual void connect() {provider->connectVertex(id);}
+ virtual size_t connect() {return provider->connectVertex(id);}
- const VertexProvider* getProvider() const {
+ VertexProvider* getProvider() const {
return provider;
}
diff --git a/Portal.h b/Portal.h
index 3596bc2..2208946 100644
--- a/Portal.h
+++ b/Portal.h
@@ -130,8 +130,11 @@ class Portal : public LevelObject, public VertexProvider {
return !connected[id];
}
- virtual void connectVertex(size_t id) {
+ virtual size_t connectVertex(size_t id) {
connected[id] = true;
+ connected[(7-id)%4] = true;
+
+ return (7-id)%4;
}
};
diff --git a/Room.cpp b/Room.cpp
index 72a9d22..e364293 100644
--- a/Room.cpp
+++ b/Room.cpp
@@ -20,30 +20,6 @@ const Room& Room::operator=(const Room &room) {
return room;
}
-void Room::addVertex(Vertex v) {
- vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexDirect(v)));
-
- if(vertices.size() < 2)
- return;
-
- if(vertices.size() == 2) {
- LevelVertex v1(this, 0, this), v2(this, 1, this);
-
- edges.push_back(Edge(v1, v2));
- edges.push_back(Edge(v2, v1));
-
- return;
- }
-
- edges.pop_back();
- LevelVertex v1(edges.back().getVertex2());
- LevelVertex v2(this, vertices.size()-1, this);
- LevelVertex v3(edges.front().getVertex1());
-
- edges.push_back(Edge(v1, v2));
- edges.push_back(Edge(v2, v3));
-}
-
std::vector<SharedPtr<LevelObject> > Room::getChildren() {
std::vector<SharedPtr<LevelObject> > children;
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;
diff --git a/ToolAddPolygon.cpp b/ToolAddPolygon.cpp
index 3c63fb7..8e68939 100644
--- a/ToolAddPolygon.cpp
+++ b/ToolAddPolygon.cpp
@@ -20,6 +20,7 @@ void ToolAddPolygon::activate() {
}
void ToolAddPolygon::deactivate() {
+ newRoom.close();
editManager->addRoom(newRoom);
}
@@ -52,13 +53,26 @@ bool ToolAddPolygon::buttonPress(unsigned int button, const Vertex *v) {
if(button != 1)
return false;
- if(!v)
- return false;
-
- if(!editManager->vertexOk(*v, &newRoom))
- return false;
-
- newRoom.addVertex(*v);
+ if(editManager->getHoveredObject() && editManager->getHoveredObject()->isOfType("LevelVertex")) {
+ LevelVertex *vertex = (LevelVertex*)editManager->getHoveredObject();
+
+ if(!vertex->canConnect())
+ return false;
+
+ if(!editManager->vertexOk(**vertex, &newRoom))
+ return false;
+
+ newRoom.addVertex(*vertex);
+ }
+ else {
+ if(!v)
+ return false;
+
+ if(!editManager->vertexOk(*v, &newRoom))
+ return false;
+
+ newRoom.addVertex(*v);
+ }
editManager->redraw();
sidebar.update();
diff --git a/ToolAddRect.cpp b/ToolAddRect.cpp
index 888205d..bf62c51 100644
--- a/ToolAddRect.cpp
+++ b/ToolAddRect.cpp
@@ -10,6 +10,7 @@ Room ToolAddRect::createRoom() {
room.addVertex(Vertex(v1.getX(), v2->getY()));
room.addVertex(*v2);
room.addVertex(Vertex(v2->getX(), v1.getY()));
+ room.close();
return room;
}
diff --git a/VertexProvider.h b/VertexProvider.h
index 101098e..a1ec4eb 100644
--- a/VertexProvider.h
+++ b/VertexProvider.h
@@ -4,6 +4,8 @@
#include "Vertex.h"
+class LevelVertex;
+
class VertexProvider {
public:
virtual ~VertexProvider() {}
@@ -15,7 +17,7 @@ class VertexProvider {
virtual void rotateVertex(size_t id, Vertex m, float a) {}
virtual bool canConnectVertex(size_t id) const {return false;}
- virtual void connectVertex(size_t id) {}
+ virtual size_t connectVertex(size_t id) {return id;}
};
#endif /*VERTEXPROVIDER_H_*/