Mercurial > fife-parpg
changeset 17:ae46cee19e76
- add geometric renderer, can currently only draw liens.
- thanks to l4rs for some help
author | spq@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 07 Jul 2008 00:27:59 +0000 |
parents | ca21a01f5b1e |
children | 40a7c9618ade |
files | engine/core/controller/engine.cpp engine/core/view/renderers/geometricrenderer.cpp engine/core/view/renderers/geometricrenderer.h engine/core/view/renderers/geometricrenderer.i |
diffstat | 4 files changed, 196 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/core/controller/engine.cpp Mon Jul 07 00:10:02 2008 +0000 +++ b/engine/core/controller/engine.cpp Mon Jul 07 00:27:59 2008 +0000 @@ -74,6 +74,7 @@ #include "view/renderers/floatingtextrenderer.h" #include "view/renderers/cellselectionrenderer.h" #include "view/renderers/blockinginforenderer.h" +#include "view/renderers/geometricrenderer.h" #include "engine.h" #ifdef USE_COCOA @@ -243,6 +244,7 @@ m_view->addRenderer(new FloatingTextRenderer(m_renderbackend, 50, dynamic_cast<AbstractFont*>(m_defaultfont))); m_view->addRenderer(new QuadTreeRenderer(m_renderbackend, 60)); m_view->addRenderer(new CoordinateRenderer(m_renderbackend, 70, dynamic_cast<AbstractFont*>(m_defaultfont))); + m_view->addRenderer(new GeometricRenderer(m_renderbackend, 80)); m_cursor = new Cursor(m_imagepool, m_animpool, m_renderbackend); FL_LOG(_log, "Engine intialized"); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/engine/core/view/renderers/geometricrenderer.cpp Mon Jul 07 00:27:59 2008 +0000 @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (C) 2005-2008 by the FIFE team * + * http://www.fifengine.de * + * This file is part of FIFE. * + * * + * FIFE 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +// Standard C++ library includes + +// 3rd party library includes + +// FIFE includes +// These includes are split up in two parts, separated by one empty line +// First block: files included from the FIFE root src directory +// Second block: files included from the same folder +#include "video/renderbackend.h" +#include "util/math/fife_math.h" +#include "util/log/logger.h" +#include "model/metamodel/grids/cellgrid.h" +#include "model/structures/instance.h" +#include "model/structures/layer.h" +#include "model/structures/location.h" + +#include "view/camera.h" +#include "geometricrenderer.h" + + +namespace FIFE { + static Logger _log(LM_VIEWVIEW); + GeometricRenderer::LineInfo::LineInfo(Point p1, Point p2, int r, int g, int b): + p1(p1), + p2(p2), + r(r), + g(g), + b(b) { + } + + GeometricRenderer* GeometricRenderer::getInstance(IRendererContainer* cnt) { + return dynamic_cast<GeometricRenderer*>(cnt->getRenderer("GeometricRenderer")); + } + + GeometricRenderer::GeometricRenderer(RenderBackend* renderbackend, int position): + RendererBase(renderbackend, position), + m_lines() { + setEnabled(false); + } + + GeometricRenderer::GeometricRenderer(const GeometricRenderer& old): + RendererBase(old) { + setEnabled(false); + } + + RendererBase* GeometricRenderer::clone() { + return new GeometricRenderer(*this); + } + + GeometricRenderer::~GeometricRenderer() { + } + + void GeometricRenderer::addLine(Point p1, Point p2, int r, int g, int b) { + LineInfo info(p1, p2, r, g, b); + m_lines.push_back(info); + } + + void GeometricRenderer::removeAllLines() { + m_lines.clear(); + } + + void GeometricRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) { + std::vector<LineInfo>::const_iterator lineinfo_it = m_lines.begin(); + for (;lineinfo_it != m_lines.end(); ++lineinfo_it) { + LineInfo info = *lineinfo_it; + m_renderbackend->drawLine(info.p1, info.p2, info.r, info.g, info.b); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/engine/core/view/renderers/geometricrenderer.h Mon Jul 07 00:27:59 2008 +0000 @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (C) 2005-2008 by the FIFE Team * + * http://www.fifengine.de * + * This file is part of FIFE. * + * * + * FIFE 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef FIFE_GEOMETRICRENDERER_H +#define FIFE_GEOMETRICRENDERER_H + +// Standard C++ library includes + +// 3rd party library includes + +// FIFE includes +// These includes are split up in two parts, separated by one empty line +// First block: files included from the FIFE root src directory +// Second block: files included from the same folder +#include "view/rendererbase.h" + +namespace FIFE { + class RenderBackend; + class AbstractFont; + + class GeometricRenderer: public RendererBase { + public: + /** constructor. + * @param renderbackend to use + * @param position position for this renderer in rendering pipeline + */ + GeometricRenderer(RenderBackend* renderbackend, int position); + + GeometricRenderer(const GeometricRenderer& old); + + RendererBase* clone(); + + /** Destructor. + */ + virtual ~GeometricRenderer(); + void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances); + std::string getName() { return "GeometricRenderer"; } + + /** Adds a line to be drawed + */ + void addLine(Point p1, Point p2, int r, int g, int b); + + /** Removes all lines + */ + void removeAllLines(); + + /** Gets instance for interface access + */ + static GeometricRenderer* getInstance(IRendererContainer* cnt); + + private: + // contains per-instance information for overlay drawing + class LineInfo { + public: + Point p1; + Point p2; + uint8_t r; + uint8_t g; + uint8_t b; + LineInfo(Point p1, Point p2, int r, int g, int b); + }; + std::vector<LineInfo> m_lines; + }; + +} + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/engine/core/view/renderers/geometricrenderer.i Mon Jul 07 00:27:59 2008 +0000 @@ -0,0 +1,19 @@ +%module fife +%{ +#include "view/renderers/geometricrenderer.h" +%} + +namespace FIFE { + class RenderBackend; + + class GeometricRenderer: public RendererBase { + public: + virtual ~GeometricRenderer(); + std::string getName(); + void addLine(Point p1, Point p2, int r, int g, int b); + void removeAllLines(); + static GeometricRenderer* getInstance(IRendererContainer* cnt); + private: + GeometricRenderer(RenderBackend* renderbackend, int position); + }; +}