Debian Codegraph @

engine/core/view/renderers/quadtreerenderer.cpp

raw
1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the FIFE team *
3 * http://www.fifengine.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 // Standard C++ library includes
23
24 // 3rd party library includes
25
26 // FIFE includes
27 // These includes are split up in two parts, separated by one empty line
28 // First block: files included from the FIFE root src directory
29 // Second block: files included from the same folder
30 #include "video/renderbackend.h"
31 #include "util/math/fife_math.h"
32 #include "util/log/logger.h"
33 #include "model/metamodel/grids/cellgrid.h"
34 #include "model/structures/instance.h"
35 #include "model/structures/layer.h"
36 #include "model/structures/location.h"
37
38 #include "view/camera.h"
39 #include "quadtreerenderer.h"
40 #include "model/structures/instancetree.h"
41 #include "util/structures/quadtree.h"
42
43 //credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the quadtree after all )
44
45 namespace FIFE {
46 /** Logger to use for this source file.
47 * @relates Logger
48 */
49 static Logger _log(LM_VIEWVIEW);
50
51 QuadTreeRenderer::QuadTreeRenderer(RenderBackend* renderbackend, int32_t position):
52 RendererBase(renderbackend, position) {
53 setEnabled(false);
54 }
55
56 QuadTreeRenderer::QuadTreeRenderer(const QuadTreeRenderer& old):
57 RendererBase(old) {
58 setEnabled(false);
59 }
60
61 RendererBase* QuadTreeRenderer::clone() {
62 return new QuadTreeRenderer(*this);
63 }
64
65 QuadTreeRenderer::~QuadTreeRenderer() { }
66 RenderVisitor::RenderVisitor(RenderBackend * rb, Layer * layer, Camera *camera) {
67
68 m_renderbackend = rb;
69 m_layer = layer;
70 m_camera = camera;
71 }
72
73 RenderVisitor::~RenderVisitor() {}
74
75 template<typename T> bool RenderVisitor::visit(QuadNode<T,InstanceTree::MIN_TREE_SIZE>* node, int32_t d) {
76
77 if (d==0)
78 visited = 0;
79
80 int32_t x = node->x();
81 int32_t y = node->y();
82 int32_t size = node->size();
83
84 ++visited;
85 CellGrid *cg = m_layer->getCellGrid(); ///we have checked for null pointer in quadtreerenderer::render().. no need to check again
86
87
88 ExactModelCoordinate emc= cg->toMapCoordinates(ExactModelCoordinate( x,y) );//0.5 for each cell's half-width
89 ScreenPoint scrpt1 =m_camera->toScreenCoordinates( emc );
90 emc= cg->toMapCoordinates(ExactModelCoordinate( x,y+size) );// this size usage is wrong.. me thinks
91 ScreenPoint scrpt2 =m_camera->toScreenCoordinates( emc );
92 emc= cg->toMapCoordinates(ExactModelCoordinate( x+size,y) );
93 ScreenPoint scrpt3 =m_camera->toScreenCoordinates( emc );
94 emc= cg->toMapCoordinates(ExactModelCoordinate( x+size,y+size) );
95 ScreenPoint scrpt4 =m_camera->toScreenCoordinates( emc );
96
97 m_renderbackend->drawLine(Point(scrpt1.x,scrpt1.y), Point(scrpt2.x,scrpt2.y), 255, 255, 255);
98 m_renderbackend->drawLine(Point(scrpt1.x,scrpt1.y), Point(scrpt3.x,scrpt3.y), 255, 255, 255);
99 m_renderbackend->drawLine(Point(scrpt3.x,scrpt3.y), Point(scrpt4.x,scrpt4.y), 255, 255, 255);
100 m_renderbackend->drawLine(Point(scrpt2.x,scrpt2.y), Point(scrpt4.x,scrpt4.y), 255, 255, 255);
101
102 return true;
103 }
104
105
106 void QuadTreeRenderer::render(Camera* cam, Layer* layer, RenderList& instances) {
107 CellGrid* cg = layer->getCellGrid();
108 if (!cg) {
109 FL_WARN(_log, "No cellgrid assigned to layer, cannot draw grid");
110 return;
111 }
112 InstanceTree * itree = layer->getInstanceTree();
113 RenderVisitor VIPguess(m_renderbackend, layer,cam);
114 itree->applyVisitor(VIPguess);
115 }
116
117 }
118