zoomedit:

* Mapped XML data structures to classes completely.
This commit is contained in:
neoraider 2008-04-10 18:36:05 +00:00
parent 2271ef709f
commit 84780a8c1d
14 changed files with 306 additions and 18 deletions

40
src/Data/Gate.cpp Normal file
View file

@ -0,0 +1,40 @@
/*
* Gate.cpp
*
* Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Gate.h"
namespace ZoomEdit {
namespace Data {
Gate::Gate(xmlpp::Element *node) : gateNode(node) {
xmlpp::Node::NodeList triangleList = node->get_children("triangle");
for(xmlpp::Node::NodeList::iterator t = triangleList.begin(); t != triangleList.end(); ++t) {
xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t);
if(tNode)
triangles.push_front(Triangle(tNode));
}
room1 = node->get_attribute_value("room1");
room2 = node->get_attribute_value("room2");
}
}
}

43
src/Data/Gate.h Normal file
View file

@ -0,0 +1,43 @@
/*
* Gate.h
*
* Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ZOOMEDIT_DATA_GATE_H_
#define ZOOMEDIT_DATA_GATE_H_
#include "Triangle.h"
#include <list>
namespace ZoomEdit {
namespace Data {
class Gate {
private:
std::list<Triangle> triangles;
xmlpp::Element *gateNode;
Glib::ustring room1, room2;
public:
Gate(xmlpp::Element *node);
};
}
}
#endif /*ZOOMEDIT_DATA_GATE_H_*/

35
src/Data/Info.cpp Normal file
View file

@ -0,0 +1,35 @@
/*
* Info.cpp
*
* Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Info.h"
#include <libxml++/nodes/textnode.h>
namespace ZoomEdit {
namespace Data {
Info::Info(xmlpp::Element *node) {
nameNode = dynamic_cast<xmlpp::Element*>(node->get_children("name").front());
name = nameNode->get_child_text()->get_content();
descNode = dynamic_cast<xmlpp::Element*>(node->get_children("desc").front());
desc = descNode->get_child_text()->get_content();
}
}
}

43
src/Data/Info.h Normal file
View file

@ -0,0 +1,43 @@
/*
* Info.h
*
* Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ZOOMEDIT_DATA_INFO_H_
#define ZOOMEDIT_DATA_INFO_H_
#include <libxml++/nodes/element.h>
namespace ZoomEdit {
namespace Data {
class Info {
private:
xmlpp::Element *nameNode;
Glib::ustring name;
xmlpp::Element *descNode;
Glib::ustring desc;
public:
Info(xmlpp::Element *node);
};
}
}
#endif /*ZOOMEDIT_DATA_INFO_H_*/

View file

