Skip to content

Commit 423ed5e

Browse files
committed
More style fixes
1 parent e9d229d commit 423ed5e

File tree

9 files changed

+88
-97
lines changed

9 files changed

+88
-97
lines changed

Core/AppRuntime/Source/AppRuntime.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ namespace Babylon
1313
: m_workQueue{std::make_unique<WorkQueue>([this] { RunPlatformTier(); })}
1414
, m_unhandledExceptionHandler{unhandledExceptionHandler}
1515
{
16-
Dispatch([this](Napi::Env env)
17-
{
16+
Dispatch([this](Napi::Env env) {
1817
JsRuntime::CreateForJavaScript(env, [this](auto func) { Dispatch(std::move(func)); });
1918
});
2019
}
@@ -24,8 +23,7 @@ namespace Babylon
2423
// Notify the JsRuntime on the JavaScript thread that the JavaScript
2524
// runtime shutdown sequence has begun. The JsRuntimeScheduler will
2625
// use this signal to gracefully cancel asynchronous operations.
27-
Dispatch([](Napi::Env env)
28-
{
26+
Dispatch([](Napi::Env env) {
2927
JsRuntime::NotifyDisposing(JsRuntime::GetFromJavaScript(env));
3028
});
3129
}
@@ -47,10 +45,8 @@ namespace Babylon
4745

4846
void AppRuntime::Dispatch(Dispatchable<void(Napi::Env)> func)
4947
{
50-
m_workQueue->Append([this, func{std::move(func)}](Napi::Env env) mutable
51-
{
52-
Execute([this, env, func{std::move(func)}]() mutable
53-
{
48+
m_workQueue->Append([this, func{std::move(func)}](Napi::Env env) mutable {
49+
Execute([this, env, func{std::move(func)}]() mutable {
5450
try
5551
{
5652
func(env);

Core/AppRuntime/Source/AppRuntime_Chakra.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ namespace Babylon
2929
ThrowIfFailed(JsSetCurrentContext(context));
3030
ThrowIfFailed(JsSetPromiseContinuationCallback(
3131
[](JsValueRef task, void* callbackState) {
32-
auto* pThis = reinterpret_cast<AppRuntime*>(callbackState);
33-
ThrowIfFailed(JsAddRef(task, nullptr));
34-
pThis->Dispatch([task](auto) {
35-
JsValueRef global;
36-
ThrowIfFailed(JsGetGlobalObject(&global));
37-
ThrowIfFailed(JsCallFunction(task, &global, 1, nullptr));
38-
ThrowIfFailed(JsRelease(task, nullptr));
39-
});
40-
}, this));
32+
auto* pThis = reinterpret_cast<AppRuntime*>(callbackState);
33+
ThrowIfFailed(JsAddRef(task, nullptr));
34+
pThis->Dispatch([task](auto) {
35+
JsValueRef global;
36+
ThrowIfFailed(JsGetGlobalObject(&global));
37+
ThrowIfFailed(JsCallFunction(task, &global, 1, nullptr));
38+
ThrowIfFailed(JsRelease(task, nullptr));
39+
});
40+
},
41+
this));
4142
ThrowIfFailed(JsProjectWinRTNamespace(L"Windows"));
4243

4344
#if defined(_DEBUG)

Core/Graphics/Source/DeviceImpl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ namespace Babylon::Graphics
304304
{
305305
arcana::task_completion_source<std::vector<uint8_t>, std::exception_ptr> taskCompletionSource{};
306306

307-
m_screenShotCallbacks.push([taskCompletionSource](std::vector<uint8_t> bytes) mutable
308-
{
307+
m_screenShotCallbacks.push([taskCompletionSource](std::vector<uint8_t> bytes) mutable {
309308
taskCompletionSource.complete(std::move(bytes));
310309
});
311310

Core/JsRuntime/InternalInclude/Babylon/JsRuntimeScheduler.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ namespace Babylon
2828
// // Wait for asynchronous operations to complete.
2929
// m_runtimeScheduler.Rundown();
3030
// }
31-
//
31+
//
3232
// void MyFunction(const Napi::CallbackInfo& info)
3333
// {
3434
// const auto callback{info[0].As<Napi::Function>()};
35-
//
35+
//
3636
// arcana::make_task(arcana::threadpool_scheduler, m_cancellationSource, []() {
3737
// // do some asynchronous work
3838
// }).then(m_runtimeScheduler.Get(), m_cancellationSource, [thisRef = Napi::Persistent(info.This()), callback = Napi::Persistent(callback)]() {
@@ -101,7 +101,8 @@ namespace Babylon
101101
class SchedulerImpl
102102
{
103103
public:
104-
explicit SchedulerImpl(JsRuntimeScheduler& parent) : m_parent{parent}
104+
explicit SchedulerImpl(JsRuntimeScheduler& parent)
105+
: m_parent{parent}
105106
{
106107
}
107108

@@ -122,8 +123,7 @@ namespace Babylon
122123

123124
if (m_runtime != nullptr)
124125
{
125-
m_runtime->Dispatch([callable{std::forward<CallableT>(callable)}](Napi::Env)
126-
{
126+
m_runtime->Dispatch([callable{std::forward<CallableT>(callable)}](Napi::Env) {
127127
callable();
128128
});
129129
}

Plugins/NativeEngine/Source/NativeEngine.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,14 +1132,11 @@ namespace Babylon
11321132
const auto textureDestination = info[0].As<Napi::Pointer<Graphics::Texture>>().Get();
11331133
const auto textureSource = info[1].As<Napi::Pointer<Graphics::Texture>>().Get();
11341134

1135-
arcana::make_task(m_update.Scheduler(), m_cancellationSource, [this, textureDestination, textureSource]() mutable
1136-
{
1137-
return arcana::make_task(m_runtimeScheduler.Get(), m_cancellationSource, [this, textureDestination, textureSource, updateToken = m_update.GetUpdateToken()]() mutable
1138-
{
1135+
arcana::make_task(m_update.Scheduler(), m_cancellationSource, [this, textureDestination, textureSource]() mutable {
1136+
return arcana::make_task(m_runtimeScheduler.Get(), m_cancellationSource, [this, textureDestination, textureSource, updateToken = m_update.GetUpdateToken()]() mutable {
11391137
bgfx::Encoder* encoder = updateToken.GetEncoder();
11401138
GetBoundFrameBuffer(*encoder).Blit(*encoder, textureDestination->Handle(), 0, 0, textureSource->Handle());
1141-
}).then(arcana::inline_scheduler, m_cancellationSource, [this](const arcana::expected<void, std::exception_ptr>& result)
1142-
{
1139+
}).then(arcana::inline_scheduler, m_cancellationSource, [this](const arcana::expected<void, std::exception_ptr>& result) {
11431140
if (result.has_error())
11441141
{
11451142
Napi::Error::New(Env(), result.error()).ThrowAsJavaScriptException();

Plugins/NativeXr/Source/NativeXr.cpp

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -696,47 +696,47 @@ namespace Babylon
696696
bgfx::overrideInternal(colorTexture, reinterpret_cast<uintptr_t>(viewConfig.ColorTexturePointer));
697697
bgfx::overrideInternal(depthTexture, reinterpret_cast<uintptr_t>(viewConfig.DepthTexturePointer));
698698
}).then(m_runtimeScheduler.Get(), m_sessionState->CancellationSource, [this, thisRef{shared_from_this()}, colorTexture, depthTexture, requiresAppClear, &viewConfig]() {
699-
const auto eyeCount = std::max(static_cast<uint16_t>(1), static_cast<uint16_t>(viewConfig.ViewTextureSize.Depth));
700-
// TODO (rgerd): Remove old framebuffers from resource table?
701-
viewConfig.FrameBuffers.resize(eyeCount);
702-
for (uint16_t eyeIdx = 0; eyeIdx < eyeCount; eyeIdx++)
703-
{
704-
std::array<bgfx::Attachment, 2> attachments{};
705-
attachments[0].init(colorTexture, bgfx::Access::Write, eyeIdx);
706-
attachments[1].init(depthTexture, bgfx::Access::Write, eyeIdx);
707-
708-
auto frameBufferHandle = bgfx::createFrameBuffer(static_cast<uint8_t>(attachments.size()), attachments.data(), false);
709-
710-
const auto frameBufferPtr = new Graphics::FrameBuffer(
711-
m_sessionState->GraphicsContext,
712-
frameBufferHandle,
713-
static_cast<uint16_t>(viewConfig.ViewTextureSize.Width),
714-
static_cast<uint16_t>(viewConfig.ViewTextureSize.Height),
715-
true,
716-
true,
717-
true);
718-
719-
auto& frameBuffer = *frameBufferPtr;
720-
721-
// WebXR, at least in its current implementation, specifies an implicit default clear to black.
722-
// https://immersive-web.github.io/webxr/#xrwebgllayer-interface
723-
frameBuffer.Clear(*m_sessionState->Update.GetUpdateToken().GetEncoder(), BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH | BGFX_CLEAR_STENCIL, 0, 1.0f, 0);
724-
725-
viewConfig.FrameBuffers[eyeIdx] = frameBufferPtr;
726-
727-
auto jsWidth{Napi::Value::From(m_env, viewConfig.ViewTextureSize.Width)};
728-
auto jsHeight{Napi::Value::From(m_env, viewConfig.ViewTextureSize.Height)};
729-
auto jsFrameBuffer{Napi::Pointer<Graphics::FrameBuffer>::Create(m_env, frameBufferPtr, Napi::NapiPointerDeleter(frameBufferPtr))};
730-
viewConfig.JsTextures[frameBufferPtr] = Napi::Persistent(m_sessionState->CreateRenderTexture.Call({jsWidth, jsHeight, jsFrameBuffer}).As<Napi::Object>());
731-
// OpenXR doesn't pre-clear textures, and so we need to make sure the render target gets cleared before rendering the scene.
732-
// ARCore and ARKit effectively pre-clear by pre-compositing the camera feed.
733-
if (requiresAppClear)
734-
{
735-
viewConfig.JsTextures[frameBufferPtr].Set("skipInitialClear", false);
736-
}
737-
}
738-
viewConfig.Initialized = true;
739-
}).then(arcana::inline_scheduler, m_sessionState->CancellationSource, [env{m_env}](const arcana::expected<void, std::exception_ptr>& result) {
699+
const auto eyeCount = std::max(static_cast<uint16_t>(1), static_cast<uint16_t>(viewConfig.ViewTextureSize.Depth));
700+
// TODO (rgerd): Remove old framebuffers from resource table?
701+
viewConfig.FrameBuffers.resize(eyeCount);
702+
for (uint16_t eyeIdx = 0; eyeIdx < eyeCount; eyeIdx++)
703+
{
704+
std::array<bgfx::Attachment, 2> attachments{};
705+
attachments[0].init(colorTexture, bgfx::Access::Write, eyeIdx);
706+
attachments[1].init(depthTexture, bgfx::Access::Write, eyeIdx);
707+
708+
auto frameBufferHandle = bgfx::createFrameBuffer(static_cast<uint8_t>(attachments.size()), attachments.data(), false);
709+
710+
const auto frameBufferPtr = new Graphics::FrameBuffer(
711+
m_sessionState->GraphicsContext,
712+
frameBufferHandle,
713+
static_cast<uint16_t>(viewConfig.ViewTextureSize.Width),
714+
static_cast<uint16_t>(viewConfig.ViewTextureSize.Height),
715+
true,
716+
true,
717+
true);
718+
719+
auto& frameBuffer = *frameBufferPtr;
720+
721+
// WebXR, at least in its current implementation, specifies an implicit default clear to black.
722+
// https://immersive-web.github.io/webxr/#xrwebgllayer-interface
723+
frameBuffer.Clear(*m_sessionState->Update.GetUpdateToken().GetEncoder(), BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH | BGFX_CLEAR_STENCIL, 0, 1.0f, 0);
724+
725+
viewConfig.FrameBuffers[eyeIdx] = frameBufferPtr;
726+
727+
auto jsWidth{Napi::Value::From(m_env, viewConfig.ViewTextureSize.Width)};
728+
auto jsHeight{Napi::Value::From(m_env, viewConfig.ViewTextureSize.Height)};
729+
auto jsFrameBuffer{Napi::Pointer<Graphics::FrameBuffer>::Create(m_env, frameBufferPtr, Napi::NapiPointerDeleter(frameBufferPtr))};
730+
viewConfig.JsTextures[frameBufferPtr] = Napi::Persistent(m_sessionState->CreateRenderTexture.Call({jsWidth, jsHeight, jsFrameBuffer}).As<Napi::Object>());
731+
// OpenXR doesn't pre-clear textures, and so we need to make sure the render target gets cleared before rendering the scene.
732+
// ARCore and ARKit effectively pre-clear by pre-compositing the camera feed.
733+
if (requiresAppClear)
734+
{
735+
viewConfig.JsTextures[frameBufferPtr].Set("skipInitialClear", false);
736+
}
737+
}
738+
viewConfig.Initialized = true;
739+
}).then(arcana::inline_scheduler, m_sessionState->CancellationSource, [env{m_env}](const arcana::expected<void, std::exception_ptr>& result) {
740740
if (result.has_error())
741741
{
742742
Napi::Error::New(env, result.error()).ThrowAsJavaScriptException();
@@ -3427,10 +3427,9 @@ namespace Babylon
34273427

34283428
// Fire off the IsSessionSupported task.
34293429
xr::System::IsSessionSupportedAsync(sessionType)
3430-
.then(m_runtimeScheduler.Get(), arcana::cancellation::none(), [deferred, thisRef = Napi::Persistent(info.This())](bool result)
3431-
{
3432-
deferred.Resolve(Napi::Boolean::New(thisRef.Env(), result));
3433-
});
3430+
.then(m_runtimeScheduler.Get(), arcana::cancellation::none(), [deferred, thisRef = Napi::Persistent(info.This())](bool result) {
3431+
deferred.Resolve(Napi::Boolean::New(thisRef.Env(), result));
3432+
});
34343433

34353434
return deferred.Promise();
34363435
}

Polyfills/Canvas/Source/Canvas.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ namespace Babylon::Polyfills::Internal
2222
Napi::Function func = DefineClass(
2323
env,
2424
JS_CONSTRUCTOR_NAME,
25-
{StaticMethod("loadTTFAsync", &NativeCanvas::LoadTTFAsync),
25+
{
26+
StaticMethod("loadTTFAsync", &NativeCanvas::LoadTTFAsync),
2627
InstanceAccessor("width", &NativeCanvas::GetWidth, &NativeCanvas::SetWidth),
2728
InstanceAccessor("height", &NativeCanvas::GetHeight, &NativeCanvas::SetHeight),
2829
InstanceMethod("getContext", &NativeCanvas::GetContext),
2930
InstanceMethod("getCanvasTexture", &NativeCanvas::GetCanvasTexture),
3031
InstanceMethod("dispose", &NativeCanvas::Dispose),
31-
StaticMethod("parseColor", &NativeCanvas::ParseColor)});
32+
StaticMethod("parseColor", &NativeCanvas::ParseColor),
33+
});
3234

3335
JsRuntime::NativeObject::GetFromJavaScript(env).Set(JS_CONSTRUCTOR_NAME, func);
3436
}
@@ -63,11 +65,9 @@ namespace Babylon::Polyfills::Internal
6365

6466
auto& deviceContext = Graphics::DeviceContext::GetFromJavaScript(info.Env());
6567
auto update = deviceContext.GetUpdate("update");
66-
arcana::make_task(update.Scheduler(), arcana::cancellation::none(), [fontName = std::move(fontName), fontData = std::move(fontBuffer), &runtime, deferred = std::move(deferred)]() mutable
67-
{
68+
arcana::make_task(update.Scheduler(), arcana::cancellation::none(), [fontName = std::move(fontName), fontData = std::move(fontBuffer), &runtime, deferred = std::move(deferred)]() mutable {
6869
fontsInfos[fontName] = fontData;
69-
runtime.Dispatch([deferred = std::move(deferred)](Napi::Env env)
70-
{
70+
runtime.Dispatch([deferred = std::move(deferred)](Napi::Env env) {
7171
deferred.Resolve(env.Undefined());
7272
});
7373
});

Polyfills/Canvas/Source/Context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ namespace Babylon::Polyfills::Internal
471471
nvgFillPaint(m_nvg, imagePaint);
472472
nvgFill(m_nvg);
473473
SetDirty(info.This());
474-
}
474+
}
475475
else if (info.Length() == 5)
476476
{
477477
const auto dx = info[1].As<Napi::Number>().Int32Value();

Polyfills/XMLHttpRequest/Source/XMLHttpRequest.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,20 @@ namespace Babylon::Polyfills::Internal
224224

225225
m_request.SendAsync()
226226
.then(m_runtimeScheduler.Get(), m_cancellationSource,
227-
[this, thisRef = Napi::Persistent(info.This())](arcana::expected<void, std::exception_ptr> result)
228-
{
229-
if (result.has_error())
230-
{
231-
Napi::Error::New(thisRef.Env(), result.error()).ThrowAsJavaScriptException();
232-
return;
233-
}
234-
235-
SetReadyState(ReadyState::Done);
236-
RaiseEvent(EventType::LoadEnd);
237-
238-
// Assume the XMLHttpRequest will only be used for a single request and clear the event handlers.
239-
// Single use seems to be the standard pattern, and we need to release our strong refs to event handlers.
240-
m_eventHandlerRefs.clear();
241-
});
227+
[this, thisRef = Napi::Persistent(info.This())](arcana::expected<void, std::exception_ptr> result) {
228+
if (result.has_error())
229+
{
230+
Napi::Error::New(thisRef.Env(), result.error()).ThrowAsJavaScriptException();
231+
return;
232+
}
233+
234+
SetReadyState(ReadyState::Done);
235+
RaiseEvent(EventType::LoadEnd);
236+
237+
// Assume the XMLHttpRequest will only be used for a single request and clear the event handlers.
238+
// Single use seems to be the standard pattern, and we need to release our strong refs to event handlers.
239+
m_eventHandlerRefs.clear();
240+
});
242241
}
243242

244243
void XMLHttpRequest::SetReadyState(ReadyState readyState)

0 commit comments

Comments
 (0)