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

#include <algorithm>
#include "Engine.h"
#include "CompileConfig.h"
#include "Cache.h"

#if defined(OUZEL_SUPPORTS_OPENGL) || defined(OUZEL_SUPPORTS_OPENGLES)
#include "RendererOGL.h"
#endif

#if defined(SUPPORTS_DIRECT3D11)
#include "RendererD3D11.h"
#endif

#include "Utils.h"
#include "Renderer.h"
#include "FileSystem.h"

#if defined(OUZEL_PLATFORM_OSX) || defined(OUZEL_PLATFORM_IOS) || defined(OUZEL_PLATFORM_TVOS)
#include "InputApple.h"
#elif defined(OUZEL_PLATFORM_WINDOWS)
#include "InputWin.h"
#endif

ouzel::AppPtr ouzelMain(const std::vector<std::string>& args);

namespace ouzel
{
    static EnginePtr sharedEngine;

    EnginePtr Engine::getInstance()
    {
        if (!sharedEngine)
        {
            sharedEngine.reset(new Engine());
        }

        return sharedEngine;
    }

    Engine::Engine()
    {

    }

    Engine::~Engine()
    {

    }

    void Engine::setArgs(const std::vector<std::string>& args)
    {
        _args = args;
    }

    std::set<Renderer::Driver> Engine::getAvailableDrivers() const
    {
        std::set<Renderer::Driver> availableDrivers;

#if defined(OUZEL_SUPPORTS_OPENGL) || defined(OUZEL_SUPPORTS_OPENGLES)
        availableDrivers.insert(Renderer::Driver::OPENGL);
#elif defined(SUPPORTS_DIRECT3D11)
        availableDrivers.insert(Renderer::Driver::DIRECT3D11);
#endif

        return availableDrivers;
    }

    bool Engine::init()
    {
        _app = ouzelMain(_args);

        if (!_app)
        {
            return false;
        }

        Settings settings = _app->getSettings();
        _targetFPS = settings.targetFPS;

#if defined(OUZEL_PLATFORM_OSX) || defined(OUZEL_PLATFORM_IOS) || defined(OUZEL_PLATFORM_TVOS)
        settings.driver = Renderer::Driver::OPENGL;
#elif defined(SUPPORTS_DIRECT3D11)
        settings.driver = Renderer::Driver::DIRECT3D11;
#endif

        _eventDispatcher.reset(new EventDispatcher());
        _cache.reset(new Cache());
        _fileSystem.reset(new FileSystem());
        _sceneManager.reset(new SceneManager());

#if defined(OUZEL_PLATFORM_OSX) || defined(OUZEL_PLATFORM_IOS) || defined(OUZEL_PLATFORM_TVOS)
        _input.reset(new InputApple());
#elif defined(OUZEL_PLATFORM_WINDOWS)
        _input.reset(new InputWin());
#else
        _input.reset(new Input());
#endif

        switch (settings.driver)
        {
#if defined(OUZEL_SUPPORTS_OPENGL) || defined(OUZEL_SUPPORTS_OPENGLES)
            case Renderer::Driver::OPENGL:
                _renderer.reset(new RendererOGL());
				break;
#endif
#if defined(SUPPORTS_DIRECT3D11)
            case Renderer::Driver::DIRECT3D11:
                _renderer.reset(new RendererD3D11());
                break;
#endif
            default:
                _renderer.reset(new Renderer());
                break;
        }

        if (!_renderer->init(settings.size, settings.resizable, settings.fullscreen, settings.driver))
        {
            return false;
        }

        _previousFrameTime = getCurrentMicroSeconds();

        return true;
    }

    void Engine::exit()
    {
        _active = false;
    }

    void Engine::begin()
    {
        _app->begin();
    }

    void Engine::end()
    {
        _app.reset();
        // remove the active scene
        _sceneManager->setScene(ScenePtr());
        _cache.reset();
    }

    bool Engine::run()
    {
        uint64_t currentTime = getCurrentMicroSeconds();
        float delta = static_cast<float>((currentTime - _previousFrameTime)) / 1000000.0f;
        _previousFrameTime = currentTime;

        _currentFPS = 1.0f / delta;

        _input->update();
        _eventDispatcher->update();

        lock();
        for (const UpdateCallbackPtr& updateCallback : _updateCallbacks)
        {
            if (!updateCallback->_remove)
            {
                updateCallback->callback(delta);
            }
        }
        unlock();

        _renderer->clear();
        _sceneManager->draw();
        _renderer->present();

        return _active;
    }

