Skip to content

Commit

Permalink
Final main branch commit as I will now be only releasing stable versi…
Browse files Browse the repository at this point in the history
…ons into main and working off a develop branch instead.
  • Loading branch information
ZOulhadj committed Nov 8, 2022
1 parent deb450f commit 21df527
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 252 deletions.
70 changes: 22 additions & 48 deletions sandbox/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@
#include "../src/renderer/renderer.hpp"
#include "../src/renderer/buffer.hpp"
#include "../src/renderer/texture.hpp"

#include "../src/renderer/ui.hpp"
#include "../src/input.hpp"
#include "../src/camera.hpp"
#include "../src/entity.hpp"
#include "../src/model.hpp"

#include "../src/events/event.hpp"
#include "../src/events/event_dispatcher.hpp"
#include "../src/events/window_event.hpp"
#include "../src/events/key_event.hpp"
#include "../src/events/mouse_event.hpp"

#include "../src/utility.hpp"


#include "../src/vertex.hpp"

// Application specific header files
Expand Down Expand Up @@ -60,12 +55,6 @@ static void handle_input(camera_t& camera, float deltaTime) {
// camera.roll += camera.roll_speed * deltaTime;
}

//VkRenderPass geometry_pass = nullptr;
//std::vector<Framebuffer> geometry_framebuffers;




VkSampler sampler;
image_buffer_t albedo_image{};
image_buffer_t depth_image{};
Expand All @@ -78,9 +67,9 @@ VkRenderPass ui_pass = nullptr;
std::vector<Framebuffer> ui_framebuffers;


Pipeline basicPipeline{};
Pipeline skyspherePipeline{};
Pipeline wireframePipeline{};
pipeline_t basicPipeline{};
pipeline_t skyspherePipeline{};
pipeline_t wireframePipeline{};

// This is a global descriptor set that will be used for all draw calls and
// will contain descriptors such as a projection view matrix, global scene
Expand All @@ -101,6 +90,7 @@ static buffer_t g_scene_buffer;

camera_t camera{};

//
// Global scene information that will be accessed by the shaders to perform
// various computations. The order of the variables cannot be changed! This
// is because the shaders themselves directly replicate this structs order.
Expand All @@ -120,8 +110,7 @@ struct engine_scene {
};


static void event_callback(Event& event);

static void event_callback(event& e);


