Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mvp UI system #555

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8e17101
Fix Vulkan validation error.
RubyNova Nov 12, 2022
fa420e2
fix botched cherry pick
capnkenny Dec 10, 2022
bf4a876
Add Dear ImGui to CMakeLists
capnkenny Dec 10, 2022
cab0732
Make engine compile with Dear ImGui embedded
capnkenny Dec 10, 2022
761f340
Got Engine building with UI Provider plugin
capnkenny Dec 10, 2022
4704622
FabulistTest now runs and compiles
capnkenny Dec 10, 2022
4b2457d
Dear ImGui Rendering, but crashing when Window forcefully closed
capnkenny Dec 10, 2022
66d328d
Fixed dtor exception
capnkenny Dec 10, 2022
37d1857
Add new UI System
capnkenny Dec 11, 2022
9676d58
Comment out experimental viewport code
capnkenny Dec 14, 2022
6058f08
Refactor naming and add Textbox support
capnkenny Dec 18, 2022
fdc3d8b
Switched to default font, added scaling logic
capnkenny Dec 20, 2022
ddeddad
Added changing of background colours for textbox
capnkenny Dec 23, 2022
c1cad8d
Added imgui implicit conversions for GV2F and RGBAColour
capnkenny Dec 23, 2022
617e84c
Added translation, but horrible lag induced when moving mouse and not…
capnkenny Jan 14, 2023
9b22677
Y axis is flipped, but I think I fixed lag issue
capnkenny Jan 14, 2023
5f4653b
Fix interop build failure.
RubyNova Jan 24, 2023
34b11c8
Fix samples.
RubyNova Jan 24, 2023
73ffbf4
Modify constructors to be correct. Begin work on button support.
RubyNova Jan 28, 2023
28f3230
Fix redundant property specifiers.
RubyNova Jan 28, 2023
dda6b23
Fix maths namespace. Additional ctor/function fixes. Begin adding but…
RubyNova Jan 29, 2023
44284ac
fix include paths in graphics headers.
RubyNova Jan 29, 2023
f9c4653
Revert header path changes.
RubyNova Jan 29, 2023
5d6a562
Add support for generating buttons from UI provider.
RubyNova Jan 29, 2023
4d35a58
Button now renders.
RubyNova Jan 29, 2023
a1b4221
Add clicked event to button.
RubyNova Jan 29, 2023
5465f85
Adding ignore for TimeTracker extension for VSC
capnkenny Jan 30, 2023
27ff830
Interrupts for InputDevice and UI
capnkenny Feb 3, 2023
2bd794d
[NOT WORKING] Began refactor of UI
capnkenny Feb 8, 2023
20534af
Merge branch 'main' into feature/mvp-ui-system
capnkenny Feb 10, 2023
c75a584
Progress update before switching PCs
capnkenny Feb 11, 2023
4286f73
Panels rendering now
capnkenny Feb 20, 2023
8c41b67
Fixed bug with alpha
capnkenny Feb 20, 2023
32c4007
[BROKEN] Provide list to Creation commands
capnkenny Mar 12, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ CTestTestfile.cmake
.DS_Store
internal/build*
internal/dist*
.timetracker
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ endif()
#
# Add subdirectories
#
add_subdirectory(internal/imgui)
add_subdirectory(internal/Fabulist)
add_subdirectory(resources)
add_subdirectory(src)
Expand Down
30 changes: 30 additions & 0 deletions include/NovelRT/Ecs/Configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace NovelRT::Ecs
std::vector<std::shared_ptr<IEcsSystem>> _iecsSystems;
std::shared_ptr<PluginManagement::IGraphicsPluginProvider> _graphicsPluginProvider;
std::shared_ptr<PluginManagement::IWindowingPluginProvider> _windowingPluginProvider;
std::shared_ptr<PluginManagement::IUIPluginProvider> _uiPluginProvider;
std::shared_ptr<PluginManagement::IResourceManagementPluginProvider> _resourceManagementPluginProvider;
std::shared_ptr<PluginManagement::IInputPluginProvider> _inputPluginProvider;

