Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion atlas/core/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,18 @@ namespace atlas {
*/
static uint32_t image_size();

protected:
[[nodiscard]] ref<renderer> renderer_instance() const {
return m_renderer;
}

private:
void set_current_api(api api);

private:
float m_delta_time = 0.f;
ref<window> m_window;
scope<renderer> m_renderer = nullptr;
ref<renderer> m_renderer = nullptr;
glm::mat4 m_proj_view;
uint32_t m_current_frame_index = -1;
vk::imgui_context m_ui_context;
Expand Down
1 change: 0 additions & 1 deletion atlas/core/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <core/core.hpp>
#include <core/application.hpp>
#include <core/engine_logger.hpp>
#include <core/utilities/state.hpp>
#include <core/event/event.hpp>
#include <core/scene/components.hpp>

Expand Down
11 changes: 11 additions & 0 deletions atlas/core/event/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@ namespace atlas::event {
uint64_t entity1;
uint64_t entity2;
};

/**
* @brief event to trigger when to transition specific scenes
*
* @param from_scene is the current scene that is being transitioned from
* @param to_scene is the new scene that is going to be transitioned to
*/
struct scene_transition {
const void* from_scene;
const void* to_scene;
};
};
53 changes: 38 additions & 15 deletions atlas/core/utilities/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,33 @@ namespace atlas {
void invoke_ui_update();
void invoke_start();

void poll_update(const std::function<void()>& p_callback);
// TODO: Look into a different way of doing this
void poll_update(void* p_address,
const std::function<void()>& p_callback);

void poll_defer_update(const std::function<void()>& p_callback);
void poll_defer_update(void* p_address,
const std::function<void()>& p_callback);

void poll_physics_update(const std::function<void()>& p_callback);
void poll_physics_update(void* p_address,
const std::function<void()>& p_callback);

void poll_ui_update(const std::function<void()>& p_callback);
void poll_ui_update(void* p_address,
const std::function<void()>& p_callback);

void poll_start(const std::function<void()>& p_callback);
void poll_start(void* p_address,
const std::function<void()>& p_callback);

// TEMP: This is a temporary solution, should look into doing this
// differently
void remove_update(void* p_address);

void remove_defer_update(void* p_address);

void remove_physics_update(void* p_address);

void remove_ui_update(void* p_address);

void remove_start(void* p_address);

};

Expand Down Expand Up @@ -70,8 +88,9 @@ namespace atlas {
static_assert(std::is_member_pointer_v<UCallback>,
"Cannot register a function that is not a member "
"function of a class object");
detail::poll_start(
[p_instance, p_callable]() { (p_instance->*p_callable)(); });
detail::poll_start(p_instance, [p_instance, p_callable]() {
(p_instance->*p_callable)();
});
}