#define APPLICATION_NAME "Vulkan 3D Model Viewer and Exporter"
Expand All @@ -137,7 +126,7 @@ int main(int argc, char** argv) {
window_t* window = create_window(APPLICATION_NAME, APPLICATION_WIDTH, APPLICATION_HEIGHT);
window->event_callback = event_callback;

renderer_context_t* renderer = create_renderer(window, BufferMode::Double, VSyncMode::Enabled);
renderer_context_t* renderer = create_renderer(window, buffer_mode::Double, vsync_mode::Enabled);


sampler = create_sampler(VK_FILTER_NEAREST, 16);
Expand Down Expand Up @@ -452,8 +441,6 @@ int main(int argc, char** argv) {
}
ImGui::End();

//

const ImGuiWindowFlags docking_flags = ImGuiWindowFlags_None;
const ImGuiWindowFlags viewport_flags = ImGuiWindowFlags_None;
static bool open = true;
Expand Down Expand Up @@ -540,13 +527,6 @@ int main(int argc, char** argv) {
destroy_sampler(sampler);






//destroy_framebuffers(geometry_framebuffers);
//destroy_render_pass(geometry_pass);

destroy_framebuffers(ui_framebuffers);
destroy_render_pass(ui_pass);

Expand All @@ -560,38 +540,32 @@ int main(int argc, char** argv) {
return 0;
}







// TODO: Event system stuff
static bool Press(KeyPressedEvent& event) {
static bool press(key_pressed_event& e) {
return true;
}

static bool ButtonPress(MouseButtonPressedEvent& event) {
static bool mouse_button_press(mouse_button_pressed_event& e) {

return true;
}

static bool ButtonRelease(MouseButtonReleasedEvent& event) {
static bool mouse_button_release(mouse_button_released_event& e) {

return true;
}

static bool MouseMove(MouseMovedEvent& event) {
static bool mouse_moved(mouse_moved_event& e) {
//update_camera_view(camera, event.GetX(), event.GetY());

return true;
}


static bool Resize(WindowResizedEvent& event) {
set_camera_projection(camera, event.get_width(), event.get_height());
static bool resize(window_resized_event& e) {
set_camera_projection(camera, e.get_width(), e.get_height());

VkExtent2D extent = {event.get_width(), event.get_height()};
VkExtent2D extent = {e.get_width(), e.get_height()};

destroy_image(albedo_image);
destroy_image(depth_image);
Expand All @@ -610,19 +584,19 @@ static bool Resize(WindowResizedEvent& event) {
return true;
}

static bool Close(WindowClosedEvent& event) {
static bool close(window_closed_event& ) {
running = false;

return true;
}

static void event_callback(Event& event) {
EventDispatcher dispatcher(event);
static void event_callback(event& e) {
event_dispatcher dispatcher(e);

dispatcher.Dispatch<KeyPressedEvent>(Press);
dispatcher.Dispatch<MouseButtonPressedEvent>(ButtonPress);
dispatcher.Dispatch<MouseButtonReleasedEvent>(ButtonRelease);
dispatcher.Dispatch<MouseMovedEvent>(MouseMove);
dispatcher.Dispatch<WindowResizedEvent>(Resize);
dispatcher.Dispatch<WindowClosedEvent>(Close);
dispatcher.dispatch<key_pressed_event>(press);
dispatcher.dispatch<mouse_button_pressed_event>(mouse_button_press);
dispatcher.dispatch<mouse_button_released_event>(mouse_button_release);
dispatcher.dispatch<mouse_moved_event>(mouse_moved);
dispatcher.dispatch<window_resized_event>(resize);
dispatcher.dispatch<window_closed_event>(close);
}
40 changes: 19 additions & 21 deletions src/events/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,38 @@
#define MYENGINE_EVENT_HPP

enum class event_type {
None = 0,
none = 0,

KeyPressedEvent,
KeyReleasedEvent,
key_pressed,
key_released,

MouseButtonPressedEvent,
MouseButtonReleasedEvent,
MouseMovedEvent,
MouseEnteredEvent,
MouseLeftEvent,
MouseScrolledUpEvent,
MouseScrolledDownEvent,
mouse_button_pressed,
mouse_button_released,
mouse_moved,
mouse_entered,
mouse_left,
mouse_scrolled_up,
mouse_scrolled_down,

WindowClosedEvent,
WindowResizedEvent,
window_closed,
window_resized,

};


#define EVENT_CLASS_TYPE(type) static event_type GetStaticType() { return event_type::type; } \
event_type GetType() const override { return GetStaticType(); } \
const char* GetName() const override { return #type; }
#define EVENT_CLASS_TYPE(type) static event_type get_static_type() { return event_type::type; } \
event_type get_type() const override { return get_static_type(); } \
const char* get_name() const override { return #type; }

class Event {
public:
virtual event_type GetType() const = 0;
virtual const char* GetName() const = 0;
struct event {
virtual event_type get_type() const = 0;
virtual const char* get_name() const = 0;

public:
bool Handled = false;
};


using event_func = std::function<void(Event&)>;
using event_func = std::function<void(event&)>;

#define BIND_EVENT(x) std::bind(&x, this, std::placeholders::_1)

Expand Down
11 changes: 5 additions & 6 deletions src/events/event_dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

#include "event.hpp"

class EventDispatcher {
public:
EventDispatcher(Event& e)
struct event_dispatcher {
event_dispatcher(event& e)
: m_Event(e)
{}

template <typename T>
bool Dispatch(std::function<bool(T&)> func) {
if (m_Event.GetType() != T::GetStaticType())
bool dispatch(std::function<bool(T&)> func) {
if (m_Event.get_type() != T::get_static_type())
return false;

m_Event.Handled = func(*(T*)&m_Event);
Expand All @@ -20,7 +19,7 @@ class EventDispatcher {
}

private:
Event& m_Event;
event& m_Event;
};

#endif
26 changes: 11 additions & 15 deletions src/events/key_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,32 @@

#include "event.hpp"

class KeyEvent : public Event {
public:
int GetKeyCode() const { return m_KeyCode; }
struct key_event : public event {
int get_key_code() const { return m_KeyCode; }

protected:
KeyEvent(int keycode)
key_event(int keycode)
: m_KeyCode(keycode)
{}

private:
int m_KeyCode;
};


class KeyPressedEvent : public KeyEvent {
public:
KeyPressedEvent(int keycode)
: KeyEvent(keycode)
struct key_pressed_event : public key_event {
key_pressed_event(int keycode)
: key_event(keycode)
{}

EVENT_CLASS_TYPE(KeyPressedEvent);
EVENT_CLASS_TYPE(key_pressed);
};

class KeyReleasedEvent : public KeyEvent {
public:
KeyReleasedEvent(int keycode)
: KeyEvent(keycode)
struct key_released_event : public key_event {
key_released_event(int keycode)
: key_event(keycode)
{}

EVENT_CLASS_TYPE(KeyReleasedEvent);
EVENT_CLASS_TYPE(key_released);
};

#endif
Loading

0 comments on commit 21df527

Please sign in to comment.