changeset 33:112fc4af772d

moved grid ownership to model in similar way as with pathers
author jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 11 Jul 2008 15:42:54 +0000
parents 75b6394ced14
children d66538926e78
files doc/dependencies/dirdeps.dot doc/dependencies/filedeps.dot engine/core/controller/engine.cpp engine/core/model/metamodel/grids/cellgrid.h engine/core/model/metamodel/grids/hexgrid.cpp engine/core/model/metamodel/grids/hexgrid.h engine/core/model/metamodel/grids/squaregrid.cpp engine/core/model/metamodel/grids/squaregrid.h engine/core/model/model.cpp engine/core/model/model.h engine/core/model/model.i engine/core/model/structures/layer.h engine/extensions/serializers/xmlmap.py
diffstat 13 files changed, 65 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/doc/dependencies/dirdeps.dot	Fri Jul 11 15:37:16 2008 +0000
+++ b/doc/dependencies/dirdeps.dot	Fri Jul 11 15:42:54 2008 +0000
@@ -105,6 +105,7 @@
     "controller" -> "loaders/native/audio_loaders"
     "controller" -> "loaders/native/video_loaders"
     "controller" -> "model"
+    "controller" -> "model/metamodel/grids"
     "controller" -> "pathfinder/linearpather"
     "controller" -> "pathfinder/routepather"
     "controller" -> "util/base"
@@ -173,6 +174,7 @@
     "loaders/native/video_loaders" -> "vfs/raw"
     "loaders/native/video_loaders" -> "video"
     "model" -> "model/metamodel"
+    "model" -> "model/metamodel/grids"
     "model" -> "model/structures"
     "model" -> "util/base"
     "model" -> "util/structures"
--- a/doc/dependencies/filedeps.dot	Fri Jul 11 15:37:16 2008 +0000
+++ b/doc/dependencies/filedeps.dot	Fri Jul 11 15:42:54 2008 +0000
@@ -43,6 +43,8 @@
     "engine/core/controller/engine.cpp" -> "loaders/native/audio_loaders/ogg_loader.h"
     "engine/core/controller/engine.cpp" -> "loaders/native/video_loaders/image_loader.h"
     "engine/core/controller/engine.cpp" -> "loaders/native/video_loaders/subimage_loader.h"
+    "engine/core/controller/engine.cpp" -> "model/metamodel/grids/hexgrid.h"
+    "engine/core/controller/engine.cpp" -> "model/metamodel/grids/squaregrid.h"
     "engine/core/controller/engine.cpp" -> "model/model.h"
     "engine/core/controller/engine.cpp" -> "pathfinder/linearpather/linearpather.h"
     "engine/core/controller/engine.cpp" -> "pathfinder/routepather/routepather.h"
@@ -66,7 +68,6 @@
     "engine/core/controller/engine.cpp" -> "view/renderers/coordinaterenderer.h"
     "engine/core/controller/engine.cpp" -> "view/renderers/floatingtextrenderer.h"
     "engine/core/controller/engine.cpp" -> "view/renderers/genericrenderer.h"
-    "engine/core/controller/engine.cpp" -> "view/renderers/geometricrenderer.h"
     "engine/core/controller/engine.cpp" -> "view/renderers/gridrenderer.h"
     "engine/core/controller/engine.cpp" -> "view/renderers/instancerenderer.h"
     "engine/core/controller/engine.cpp" -> "view/renderers/quadtreerenderer.h"
@@ -232,6 +233,7 @@
     "engine/core/model/metamodel/timeprovider.h" -> "util/base/exception.h"
     "engine/core/model/model.cpp" -> "model.h"
     "engine/core/model/model.cpp" -> "model/metamodel/abstractpather.h"
+    "engine/core/model/model.cpp" -> "model/metamodel/grids/cellgrid.h"
     "engine/core/model/model.cpp" -> "model/metamodel/object.h"
     "engine/core/model/model.cpp" -> "structures/map.h"
     "engine/core/model/model.cpp" -> "util/base/exception.h"
