Update examples and tests code
This commit is contained in:
committed by
Jérôme Leclercq
parent
2b7ff9274c
commit
4668a1d158
@@ -1,30 +1,34 @@
|
||||
// Sources pour https://github.com/NazaraEngine/NazaraEngine/wiki/(FR)-Tutoriel:-%5B02%5D-Gestion-des-événements
|
||||
|
||||
#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>
|
||||
#include <entt/entt.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
int main()
|
||||
{
|
||||
Nz::Modules<Nz::Graphics> nazara;
|
||||
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), "Tut02 - Events");
|
||||
auto& windowing = app.AddComponent<Nz::AppWindowingComponent>();
|
||||
Nz::Window& mainWindow = windowing.CreateWindow(Nz::VideoMode(1280, 720), "Tut02 - 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));
|
||||
}
|
||||
|
||||
@@ -36,10 +40,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();
|
||||
@@ -47,8 +51,8 @@ int main()
|
||||
nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2);
|
||||
}
|
||||
|
||||
Nz::EventHandler& eventHandler = mainWindow.GetEventHandler();
|
||||
eventHandler.OnKeyPressed.Connect([&](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& e)
|
||||
Nz::WindowEventHandler& eventHandler = mainWindow.GetEventHandler();
|
||||
eventHandler.OnKeyPressed.Connect([&](const Nz::WindowEventHandler*, const Nz::WindowEvent::KeyEvent& e)
|
||||
{
|
||||
textDrawer.SetText("You pressed " + Nz::Keyboard::GetKeyName(e.virtualKey));
|
||||
textSprite->Update(textDrawer);
|
||||
@@ -56,7 +60,7 @@ int main()
|
||||
Nz::Boxf textBox = textSprite->GetAABB();
|
||||
Nz::Vector2ui windowSize = mainWindow.GetSize();
|
||||
|
||||
auto& nodeComponent = registry.get<Nz::NodeComponent>(textEntity);
|
||||
auto& nodeComponent = textEntity.get<Nz::NodeComponent>();
|
||||
nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2);
|
||||
|
||||
// Profitons-en aussi pour nous donner un moyen de quitter le programme
|
||||
@@ -64,11 +68,5 @@ int main()
|
||||
mainWindow.Close(); // Cette ligne casse la boucle de la fenêtre
|
||||
});
|
||||
|
||||
while (mainWindow.IsOpen())
|
||||
{
|
||||
mainWindow.ProcessEvents();
|
||||
systemGraph.Update();
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return app.Run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user