65 for(std::vector<Instance*>::iterator i = instances.begin();
66 i != instances.end(); ++i) {
100 if ((rotation >= 0) && (rotation <= 60)) {
105 }
else if ((rotation >= 60) && (rotation <= 120)) {
110 }
else if ((rotation >= 120) && (rotation <= 180)) {
115 }
else if ((rotation >= 180) && (rotation <= 240)) {
120 }
else if ((rotation >= 240) && (rotation <= 300)) {
125 }
else if ((rotation >= 300) && (rotation <= 360)) {
136 lpos.
x += lpos.
y / 2;
137 rpos.
x += rpos.
y / 2;
140 int32_t lvc = ceil(xtox*lpos.
x + ytox*lpos.
y) + ceil(xtoy*lpos.
x + ytoy*lpos.
y) + liv->
getStackPosition();
141 int32_t rvc = ceil(xtox*rpos.
x + ytox*rpos.
y) + ceil(xtoy*rpos.
x + ytoy*rpos.
y) + riv->getStackPosition();
146 return lpos.
z < rpos.
z;
168 return lpos.
z < rpos.
z;
186 m_needSorting =
false;
188 m_needSorting =
true;
194 for (std::vector<Entry*>::iterator it = m_entries.begin(); it != m_entries.end(); ++it) {
198 for (std::vector<RenderItem*>::iterator it = m_renderItems.begin(); it != m_renderItems.end(); ++it) {
201 m_layer->removeChangeListener(m_layerObserver);
202 delete m_layerObserver;
207 if (m_layer != layer) {
209 m_layer->removeChangeListener(m_layerObserver);
210 delete m_layerObserver;
221 for (std::vector<Entry*>::iterator it = m_entries.begin(); it != m_entries.end(); ++it) {
226 for (std::vector<RenderItem*>::iterator it = m_renderItems.begin(); it != m_renderItems.end(); ++it) {
229 m_renderItems.clear();
230 m_instance_map.clear();
231 m_entriesToUpdate.clear();
232 m_freeEntries.clear();
233 m_cacheImage.reset();
237 const std::vector<Instance*>& instances = m_layer->getInstances();
238 for(std::vector<Instance*>::const_iterator i = instances.begin();
239 i != instances.end(); ++i) {
245 assert(m_instance_map.find(instance) == m_instance_map.end());
249 if (m_freeEntries.empty()) {
252 m_renderItems.push_back(item);
253 m_instance_map[instance] = m_renderItems.size() - 1;
256 m_entries.push_back(entry);
261 int32_t index = m_freeEntries.front();
262 m_freeEntries.pop_front();
263 item = m_renderItems[index];
264 item->instance = instance;
265 m_instance_map[instance] = index;
267 entry = m_entries[index];
281 assert(m_instance_map.find(instance) != m_instance_map.end());
283 Entry* entry = m_entries[m_instance_map[instance]];
284 assert(entry->instanceIndex == m_instance_map[instance]);
285 RenderItem* item = m_renderItems[entry->instanceIndex];
287 std::set<int32_t>::iterator it = m_entriesToUpdate.find(entry->entryIndex);
288 if (it != m_entriesToUpdate.end()) {
289 m_entriesToUpdate.erase(it);
293 entry->node->data().erase(entry->entryIndex);
296 entry->instanceIndex = -1;
297 entry->forceUpdate =
false;
298 m_instance_map.erase(instance);
301 RenderList& renderList = m_camera->getRenderListRef(m_layer);
302 for (RenderList::iterator it = renderList.begin(); it != renderList.end(); ++it) {
303 if ((*it)->instance == instance) {
304 renderList.erase(it);
311 m_freeEntries.push_back(entry->entryIndex);
315 Entry* entry = m_entries[m_instance_map[instance]];
345 : m_indices(indices), m_viewport(viewport) {
351 if(!m_viewport.intersects(
Rect(node->
x(), node->
y(),node->
size(),node->
size()))) {
354 m_indices.insert(m_indices.end(), node->
data().begin(), node->
data().end());
364 collector.
visit(node);
371 if(!m_layer->areInstancesVisible()) {
373 std::set<int32_t>::const_iterator entry_it = m_entriesToUpdate.begin();
374 for (; entry_it != m_entriesToUpdate.end(); ++entry_it) {
375 Entry* entry = m_entries[*entry_it];
379 m_entriesToUpdate.clear();
385 if (!m_entriesToUpdate.empty()) {
386 std::set<int32_t> entryToRemove;
387 updateEntries(entryToRemove, renderlist);
389 if (!entryToRemove.empty()) {
390 std::set<int32_t>::iterator entry_it = entryToRemove.begin();
391 for (; entry_it != entryToRemove.end(); ++entry_it) {
392 m_entriesToUpdate.erase(*entry_it);
397 m_zoom = m_camera->getZoom();
406 fullUpdate(transform);
408 fullCoordinateUpdate(transform);
412 Rect viewport = m_camera->getViewPort();
413 Rect screenViewport = viewport;
416 viewport.
x =
static_cast<int32_t
>(std::min(viewport_a.
x, viewport_b.
x));
417 viewport.
y =
static_cast<int32_t
>(std::min(viewport_a.
y, viewport_b.
y));
418 viewport.
w =
static_cast<int32_t
>(std::max(viewport_a.
x, viewport_b.
x) - viewport.
x);
419 viewport.
h =
static_cast<int32_t
>(std::max(viewport_a.
y, viewport_b.
y) - viewport.
y);
424 std::vector<int32_t> index_list;
425 collect(viewport, index_list);
427 for (
uint32_t i = 0; i != index_list.size(); ++i) {
428 Entry* entry = m_entries[index_list[i]];
435 renderlist.push_back(item);
440 sortRenderList(renderlist);
443 Rect r = m_camera->getMapViewPort();
444 std::vector<ExactModelCoordinate> coords;
449 for (
uint8_t i = 0; i < 4; ++i) {
450 double z = m_camera->toVirtualScreenCoordinates(coords[i]).z;
451 m_zMin = std::min(z, m_zMin);
452 m_zMax = std::max(z, m_zMax);
455 sortRenderList(renderlist);
462 for (
uint32_t i = 0; i != m_entries.size(); ++i) {
463 Entry* entry = m_entries[i];
478 updatePosition(entry);
485 for (
uint32_t i = 0; i != m_entries.size(); ++i) {
486 Entry* entry = m_entries[i];
490 updatePosition(entry);
498 updateScreenCoordinate(m_renderItems[entry->
instanceIndex], zoomChange);
505 Rect viewport = m_camera->getViewPort();
506 std::set<int32_t>::const_iterator entry_it = m_entriesToUpdate.begin();
507 for (; entry_it != m_entriesToUpdate.end(); ++entry_it) {
508 Entry* entry = m_entries[*entry_it];
512 removes.insert(*entry_it);
517 bool positionUpdate = (entry->
updateInfo & EntryPositionUpdate) == EntryPositionUpdate;
518 if ((entry->
updateInfo & EntryVisualUpdate) == EntryVisualUpdate) {
519 positionUpdate |= updateVisual(entry);
521 if (positionUpdate) {
522 updatePosition(entry);
525 if (onScreenA != onScreenB) {
528 renderlist.push_back(item);
529 needSorting.push_back(item);
532 for (RenderList::iterator it = renderlist.begin(); it != renderlist.end(); ++it) {
533 if ((*it)->instance == item->
instance) {
534 renderlist.erase(it);
539 }
else if (onScreenA && onScreenB && positionUpdate) {
541 needSorting.push_back(item);
547 removes.insert(*entry_it);
553 if (!needSorting.empty()) {
555 sortRenderList(renderlist);
557 sortRenderList(needSorting);
567 int32_t angle =
static_cast<int32_t
>(m_camera->getRotation()) + item->
facingAngle;
572 uint8_t layerTrans = m_layer->getLayerTransparency();
574 if (layerTrans != 0) {
575 if (instanceTrans != 0) {
576 uint8_t calcTrans = layerTrans - instanceTrans;
577 if (calcTrans >= 0) {
578 instanceTrans = calcTrans;
583 instanceTrans = layerTrans;
596 if (image_id == -1) {
612 std::map<int32_t, AnimationPtr>::iterator it = animations.begin();
613 std::vector<ImagePtr>* animOverlays =
new std::vector<ImagePtr>();
614 std::vector<OverlayColors*>* animationColorOverlays = colorOverlay ?
new std::vector<OverlayColors*>() : 0;
615 for (; it != animations.end(); ++it) {
617 image = it->second->getFrameByTimestamp(animationTime);
618 animOverlays->push_back(image);
627 animationColorOverlays->push_back(co);
630 int32_t actionFrame = it->second->getActionFrame();
631 if (actionFrame != -1) {
632 int32_t newFrame = it->second->getFrameIndex(animationTime);
634 if (actionFrame == newFrame) {
637 }
else if (newFrame > actionFrame && item->
currentFrame < actionFrame) {
665 if (actionFrame != -1) {
666 if (item->
image != image) {
668 if (actionFrame == newFrame) {
671 }
else if (newFrame > actionFrame && item->
currentFrame < actionFrame) {
680 bool newPosition =
false;
681 if (image != item->
image) {
682 if (!item->
image || !image) {
699 DoublePoint3D screenPosition = m_camera->toVirtualScreenCoordinates(mapCoords);
705 screenPosition.
x = (screenPosition.
x - w / 2) + image->
getXShift();
706 screenPosition.
y = (screenPosition.
y - h / 2) + image->
getYShift();
714 item->
bbox.
x =
static_cast<int32_t
>(screenPosition.
x);
715 item->
bbox.
y =
static_cast<int32_t
>(screenPosition.
y);
717 updateScreenCoordinate(item);
721 if (node != entry->
node) {
753 if (renderlist.empty()) {
764 if (!m_needSorting && !m_layer->isStatic()) {
766 float det = m_zMin - m_zMax;
767 if (fabs(det) > FLT_EPSILON) {
768 static const float globalrange = 200.0;
769 static const float stackdelta = (FLT_EPSILON * 100.0);
770 int32_t numlayers = m_layer->getLayerCount();
771 float lmin = m_layer->getZOffset();
772 float lmax = lmin + globalrange/numlayers;
773 float a = (lmin - lmax) / det;
774 float b = (lmax * m_zMin - lmin * m_zMax) / det;
776 RenderList::iterator it = renderlist.begin();
777 for ( ; it != renderlist.end(); ++it) {
779 float& z = (*it)->vertexZ;
788 std::stable_sort(renderlist.begin(), renderlist.end(), ids);
792 std::stable_sort(renderlist.begin(), renderlist.end(), ids);
796 std::stable_sort(renderlist.begin(), renderlist.end(), ids);
800 std::stable_sort(renderlist.begin(), renderlist.end(), ids);
811 m_cacheImage = image;
ExactModelCoordinate getExactLayerCoordinates() const
Gets exact layer coordinates set to this location.
virtual ~CacheLayerChangeListener()
void setColorOverlay(OverlayColors *co)
Sets single ColorOverlay.
bool operator()(RenderItem *const &lhs, RenderItem *const &rhs)
void fullUpdate(Camera::Transform transform)
std::vector< RenderItem * > RenderList
void updatePosition(Entry *entry)
void setLayer(Layer *layer)
QuadNode * parent()
Return the parent node.
int32_t getStaticImageIndexByAngle(uint32_t angle, Instance *instance)
Returns closest matching static image for given angle.
int32_t getStackPosition()
Gets current stack position of instance.
T h
Height of the rectangle.
void fullCoordinateUpdate(Camera::Transform transform)
virtual ImagePtr get(const std::string &name)
Gets a shared pointer to the Image.
Instance visual contains data that is needed to visualize the instance on screen. ...
void callOnActionFrame(Action *action, int32_t frame)
Auxiliary function to inform ActionListeners about the active ActionFrame.
void updateScreenCoordinate(RenderItem *item, bool changedZoom=true)
DoublePoint3D screenpoint
Action visual contains data that is needed to visualize different actions on screen.
InstanceChangeInfo getChangeInfo()
Returns a bitmask of changes of the last update.
void deleteOverlayData()
Deletes OverlayData.
static Logger _log(LM_AUDIO)
PointType3D< int32_t > Point3D
DataType & data()
Return a reference to the data of the node.
uint32_t getActionRuntime()
Gets the time in milliseconds how long action has been active In case there is no current action...
bool operator()(RenderItem *const &lhs, RenderItem *const &rhs)
virtual void onInstanceCreate(Layer *layer, Instance *instance)
Called when some instance gets created on layer.
int32_t getYShift() const
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
static RenderBackend * instance()
Location & getLocationRef()
Gets reference of current location of instance.
void apply_visitor(Visitor &visitor, int32_t d=0)
Apply a visitor recursively to the QuadTree A visitor is an object which has a visit method which tak...
void sortRenderList(RenderList &renderlist)
RenderEntryUpdate updateInfo
bool intersects(const RectType< T > &rect) const
Check whether two rectangles share some area.
OverlayColors * getColorOverlay(int32_t angle)
Gets OverlayColors for given angle (degrees).
int32_t getActionFrame() const
Gets the action frame.
bool isVisible()
Is instance visible or not.
bool isStatic() const
Gets if object moves.
Comparison functions for sorting.
void setColorOverlayImage(ImagePtr image)
ImagePtr getFrameByTimestamp(uint32_t timestamp)
Gets the frame image that matches the given timestamp.
uint32_t getHeight() const
static bool Equal(T _val1, T _val2)
Object * getObject()
Gets object where this instance is instantiated from.
uint32_t InstanceChangeInfo
Dynamic QuadTree A space partitioning tree automatically expanding to adjust to any object size put i...
int32_t size() const
Return the size (width and height) of the node.
int32_t getXShift() const
CacheTreeCollector(std::vector< int32_t > &indices, const Rect &viewport)
Listener interface for changes happening on a layer.
int32_t getFrameIndex(uint32_t timestamp)
Get the frame index that matches given timestamp.
void addChangeListener(LayerChangeListener *listener)
Adds new change listener.
void setCacheImage(ImagePtr image)
ExactModelCoordinate & getExactLayerCoordinatesRef()
Gets reference to exact layer coordinates.
void setAnimationOverlay(std::vector< ImagePtr > *ao, std::vector< OverlayColors *> *aco)
Sets AnimationOverlay and if available AnimationOverlayColors.
T right() const
The X coordinate of the right edge.
CacheLayerChangeListener(LayerCache *cache)
double getZoom() const
Gets camera zoom.
virtual void onInstanceDelete(Layer *layer, Instance *instance)
Called when some instance gets deleted on layer.
void collect(const Rect &viewport, std::vector< int32_t > &indices)
std::vector< int32_t > & m_indices
Action * getCurrentAction() const
Gets the currently active action.
virtual void onLayerChanged(Layer *layer, std::vector< Instance *> &instances)
Called when some instance is changed on layer.
DoublePoint3D ExactModelCoordinate
bool visit(LayerCache::CacheTree::Node *node, int32_t d=-1)
Action * getDefaultAction() const
Gets default action assigned to this object.
LayerCache(Camera *camera)
uint8_t getTransparency()
Gets current transparency value (0-255)
bool operator()(RenderItem *const &lhs, RenderItem *const &rhs)
void update(Camera::Transform transform, RenderList &renderlist)
T * getVisual() const
Gets used visualization.
int32_t y() const
Return the Y position of the node.
uint32_t getFrameCount() const
Get the number of frames.
void removeInstance(Instance *instance)
InstanceDistanceSortLocation(double rotation)
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
void updateEntries(std::set< int32_t > &removes, RenderList &renderlist)
AnimationPtr getColorOverlayAnimation()
void addInstance(Instance *instance)
QuadNode * find_container(int32_t x, int32_t y, int32_t w, int32_t h)
Find a container node for a given rectangle.
bool updateVisual(Entry *entry)
uint32_t getDuration() const
Gets the total duration for the whole animation.
T w
Width of the rectangle.
#define FL_DBG(logger, msg)
int32_t getRotation() const
Get the rotation offset of this instance Returns direction where instance is heading.
An Instance is an "instantiation" of an Object at a Location.
std::map< int32_t, AnimationPtr > getAnimationOverlay(int32_t angle)
Gets map with animations closest to given angle.
bool isAnimationOverlay()
Returns true if it exists a animation overlay, otherwise false.
void reset()
Resets the important values.
T bottom() const
The Y coordinate of the bottom edge.
bool isColorOverlay()
Returns true if it exists a color overlay, otherwise false.
uint32_t getWidth() const
void updateInstance(Instance *instance)
int32_t x() const
Return the X position of the node.