<commit_before>#include "InputManager.hpp"
#include "EntityManager.hpp"

#include "components/InputComponent.hpp"

InputManager::InputManager(kengine::EntityManager & em, OgreBites::ApplicationContext & app) : _em(em) {
	app.addInputListener(this);
}

static putils::vector<OgreBites::KeyboardEvent, 128> g_keyPressedEvents;
static putils::vector<OgreBites::KeyboardEvent, 128> g_keyReleasedEvents;
static putils::vector<OgreBites::MouseMotionEvent, 128> g_mouseMovedEvents;
static putils::vector<OgreBites::MouseButtonEvent, 128> g_mousePressedEvents;
static putils::vector<OgreBites::MouseButtonEvent, 128> g_mouseReleasedEvents;
static putils::vector<OgreBites::MouseWheelEvent, 128> g_mouseWheelEvents;

void InputManager::execute() noexcept {
	for (const auto & [e, input] : _em.getEntities<kengine::InputComponent>()) {
		if (input.onKey != nullptr) {
			for (const auto & event : g_keyPressedEvents)
				input.onKey(event.keysym.sym, true);
			for (const auto & event : g_keyReleasedEvents)
				input.onKey(event.keysym.sym, false);
		}

		if (input.onMouseMove != nullptr)
			for (const auto & event : g_mouseMovedEvents)
				input.onMouseMove((float)event.x, (float)event.y);

		if (input.onMouseButton != nullptr) {
			for (const auto & event : g_mousePressedEvents)
				input.onMouseButton(event.button, (float)event.x, (float)event.y, true);
			for (const auto & event : g_mouseReleasedEvents)
				input.onMouseButton(event.button, (float)event.x, (float)event.y, false);
		}

		if (input.onMouseWheel != nullptr)
			for (const auto & event : g_mouseWheelEvents)
				input.onMouseWheel((float)event.y, 0.f, 0.f);
	}

	g_keyPressedEvents.clear();
	g_keyReleasedEvents.clear();
	g_mouseMovedEvents.clear();
	g_mousePressedEvents.clear();
	g_mouseReleasedEvents.clear();
	g_mouseWheelEvents.clear();<commit_msg>ogre -- made InputManager take imgui into account<commit_after>#include "InputManager.hpp"
#include "EntityManager.hpp"

#include "components/InputComponent.hpp"
#include "imgui.h"

InputManager::InputManager(kengine::EntityManager & em, OgreBites::ApplicationContext & app) : _em(em) {
	app.addInputListener(this);
}

static putils::vector<OgreBites::KeyboardEvent, 128> g_keyPressedEvents;
static putils::vector<OgreBites::KeyboardEvent, 128> g_keyReleasedEvents;
static putils::vector<OgreBites::MouseMotionEvent, 128> g_mouseMovedEvents;
static putils::vector<OgreBites::MouseButtonEvent, 128> g_mousePressedEvents;
static putils::vector<OgreBites::MouseButtonEvent, 128> g_mouseReleasedEvents;
static putils::vector<OgreBites::MouseWheelEvent, 128> g_mouseWheelEvents;

void InputManager::execute() noexcept {
	const auto & imgui = ImGui::GetIO();
	for (const auto & [e, input] : _em.getEntities<kengine::InputComponent>()) {
		if (!imgui.WantCaptureKeyboard && input.onKey != nullptr) {
			for (const auto & event : g_keyPressedEvents)
				input.onKey(event.keysym.sym, true);
			for (const auto & event : g_keyReleasedEvents)
				input.onKey(event.keysym.sym, false);
		}

		if (!imgui.WantCaptureMouse) {
			if (imgui.WantCaptureMouse && input.onMouseMove != nullptr)
				for (const auto & event : g_mouseMovedEvents)
					input.onMouseMove((float)event.x, (float)event.y);

			if (input.onMouseButton != nullptr) {
				for (const auto & event : g_mousePressedEvents)
					input.onMouseButton(event.button, (float)event.x, (float)event.y, true);
				for (const auto & event : g_mouseReleasedEvents)
					input.onMouseButton(event.button, (float)event.x, (float)event.y, false);
			}

			if (input.onMouseWheel != nullptr)
				for (const auto & event : g_mouseWheelEvents)
					input.onMouseWheel((float)event.y, 0.f, 0.f);
		}
	}

	g_keyPressedEvents.clear();
	g_keyReleasedEvents.clear();
	g_mouseMovedEvents.clear();
	g_mousePressedEvents.clear();
	g_mouseReleasedEvents.clear();
	g_mouseWheelEvents.clear();
{'fraction_non_alphanumeric': 0.13236060448150078, 'fraction_numerical': 0.010422094841063054, 'mean_word_length': 6.096118299445472, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '2120498', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1315, 'n_words': 235}