loading screen: background image always scaled to best fit screen while keeping correct aspect;

audio lua binding simplified constructors;
This commit is contained in:
Turánszki János
2024-03-19 08:40:23 +01:00
parent bef7cef6f8
commit ef401d2235
8 changed files with 88 additions and 46 deletions
@@ -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
+45 -6
View File
@@ -32,8 +32,8 @@ namespace wi::lua
Sound_BindLua* sound = Luna<Sound_BindLua>::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<Sound_BindLua>::lightcheck(L, 1);
Sound_BindLua* s = Luna<Sound_BindLua>::lightcheck(L, 1);
SoundInstance_BindLua* soundinstance = Luna<SoundInstance_BindLua>::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<Sound_BindLua>::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);
+8 -4
View File
@@ -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<Sound_BindLua>::FunctionType methods[];
static Luna<Sound_BindLua>::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<SoundInstance_BindLua>::FunctionType methods[];
static Luna<SoundInstance_BindLua>::PropertyType properties[];
SoundInstance_BindLua(lua_State* L) { }
SoundInstance_BindLua(lua_State* L);
~SoundInstance_BindLua() { }
int SetSubmixType(lua_State* L);
+22 -4
View File
@@ -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);
}
+8 -28
View File
@@ -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())
-2
View File
@@ -137,7 +137,6 @@ namespace wi::renderer
std::atomic<uint32_t> object_counter;
std::atomic<uint32_t> light_counter;
std::atomic<uint32_t> 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<float>::max();
planar_reflection_visible = false;
+1 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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);