zoomedit:

* New data interfaces, yay! Levels should now be completely editable
* Fixed some -Wextra warnings
This commit is contained in:
neoraider 2008-04-13 01:59:01 +00:00
parent 7fa8e4b4fa
commit 184c6305a6
10 changed files with 189 additions and 95 deletions

View file

@ -18,6 +18,7 @@
*/ */
#include "Gate.h" #include "Gate.h"
#include "Triangle.h"
namespace ZoomEdit { namespace ZoomEdit {
namespace Data { namespace Data {
@ -29,7 +30,7 @@ Gate::Gate(xmlpp::Element *node) : gateNode(node) {
xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t); xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t);
if(tNode) if(tNode)
triangles.push_back(Triangle(tNode)); triangles.push_back(new Triangle(tNode));
} }
id = node->get_attribute_value("id"); id = node->get_attribute_value("id");
@ -37,5 +38,40 @@ Gate::Gate(xmlpp::Element *node) : gateNode(node) {
room2 = node->get_attribute_value("room2"); 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;
}
} }
} }

View file

@ -20,27 +20,37 @@
#ifndef ZOOMEDIT_DATA_GATE_H_ #ifndef ZOOMEDIT_DATA_GATE_H_
#define ZOOMEDIT_DATA_GATE_H_ #define ZOOMEDIT_DATA_GATE_H_
#include "Triangle.h"
#include <list> #include <list>
#include <libxml++/nodes/element.h>
namespace ZoomEdit { namespace ZoomEdit {
namespace Data { namespace Data {
class Triangle;
class Gate { class Gate {
private: private:
std::list<Triangle> triangles; std::list<Triangle*> triangles;
xmlpp::Element *gateNode; xmlpp::Element *gateNode;
Glib::ustring id; Glib::ustring id;
Glib::ustring room1, room2; Glib::ustring room1, room2;
// Prevent shallow copy
Gate(const Gate &o);
Gate& operator=(const Gate &o);
public: public:
Gate(xmlpp::Element *node); Gate(xmlpp::Element *node);
virtual ~Gate();
const std::list<Triangle>& getTriangles() { const std::list<Triangle*>& getTriangles() {
return triangles; return triangles;
} }
Triangle* addTriangle();
void removeTriangle(Triangle *t);
const Glib::ustring& getId() const { const Glib::ustring& getId() const {
return id; return id;
} }

View file

@ -18,6 +18,9 @@
*/ */
#include "Level.h" #include "Level.h"
#include "Room.h"
#include "Gate.h"
#include "Texture.h"
namespace ZoomEdit { namespace ZoomEdit {
namespace Data { 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) { for(xmlpp::Node::NodeList::iterator room = nodeList.begin(); room != nodeList.end(); ++room) {
xmlpp::Element *roomNode = dynamic_cast<xmlpp::Element*>(*room); xmlpp::Element *roomNode = dynamic_cast<xmlpp::Element*>(*room);
if(roomNode) { if(roomNode)
Room room(roomNode); rooms.push_back(new Room(roomNode));
rooms.insert(std::make_pair(room.getId(), room));
}
} }
nodeList = gatesNode->get_children("gate"); 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) { for(xmlpp::Node::NodeList::iterator gate = nodeList.begin(); gate != nodeList.end(); ++gate) {
xmlpp::Element *gateNode = dynamic_cast<xmlpp::Element*>(*gate); xmlpp::Element *gateNode = dynamic_cast<xmlpp::Element*>(*gate);
if(gateNode) { if(gateNode)
Gate gate(gateNode); gates.push_back(new Gate(gateNode));
gates.insert(std::make_pair(gate.getId(), gate));
}
} }
nodeList = texturesNode->get_children("texture"); 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) { for(xmlpp::Node::NodeList::iterator tex = nodeList.begin(); tex != nodeList.end(); ++tex) {
xmlpp::Element *texNode = dynamic_cast<xmlpp::Element*>(*tex); xmlpp::Element *texNode = dynamic_cast<xmlpp::Element*>(*tex);
if(texNode) { if(texNode)
Texture tex(texNode); textures.push_back(new Texture(texNode));
textures.insert(std::make_pair(tex.getId(), tex));
}
} }
} }
Room* Level::getRoom(const Glib::ustring &id) { Level::~Level() {
std::map<Glib::ustring,Room>::iterator room = rooms.find(id); for(std::list<Room*>::iterator room = rooms.begin(); room != rooms.end(); ++room)
return (room != rooms.end()) ? &room->second : NULL; delete *room;
} }
const Room* Level::getRoom(const Glib::ustring &id) const { Room* Level::getRoom(const Glib::ustring &id) const {
std::map<Glib::ustring,Room>::const_iterator room = rooms.find(id); for(std::list<Room*>::const_iterator room = rooms.begin(); room != rooms.end(); ++room) {
return (room != rooms.end()) ? &room->second : NULL; if((*room)->getId() == id)
return *room;
}
return NULL;
} }
Room* Level::addRoom(const Glib::ustring &id) { Room* Level::addRoom(const Glib::ustring &id) {
@ -79,26 +77,25 @@ Room* Level::addRoom(const Glib::ustring &id) {
node->set_attribute("id", id); node->set_attribute("id", id);
return &rooms.insert(std::make_pair(id, Room(node))).first->second; Room *room = new Room(node);
rooms.push_back(room);
return room;
} }
void Level::removeRoom(const Glib::ustring &id) { void Level::removeRoom(Room *room) {
Room *room = getRoom(id);
if(!room)
return;
roomsNode->remove_child(room->getNode()); roomsNode->remove_child(room->getNode());
rooms.erase(id); rooms.remove(room);
delete room;
} }
Gate* Level::getGate(const Glib::ustring &id) { Gate* Level::getGate(const Glib::ustring &id) const {
std::map<Glib::ustring,Gate>::iterator gate = gates.find(id); for(std::list<Gate*>::const_iterator gate = gates.begin(); gate != gates.end(); ++gate) {
return (gate != gates.end()) ? &gate->second : NULL; if((*gate)->getId() == id)
return *gate;
} }
const Gate* Level::getGate(const Glib::ustring &id) const { return NULL;
std::map<Glib::ustring,Gate>::const_iterator gate = gates.find(id);
return (gate != gates.end()) ? &gate->second : NULL;
} }
Gate* Level::addGate(const Glib::ustring &id) { 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("room1", "");
node->set_attribute("room2", ""); node->set_attribute("room2", "");
return &gates.insert(std::make_pair(id, Gate(node))).first->second; Gate *gate = new Gate(node);
gates.push_back(gate);
return gate;
} }
void Level::removeGate(const Glib::ustring &id) { void Level::removeGate(Gate *gate) {
Gate *gate = getGate(id);
if(!gate)
return;
gatesNode->remove_child(gate->getNode()); gatesNode->remove_child(gate->getNode());
gates.erase(id); gates.remove(gate);
delete gate;
} }
Texture* Level::getTexture(const Glib::ustring &id) { Texture* Level::getTexture(const Glib::ustring &id) const {
std::map<Glib::ustring,Texture>::iterator tex = textures.find(id); for(std::list<Texture*>::const_iterator tex = textures.begin(); tex != textures.end(); ++tex) {
return (tex != textures.end()) ? &tex->second : NULL; if((*tex)->getId() == id)
return *tex;
} }
const Texture* Level::getTexture(const Glib::ustring &id) const { return NULL;
std::map<Glib::ustring,Texture>::const_iterator tex = textures.find(id);
return (tex != textures.end()) ? &tex->second : NULL;
} }
Texture* Level::addTexture(const Glib::ustring &id) { 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("id", id);
node->set_attribute("name", ""); 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) { void Level::removeTexture(Texture *tex) {
Texture *tex = getTexture(id);
if(!tex)
return;
texturesNode->remove_child(tex->getNode()); texturesNode->remove_child(tex->getNode());
textures.erase(id); textures.remove(tex);
delete tex;
} }
} }

View file

@ -21,54 +21,56 @@
#define ZOOMEDIT_DATA_LEVEL_H_ #define ZOOMEDIT_DATA_LEVEL_H_
#include "Info.h" #include "Info.h"
#include "Room.h"
#include "Gate.h"
#include "Texture.h"
#include <list> #include <list>
#include <map>
namespace ZoomEdit { namespace ZoomEdit {
namespace Data { namespace Data {
class Room;
class Gate;
class Texture;
class Level { class Level {
private: private:
Info info; Info info;
std::map<Glib::ustring,Room> rooms; std::list<Room*> rooms;
xmlpp::Element *roomsNode; xmlpp::Element *roomsNode;
std::map<Glib::ustring,Gate> gates; std::list<Gate*> gates;
xmlpp::Element *gatesNode; xmlpp::Element *gatesNode;
std::map<Glib::ustring,Texture> textures; std::list<Texture*> textures;
xmlpp::Element *texturesNode; xmlpp::Element *texturesNode;
// Prevent shallow copy
Level(const Level &o);
Level& operator=(const Level &o);
public: public:
Level(xmlpp::Element *levelNode); 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); Room* getRoom(const Glib::ustring &id) const;
const Room* getRoom(const Glib::ustring &id) const;
Room* addRoom(const Glib::ustring &id); 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); Gate* getGate(const Glib::ustring &id) const;
const Gate* getGate(const Glib::ustring &id) const;
Gate* addGate(const Glib::ustring &id); 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); Texture* getTexture(const Glib::ustring &id) const;
const Texture* getTexture(const Glib::ustring &id) const;
Texture* addTexture(const Glib::ustring &id); Texture* addTexture(const Glib::ustring &id);
void removeTexture(const Glib::ustring &id); void removeTexture(Texture *tex);
}; };
} }

View file

@ -18,6 +18,7 @@
*/ */
#include "Room.h" #include "Room.h"
#include "Triangle.h"
namespace ZoomEdit { namespace ZoomEdit {
namespace Data { namespace Data {
@ -29,11 +30,46 @@ Room::Room(xmlpp::Element *node) : roomNode(node) {
xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t); xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t);
if(tNode) if(tNode)
triangles.push_back(Triangle(tNode)); triangles.push_back(new Triangle(tNode));
} }
id = node->get_attribute_value("id"); 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;
}
} }
} }

