Skip to content

Commit 07182c0

Browse files
committed
clang-format everything
Including unix newlines
1 parent 78ef6f7 commit 07182c0

35 files changed

+329
-321
lines changed

.clang-format

+32-30
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
BasedOnStyle: Google
2-
AlignAfterOpenBracket: AlwaysBreak
3-
AlignConsecutiveDeclarations: 'false'
4-
AlignEscapedNewlinesLeft: DontAlign
5-
AlignOperands: 'false'
6-
AlignTrailingComments: 'false'
7-
AllowAllParametersOfDeclarationOnNextLine: 'false'
8-
AllowShortBlocksOnASingleLine: 'false'
9-
AllowShortFunctionsOnASingleLine: false
10-
AllowShortIfStatementsOnASingleLine: 'false'
11-
AllowShortLoopsOnASingleLine: 'false'
12-
BinPackArguments: 'false'
13-
BinPackParameters: 'false'
14-
BreakBeforeBinaryOperators: 'true'
15-
ColumnLimit: '80'
16-
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
17-
ConstructorInitializerIndentWidth: '2'
18-
ContinuationIndentWidth: '2'
19-
IndentRequires: true
20-
IndentWidth: '2'
21-
MaxEmptyLinesToKeep: '1'
22-
PointerAlignment: Left
23-
ReflowComments: true
24-
SpaceBeforeCpp11BracedList: 'true'
25-
SpaceBeforeAssignmentOperators: 'true'
26-
SpaceBeforeRangeBasedForLoopColon: 'false'
27-
SpacesBeforeTrailingComments: '0'
28-
Standard: c++20
29-
TabWidth: '2'
30-
UseTab: Never
1+
BasedOnStyle: Google
2+
AlignAfterOpenBracket: AlwaysBreak
3+
AlignConsecutiveDeclarations: 'false'
4+
AlignEscapedNewlinesLeft: DontAlign
5+
AlignOperands: 'false'
6+
AlignTrailingComments: 'false'
7+
AllowAllParametersOfDeclarationOnNextLine: 'false'
8+
AllowShortBlocksOnASingleLine: 'false'
9+
AllowShortFunctionsOnASingleLine: false
10+
AllowShortIfStatementsOnASingleLine: 'false'
11+
AllowShortLoopsOnASingleLine: 'false'
12+
BinPackArguments: 'false'
13+
BinPackParameters: 'false'
14+
BreakBeforeBinaryOperators: 'true'
15+
ColumnLimit: '80'
16+
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
17+
ConstructorInitializerIndentWidth: '2'
18+
ContinuationIndentWidth: '2'
19+
DeriveLineEnding: false
20+
IndentRequires: true
21+
IndentWidth: '2'
22+
MaxEmptyLinesToKeep: '1'
23+
PointerAlignment: Left
24+
ReflowComments: true
25+
SpaceBeforeCpp11BracedList: 'true'
26+
SpaceBeforeAssignmentOperators: 'true'
27+
SpaceBeforeRangeBasedForLoopColon: 'false'
28+
SpacesBeforeTrailingComments: '0'
29+
Standard: c++20
30+
TabWidth: '2'
31+
UseCRLF: false
32+
UseTab: Never

lib/AxisToHat.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#include <cstdint>
1111

12-
#include "Source.h"
1312
#include "SinkRef.h"
13+
#include "Source.h"
1414