@ -22,20 +22,37 @@
namespace ZoomEdit {
namespace Data {
Level::Level(xmlpp::Element *levelNode) {
Level::Level(xmlpp::Element *levelNode) : info(dynamic_cast<xmlpp::Element*>(levelNode->get_children("info").front())) {
roomsNode = dynamic_cast<xmlpp::Element*>(levelNode->get_children("rooms").front());
gatesNode = dynamic_cast<xmlpp::Element*>(levelNode->get_children("gates").front());
texturesNode = dynamic_cast<xmlpp::Element*>(levelNode->get_children("textures").front());
if(!roomsNode)
return;
xmlpp::Node::NodeList nodeList = roomsNode->get_children("room");
xmlpp::Node::NodeList roomList = roomsNode->get_children("room");
for(xmlpp::Node::NodeList::iterator room = roomList.begin(); room != roomList.end(); ++room) {
for(xmlpp::Node::NodeList::iterator room = nodeList.begin(); room != nodeList.end(); ++room) {
xmlpp::Element *roomNode = dynamic_cast<xmlpp::Element*>(*room);
if(roomNode)
rooms.push_front(Room(roomNode));
}
nodeList = gatesNode->get_children("gate");
for(xmlpp::Node::NodeList::iterator gate = nodeList.begin(); gate != nodeList.end(); ++gate) {
xmlpp::Element *gateNode = dynamic_cast<xmlpp::Element*>(*gate);
if(gateNode)
gates.push_front(Gate(gateNode));
}
nodeList = texturesNode->get_children("texture");
for(xmlpp::Node::NodeList::iterator tex = nodeList.begin(); tex != nodeList.end(); ++tex) {
xmlpp::Element *texNode = dynamic_cast<xmlpp::Element*>(*tex);
if(texNode)
textures.push_front(Texture(texNode));
}
}
}

View file

@ -20,7 +20,10 @@
#ifndef ZOOMEDIT_DATA_LEVEL_H_
#define ZOOMEDIT_DATA_LEVEL_H_
#include "Info.h"
#include "Room.h"
#include "Gate.h"
#include "Texture.h"
#include <list>
namespace ZoomEdit {
@ -28,9 +31,17 @@ namespace Data {
class Level {
private:
Info info;
std::list<Room> rooms;
xmlpp::Element *roomsNode;
std::list<Gate> gates;
xmlpp::Element *gatesNode;
std::list<Texture> textures;
xmlpp::Element *texturesNode;
public:
Level(xmlpp::Element *levelNode);
};

View file

@ -1,4 +1,4 @@
noinst_LTLIBRARIES = libdata.la
libdata_la_SOURCES = Level.cpp Room.cpp Triangle.cpp Vector.cpp Vertex.cpp
libdata_la_SOURCES = Info.cpp Gate.cpp Level.cpp Room.cpp Texture.cpp Triangle.cpp Vector.cpp Vertex.cpp
libdata_la_CPPFLAGS = $(libxml_CFLAGS)

View file

@ -43,7 +43,8 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libdata_la_LIBADD =
am_libdata_la_OBJECTS = libdata_la-Level.lo libdata_la-Room.lo \
am_libdata_la_OBJECTS = libdata_la-Info.lo libdata_la-Gate.lo \
libdata_la-Level.lo libdata_la-Room.lo libdata_la-Texture.lo \
libdata_la-Triangle.lo libdata_la-Vector.lo \
libdata_la-Vertex.lo
libdata_la_OBJECTS = $(am_libdata_la_OBJECTS)
@ -181,7 +182,7 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libdata.la
libdata_la_SOURCES = Level.cpp Room.cpp Triangle.cpp Vector.cpp Vertex.cpp
libdata_la_SOURCES = Info.cpp Gate.cpp Level.cpp Room.cpp Texture.cpp Triangle.cpp Vector.cpp Vertex.cpp
libdata_la_CPPFLAGS = $(libxml_CFLAGS)
all: all-am
@ -234,8 +235,11 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdata_la-Gate.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdata_la-Info.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdata_la-Level.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdata_la-Room.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdata_la-Texture.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdata_la-Triangle.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdata_la-Vector.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdata_la-Vertex.Plo@am__quote@
@ -261,6 +265,20 @@ distclean-compile:
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $<
libdata_la-Info.lo: Info.cpp
@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdata_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libdata_la-Info.lo -MD -MP -MF $(DEPDIR)/libdata_la-Info.Tpo -c -o libdata_la-Info.lo `test -f 'Info.cpp' || echo '$(srcdir)/'`Info.cpp
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/libdata_la-Info.Tpo $(DEPDIR)/libdata_la-Info.Plo
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Info.cpp' object='libdata_la-Info.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdata_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libdata_la-Info.lo `test -f 'Info.cpp' || echo '$(srcdir)/'`Info.cpp
libdata_la-Gate.lo: Gate.cpp
@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdata_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libdata_la-Gate.lo -MD -MP -MF $(DEPDIR)/libdata_la-Gate.Tpo -c -o libdata_la-Gate.lo `test -f 'Gate.cpp' || echo '$(srcdir)/'`Gate.cpp
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/libdata_la-Gate.Tpo $(DEPDIR)/libdata_la-Gate.Plo
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Gate.cpp' object='libdata_la-Gate.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdata_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libdata_la-Gate.lo `test -f 'Gate.cpp' || echo '$(srcdir)/'`Gate.cpp
libdata_la-Level.lo: Level.cpp
@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdata_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libdata_la-Level.lo -MD -MP -MF $(DEPDIR)/libdata_la-Level.Tpo -c -o libdata_la-Level.lo `test -f 'Level.cpp' || echo '$(srcdir)/'`Level.cpp
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/libdata_la-Level.Tpo $(DEPDIR)/libdata_la-Level.Plo
@ -275,6 +293,13 @@ libdata_la-Room.lo: Room.cpp
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdata_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libdata_la-Room.lo `test -f 'Room.cpp' || echo '$(srcdir)/'`Room.cpp
libdata_la-Texture.lo: Texture.cpp
@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdata_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libdata_la-Texture.lo -MD -MP -MF $(DEPDIR)/libdata_la-Texture.Tpo -c -o libdata_la-Texture.lo `test -f 'Texture.cpp' || echo '$(srcdir)/'`Texture.cpp
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/libdata_la-Texture.Tpo $(DEPDIR)/libdata_la-Texture.Plo
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Texture.cpp' object='libdata_la-Texture.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdata_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libdata_la-Texture.lo `test -f 'Texture.cpp' || echo '$(srcdir)/'`Texture.cpp
libdata_la-Triangle.lo: Triangle.cpp
@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdata_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libdata_la-Triangle.lo -MD -MP -MF $(DEPDIR)/libdata_la-Triangle.Tpo -c -o libdata_la-Triangle.lo `test -f 'Triangle.cpp' || echo '$(srcdir)/'`Triangle.cpp
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/libdata_la-Triangle.Tpo $(DEPDIR)/libdata_la-Triangle.Plo

View file

@ -23,7 +23,7 @@ namespace ZoomEdit {
namespace Data {
Room::Room(xmlpp::Element *node) : roomNode(node) {
xmlpp::Node::NodeList triangleList = roomNode->get_children("triangle");
xmlpp::Node::NodeList triangleList = node->get_children("triangle");
for(xmlpp::Node::NodeList::iterator t = triangleList.begin(); t != triangleList.end(); ++t) {
xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t);
@ -31,6 +31,8 @@ Room::Room(xmlpp::Element *node) : roomNode(node) {
if(tNode)
triangles.push_front(Triangle(tNode));
}
id = node->get_attribute_value("id");
}
}

View file

@ -30,7 +30,9 @@ class Room {
private:
std::list<Triangle> triangles;
xmlpp::Element *roomNode;
Glib::ustring id;
public:
Room(xmlpp::Element *node);
};

31
src/Data/Texture.cpp Normal file
View file

@ -0,0 +1,31 @@
/*
* Texture.cpp
*
* Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Texture.h"
namespace ZoomEdit {
namespace Data {
Texture::Texture(xmlpp::Element *node) : texNode(node) {
id = node->get_attribute_value("id");
name = node->get_attribute_value("name");
}
}
}

41
src/Data/Texture.h Normal file
View file

@ -0,0 +1,41 @@
/*
* Texture.h
*
* Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ZOOMEDIT_DATA_TEXTURE_H_
#define ZOOMEDIT_DATA_TEXTURE_H_
#include <libxml++/nodes/element.h>
namespace ZoomEdit {
namespace Data {
class Texture {
private:
xmlpp::Element *texNode;
Glib::ustring id;
Glib::ustring name;
public:
Texture(xmlpp::Element *node);
};
}
}
#endif /*ZOOMEDIT_DATA_TEXTURE_H_*/

View file

@ -19,7 +19,6 @@
#include "Triangle.h"
#include <cstdlib>
#include <iostream>
namespace ZoomEdit {
namespace Data {
@ -77,8 +76,6 @@ Triangle::Triangle(xmlpp::Element *node) : triangleNode(node) {
texCoordsNodes[i] = e;
texCoords[i] = loadTexCoords(e);
std::cout << "TexCoords (" << texCoords[i].getS() << ", " << texCoords[i].getT() << ", " << texCoords[i].getR() << ", " << texCoords[i].getQ() << ")" << std::endl;
continue;
}
}
@ -86,12 +83,11 @@ Triangle::Triangle(xmlpp::Element *node) : triangleNode(node) {
if(e->get_name() == "vertex") {
vertexNodes[++i] = e;
vertices[i] = loadVertex(e);
std::cout << "Vertex (" << vertices[i].getX() << ", " << vertices[i].getY() << ", " << vertices[i].getZ() << ")" << std::endl;
}
}
visibleNode = node->get_attribute("visible");
visible = (node->get_attribute_value("visible").lowercase() != "false");
texture = node->get_attribute_value("texture");
}
}

View file

@ -33,13 +33,15 @@ class Triangle {
xmlpp::Element *vertexNodes[3];
xmlpp::Element *normalNodes[3];
xmlpp::Element *texCoordsNodes[3];
xmlpp::Attribute *visibleNode;
Vertex vertices[3];
Vector normals[3];
TexCoords texCoords[3];
bool visible;
Glib::ustring texture;
Vertex loadVertex(xmlpp::Element *node) const;
Vector loadVector(xmlpp::Element *node) const;
TexCoords loadTexCoords(xmlpp::Element *node) const;