Skip to content

Commit f7f3803

Browse files
authored
Merge pull request #129 from BastiaanOlij/clang_format_ci
Add clang format to CI
2 parents 1ed3c5a + 1291027 commit f7f3803

22 files changed

+162
-47
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
# This script runs clang-format and fixes copyright headers on all relevant files in the repo.
4+
# This is the primary script responsible for fixing style violations.
5+
6+
set -uo pipefail
7+
IFS=$'\n\t'
8+
9+
CLANG_FORMAT_FILE_EXTS=(".c" ".h" ".cpp" ".hpp" ".cc" ".hh" ".cxx" ".m" ".mm" ".inc" ".java" ".glsl")
10+
11+
# Loops through all text files tracked by Git.
12+
git grep -zIl '' |
13+
while IFS= read -rd '' f; do
14+
# Exclude 3rd party files.
15+
if [[ "$f" == "openvr"* ]]; then
16+
continue
17+
elif [[ "$f" == "godot-cpp"* ]]; then
18+
continue
19+
elif [[ "$f" == "demo/addons/godot-xr-tools"* ]]; then
20+
continue
21+
elif [[ "$f" == ".github"* ]]; then
22+
continue
23+
fi
24+
for extension in ${CLANG_FORMAT_FILE_EXTS[@]}; do
25+
if [[ "$f" == *"$extension" ]]; then
26+
# Run clang-format.
27+
clang-format -i "$f"
28+
fi
29+
done
30+
done
31+
32+
git diff > patch.patch
33+
34+
# If no patch has been generated all is OK, clean up, and exit.
35+
if [ ! -s patch.patch ] ; then
36+
printf "Files in this commit comply with the clang-format style rules.\n"
37+
rm -f patch.patch
38+
exit 0
39+
fi
40+
41+
# A patch has been created, notify the user, clean up, and exit.
42+
printf "\n*** The following differences were found between the code "
43+
printf "and the formatting rules:\n\n"
44+
cat patch.patch
45+
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
46+
rm -f patch.patch
47+
exit 1
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
# This script ensures proper POSIX text file formatting and a few other things.
4+
# This is supplementary to clang_format.sh, but should be run before it.
5+
6+
# We need dos2unix and recode.
7+
if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v recode)" ]; then
8+
printf "Install 'dos2unix' and 'recode' to use this script.\n"
9+
fi
10+
11+
set -uo pipefail
12+
IFS=$'\n\t'
13+
14+
# Loops through all text files tracked by Git.
15+
git grep -zIl '' |
16+
while IFS= read -rd '' f; do
17+
# Exclude 3rd party files
18+
if [[ "$f" == "openvr"* ]]; then
19+
continue
20+
elif [[ "$f" == "godot-cpp"* ]]; then
21+
continue
22+
elif [[ "$f" == "demo"* ]]; then
23+
continue
24+
elif [[ "$f" == ".github"* ]]; then
25+
continue
26+
fi
27+
# Ensure that files are UTF-8 formatted.
28+
recode UTF-8 "$f" 2> /dev/null
29+
# Ensure that files have LF line endings and do not contain a BOM.
30+
dos2unix "$f" 2> /dev/null
31+
# Remove trailing space characters and ensures that files end
32+
# with newline characters. -l option handles newlines conveniently.
33+
perl -i -ple 's/\s*$//g' "$f"
34+
# Remove the character sequence "== true" if it has a leading space.
35+
perl -i -pe 's/\x20== true//g' "$f"
36+
# We don't want to change lines around braces in godot/tscn files.
37+
if [[ "$f" == *"godot" ]]; then
38+
continue
39+
elif [[ "$f" == *"tscn" ]]; then
40+
continue
41+
fi
42+
# Disallow empty lines after the opening brace.
43+
sed -z -i 's/\x7B\x0A\x0A/\x7B\x0A/g' "$f"
44+
# Disallow some empty lines before the closing brace.
45+
sed -z -i 's/\x0A\x0A\x7D/\x0A\x7D/g' "$f"
46+
done
47+
48+
git diff > patch.patch
49+
50+
# If no patch has been generated all is OK, clean up, and exit.
51+
if [ ! -s patch.patch ] ; then
52+
printf "Files in this commit comply with the formatting rules.\n"
53+
rm -f patch.patch
54+
exit 0
55+
fi
56+
57+
# A patch has been created, notify the user, clean up, and exit.
58+
printf "\n*** The following differences were found between the code "
59+
printf "and the formatting rules:\n\n"
60+
cat patch.patch
61+
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
62+
rm -f patch.patch
63+
exit 1
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 📊 Static Checks
2+
on: [push, pull_request]
3+
4+
jobs:
5+
static-checks:
6+
name: Formatting (clang-format, file format)
7+
runs-on: ubuntu-20.04
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2
11+
12+
- name: Install dependencies
13+
run: |
14+
sudo apt-get install -qq dos2unix recode clang-format
15+
16+
- name: File formatting checks (file_format.sh)
17+
run: |
18+
bash ./.github/workflows/scripts/file_format.sh
19+
20+
- name: Style checks via clang-format (clang_format.sh)
21+
run: |
22+
bash ./.github/workflows/scripts/clang_format.sh

