<commit_before>#include "InputManager.h"
#include "Logging.h"

namespace ECSE
{

InputManager::InputManager()
{
}

void InputManager::update()
{
    sf::Vector2i newMousePosition;
    if (monkeyMode)
    {
        newMousePosition = sf::Vector2i(rand(), rand());
    }
    else if (window != nullptr && !(demoMouse && playingDemo))
    {
        newMousePosition = sf::Mouse::getPosition(*window);
    }

    if (playingDemo)
    {
        for (auto& modePair : demoSources)
        {
            for (auto& bindingPair : modePair.second)
            {
                auto& source = bindingPair.second;

                source->updatePrevInternalValue();
            }
        }

        // Time to read the next change frame
        if (nextChangeFrame < demoFrames || nextChangeFrame == 0)
        {
            uint8_t delta;
            demoIn->read(reinterpret_cast<char*>(&delta), sizeof(delta));

            // Full time will be specified
            if (delta == maxDelta)
            {
                demoIn->read(reinterpret_cast<char*>(&nextChangeFrame), sizeof(nextChangeFrame));
            }
            else
            {
                nextChangeFrame = demoFrames + delta;
            }
        }
        
        if (nextChangeFrame == demoFrames)
        {
            readDemoChanges();

            if (demoIn->peek() == EOF)
            {
                stopDemo();
            }
        }
    }
    else
    {
        auto changes = std::set<std::pair<uint8_t, uint8_t>>();

        for (auto& modePair : bindings)
        {
            for (auto& bindingPair : modePair.second)
            {
                auto& source = bindingPair.second;
                source->updatePrevInternalValue();

                if (monkeyMode)
                {
                    source->setInternalValue(rand());
                }
                else
                {
                    source->updateInternalValue();
                }

                if (source->getInternalValue() != source->getPrevInternalValue() || demoFrames == 0)
                {
                    changes.insert(std::pair<uint8_t, uint8_t>(modePair.first, bindingPair.first));
                }
            }
        }

        // Write out recording data
        if (recording &&
            (!changes.empty() ||
            prevInputMode != inputMode ||
            (newMousePosition != mousePosition && demoMouse)))
        {
            writeDemoChanges(changes);
        }
    }

    if (playingDemo || recording)
    {
        ++demoFrames;
    }

    prevInputMode = inputMode;
}

void InputManager::bindInput(uint8_t bindingId, uint8_t mode, sf::Keyboard::Key key)
{
    std::function<bool()> poll = [key]() { return sf::Keyboard::isKeyPressed(key); };
    bindInput(bindingId, mode, poll);
}
<commit_msg>Actually update mouse position.<commit_after>#include "InputManager.h"
#include "Logging.h"

namespace ECSE
{

InputManager::InputManager()
{
}

void InputManager::update()
{
    sf::Vector2i newMousePosition;
    if (monkeyMode)
    {
        newMousePosition = sf::Vector2i(rand(), rand());
    }
    else if (window != nullptr && !(demoMouse && playingDemo))
    {
        newMousePosition = sf::Mouse::getPosition(*window);
    }

    if (playingDemo)
    {
        for (auto& modePair : demoSources)
        {
            for (auto& bindingPair : modePair.second)
            {
                auto& source = bindingPair.second;

                source->updatePrevInternalValue();
            }
        }

        // Time to read the next change frame
        if (nextChangeFrame < demoFrames || nextChangeFrame == 0)
        {
            uint8_t delta;
            demoIn->read(reinterpret_cast<char*>(&delta), sizeof(delta));

            // Full time will be specified
            if (delta == maxDelta)
            {
                demoIn->read(reinterpret_cast<char*>(&nextChangeFrame), sizeof(nextChangeFrame));
            }
            else
            {
                nextChangeFrame = demoFrames + delta;
            }
        }
        
        if (nextChangeFrame == demoFrames)
        {
            readDemoChanges();

            if (demoIn->peek() == EOF)
            {
                stopDemo();
            }
        }
    }
    else
    {
        auto changes = std::set<std::pair<uint8_t, uint8_t>>();

        for (auto& modePair : bindings)
        {
            for (auto& bindingPair : modePair.second)
            {
                auto& source = bindingPair.second;
                source->updatePrevInternalValue();

                if (monkeyMode)
                {
                    source->setInternalValue(rand());
                }
                else
                {
                    source->updateInternalValue();
                }

                if (source->getInternalValue() != source->getPrevInternalValue() || demoFrames == 0)
                {
                    changes.insert(std::pair<uint8_t, uint8_t>(modePair.first, bindingPair.first));
                }
            }
        }

        // Write out recording data
        if (recording &&
            (!changes.empty() ||
            prevInputMode != inputMode ||
            (newMousePosition != mousePosition && demoMouse)))
        {
            writeDemoChanges(changes);
        }
        mousePosition = newMousePosition;
    }

    if (playingDemo || recording)
    {
        ++demoFrames;
    }

    prevInputMode = inputMode;
}

void InputManager::bindInput(uint8_t bindingId, uint8_t mode, sf::Keyboard::Key key)
{
    std::function<bool()> poll = [key]() { return sf::Keyboard::isKeyPressed(key); };
    bindInput(bindingId, mode, poll);
}

{'fraction_non_alphanumeric': 0.11672535211267605, 'fraction_numerical': 0.0038732394366197184, 'mean_word_length': 1.5521114106019767, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 33, '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': '6113110', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1496, 'n_words': 285}