@@ -626,24 +628,20 @@
     "engine/core/view/renderers/floatingtextrenderer.h" -> "view/rendererbase.h"
     "engine/core/view/renderers/genericrenderer.cpp" -> "genericrenderer.h"
     "engine/core/view/renderers/genericrenderer.cpp" -> "model/metamodel/grids/cellgrid.h"
+    "engine/core/view/renderers/genericrenderer.cpp" -> "model/metamodel/timeprovider.h"
     "engine/core/view/renderers/genericrenderer.cpp" -> "model/structures/instance.h"
     "engine/core/view/renderers/genericrenderer.cpp" -> "model/structures/layer.h"
     "engine/core/view/renderers/genericrenderer.cpp" -> "model/structures/location.h"
     "engine/core/view/renderers/genericrenderer.cpp" -> "util/log/logger.h"
     "engine/core/view/renderers/genericrenderer.cpp" -> "util/math/fife_math.h"
+    "engine/core/view/renderers/genericrenderer.cpp" -> "video/animation.h"
+    "engine/core/view/renderers/genericrenderer.cpp" -> "video/animationpool.h"
+    "engine/core/view/renderers/genericrenderer.cpp" -> "video/fonts/abstractfont.h"
+    "engine/core/view/renderers/genericrenderer.cpp" -> "video/image.h"
+    "engine/core/view/renderers/genericrenderer.cpp" -> "video/imagepool.h"
     "engine/core/view/renderers/genericrenderer.cpp" -> "video/renderbackend.h"
     "engine/core/view/renderers/genericrenderer.cpp" -> "view/camera.h"
     "engine/core/view/renderers/genericrenderer.h" -> "view/rendererbase.h"
-    "engine/core/view/renderers/geometricrenderer.cpp" -> "geometricrenderer.h"
-    "engine/core/view/renderers/geometricrenderer.cpp" -> "model/metamodel/grids/cellgrid.h"
-    "engine/core/view/renderers/geometricrenderer.cpp" -> "model/structures/instance.h"
-    "engine/core/view/renderers/geometricrenderer.cpp" -> "model/structures/layer.h"
-    "engine/core/view/renderers/geometricrenderer.cpp" -> "model/structures/location.h"
-    "engine/core/view/renderers/geometricrenderer.cpp" -> "util/log/logger.h"
-    "engine/core/view/renderers/geometricrenderer.cpp" -> "util/math/fife_math.h"
-    "engine/core/view/renderers/geometricrenderer.cpp" -> "video/renderbackend.h"
-    "engine/core/view/renderers/geometricrenderer.cpp" -> "view/camera.h"
-    "engine/core/view/renderers/geometricrenderer.h" -> "view/rendererbase.h"
     "engine/core/view/renderers/gridrenderer.cpp" -> "gridrenderer.h"
     "engine/core/view/renderers/gridrenderer.cpp" -> "model/metamodel/grids/cellgrid.h"
     "engine/core/view/renderers/gridrenderer.cpp" -> "model/structures/instance.h"
--- a/engine/core/controller/engine.cpp	Fri Jul 11 15:37:16 2008 +0000
+++ b/engine/core/controller/engine.cpp	Fri Jul 11 15:42:54 2008 +0000
@@ -59,12 +59,11 @@
 #include "loaders/native/video_loaders/subimage_loader.h"
 #include "loaders/native/video_loaders/image_loader.h"
 #include "loaders/native/audio_loaders/ogg_loader.h"
-//#include "loaders/fallout/model_loaders/dat1.h"
-//#include "loaders/fallout/model_loaders/dat2.h"
 #include "model/model.h"
 #include "pathfinder/linearpather/linearpather.h"
 #include "pathfinder/routepather/routepather.h"
-
+#include "model/metamodel/grids/hexgrid.h"
+#include "model/metamodel/grids/squaregrid.h"
 #include "view/view.h"
 #include "view/renderers/camerazonerenderer.h"
 #include "view/renderers/quadtreerenderer.h"
