Started implementation of first event/message passing system
This commit is contained in:
		@ -20,3 +20,5 @@ extern void Start();
 | 
			
		||||
extern void Update();
 | 
			
		||||
extern void ImmediateGraphicsDraw();
 | 
			
		||||
extern void Stop();
 | 
			
		||||
 | 
			
		||||
extern BarinkEngine::InputManager InputSystem;
 | 
			
		||||
							
								
								
									
										11
									
								
								BarinkEngine/Include/EventSystem/Event.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								BarinkEngine/Include/EventSystem/Event.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
#pragma once 
 | 
			
		||||
#include <string> 
 | 
			
		||||
 | 
			
		||||
struct Event
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    std::string name;
 | 
			
		||||
    int argc;
 | 
			
		||||
    void** argv;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										16
									
								
								BarinkEngine/Include/EventSystem/EventEmitter.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								BarinkEngine/Include/EventSystem/EventEmitter.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "Event.h"
 | 
			
		||||
#include "EventListener.h"
 | 
			
		||||
 | 
			
		||||
class EventEmitter {
 | 
			
		||||
public: 
 | 
			
		||||
  void Subscribe (EventListener& subscriber);
 | 
			
		||||
  void Unsubscribe(EventListener& subscriber);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
  std::list<EventListener*> subscribers;
 | 
			
		||||
  void EmitEvent(Event& incident);
 | 
			
		||||
 | 
			
		||||
  EventEmitter();
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										5
									
								
								BarinkEngine/Include/EventSystem/EventListener.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								BarinkEngine/Include/EventSystem/EventListener.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
			
		||||
#include "EventListener.h"
 | 
			
		||||
 | 
			
		||||
void EventListener::ReceiveEvent(Event& incident)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								BarinkEngine/Include/EventSystem/EventListener.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								BarinkEngine/Include/EventSystem/EventListener.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
#pragma once 
 | 
			
		||||
#include "Event.h"
 | 
			
		||||
#include <list>
 | 
			
		||||
class EventListener{
 | 
			
		||||
  public: 
 | 
			
		||||
    virtual void ReceiveEvent(Event& incident);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
@ -3,12 +3,13 @@
 | 
			
		||||
 | 
			
		||||
#include <glad/glad.h>
 | 
			
		||||
#include <GLFW/glfw3.h>
 | 
			
		||||
#include "../Include/EventSystem/EventListener.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BarinkWindow{
 | 
			
		||||
class BarinkWindow : EventListener {
 | 
			
		||||
    private:
 | 
			
		||||
        GLFWwindow* window;
 | 
			
		||||
        bool FullScreen;
 | 
			
		||||
@ -18,12 +19,15 @@ class BarinkWindow{
 | 
			
		||||
        static bool InitGLFW();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
        BarinkWindow(const int width, const int height);
 | 
			
		||||
        ~BarinkWindow();
 | 
			
		||||
 | 
			
		||||
        GLFWwindow* windowptr();
 | 
			
		||||
 | 
			
		||||
        void ReceiveEvent(Event& incident) override;
 | 
			
		||||
        bool WindowShouldClose();
 | 
			
		||||
 | 
			
		||||
        void Poll();
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,11 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "Graphics/Window.h"
 | 
			
		||||
#include "EventSystem/EventEmitter.h"
 | 
			
		||||
 | 
			
		||||
namespace BarinkEngine {
 | 
			
		||||
 | 
			
		||||
	class InputManager {
 | 
			
		||||
	class InputManager : EventEmitter {
 | 
			
		||||
	public:
 | 
			
		||||
		InputManager();
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,7 @@ namespace BarinkEngine {
 | 
			
		||||
		void attach(BarinkWindow* window);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		// GLFW Handlers
 | 
			
		||||
		static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
 | 
			
		||||
		static void CursorPositionCallback(GLFWwindow* window, double x, double y);
 | 
			
		||||
@ -21,5 +22,6 @@ namespace BarinkEngine {
 | 
			
		||||
		static void ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
 | 
			
		||||
	private:
 | 
			
		||||
		std::vector<BarinkWindow*> windows;
 | 
			
		||||
 | 
			
		||||
	};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user