Expand Down Expand Up @@ -73,10 +74,22 @@ namespace NovelRT::Ecs
Audio::AudioEmitterStateComponent{Audio::AudioEmitterState::Done},
"NovelRT::Ecs::Audio::AudioEmitterStateComponent");

auto uiPanelDeleteState = NovelRT::UI::UIPanel{};
uiPanelDeleteState.State = NovelRT::UI::UIElementState::Disposed;
auto uiTextDeleteState = NovelRT::UI::UIText{};
uiTextDeleteState.State = NovelRT::UI::UIElementState::Disposed;
target.GetComponentCache().RegisterComponentType(uiPanelDeleteState, "NovelRT::UI::UIPanel");
target.GetComponentCache().RegisterComponentType(uiTextDeleteState, "NovelRT::UI::UIText");

target.RegisterSystem(
std::make_shared<Ecs::Input::InputSystem>(_windowingPluginProvider, _inputPluginProvider));

target.RegisterSystem(std::make_shared<Ecs::Audio::AudioSystem>(_resourceManagementPluginProvider));

target.RegisterSystem(std::make_shared<NovelRT::Ecs::UI::UISystem>(_uiPluginProvider,
target.GetRegisteredIEcsSystemAs<NovelRT::Ecs::Input::InputSystem>(),
target.GetRegisteredIEcsSystemAs<NovelRT::Ecs::Graphics::DefaultRenderingSystem>(),
_resourceManagementPluginProvider->GetResourceLoader()));
}

public:
Expand Down Expand Up @@ -221,6 +234,23 @@ namespace NovelRT::Ecs
return *this;
}

/**
* @brief Specifies a plugin provider object to use for creating the default systems.
*
* @tparam TPluginProvider The type of PluginProvider interface this provider implements.
* @return A reference to this to allow method chaining.
*
* @exception Exceptions::NotSupportedException if the plugin provider type is currently not used or supported
* by default systems.
*/
template<>
[[nodiscard]] Configurator& WithPluginProvider<PluginManagement::IUIPluginProvider>(
std::shared_ptr<PluginManagement::IUIPluginProvider> pluginInstance)
{
_uiPluginProvider = std::move(pluginInstance);
return *this;
}

