Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions GAME/source/GAME/Layers/MainGameLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ namespace soge_game

void MainGameLayer::OnUpdate()
{
auto inputModule = soge::Engine::GetInstance()->GetModule<soge::InputModule>();
if (inputModule->IsKeyPressed(soge::Keys::W))
const auto engine = soge::Engine::GetInstance();
if (const auto inputModule = engine->GetModule<soge::InputModule>(); inputModule->IsKeyPressed(soge::Keys::W))
{
SOGE_APP_INFO_LOG("Key W pressed");
SOGE_APP_INFO_LOG("Key W pressed!");
}
else if (inputModule->IsKeyPressed(soge::Keys::Escape))
{
SOGE_APP_INFO_LOG("Key Escape pressed - shutting down!");
engine->RequestShutdown();
}
}

Expand Down
21 changes: 11 additions & 10 deletions SOGE/include/SOGE/Event/EventModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ namespace soge
void ClearQueue();
void Clear();

template <DerivedFromEvent E, typename... Args>
requires std::is_constructible_v<E, Args...>
void Dispatch(Args&&... args);
// TODO: return this method when weird library bug will be fixed
// template <DerivedFromEvent E, typename... Args>
// requires std::is_constructible_v<E, Args...>
// void Dispatch(Args&&... args);

template <DerivedFromEvent E, typename... Args>
requires std::is_constructible_v<E, Args...>
Expand Down Expand Up @@ -241,13 +242,13 @@ namespace soge
return IsEmpty(eventType);
}

template <DerivedFromEvent E, typename... Args>
requires std::is_constructible_v<E, Args...>
void EventModule::Dispatch(Args&&... args)
{
AnyEvent event{E{std::forward<Args>(args)...}};
m_eventQueue.dispatch(event);
}
// template <DerivedFromEvent E, typename... Args>
// requires std::is_constructible_v<E, Args...>
// void EventModule::Dispatch(Args&&... args)
// {
// AnyEvent event{E{std::forward<Args>(args)...}};
// m_eventQueue.dispatch(event);
// }

template <DerivedFromEvent E, typename... Args>
requires std::is_constructible_v<E, Args...>
Expand Down
2 changes: 0 additions & 2 deletions SOGE/include/SOGE/Input/Device/Keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define SOGE_INPUT_DEVICE_KEYBOARD_HPP

#include "SOGE/Input/Device/InputDevice.hpp"
#include "SOGE/Input/InputTypes.hpp"


namespace soge
Expand All @@ -13,7 +12,6 @@ namespace soge
explicit Keyboard(eastl::string_view aKeyboardName);

virtual void Update() = 0;

};
}

Expand Down
2 changes: 0 additions & 2 deletions SOGE/include/SOGE/Input/Device/Mouse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define SOGE_INPUT_DEVICE_MOUSE_HPP

#include "SOGE/Input/Device/InputDevice.hpp"
#include "SOGE/Input/InputTypes.hpp"


namespace soge
Expand All @@ -13,7 +12,6 @@ namespace soge
explicit Mouse(eastl::string_view aMouseName);

virtual void Update() = 0;

};
}

Expand Down
6 changes: 4 additions & 2 deletions SOGE/include/SOGE/Input/InputModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ namespace soge
class InputModule : public Module
{
private:
void Update() const;

InputCore* m_inputCore;
EventModule* m_eventModule;
EventModule::FunctionHandle m_updateEventHandle;

public:
explicit InputModule();
Expand All @@ -33,8 +37,6 @@ namespace soge
Gamepad* GetGamepad() const;
[[nodiscard]]
Mouse* GetMouse() const;

void Update() const;
};
}

Expand Down
8 changes: 4 additions & 4 deletions SOGE/source/SOGE/Core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ namespace soge
SOGE_INFO_LOG(R"(Created window "{}" of width {} and height {} with UUID {})",
EAToNarrow(window.GetTitle()).c_str(), window.GetWidth(), window.GetHeight(), uuid.str());

const auto eventModule = GetModule<EventModule>();

m_shutdownRequested = false;
while (!m_shutdownRequested)
{
Timestep::StartFrame();
Timestep::CalculateDelta();

GetModule<InputModule>()->Update();

const auto eventModule = GetModule<EventModule>();
eventModule->Dispatch<UpdateEvent>(Timestep::DeltaTime());
eventModule->Enqueue<UpdateEvent>(Timestep::DeltaTime());
eventModule->DispatchQueue<UpdateEvent>();

for (const auto layer : m_renderLayers)
{
Expand Down
7 changes: 5 additions & 2 deletions SOGE/source/SOGE/Input/InputModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@

namespace soge
{
InputModule::InputModule() : m_inputCore(nullptr)
InputModule::InputModule() : m_inputCore(nullptr), m_eventModule(nullptr)
{
Keys::Initialize();
}

void InputModule::Load(di::Container& aContainer, ModuleManager& aModuleManager)
{
aModuleManager.CreateModule<EventModule>();
m_inputCore = &aContainer.Provide<ImplInputCore>();
m_eventModule = &aModuleManager.CreateModule<EventModule>().first;
m_updateEventHandle = m_eventModule->PushBack<UpdateEvent>([this](const UpdateEvent&) { Update(); });

SOGE_INFO_LOG("Input module loaded...");
}

void InputModule::Unload(di::Container& aContainer, ModuleManager& aModuleManager)
{
m_eventModule->Remove(m_updateEventHandle);
m_eventModule = nullptr;
m_inputCore = nullptr;

SOGE_INFO_LOG("Input module unloaded...");
Expand Down