/**
Expand Down Expand Up @@ -101,8 +120,9 @@ namespace atlas {
static_assert(std::is_member_pointer_v<UCallback>,
"Cannot register a function that is not a member "
"function of a class object");
detail::poll_update(
[p_instance, p_callable]() { (p_instance->*p_callable)(); });
detail::poll_update(p_instance, [p_instance, p_callable]() {
(p_instance->*p_callable)();
});
}

/**
Expand Down Expand Up @@ -130,8 +150,9 @@ namespace atlas {
static_assert(std::is_member_pointer_v<UCallback>,
"Cannot register a function that is not a member "
"function of a class object");
detail::poll_physics_update(
[p_instance, p_callable]() { (p_instance->*p_callable)(); });
detail::poll_physics_update(p_instance, [p_instance, p_callable]() {
(p_instance->*p_callable)();
});
}

/**
Expand Down Expand Up @@ -161,8 +182,9 @@ namespace atlas {
static_assert(std::is_member_pointer_v<UCallback>,
"Cannot register a function that is not a member "
"function of a class object");
detail::poll_defer_update(
[p_instance, p_callable]() { (p_instance->*p_callable)(); });
detail::poll_defer_update(p_instance, [p_instance, p_callable]() {
(p_instance->*p_callable)();
});
}

/**
Expand Down Expand Up @@ -194,8 +216,9 @@ namespace atlas {
static_assert(std::is_member_pointer_v<UCallback>,
"Cannot register a function that is not a member "
"function of a class object");
detail::poll_ui_update(
[p_instance, p_callable]() { (p_instance->*p_callable)(); });
detail::poll_ui_update(p_instance, [p_instance, p_callable]() {
(p_instance->*p_callable)();
});
}

};
7 changes: 7 additions & 0 deletions atlas/drivers/renderer_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <string>
#include <core/core.hpp>
#include <drivers/vulkan-cpp/vk_swapchain.hpp>
#include <core/scene/scene.hpp>

namespace atlas {
/**
Expand Down Expand Up @@ -65,6 +66,10 @@ namespace atlas {
return background_color(p_color);
}

void current_scene_context(ref<scene> p_scene) {
return current_scene(std::move(p_scene));
}

private:
virtual void preload_assets(const VkRenderPass& p_renderpass) = 0;

Expand All @@ -76,6 +81,8 @@ namespace atlas {
virtual void post_frame() = 0;

virtual void background_color(const std::array<float, 4>& p_color) = 0;

virtual void current_scene(ref<scene>) = 0;
};

ref<render_context> initialize_renderer(
Expand Down
4 changes: 4 additions & 0 deletions atlas/drivers/vulkan-cpp/vk_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace atlas::vk {

void post_frame() override;

void current_scene(ref<scene>) override;

private:
VkDevice m_device = nullptr;
vk_physical_driver m_physical;
Expand Down Expand Up @@ -88,5 +90,7 @@ namespace atlas::vk {
glm::mat4 m_model = { 1.f };

::vk::texture m_white_texture;

ref<scene> m_current_scene;
};
};
3 changes: 3 additions & 0 deletions atlas/renderer/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ namespace atlas {
const std::string& p_tag = "Renderer");

void preload(const VkRenderPass& p_renderpass);

void current_scene(ref<scene>);

/**
* @brief Indicates to the renderer is at the start of the next frame to
* prepare workloads before next frame is processeed
Expand Down
4 changes: 2 additions & 2 deletions editor/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class editor_application : public atlas::application {

// TODO -- this is going to be changed with the use of the level
// streamer API
m_world =
atlas::create_strong_ref<editor_world>(m_allocator, "Editor World");
m_world = atlas::create_strong_ref<editor_world>(
m_allocator, "Editor World", renderer_instance());
}

private:
Expand Down
12 changes: 5 additions & 7 deletions editor/editor_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
#include <core/system/registry.hpp>
#include "level_scene.hpp"

editor_world::editor_world() {
console_log_fatal("Instantiate Default editor_world!");
}

editor_world::editor_world(const std::string& p_tag) {
editor_world::editor_world(
const std::string& p_tag,
/*NOLINT*/ atlas::ref<atlas::renderer> p_renderer_instance)
: m_renderer(/*NOLINT*/ p_renderer_instance) {
m_main_world = atlas::system_registry::create_world(p_tag);

console_log_trace("m_main_world->get_tag() = {}", m_main_world->name());

m_bus.create_listener<atlas::event::collision_enter>();
m_bus.create_listener<atlas::event::collision_persisted>();
m_bus.create_listener<atlas::event::collision_exit>();

atlas::ref<level_scene> first_scene =
atlas::create_ref<level_scene>("LevelScene", m_bus);
m_renderer->current_scene(first_scene);
m_main_world->add_scene(first_scene);
}
7 changes: 5 additions & 2 deletions editor/editor_world.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#pragma once
#include <core/core.hpp>
#include <core/scene/world.hpp>
#include <core/event/event_bus.hpp>
#include <renderer/renderer.hpp>

class editor_world {
public:
editor_world();
editor_world(const std::string& p_tag);
editor_world(const std::string& p_tag,
atlas::ref<atlas::renderer> p_renderer_instance);

private:
atlas::ref<atlas::world> m_main_world;

atlas::event::event_bus m_bus;
atlas::ref<atlas::renderer> m_renderer;
};
1 change: 1 addition & 0 deletions editor/level_scene.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "level_scene.hpp"
#include <core/common.hpp>
#include <core/utilities/state.hpp>
#include <core/application.hpp>
#include <drivers/jolt-cpp/jolt_components.hpp>
#include <physics/physics_engine.hpp>
Expand Down
3 changes: 2 additions & 1 deletion src/atlas/core/application.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <core/application.hpp>
#include <core/common.hpp>
#include <core/utilities/state.hpp>
#include <drivers/vulkan-cpp/vk_swapchain.hpp>
#include <drivers/vulkan-cpp/vk_context.hpp>

