Handle windows and EnTT with application components

This commit is contained in:
SirLynix
2023-01-21 12:03:02 +01:00
committed by Jérôme Leclercq
parent 18851c9185
commit da9eb14ebe
16 changed files with 287 additions and 65 deletions

View File

@@ -1,10 +1,12 @@
// Sources pour https://github.com/NazaraEngine/NazaraEngine/wiki/(FR)-Tutoriel:-%5B01%5D-Hello-World
#include <Nazara/Core/Application.hpp>
#include <Nazara/Core/AppEntitySystemComponent.hpp>
#include <Nazara/Core/Systems.hpp>
#include <Nazara/Graphics.hpp>
#include <Nazara/Graphics/Components.hpp>
#include <Nazara/Graphics/Systems.hpp>
#include <Nazara/Platform/AppWindowingComponent.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <Nazara/Utility/Components.hpp>
@@ -17,15 +19,19 @@ int main()
{
Nz::Application<Nz::Graphics> app;
entt::registry registry;
Nz::SystemGraph systemGraph(registry);
Nz::RenderSystem& renderSystem = systemGraph.AddSystem<Nz::RenderSystem>();
Nz::RenderWindow& mainWindow = renderSystem.CreateWindow(Nz::Graphics::Instance()->GetRenderDevice(), Nz::VideoMode(1280, 720), "Tut01 - Hello world");
auto& windowing = app.AddComponent<Nz::AppWindowingComponent>();
Nz::Window& mainWindow = windowing.CreateWindow(Nz::VideoMode(1280, 720), "Hello world");
entt::entity cameraEntity = registry.create();
auto& ecs = app.AddComponent<Nz::AppEntitySystemComponent>();
Nz::RenderSystem& renderSystem = ecs.AddSystem<Nz::RenderSystem>();
auto& windowSwapchain = renderSystem.CreateSwapchain(mainWindow);
entt::handle cameraEntity = ecs.CreateEntity();
{
registry.emplace<Nz::NodeComponent>(cameraEntity);
auto& cameraComponent = registry.emplace<Nz::CameraComponent>(cameraEntity, mainWindow.GetRenderTarget(), Nz::ProjectionType::Orthographic);
cameraEntity.emplace<Nz::NodeComponent>();
auto& cameraComponent = cameraEntity.emplace<Nz::CameraComponent>(&windowSwapchain.GetSwapchain(), Nz::ProjectionType::Orthographic);
cameraComponent.UpdateClearColor(Nz::Color(0.46f, 0.48f, 0.84f, 1.f));
}
@@ -37,10 +43,10 @@ int main()
std::shared_ptr<Nz::TextSprite> textSprite = std::make_shared<Nz::TextSprite>();
textSprite->Update(textDrawer);
entt::entity textEntity = registry.create();
entt::handle textEntity = ecs.CreateEntity();
{
auto& nodeComponent = registry.emplace<Nz::NodeComponent>(textEntity);
auto& gfxComponent = registry.emplace<Nz::GraphicsComponent>(textEntity);
auto& nodeComponent = textEntity.emplace<Nz::NodeComponent>();
auto& gfxComponent = textEntity.emplace<Nz::GraphicsComponent>();
gfxComponent.AttachRenderable(textSprite, 0xFFFFFFFF);
Nz::Boxf textBox = textSprite->GetAABB();
@@ -48,11 +54,5 @@ int main()
nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2);
}
while (mainWindow.IsOpen())
{
mainWindow.ProcessEvents();
systemGraph.Update();
}
return EXIT_SUCCESS;
return app.Run();
}