summaryrefslogtreecommitdiffstats
path: root/edit.cpp
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2007-09-17 00:24:02 +0200
committerneoraider <devnull@localhost>2007-09-17 00:24:02 +0200
commitd7a846e58a85ed311e83362af0b6474652d85c8a (patch)
tree965e42028a4eacb6790b908692dc321ddf5fc45f /edit.cpp
parent96e9d04527dc17a2a4f8c2f7034c1c356ed5186e (diff)
downloadzoomedit-d7a846e58a85ed311e83362af0b6474652d85c8a.tar
zoomedit-d7a846e58a85ed311e83362af0b6474652d85c8a.zip
zoomedit: Alle Datenstrukturen durch Klassen ersetzt.
Diffstat (limited to 'edit.cpp')
-rw-r--r--edit.cpp80
1 files changed, 41 insertions, 39 deletions
diff --git a/edit.cpp b/edit.cpp
index 96dce6e..ab19969 100644
--- a/edit.cpp
+++ b/edit.cpp
@@ -1,12 +1,16 @@
+#include "Level.h"
#include "edit.h"
-#include "level.h"
#include "geometry.h"
static int editMode = EDIT_MODE_VIEW;
-static ROOM *activeRoom = NULL;
-static ROOM *hoveredRoom = NULL;
+static Level *level = NULL;
+
+static Room *activeRoom = NULL;
+static Room *hoveredRoom = NULL;
+
+static Room addRoom;
static Vertex hoveredVertex;
static int hasHoveredVertex = 0;
@@ -15,11 +19,19 @@ int getEditMode() {
return editMode;
}
-ROOM *getActiveRoom() {
+Level *getLevel() {
+ return level;
+}
+
+void setLevel(Level *l) {
+ level = l;
+}
+
+Room *getActiveRoom() {
return activeRoom;
}
-void setActiveRoom(ROOM *room) {
+void setActiveRoom(Room *room) {
activeRoom = room;
if(room == NULL) {
@@ -36,19 +48,15 @@ Vertex *getHoveredVertex() {
}
void setHoveredVertex(Vertex *v) {
- int i;
- LEVEL *l;
-
if(v) {
hasHoveredVertex = 1;
hoveredVertex = *v;
- l = getLevel();
hoveredRoom = NULL;
- for(i = 0; i < l->nRooms; i++) {
- if(l->rooms[i].polygon.contains(*v)) {
- hoveredRoom = &l->rooms[i];
+ for(Level::iterator room = level->begin(); room != level->end(); room++) {
+ if(room->contains(*v)) {
+ hoveredRoom = &*room;
break;
}
}
@@ -60,9 +68,8 @@ void setHoveredVertex(Vertex *v) {
}
void startAddMode() {
- activeRoom = (ROOM*)calloc(1, sizeof(ROOM));
- activeRoom->polygon = Polygon();
- activeRoom->name = (char*)calloc(1, sizeof(unsigned char));
+ addRoom = Room();
+ activeRoom = &addRoom;
editMode = EDIT_MODE_ADD;
}
@@ -71,32 +78,31 @@ void endAddMode() {
editMode = activeRoom ? EDIT_MODE_SELECTED : EDIT_MODE_VIEW;
}
-ROOM *getHoveredRoom() {
+Room *getHoveredRoom() {
return hoveredRoom;
}
static bool isLineOk(Line *l) {
- LEVEL *lvl = getLevel();
Line l2;
if(activeRoom) {
- for(int i = 0; i+2 < activeRoom->polygon.size(); i++) {
- l2.setVertex1(activeRoom->polygon[i]);
- l2.setVertex2(activeRoom->polygon[i+1]);
+ for(int i = 0; i+2 < activeRoom->size(); i++) {
+ l2.setVertex1(activeRoom->at(i));
+ l2.setVertex2(activeRoom->at(i+1));
if(l->intersects(l2, NULL) == INTERSECTION_SEGMENT_SEGMENT) return false;
}
- if(activeRoom->polygon.size() > 1) {
- l2.setVertex1(activeRoom->polygon[activeRoom->polygon.size()-2]);
- l2.setVertex2(activeRoom->polygon.back());
+ if(activeRoom->size() > 1) {
+ l2.setVertex1(activeRoom->at(activeRoom->size()-2));
+ l2.setVertex2(activeRoom->back());
if(l2.contains(l->getVertex2())) return false;
}
}
- for(int i = 0; i < lvl->nRooms; i++) {
- if(lvl->rooms[i].polygon.intersects(*l))
+ for(Level::iterator room = level->begin(); room != level->end(); room++) {
+ if(room->intersects(*l))
return false;
}
@@ -104,19 +110,16 @@ static bool isLineOk(Line *l) {
}
bool isVertexOk(Vertex *v) {
- LEVEL *lvl = getLevel();
Line l;
- int i;
-
- for(i = 0; i < lvl->nRooms; i++) {
- if(lvl->rooms[i].polygon.contains(*v)) return false;
+ for(Level::iterator room = level->begin(); room != level->end(); room++) {
+ if(room->contains(*v)) return false;
}
- if(!(getActiveRoom() && !getActiveRoom()->polygon.empty()))
+ if(!(getActiveRoom() && !getActiveRoom()->empty()))
return true;
- l.setVertex1(getActiveRoom()->polygon.back());
+ l.setVertex1(getActiveRoom()->back());
l.setVertex2(*v);
return isLineOk(&l);
@@ -125,18 +128,17 @@ bool isVertexOk(Vertex *v) {
bool isPolygonOk(Polygon *polygon) {
- LEVEL *lvl = getLevel();
Line l, l2;
if(polygon->empty()) return false;
- for(int i = 0; i < lvl->nRooms; i++) {
- if(lvl->rooms[i].polygon.empty()) continue;
+ for(Level::iterator room = level->begin(); room != level->end(); room++) {
+ if(room->empty()) continue;
- if(lvl->rooms[i].polygon.contains(polygon->front()));
+ if(room->contains(polygon->front()))
return false;
- if(polygon->contains(lvl->rooms[i].polygon.front()));
+ if(polygon->contains(room->front()))
return false;
}
@@ -150,8 +152,8 @@ bool isPolygonOk(Polygon *polygon) {
l.setVertex1(*it);
l.setVertex2(*it2);
- for(int i = 0; i < lvl->nRooms; i++) {
- if(lvl->rooms[i].polygon.intersects(l))
+ for(Level::iterator room = level->begin(); room != level->end(); room++) {
+ if(room->intersects(l))
return false;
}