<commit_before>// Copyright (C) 2016 <NAME>
// This file is part of the Ouzel engine.

#include <algorithm>
#include "Node.h"
#include "Engine.h"
#include "SceneManager.h"
#include "Layer.h"
#include "Animator.h"
#include "Camera.h"
#include "Utils.h"
#include "MathUtils.h"

namespace ouzel
{
    Node::Node()
    {
        
    }

    Node::~Node()
    {
        
    }
    
    void Node::visit(const Matrix4& parentTransform, bool parentTransformDirty)
    {
        if (_visible)
        {
            if (parentTransformDirty)
            {
                _parentTransform = parentTransform;
                _transformDirty = true;
            }
            
            bool dirty = _transformDirty;
            if (dirty)
            {
                calculateTransform();
            }
            
            lock();
            
            std::stable_sort(_children.begin(), _children.end(), [](const NodePtr& a, const NodePtr& b) {
                return a->getZ() > b->getZ();
            });
            
            auto i = _children.begin();
            NodePtr node;
            
            for (; i != _children.end(); ++i)
            {
                node = *i;
                
                if (!node->_remove)
                {
                    if (node->getZ() < 0.0f)
                    {
                        node->visit(_transform, dirty);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            
            LayerPtr layer = _layer.lock();
            
            // check if _parent is _layer
            bool isRoot = !_parent.owner_before(_layer) && !_layer.owner_before(_parent);
            
            if (layer && (_globalOrder || isRoot) && checkVisibility())
            {
                layer->addToDrawQueue(std::static_pointer_cast<Node>(shared_from_this()));
            }
            
            for (; i != _children.end(); ++i)
            {
                if (!node->_remove)
                {
                    node = *i;
                    node->visit(_transform, dirty);
                }
            }
            
            unlock();
        }
    }
    
    void Node::process()
    {
        lock();
        
        auto i = _children.begin();
        NodePtr node;
        
        for (; i != _children.end(); ++i)
        {
            node = *i;
            
            if (node->getZ() < 0.0f)
            {
                if (!node->isGlobalOrder() && node->isVisible() && node->checkVisibility())
                {
                    node->draw();
                }
            }
            else<commit_msg>Visit children only if child vector is not empty<commit_after>// Copyright (C) 2016 <NAME>
// This file is part of the Ouzel engine.

#include <algorithm>
#include "Node.h"
#include "Engine.h"
#include "SceneManager.h"
#include "Layer.h"
#include "Animator.h"
#include "Camera.h"
#include "Utils.h"
#include "MathUtils.h"

namespace ouzel
{
    Node::Node()
    {
        
    }

    Node::~Node()
    {
        
    }
    
    void Node::visit(const Matrix4& parentTransform, bool parentTransformDirty)
    {
        if (_visible)
        {
            if (parentTransformDirty)
            {
                _parentTransform = parentTransform;
                _transformDirty = true;
            }
            
            bool dirty = _transformDirty;
            if (dirty)
            {
                calculateTransform();
            }
            
            LayerPtr layer = _layer.lock();
            // check if _parent is _layer
            bool isRoot = !_parent.owner_before(_layer) && !_layer.owner_before(_parent);
            
            if (_children.empty())
            {
                if (layer && (_globalOrder || isRoot) && checkVisibility())
                {
                    layer->addToDrawQueue(std::static_pointer_cast<Node>(shared_from_this()));
                }
            }
            else
            {
                lock();
                
                std::stable_sort(_children.begin(), _children.end(), [](const NodePtr& a, const NodePtr& b) {
                    return a->getZ() > b->getZ();
                });
                
                auto i = _children.begin();
                NodePtr node;
                
                for (; i != _children.end(); ++i)
                {
                    node = *i;
                    
                    if (!node->_remove)
                    {
                        if (node->getZ() < 0.0f)
                        {
                            node->visit(_transform, dirty);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                
                if (layer && (_globalOrder || isRoot) && checkVisibility())
                {
                    layer->addToDrawQueue(std::static_pointer_cast<Node>(shared_from_this()));
                }
                
                for (; i != _children.end(); ++i)
                {
                    if (!node->_remove)
                    {
                        node = *i;
                        node->visit(_transform, dirty);
                    }
                }
                
                unlock();
            }
        }
    }
    
    void Node::process()
    {
        lock();
        
        auto i = _children.begin();
        NodePtr node;
        
        for (; i != _children.end(); ++i)
        {
            node = *i;
            
            if (node->getZ() < 0.0f)
            {
                if (!node->isGlobalOrder() && node->isVisible() && node->checkVisibility())
                {
                    node->draw();
                }
            }
            else
{'fraction_non_alphanumeric': 0.11289504816630049, 'fraction_numerical': 0.003042082136217678, 'mean_word_length': 0.915210355987055, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6109120', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1457, 'n_words': 294}