/**
* @brief Creates the ECS instance and registers component types to it.
* This is the final method you should call to obtain the ECS instance.
Expand Down
20 changes: 10 additions & 10 deletions include/NovelRT/Ecs/Ecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
// dependencies for ECS
// clang-format off

#include "../Atom.h"
#include "../Exceptions/Exceptions.h"
#include "../Maths/Maths.h"
#include "../Timing/Timestamp.h"
#include "../Utilities/Event.h"
#include "../Utilities/KeyValuePair.h"
#include "../Utilities/Misc.h"
#include "../PluginManagement/PluginManagement.h"
#include "../Threading/Threading.h"
#include "NovelRT/Atom.h"
#include "NovelRT/Exceptions/Exceptions.h"
#include "NovelRT/Maths/Maths.h"
#include "NovelRT/Timing/Timestamp.h"
#include "NovelRT/Utilities/Event.h"
#include "NovelRT/Utilities/KeyValuePair.h"
#include "NovelRT/PluginManagement/PluginManagement.h"
#include "NovelRT/Threading/Threading.h"
#include <algorithm>
#include <atomic>
#include <cstddef>
Expand Down Expand Up @@ -83,11 +82,12 @@ namespace NovelRT::Ecs
#include "Graphics/Ecs.Graphics.h"
#include "Audio/Ecs.Audio.h"
#include "Input/Ecs.Input.h"
#include "UI/Ecs.UI.h"
#include "Narrative/Ecs.Narrative.h"
#include "Configurator.h"
#include "LinkedEntityListView.h"
#include "EntityGraphView.h"

// clang-format on

#endif // NOVELRT_ECS_H
#endif // NOVELRT_ECS_H
21 changes: 21 additions & 0 deletions include/NovelRT/Ecs/Graphics/DefaultRenderingSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace NovelRT::Ecs::Graphics
Utilities::Lazy<NovelRT::Graphics::GraphicsResourceManager> _resourceManager;
std::shared_ptr<PluginManagement::IGraphicsPluginProvider> _graphicsPluginProvider;
std::shared_ptr<PluginManagement::IWindowingPluginProvider> _windowingPluginProvider;
std::shared_ptr<PluginManagement::IUIPluginProvider> _uiPluginProvider;
std::shared_ptr<PluginManagement::IResourceManagementPluginProvider> _resourceManagementPluginProvider;
std::shared_ptr<NovelRT::Graphics::GraphicsSurfaceContext> _surfaceContext;
std::shared_ptr<NovelRT::Graphics::GraphicsAdapter> _graphicsAdapter;
Expand Down Expand Up @@ -156,6 +157,11 @@ namespace NovelRT::Ecs::Graphics

void DeleteVertexData(const std::string& name);

[[nodiscard]] inline Threading::ConcurrentSharedPtr<GraphicsPipelineInfo> GetExistingDefaultPipelineInfo() const noexcept
{
return _defaultGraphicsPipelinePtr;
}

[[nodiscard]] Threading::ConcurrentSharedPtr<GraphicsPipelineInfo> GetExistingPipelineInfo(
const std::string& name);

Expand Down Expand Up @@ -217,6 +223,21 @@ namespace NovelRT::Ecs::Graphics

[[nodiscard]] Atom GetPipelineFromAssetGuids(uuids::uuid vertexShaderAssetGuid,
uuids::uuid pixelShaderAssetGuid) const;

[[nodiscard]] inline std::shared_ptr<NovelRT::Graphics::GraphicsDevice> GetCurrentGraphicsDevice() const noexcept
{
return _graphicsDevice;
}

[[nodiscard]] inline std::shared_ptr<NovelRT::Graphics::GraphicsProvider> GetCurrentGraphicsProvider() const noexcept
{
return _graphicsPluginProvider->GetGraphicsProvider();
}

[[nodiscard]] inline std::shared_ptr<NovelRT::PluginManagement::IWindowingPluginProvider> GetCurrentWindowingPluginProvider() const noexcept
{
return _windowingPluginProvider;
}
};
}
#endif // !NOVELRT_ECS_GRAPHICS_DEFAULTRENDERINGSYSTEM_H
1 change: 1 addition & 0 deletions include/NovelRT/Ecs/Graphics/Ecs.Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// Ecs.Graphics Dependencies
#include "NovelRT/Graphics/RGBAColour.h"
#include "NovelRT/UI/UI.h"

namespace NovelRT::Ecs::Graphics
{
Expand Down
1 change: 1 addition & 0 deletions include/NovelRT/Ecs/Input/InputSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace NovelRT::Ecs::Input
void Update(Timing::Timestamp delta, Ecs::Catalogue catalogue) final;
void AddMapping(std::string name, std::string id);
void AddDefaultKBMMapping();
[[nodiscard]] std::shared_ptr<NovelRT::Input::IInputDevice> GetInputDevice();
[[nodiscard]] NovelRT::Atom GetMappingId(const std::string& mappingName) const;
};
}
Expand Down
21 changes: 21 additions & 0 deletions include/NovelRT/Ecs/UI/Ecs.UI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#ifndef NOVELRT_ECS_UI_H
#define NOVELRT_ECS_UI_H

#ifndef NOVELRT_ECS_H
#error NovelRT does not support including types explicitly by default. Please include Ecs.h instead for the Ecs namespace subset.
#endif

#include <NovelRT/UI/UI.h>
#include <map>

namespace NovelRT::Ecs::UI
{
class UISystem;
}

#include "UISystem.h"

#endif // NOVELRT_ECS_UI_H
38 changes: 38 additions & 0 deletions include/NovelRT/Ecs/UI/UISystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#ifndef NOVELRT_ECS_UI_UISYSTEM_H
#define NOVELRT_ECS_UI_UISYSTEM_H

#ifndef NOVELRT_ECS_UI_H
#error NovelRT does not support including types explicitly by default. Please include Ecs.UI.h instead for the Ecs.UI namespace subset.
#endif

namespace NovelRT::Ecs::UI
{
class UISystem : public Ecs::IEcsSystem
{
private:
LoggingService _logger;
std::shared_ptr<NovelRT::UI::UIProvider> _uiProvider;

//void GeneratePanelCommand(NovelRT::UI::UIPanel panel, std::vector<std::function<void()>>& commandList);

public:
UISystem(std::shared_ptr<NovelRT::PluginManagement::IUIPluginProvider> uiPluginProvider,
std::shared_ptr<NovelRT::Ecs::Input::InputSystem> inputSystem,
std::shared_ptr<NovelRT::Ecs::Graphics::DefaultRenderingSystem> renderingSystem,
std::shared_ptr<NovelRT::ResourceManagement::ResourceLoader> resourceLoader);

void Update(Timing::Timestamp delta, Ecs::Catalogue catalogue) final;
NovelRT::UI::UIText CreateTextElement(Ecs::SystemScheduler& scheduler, NovelRT::UI::UIPanel& panel);

inline std::shared_ptr<NovelRT::UI::UIProvider> GetProvider() const
{
return _uiProvider;
}

};
}

#endif // NOVELRT_ECS_UI_UISYSTEM_H
1 change: 1 addition & 0 deletions include/NovelRT/EngineConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace NovelRT::EngineConfig
std::vector<std::string>& OptionalVulkanLayers() noexcept;
LogLevel& MinimumInternalLoggingLevel() noexcept;
bool& EnableDebugOutputFromEngineInternals() noexcept;
bool& EnableEditorMode() noexcept;
}

#endif // NOVELRT_ENGINECONFIG_H
10 changes: 10 additions & 0 deletions include/NovelRT/Graphics/RGBAColour.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace NovelRT::Graphics
uint8_t b;
uint8_t a;

RGBAColour() noexcept :
r(0), g(0), b(0), a(0)
{
}

RGBAColour(uint8_t initialR, uint8_t initialG, uint8_t initialB, uint8_t initialA) noexcept
: r(initialR), g(initialG), b(initialB), a(initialA)
{
Expand All @@ -40,6 +45,11 @@ namespace NovelRT::Graphics
{
return a / 255.0f;
}

[[nodiscard]] inline uint32_t Get32BitColour() const noexcept
{
return (r | g << 8 | b << 16 | a << 24);
}
};
}

Expand Down
3 changes: 2 additions & 1 deletion include/NovelRT/Graphics/Vulkan/VulkanGraphicsContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace NovelRT::Graphics::Vulkan

Threading::VolatileState _state;

VkCommandBuffer CreateVulkanCommandBuffer();

VkCommandPool CreateVulkanCommandPool();
VkFramebuffer CreateVulkanFramebuffer();
VkImageView CreateVulkanSwapChainImageView();
Expand Down Expand Up @@ -110,6 +110,7 @@ namespace NovelRT::Graphics::Vulkan
void EndFrame() final;

void ResetContext();
VkCommandBuffer CreateVulkanCommandBuffer();

~VulkanGraphicsContext() final;
};
Expand Down
31 changes: 31 additions & 0 deletions include/NovelRT/Input/Glfw/GlfwInputDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,44 @@ namespace NovelRT::Input::Glfw
[[nodiscard]] bool IsKeyPressed(const std::string& input) noexcept final;
[[nodiscard]] bool IsKeyHeld(const std::string& input) noexcept final;
[[nodiscard]] bool IsKeyReleased(const std::string& input) noexcept final;
[[nodiscard]] bool IsMouseKey(const std::string& key) noexcept final;
[[nodiscard]] KeyState GetKeyState(const std::string& key) noexcept final;
[[nodiscard]] InputAction& AddInputAction(const std::string& actionName,
const std::string& keyIdentifier) final;
[[nodiscard]] NovelKey& GetAvailableKey(const std::string& keyRequested) final;
[[nodiscard]] NovelRT::Maths::GeoVector2F GetMousePosition() noexcept final;
[[nodiscard]] NovelRT::Utilities::Misc::Span<InputAction> GetAllMappings() noexcept final;

[[nodiscard]] inline bool& MouseButtonInterrupt() final
{
return _mouseButtonInterrupt;
}

[[nodiscard]] inline const bool& MouseButtonInterrupt() const final
{
return _mouseButtonInterrupt;
}

[[nodiscard]] inline bool& MousePositionInterrupt() final
{
return _mousePositionInterrupt;
}

[[nodiscard]] inline const bool& MousePositionInterrupt() const final
{
return _mousePositionInterrupt;
}

[[nodiscard]] inline bool& KeyPressInterrupt() final
{
return _keyPressInterrupt;
}

[[nodiscard]] inline const bool& KeyPressInterrupt() const final
{
return _keyPressInterrupt;
}

~GlfwInputDevice() final;
};
}
Expand Down
15 changes: 15 additions & 0 deletions include/NovelRT/Input/IInputDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,28 @@ namespace NovelRT::Input
LoggingService _logger;
std::vector<InputAction> _mappedActions;
std::map<std::string, NovelKey> _availableKeys;
bool _mouseButtonInterrupt;
bool _keyPressInterrupt;
bool _mousePositionInterrupt;

public:
Utilities::Event<std::shared_ptr<IInputDevice>, float, float> MousePositionHandler;
Utilities::Event<std::shared_ptr<IInputDevice>, NovelKey, KeyState> MouseButtonHandler;
Utilities::Event<std::shared_ptr<IInputDevice>, NovelKey, KeyState> KeyPressHandler;
Utilities::Event<std::shared_ptr<IInputDevice>> UpdateHandler;

virtual void Initialise(void* window) = 0;
virtual void Update(Timing::Timestamp delta) = 0;
[[nodiscard]] virtual inline bool& MouseButtonInterrupt() = 0;
[[nodiscard]] virtual inline bool& MousePositionInterrupt() = 0;
[[nodiscard]] virtual inline bool& KeyPressInterrupt() = 0;
[[nodiscard]] virtual inline const bool& MouseButtonInterrupt() const = 0;
[[nodiscard]] virtual inline const bool& MousePositionInterrupt() const = 0;
[[nodiscard]] virtual inline const bool& KeyPressInterrupt() const = 0;
[[nodiscard]] virtual bool IsKeyPressed(const std::string& key) = 0;
[[nodiscard]] virtual bool IsKeyHeld(const std::string& key) = 0;
[[nodiscard]] virtual bool IsKeyReleased(const std::string& key) = 0;
[[nodiscard]] virtual bool IsMouseKey(const std::string& key) = 0;
[[nodiscard]] virtual KeyState GetKeyState(const std::string& key) = 0;
[[nodiscard]] virtual InputAction& AddInputAction(const std::string& actionName,
const std::string& keyIdentifier) = 0;
Expand Down
3 changes: 2 additions & 1 deletion include/NovelRT/Input/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include "NovelRT/LoggingService.h"
#include "NovelRT/Maths/Maths.h"
#include "NovelRT/Timing/Timestamp.h"
#include "NovelRT/Utilities/Misc.h"
#include "NovelRT/Utilities/Event.h"
#include <gsl/span>
#include <map>
#include <string>

Expand Down
4 changes: 2 additions & 2 deletions include/NovelRT/Maths/Maths.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#define NOVELRT_MATHS_H

// Maths dependencies
#include <NovelRT/Exceptions/Exceptions.h>
#include <NovelRT/Utilities/Misc.h>
#include "NovelRT/Exceptions/Exceptions.h"
#include "NovelRT/Utilities/Misc.h"
#include <array>
#include <glm/glm.hpp>
#include <glm/gtx/rotate_vector.hpp>
Expand Down
Loading