Mercurial > fife-parpg
annotate engine/core/view/renderers/geometricrenderer.cpp @ 23:e5e2fec68834
add generic renderer
author | spq@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 11 Jul 2008 10:42:31 +0000 |
parents | ae46cee19e76 |
children |
rev | line source |
---|---|
17
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 /*************************************************************************** |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 * Copyright (C) 2005-2008 by the FIFE team * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 * http://www.fifengine.de * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 * This file is part of FIFE. * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 * * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 * FIFE is free software; you can redistribute it and/or modify * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 * (at your option) any later version. * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 * * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 * GNU General Public License for more details. * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 * * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 * along with this program; if not, write to the * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 * Free Software Foundation, Inc., * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 ***************************************************************************/ |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 // Standard C++ library includes |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 // 3rd party library includes |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 // FIFE includes |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 // These includes are split up in two parts, separated by one empty line |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 // First block: files included from the FIFE root src directory |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 // Second block: files included from the same folder |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 #include "video/renderbackend.h" |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 #include "util/math/fife_math.h" |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 #include "util/log/logger.h" |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 #include "model/metamodel/grids/cellgrid.h" |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 #include "model/structures/instance.h" |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 #include "model/structures/layer.h" |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 #include "model/structures/location.h" |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 #include "view/camera.h" |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 #include "geometricrenderer.h" |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 namespace FIFE { |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 static Logger _log(LM_VIEWVIEW); |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 GeometricRenderer::LineInfo::LineInfo(Point p1, Point p2, int r, int g, int b): |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 p1(p1), |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 p2(p2), |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 r(r), |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 g(g), |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 b(b) { |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 } |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 GeometricRenderer* GeometricRenderer::getInstance(IRendererContainer* cnt) { |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 return dynamic_cast<GeometricRenderer*>(cnt->getRenderer("GeometricRenderer")); |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 } |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 GeometricRenderer::GeometricRenderer(RenderBackend* renderbackend, int position): |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 RendererBase(renderbackend, position), |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 m_lines() { |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 setEnabled(false); |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 } |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 GeometricRenderer::GeometricRenderer(const GeometricRenderer& old): |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 RendererBase(old) { |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 setEnabled(false); |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 } |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 RendererBase* GeometricRenderer::clone() { |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 return new GeometricRenderer(*this); |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 } |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 GeometricRenderer::~GeometricRenderer() { |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 } |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 void GeometricRenderer::addLine(Point p1, Point p2, int r, int g, int b) { |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 LineInfo info(p1, p2, r, g, b); |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 m_lines.push_back(info); |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 } |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 void GeometricRenderer::removeAllLines() { |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 m_lines.clear(); |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 } |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 void GeometricRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) { |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 std::vector<LineInfo>::const_iterator lineinfo_it = m_lines.begin(); |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 for (;lineinfo_it != m_lines.end(); ++lineinfo_it) { |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 LineInfo info = *lineinfo_it; |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 m_renderbackend->drawLine(info.p1, info.p2, info.r, info.g, info.b); |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 } |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 } |
ae46cee19e76
- add geometric renderer, can currently only draw liens.
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 } |