From ef401d2235d7e86512d880c0103e22adb9910fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Tue, 19 Mar 2024 08:40:23 +0100 Subject: [PATCH] loading screen: background image always scaled to best fit screen while keeping correct aspect; audio lua binding simplified constructors; --- .../ScriptingAPI-Documentation.md | 3 ++ WickedEngine/wiAudio_BindLua.cpp | 51 ++++++++++++++++--- WickedEngine/wiAudio_BindLua.h | 12 +++-- WickedEngine/wiLoadingScreen.cpp | 26 ++++++++-- WickedEngine/wiRenderer.cpp | 36 +++---------- WickedEngine/wiRenderer.h | 2 - WickedEngine/wiSpriteFont_BindLua.cpp | 2 +- WickedEngine/wiVersion.cpp | 2 +- 8 files changed, 88 insertions(+), 46 deletions(-) diff --git a/Content/Documentation/ScriptingAPI-Documentation.md b/Content/Documentation/ScriptingAPI-Documentation.md index 38d100ad8..328baba3b 100644 --- a/Content/Documentation/ScriptingAPI-Documentation.md +++ b/Content/Documentation/ScriptingAPI-Documentation.md @@ -474,11 +474,13 @@ Loads and plays an audio files. #### Sound An audio file. Can be instanced several times via SoundInstance. - [constructor]Sound() -- creates an empty sound. Use the audio device to load sounds from files +- [constructor]Sound(string name) -- loads a sound from a file - IsValid() : bool -- returns whether the sound was created successfully #### SoundInstance An audio file instance that can be played. Note: after modifying parameters of the SoundInstance, the SoundInstance will need to be recreated from a specified sound - [constructor]SoundInstance() -- creates an empty soundinstance. Use the audio device to clone sounds +- [constructor]SoundInstance(Sound sound, opt float begin,length) -- creates a soundinstance from a sound - SetSubmixType(int submixtype) -- set a submix type group (default is SUBMIX_TYPE_SOUNDEFFECT) - SetBegin(float seconds) -- beginning of the playback in seconds, relative to the Sound it will be created from (0 = from beginning) - SetLength(float seconds) -- length in seconds (0 = until end) @@ -1022,6 +1024,7 @@ TextureSlot = { - SetRotation(float value) -- set rotation speed - SetMotionBlurAmount(float value) -- set the motion elongation factor - SetCollidersDisabled(bool value) -- disable GPU colliders +- IsCollidersDisabled() #### HairParticleSystem - _flags : int diff --git a/WickedEngine/wiAudio_BindLua.cpp b/WickedEngine/wiAudio_BindLua.cpp index df3b8caa0..35e087fd9 100644 --- a/WickedEngine/wiAudio_BindLua.cpp +++ b/WickedEngine/wiAudio_BindLua.cpp @@ -32,8 +32,8 @@ namespace wi::lua Sound_BindLua* sound = Luna::lightcheck(L, 2); if (sound != nullptr) { - bool result = wi::audio::CreateSound(wi::lua::SGetString(L, 1), &sound->sound); - wi::lua::SSetBool(L, result); + sound->soundResource = wi::resourcemanager::Load(wi::lua::SGetString(L, 1)); + wi::lua::SSetBool(L, sound->soundResource.GetSound().IsValid()); return 1; } else @@ -50,11 +50,12 @@ namespace wi::lua int argc = wi::lua::SGetArgCount(L); if (argc > 0) { - Sound_BindLua* sound = Luna::lightcheck(L, 1); + Sound_BindLua* s = Luna::lightcheck(L, 1); SoundInstance_BindLua* soundinstance = Luna::lightcheck(L, 2); - if (sound != nullptr && soundinstance != nullptr) + if (s != nullptr && soundinstance != nullptr) { - bool result = wi::audio::CreateSoundInstance(&sound->sound, &soundinstance->soundinstance); + const wi::audio::Sound& sound = s->soundResource.GetSound(); + bool result = wi::audio::CreateSoundInstance(&sound, &soundinstance->soundinstance); wi::lua::SSetBool(L, result); return 1; } @@ -296,9 +297,18 @@ REVERB_PRESET_PLATE = 29 { NULL, NULL } }; + Sound_BindLua::Sound_BindLua(lua_State* L) + { + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + soundResource = wi::resourcemanager::Load(wi::lua::SGetString(L, 1)); + } + } + int Sound_BindLua::IsValid(lua_State* L) { - wi::lua::SSetBool(L, sound.IsValid()); + wi::lua::SSetBool(L, soundResource.IsValid() && soundResource.GetSound().IsValid()); return 1; } @@ -336,6 +346,35 @@ REVERB_PRESET_PLATE = 29 { NULL, NULL } }; + SoundInstance_BindLua::SoundInstance_BindLua(lua_State* L) + { + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + Sound_BindLua* s = Luna::lightcheck(L, 1); + if (s == nullptr) + { + wi::lua::SError(L, "SoundInstance(Sound sound, opt float begin,length) : first argument is not a Sound!"); + return; + } + if (argc > 1) + { + soundinstance.begin = wi::lua::SGetFloat(L, 2); + if (argc > 2) + { + soundinstance.length = wi::lua::SGetFloat(L, 3); + } + } + const wi::audio::Sound& sound = s->soundResource.GetSound(); + if (!sound.IsValid()) + { + wi::lua::SError(L, "SoundInstance(Sound sound, opt float begin,end) : Sound is not valid!"); + return; + } + wi::audio::CreateSoundInstance(&sound, &soundinstance); + } + } + int SoundInstance_BindLua::SetSubmixType(lua_State* L) { int argc = wi::lua::SGetArgCount(L); diff --git a/WickedEngine/wiAudio_BindLua.h b/WickedEngine/wiAudio_BindLua.h index f909a6743..c2cd5b0f9 100644 --- a/WickedEngine/wiAudio_BindLua.h +++ b/WickedEngine/wiAudio_BindLua.h @@ -2,6 +2,7 @@ #include "wiLua.h" #include "wiLuna.h" #include "wiAudio.h" +#include "wiResourceManager.h" namespace wi::lua { @@ -35,14 +36,17 @@ namespace wi::lua class Sound_BindLua { public: - wi::audio::Sound sound; + wi::Resource soundResource; inline static constexpr char className[] = "Sound"; static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; - Sound_BindLua(lua_State* L) {} - Sound_BindLua(const wi::audio::Sound& sound) :sound(sound) {} + Sound_BindLua(lua_State* L); + Sound_BindLua(const wi::audio::Sound& sound) + { + soundResource.SetSound(sound); + } int IsValid(lua_State* L); @@ -58,7 +62,7 @@ namespace wi::lua static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; - SoundInstance_BindLua(lua_State* L) { } + SoundInstance_BindLua(lua_State* L); ~SoundInstance_BindLua() { } int SetSubmixType(lua_State* L); diff --git a/WickedEngine/wiLoadingScreen.cpp b/WickedEngine/wiLoadingScreen.cpp index 00d649617..95ca3febf 100644 --- a/WickedEngine/wiLoadingScreen.cpp +++ b/WickedEngine/wiLoadingScreen.cpp @@ -78,14 +78,32 @@ namespace wi if (backgroundTexture.IsValid()) { wi::image::Params fx; - fx.enableFullScreen(); - fx.blendFlag = wi::enums::BLENDMODE_PREMULTIPLIED; + const Texture& tex = backgroundTexture.GetTexture(); + const TextureDesc& desc = tex.GetDesc(); + + const float canvas_aspect = GetLogicalWidth() / GetLogicalHeight(); + const float image_aspect = float(desc.width) / float(desc.height); + + if (canvas_aspect > image_aspect) + { + // display aspect is wider than image: + fx.siz.x = GetLogicalWidth() / canvas_aspect * image_aspect; + fx.siz.y = GetLogicalHeight(); + } + else + { + // image aspect is wider or equal to display + fx.siz.x = GetLogicalWidth(); + fx.siz.y = GetLogicalHeight() * canvas_aspect / image_aspect; + } + + fx.pos = XMFLOAT3(GetLogicalWidth() * 0.5f, GetLogicalHeight() * 0.5f, 0); + fx.pivot = XMFLOAT2(0.5f, 0.5f); + fx.blendFlag = wi::enums::BLENDMODE_ALPHA; if (colorspace != ColorSpace::SRGB) { - // Convert the regular SRGB result of the render path to linear space for HDR compositing: fx.enableLinearOutputMapping(hdr_scaling); } - const Texture& tex = backgroundTexture.GetTexture(); wi::image::Draw(&tex, fx, cmd); } diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 3eebbfa34..8ee2707bf 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -3183,43 +3183,24 @@ void UpdateVisibility(Visibility& vis) if (vis.flags & Visibility::ALLOW_DECALS) { - const uint32_t decal_loop = (uint32_t)std::min(vis.scene->aabb_decals.size(), vis.scene->decals.GetCount()); - vis.visibleDecals.resize(decal_loop); - wi::jobsystem::Dispatch(ctx, decal_loop, groupSize, [&](wi::jobsystem::JobArgs args) { - - // Setup stream compaction: - uint32_t& group_count = *(uint32_t*)args.sharedmemory; - uint32_t* group_list = (uint32_t*)args.sharedmemory + 1; - if (args.isFirstJobInGroup) + // Note: decals must be appended in order for correct blending, must not use parallelization! + wi::jobsystem::Execute(ctx, [&](wi::jobsystem::JobArgs args) { + for (size_t i = 0; i < vis.scene->aabb_decals.size(); ++i) { - group_count = 0; // first thread initializes local counter - } + const AABB& aabb = vis.scene->aabb_decals[i]; - const AABB& aabb = vis.scene->aabb_decals[args.jobIndex]; - - if ((aabb.layerMask & vis.layerMask) && vis.frustum.CheckBoxFast(aabb)) - { - // Local stream compaction: - group_list[group_count++] = args.jobIndex; - } - - // Global stream compaction: - if (args.isLastJobInGroup && group_count > 0) - { - uint32_t prev_count = vis.decal_counter.fetch_add(group_count); - for (uint32_t i = 0; i < group_count; ++i) + if ((aabb.layerMask & vis.layerMask) && vis.frustum.CheckBoxFast(aabb)) { - vis.visibleDecals[prev_count + i] = group_list[i]; + vis.visibleDecals.push_back(uint32_t(i)); } } - - }, sharedmemory_size); + }); } if (vis.flags & Visibility::ALLOW_ENVPROBES) { + // Note: probes must be appended in order for correct blending, must not use parallelization! wi::jobsystem::Execute(ctx, [&](wi::jobsystem::JobArgs args) { - // Cull probes: for (size_t i = 0; i < vis.scene->aabb_probes.size(); ++i) { const AABB& aabb = vis.scene->aabb_probes[i]; @@ -3279,7 +3260,6 @@ void UpdateVisibility(Visibility& vis) // finalize stream compaction: vis.visibleObjects.resize((size_t)vis.object_counter.load()); - vis.visibleDecals.resize((size_t)vis.decal_counter.load()); vis.visibleLights.resize((size_t)vis.light_counter.load()); if (vis.scene->weather.IsOceanEnabled()) diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 1968d2c6f..07101be9f 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -137,7 +137,6 @@ namespace wi::renderer std::atomic object_counter; std::atomic light_counter; - std::atomic decal_counter; wi::SpinLock locker; bool planar_reflection_visible = false; @@ -156,7 +155,6 @@ namespace wi::renderer object_counter.store(0); light_counter.store(0); - decal_counter.store(0); closestRefPlane = std::numeric_limits::max(); planar_reflection_visible = false; diff --git a/WickedEngine/wiSpriteFont_BindLua.cpp b/WickedEngine/wiSpriteFont_BindLua.cpp index adb9e161f..362ee6bef 100644 --- a/WickedEngine/wiSpriteFont_BindLua.cpp +++ b/WickedEngine/wiSpriteFont_BindLua.cpp @@ -424,7 +424,7 @@ namespace wi::lua wi::lua::SError(L, "SetTypewriterSound(Sound sound, SoundInstance soundinstance) second argument is not a sound instance!"); return 0; } - font.anim.typewriter.sound = sound->sound; + font.anim.typewriter.sound = sound->soundResource.GetSound(); font.anim.typewriter.soundinstance = soundinstance->soundinstance; return 0; } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 6c8ae8b50..9f0d158e2 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 401; + const int revision = 402; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);