From 0360a8bfa145c4773755ff2ba3a4cc36d825d86b Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Sat, 1 Oct 2022 14:34:30 +0800 Subject: [PATCH] made the Input Manager NOT be a System anymore --- .../src/Application/SBApplication.cpp | 5 +- .../src/Graphics/Windowing/SHWindow.cpp | 7 +- ...utManagerSystem.cpp => SHInputManager.cpp} | 80 +++++++------------ ...HInputManagerSystem.h => SHInputManager.h} | 33 +++----- 4 files changed, 42 insertions(+), 83 deletions(-) rename SHADE_Engine/src/Input/{SHInputManagerSystem.cpp => SHInputManager.cpp} (60%) rename SHADE_Engine/src/Input/{SHInputManagerSystem.h => SHInputManager.h} (93%) diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 3e9b0dce..700b36e3 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -23,7 +23,7 @@ #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Scene/SHSceneManager.h" #include "Math/Transform/SHTransformSystem.h" -#include "Input/SHInputManagerSystem.h" +#include "Input/SHInputManager.h" #include "FRC/SHFramerateController.h" //#include "AudioSystem/SHAudioSystem.h" @@ -58,7 +58,6 @@ namespace Sandbox // TODO(Diren): Create Physics System here SHADE::SHSystemManager::CreateSystem(); SHADE::SHGraphicsSystem* graphicsSystem = static_cast(SHADE::SHSystemManager::GetSystem()); - SHADE::SHSystemManager::CreateSystem(); //SHADE::SHSystemManager::CreateSystem(); // Create Routines @@ -80,8 +79,6 @@ namespace Sandbox SHADE::SHComponentManager::CreateComponentSparseSet(); SHADE::SHComponentManager::CreateComponentSparseSet(); - SHADE::SHSystemManager::RegisterRoutine(); - //TODO: REMOVE AFTER PRESENTATION SHADE::SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf"); SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonBag_Color_Ver4.dds"); diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp index 4d8dae72..3a1deb00 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp @@ -2,7 +2,7 @@ #include "SHWindowMap.h" #include "SHWindow.h" #include "ECS_Base/Managers/SHSystemManager.h" -#include "Input/SHInputManagerSystem.h" +#include "Input/SHInputManager.h" namespace SHADE @@ -343,10 +343,7 @@ namespace SHADE } case WM_MOUSEWHEEL: { - if (auto im = SHSystemManager::GetSystem()) - { - im->PollWheelVerticalDelta(wparam); - } + SHInputManager::PollWheelVerticalDelta(wparam); break; } default: diff --git a/SHADE_Engine/src/Input/SHInputManagerSystem.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp similarity index 60% rename from SHADE_Engine/src/Input/SHInputManagerSystem.cpp rename to SHADE_Engine/src/Input/SHInputManager.cpp index 1beabe3f..619afec0 100644 --- a/SHADE_Engine/src/Input/SHInputManagerSystem.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -1,5 +1,5 @@ /********************************************************************* - * \file SHInputManagerSystem.cpp + * \file SHInputManager.cpp * \author Ryan Wang Nian Jing * \brief Definition of input manager. * Handles input from keyboard and mouse. Soon to include controller. @@ -11,7 +11,8 @@ #pragma once #include -#include "SHInputManagerSystem.h" +#include "SHInputManager.h" +#include "../Tools/SHException.h" namespace SHADE { @@ -19,61 +20,34 @@ namespace SHADE /* Static defines */ /*------------------------------------------------------------------------*/ - unsigned SHInputManagerSystem::keyCount = 0; - bool SHInputManagerSystem::keys[MAX_KEYS]; - bool SHInputManagerSystem::keysLast[MAX_KEYS]; - double SHInputManagerSystem::keysHeldTime[MAX_KEYS]; - double SHInputManagerSystem::keysReleasedTime[MAX_KEYS]; + unsigned SHInputManager::keyCount = 0; + bool SHInputManager::keys[MAX_KEYS]; + bool SHInputManager::keysLast[MAX_KEYS]; + double SHInputManager::keysHeldTime[MAX_KEYS]; + double SHInputManager::keysReleasedTime[MAX_KEYS]; - unsigned SHInputManagerSystem::keyToggleCount = 0; - bool SHInputManagerSystem::keysToggle[MAX_KEYS]; - bool SHInputManagerSystem::keysToggleLast[MAX_KEYS]; - double SHInputManagerSystem::keysToggleOnTime[MAX_KEYS]; - double SHInputManagerSystem::keysToggleOffTime[MAX_KEYS]; + unsigned SHInputManager::keyToggleCount = 0; + bool SHInputManager::keysToggle[MAX_KEYS]; + bool SHInputManager::keysToggleLast[MAX_KEYS]; + double SHInputManager::keysToggleOnTime[MAX_KEYS]; + double SHInputManager::keysToggleOffTime[MAX_KEYS]; - int SHInputManagerSystem::mouseScreenX = 0; - int SHInputManagerSystem::mouseScreenY = 0; - int SHInputManagerSystem::mouseScreenXLast = 0; - int SHInputManagerSystem::mouseScreenYLast = 0; - double SHInputManagerSystem::mouseVelocityX = 0; - double SHInputManagerSystem::mouseVelocityY = 0; - int SHInputManagerSystem::mouseWheelVerticalDelta = 0; - int SHInputManagerSystem::mouseWheelVerticalDeltaPoll = 0; + int SHInputManager::mouseScreenX = 0; + int SHInputManager::mouseScreenY = 0; + int SHInputManager::mouseScreenXLast = 0; + int SHInputManager::mouseScreenYLast = 0; + double SHInputManager::mouseVelocityX = 0; + double SHInputManager::mouseVelocityY = 0; + int SHInputManager::mouseWheelVerticalDelta = 0; + int SHInputManager::mouseWheelVerticalDeltaPoll = 0; - void SHInputManagerSystem::Init() - { - keyCount = 0; - SecureZeroMemory(keys, sizeof(keys)); - SecureZeroMemory(keysLast, sizeof(keysLast)); - SecureZeroMemory(keysHeldTime, sizeof(keysHeldTime)); - SecureZeroMemory(keysReleasedTime, sizeof(keysReleasedTime)); - - keyToggleCount = 0; - SecureZeroMemory(keysToggle, sizeof(keysToggle)); - SecureZeroMemory(keysToggleLast, sizeof(keysToggleLast)); - SecureZeroMemory(keysToggleOnTime, sizeof(keysToggleOnTime)); - SecureZeroMemory(keysToggleOffTime, sizeof(keysToggleOffTime)); - - mouseScreenX = 0; - mouseScreenY = 0; - mouseScreenXLast = 0; - mouseScreenYLast = 0; - mouseWheelVerticalDelta = 0; - mouseWheelVerticalDeltaPoll = 0; - } - - void SHInputManagerSystem::Exit() - { - //No dynamically allocated memory. Nothing to do here. - } - - void SHInputManagerSystem::InputManagerRoutine:: - FixedExecute(double dt) noexcept + void SHInputManager::UpdateInput(double dt) noexcept { //Keyboard and Mouse Buttons//////////////////////////////////////////////// //Poll unsigned char keyboardState[MAX_KEYS]; - GetKeyboardState(keyboardState); + //if (GetKeyboardState(keyboardState) == false) return; + SHASSERT(GetKeyboardState(keyboardState), "SHInputManager:GetKeyboardState() failed ({})", GetLastError()); keyCount = 0; keyToggleCount = 0; for (size_t i = 0; i < MAX_KEYS; ++i) @@ -144,7 +118,7 @@ namespace SHADE mouseWheelVerticalDeltaPoll = 0; } - bool SHInputManagerSystem::AnyKeyDown(SH_KEYCODE* firstDetected) noexcept + bool SHInputManager::AnyKeyDown(SH_KEYCODE* firstDetected) noexcept { for (size_t i = 0; i < MAX_KEYS; ++i) { @@ -157,7 +131,7 @@ namespace SHADE return false; } - bool SHInputManagerSystem::AnyKey(SH_KEYCODE* firstDetected) noexcept + bool SHInputManager::AnyKey(SH_KEYCODE* firstDetected) noexcept { for (size_t i = 0; i < MAX_KEYS; ++i) { @@ -170,7 +144,7 @@ namespace SHADE return false; } - bool SHInputManagerSystem::AnyKeyUp(SH_KEYCODE* firstDetected) noexcept + bool SHInputManager::AnyKeyUp(SH_KEYCODE* firstDetected) noexcept { for (size_t i = 0; i < MAX_KEYS; ++i) { diff --git a/SHADE_Engine/src/Input/SHInputManagerSystem.h b/SHADE_Engine/src/Input/SHInputManager.h similarity index 93% rename from SHADE_Engine/src/Input/SHInputManagerSystem.h rename to SHADE_Engine/src/Input/SHInputManager.h index 2a8fe052..d3e31004 100644 --- a/SHADE_Engine/src/Input/SHInputManagerSystem.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -1,5 +1,5 @@ /********************************************************************* - * \file SHInputManagerSystem.h + * \file SHInputManager.h * \author Ryan Wang Nian Jing * \brief Declaration of input manager. * Handles input from keyboard and mouse. Soon to include controller. @@ -13,19 +13,12 @@ //#include //#include "../../SHADE_Managed/src/SHpch.h" #include "SH_API.h" -#include "ECS_Base/System/SHSystem.h" -#include "ECS_Base/System/SHFixedSystemRoutine.h" namespace SHADE { - class SH_API SHInputManagerSystem : public SHSystem + class SH_API SHInputManager { public: - class SH_API InputManagerRoutine : public SHFixedSystemRoutine - { - public: - virtual void FixedExecute(double dt) noexcept override final; - }; public: /*------------------------------------------------------------------------*/ @@ -276,23 +269,21 @@ namespace SHADE }; public: + //Updates current state of the input, with dt to be fetched from FRC + //TODO should dt be fixed or variable? + static void UpdateInput(double dt) noexcept; + /*------------------------------------------------------------------------*/ /* Constructors & Destructor */ /*------------------------------------------------------------------------*/ - SHInputManagerSystem() noexcept = default; - ~SHInputManagerSystem() noexcept = default; + SHInputManager() noexcept = default; + ~SHInputManager() noexcept = default; - SHInputManagerSystem(const SHInputManagerSystem&) = delete; - SHInputManagerSystem(SHInputManagerSystem&&) = delete; + SHInputManager(const SHInputManager&) = delete; + SHInputManager(SHInputManager&&) = delete; - SHInputManagerSystem& operator= (const SHInputManagerSystem&) = delete; - SHInputManagerSystem& operator= (SHInputManagerSystem&&) = delete; - - /*------------------------------------------------------------------------*/ - /* SHSystem Overrides */ - /*------------------------------------------------------------------------*/ - virtual void Init() override final; - virtual void Exit() override final; + SHInputManager& operator= (const SHInputManager&) = delete; + SHInputManager& operator= (SHInputManager&&) = delete; /*------------------------------------------------------------------------*/ /* Member Functions */