Debian Codegraph @

engine/core/view/renderitem.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 "model/structures/instance.h"
31 #include "model/metamodel/object.h"
32 #include "model/metamodel/action.h"
33
34 #include "visual.h"
35 #include "renderitem.h"
36
37 namespace FIFE {
38 const int32_t STATIC_IMAGE_NOT_INITIALIZED = -1;
39
40 OverlayData::OverlayData():
41 colorOverlay(0),
42 animationOverlayImages(0),
43 animationColorOverlays(0) {
44 }
45
46 OverlayData::~OverlayData() {
47 delete animationOverlayImages;
48 delete animationColorOverlays;
49 // don't delete colorOverlay here
50 }
51
52 RenderItem::RenderItem(Instance* parent):
53 instance(parent),
54 screenpoint(),
55 dimensions(),
56 vertexZ(0),
57 facingAngle(0),
58 transparency(255),
59 currentFrame(-1),
60 m_overlay(0),
61 m_cachedStaticImgId(STATIC_IMAGE_NOT_INITIALIZED),
62 m_cachedStaticImgAngle(0) {
63 }
64
65 RenderItem::~RenderItem() {
66 delete m_overlay;
67 }
68
69 int32_t RenderItem::getStaticImageIndexByAngle(uint32_t angle, Instance* instance) {
70 ObjectVisual* objVis = instance->getObject()->getVisual<ObjectVisual>();
71 if (!objVis) {
72 return STATIC_IMAGE_NOT_INITIALIZED;
73 }
74 if (static_cast<int32_t>(angle) != m_cachedStaticImgAngle) {
75 m_cachedStaticImgId = STATIC_IMAGE_NOT_INITIALIZED;
76 }
77 if (objVis->isColorOverlay()) {
78 if (!m_overlay) {
79 m_overlay = new OverlayData();
80 }
81 m_overlay->colorOverlay = objVis->getStaticColorOverlay(angle);
82 }
83 if (m_cachedStaticImgId != STATIC_IMAGE_NOT_INITIALIZED) {
84 return m_cachedStaticImgId;
85 }
86
87 m_cachedStaticImgId = objVis->getStaticImageIndexByAngle(angle);
88 m_cachedStaticImgAngle = angle;
89
90 return m_cachedStaticImgId;
91 }
92
93 void RenderItem::setAnimationOverlay(std::vector<ImagePtr>* ao, std::vector<OverlayColors*>* aco) {
94 if (!m_overlay) {
95 m_overlay = new OverlayData();
96 }
97 m_overlay->animationOverlayImages = ao;
98 m_overlay->animationColorOverlays = aco;
99 }
100
101 std::vector<ImagePtr>* RenderItem::getAnimationOverlay() const {
102 if (m_overlay) {
103 return m_overlay->animationOverlayImages;
104 }
105 return NULL;
106 }
107
108 std::vector<OverlayColors*>* RenderItem::getAnimationColorOverlay() const {
109 if (m_overlay) {
110 return m_overlay->animationColorOverlays;
111 }
112 return NULL;
113 }
114
115 void RenderItem::setColorOverlay(OverlayColors* co) {
116 if (!m_overlay) {
117 m_overlay = new OverlayData();
118 }
119 m_overlay->colorOverlay = co;
120 }
121
122 OverlayColors* RenderItem::getColorOverlay() const {
123 if (m_overlay) {
124 return m_overlay->colorOverlay;
125 }
126 return NULL;
127 }
128
129 void RenderItem::deleteOverlayData() {
130 if (m_overlay) {
131 delete m_overlay;
132 m_overlay = 0;
133 }
134 }
135
136 void RenderItem::reset() {
137 instance = 0;
138 dimensions = Rect();
139 image.reset();
140 transparency = 255;
141 currentFrame = -1;
142 m_cachedStaticImgId = STATIC_IMAGE_NOT_INITIALIZED;
143 deleteOverlayData();
144 }
145 }