Expand All @@ -20,7 +21,7 @@ namespace atlas {
};
m_window = create_window(settings);

m_renderer = create_scope<renderer>(
m_renderer = create_ref<renderer>(
settings, m_window->current_swapchain().image_size(), "Renderer");
m_renderer->set_background_color({
p_settings.background_color.x,
Expand Down
78 changes: 57 additions & 21 deletions src/atlas/core/utilities/state.cpp
Original file line number Diff line number Diff line change
@@ -1,60 +1,96 @@
#include <core/utilities/state.hpp>
#include <deque>
#include <unordered_map>

namespace atlas {
namespace detail {
inline std::deque<std::function<void()>> s_update{};
inline std::deque<std::function<void()>> s_defer_update{};
inline std::deque<std::function<void()>> s_ui_update{};
inline std::deque<std::function<void()>> s_physica_update{};
inline std::deque<std::function<void()>> s_start{};
// inline std::deque<std::function<void()>> s_update{};
// inline std::deque<std::function<void()>> s_defer_update{};
// inline std::deque<std::function<void()>> s_ui_update{};
// inline std::deque<std::function<void()>> s_physica_update{};
// inline std::deque<std::function<void()>> s_start{};

void poll_update(const std::function<void()>& p_callback) {
s_update.emplace_back(p_callback);
// TODO: This should be done in a better way
// Potential replace this approach with using std::hive from C++26
inline std::unordered_map<void*, std::function<void()>> s_update{};
inline std::unordered_map<void*, std::function<void()>>
s_defer_update{};
inline std::unordered_map<void*, std::function<void()>> s_ui_update{};
inline std::unordered_map<void*, std::function<void()>>
s_physica_update{};
inline std::unordered_map<void*, std::function<void()>> s_start{};

void poll_update(void* p_address,
const std::function<void()>& p_callable) {
// s_update.emplace_back(p_callback);
s_update.emplace(p_address, p_callable);
}

void poll_defer_update(void* p_address,
const std::function<void()>& p_callback) {
s_defer_update.emplace(p_address, p_callback);
}

void poll_physics_update(void* p_address,
const std::function<void()>& p_callback) {
s_physica_update.emplace(p_address, p_callback);
}

void poll_ui_update(void* p_address,
const std::function<void()>& p_callback) {
s_ui_update.emplace(p_address, p_callback);
}

void poll_start(void* p_address,
const std::function<void()>& p_callback) {
s_start.emplace(p_address, p_callback);
}

void remove_update(void* p_address) {
s_update.erase(p_address);
}

void poll_defer_update(const std::function<void()>& p_callback) {
s_defer_update.emplace_back(p_callback);
void remove_defer_update(void* p_address) {
s_defer_update.erase(p_address);
}

void poll_physics_update(const std::function<void()>& p_callback) {
s_physica_update.emplace_back(p_callback);
void remove_physics_update(void* p_address) {
s_physica_update.erase(p_address);
}

void poll_ui_update(const std::function<void()>& p_callback) {
s_ui_update.emplace_back(p_callback);
void remove_ui_update(void* p_address) {
s_ui_update.erase(p_address);
}

void poll_start(const std::function<void()>& p_callback) {
s_start.emplace_back(p_callback);
void remove_start(void* p_address) {
s_start.erase(p_address);
}

void invoke_on_update() {
for (auto& on_update : s_update) {
for (auto& [address, on_update] : s_update) {
on_update();
}
}

void invoke_defer_update() {
for (auto& on_update : s_defer_update) {
for (auto& [address, on_update] : s_defer_update) {
on_update();
}
}

void invoke_physics_update() {
for (auto& on_update : s_physica_update) {
for (auto& [address, on_update] : s_physica_update) {
on_update();
}
}

void invoke_ui_update() {
for (auto& on_update : s_ui_update) {
for (auto& [address, on_update] : s_ui_update) {
on_update();
}
}

void invoke_start() {
for (auto& on_update : s_start) {
for (auto& [address, on_update] : s_start) {
on_update();
}
}
Expand Down
Loading
Loading