#include "input.hpp"
#include <psp2/kernel/processmgr.h>

Input::Input()
{
    sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);
}

void Input::Update() noexcept
{
    this->oldTime = this->currentTime;
    this->currentTime = sceKernelGetProcessTimeWide();

    this->deltaTime = (float)(this->currentTime - this->oldTime) / 1000000.0f;

    SceCtrlData ctrl;
    sceCtrlPeekBufferPositive(0, &ctrl, 1);

    this->oldState = this->currentState;
    this->currentState = ctrl.buttons;
}

bool Input::IsButtonPressed(const uint32_t button) const noexcept
{
    return this->currentState & button;
}

bool Input::IsButtonJustPressed(const uint32_t button) const noexcept
{
    return this->currentState & button && !(this->oldState & button);
}

bool Input::IsButtonReleased(const uint32_t button) const noexcept
{
    return !(this->currentState & button);
}
