Adjusted workflow.
All checks were successful
Build & Release / Windows-AMD64-Build (push) Successful in 1m8s
Build & Release / Linux-AMD64-Build (push) Successful in 1m30s
Build & Release / Linux-AARCH64-Build (push) Successful in 3m21s

This commit is contained in:
2024-02-05 22:25:30 -08:00
commit bcd71cf2b5
251 changed files with 45909 additions and 0 deletions

160
src/io/hid/Input.cpp Normal file
View File

@@ -0,0 +1,160 @@
#include "ehs/io/hid/Input.h"
namespace ehs
{
Input::~Input()
{
for (UInt_64 i = 0; i < handlers.Size(); i++)
delete handlers[i];
}
Input::Input()
: initalized(false)
{
}
Input::Input(Input&& input) noexcept
: handlers((Array<InputHandler*>&&)input.handlers), initalized(input.initalized)
{
input.initalized = false;
}
Input::Input(const Input& input)
: initalized(false)
{
}
Input& Input::operator=(Input&& input) noexcept
{
if (this == &input)
return *this;
handlers = (Array<InputHandler*>&&)input.handlers;
initalized = input.initalized;
input.initalized = false;
return *this;
}
Input& Input::operator=(const Input& input)
{
if (this == &input)
return *this;
for (UInt_64 i = 0; i < handlers.Size(); i++)
delete handlers;
handlers = Array<InputHandler*>();
initalized = false;
return *this;
}
void Input::Initialize()
{
if (initalized)
return;
UInt_64 i = 0;
while (i < handlers.Size())
{
if (!handlers[i]->Initialize())
{
if (i != handlers.Size() - 1)
handlers.Swap(i, handlers.End());
delete handlers.Pop();
continue;
}
i++;
}
initalized = true;
}
void Input::Release()
{
if (!initalized)
return;
UInt_64 i = 0;
while (i < handlers.Size())
{
if (!handlers[i]->Release())
{
if (i != handlers.Size() - 1)
handlers.Swap(i, handlers.End());
delete handlers.Pop();
continue;
}
i++;
}
initalized = false;
}
void Input::Poll()
{
for (UInt_64 i = 0; i < handlers.Size(); i++)
handlers[i]->Poll();
}
bool Input::HasHandler(const UInt_64 hashId) const
{
for (UInt_64 i = 0; i < handlers.Size(); i++)
if (*handlers[i] == hashId)
return true;
return false;
}
bool Input::HasHandler(const Str_8& id) const
{
return HasHandler(id.Hash_64());
}
bool Input::AddHandler(InputHandler* handler)
{
if (HasHandler(handler->GetHashId()))
return false;
if (initalized)
{
bool hInitialized = handler->Initialize();
if (!hInitialized)
{
delete handler;
return false;
}
}
handlers.Push(handler);
return true;
}
const InputHandler* Input::GetHandler(const UInt_64 hashId) const
{
for (UInt_64 i = 0; i < handlers.Size(); i++)
if (*handlers[i] == hashId)
return handlers[i];
return nullptr;
}
const InputHandler* Input::GetHandler(const Str_8& id) const
{
return GetHandler(id.Hash_64());
}
bool Input::IsInitialized() const
{
return initalized;
}
}