Skip to content

Commit e624603

Browse files
authored
Make clang-format compatible with VS (#1213)
The previous [PR](#1201) assumed clang-format version 11. VS2022 uses version 15. This change will make the formatting compatible with VS.
1 parent d0278b9 commit e624603

File tree

11 files changed

+183
-197
lines changed

11 files changed

+183
-197
lines changed

.clang-format

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
1-
BasedOnStyle: LLVM
2-
1+
---
32
Language: Cpp
3+
# BasedOnStyle: LLVM
44

5-
AlignOperands: true
6-
BreakBeforeBraces: Allman
7-
BreakConstructorInitializersBeforeComma: true
5+
AccessModifierOffset: -4
6+
AlignAfterOpenBracket: DontAlign
7+
AlignEscapedNewlines: Left
8+
BraceWrapping:
9+
AfterCaseLabel: true
10+
AfterClass: true
11+
AfterControlStatement: Always
12+
AfterEnum: true
13+
AfterFunction: true
14+
AfterNamespace: true
15+
AfterObjCDeclaration: true
16+
AfterStruct: true
17+
AfterUnion: true
18+
AfterExternBlock: true
19+
BeforeCatch: true
20+
BeforeElse: true
21+
BeforeWhile: true
22+
BreakBeforeBraces: Custom
823
BreakConstructorInitializers: BeforeComma
24+
BreakStringLiterals: false
925
ColumnLimit: 0
1026
FixNamespaceComments: false
1127
IndentCaseLabels: true
1228
IndentWidth: 4
13-
SortIncludes: false
14-
SpaceAfterTemplateKeyword: false
15-
SpaceBeforeParens: ControlStatements
16-
SpaceBeforeRangeBasedForLoopColon: true
17-
SpacesBeforeTrailingComments: 1
29+
KeepEmptyLinesAtTheStartOfBlocks: false
1830
NamespaceIndentation: All
19-
AccessModifierOffset: -4
31+
ReflowComments: false
32+
PackConstructorInitializers: Never
2033
PointerAlignment: Left
21-
AlwaysBreakTemplateDeclarations: true
22-
AlignAfterOpenBracket: DontAlign
23-
ConstructorInitializerIndentWidth: 4
24-
ContinuationIndentWidth: 4
25-
ConstructorInitializerAllOnOneLineOrOnePerLine: false
26-
AllowShortLambdasOnASingleLine: All
27-
AllowShortCaseLabelsOnASingleLine: true
28-
AllowShortIfStatementsOnASingleLine: WithoutElse
29-
BreakBeforeTernaryOperators: true
34+
SortIncludes: Never
35+
SortUsingDeclarations: false
36+
SpaceAfterTemplateKeyword: false

Core/Graphics/Source/DeviceImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ namespace Babylon::Graphics
2828
init.type = s_bgfxRenderType;
2929
init.resolution.reset = BGFX_RESET_VSYNC | BGFX_RESET_MAXANISOTROPY;
3030
init.resolution.maxFrameLatency = 1;
31-
if (s_bgfxFlipAfterRender) init.resolution.reset |= BGFX_RESET_FLIP_AFTER_RENDER;
31+
if (s_bgfxFlipAfterRender)
32+
init.resolution.reset |= BGFX_RESET_FLIP_AFTER_RENDER;
3233

3334
init.callback = &m_bgfxCallback;
3435
init.platformData = {};

Plugins/NativeCamera/Source/Android/CameraDevice.cpp

Lines changed: 75 additions & 93 deletions
Large diffs are not rendered by default.

Plugins/NativeCamera/Source/Android/CameraWrappers.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,37 @@
2121
#define __INTRODUCED_IN(x)
2222
namespace API24
2323
{
24-
#include <camera/NdkCameraManager.h>
25-
#include <camera/NdkCameraCaptureSession.h>
26-
#include <camera/NdkCameraDevice.h>
27-
#include <camera/NdkCameraError.h>
28-
#include <camera/NdkCameraManager.h>
29-
#include <camera/NdkCameraMetadata.h>
30-
#include <camera/NdkCameraMetadataTags.h>
31-
#include <camera/NdkCameraWindowType.h>
32-
#include <camera/NdkCaptureRequest.h>
24+
#include <camera/NdkCameraManager.h>
25+
#include <camera/NdkCameraCaptureSession.h>
26+
#include <camera/NdkCameraDevice.h>
27+
#include <camera/NdkCameraError.h>
28+
#include <camera/NdkCameraManager.h>
29+
#include <camera/NdkCameraMetadata.h>
30+
#include <camera/NdkCameraMetadataTags.h>
31+
#include <camera/NdkCameraWindowType.h>
32+
#include <camera/NdkCaptureRequest.h>
3333
}
3434
#undef __ANDROID_API__
3535
#define __ANDROID_API__ __ORIG_ANDROID_API__
3636
#undef __ORIG_ANDROID_API__
3737

3838
// Helper macro to make calling camera NDK api's more type safe
39-
#define GET_CAMERA_FUNCTION(function) reinterpret_cast<decltype(&API24::function)>(Babylon::Plugins::GetCameraDynamicFunction(#function))
39+
#define CAMERA_FUNCTION(function, ...) reinterpret_cast<decltype(&API24::function)>(Babylon::Plugins::GetCameraDynamicFunction(#function))(__VA_ARGS__)
4040

4141
namespace
4242
{
43-
const int API_LEVEL{ android_get_device_api_level() };
43+
const int API_LEVEL{android_get_device_api_level()};
4444

4545
// Load the NDK camera lib dynamically. When running on OS 6.0 and below this will return nullptr,
4646
// on OS 7.0 and up this should return a pointer to access the library using dlsym. It is technically fine
4747
// to call dlopen when the API_LEVEL is below 24, but it's wasted effort on those devices.
48-
void* libCamera2NDK{ API_LEVEL >= 24 ? dlopen("libcamera2ndk.so", RTLD_NOW): nullptr };
48+
void* libCamera2NDK{API_LEVEL >= 24 ? dlopen("libcamera2ndk.so", RTLD_NOW) : nullptr};
4949

5050
std::map<std::string, void*> CameraDynamicFunctions{};
5151
}
5252

53-
namespace Babylon::Plugins {
53+
namespace Babylon::Plugins
54+
{
5455
inline void* GetCameraDynamicFunction(const char* functionName)
5556
{
5657
if (!libCamera2NDK)

Plugins/NativeEngine/Source/NativeEngine.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,17 +752,15 @@ namespace Babylon
752752
Napi::Value jsProgram = Napi::Pointer<ProgramData>::Create(info.Env(), program, Napi::NapiPointerDeleter(program));
753753

754754
arcana::make_task(arcana::threadpool_scheduler, *m_cancellationSource,
755-
[this, vertexSource, fragmentSource, cancellationSource{m_cancellationSource}]() -> std::unique_ptr<ProgramData>
756-
{
755+
[this, vertexSource, fragmentSource, cancellationSource{m_cancellationSource}]() -> std::unique_ptr<ProgramData> {
757756
return CreateProgramInternal(vertexSource, fragmentSource);
758757
})
759758
.then(m_runtimeScheduler, *m_cancellationSource,
760759
[program,
761760
jsProgramRef{Napi::Persistent(jsProgram)},
762761
onSuccessRef{Napi::Persistent(onSuccess)},
763762
onErrorRef{Napi::Persistent(onError)},
764-
cancellationSource{m_cancellationSource}](const arcana::expected<std::unique_ptr<ProgramData>, std::exception_ptr>& result)
765-
{
763+
cancellationSource{m_cancellationSource}](const arcana::expected<std::unique_ptr<ProgramData>, std::exception_ptr>& result) {
766764
if (result.has_error())
767765
{
768766
onErrorRef.Call({Napi::Error::New(onErrorRef.Env(), result.error()).Value()});

Plugins/NativeEngine/Source/NativeEngine.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ namespace Babylon
4646
ProgramData(const ProgramData&) = delete;
4747
ProgramData& operator=(const ProgramData&) = delete;
4848

49-
ProgramData(ProgramData&& other) noexcept:
50-
Handle{other.Handle},
51-
Uniforms{std::move(other.Uniforms)},
52-
UniformNameToIndex{std::move(other.UniformNameToIndex)},
53-
UniformInfos{std::move(other.UniformInfos)},
54-
VertexAttributeLocations{std::move(other.VertexAttributeLocations)}
49+
ProgramData(ProgramData&& other) noexcept
50+
: Handle{other.Handle}
51+
, Uniforms{std::move(other.Uniforms)}
52+
, UniformNameToIndex{std::move(other.UniformNameToIndex)}
53+
, UniformInfos{std::move(other.UniformInfos)}
54+
, VertexAttributeLocations{std::move(other.VertexAttributeLocations)}
5555
{
5656
other.Handle = BGFX_INVALID_HANDLE;
5757
}

Plugins/NativeInput/Source/Shared/DeviceInputSystem.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ namespace Babylon::Plugins
88

99
static constexpr auto JS_CONSTRUCTOR_NAME = "DeviceInputSystem";
1010

11-
Napi::Function func
12-
{
11+
Napi::Function func{
1312
DefineClass(
1413
env,
1514
JS_CONSTRUCTOR_NAME,
1615
{
1716
InstanceMethod("pollInput", &DeviceInputSystem::PollInput),
1817
InstanceMethod("isDeviceAvailable", &DeviceInputSystem::IsDeviceAvailable),
1918
InstanceMethod("dispose", &DeviceInputSystem::Dispose),
20-
})
21-
};
19+
})};
2220

2321
JsRuntime::NativeObject::GetFromJavaScript(env).Set(JS_CONSTRUCTOR_NAME, func);
2422
}
@@ -29,24 +27,18 @@ namespace Babylon::Plugins
2927
: Napi::ObjectWrap<DeviceInputSystem>{info}
3028
, m_nativeInput{*NativeInput::GetFromJavaScript(info.Env()).m_impl}
3129
, m_deviceConnectedTicket{m_nativeInput.AddDeviceConnectedCallback([this, callback = std::make_shared<Napi::FunctionReference>(Napi::Persistent(info[0].As<Napi::Function>()))](DeviceType deviceType, int32_t deviceSlot) {
32-
(*callback)({
33-
Napi::Value::From(Env(), static_cast<uint32_t>(deviceType)),
34-
Napi::Value::From(Env(), deviceSlot)
35-
});
30+
(*callback)({Napi::Value::From(Env(), static_cast<uint32_t>(deviceType)),
31+
Napi::Value::From(Env(), deviceSlot)});
3632
})}
3733
, m_deviceDisconnectedTicket{m_nativeInput.AddDeviceDisconnectedCallback([this, callback = std::make_shared<Napi::FunctionReference>(Napi::Persistent(info[1].As<Napi::Function>()))](DeviceType deviceType, int32_t deviceSlot) {
38-
(*callback)({
39-
Napi::Value::From(Env(), static_cast<uint32_t>(deviceType)),
40-
Napi::Value::From(Env(), deviceSlot)
41-
});
34+
(*callback)({Napi::Value::From(Env(), static_cast<uint32_t>(deviceType)),
35+
Napi::Value::From(Env(), deviceSlot)});
4236
})}
4337
, m_InputChangedTicket{m_nativeInput.AddInputChangedCallback([this, callback = std::make_shared<Napi::FunctionReference>(Napi::Persistent(info[2].As<Napi::Function>()))](DeviceType deviceType, int32_t deviceSlot, uint32_t inputIndex, std::optional<int32_t> currentState) {
44-
(*callback)({
45-
Napi::Value::From(Env(), static_cast<uint32_t>(deviceType)),
38+
(*callback)({Napi::Value::From(Env(), static_cast<uint32_t>(deviceType)),
4639
Napi::Value::From(Env(), deviceSlot),
4740
Napi::Value::From(Env(), inputIndex),
48-
currentState ? Napi::Value::From(Env(), *currentState) : Env().Null()
49-
});
41+
currentState ? Napi::Value::From(Env(), *currentState) : Env().Null()});
5042
})}
5143
{
5244
}

Plugins/NativeInput/Source/Shared/NativeInput.cpp

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Babylon::Plugins
3636
}
3737

3838
NativeInput::NativeInput(Napi::Env env)
39-
: m_impl{ std::make_unique<Impl>(env) }
39+
: m_impl{std::make_unique<Impl>(env)}
4040
{
4141
Napi::Value nativeInput = Napi::External<NativeInput>::New(env, this, [](Napi::Env, NativeInput* nativeInput) { delete nativeInput; });
4242
env.Global().Set(JS_NATIVE_INPUT_NAME, nativeInput);
@@ -110,7 +110,7 @@ namespace Babylon::Plugins
110110
POINTER_MOUSEWHEEL_Z_INDEX,
111111
POINTER_DELTA_HORIZONTAL_INDEX,
112112
POINTER_DELTA_VERTICAL_INDEX,
113-
POINTER_MOVE_INDEX
113+
POINTER_MOVE_INDEX,
114114
});
115115
}
116116
}
@@ -153,14 +153,16 @@ namespace Babylon::Plugins
153153
void NativeInput::Impl::PointerDown(uint32_t pointerId, uint32_t buttonIndex, int32_t x, int32_t y, DeviceType deviceType)
154154
{
155155
m_runtimeScheduler([pointerId, buttonIndex, x, y, deviceType, this]() {
156-
const uint32_t inputIndex{ GetPointerButtonInputIndex(buttonIndex) };
157-
std::vector<int32_t>& deviceInputs{ GetOrCreateInputMap(deviceType, pointerId, {
158-
inputIndex,
159-
POINTER_X_INPUT_INDEX,
160-
POINTER_Y_INPUT_INDEX,
161-
POINTER_DELTA_HORIZONTAL_INDEX,
162-
POINTER_DELTA_VERTICAL_INDEX
163-
})};
156+
const uint32_t inputIndex{GetPointerButtonInputIndex(buttonIndex)};
157+
std::vector<int32_t>& deviceInputs{
158+
GetOrCreateInputMap(deviceType, pointerId,
159+
{
160+
inputIndex,
161+
POINTER_X_INPUT_INDEX,
162+
POINTER_Y_INPUT_INDEX,
163+
POINTER_DELTA_HORIZONTAL_INDEX,
164+
POINTER_DELTA_VERTICAL_INDEX,
165+
})};
164166

165167
// Record the x/y, but don't raise associated events (this matches the behavior in the browser).
166168
SetInputState(deviceType, pointerId, POINTER_DELTA_HORIZONTAL_INDEX, 0, deviceInputs, false);
@@ -176,14 +178,16 @@ namespace Babylon::Plugins
176178
void NativeInput::Impl::PointerUp(uint32_t pointerId, uint32_t buttonIndex, int32_t x, int32_t y, DeviceType deviceType)
177179
{
178180
m_runtimeScheduler([pointerId, buttonIndex, x, y, deviceType, this]() {
179-
const uint32_t inputIndex{ GetPointerButtonInputIndex(buttonIndex) };
180-
std::vector<int32_t>& deviceInputs{ GetOrCreateInputMap(deviceType, pointerId, {
181-
inputIndex,
182-
POINTER_X_INPUT_INDEX,
183-
POINTER_Y_INPUT_INDEX,
184-
POINTER_DELTA_HORIZONTAL_INDEX,
185-
POINTER_DELTA_VERTICAL_INDEX
186-
})};
181+
const uint32_t inputIndex{GetPointerButtonInputIndex(buttonIndex)};
182+
std::vector<int32_t>& deviceInputs{
183+
GetOrCreateInputMap(deviceType, pointerId,
184+
{
185+
inputIndex,
186+
POINTER_X_INPUT_INDEX,
187+
POINTER_Y_INPUT_INDEX,
188+
POINTER_DELTA_HORIZONTAL_INDEX,
189+
POINTER_DELTA_VERTICAL_INDEX,
190+
})};
187191

188192
// Record the x/y, but don't raise associated events (this matches the behavior in the browser).
189193
SetInputState(deviceType, pointerId, POINTER_DELTA_HORIZONTAL_INDEX, 0, deviceInputs, false);
@@ -208,13 +212,15 @@ namespace Babylon::Plugins
208212
void NativeInput::Impl::PointerMove(uint32_t pointerId, int32_t x, int32_t y, DeviceType deviceType)
209213
{
210214
m_runtimeScheduler([pointerId, x, y, deviceType, this]() {
211-
std::vector<int32_t>& deviceInputs{GetOrCreateInputMap(deviceType, pointerId, {
212-
POINTER_X_INPUT_INDEX,
213-
POINTER_Y_INPUT_INDEX,
214-
POINTER_DELTA_HORIZONTAL_INDEX,
215-
POINTER_DELTA_VERTICAL_INDEX,
216-
POINTER_MOVE_INDEX
217-
})};
215+
std::vector<int32_t>& deviceInputs{
216+
GetOrCreateInputMap(deviceType, pointerId,
217+
{
218+
POINTER_X_INPUT_INDEX,
219+
POINTER_Y_INPUT_INDEX,
220+
POINTER_DELTA_HORIZONTAL_INDEX,
221+
POINTER_DELTA_VERTICAL_INDEX,
222+
POINTER_MOVE_INDEX,
223+
})};
218224
int32_t deltaX = 0;
219225
int32_t deltaY = 0;
220226

@@ -240,21 +246,19 @@ namespace Babylon::Plugins
240246
SetInputState(deviceType, pointerId, POINTER_DELTA_HORIZONTAL_INDEX, 0, deviceInputs, false);
241247
SetInputState(deviceType, pointerId, POINTER_DELTA_VERTICAL_INDEX, 0, deviceInputs, false);
242248
m_eventDispatcher.tick(arcana::cancellation::none());
243-
244249
});
245250
}
246251

247252
void NativeInput::Impl::PointerScroll(uint32_t pointerId, uint32_t scrollAxis, int32_t scrollValue, DeviceType deviceType)
248253
{
249-
m_runtimeScheduler([pointerId, scrollAxis, scrollValue, deviceType, this]()
250-
{
251-
std::vector<int32_t>& deviceInputs{GetOrCreateInputMap(deviceType, pointerId, {scrollAxis})};
252-
SetInputState(deviceType, pointerId, scrollAxis, scrollValue, deviceInputs, true);
254+
m_runtimeScheduler([pointerId, scrollAxis, scrollValue, deviceType, this]() {
255+
std::vector<int32_t>& deviceInputs{GetOrCreateInputMap(deviceType, pointerId, {scrollAxis})};
256+
SetInputState(deviceType, pointerId, scrollAxis, scrollValue, deviceInputs, true);
253257

254-
m_eventDispatcher.tick(arcana::cancellation::none());
255-
SetInputState(deviceType, pointerId, scrollAxis, 0, deviceInputs, true);
256-
m_eventDispatcher.tick(arcana::cancellation::none());
257-
});
258+
m_eventDispatcher.tick(arcana::cancellation::none());
259+
SetInputState(deviceType, pointerId, scrollAxis, 0, deviceInputs, true);
260+
m_eventDispatcher.tick(arcana::cancellation::none());
261+
});
258262
}
259263

260264
NativeInput::Impl::DeviceStatusChangedCallbackTicket NativeInput::Impl::AddDeviceConnectedCallback(NativeInput::Impl::DeviceStatusChangedCallback&& callback)
@@ -265,15 +269,15 @@ namespace Babylon::Plugins
265269
callback(key.first, key.second);
266270
}
267271

268-
return m_deviceConnectedCallbacks.insert(std::move(callback));
272+
return m_deviceConnectedCallbacks.insert(std::move(callback));
269273
}
270274

271275
NativeInput::Impl::DeviceStatusChangedCallbackTicket NativeInput::Impl::AddDeviceDisconnectedCallback(NativeInput::Impl::DeviceStatusChangedCallback&& callback)
272276
{
273277
return m_deviceDisconnectedCallbacks.insert(std::move(callback));
274278
}
275279

276-
NativeInput::Impl::InputStateChangedCallbackTicket NativeInput::Impl::AddInputChangedCallback(NativeInput::Impl::InputStateChangedCallback &&callback)
280+
NativeInput::Impl::InputStateChangedCallbackTicket NativeInput::Impl::AddInputChangedCallback(NativeInput::Impl::InputStateChangedCallback&& callback)
277281
{
278282
return m_inputChangedCallbacks.insert(std::move(callback));
279283
}
@@ -285,15 +289,15 @@ namespace Babylon::Plugins
285289
{
286290
std::ostringstream message;
287291
message << "Unable to find device of type " << static_cast<uint32_t>(deviceType) << " with slot " << deviceSlot;
288-
throw std::runtime_error{ message.str() };
292+
throw std::runtime_error{message.str()};
289293
}
290294

291295
const auto& device = it->second;
292296
if (inputIndex >= device.size())
293297
{
294298
std::ostringstream message;
295299
message << "Unable to find " << inputIndex << " on device of type " << static_cast<uint32_t>(deviceType) << " with slot " << deviceSlot;
296-
throw std::runtime_error{ message.str() };
300+
throw std::runtime_error{message.str()};
297301
}
298302

299303
return device.at(inputIndex);
@@ -331,7 +335,7 @@ namespace Babylon::Plugins
331335
if (m_inputs.erase({deviceType, deviceSlot}))
332336
{
333337
m_eventDispatcher.queue([this, deviceType, deviceSlot]() {
334-
m_deviceDisconnectedCallbacks.apply_to_all([deviceType, deviceSlot](auto& callback){
338+
m_deviceDisconnectedCallbacks.apply_to_all([deviceType, deviceSlot](auto& callback) {
335339
callback(deviceType, deviceSlot);
336340
});
337341
});

Plugins/NativeXr/Source/NativeXr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,8 @@ namespace Babylon
557557
// Block and burn frames until XR successfully shuts down.
558558
m_sessionState->Frame = m_sessionState->Session->GetNextFrame(shouldEndSession, shouldRestartSession);
559559
m_sessionState->Frame.reset();
560-
} while (!shouldEndSession);
560+
}
561+
while (!shouldEndSession);
561562

562563
m_sessionState.reset();
563564
m_beginTask.reset();

0 commit comments

Comments
 (0)