FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
renderitem.cpp
Go to the documentation of this file.
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
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 
41  colorOverlay(0),
42  animationOverlayImages(0),
43  animationColorOverlays(0) {
44  }
45 
49  // don't delete colorOverlay here
50  }
51 
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 
66  delete m_overlay;
67  }
68 
70  ObjectVisual* objVis = instance->getObject()->getVisual<ObjectVisual>();
71  if (!objVis) {
73  }
74  if (static_cast<int32_t>(angle) != m_cachedStaticImgAngle) {
76  }
77  if (objVis->isColorOverlay()) {
78  if (!m_overlay) {
79  m_overlay = new OverlayData();
80  }
82  }
83  if (m_cachedStaticImgId != STATIC_IMAGE_NOT_INITIALIZED) {
84  return m_cachedStaticImgId;
85  }
86 
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  }
99  }
100 
101  std::vector<ImagePtr>* RenderItem::getAnimationOverlay() const {
102  if (m_overlay) {
104  }
105  return NULL;
106  }
107 
108  std::vector<OverlayColors*>* RenderItem::getAnimationColorOverlay() const {
109  if (m_overlay) {
111  }
112  return NULL;
113  }
114 
116  if (!m_overlay) {
117  m_overlay = new OverlayData();
118  }
119  m_overlay->colorOverlay = co;
120  }
121 
123  if (m_overlay) {
124  return m_overlay->colorOverlay;
125  }
126  return NULL;
127  }
128 
130  if (m_overlay) {
131  delete m_overlay;
132  m_overlay = 0;
133  }
134  }
135 
137  instance = 0;
138  dimensions = Rect();
139  image.reset();
140  transparency = 255;
141  currentFrame = -1;
144  }
145 }
void setColorOverlay(OverlayColors *co)
Sets single ColorOverlay.
Definition: renderitem.cpp:115
OverlayColors * getColorOverlay() const
Returns pointer to single ColorOverlay.
Definition: renderitem.cpp:122
int32_t getStaticImageIndexByAngle(uint32_t angle, Instance *instance)
Returns closest matching static image for given angle.
Definition: renderitem.cpp:69
void reset(T *ptr=0)
reset this pointer to a null shared pointer this can be used to lower the reference count of the shar...
Definition: sharedptr.h:164
std::vector< ImagePtr > * animationOverlayImages
Definition: renderitem.h:49
RenderItem(Instance *parent)
Definition: renderitem.cpp:52
Instance * instance
Definition: renderitem.h:58
OverlayColors * colorOverlay
Definition: renderitem.h:47
void deleteOverlayData()
Deletes OverlayData.
Definition: renderitem.cpp:129
OverlayColors * getStaticColorOverlay(int32_t angle)
Returns closest matching static color overlay for given angle.
Definition: visual.cpp:139
int32_t getStaticImageIndexByAngle(int32_t angle)
Returns closest matching static image for given angle.
Definition: visual.cpp:117
Object * getObject()
Gets object where this instance is instantiated from.
Definition: instance.cpp:292
bool isColorOverlay()
Indicates if there exists a color overlay.
Definition: visual.h:141
void setAnimationOverlay(std::vector< ImagePtr > *ao, std::vector< OverlayColors *> *aco)
Sets AnimationOverlay and if available AnimationOverlayColors.
Definition: renderitem.cpp:93
int32_t m_cachedStaticImgAngle
Definition: renderitem.h:127
std::vector< OverlayColors * > * getAnimationColorOverlay() const
Returns pointer to AnimationColorOverlay vector.
Definition: renderitem.cpp:108
Object visual contains data that is needed for visualizing objects.
Definition: visual.h:91
ImagePtr image
Definition: renderitem.h:112
std::vector< ImagePtr > * getAnimationOverlay() const
Returns pointer to AnimationOverlay vector.
Definition: renderitem.cpp:101
RectType< int32_t > Rect
Definition: rect.h:258
std::vector< OverlayColors * > * animationColorOverlays
Definition: renderitem.h:51
unsigned int uint32_t
Definition: core.h:40
T * getVisual() const
Gets used visualization.
Definition: object.h:122
int32_t m_cachedStaticImgId
Definition: renderitem.h:126
OverlayData * m_overlay
Definition: renderitem.h:124
uint8_t transparency
Definition: renderitem.h:118
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:94
const int32_t STATIC_IMAGE_NOT_INITIALIZED
Definition: renderitem.cpp:38
void reset()
Resets the important values.
Definition: renderitem.cpp:136
int32_t currentFrame
Definition: renderitem.h:121