Last changes

This commit is contained in:
SirLynix
2023-02-02 20:33:53 +01:00
committed by Jérôme Leclercq
parent cee75dcc11
commit 5a57aca66a
26 changed files with 310 additions and 183 deletions

View File

@@ -75,14 +75,7 @@ int main()
if (!std::filesystem::is_directory(shaderDir) && std::filesystem::is_directory("../.." / shaderDir))
shaderDir = "../.." / shaderDir;
Nz::Renderer::Config rendererConfig;
std::cout << "Run using Vulkan? (y/n)" << std::endl;
if (std::getchar() == 'y')
rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan;
else
rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL;
Nz::Application<Nz::Graphics> app(rendererConfig);
Nz::Application<Nz::Graphics> app;
nzsl::ShaderWriter::States states;
states.shaderModuleResolver = Nz::Graphics::Instance()->GetShaderModuleResolver();

View File

@@ -16,7 +16,6 @@
#include <Nazara/Platform/Keyboard.hpp>
#include <Nazara/Platform/Platform.hpp>
#include <Nazara/Platform/Window.hpp>
#include <Nazara/Utility/BasicMainloop.hpp>
#include <chrono>
#include <iostream>
#include <thread>
@@ -47,10 +46,10 @@ int main()
sound.EnableLooping(true);
// La source du son se situe vers la gauche (Et un peu en avant)
sound.SetPosition(Nz::Vector3f::Left()*50.f + Nz::Vector3f::Forward()*5.f);
sound.SetPosition(Nz::Vector3f::Left() * 50.f + Nz::Vector3f::Forward() * 5.f);
// Et possède une vitesse de 10 par seconde vers la droite
sound.SetVelocity(Nz::Vector3f::Left()*-10.f);
sound.SetVelocity(Nz::Vector3f::Right() * 10.f);
// On joue le son
sound.Play();
@@ -58,16 +57,27 @@ int main()
Nz::MillisecondClock clock;
app.AddUpdater([&](Nz::Time elapsedTime)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 30));
if (sound.GetStatus() != Nz::SoundStatus::Playing)
{
// On arrête le son et l'application
sound.Stop();
app.Quit();
}
// On bouge la source du son en fonction du temps depuis chaque mise à jour
Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity() * clock.GetElapsedTime().AsSeconds();
Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity() * clock.Restart().AsSeconds();
sound.SetPosition(pos);
std::cout << "Position: " << pos.x << std::endl;
// Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap
if (pos.x > Nz::Vector3f::Left().x * -50.f || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Escape))
sound.Stop(); // On arrête le son (Stoppant également la boucle)
if (pos.x > Nz::Vector3f::Right().x * 50.f || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Escape))
{
sound.Stop();
app.Quit();
}
});
return app.Run();

View File

@@ -13,14 +13,7 @@ int main()
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
resourceDir = "../.." / resourceDir;
Nz::Renderer::Config rendererConfig;
std::cout << "Run using Vulkan? (y/n)" << std::endl;
if (std::getchar() == 'y')
rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan;
else
rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL;
Nz::Application<Nz::Graphics> app(rendererConfig);
Nz::Application<Nz::Graphics> app;
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();

View File

@@ -21,16 +21,7 @@ int main()
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
resourceDir = "../.." / resourceDir;
Nz::Renderer::Config rendererConfig;
std::cout << "Run using Vulkan? (y/n)" << std::endl;
if (std::getchar() != 'n')
rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan;
else
rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
Nz::Application<Nz::Graphics, Nz::Physics2D> app(rendererConfig);
Nz::Application<Nz::Graphics, Nz::Physics2D> app;
auto& windowing = app.AddComponent<Nz::AppWindowingComponent>();

View File

@@ -20,16 +20,7 @@ int main()
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
resourceDir = "../.." / resourceDir;
Nz::Renderer::Config rendererConfig;
std::cout << "Run using Vulkan? (y/n)" << std::endl;
if (std::getchar() != 'n')
rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan;
else
rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
Nz::Application<Nz::Graphics, Nz::Physics3D> app(rendererConfig);
Nz::Application<Nz::Graphics, Nz::Physics3D> app;
auto& windowing = app.AddComponent<Nz::AppWindowingComponent>();

View File

@@ -1,3 +1,7 @@
if is_plat("wasm") then
return -- Physics3D is not yet supported on wasm because of Newton
end
target("PhysicsDemo")
add_deps("NazaraGraphics", "NazaraPhysics3D")
add_packages("entt")

View File