@@ -232,6 +231,9 @@
 		FL_LOG(_log, "Adding pathers to model");
 		m_model->adoptPather(new LinearPather());
 		m_model->adoptPather(new RoutePather());
+		FL_LOG(_log, "Adding grid prototypes to model");
+		m_model->adoptCellGrid(new SquareGrid());
+		m_model->adoptCellGrid(new HexGrid());
 
 		FL_LOG(_log, "Creating view");
 		m_view = new View(m_renderbackend, m_imagepool, m_animpool);
--- a/engine/core/model/metamodel/grids/cellgrid.h	Fri Jul 11 15:37:16 2008 +0000
+++ b/engine/core/model/metamodel/grids/cellgrid.h	Fri Jul 11 15:42:54 2008 +0000
@@ -174,6 +174,10 @@
 		 */
 		const double getRotation() const { return m_rotation; }
 
+		/** Returns clone of this cellgrid
+		 */
+		virtual CellGrid* clone() = 0;
+
 	protected:
 		void updateMatrices();
 		bool ptInTriangle(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2, const ExactModelCoordinate& pt3);
--- a/engine/core/model/metamodel/grids/hexgrid.cpp	Fri Jul 11 15:37:16 2008 +0000
+++ b/engine/core/model/metamodel/grids/hexgrid.cpp	Fri Jul 11 15:42:54 2008 +0000
@@ -52,6 +52,10 @@
 		FL_DBG(_log, LMsg("VERTICAL_MULTIP ") << VERTICAL_MULTIP);
 	}
 
+	CellGrid* HexGrid::clone() {
+		return new HexGrid(this);
+	}
+
 	HexGrid::~HexGrid() {
 	}
 
--- a/engine/core/model/metamodel/grids/hexgrid.h	Fri Jul 11 15:37:16 2008 +0000
+++ b/engine/core/model/metamodel/grids/hexgrid.h	Fri Jul 11 15:42:54 2008 +0000
@@ -47,6 +47,8 @@
 		ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord);
 		ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate& map_coord);
 		void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell);
+		CellGrid* clone();
+
 	private:
 		double getXZigzagOffset(double y);
 	};
--- a/engine/core/model/metamodel/grids/squaregrid.cpp	Fri Jul 11 15:37:16 2008 +0000
+++ b/engine/core/model/metamodel/grids/squaregrid.cpp	Fri Jul 11 15:42:54 2008 +0000
@@ -41,6 +41,10 @@
 		CellGrid(allow_diagonals) {
 	}
 
+	CellGrid* SquareGrid::clone() {
+		return new SquareGrid(this);
+	}
+
 	SquareGrid::~SquareGrid() {
 	}
 
--- a/engine/core/model/metamodel/grids/squaregrid.h	Fri Jul 11 15:37:16 2008 +0000
+++ b/engine/core/model/metamodel/grids/squaregrid.h	Fri Jul 11 15:42:54 2008 +0000
@@ -47,6 +47,7 @@
 		ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord);
 		ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate& map_coord);
 		void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell);
+		CellGrid* clone();
 
 	private:
 		bool isAccessibleDiagonal(const ModelCoordinate& curpos, const ModelCoordinate& target);
--- a/engine/core/model/model.cpp	Fri Jul 11 15:37:16 2008 +0000
+++ b/engine/core/model/model.cpp	Fri Jul 11 15:42:54 2008 +0000
@@ -30,6 +30,7 @@
 #include "util/structures/purge.h"
 #include "model/metamodel/abstractpather.h"
 #include "model/metamodel/object.h"
+#include "model/metamodel/grids/cellgrid.h"
 #include "structures/map.h"
 #include "util/base/exception.h"
 
@@ -47,6 +48,8 @@
 		for(std::list<namespace_t>::iterator nspace = m_namespaces.begin(); nspace != m_namespaces.end(); ++nspace)
 			purge(nspace->second);
 		purge(m_pathers);
