summaryrefslogtreecommitdiffstats
path: root/src/Data
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2008-04-13 03:59:01 +0200
committerneoraider <devnull@localhost>2008-04-13 03:59:01 +0200
commit184c6305a677d968e60eb6cba9b29dd840cdce3c (patch)
tree9e0eaab4cf21c1e9717e29a79a9010678eccfc0b /src/Data
parent7fa8e4b4faf6dca308607977d2c2aaa5428ca60d (diff)
downloadzoomedit-184c6305a677d968e60eb6cba9b29dd840cdce3c.tar
zoomedit-184c6305a677d968e60eb6cba9b29dd840cdce3c.zip
zoomedit:
* New data interfaces, yay! Levels should now be completely editable * Fixed some -Wextra warnings
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/Gate.cpp38
-rw-r--r--src/Data/Gate.h16
-rw-r--r--src/Data/Level.cpp112
-rw-r--r--src/Data/Level.h40
-rw-r--r--src/Data/Room.cpp38
-rw-r--r--src/Data/Room.h16
-rw-r--r--src/Data/Texture.h6
-rw-r--r--src/Data/Triangle.h4
8 files changed, 182 insertions, 88 deletions
diff --git a/src/Data/Gate.cpp b/src/Data/Gate.cpp
index 2aa89ee..62794c2 100644
--- a/src/Data/Gate.cpp
+++ b/src/Data/Gate.cpp
@@ -18,6 +18,7 @@
*/
#include "Gate.h"
+#include "Triangle.h"
namespace ZoomEdit {
namespace Data {
@@ -29,7 +30,7 @@ Gate::Gate(xmlpp::Element *node) : gateNode(node) {
xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t);
if(tNode)
- triangles.push_back(Triangle(tNode));
+ triangles.push_back(new Triangle(tNode));
}
id = node->get_attribute_value("id");
@@ -37,5 +38,40 @@ Gate::Gate(xmlpp::Element *node) : gateNode(node) {
room2 = node->get_attribute_value("room2");
}
+Gate::~Gate() {
+ for(std::list<Triangle*>::iterator t = triangles.begin(); t != triangles.end(); ++t)
+ delete *t;
+}
+
+Triangle* Gate::addTriangle() {
+ xmlpp::Element *tNode = gateNode->add_child("triangle");
+
+ xmlpp::Element *node = tNode->add_child("vertex");
+ node->set_attribute("x", "0.0");
+ node->set_attribute("y", "0.0");
+ node->set_attribute("z", "0.0");
+
+ node = tNode->add_child("vertex");
+ node->set_attribute("x", "0.0");
+ node->set_attribute("y", "0.0");
+ node->set_attribute("z", "0.0");
+
+ node = tNode->add_child("vertex");
+ node->set_attribute("x", "0.0");
+ node->set_attribute("y", "0.0");
+ node->set_attribute("z", "0.0");
+
+ Triangle *t = new Triangle(tNode);
+ triangles.push_back(t);
+
+ return t;
+}
+
+void Gate::removeTriangle(Triangle *t) {
+ gateNode->remove_child(t->getNode());
+ triangles.remove(t);
+ delete t;
+}
+
}
}
diff --git a/src/Data/Gate.h b/src/Data/Gate.h
index b1cde71..a6fb958 100644
--- a/src/Data/Gate.h
+++ b/src/Data/Gate.h
@@ -20,27 +20,37 @@
#ifndef ZOOMEDIT_DATA_GATE_H_
#define ZOOMEDIT_DATA_GATE_H_
-#include "Triangle.h"
#include <list>
+#include <libxml++/nodes/element.h>
namespace ZoomEdit {
namespace Data {
+class Triangle;
+
class Gate {
private:
- std::list<Triangle> triangles;
+ std::list<Triangle*> triangles;
xmlpp::Element *gateNode;
Glib::ustring id;
Glib::ustring room1, room2;
+ // Prevent shallow copy
+ Gate(const Gate &o);
+ Gate& operator=(const Gate &o);
+
public:
Gate(xmlpp::Element *node);
+ virtual ~Gate();
- const std::list<Triangle>& getTriangles() {
+ const std::list<Triangle*>& getTriangles() {
return triangles;
}
+ Triangle* addTriangle();
+ void removeTriangle(Triangle *t);
+
const Glib::ustring& getId() const {
return id;
}
diff --git a/src/Data/Level.cpp b/src/Data/Level.cpp
index 6689107..283bf66 100644
--- a/src/Data/Level.cpp
+++ b/src/Data/Level.cpp
@@ -18,6 +18,9 @@
*/
#include "Level.h"
+#include "Room.h"
+#include "Gate.h"
+#include "Texture.h"
namespace ZoomEdit {
namespace Data {
@@ -32,11 +35,8 @@ Level::Level(xmlpp::Element *levelNode) : info(dynamic_cast<xmlpp::Element*>(lev
for(xmlpp::Node::NodeList::iterator room = nodeList.begin(); room != nodeList.end(); ++room) {
xmlpp::Element *roomNode = dynamic_cast<xmlpp::Element*>(*room);
- if(roomNode) {
- Room room(roomNode);
-
- rooms.insert(std::make_pair(room.getId(), room));
- }
+ if(roomNode)
+ rooms.push_back(new Room(roomNode));
}
nodeList = gatesNode->get_children("gate");
@@ -44,11 +44,8 @@ Level::Level(xmlpp::Element *levelNode) : info(dynamic_cast<xmlpp::Element*>(lev
for(xmlpp::Node::NodeList::iterator gate = nodeList.begin(); gate != nodeList.end(); ++gate) {
xmlpp::Element *gateNode = dynamic_cast<xmlpp::Element*>(*gate);
- if(gateNode) {
- Gate gate(gateNode);
-
- gates.insert(std::make_pair(gate.getId(), gate));
- }
+ if(gateNode)
+ gates.push_back(new Gate(gateNode));
}
nodeList = texturesNode->get_children("texture");
@@ -56,22 +53,23 @@ Level::Level(xmlpp::Element *levelNode) : info(dynamic_cast<xmlpp::Element*>(lev
for(xmlpp::Node::NodeList::iterator tex = nodeList.begin(); tex != nodeList.end(); ++tex) {
xmlpp::Element *texNode = dynamic_cast<xmlpp::Element*>(*tex);
- if(texNode) {
- Texture tex(texNode);
-
- textures.insert(std::make_pair(tex.getId(), tex));
- }
+ if(texNode)
+ textures.push_back(new Texture(texNode));
}
}
-Room* Level::getRoom(const Glib::ustring &id) {
- std::map<Glib::ustring,Room>::iterator room = rooms.find(id);
- return (room != rooms.end()) ? &room->second : NULL;
+Level::~Level() {
+ for(std::list<Room*>::iterator room = rooms.begin(); room != rooms.end(); ++room)
+ delete *room;
}
-const Room* Level::getRoom(const Glib::ustring &id) const {
- std::map<Glib::ustring,Room>::const_iterator room = rooms.find(id);
- return (room != rooms.end()) ? &room->second : NULL;
+Room* Level::getRoom(const Glib::ustring &id) const {
+ for(std::list<Room*>::const_iterator room = rooms.begin(); room != rooms.end(); ++room) {
+ if((*room)->getId() == id)
+ return *room;
+ }
+
+ return NULL;
}
Room* Level::addRoom(const Glib::ustring &id) {
@@ -79,26 +77,25 @@ Room* Level::addRoom(const Glib::ustring &id) {
node->set_attribute("id", id);
- return &rooms.insert(std::make_pair(id, Room(node))).first->second;
-}
-
-void Level::removeRoom(const Glib::ustring &id) {
- Room *room = getRoom(id);
- if(!room)
- return;
+ Room *room = new Room(node);
+ rooms.push_back(room);
- roomsNode->remove_child(room->getNode());
- rooms.erase(id);
+ return room;
}
-Gate* Level::getGate(const Glib::ustring &id) {
- std::map<Glib::ustring,Gate>::iterator gate = gates.find(id);
- return (gate != gates.end()) ? &gate->second : NULL;
+void Level::removeRoom(Room *room) {
+ roomsNode->remove_child(room->getNode());
+ rooms.remove(room);
+ delete room;
}
-const Gate* Level::getGate(const Glib::ustring &id) const {
- std::map<Glib::ustring,Gate>::const_iterator gate = gates.find(id);
- return (gate != gates.end()) ? &gate->second : NULL;
+Gate* Level::getGate(const Glib::ustring &id) const {
+ for(std::list<Gate*>::const_iterator gate = gates.begin(); gate != gates.end(); ++gate) {
+ if((*gate)->getId() == id)
+ return *gate;
+ }
+
+ return NULL;
}
Gate* Level::addGate(const Glib::ustring &id) {
@@ -108,26 +105,25 @@ Gate* Level::addGate(const Glib::ustring &id) {
node->set_attribute("room1", "");
node->set_attribute("room2", "");
- return &gates.insert(std::make_pair(id, Gate(node))).first->second;
-}
-
-void Level::removeGate(const Glib::ustring &id) {
- Gate *gate = getGate(id);
- if(!gate)
- return;
+ Gate *gate = new Gate(node);
+ gates.push_back(gate);
- gatesNode->remove_child(gate->getNode());
- gates.erase(id);
+ return gate;
}
-Texture* Level::getTexture(const Glib::ustring &id) {
- std::map<Glib::ustring,Texture>::iterator tex = textures.find(id);
- return (tex != textures.end()) ? &tex->second : NULL;
+void Level::removeGate(Gate *gate) {
+ gatesNode->remove_child(gate->getNode());
+ gates.remove(gate);
+ delete gate;
}
-const Texture* Level::getTexture(const Glib::ustring &id) const {
- std::map<Glib::ustring,Texture>::const_iterator tex = textures.find(id);
- return (tex != textures.end()) ? &tex->second : NULL;
+Texture* Level::getTexture(const Glib::ustring &id) const {
+ for(std::list<Texture*>::const_iterator tex = textures.begin(); tex != textures.end(); ++tex) {
+ if((*tex)->getId() == id)
+ return *tex;
+ }
+
+ return NULL;
}
Texture* Level::addTexture(const Glib::ustring &id) {
@@ -136,16 +132,16 @@ Texture* Level::addTexture(const Glib::ustring &id) {
node->set_attribute("id", id);
node->set_attribute("name", "");
- return &textures.insert(std::make_pair(id, Texture(node))).first->second;
+ Texture *tex = new Texture(node);
+ textures.push_back(tex);
+
+ return tex;
}
-void Level::removeTexture(const Glib::ustring &id) {
- Texture *tex = getTexture(id);
- if(!tex)
- return;
-
+void Level::removeTexture(Texture *tex) {
texturesNode->remove_child(tex->getNode());
- textures.erase(id);
+ textures.remove(tex);
+ delete tex;
}
}
diff --git a/src/Data/Level.h b/src/Data/Level.h
index c72b503..34b5b1a 100644
--- a/src/Data/Level.h
+++ b/src/Data/Level.h
@@ -21,54 +21,56 @@
#define ZOOMEDIT_DATA_LEVEL_H_
#include "Info.h"
-#include "Room.h"
-#include "Gate.h"
-#include "Texture.h"
#include <list>
-#include <map>
namespace ZoomEdit {
namespace Data {
+class Room;
+class Gate;
+class Texture;
+
class Level {
private:
Info info;
- std::map<Glib::ustring,Room> rooms;
+ std::list<Room*> rooms;
xmlpp::Element *roomsNode;
- std::map<Glib::ustring,Gate> gates;
+ std::list<Gate*> gates;
xmlpp::Element *gatesNode;
- std::map<Glib::ustring,Texture> textures;
+ std::list<Texture*> textures;
xmlpp::Element *texturesNode;
+ // Prevent shallow copy
+ Level(const Level &o);
+ Level& operator=(const Level &o);
+
public:
Level(xmlpp::Element *levelNode);
+ virtual ~Level();
- const std::map<Glib::ustring,Room>& getRooms() const {return rooms;}
+ const std::list<Room*>& getRooms() const {return rooms;}
- Room* getRoom(const Glib::ustring &id);
- const Room* getRoom(const Glib::ustring &id) const;
+ Room* getRoom(const Glib::ustring &id) const;
Room* addRoom(const Glib::ustring &id);
- void removeRoom(const Glib::ustring &id);
+ void removeRoom(Room *room);
- const std::map<Glib::ustring,Gate>& getGates() const {return gates;}
+ const std::list<Gate*>& getGates() const {return gates;}
- Gate* getGate(const Glib::ustring &id);
- const Gate* getGate(const Glib::ustring &id) const;
+ Gate* getGate(const Glib::ustring &id) const;
Gate* addGate(const Glib::ustring &id);
- void removeGate(const Glib::ustring &id);
+ void removeGate(Gate *gate);
- const std::map<Glib::ustring,Texture>& getTextures() const {return textures;}
+ const std::list<Texture*>& getTextures() const {return textures;}
- Texture* getTexture(const Glib::ustring &id);
- const Texture* getTexture(const Glib::ustring &id) const;
+ Texture* getTexture(const Glib::ustring &id) const;
Texture* addTexture(const Glib::ustring &id);
- void removeTexture(const Glib::ustring &id);
+ void removeTexture(Texture *tex);
};
}
diff --git a/src/Data/Room.cpp b/src/Data/Room.cpp
index 9749b22..acc79be 100644
--- a/src/Data/Room.cpp
+++ b/src/Data/Room.cpp
@@ -18,6 +18,7 @@
*/
#include "Room.h"
+#include "Triangle.h"
namespace ZoomEdit {
namespace Data {
@@ -29,11 +30,46 @@ Room::Room(xmlpp::Element *node) : roomNode(node) {
xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t);
if(tNode)
- triangles.push_back(Triangle(tNode));
+ triangles.push_back(new Triangle(tNode));
}
id = node->get_attribute_value("id");
}
+Room::~Room() {
+ for(std::list<Triangle*>::iterator t = triangles.begin(); t != triangles.end(); ++t)
+ delete *t;
+}
+
+Triangle* Room::addTriangle() {
+ xmlpp::Element *tNode = roomNode->add_child("triangle");
+
+ xmlpp::Element *node = tNode->add_child("vertex");
+ node->set_attribute("x", "0.0");
+ node->set_attribute("y", "0.0");
+ node->set_attribute("z", "0.0");
+
+ node = tNode->add_child("vertex");
+ node->set_attribute("x", "0.0");
+ node->set_attribute("y", "0.0");
+ node->set_attribute("z", "0.0");
+
+ node = tNode->add_child("vertex");
+ node->set_attribute("x", "0.0");
+ node->set_attribute("y", "0.0");
+ node->set_attribute("z", "0.0");
+
+ Triangle *t = new Triangle(tNode);
+ triangles.push_back(t);
+
+ return t;
+}
+
+void Room::removeTriangle(Triangle *t) {
+ roomNode->remove_child(t->getNode());
+ triangles.remove(t);
+ delete t;
+}
+
}
}
diff --git a/src/Data/Room.h b/src/Data/Room.h
index 1c1f9e8..e290e36 100644
--- a/src/Data/Room.h
+++ b/src/Data/Room.h
@@ -20,26 +20,36 @@
#ifndef ZOOMEDIT_DATA_ROOM_H_
#define ZOOMEDIT_DATA_ROOM_H_
-#include "Triangle.h"
#include <list>
+#include <libxml++/nodes/element.h>
namespace ZoomEdit {
namespace Data {
+class Triangle;
+
class Room {
private:
- std::list<Triangle> triangles;
+ std::list<Triangle*> triangles;
xmlpp::Element *roomNode;
Glib::ustring id;
+ // Prevent shallow copy
+ Room(const Room &o);
+ Room& operator=(const Room &o);
+
public:
Room(xmlpp::Element *node);
+ virtual ~Room();
- const std::list<Triangle>& getTriangles() const {
+ const std::list<Triangle*>& getTriangles() const {
return triangles;
}
+ Triangle* addTriangle();
+ void removeTriangle(Triangle *t);
+
const Glib::ustring& getId() const {
return id;
}
diff --git a/src/Data/Texture.h b/src/Data/Texture.h
index b301bbf..8bc2c82 100644
--- a/src/Data/Texture.h
+++ b/src/Data/Texture.h
@@ -38,9 +38,9 @@ class Texture {
return id;
}
- void setId(const Glib::ustring &nid) {
- id = nid;
- texNode->set_attribute("id", nid);
+ void setId(const Glib::ustring &id0) {
+ id = id0;
+ texNode->set_attribute("id", id0);
}
const Glib::ustring& getName() const {
diff --git a/src/Data/Triangle.h b/src/Data/Triangle.h
index 3a235ce..2267f36 100644
--- a/src/Data/Triangle.h
+++ b/src/Data/Triangle.h
@@ -78,6 +78,10 @@ class Triangle {
visible = vis;
triangleNode->set_attribute("visible", vis ? "true" : "false");
}
+
+ xmlpp::Element* getNode() const {
+ return triangleNode;
+ }
};
}