CONTRIBUTORS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
Contributors
22
============
33

4-
This plugin has mostly been developed by [Bastiaan Olij](https://github.com/BastiaanOlij).
4+
This plugin has mostly been developed by [Bastiaan Olij](https://github.com/BastiaanOlij).
55
Special thanks to [Benedikt](https://github.com/beniwtv) for doing all the work on overlay support.
66

77
Other people who have helped out by submitting fixes, enhancements, etc are:
88
- [RMKD](https://github.com/RMKD)
99
- [Bruvzg](https://github.com/bruvzg)
1010
- [Aaron Franke](https://github.com/aaronfranke)
11+
- [CrispyPin](https://github.com/CrispyPin)
12+
- [SaracenOne](https://github.com/SaracenOne)
13+
- [lyuma](https://github.com/lyuma)

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018-2020 Bastiaan Olij
3+
Copyright (c) 2018-2021 Bastiaan Olij and contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ OpenVR from version 1.6 onwards is able to support the HDR render buffers Godot
9696

9797
OpenVR however expects the color buffer to contain color values in linear color space, its build in sRGB support only works for 8bit color buffers. Godot performs all 3D color calculations in linear color space but will do a final conversion to sRGB during post processing. The result is that everything inside of the headset will look far too bright.
9898

99-
You can work around this by turning `keep_3d_linear` on for our viewport, this will skip the sRGB conversion and result the display inside of the headset to be correct however the output to screen will be too dark. We'll be looking at an interim solution for this soon however a full solution will likely not become available until after Godots rewrite to Vulkan.
99+
You can work around this by turning `keep_3d_linear` on for our viewport, this will skip the sRGB conversion and result the display inside of the headset to be correct however the output to screen will be too dark. We'll be looking at an interim solution for this soon however a full solution will likely not become available until after Godots rewrite to Vulkan.
100100

101101
```
102102
func _ready():
103-
var interface = ARVRServer.find_interface("OpenVR")
104-
if interface and interface.initialize():
105-
get_viewport().arvr = true
106-
get_viewport().keep_3d_linear = true
103+
var interface = ARVRServer.find_interface("OpenVR")
104+
if interface and interface.initialize():
105+
get_viewport().arvr = true
106+
get_viewport().keep_3d_linear = true
107107
```
108108

109109
Shader hickup
@@ -112,7 +112,7 @@ There are a few moment where OpenVR has a hickup.
112112

113113
One is around the teleporter function which can be solved by adding the `VR_Common_Shader_Cache.tscn` as a child scene to our ARVRCamera. `ovr_first_person.tscn` does this.
114114

115-
For the controllers they use a standard material. Adding a mesh instance with a standard material will ensure the shader is pre-compiled. Again we do this in `ovr_first_person.tscn`.
115+
For the controllers they use a standard material. Adding a mesh instance with a standard material will ensure the shader is pre-compiled. Again we do this in `ovr_first_person.tscn`.
116116

117117
However there is still an issue with loading the texture. We need to redo loading of the controller mesh by handing it off to a separate thread.
118118

@@ -137,7 +137,7 @@ if interface and interface.initialize():
137137
138138
# make sure vsync is disabled or we'll be limited to 60fps
139139
OS.vsync_enabled = false
140-
140+
141141
# up our physics to 90fps to get in sync with our rendering
142142
Engine.iterations_per_second = 90
143143
```
@@ -160,15 +160,15 @@ if interface:
160160
161161
# make sure vsync is disabled or we'll be limited to 60fps
162162
OS.vsync_enabled = false
163-
163+
164164
# up our physics to 90fps to get in sync with our rendering
165165
Engine.iterations_per_second = 90
166166
```
167167

168168
License
169169
-------
170170
Note that the source in this repository is licensed by the MIT license model.
171-
This covers only the source code in this repository.
171+
This covers only the source code in this repository.
172172

173173
Both Godot and OpenVR have their own license requirements.
174174
See their respective git repositories for more details.

SConstruct

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if env['platform'] == 'windows':
6565
env.Append(CCFLAGS = ['-fPIC', '-g3','-Og', '-std=c++17'])
6666
else:
6767
env.Append(CCFLAGS = ['-fPIC', '-g','-O3', '-std=c++17'])
68-
68+
6969
openvr_dll_target = env['target_path'] + "openvr_api.dll"
7070
openvr_dll_source = env['openvr_path'] + "bin/win" + str(env['bits']) + "/openvr_api.dll"
7171

@@ -106,11 +106,11 @@ else:
106106

107107
godot_cpp_library += '.' + str(env['bits'])
108108

109-
# Update our include search path
109+
# Update our include search path
110110
env.Append(CPPPATH=[
111-
'.',
112-
'src/',
113-
'src/open_vr/',
111+
'.',
112+
'src/',
113+
'src/open_vr/',
114114
godot_headers_path,
115115
godot_cpp_path + 'include/',
116116
godot_cpp_path + 'include/core/',

demo/Construct.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ extends Node2D
44
# OpenVR wants a buffer without this conversion applied and leave the color in linear color space.
55
# As a result we've turned off our sRGB conversion on our viewport.
66
# To output with the correct colors to screen we output our VR preview using a TextureRect
7-
# with a linear to sRGB conversion shader.
7+
# with a linear to sRGB conversion shader.
88

99
func on_window_size_change():
1010
$TextureRect.rect_size = OS.window_size
1111

1212
# Called when the node enters the scene tree for the first time.
1313
func _ready():
1414
$TextureRect.texture = $Viewport.get_texture()
15-
15+
1616
get_tree().get_root().connect("size_changed", self, "on_window_size_change")
1717
on_window_size_change();
1818

demo/addons/godot-openvr/CHANGES.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ Changes to the Godot OpenVR asset
44
Note, version numbers listed here are the version number assigned to the asset. Each time a new version is uploaded to the asset store we will increase the version number.
55
More frequent updates may be available on the source repository.
66

7-
1.1.0 - In progress
7+
1.1.0 - 9 July 2021
88
-------------------
99
- Build for Godot 3.3
1010
- Now using OpenVR 1.16.8 (drops MacOS support)
1111
- Added support for actions
1212
- Added support for request play area
1313
- Added skeleton support (finger tracking)
14+
- Added support for querying battery state of devices
1415

15-
1.0.5 - 1 March 2019
16+
1.0.5 - 1 March 2020
1617
--------------------
1718
- Now using OpenVR 1.9.16
1819
- Added support for overlays

demo/addons/godot-openvr/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018-2020 Bastiaan Olij
3+
Copyright (c) 2018-2021 Bastiaan Olij and contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)