Started implementation of first event/message passing system
This commit is contained in:
		@ -1,16 +1,24 @@
 | 
			
		||||
#include "BarinkEngine.h"
 | 
			
		||||
#include "Input/InputManager.h"
 | 
			
		||||
#include "GLFW/glfw3.h"
 | 
			
		||||
#include "spdlog/spdlog.h"
 | 
			
		||||
#include <iostream>
 | 
			
		||||
void BarinkEngine::InputManager::PollEvents()
 | 
			
		||||
{
 | 
			
		||||
	for (std::vector<BarinkWindow*>::iterator it = windows.begin(); it != windows.end(); ++it) {
 | 
			
		||||
	for (auto it = windows.begin(); it != windows.end(); ++it) {
 | 
			
		||||
		(*it)->Poll();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) 
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	Event KeyEvent{};
 | 
			
		||||
	KeyEvent.name = "KEY";
 | 
			
		||||
	 
 | 
			
		||||
	InputSystem.EmitEvent(KeyEvent);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	if (key == GLFW_KEY_A && action == GLFW_PRESS)
 | 
			
		||||
	{
 | 
			
		||||
		
 | 
			
		||||
@ -21,23 +29,49 @@ void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int sc
 | 
			
		||||
 | 
			
		||||
void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y) 
 | 
			
		||||
{
 | 
			
		||||
	std::cout << "Cursor Position  x: " << x << ", y: " << y << std::endl;
 | 
			
		||||
	//std::cout << "Cursor Position  x: " << x << ", y: " << y << std::endl;
 | 
			
		||||
	Event CursorPosUpdate{};
 | 
			
		||||
	CursorPosUpdate.name = "UPDATE::CURSOR:POSITION";
 | 
			
		||||
 | 
			
		||||
	InputSystem.EmitEvent(CursorPosUpdate);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered)
 | 
			
		||||
{
 | 
			
		||||
	if (entered) {
 | 
			
		||||
		// Cursor entered the window's screen space
 | 
			
		||||
		std::cout << "Cursor entered!" << std::endl;
 | 
			
		||||
		Event mouseEntered {};
 | 
			
		||||
		mouseEntered.name = "Mouse Entered Window's confines!";
 | 
			
		||||
		mouseEntered.argc = 0;
 | 
			
		||||
		
 | 
			
		||||
		InputSystem.EmitEvent(mouseEntered);
 | 
			
		||||
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
		std::cout << "Cursor left!" << std::endl;
 | 
			
		||||
		Event mouseLeft{};
 | 
			
		||||
		mouseLeft.name = "Mouse Left Window's confines!";
 | 
			
		||||
		mouseLeft.argc = 0;
 | 
			
		||||
 | 
			
		||||
		InputSystem.EmitEvent(mouseLeft);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	Event MouseButtonEvent{};
 | 
			
		||||
	MouseButtonEvent.name = "MOUSEBUTTON";
 | 
			
		||||
 | 
			
		||||
	InputSystem.EmitEvent(MouseButtonEvent);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
 | 
			
		||||
		std::cout << "Right mouse button was pressed!" << std::endl;
 | 
			
		||||
	}
 | 
			
		||||
@ -47,7 +81,12 @@ void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int but
 | 
			
		||||
void BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
 | 
			
		||||
{
 | 
			
		||||
	std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl;
 | 
			
		||||
		
 | 
			
		||||
	
 | 
			
		||||
	Event ScrollEvent{};
 | 
			
		||||
	ScrollEvent.name = "SCROLL";
 | 
			
		||||
 | 
			
		||||
	InputSystem.EmitEvent(ScrollEvent);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -64,9 +103,16 @@ void BarinkEngine::InputManager::attach(BarinkWindow* window)
 | 
			
		||||
	glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback);
 | 
			
		||||
	glfwSetScrollCallback(window->windowptr(), ScrollCallback);
 | 
			
		||||
 | 
			
		||||
	this->Subscribe( (EventListener&)(*window));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BarinkEngine::InputManager::InputManager()
 | 
			
		||||
BarinkEngine::InputManager::InputManager() : EventEmitter ()
 | 
			
		||||
{
 | 
			
		||||
	windows = std::vector<BarinkWindow*>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user