View file

@ -20,26 +20,36 @@
#ifndef ZOOMEDIT_DATA_ROOM_H_ #ifndef ZOOMEDIT_DATA_ROOM_H_
#define ZOOMEDIT_DATA_ROOM_H_ #define ZOOMEDIT_DATA_ROOM_H_
#include "Triangle.h"
#include <list> #include <list>
#include <libxml++/nodes/element.h>
namespace ZoomEdit { namespace ZoomEdit {
namespace Data { namespace Data {
class Triangle;
class Room { class Room {
private: private:
std::list<Triangle> triangles; std::list<Triangle*> triangles;
xmlpp::Element *roomNode; xmlpp::Element *roomNode;
Glib::ustring id; Glib::ustring id;
// Prevent shallow copy
Room(const Room &o);
Room& operator=(const Room &o);
public: public:
Room(xmlpp::Element *node); Room(xmlpp::Element *node);
virtual ~Room();
const std::list<Triangle>& getTriangles() const { const std::list<Triangle*>& getTriangles() const {
return triangles; return triangles;
} }
Triangle* addTriangle();
void removeTriangle(Triangle *t);
const Glib::ustring& getId() const { const Glib::ustring& getId() const {
return id; return id;
} }

View file

@ -38,9 +38,9 @@ class Texture {
return id; return id;
} }
void setId(const Glib::ustring &nid) { void setId(const Glib::ustring &id0) {
id = nid; id = id0;
texNode->set_attribute("id", nid); texNode->set_attribute("id", id0);
} }
const Glib::ustring& getName() const { const Glib::ustring& getName() const {

View file

@ -78,6 +78,10 @@ class Triangle {
visible = vis; visible = vis;
triangleNode->set_attribute("visible", vis ? "true" : "false"); triangleNode->set_attribute("visible", vis ? "true" : "false");
} }
xmlpp::Element* getNode() const {
return triangleNode;
}
}; };
} }

View file

@ -84,12 +84,12 @@ void RenderArea::onRealize() {
gdkGLEnd(); gdkGLEnd();
} }
bool RenderArea::onConfigureEvent(GdkEventConfigure *event) { bool RenderArea::onConfigureEvent(GdkEventConfigure*) {
updateViewport(); updateViewport();
return true; return true;
} }
bool RenderArea::onExposeEvent(GdkEventExpose *event) { bool RenderArea::onExposeEvent(GdkEventExpose*) {
if(!gdkGLBegin()) if(!gdkGLBegin())
return false; return false;

View file

@ -44,8 +44,8 @@ class RenderArea : public Gtk::DrawingArea {
float scale; float scale;
void onRealize(); void onRealize();
bool onConfigureEvent(GdkEventConfigure *event); bool onConfigureEvent(GdkEventConfigure*);
bool onExposeEvent(GdkEventExpose *event); bool onExposeEvent(GdkEventExpose*);
bool onScrollEvent(GdkEventScroll *event); bool onScrollEvent(GdkEventScroll *event);
void zoom(int zoom, float x = 0.5f, float y = 0.5f); void zoom(int zoom, float x = 0.5f, float y = 0.5f);