+		purge(m_created_grids);
+		purge(m_adopted_grids);
 	}
 
 	Map* Model::createMap(const std::string& identifier) {
@@ -74,6 +77,23 @@
 		}
 		return NULL;
 	}
+
+	void Model::adoptCellGrid(CellGrid* grid) {
+		m_adopted_grids.push_back(grid);
+	}
+
+	CellGrid* Model::getCellGrid(const std::string& gridtype) {
+		std::vector<CellGrid*>::const_iterator it = m_adopted_grids.begin();
+		for(; it != m_adopted_grids.end(); ++it) {
+			if ((*it)->getType() == gridtype) {
+				CellGrid* newcg = (*it)->clone();
+				m_created_grids.push_back(newcg);
+				return newcg;
+			}
+		}
+		return NULL;
+	}
+
 	
 	Map* Model::getMap(const std::string& identifier) const {
 		std::list<Map*>::const_iterator it = m_maps.begin();
--- a/engine/core/model/model.h	Fri Jul 11 15:37:16 2008 +0000
+++ b/engine/core/model/model.h	Fri Jul 11 15:42:54 2008 +0000
@@ -114,6 +114,14 @@
 		 */
 		AbstractPather* getPather(const std::string& pathername);
 		
+		/** Adds cellgrid to model. Moves ownership to model
+		 */
+		void adoptCellGrid(CellGrid* grid);
+		
+		/** Returns new copy of cellgrid corresponding given name. If none found, returns NULL
+		 */
+		CellGrid* getCellGrid(const std::string& gridtype);
+		
 		/** Called periodically to update events on model
 		 */
 		void update();
@@ -136,6 +144,8 @@
 		std::list<namespace_t> m_namespaces;
 
 		std::vector<AbstractPather*> m_pathers;
+		std::vector<CellGrid*> m_adopted_grids;
+		std::vector<CellGrid*> m_created_grids;
 		TimeProvider m_timeprovider;
 	};
 
--- a/engine/core/model/model.i	Fri Jul 11 15:37:16 2008 +0000
+++ b/engine/core/model/model.i	Fri Jul 11 15:42:54 2008 +0000
@@ -40,6 +40,7 @@
 		void deleteMaps();
 
 		AbstractPather* getPather(const std::string& pathername);
+		CellGrid* getCellGrid(const std::string& gridtype);
 		
 		void setTimeMultiplier(float multip);
 		double getTimeMultiplier() const;
--- a/engine/core/model/structures/layer.h	Fri Jul 11 15:37:16 2008 +0000
+++ b/engine/core/model/structures/layer.h	Fri Jul 11 15:42:54 2008 +0000
@@ -93,7 +93,7 @@
 		public:
 			/** Constructor
 			 * Layers are created by calling addLayer from map, thus
-			 * this method should really be called only by elevation or test code
+			 * this method should really be called only by map or test code
 			 */
 			Layer(const std::string& identifier, Map* map, CellGrid* grid);
 
--- a/engine/extensions/serializers/xmlmap.py	Fri Jul 11 15:37:16 2008 +0000
+++ b/engine/extensions/serializers/xmlmap.py	Fri Jul 11 15:42:54 2008 +0000
@@ -104,11 +104,8 @@
 			if not grid_type: self._err(''.join(['Layer ', str(id), ' has no grid_type attribute.']))
 
 			allow_diagonals = pathing == "cell_edges_and_diagonals"
-			if grid_type == "square":
-				cellgrid = fife.SquareGrid(allow_diagonals)
-			else:
-				cellgrid = fife.HexGrid(allow_diagonals)
-			cellgrid.thisown = 0
+			cellgrid = self.model.getCellGrid(grid_type)
+			if not cellgrid: self._err('<layer> declared with invalid cellgrid type. (%s)' % grid_type)
 
 			cellgrid.setRotation(float(rotation))
 			cellgrid.setXScale(float(x_scale))