    void Engine::scheduleUpdate(const UpdateCallbackPtr& callback)
    {
        if (_locked)
        {
            _updateCallbackAddList.insert(callback);
        }
        else<commit_msg>Call update only if update callback is set<commit_after>// Copyright (C) 2016 <NAME>
// This file is part of the Ouzel engine.

#include <algorithm>
#include "Engine.h"
#include "CompileConfig.h"
#include "Cache.h"

#if defined(OUZEL_SUPPORTS_OPENGL) || defined(OUZEL_SUPPORTS_OPENGLES)
#include "RendererOGL.h"
#endif

#if defined(SUPPORTS_DIRECT3D11)
#include "RendererD3D11.h"
#endif

#include "Utils.h"
#include "Renderer.h"
#include "FileSystem.h"

#if defined(OUZEL_PLATFORM_OSX) || defined(OUZEL_PLATFORM_IOS) || defined(OUZEL_PLATFORM_TVOS)
#include "InputApple.h"
#elif defined(OUZEL_PLATFORM_WINDOWS)
#include "InputWin.h"
#endif

ouzel::AppPtr ouzelMain(const std::vector<std::string>& args);

namespace ouzel
{
    static EnginePtr sharedEngine;

    EnginePtr Engine::getInstance()
    {
        if (!sharedEngine)
        {
            sharedEngine.reset(new Engine());
        }

        return sharedEngine;
    }

    Engine::Engine()
    {

    }

    Engine::~Engine()
    {

    }

    void Engine::setArgs(const std::vector<std::string>& args)
    {
        _args = args;
    }

    std::set<Renderer::Driver> Engine::getAvailableDrivers() const
    {
        std::set<Renderer::Driver> availableDrivers;

#if defined(OUZEL_SUPPORTS_OPENGL) || defined(OUZEL_SUPPORTS_OPENGLES)
        availableDrivers.insert(Renderer::Driver::OPENGL);
#elif defined(SUPPORTS_DIRECT3D11)
        availableDrivers.insert(Renderer::Driver::DIRECT3D11);
#endif

        return availableDrivers;
    }

    bool Engine::init()
    {
        _app = ouzelMain(_args);

        if (!_app)
        {
            return false;
        }

        Settings settings = _app->getSettings();
        _targetFPS = settings.targetFPS;

#if defined(OUZEL_PLATFORM_OSX) || defined(OUZEL_PLATFORM_IOS) || defined(OUZEL_PLATFORM_TVOS)
        settings.driver = Renderer::Driver::OPENGL;
#elif defined(SUPPORTS_DIRECT3D11)
        settings.driver = Renderer::Driver::DIRECT3D11;
#endif

        _eventDispatcher.reset(new EventDispatcher());
        _cache.reset(new Cache());
        _fileSystem.reset(new FileSystem());
        _sceneManager.reset(new SceneManager());

#if defined(OUZEL_PLATFORM_OSX) || defined(OUZEL_PLATFORM_IOS) || defined(OUZEL_PLATFORM_TVOS)
        _input.reset(new InputApple());
#elif defined(OUZEL_PLATFORM_WINDOWS)
        _input.reset(new InputWin());
#else
        _input.reset(new Input());
#endif

        switch (settings.driver)
        {
#if defined(OUZEL_SUPPORTS_OPENGL) || defined(OUZEL_SUPPORTS_OPENGLES)
            case Renderer::Driver::OPENGL:
                _renderer.reset(new RendererOGL());
				break;
#endif
#if defined(SUPPORTS_DIRECT3D11)
            case Renderer::Driver::DIRECT3D11:
                _renderer.reset(new RendererD3D11());
                break;
#endif
            default:
                _renderer.reset(new Renderer());
                break;
        }

        if (!_renderer->init(settings.size, settings.resizable, settings.fullscreen, settings.driver))
        {
            return false;
        }

        _previousFrameTime = getCurrentMicroSeconds();

        return true;
    }

    void Engine::exit()
    {
        _active = false;
    }

    void Engine::begin()
    {
        _app->begin();
    }

    void Engine::end()
    {
        _app.reset();
        // remove the active scene
        _sceneManager->setScene(ScenePtr());
        _cache.reset();
    }

    bool Engine::run()
    {
        uint64_t currentTime = getCurrentMicroSeconds();
        float delta = static_cast<float>((currentTime - _previousFrameTime)) / 1000000.0f;
        _previousFrameTime = currentTime;

        _currentFPS = 1.0f / delta;

        _input->update();
        _eventDispatcher->update();

        lock();
        for (const UpdateCallbackPtr& updateCallback : _updateCallbacks)
        {
            if (!updateCallback->_remove && updateCallback->callback)
            {
                updateCallback->callback(delta);
            }
        }
        unlock();

        _renderer->clear();
        _sceneManager->draw();
        _renderer->present();

        return _active;
    }

    void Engine::scheduleUpdate(const UpdateCallbackPtr& callback)
    {
        if (_locked)
        {
            _updateCallbackAddList.insert(callback);
        }
        else
{'fraction_non_alphanumeric': 0.11803049703177744, 'fraction_numerical': 0.010010476079618205, 'mean_word_length': 2.59648388447049, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 40, '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': '1628212', 'n_tokens_mistral': 2801, 'n_tokens_neox': 2682, 'n_words': 457}