-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from timmypidashev/main
Merge latest work :)
- Loading branch information
Showing
19 changed files
with
661 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: gitsubmodule | ||
directory: "/" | ||
schedule: | ||
interval: weekly | ||
open-pull-requests-limit: 10 | ||
labels: | ||
- External (3rd party) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,5 @@ | |
|
||
"cmake.configureSettings": { | ||
"BUILD_EXAMPLES": "OFF" | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,49 @@ | ||
#define GLFW_INCLUDE_NONE | ||
|
||
#include <Iridpch.h> | ||
|
||
#include "Logger/Log.h" | ||
|
||
#include "Application.h" | ||
|
||
#include <glad/glad.h> | ||
|
||
#include "GLFW/glfw3.h" | ||
|
||
namespace Iridescent { | ||
|
||
#define BIND_EVENT_FUNCTION(x) std::bind(&Application::x, this, std::placeholders::_1) | ||
|
||
Application::Application() | ||
{ | ||
m_Window = std::unique_ptr<Window>(Window::Create()); | ||
m_Window->SetEventCallback(BIND_EVENT_FUNCTION(OnEvent)); | ||
} | ||
|
||
|
||
Application::~Application() | ||
{ | ||
} | ||
|
||
void Application::OnEvent(Event& e) | ||
{ | ||
EventDispatcher dispatcher(e); | ||
dispatcher.Dispatch<WindowCloseEvent>(BIND_EVENT_FUNCTION(OnWindowClose)); | ||
|
||
IRID_CORE_TRACE("{0}", e); | ||
} | ||
|
||
void Application::Run() | ||
{ | ||
while (true); | ||
while (m_Running) | ||
{ | ||
m_Window->OnUpdate(); | ||
} | ||
} | ||
|
||
bool Application::OnWindowClose(WindowCloseEvent& e) | ||
{ | ||
m_Running = false; | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#pragma once | ||
|
||
#include "Event.h" | ||
|
||
#include <sstream> | ||
|
||
namespace Iridescent { | ||
|
||
class IRID_EXPORT WindowResizeEvent : public Event | ||
{ | ||
public: | ||
WindowResizeEvent(unsigned int width, unsigned int height) | ||
: m_Width(width), m_Height(height) {} | ||
|
||
inline unsigned int GetWidth() const { return m_Width; } | ||
inline unsigned int GetHeight() const { return m_Height; } | ||
|
||
std::string ToString() const override | ||
{ | ||
std::stringstream ss; | ||
ss << "WindowResizeEvent: " << m_Width << ", " << m_Height; | ||
return ss.str(); | ||
} | ||
|
||
EVENT_CLASS_TYPE(WindowResize) | ||
EVENT_CLASS_CATEGORY(EventCategoryApplication) | ||
private: | ||
unsigned int m_Width, m_Height; | ||
}; | ||
|
||
class IRID_EXPORT WindowCloseEvent : public Event | ||
{ | ||
public: | ||
WindowCloseEvent() {} | ||
|
||
EVENT_CLASS_TYPE(WindowClose) | ||
EVENT_CLASS_CATEGORY(EventCategoryApplication) | ||
}; | ||
|
||
class IRID_EXPORT AppTickEvent : public Event | ||
{ | ||
public: | ||
AppTickEvent() {} | ||
|
||
EVENT_CLASS_TYPE(AppTick) | ||
EVENT_CLASS_CATEGORY(EventCategoryApplication) | ||
}; | ||
|
||
class IRID_EXPORT AppUpdateEvent : public Event | ||
{ | ||
public: | ||
AppUpdateEvent() {} | ||
|
||
EVENT_CLASS_TYPE(AppUpdate) | ||
EVENT_CLASS_CATEGORY(EventCategoryApplication) | ||
}; | ||
|
||
class IRID_EXPORT AppRenderEvent : public Event | ||
{ | ||
public: | ||
AppRenderEvent() {} | ||
|
||
EVENT_CLASS_TYPE(AppRender) | ||
EVENT_CLASS_CATEGORY(EventCategoryApplication) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#pragma once | ||
|
||
#include "Exports.h" | ||
|
||
#include <string> | ||
#include <functional> | ||
|
||
namespace Iridescent { | ||
|
||
// Events in Hazel are currently blocking, meaning when an event occurs it | ||
// immediately gets dispatched and must be dealt with right then an there. | ||
// For the future, a better strategy might be to buffer events in an event | ||
// bus and process them during the "event" part of the update stage. | ||
|
||
enum class EventType | ||
{ | ||
None = 0, | ||
WindowClose, WindowResize, WindowFocus, WindowLostFocus, WindowMoved, | ||
AppTick, AppUpdate, AppRender, | ||
KeyPressed, KeyReleased, | ||
MouseButtonPressed, MouseButtonReleased, MouseMoved, MouseScrolled | ||
}; | ||
|
||
enum EventCategory | ||
{ | ||
None = 0, | ||
EventCategoryApplication = BIT(0), | ||
EventCategoryInput = BIT(1), | ||
EventCategoryKeyboard = BIT(2), | ||
EventCategoryMouse = BIT(3), | ||
EventCategoryMouseButton = BIT(4) | ||
}; | ||
|
||
#define EVENT_CLASS_TYPE(type) static EventType GetStaticType() { return EventType::##type; }\ | ||
virtual EventType GetEventType() const override { return GetStaticType(); }\ | ||
virtual const char* GetName() const override { return #type; } | ||
|
||
#define EVENT_CLASS_CATEGORY(category) virtual int GetCategoryFlags() const override { return category; } | ||
|
||
class IRID_EXPORT Event | ||
{ | ||
friend class EventDispatcher; | ||
public: | ||
virtual EventType GetEventType() const = 0; | ||
virtual const char* GetName() const = 0; | ||
virtual int GetCategoryFlags() const = 0; | ||
virtual std::string ToString() const { return GetName(); } | ||
|
||
inline bool IsInCategory(EventCategory category) | ||
{ | ||
return GetCategoryFlags() & category; | ||
} | ||
protected: | ||
bool m_Handled = false; | ||
}; | ||
|
||
class EventDispatcher | ||
{ | ||
template<typename T> | ||
using EventFn = std::function<bool(T&)>; | ||
public: | ||
EventDispatcher(Event& event) | ||
: m_Event(event) | ||
{ | ||
} | ||
|
||
template<typename T> | ||
bool Dispatch(EventFn<T> func) | ||
{ | ||
if (m_Event.GetEventType() == T::GetStaticType()) | ||
{ | ||
m_Event.m_Handled = func(*(T*)&m_Event); | ||
return true; | ||
} | ||
return false; | ||
} | ||
private: | ||
Event& m_Event; | ||
}; | ||
|
||
inline std::ostream& operator<<(std::ostream& os, const Event& e) | ||
{ | ||
return os << e.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#pragma once | ||
|
||
#include "Event.h" | ||
|
||
#include <sstream> | ||
|
||
namespace Iridescent { | ||
|
||
class IRID_EXPORT KeyEvent : public Event | ||
{ | ||
public: | ||
inline int GetKeyCode() const { return m_KeyCode; } | ||
|
||
EVENT_CLASS_CATEGORY(EventCategoryKeyboard | EventCategoryInput) | ||
protected: | ||
KeyEvent(int keycode) | ||
: m_KeyCode(keycode) {} | ||
|
||
int m_KeyCode; | ||
}; | ||
|
||
class IRID_EXPORT KeyPressedEvent : public KeyEvent | ||
{ | ||
public: | ||
KeyPressedEvent(int keycode, int repeatCount) | ||
: KeyEvent(keycode), m_RepeatCount(repeatCount) {} | ||
|
||
inline int GetRepeatCount() const { return m_RepeatCount; } | ||
|
||
std::string ToString() const override | ||
{ | ||
std::stringstream ss; | ||
ss << "KeyPressedEvent: " << m_KeyCode << " (" << m_RepeatCount << " repeats)"; | ||
return ss.str(); | ||
} | ||
|
||
EVENT_CLASS_TYPE(KeyPressed) | ||
private: | ||
int m_RepeatCount; | ||
}; | ||
|
||
class IRID_EXPORT KeyReleasedEvent : public KeyEvent | ||
{ | ||
public: | ||
KeyReleasedEvent(int keycode) | ||
: KeyEvent(keycode) {} | ||
|
||
std::string ToString() const override | ||
{ | ||
std::stringstream ss; | ||
ss << "KeyReleasedEvent: " << m_KeyCode; | ||
return ss.str(); | ||
} | ||
|
||
EVENT_CLASS_TYPE(KeyReleased) | ||
}; | ||
} |
Oops, something went wrong.