@@ -9,49 +9,39 @@
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Platform/Keyboard.hpp>
#include <Nazara/Platform/Platform.hpp>
#include <Nazara/Utility/BasicMainloop.hpp>
#include <chrono>
#include <iostream>
#include <thread>
int main()
{
try
std::filesystem::path resourceDir = "assets/examples";
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
resourceDir = "../.." / resourceDir;
Nz::Application<Nz::Audio> app;
Nz::SoundStreamParams streamParams;
streamParams.forceMono = false;
Nz::Music music;
if (!music.OpenFromFile(resourceDir / "Audio/file_example_MP3_700KB.mp3", streamParams))
{
std::filesystem::path resourceDir = "assets/examples";
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
resourceDir = "../.." / resourceDir;
Nz::Application<Nz::Audio> app;
Nz::SoundStreamParams streamParams;
streamParams.forceMono = false;
Nz::Music music;
if (!music.OpenFromFile(resourceDir / "Audio/file_example_MP3_700KB.mp3", streamParams))
{
std::cout << "Failed to load sound" << std::endl;
std::getchar();
return EXIT_FAILURE;
}
std::getchar();
music.Play();
std::cout << "Playing sound..." << std::endl;
app.AddUpdater([&](Nz::Time /*elapsedTime*/)
{
if (!music.IsPlaying())
app.Quit();
});
return app.Run();
std::cout << "Failed to load sound" << std::endl;
return EXIT_FAILURE;
}
catch (const std::exception& e)
music.Play();
std::cout << "Playing sound..." << std::endl;
app.AddUpdater([&](Nz::Time /*elapsedTime*/)
{
std::cerr << e.what() << std::endl;
}
if (!music.IsPlaying())
app.Quit();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
});
return app.Run();
}

View File

@@ -1,3 +1,7 @@
if is_plat("wasm") then
return -- Threads are broken for now
end
target("PlayMusic")
add_deps("NazaraAudio", "NazaraUtility", "NazaraPlatform")
add_deps("NazaraAudio")
add_files("main.cpp")

View File

@@ -22,14 +22,7 @@ int main()
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
resourceDir = "../.." / resourceDir;
Nz::Renderer::Config rendererConfig;
std::cout << "Run using Vulkan? (y/n)" << std::endl;
if (std::getchar() == 'y')
rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan;
else
rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL;
Nz::Application<Nz::Graphics> app(rendererConfig);
Nz::Application<Nz::Graphics> app;
Nz::PluginLoader loader;
Nz::Plugin<Nz::AssimpPlugin> assimp = loader.Load<Nz::AssimpPlugin>();

View File

@@ -2,6 +2,10 @@ if not has_config("assimp") then
return
end
if is_plat("wasm") then
return -- Physics3D is not yet supported on wasm because of Newton
end
target("Showcase")
set_group("Examples")
set_kind("binary")

View File

@@ -1,3 +1,7 @@
if is_plat("wasm") then
return -- Physics3D is not yet supported on wasm because of Newton
end
target("Tut00_EmptyProject")
add_deps("NazaraAudio", "NazaraGraphics", "NazaraNetwork", "NazaraPhysics2D", "NazaraPhysics3D", "NazaraRenderer", "NazaraUtility")
add_files("main.cpp")

View File

@@ -14,16 +14,7 @@ NAZARA_REQUEST_DEDICATED_GPU()
int main()
{
Nz::Renderer::Config rendererConfig;
std::cout << "Run using Vulkan? (y/n)" << std::endl;
if (std::getchar() != 'n')
rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan;
else
rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
Nz::Application<Nz::Graphics, Nz::Widgets> app(rendererConfig);
Nz::Application<Nz::Graphics, Nz::Widgets> app;
auto& windowing = app.AddComponent<Nz::AppWindowingComponent>();
Nz::Window& mainWindow = windowing.CreateWindow(Nz::VideoMode(1920, 1080), "Widget demo");
@@ -67,7 +58,7 @@ int main()
samplerInfo.anisotropyLevel = 8;
std::shared_ptr<Nz::MaterialInstance> materialInstance = material->Instantiate();
materialInstance->SetTextureProperty("BaseColorMap", fs.GetOrLoad<Nz::Texture>("assets/lynix.jpg"));
materialInstance->SetTextureProperty("BaseColorMap", fs.Load<Nz::Texture>("assets/lynix.jpg"));
Nz::ImageWidget* imageWidget = canvas2D.Add<Nz::ImageWidget>(materialInstance);
imageWidget->SetPosition(1200.f, 200.f);