1515
namespace fredemmott::inputmapping {
1616

@@ -31,8 +31,7 @@ class AxisToHat final : public HatSource {
3131
update();
3232
};
3333

34-
AxisToHat(
35-
uint8_t deadzone_percent = DEFAULT_DEADZONE_PERCENT);
34+
AxisToHat(uint8_t deadzone_percent = DEFAULT_DEADZONE_PERCENT);
3635
~AxisToHat();
3736

3837
private:

lib/DS4Device.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ DS4Device* DS4Device::setButton(SpecialButton button, bool value) {
7272
}
7373

7474
DS4Device* DS4Device::setDPad(DPadDirection dpad) {
75-
DS4_SET_DPAD(&p->state, (DS4_DPAD_DIRECTIONS) dpad);
75+
DS4_SET_DPAD(&p->state, (DS4_DPAD_DIRECTIONS)dpad);
7676
return this;
7777
}
7878

7979
namespace {
80-
inline BYTE scale_axis(long value) {
81-
return (value * 255) / 65535;
82-
}
80+
inline BYTE scale_axis(long value) {
81+
return (value * 255) / 65535;
8382
}
83+
}// namespace
8484

8585
DS4Device* DS4Device::setLXAxis(long value) {
8686
p->state.bThumbLX = scale_axis(value);

lib/DeviceSpecifier.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
#pragma once
99

10-
#include <cstdint>
1110
#include <concepts>
11+
#include <cstdint>
1212
#include <string>
1313
#include <tuple>
1414
#include <variant>
@@ -21,6 +21,7 @@ class InputDevice;
2121
class DeviceSpecifierBase {
2222
protected:
2323
DeviceSpecifierBase();
24+
2425
public:
2526
virtual ~DeviceSpecifierBase();
2627
virtual bool matches(const InputDevice& device) const = 0;

lib/FunctionSink.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#include <functional>
1111

12-
#include "function_traits.h"
1312
#include "Sink.h"
13+
#include "function_traits.h"
1414

1515
namespace fredemmott::inputmapping {
1616

lib/HatToButtons.cpp

+80-80
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,81 @@
1-
/*
2-
* Copyright (c) 2020-present, Fred Emmott <fred@fredemmott.com>
3-
* All rights reserved.
4-
*
5-
* This source code is licensed under the ISC license found in the LICENSE file
6-
* in the root directory of this source tree.
7-
*/
8-
9-
#include "HatToButtons.h"
10-
11-
#include "MappableVJoyOutput.h"
12-
13-
namespace fredemmott::inputmapping {
14-
15-
HatToButtons::HatToButtons(
16-
MappableVJoyOutput* output,
17-
uint8_t first,
18-
uint8_t count) {
19-
assignToVJoy(output, first, count);
20-
}
21-
22-
HatToButtons::HatToButtons(
23-
const ButtonSinkRef& center,
24-
MappableVJoyOutput* output,
25-
uint8_t first,
26-
uint8_t count)
27-
: mCenter(center) {
28-
assignToVJoy(output, first, count);
29-
}
30-
31-
HatToButtons::HatToButtons(const std::vector<ButtonSinkRef>& buttons)
32-
: mButtons(buttons) {
33-
}
34-
35-
HatToButtons::HatToButtons(
36-
const ButtonSinkRef& center,
37-
const std::vector<ButtonSinkRef>& buttons)
38-
: mCenter(center), mButtons(buttons) {
39-
}
40-
41-
void HatToButtons::map(Hat::Value value) {
42-
if (mCenter) {
43-
(*mCenter)->map(value == Hat::CENTER);
44-
}
45-
if (value == Hat::CENTER) {
46-
for (auto& next: mButtons) {
47-
next->map(false);
48-
}
49-
return;
50-
}
51-
52-
const auto step = 36000 / mButtons.size();
53-
// Let's say we have 4 buttons: N, E, S, W
54-
// If the hat is at NE, we want both N and E on, so there's an area that's
55-
// "NE" - which goes half way from true NE to E - in another words, the N
56-
// button is pressed when the hat is between WNW and ENE, and covers 3/8ths
57-
// of the area
58-
const auto range = (36000 * 3) / (mButtons.size() * 2);
59-
// first one is special, as North should be on for a bit both sides of 0
60-
auto offset = range / 2;
61-
mButtons[0]->map(value <= offset || value > 36000 - offset);
62-
63-
// If we have 4 buttons, the 'E' button starts pressed active at NNE, while
64-
// 'N' is still active. N drops off 45 degrees later at ENE
65-
offset = 36000 / (mButtons.size() * 4);
66-
for (auto i = 1; i < mButtons.size(); ++i) {
67-
mButtons[i]->map(value > offset && value <= offset + range);
68-
offset += step;
69-
}
70-
}
71-
72-
void HatToButtons::assignToVJoy(
73-
MappableVJoyOutput* output,
74-
uint8_t first,
75-
uint8_t count) {
76-
for (auto i = first; i < first + count; ++i) {
77-
mButtons.push_back(output->button(i));
78-
}
79-
}
80-
1+
/*
2+
* Copyright (c) 2020-present, Fred Emmott <fred@fredemmott.com>
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the ISC license found in the LICENSE file
6+
* in the root directory of this source tree.
7+
*/
8+
9+
#include "HatToButtons.h"
10+
11+
#include "MappableVJoyOutput.h"
12+
13+
namespace fredemmott::inputmapping {
14+
15+
HatToButtons::HatToButtons(
16+
MappableVJoyOutput* output,
17+
uint8_t first,
18+
uint8_t count) {
19+
assignToVJoy(output, first, count);
20+
}
21+
22+
HatToButtons::HatToButtons(
23+
const ButtonSinkRef& center,
24+
MappableVJoyOutput* output,
25+
uint8_t first,
26+
uint8_t count)
27+
: mCenter(center) {
28+
assignToVJoy(output, first, count);
29+
}
30+
31+
HatToButtons::HatToButtons(const std::vector<ButtonSinkRef>& buttons)
32+
: mButtons(buttons) {
33+
}
34+
35+
HatToButtons::HatToButtons(
36+
const ButtonSinkRef& center,
37+
const std::vector<ButtonSinkRef>& buttons)
38+
: mCenter(center), mButtons(buttons) {
39+
}
40+
41+
void HatToButtons::map(Hat::Value value) {
42+
if (mCenter) {
43+
(*mCenter)->map(value == Hat::CENTER);
44+
}
45+
if (value == Hat::CENTER) {
46+
for (auto& next: mButtons) {
47+
next->map(false);
48+
}
49+
return;
50+
}
51+
52+
const auto step = 36000 / mButtons.size();
53+
// Let's say we have 4 buttons: N, E, S, W
54+
// If the hat is at NE, we want both N and E on, so there's an area that's
55+
// "NE" - which goes half way from true NE to E - in another words, the N
56+
// button is pressed when the hat is between WNW and ENE, and covers 3/8ths
57+
// of the area
58+
const auto range = (36000 * 3) / (mButtons.size() * 2);
59+
// first one is special, as North should be on for a bit both sides of 0
60+
auto offset = range / 2;
61+
mButtons[0]->map(value <= offset || value > 36000 - offset);
62+
63+
// If we have 4 buttons, the 'E' button starts pressed active at NNE, while
64+
// 'N' is still active. N drops off 45 degrees later at ENE
65+
offset = 36000 / (mButtons.size() * 4);
66+
for (auto i = 1; i < mButtons.size(); ++i) {
67+
mButtons[i]->map(value > offset && value <= offset + range);
68+
offset += step;
69+
}
70+
}
71+
72+
void HatToButtons::assignToVJoy(
73+
MappableVJoyOutput* output,
74+
uint8_t first,
75+
uint8_t count) {
76+
for (auto i = first; i < first + count; ++i) {
77+
mButtons.push_back(output->button(i));
78+
}
79+
}
80+
8181
}// namespace fredemmott::inputmapping

lib/HatToButtons.h

+45-45
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
/*
2-
* Copyright (c) 2020-present, Fred Emmott <fred@fredemmott.com>
3-
* All rights reserved.
4-
*
5-
* This source code is licensed under the ISC license found in the LICENSE file
6-
* in the root directory of this source tree.
7-
*/
8-
#pragma once
9-
10-
#include <cstdint>
11-
#include <optional>
12-
#include <vector>
13-
14-
#include "Sink.h"
15-
#include "SinkRef.h"
16-
17-
namespace fredemmott::inputmapping {
18-
19-
class MappableVJoyOutput;
20-
21-
class HatToButtons final : public Sink<Hat> {
22-
private:
23-
std::optional<ButtonSinkRef> mCenter;
24-
std::vector<ButtonSinkRef> mButtons;
25-
26-
public:
27-
HatToButtons() = delete;
28-
29-
HatToButtons(MappableVJoyOutput* output, uint8_t first, uint8_t count);
30-
HatToButtons(
31-
const ButtonSinkRef& center,
32-
MappableVJoyOutput* output,
33-
uint8_t first,
34-
uint8_t count);
35-
HatToButtons(const std::vector<ButtonSinkRef>& buttons);
36-
HatToButtons(
37-
const ButtonSinkRef& center,
38-
const std::vector<ButtonSinkRef>& buttons);
39-
40-
virtual void map(Hat::Value value) override;
41-
42-
private:
43-
void assignToVJoy(MappableVJoyOutput* output, uint8_t first, uint8_t count);
44-
};
45-
1+
/*
2+
* Copyright (c) 2020-present, Fred Emmott <fred@fredemmott.com>
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the ISC license found in the LICENSE file
6+
* in the root directory of this source tree.
7+
*/
8+
#pragma once
9+
10+
#include <cstdint>
11+
#include <optional>
12+
#include <vector>
13+
14+
#include "Sink.h"
15+
#include "SinkRef.h"
16+
17+
namespace fredemmott::inputmapping {
18+
19+
class MappableVJoyOutput;
20+
21+
class HatToButtons final : public Sink<Hat> {
22+
private:
23+
std::optional<ButtonSinkRef> mCenter;
24+
std::vector<ButtonSinkRef> mButtons;
25+
26+
public:
27+
HatToButtons() = delete;
28+
29+
HatToButtons(MappableVJoyOutput* output, uint8_t first, uint8_t count);
30+
HatToButtons(
31+
const ButtonSinkRef& center,
32+
MappableVJoyOutput* output,
33+
uint8_t first,
34+
uint8_t count);
35+
HatToButtons(const std::vector<ButtonSinkRef>& buttons);
36+
HatToButtons(
37+
const ButtonSinkRef& center,
38+
const std::vector<ButtonSinkRef>& buttons);
39+
40+
virtual void map(Hat::Value value) override;
41+
42+
private:
43+
void assignToVJoy(MappableVJoyOutput* output, uint8_t first, uint8_t count);
44+
};
45+
4646
}// namespace fredemmott::inputmapping

lib/InputDevice.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class InputDevice final {
5454
private:
5555
StateOffsets offsets;
5656
std::vector<std::byte> buffer;
57+
5758
public:
5859
State(const StateOffsets& offsets, const std::vector<std::byte>& buffer);
5960
~State();

0 commit comments

Comments
 (0)