mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Compare commits
579 Commits
v0.8.69
...
feature/st
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42b414d3b7 | ||
|
|
25212cbb4d | ||
|
|
c56cc24804 | ||
|
|
cf9250f25d | ||
|
|
a105e02131 | ||
|
|
cebdca87df | ||
|
|
bbabee3949 | ||
|
|
f16d41704b | ||
|
|
6f557ac821 | ||
|
|
ba70a7c95e | ||
|
|
f3796ee69d | ||
|
|
b2a71e5ef8 | ||
|
|
c253130c4a | ||
|
|
f03826b5ec | ||
|
|
69cf93a425 | ||
|
|
a4ea7fed6a | ||
|
|
7046152ec8 | ||
|
|
f6f1f76980 | ||
|
|
a98a214fa3 | ||
|
|
faadb70de7 | ||
|
|
7a6d6c83b1 | ||
|
|
9e32eb46e5 | ||
|
|
bea91d119e | ||
|
|
9ec725d848 | ||
|
|
790d523ebd | ||
|
|
147ca286ea | ||
|
|
bc25f5d727 | ||
|
|
c65740eba6 | ||
|
|
59e6a797f1 | ||
|
|
663d901e6b | ||
|
|
585126bf52 | ||
|
|
e27ed228ad | ||
|
|
ef35187624 | ||
|
|
1cf31fbea6 | ||
|
|
c7a3c43a4f | ||
|
|
01b55494e8 | ||
|
|
be9ab89b29 | ||
|
|
d4c8631587 | ||
|
|
3d43fc510e | ||
|
|
931c38a97d | ||
|
|
53c496fe27 | ||
|
|
c696ac1c73 | ||
|
|
57e5ceef1a | ||
|
|
b5279f3f89 | ||
|
|
fc424309c1 | ||
|
|
19aac6c461 | ||
|
|
2decf31a78 | ||
|
|
f33ba17148 | ||
|
|
752d4dfe8b | ||
|
|
92d40cded3 | ||
|
|
11f8bf794a | ||
|
|
0604464dcc | ||
|
|
9f25c14707 | ||
|
|
2c50e4f219 | ||
|
|
e97d8b9b14 | ||
|
|
f129bd45c5 | ||
|
|
f812b307b5 | ||
|
|
436cb98d53 | ||
|
|
1c1ced0f8a | ||
|
|
97015569f6 | ||
|
|
ee2d266d6b | ||
|
|
786ecdb8b1 | ||
|
|
488260cc64 | ||
|
|
6ee96873a4 | ||
|
|
2220f3e346 | ||
|
|
137723357c | ||
|
|
db3f3e5b32 | ||
|
|
fc10adfb03 | ||
|
|
812809bbfd | ||
|
|
ec70abe928 | ||
|
|
0ec6995542 | ||
|
|
1c28782d5d | ||
|
|
45472fa342 | ||
|
|
18a5335373 | ||
|
|
86590ceb1f | ||
|
|
e518abd2be | ||
|
|
13ae59dbf6 | ||
|
|
0ded41ebe1 | ||
|
|
3eb295e3ef | ||
|
|
1782792d30 | ||
|
|
d5c0776278 | ||
|
|
0822b41155 | ||
|
|
7a81c7f64a | ||
|
|
a925b7f84d | ||
|
|
557de01532 | ||
|
|
a38cbc7188 | ||
|
|
5146b1b3c6 | ||
|
|
0e97e3000f | ||
|
|
0c4a05dcbf | ||
|
|
565fa9f046 | ||
|
|
2783e89d1f | ||
|
|
d9d08dcbe3 | ||
|
|
6abeedae97 | ||
|
|
7bc1eaabfd | ||
|
|
526997639b | ||
|
|
9dc030c764 | ||
|
|
35308975db | ||
|
|
7649c120e9 | ||
|
|
610f6d88af | ||
|
|
0fb5b59eba | ||
|
|
77b1fd933c | ||
|
|
4ec019078d | ||
|
|
fe022d4100 | ||
|
|
1d4eec4855 | ||
|
|
84fceb587b | ||
|
|
a4ad98519e | ||
|
|
8f55a21cc4 | ||
|
|
4e40184c4a | ||
|
|
8bea8237f8 | ||
|
|
00c4d68db8 | ||
|
|
93e26fd88a | ||
|
|
312b879b06 | ||
|
|
852d1874db | ||
|
|
9e14a7e0d3 | ||
|
|
5700969945 | ||
|
|
6feb8b69ee | ||
|
|
1ab14fa6b7 | ||
|
|
445b13791e | ||
|
|
5605149a63 | ||
|
|
162b069de3 | ||
|
|
1c65686ee0 | ||
|
|
278755d938 | ||
|
|
64b356a9bf | ||
|
|
9681dc705e | ||
|
|
fa2b0233c3 | ||
|
|
392e2fefca | ||
|
|
47c56ffcf4 | ||
|
|
dd602fd6d0 | ||
|
|
2059d37c8f | ||
|
|
6b73b765b2 | ||
|
|
fb32b55584 | ||
|
|
045aebfc9e | ||
|
|
449418b1d4 | ||
|
|
06cf2208f4 | ||
|
|
ffbfdfe0b2 | ||
|
|
d7caa93cf5 | ||
|
|
0665781dfe | ||
|
|
a91413f1a6 | ||
|
|
6b9eeac228 | ||
|
|
c86e4e1ab9 | ||
|
|
269d229c2d | ||
|
|
7e86065c67 | ||
|
|
dcb0c2eb92 | ||
|
|
fd667a67e7 | ||
|
|
bf966ee49b | ||
|
|
2f75b74f1e | ||
|
|
a05b864952 | ||
|
|
2d96e0cda1 | ||
|
|
cd1d6ee598 | ||
|
|
09d7ad9d62 | ||
|
|
0c9c1366b0 | ||
|
|
8470cf43b1 | ||
|
|
62a24a320c | ||
|
|
578066511f | ||
|
|
2821492885 | ||
|
|
3806481f81 | ||
|
|
e610b8a286 | ||
|
|
d283043a56 | ||
|
|
4171b3ec4e | ||
|
|
f90872b085 | ||
|
|
077faebfc5 | ||
|
|
526b37804e | ||
|
|
b8cb9e6b1d | ||
|
|
0dfd71c990 | ||
|
|
18232e946b | ||
|
|
c06f3f003c | ||
|
|
72cf2f6334 | ||
|
|
e0e47ad545 | ||
|
|
70157265b8 | ||
|
|
1e5068f057 | ||
|
|
2bdea420ae | ||
|
|
be906faf42 | ||
|
|
a03eecaa36 | ||
|
|
bc12a0af87 | ||
|
|
d347641d00 | ||
|
|
221dbf945e | ||
|
|
24c900aeae | ||
|
|
76aaca6260 | ||
|
|
d3519d799a | ||
|
|
1ea18b9448 | ||
|
|
1e7956eaa8 | ||
|
|
7655aec413 | ||
|
|
a36a10c814 | ||
|
|
26cdae6877 | ||
|
|
c96eae620c | ||
|
|
9591d16aed | ||
|
|
05bb361eb2 | ||
|
|
776669b789 | ||
|
|
8d5fa58e1a | ||
|
|
dda544223f | ||
|
|
34106195b0 | ||
|
|
5bf3067342 | ||
|
|
ebeb504347 | ||
|
|
0b824f2170 | ||
|
|
0d04d8a82a | ||
|
|
b360c4439b | ||
|
|
d2cb4d102a | ||
|
|
b44524cd10 | ||
|
|
7f0feef97c | ||
|
|
82a67ecd99 | ||
|
|
42ad734a46 | ||
|
|
ac949a4bee | ||
|
|
60ca5beffa | ||
|
|
a6ab044582 | ||
|
|
d46fb519d5 | ||
|
|
832672149b | ||
|
|
3941930c2f | ||
|
|
4ab43cc923 | ||
|
|
cb0cb37e3c | ||
|
|
df4ebd6c8c | ||
|
|
647aa7ecf2 | ||
|
|
6aaf18cb27 | ||
|
|
08e295972c | ||
|
|
b4a7c5d47a | ||
|
|
4226976821 | ||
|
|
38bc58e77c | ||
|
|
386b0bc232 | ||
|
|
487471c2d1 | ||
|
|
e46cfe1601 | ||
|
|
fc4eb664e2 | ||
|
|
6c92d246c8 | ||
|
|
e86bd33a29 | ||
|
|
c4787b63a8 | ||
|
|
6b305349c9 | ||
|
|
3c16779d68 | ||
|
|
38fcadf649 | ||
|
|
6cc50013be | ||
|
|
bb7c9ad7fa | ||
|
|
b53d838b14 | ||
|
|
e03831586e | ||
|
|
6acb8f8b1b | ||
|
|
29bf2cbbc4 | ||
|
|
4fc238864b | ||
|
|
cb8d2727f4 | ||
|
|
9ef433d3ed | ||
|
|
02de3cd437 | ||
|
|
e7211063e7 | ||
|
|
e32ee1a58e | ||
|
|
1eb5859f01 | ||
|
|
ff7c3dc45c | ||
|
|
655b5974a3 | ||
|
|
47d7c7cf6c | ||
|
|
1c39deae6c | ||
|
|
6c4dc7fc72 | ||
|
|
3c5618364c | ||
|
|
bf1cc8fd7c | ||
|
|
72d4d50788 | ||
|
|
6a86fcdeeb | ||
|
|
dad95ad73a | ||
|
|
77f915acf5 | ||
|
|
6fc1daf978 | ||
|
|
934f589778 | ||
|
|
305ea97d5b | ||
|
|
e3b26e80bf | ||
|
|
810ef119b0 | ||
|
|
393b27679d | ||
|
|
a592134caf | ||
|
|
2389df7c6f | ||
|
|
422202348e | ||
|
|
284e08ffd9 | ||
|
|
2ce3d04bba | ||
|
|
8e67bfe990 | ||
|
|
27dc9510a3 | ||
|
|
d4708cb144 | ||
|
|
986de32043 | ||
|
|
4e90c291b3 | ||
|
|
7775767687 | ||
|
|
5624476e2b | ||
|
|
9ef80864b7 | ||
|
|
c32ef136a1 | ||
|
|
b2ea0fe1e2 | ||
|
|
be86b12b14 | ||
|
|
8b8e499615 | ||
|
|
36b0d38b70 | ||
|
|
78ef6921da | ||
|
|
f6ab67e92c | ||
|
|
44ffdcf429 | ||
|
|
53f4d3fab6 | ||
|
|
7dcf543443 | ||
|
|
4e445ee313 | ||
|
|
c6be3e145a | ||
|
|
f90526be22 | ||
|
|
df09bc2cf0 | ||
|
|
a1affcfd3f | ||
|
|
a402f3a880 | ||
|
|
b0fe9fb1a4 | ||
|
|
5057c91dcd | ||
|
|
84a80db21f | ||
|
|
8657e5516b | ||
|
|
6b24da6990 | ||
|
|
0ee87bc771 | ||
|
|
6e35c89740 | ||
|
|
9d69b330b5 | ||
|
|
22b3f3148c | ||
|
|
b73b3007f2 | ||
|
|
37dd4b0893 | ||
|
|
07c5a38582 | ||
|
|
c866c6b59b | ||
|
|
c3e97cb97e | ||
|
|
52ffb97369 | ||
|
|
bad5657725 | ||
|
|
f8dc3c8a0e | ||
|
|
77493b5d14 | ||
|
|
b1ceafbe4f | ||
|
|
41e9d9b08b | ||
|
|
dc32549c75 | ||
|
|
17dd3af3c7 | ||
|
|
32bdc19fe9 | ||
|
|
70fbefbe62 | ||
|
|
64cd6ea9be | ||
|
|
aa92c2444d | ||
|
|
9b19626f1b | ||
|
|
2bbe5193ee | ||
|
|
d11318f082 | ||
|
|
237f948d99 | ||
|
|
f3449be1e9 | ||
|
|
b95ffda711 | ||
|
|
0932fa0058 | ||
|
|
da2e46b81b | ||
|
|
d4a1fcc9c6 | ||
|
|
c7e7f4f28f | ||
|
|
87e191b8d7 | ||
|
|
05b21fcfcc | ||
|
|
48e4ae87d8 | ||
|
|
8b090034f1 | ||
|
|
41c183ac09 | ||
|
|
4380b95451 | ||
|
|
90fc486a20 | ||
|
|
f254153962 | ||
|
|
a2538d1905 | ||
|
|
5d7a2879a7 | ||
|
|
986adf6494 | ||
|
|
15932fb9aa | ||
|
|
3ae4bb03f5 | ||
|
|
7f47478997 | ||
|
|
a2923450ea | ||
|
|
5366b9a35b | ||
|
|
5ca37c68e2 | ||
|
|
22aa274d03 | ||
|
|
54bbe55bb9 | ||
|
|
9706576e66 | ||
|
|
b2ccd65da4 | ||
|
|
c587cd2e12 | ||
|
|
ba23a989a9 | ||
|
|
c6c69668c8 | ||
|
|
b0a4593f44 | ||
|
|
2d6e699e2c | ||
|
|
4307509402 | ||
|
|
ed165b1e4c | ||
|
|
3503300a23 | ||
|
|
3ab3d255ed | ||
|
|
fd625e0b30 | ||
|
|
53af37cd56 | ||
|
|
6bf4945181 | ||
|
|
868320c513 | ||
|
|
577b836420 | ||
|
|
4a36b52657 | ||
|
|
8dc944d22d | ||
|
|
0a10170155 | ||
|
|
dfa2c222d1 | ||
|
|
e288af162c | ||
|
|
6280820c86 | ||
|
|
102b31f83d | ||
|
|
37ca9ca19a | ||
|
|
0c151ad456 | ||
|
|
55e3f749b4 | ||
|
|
16902d7fbc | ||
|
|
c37f53e083 | ||
|
|
4cc499afdf | ||
|
|
48895efad7 | ||
|
|
eb46b04c0e | ||
|
|
442de12b99 | ||
|
|
712c1f3559 | ||
|
|
5a5cfa1eba | ||
|
|
7988386bc3 | ||
|
|
76bfe2905d | ||
|
|
23893bcacd | ||
|
|
c1da159e8f | ||
|
|
13889acb37 | ||
|
|
ffb3de3f2c | ||
|
|
87cd45fc64 | ||
|
|
1cf914813c | ||
|
|
86d61f8d03 | ||
|
|
8f638fbf9e | ||
|
|
95ac134a07 | ||
|
|
4e65f9b2a1 | ||
|
|
d60bbe9fe9 | ||
|
|
dec1495e1e | ||
|
|
dc72c6fe22 | ||
|
|
141b1205c6 | ||
|
|
65f4a09ad5 | ||
|
|
3d1545c0b9 | ||
|
|
ec26dd622b | ||
|
|
0ab3131964 | ||
|
|
588a9e9f63 | ||
|
|
f2fa930edd | ||
|
|
ec47229a37 | ||
|
|
bf5d1d58a8 | ||
|
|
8b4da24ee7 | ||
|
|
3fba108d70 | ||
|
|
35029f0eed | ||
|
|
b66ab9d7c6 | ||
|
|
5e0b745ba9 | ||
|
|
45d906ba7e | ||
|
|
24b124fb17 | ||
|
|
7cb0978468 | ||
|
|
44cb135a1d | ||
|
|
146b673203 | ||
|
|
b0d23c5665 | ||
|
|
68f89c8958 | ||
|
|
1327d6bf25 | ||
|
|
237e37ff30 | ||
|
|
4d707c86cb | ||
|
|
c7027c6e00 | ||
|
|
81ec61bcc8 | ||
|
|
649178fa54 | ||
|
|
9ff46b9aad | ||
|
|
cdcbb60ca7 | ||
|
|
d8cdb2b312 | ||
|
|
fa1c1b8e6e | ||
|
|
2ded835602 | ||
|
|
a43f04818d | ||
|
|
278dc60119 | ||
|
|
8a202be0cf | ||
|
|
58940a3cd7 | ||
|
|
aa9721d146 | ||
|
|
79f114ad5b | ||
|
|
197a6ddd9d | ||
|
|
4a4fb15e06 | ||
|
|
e7e83ce6e8 | ||
|
|
a82b293452 | ||
|
|
bb483a3a38 | ||
|
|
2ca3d0e395 | ||
|
|
bda79b1e82 | ||
|
|
4f4b754e2d | ||
|
|
214cabac43 | ||
|
|
7b6229c222 | ||
|
|
1a14a75897 | ||
|
|
76b75fd9b3 | ||
|
|
b969fd22f7 | ||
|
|
8d27d091af | ||
|
|
1eb7393a60 | ||
|
|
4cf88507c2 | ||
|
|
3565d8b321 | ||
|
|
7094c29b2e | ||
|
|
63004b270f | ||
|
|
6714a99b38 | ||
|
|
4c3b8df1e7 | ||
|
|
4bb695121f | ||
|
|
09fd47c421 | ||
|
|
d201d9c688 | ||
|
|
fd1e25c584 | ||
|
|
6bb66ae70e | ||
|
|
cc82d6b1d9 | ||
|
|
956be749b6 | ||
|
|
6585a00608 | ||
|
|
c0525f710f | ||
|
|
d3672807d2 | ||
|
|
60f18d5f36 | ||
|
|
e72d3de256 | ||
|
|
ba9846b9c4 | ||
|
|
09586284dc | ||
|
|
a1ee4374b2 | ||
|
|
4de6f25f11 | ||
|
|
582d8a5587 | ||
|
|
ec53b04f99 | ||
|
|
950fc94408 | ||
|
|
58d12e6e09 | ||
|
|
94323005c4 | ||
|
|
4989842057 | ||
|
|
80172636a8 | ||
|
|
8491f7be24 | ||
|
|
de8c2c14bb | ||
|
|
baebfff321 | ||
|
|
24191404aa | ||
|
|
990842f5c2 | ||
|
|
2c2bd3f330 | ||
|
|
1ae14c4bfa | ||
|
|
61a1701dc9 | ||
|
|
c6ea11346e | ||
|
|
ad7c871e28 | ||
|
|
c77b3f8022 | ||
|
|
b263f4a1df | ||
|
|
1a11d41bba | ||
|
|
14d0a77644 | ||
|
|
b75045ce1a | ||
|
|
1d8a8e15ef | ||
|
|
28a087c267 | ||
|
|
8dc849b6bb | ||
|
|
7e56f46f35 | ||
|
|
4453a23069 | ||
|
|
57be0bc845 | ||
|
|
430910ff36 | ||
|
|
4c95807e2d | ||
|
|
92fd04552d | ||
|
|
9c7e244821 | ||
|
|
41f64b5c3c | ||
|
|
4003003580 | ||
|
|
f49341b53c | ||
|
|
61d9d9a832 | ||
|
|
c0b7dd053f | ||
|
|
f642e10acc | ||
|
|
2fb64480db | ||
|
|
075b5ec203 | ||
|
|
21f2fe6b1b | ||
|
|
89080ef7c7 | ||
|
|
f5d36dc9ca | ||
|
|
ef87610b36 | ||
|
|
c89f1e4d31 | ||
|
|
c4805d89e0 | ||
|
|
659ffb028a | ||
|
|
a14c956ccc | ||
|
|
facb3914a4 | ||
|
|
aab8f7876b | ||
|
|
1f199ea71c | ||
|
|
00b557b77a | ||
|
|
eac536cffe | ||
|
|
bf75c6f247 | ||
|
|
1518c79291 | ||
|
|
aae2f72d1a | ||
|
|
273aa3d6ea | ||
|
|
756c4510eb | ||
|
|
cd50e89aec | ||
|
|
25b648b929 | ||
|
|
1dbbb08250 | ||
|
|
5432f7311e | ||
|
|
e662802b4c | ||
|
|
bae2c390bb | ||
|
|
7976926eaf | ||
|
|
4aee730753 | ||
|
|
e87c342aa2 | ||
|
|
d335d74d8f | ||
|
|
bc68b0e3ec | ||
|
|
b1eadbc58f | ||
|
|
2d3165a16f | ||
|
|
d99d25de37 | ||
|
|
be035ab002 | ||
|
|
12c8883eea | ||
|
|
758c7c1869 | ||
|
|
72ab1f5a1a | ||
|
|
6b9c1369c0 | ||
|
|
fd1f1dc64a | ||
|
|
e211368bc4 | ||
|
|
39307f916d | ||
|
|
7378cc50a1 | ||
|
|
867b9ad932 | ||
|
|
03064255f6 | ||
|
|
c9ccd0b873 | ||
|
|
650eceea7e | ||
|
|
452ad5a6e5 | ||
|
|
7c292c75d4 | ||
|
|
cab4113697 | ||
|
|
f1a5de79b5 | ||
|
|
191e80c175 | ||
|
|
241bce56c8 | ||
|
|
b105639b31 | ||
|
|
419e63ecd5 | ||
|
|
46e632bf9d | ||
|
|
a8871f4ff4 | ||
|
|
65f28c023d | ||
|
|
e506f6aba2 | ||
|
|
93ae74b5a7 | ||
|
|
7b25fa98ee | ||
|
|
e320b7abb4 | ||
|
|
6b9b56ca83 | ||
|
|
4d19790b3d | ||
|
|
2027863d4c | ||
|
|
4a4444a1ee | ||
|
|
f10316d384 | ||
|
|
778be40c86 | ||
|
|
2046323c71 | ||
|
|
71bb5cd58e | ||
|
|
71c6e437fa | ||
|
|
26e1474179 | ||
|
|
89a7459fda | ||
|
|
a61adf5631 | ||
|
|
97db1712f3 | ||
|
|
ea7012d114 | ||
|
|
d3eaea5697 |
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
@@ -11,7 +11,7 @@
|
||||
/Robust.Analyzers @PaulRitter
|
||||
/Robust.*/GameStates @PaulRitter
|
||||
/Robust.Shared/Analyzers @PaulRitter
|
||||
/Robust.*/Serialization @PaulRitter
|
||||
/Robust.*/Serialization @PaulRitter @DrSmugleaf
|
||||
/Robust.*/Prototypes @PaulRitter
|
||||
/Robust.Shared/GameObjects/ComponentDependencies @PaulRitter
|
||||
/Robust.*/Containers @PaulRitter
|
||||
|
||||
35
.github/workflows/benchmarks.yml
vendored
Normal file
35
.github/workflows/benchmarks.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
name: Benchmarks
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 5 * * *'
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
concurrency: benchmarks
|
||||
|
||||
env:
|
||||
ROBUST_BENCHMARKS_ENABLE_SQL: 1
|
||||
ROBUST_BENCHMARKS_SQL_ADDRESS: ${{ secrets.BENCHMARKS_WRITE_ADDRESS }}
|
||||
ROBUST_BENCHMARKS_SQL_PORT: ${{ secrets.BENCHMARKS_WRITE_PORT }}
|
||||
ROBUST_BENCHMARKS_SQL_USER: ${{ secrets.BENCHMARKS_WRITE_USER }}
|
||||
ROBUST_BENCHMARKS_SQL_PASSWORD: ${{ secrets.BENCHMARKS_WRITE_PASSWORD }}
|
||||
ROBUST_BENCHMARKS_SQL_DATABASE: benchmarks
|
||||
|
||||
jobs:
|
||||
benchmark:
|
||||
name: Run Benchmarks
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Run script on centcomm
|
||||
uses: appleboy/ssh-action@master
|
||||
with:
|
||||
host: centcomm.spacestation14.io
|
||||
username: robust-benchmark-runner
|
||||
key: ${{ secrets.CENTCOMM_ROBUST_BENCHMARK_RUNNER_KEY }}
|
||||
command_timeout: 100000m
|
||||
script: |
|
||||
wget https://raw.githubusercontent.com/space-wizards/RobustToolbox/${{ github.sha }}/Tools/run_benchmarks.py
|
||||
python3 run_benchmarks.py "${{ secrets.BENCHMARKS_WRITE_ADDRESS }}" "${{ secrets.BENCHMARKS_WRITE_PORT }}" "${{ secrets.BENCHMARKS_WRITE_USER }}" "${{ secrets.BENCHMARKS_WRITE_PASSWORD }}" "${{ github.sha }}"
|
||||
rm run_benchmarks.py
|
||||
34
.github/workflows/build-docfx.yml
vendored
Normal file
34
.github/workflows/build-docfx.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
name: Build & Publish DocFX
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0 * * 0"
|
||||
jobs:
|
||||
docfx:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Setup .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 6.0.x
|
||||
|
||||
- name: Install dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build Project
|
||||
run: dotnet build --no-restore /p:WarningsAsErrors=nullable
|
||||
|
||||
- name: Build DocFX
|
||||
uses: nikeee/docfx-action@v1.0.0
|
||||
with:
|
||||
args: Robust.Docfx/docfx.json
|
||||
|
||||
- name: Publish Docfx Documentation on GitHub Pages
|
||||
uses: maxheld83/ghpages@master
|
||||
env:
|
||||
BUILD_DIR: Robust.Docfx/_robust-site
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
6
.github/workflows/build-test.yml
vendored
6
.github/workflows/build-test.yml
vendored
@@ -22,10 +22,12 @@ jobs:
|
||||
- name: Setup .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 6.0.100
|
||||
dotnet-version: 6.0.x
|
||||
- name: Install dependencies
|
||||
run: dotnet restore
|
||||
- name: Build
|
||||
run: dotnet build --no-restore /p:WarningsAsErrors=nullable
|
||||
- name: Test Engine
|
||||
run: dotnet test --no-build Robust.UnitTesting/Robust.UnitTesting.csproj -v n
|
||||
run: dotnet test --no-build Robust.UnitTesting/Robust.UnitTesting.csproj -- NUnit.ConsoleOut=0
|
||||
|
||||
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -76,3 +76,5 @@ MSBuild/Robust.Custom.targets
|
||||
|
||||
|
||||
release/
|
||||
Robust.Docfx/*-site
|
||||
Robust.Docfx/api
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -10,9 +10,6 @@
|
||||
[submodule "Robust.LoaderApi"]
|
||||
path = Robust.LoaderApi
|
||||
url = https://github.com/space-wizards/Robust.LoaderApi.git
|
||||
[submodule "ManagedHttpListener"]
|
||||
path = ManagedHttpListener
|
||||
url = https://github.com/space-wizards/ManagedHttpListener.git
|
||||
[submodule "cefglue"]
|
||||
path = cefglue
|
||||
url = https://github.com/space-wizards/cefglue.git
|
||||
|
||||
Submodule Lidgren.Network/Lidgren.Network updated: 1dd5c1f333...1e7fb3c2b6
@@ -1,4 +1,4 @@
|
||||
<Project>
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
<PropertyGroup><Version>0.8.69</Version></PropertyGroup>
|
||||
<PropertyGroup><Version>0.40.3.0</Version></PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<!-- Avoid MSBuild adding a None entry for XAML files because they'd show up TWICE in the project view. -->
|
||||
<DefaultItemExcludes>**/*.xaml</DefaultItemExcludes>
|
||||
<RobustUseExternalMSBuild>true</RobustUseExternalMSBuild>
|
||||
<RobustUseExternalMSBuild>false</RobustUseExternalMSBuild>
|
||||
<_RobustUseExternalMSBuild>$(RobustUseExternalMSBuild)</_RobustUseExternalMSBuild>
|
||||
<_RobustUseExternalMSBuild Condition="'$(_RobustForceInternalMSBuild)' == 'true'">false</_RobustUseExternalMSBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
Submodule ManagedHttpListener deleted from ae0539e66f
@@ -10,7 +10,6 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using static OpenToolkit.GraphicsLibraryFramework.GLFWNative;
|
||||
using static Robust.Shared.Utility.MarshalHelper;
|
||||
|
||||
namespace OpenToolkit.GraphicsLibraryFramework
|
||||
{
|
||||
@@ -211,7 +210,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// <seealso cref="GetVersion"/>
|
||||
public static unsafe string GetVersionString()
|
||||
{
|
||||
return PtrToStringUTF8(glfwGetVersionString());
|
||||
return Marshal.PtrToStringUTF8((IntPtr) glfwGetVersionString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -272,7 +271,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
{
|
||||
byte* desc;
|
||||
var code = glfwGetError(&desc);
|
||||
description = PtrToStringUTF8(desc);
|
||||
description = Marshal.PtrToStringUTF8((IntPtr) desc);
|
||||
return code;
|
||||
}
|
||||
|
||||
@@ -590,7 +589,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// </remarks>
|
||||
public static unsafe string GetMonitorName(Monitor* monitor)
|
||||
{
|
||||
return PtrToStringUTF8(glfwGetMonitorName(monitor));
|
||||
return Marshal.PtrToStringUTF8((IntPtr) glfwGetMonitorName(monitor));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -902,7 +901,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// </remarks>
|
||||
public static unsafe void WindowHint(WindowHintString hint, string value)
|
||||
{
|
||||
var ptr = StringToCoTaskMemUTF8(value);
|
||||
var ptr = Marshal.StringToCoTaskMemUTF8(value);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -1364,7 +1363,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// </remarks>
|
||||
public static unsafe string GetKeyName(Keys key, int scanCode)
|
||||
{
|
||||
return PtrToStringUTF8(glfwGetKeyName(key, scanCode));
|
||||
return Marshal.PtrToStringUTF8((IntPtr) glfwGetKeyName(key, scanCode));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2278,7 +2277,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// </remarks>
|
||||
public static unsafe string GetJoystickName(int jid)
|
||||
{
|
||||
return PtrToStringUTF8(glfwGetJoystickName(jid));
|
||||
return Marshal.PtrToStringUTF8((IntPtr) glfwGetJoystickName(jid));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2351,7 +2350,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// </remarks>
|
||||
public static unsafe string GetJoystickGUID(int jid)
|
||||
{
|
||||
return PtrToStringUTF8(glfwGetJoystickGUID(jid));
|
||||
return Marshal.PtrToStringUTF8((IntPtr) glfwGetJoystickGUID(jid));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2509,7 +2508,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// </remarks>
|
||||
public static unsafe bool UpdateGamepadMappings(string newMapping)
|
||||
{
|
||||
var ptr = StringToCoTaskMemUTF8(newMapping);
|
||||
var ptr = Marshal.StringToCoTaskMemUTF8(newMapping);
|
||||
try
|
||||
{
|
||||
return glfwUpdateGamepadMappings((byte*)ptr) == GLFW_TRUE;
|
||||
@@ -2585,7 +2584,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// </remarks>
|
||||
public static unsafe string GetGamepadName(int jid)
|
||||
{
|
||||
return PtrToStringUTF8(glfwGetGamepadName(jid));
|
||||
return Marshal.PtrToStringUTF8((IntPtr) glfwGetGamepadName(jid));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2854,7 +2853,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// </remarks>
|
||||
public static unsafe bool ExtensionSupported(string extensionName)
|
||||
{
|
||||
var ptr = StringToCoTaskMemUTF8(extensionName);
|
||||
var ptr = Marshal.StringToCoTaskMemUTF8(extensionName);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -2893,7 +2892,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// <seealso cref="ExtensionSupported" />
|
||||
public static unsafe IntPtr GetProcAddress(string procName)
|
||||
{
|
||||
var ptr = StringToCoTaskMemUTF8(procName);
|
||||
var ptr = Marshal.StringToCoTaskMemUTF8(procName);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -3085,7 +3084,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// </remarks>
|
||||
public static unsafe Window* CreateWindow(int width, int height, string title, Monitor* monitor, Window* share)
|
||||
{
|
||||
var ptr = StringToCoTaskMemUTF8(title);
|
||||
var ptr = Marshal.StringToCoTaskMemUTF8(title);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -3306,7 +3305,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// <seealso cref="SetClipboardString"/>
|
||||
public static unsafe string GetClipboardString(Window* window)
|
||||
{
|
||||
return PtrToStringUTF8(glfwGetClipboardString(window));
|
||||
return Marshal.PtrToStringUTF8((IntPtr) glfwGetClipboardString(window));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -3917,7 +3916,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// <seealso cref="GetClipboardString"/>
|
||||
public static unsafe void SetClipboardString(Window* window, string data)
|
||||
{
|
||||
var ptr = StringToCoTaskMemUTF8(data);
|
||||
var ptr = Marshal.StringToCoTaskMemUTF8(data);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -4751,7 +4750,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// </remarks>
|
||||
public static unsafe void SetWindowTitle(Window* window, string title)
|
||||
{
|
||||
var ptr = StringToCoTaskMemUTF8(title);
|
||||
var ptr = Marshal.StringToCoTaskMemUTF8(title);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -5340,7 +5339,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
var array = new string[count];
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
array[i] = PtrToStringUTF8(ptr[i]);
|
||||
array[i] = Marshal.PtrToStringUTF8((IntPtr) ptr[i]);
|
||||
}
|
||||
|
||||
return array;
|
||||
@@ -5386,7 +5385,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
|
||||
/// <returns>The address of the function, or <c>null</c> if an error occurred.</returns>
|
||||
public static unsafe IntPtr GetInstanceProcAddress(VkHandle instance, string procName)
|
||||
{
|
||||
var ptr = StringToCoTaskMemUTF8(procName);
|
||||
var ptr = Marshal.StringToCoTaskMemUTF8(procName);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -14,7 +14,4 @@
|
||||
<PackageReference Condition="'$(TargetFramework)' == 'net472'" Include="System.Memory" Version="4.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Robust.Shared\Robust.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
155
Resources/Locale/en-US/commands.ftl
Normal file
155
Resources/Locale/en-US/commands.ftl
Normal file
@@ -0,0 +1,155 @@
|
||||
### Localization for engine console commands
|
||||
|
||||
## generic
|
||||
|
||||
cmd-parse-failure-integer = {$arg} is not a valid integer.
|
||||
cmd-parse-failure-float = {$arg} is not a valid float.
|
||||
cmd-parse-failure-bool = {$arg} is not a valid bool.
|
||||
|
||||
|
||||
## 'help' command
|
||||
cmd-help-desc = Display general help or help text for a specific command
|
||||
cmd-help-help = Usage: help [command name]
|
||||
When no command name is provided, displays general-purpose help text. If a command name is provided, displays help text for that command.
|
||||
|
||||
cmd-help-no-args = To display help for a specific command, write 'help <command>'. To list all available commands, write 'list'. To search for commands, use 'list <filter>'.
|
||||
cmd-help-unknown = Unknown command: { $command }
|
||||
cmd-help-top = { $command } - { $description }
|
||||
cmd-help-invalid-args = Invalid amount of arguments.
|
||||
cmd-help-arg-cmdname = [command name]
|
||||
|
||||
## 'cvar' command
|
||||
cmd-cvar-desc = Gets or sets a CVar.
|
||||
cmd-cvar-help = Usage: cvar <name | ?> [value]
|
||||
If a value is passed, the value is parsed and stored as the new value of the CVar.
|
||||
If not, the current value of the CVar is displayed.
|
||||
Use 'cvar ?' to get a list of all registered CVars.
|
||||
|
||||
cmd-cvar-invalid-args = Must provide exactly one or two arguments.
|
||||
cmd-cvar-not-registered = CVar '{ $cvar }' is not registered. Use 'cvar ?' to get a list of all registered CVars.
|
||||
cmd-cvar-parse-error = Input value is in incorrect format for type { $type }
|
||||
cmd-cvar-compl-list = List available CVars
|
||||
cmd-cvar-arg-name = <name | ?>
|
||||
cmd-cvar-value-hidden = <value hidden>
|
||||
|
||||
## 'list' command
|
||||
cmd-list-desc = Lists available commands, with optional search filter
|
||||
cmd-list-help = Usage: list [filter]
|
||||
Lists all available commands. If an argument is provided, it will be used to filter commands by name.
|
||||
|
||||
cmd-list-heading = SIDE NAME DESC{"\u000A"}-------------------------{"\u000A"}
|
||||
|
||||
cmd-list-arg-filter = [filter]
|
||||
|
||||
## '>' command, aka remote exec
|
||||
cmd-remoteexec-desc = Executes server-side commands
|
||||
cmd-remoteexec-help = Usage: > <command> [arg] [arg] [arg...]
|
||||
Executes a command on the server. This is necessary if a command with the same name exists on the client, as simply running the command would run the client command first.
|
||||
|
||||
## 'gc' command
|
||||
cmd-gc-desc = Run the GC (Garbage Collector)
|
||||
cmd-gc-help = Usage: gc [generation]
|
||||
Uses GC.Collect() to execute the Garbage Collector.
|
||||
If an argument is provided, it is parsed as a GC generation number and GC.Collect(int) is used.
|
||||
Use the 'gfc' command to do an LOH-compacting full GC.
|
||||
cmd-gc-failed-parse = Failed to parse argument.
|
||||
cmd-gc-arg-generation = [generation]
|
||||
|
||||
## 'gcf' command
|
||||
cmd-gcf-desc = Run the GC, fully, compacting LOH and everything.
|
||||
cmd-gcf-help = Usage: gcf
|
||||
Does a full GC.Collect(2, GCCollectionMode.Forced, true, true) while also compacting LOH.
|
||||
This will probably lock up for hundreds of milliseconds, be warned.
|
||||
|
||||
## 'gc_mode' command
|
||||
cmd-gc_mode-desc = Change/Read the GC Latency mode
|
||||
cmd-gc_mode-help = Usage: gc_mode [type]
|
||||
If no argument is provided, returns the current GC latency mode.
|
||||
If an argument is passed, it is parsed as GCLatencyMode and set as the GC latency mode.
|
||||
|
||||
cmd-gc_mode-current = current gc latency mode: { $prevMode }
|
||||
cmd-gc_mode-possible = possible modes:
|
||||
cmd-gc_mode-option = - { $mode }
|
||||
cmd-gc_mode-unknown = unknown gc latency mode: { $arg }
|
||||
cmd-gc_mode-attempt = attempting gc latency mode change: { $prevMode } -> { $mode }
|
||||
cmd-gc_mode-result = resulting gc latency mode: { $mode }
|
||||
cmd-gc_mode-arg-type = [type]
|
||||
|
||||
## 'mem' command
|
||||
cmd-mem-desc = Prints managed memory info
|
||||
cmd-mem-help = Usage: mem
|
||||
|
||||
cmd-mem-report = Heap Size: { TOSTRING($heapSize, "N0") }
|
||||
Total Allocated: { TOSTRING($totalAllocated, "N0") }
|
||||
|
||||
## 'physics' command
|
||||
cmd-physics-overlay = {$overlay} is not a recognised overlay
|
||||
|
||||
## 'lsasm' command
|
||||
cmd-lsasm-desc = Lists loaded assemblies by load context
|
||||
cmd-lsasm-help = Usage: lsasm
|
||||
|
||||
## 'exec' command
|
||||
cmd-exec-desc = Executes a script file from the game's writeable user data
|
||||
cmd-exec-help = Usage: exec <fileName>
|
||||
Each line in the file is executed as a single command, unless it starts with a #
|
||||
|
||||
cmd-exec-arg-filename = <fileName>
|
||||
|
||||
## 'dump_net_comps' command
|
||||
cmd-dump_net_comps-desc = Prints the table of networked components.
|
||||
cmd-dump_net_comps-help = Usage: dump_net-comps
|
||||
|
||||
cmd-dump_net_comps-error-writeable = Registration still writeable, network ids have not been generated.
|
||||
cmd-dump_net_comps-header = Networked Component Registrations:
|
||||
|
||||
## 'dump_event_tables' command
|
||||
cmd-dump_event_tables-desc = Prints directed event tables for an entity.
|
||||
cmd-dump_event_tables-help = Usage: dump_event_tables <entityUid>
|
||||
|
||||
cmd-dump_event_tables-missing-arg-entity = Missing entity argument
|
||||
cmd-dump_event_tables-error-entity = Invalid entity
|
||||
cmd-dump_event_tables-arg-entity = <entityUid>
|
||||
|
||||
## 'monitor' command
|
||||
cmd-monitor-desc = Toggles a debug monitor in the F3 menu.
|
||||
cmd-monitor-help = Usage: monitor <name>
|
||||
Possible monitors are: { $monitors }
|
||||
You can also use the special values "-all" and "+all" to hide or show all monitors, respectively.
|
||||
|
||||
cmd-monitor-arg-monitor = <monitor>
|
||||
cmd-monitor-invalid-name = Invalid monitor name
|
||||
cmd-monitor-arg-count = Missing monitor argument
|
||||
cmd-monitor-minus-all-hint = Hides all monitors
|
||||
cmd-monitor-plus-all-hint = Shows all monitors
|
||||
|
||||
|
||||
## Mapping commands
|
||||
|
||||
cmd-savemap-desc = Serializes a map to disk. Will not save a post-init map unless forced.
|
||||
cmd-savemap-help = savemap <MapID> <Path> [force]
|
||||
cmd-savemap-not-exist = Target map does not exist.
|
||||
cmd-savemap-init-warning = Attempted to save a post-init map without forcing the save.
|
||||
cmd-savemap-attempt = Attempting to save map {$mapId} to {$path}.
|
||||
cmd-savemap-success = Map successfully saved.
|
||||
cmd-hint-savemap-id = <MapID>
|
||||
cmd-hint-savemap-path = <Path>
|
||||
cmd-hint-savemap-force = [bool]
|
||||
|
||||
cmd-loadmap-desc = Loads a map from disk into the game.
|
||||
cmd-loadmap-help = loadmap <MapID> <Path> [x] [y] [rotation] [consistentUids]
|
||||
cmd-loadmap-nullspace = You cannot load into map 0.
|
||||
cmd-loadmap-exists = Map {$mapId} already exists.
|
||||
cmd-loadmap-success = Map {$mapId} has been loaded from {$path}.
|
||||
cmd-loadmap-error = An error occurred while loading map from {$path}.
|
||||
cmd-hint-loadmap-x-position = [x-position]
|
||||
cmd-hint-loadmap-y-position = [y-position]
|
||||
cmd-hint-loadmap-rotation = [rotation]
|
||||
cmd-hint-loadmap-uids = [float]
|
||||
|
||||
## 'flushcookies' command
|
||||
# Note: the flushcookies command is from Robust.Client.WebView, it's not in the main engine code.
|
||||
|
||||
cmd-flushcookies-desc = Flush CEF cookie storage to disk
|
||||
cmd-flushcookies-help = This ensure cookies are properly saved to disk in the event of unclean shutdowns.
|
||||
Note that the actual operation is asynchronous.
|
||||
10
Resources/Locale/en-US/controls.ftl
Normal file
10
Resources/Locale/en-US/controls.ftl
Normal file
@@ -0,0 +1,10 @@
|
||||
color-selector-sliders-red = R
|
||||
color-selector-sliders-green = G
|
||||
color-selector-sliders-blue = B
|
||||
color-selector-sliders-hue = H
|
||||
color-selector-sliders-saturation = S
|
||||
color-selector-sliders-value = V
|
||||
color-selector-sliders-alpha = A
|
||||
|
||||
color-selector-sliders-rgb = RGB
|
||||
color-selector-sliders-hsv = HSV
|
||||
1
Resources/Locale/en-US/midi-commands.ftl
Normal file
1
Resources/Locale/en-US/midi-commands.ftl
Normal file
@@ -0,0 +1 @@
|
||||
midi-panic-command-description = Turns off every note for every active MIDI renderer.
|
||||
BIN
Resources/Textures/noTile.png
Normal file
BIN
Resources/Textures/noTile.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 535 B |
822
Robust.Analyzers.Tests/AccessAnalyzer_Test.cs
Normal file
822
Robust.Analyzers.Tests/AccessAnalyzer_Test.cs
Normal file
@@ -0,0 +1,822 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CodeAnalysis.CSharp.Testing;
|
||||
using Microsoft.CodeAnalysis.Testing;
|
||||
using Microsoft.CodeAnalysis.Testing.Verifiers;
|
||||
using NUnit.Framework;
|
||||
using Robust.Analyzers;
|
||||
|
||||
using VerifyCS = Microsoft.CodeAnalysis.CSharp.Testing.NUnit.AnalyzerVerifier<Robust.Analyzers.AccessAnalyzer>;
|
||||
using static Microsoft.CodeAnalysis.Testing.DiagnosticResult;
|
||||
|
||||
namespace Robust.Analyzers.Tests;
|
||||
|
||||
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)]
|
||||
[TestFixture]
|
||||
public sealed class AccessAnalyzer_Test
|
||||
{
|
||||
public Task Verifier(string code, params DiagnosticResult[] expected)
|
||||
{
|
||||
var test = new CSharpAnalyzerTest<AccessAnalyzer, NUnitVerifier>()
|
||||
{
|
||||
TestState =
|
||||
{
|
||||
AdditionalReferences = { typeof(AccessAnalyzer).Assembly },
|
||||
Sources = { code }
|
||||
},
|
||||
};
|
||||
|
||||
// ExpectedDiagnostics cannot be set, so we need to AddRange here...
|
||||
test.TestState.ExpectedDiagnostics.AddRange(expected);
|
||||
|
||||
return test.RunAsync();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
[Test]
|
||||
public async Task ReadTest()
|
||||
{
|
||||
const string code = @"
|
||||
using System;
|
||||
using Robust.Shared.Analyzers;
|
||||
// ReSharper disable RedundantAssignment
|
||||
// ReSharper disable UnusedVariable
|
||||
// ReSharper disable ArrangeThisQualifier
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable UnusedType.Global
|
||||
|
||||
public struct MyData
|
||||
{
|
||||
public int MyField;
|
||||
|
||||
public static bool operator ==(MyData lhs, MyData rhs) => lhs.MyField == rhs.MyField;
|
||||
public static bool operator !=(MyData lhs, MyData rhs) => lhs.MyField != rhs.MyField;
|
||||
}
|
||||
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.None,
|
||||
Friend = AccessPermissions.None,
|
||||
Other = AccessPermissions.None)]
|
||||
public sealed class TypeNobodyCanRead
|
||||
{
|
||||
public MyData Data = default;
|
||||
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.Read,
|
||||
Friend = AccessPermissions.Read,
|
||||
Other = AccessPermissions.Read)]
|
||||
public MyData Data2 = default;
|
||||
|
||||
public void TestTypeNobodyCanRead(TypeNobodyCanRead obj)
|
||||
{
|
||||
// None of these accesses should be allowed.
|
||||
var copy = Data;
|
||||
var copy2 = this.Data;
|
||||
var copy3 = obj.Data;
|
||||
|
||||
copy = Data;
|
||||
copy = this.Data;
|
||||
copy = obj.Data;
|
||||
|
||||
var copy4 = Data.MyField;
|
||||
var copy5 = this.Data.MyField;
|
||||
var copy6 = obj.Data.MyField;
|
||||
|
||||
if (Data == copy) {}
|
||||
if (this.Data == copy) {}
|
||||
if (obj.Data == copy) {}
|
||||
|
||||
if(Data.MyField == 0) {}
|
||||
if(this.Data.MyField == 0) {}
|
||||
if(obj.Data.MyField == 0) {}
|
||||
|
||||
// All of these accesses should be fine.
|
||||
var copy7 = Data2;
|
||||
var copy8 = this.Data2;
|
||||
var copy9 = obj.Data2;
|
||||
|
||||
copy = Data2;
|
||||
copy = this.Data2;
|
||||
copy = obj.Data2;
|
||||
|
||||
var copy10 = Data2.MyField;
|
||||
var copy11 = this.Data2.MyField;
|
||||
var copy12 = obj.Data2.MyField;
|
||||
|
||||
if (Data2 == copy) {}
|
||||
if (this.Data2 == copy) {}
|
||||
if (obj.Data2 == copy) {}
|
||||
|
||||
if(Data2.MyField == 0) {}
|
||||
if(this.Data2.MyField == 0) {}
|
||||
if(obj.Data2.MyField == 0) {}
|
||||
}
|
||||
}
|
||||
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.Read,
|
||||
Friend = AccessPermissions.Read,
|
||||
Other = AccessPermissions.Read)]
|
||||
public sealed class MemberNobodyCanRead
|
||||
{
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.None,
|
||||
Friend = AccessPermissions.None,
|
||||
Other = AccessPermissions.None)]
|
||||
public MyData Data = default;
|
||||
|
||||
public MyData Data2 = default;
|
||||
|
||||
public void TestMemberNobodyCanRead(TypeNobodyCanRead obj)
|
||||
{
|
||||
// None of these accesses should be allowed.
|
||||
var copy = Data;
|
||||
var copy2 = this.Data;
|
||||
var copy3 = obj.Data;
|
||||
|
||||
copy = Data;
|
||||
copy = this.Data;
|
||||
copy = obj.Data;
|
||||
|
||||
var copy4 = Data.MyField;
|
||||
var copy5 = this.Data.MyField;
|
||||
var copy6 = obj.Data.MyField;
|
||||
|
||||
if (Data == copy) {}
|
||||
if (this.Data == copy) {}
|
||||
if (obj.Data == copy) {}
|
||||
|
||||
if(Data.MyField == 0) {}
|
||||
if(this.Data.MyField == 0) {}
|
||||
if(obj.Data.MyField == 0) {}
|
||||
|
||||
// All of these accesses should be fine.
|
||||
var copy7 = Data2;
|
||||
var copy8 = this.Data2;
|
||||
var copy9 = obj.Data2;
|
||||
|
||||
copy = Data2;
|
||||
copy = this.Data2;
|
||||
copy = obj.Data2;
|
||||
|
||||
var copy10 = Data2.MyField;
|
||||
var copy11 = this.Data2.MyField;
|
||||
var copy12 = obj.Data2.MyField;
|
||||
|
||||
if (Data2 == copy) {}
|
||||
if (this.Data2 == copy) {}
|
||||
if (obj.Data2 == copy) {}
|
||||
|
||||
if(Data2.MyField == 0) {}
|
||||
if(this.Data2.MyField == 0) {}
|
||||
if(obj.Data2.MyField == 0) {}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class FriendlyClass
|
||||
{
|
||||
public void TestTypeNobodyCanRead(TypeNobodyCanRead obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, even if we're a friend..
|
||||
var copy = obj.Data;
|
||||
copy = obj.Data;
|
||||
|
||||
var copy2 = obj.Data.MyField;
|
||||
copy2 = obj.Data.MyField;
|
||||
|
||||
if (obj.Data == copy) {}
|
||||
if(obj.Data.MyField == 0) {}
|
||||
|
||||
// We should be allowed to access all of these, we're friends!
|
||||
var copy3 = obj.Data2;
|
||||
copy = obj.Data2;
|
||||
|
||||
var copy4 = obj.Data2.MyField;
|
||||
copy4 = obj.Data2.MyField;
|
||||
|
||||
if(obj.Data2 == copy) {}
|
||||
if(obj.Data2.MyField == 0) {}
|
||||
}
|
||||
|
||||
public void TestMemberNobodyCanRead(MemberNobodyCanRead obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, even if we're a friend..
|
||||
var copy = obj.Data;
|
||||
copy = obj.Data;
|
||||
|
||||
var copy2 = obj.Data.MyField;
|
||||
copy2 = obj.Data.MyField;
|
||||
|
||||
if (obj.Data == copy) {}
|
||||
if(obj.Data.MyField == 0) {}
|
||||
|
||||
// We should be allowed to access all of these, we're friends!
|
||||
var copy3 = obj.Data2;
|
||||
copy = obj.Data2;
|
||||
|
||||
var copy4 = obj.Data2.MyField;
|
||||
copy4 = obj.Data2.MyField;
|
||||
|
||||
if(obj.Data2 == copy) {}
|
||||
if(obj.Data2.MyField == 0) {}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class OtherClass
|
||||
{
|
||||
public void TestTypeNobodyCanRead(TypeNobodyCanRead obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, as 'other types' can't..
|
||||
var copy = obj.Data;
|
||||
copy = obj.Data;
|
||||
|
||||
var copy2 = obj.Data.MyField;
|
||||
copy2 = obj.Data.MyField;
|
||||
|
||||
if (obj.Data == copy) {}
|
||||
if(obj.Data.MyField == 0) {}
|
||||
|
||||
// We should be allowed to access all of these, they let others read it!
|
||||
var copy3 = obj.Data2;
|
||||
copy = obj.Data2;
|
||||
|
||||
var copy4 = obj.Data2.MyField;
|
||||
copy4 = obj.Data2.MyField;
|
||||
|
||||
if(obj.Data2 == copy) {}
|
||||
if(obj.Data2.MyField == 0) {}
|
||||
}
|
||||
|
||||
public void TestMemberNobodyCanRead(MemberNobodyCanRead obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, as 'other types' can't..
|
||||
var copy = obj.Data;
|
||||
copy = obj.Data;
|
||||
|
||||
var copy2 = obj.Data.MyField;
|
||||
copy2 = obj.Data.MyField;
|
||||
|
||||
if (obj.Data == copy) {}
|
||||
if(obj.Data.MyField == 0) {}
|
||||
|
||||
// We should be allowed to access all of these, they let others read it!
|
||||
var copy3 = obj.Data2;
|
||||
copy = obj.Data2;
|
||||
|
||||
var copy4 = obj.Data2.MyField;
|
||||
copy4 = obj.Data2.MyField;
|
||||
|
||||
if(obj.Data2 == copy) {}
|
||||
if(obj.Data2.MyField == 0) {}
|
||||
}
|
||||
}";
|
||||
|
||||
await Verifier(code,
|
||||
// AUTO-GENERATED DIAGNOSTICS BELOW //
|
||||
// /0/Test0.cs(35,20): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(35, 20, 35, 24).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(36,21): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(36, 21, 36, 30).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(37,21): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(37, 21, 37, 29).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(39,16): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(39, 16, 39, 20).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(40,16): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(40, 16, 40, 25).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(41,16): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(41, 16, 41, 24).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(43,21): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(43, 21, 43, 25).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(44,21): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(44, 21, 44, 30).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(45,21): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(45, 21, 45, 29).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(47,13): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(47, 13, 47, 17).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(48,13): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(48, 13, 48, 22).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(49,13): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(49, 13, 49, 21).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(51,12): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(51, 12, 51, 16).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(52,12): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(52, 12, 52, 21).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(53,12): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(53, 12, 53, 20).WithArguments("a 'Read' same-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(95,20): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(95, 20, 95, 24).WithArguments("a 'Read' same-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(96,21): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(96, 21, 96, 30).WithArguments("a 'Read' same-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(97,21): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(97, 21, 97, 29).WithArguments("a 'Read' other-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(99,16): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(99, 16, 99, 20).WithArguments("a 'Read' same-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(100,16): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(100, 16, 100, 25).WithArguments("a 'Read' same-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(101,16): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(101, 16, 101, 24).WithArguments("a 'Read' other-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(103,21): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(103, 21, 103, 25).WithArguments("a 'Read' same-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(104,21): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(104, 21, 104, 30).WithArguments("a 'Read' same-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(105,21): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(105, 21, 105, 29).WithArguments("a 'Read' other-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(107,13): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(107, 13, 107, 17).WithArguments("a 'Read' same-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(108,13): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(108, 13, 108, 22).WithArguments("a 'Read' same-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(109,13): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(109, 13, 109, 21).WithArguments("a 'Read' other-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(111,12): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(111, 12, 111, 16).WithArguments("a 'Read' same-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(112,12): error RA0002: Tried to perform a 'Read' same-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(112, 12, 112, 21).WithArguments("a 'Read' same-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(113,12): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(113, 12, 113, 20).WithArguments("a 'Read' other-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(143,20): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(143, 20, 143, 28).WithArguments("a 'Read' friend-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(144,16): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(144, 16, 144, 24).WithArguments("a 'Read' friend-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(146,21): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(146, 21, 146, 29).WithArguments("a 'Read' friend-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(147,17): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(147, 17, 147, 25).WithArguments("a 'Read' friend-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(149,13): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(149, 13, 149, 21).WithArguments("a 'Read' friend-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(150,12): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(150, 12, 150, 20).WithArguments("a 'Read' friend-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(166,20): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(166, 20, 166, 28).WithArguments("a 'Read' friend-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(167,16): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(167, 16, 167, 24).WithArguments("a 'Read' friend-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(169,21): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(169, 21, 169, 29).WithArguments("a 'Read' friend-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(170,17): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(170, 17, 170, 25).WithArguments("a 'Read' friend-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(172,13): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(172, 13, 172, 21).WithArguments("a 'Read' friend-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(173,12): error RA0002: Tried to perform a 'Read' friend-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(173, 12, 173, 20).WithArguments("a 'Read' friend-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(192,20): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(192, 20, 192, 28).WithArguments("a 'Read' other-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(193,16): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(193, 16, 193, 24).WithArguments("a 'Read' other-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(195,21): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(195, 21, 195, 29).WithArguments("a 'Read' other-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(196,17): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(196, 17, 196, 25).WithArguments("a 'Read' other-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(198,13): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(198, 13, 198, 21).WithArguments("a 'Read' other-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(199,12): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'TypeNobodyCanRead', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(199, 12, 199, 20).WithArguments("a 'Read' other-type", "Data", "TypeNobodyCanRead", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(215,20): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(215, 20, 215, 28).WithArguments("a 'Read' other-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(216,16): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(216, 16, 216, 24).WithArguments("a 'Read' other-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(218,21): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(218, 21, 218, 29).WithArguments("a 'Read' other-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(219,17): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(219, 17, 219, 25).WithArguments("a 'Read' other-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(221,13): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(221, 13, 221, 21).WithArguments("a 'Read' other-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(222,12): error RA0002: Tried to perform a 'Read' other-type access to member 'Data' in type 'MemberNobodyCanRead', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(222, 12, 222, 20).WithArguments("a 'Read' other-type", "Data", "MemberNobodyCanRead", "having no", "Member Permissions: ---------")
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task WriteTest()
|
||||
{
|
||||
const string code = @"
|
||||
using System;
|
||||
using Robust.Shared.Analyzers;
|
||||
// ReSharper disable RedundantAssignment
|
||||
// ReSharper disable UnusedVariable
|
||||
// ReSharper disable ArrangeThisQualifier
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable UnusedType.Global
|
||||
// ReSharper disable NotAccessedField.Global
|
||||
// ReSharper disable RedundantDefaultMemberInitializer
|
||||
|
||||
public struct MyData
|
||||
{
|
||||
public int MyField;
|
||||
}
|
||||
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.None,
|
||||
Friend = AccessPermissions.None,
|
||||
Other = AccessPermissions.None)]
|
||||
public sealed class TypeNobodyCanWrite
|
||||
{
|
||||
public MyData Data = default;
|
||||
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.Write,
|
||||
Friend = AccessPermissions.Write,
|
||||
Other = AccessPermissions.Write)]
|
||||
public MyData Data2 = default;
|
||||
|
||||
public void TestTypeNobodyCanWrite(TypeNobodyCanWrite obj)
|
||||
{
|
||||
// None of these accesses should be allowed.
|
||||
Data = default;
|
||||
this.Data = default;
|
||||
obj.Data = default;
|
||||
|
||||
Data.MyField = 0;
|
||||
this.Data.MyField = 0;
|
||||
obj.Data.MyField = 0;
|
||||
|
||||
// All of these accesses should be fine.
|
||||
Data2 = default;
|
||||
this.Data2 = default;
|
||||
obj.Data2 = default;
|
||||
|
||||
Data2.MyField = 0;
|
||||
this.Data2.MyField = 0;
|
||||
obj.Data2.MyField = 0;
|
||||
}
|
||||
}
|
||||
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.Write,
|
||||
Friend = AccessPermissions.Write,
|
||||
Other = AccessPermissions.Write)]
|
||||
public sealed class MemberNobodyCanWrite
|
||||
{
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.None,
|
||||
Friend = AccessPermissions.None,
|
||||
Other = AccessPermissions.None)]
|
||||
public MyData Data = default;
|
||||
|
||||
public MyData Data2 = default;
|
||||
|
||||
public void TestMemberNobodyCanWrite(TypeNobodyCanWrite obj)
|
||||
{
|
||||
// None of these accesses should be allowed.
|
||||
Data = default;
|
||||
this.Data = default;
|
||||
obj.Data = default;
|
||||
|
||||
Data.MyField = 0;
|
||||
this.Data.MyField = 0;
|
||||
obj.Data.MyField = 0;
|
||||
|
||||
// All of these accesses should be fine.
|
||||
Data2 = default;
|
||||
this.Data2 = default;
|
||||
obj.Data2 = default;
|
||||
|
||||
Data2.MyField = 0;
|
||||
this.Data2.MyField = 0;
|
||||
obj.Data2.MyField = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class FriendlyClass
|
||||
{
|
||||
public void TestTypeNobodyCanWrite(TypeNobodyCanWrite obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, even if we're a friend..
|
||||
obj.Data = default;
|
||||
obj.Data.MyField = 0;
|
||||
|
||||
// We should be allowed to access all of these, we're friends!
|
||||
obj.Data2 = default;
|
||||
obj.Data2.MyField = 0;
|
||||
}
|
||||
|
||||
public void TestMemberNobodyCanWrite(MemberNobodyCanWrite obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, even if we're a friend..
|
||||
obj.Data = default;
|
||||
obj.Data.MyField = 0;
|
||||
|
||||
// We should be allowed to access all of these, we're friends!
|
||||
obj.Data2 = default;
|
||||
obj.Data2.MyField = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class OtherClass
|
||||
{
|
||||
public void TestTypeNobodyCanWrite(TypeNobodyCanWrite obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, as 'other types' can't..
|
||||
obj.Data = default;
|
||||
obj.Data.MyField = 0;
|
||||
|
||||
// We should be allowed to access all of these, they let others write!
|
||||
obj.Data2 = default;
|
||||
obj.Data2.MyField = 0;
|
||||
}
|
||||
|
||||
public void TestMemberNobodyCanWrite(MemberNobodyCanWrite obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, as 'other types' can't..
|
||||
obj.Data = default;
|
||||
obj.Data.MyField = 0;
|
||||
|
||||
// We should be allowed to access all of these, they let others write!
|
||||
obj.Data2 = default;
|
||||
obj.Data2.MyField = 0;
|
||||
}
|
||||
}";
|
||||
|
||||
await Verifier(code,
|
||||
// AUTO-GENERATED DIAGNOSTICS BELOW //
|
||||
// /0/Test0.cs(34,9): error RA0002: Tried to perform a 'Write' same-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(34, 9, 34, 13).WithArguments("a 'Write' same-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(35,9): error RA0002: Tried to perform a 'Write' same-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(35, 9, 35, 18).WithArguments("a 'Write' same-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(36,9): error RA0002: Tried to perform a 'Write' same-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(36, 9, 36, 17).WithArguments("a 'Write' same-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(38,9): error RA0002: Tried to perform a 'Write' same-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(38, 9, 38, 13).WithArguments("a 'Write' same-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(39,9): error RA0002: Tried to perform a 'Write' same-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(39, 9, 39, 18).WithArguments("a 'Write' same-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(40,9): error RA0002: Tried to perform a 'Write' same-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(40, 9, 40, 17).WithArguments("a 'Write' same-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(70,9): error RA0002: Tried to perform a 'Write' same-type access to member 'Data' in type 'MemberNobodyCanWrite', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(70, 9, 70, 13).WithArguments("a 'Write' same-type", "Data", "MemberNobodyCanWrite", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(71,9): error RA0002: Tried to perform a 'Write' same-type access to member 'Data' in type 'MemberNobodyCanWrite', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(71, 9, 71, 18).WithArguments("a 'Write' same-type", "Data", "MemberNobodyCanWrite", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(72,9): error RA0002: Tried to perform a 'Write' other-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(72, 9, 72, 17).WithArguments("a 'Write' other-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(74,9): error RA0002: Tried to perform a 'Write' same-type access to member 'Data' in type 'MemberNobodyCanWrite', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(74, 9, 74, 13).WithArguments("a 'Write' same-type", "Data", "MemberNobodyCanWrite", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(75,9): error RA0002: Tried to perform a 'Write' same-type access to member 'Data' in type 'MemberNobodyCanWrite', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(75, 9, 75, 18).WithArguments("a 'Write' same-type", "Data", "MemberNobodyCanWrite", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(76,9): error RA0002: Tried to perform a 'Write' other-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(76, 9, 76, 17).WithArguments("a 'Write' other-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(94,9): error RA0002: Tried to perform a 'Write' friend-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(94, 9, 94, 17).WithArguments("a 'Write' friend-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(95,9): error RA0002: Tried to perform a 'Write' friend-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(95, 9, 95, 17).WithArguments("a 'Write' friend-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(105,9): error RA0002: Tried to perform a 'Write' friend-type access to member 'Data' in type 'MemberNobodyCanWrite', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(105, 9, 105, 17).WithArguments("a 'Write' friend-type", "Data", "MemberNobodyCanWrite", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(106,9): error RA0002: Tried to perform a 'Write' friend-type access to member 'Data' in type 'MemberNobodyCanWrite', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(106, 9, 106, 17).WithArguments("a 'Write' friend-type", "Data", "MemberNobodyCanWrite", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(119,9): error RA0002: Tried to perform a 'Write' other-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(119, 9, 119, 17).WithArguments("a 'Write' other-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(120,9): error RA0002: Tried to perform a 'Write' other-type access to member 'Data' in type 'TypeNobodyCanWrite', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(120, 9, 120, 17).WithArguments("a 'Write' other-type", "Data", "TypeNobodyCanWrite", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(130,9): error RA0002: Tried to perform a 'Write' other-type access to member 'Data' in type 'MemberNobodyCanWrite', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(130, 9, 130, 17).WithArguments("a 'Write' other-type", "Data", "MemberNobodyCanWrite", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(131,9): error RA0002: Tried to perform a 'Write' other-type access to member 'Data' in type 'MemberNobodyCanWrite', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(131, 9, 131, 17).WithArguments("a 'Write' other-type", "Data", "MemberNobodyCanWrite", "having no", "Member Permissions: ---------")
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ExecuteTest()
|
||||
{
|
||||
const string code = @"
|
||||
using System;
|
||||
using Robust.Shared.Analyzers;
|
||||
// ReSharper disable RedundantAssignment
|
||||
// ReSharper disable UnusedVariable
|
||||
// ReSharper disable ArrangeThisQualifier
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable UnusedType.Global
|
||||
// ReSharper disable NotAccessedField.Global
|
||||
// ReSharper disable RedundantDefaultMemberInitializer
|
||||
// ReSharper disable ReturnValueOfPureMethodIsNotUsed
|
||||
|
||||
public struct MyData
|
||||
{
|
||||
public int MyField;
|
||||
public void MyMethod() {}
|
||||
}
|
||||
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.None,
|
||||
Friend = AccessPermissions.None,
|
||||
Other = AccessPermissions.None)]
|
||||
public sealed class TypeNobodyCanExecute
|
||||
{
|
||||
public MyData Data = default;
|
||||
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.Execute,
|
||||
Friend = AccessPermissions.Execute,
|
||||
Other = AccessPermissions.Execute)]
|
||||
public MyData Data2 = default;
|
||||
|
||||
public void MyMethod() {}
|
||||
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.Execute,
|
||||
Friend = AccessPermissions.Execute,
|
||||
Other = AccessPermissions.Execute)]
|
||||
public void MyMethod2() {}
|
||||
|
||||
public void TestTypeNobodyCanExecute(TypeNobodyCanExecute obj)
|
||||
{
|
||||
// None of these accesses should be allowed.
|
||||
MyMethod();
|
||||
this.MyMethod();
|
||||
obj.MyMethod();
|
||||
|
||||
Data.MyMethod();
|
||||
this.Data.MyMethod();
|
||||
obj.Data.MyMethod();
|
||||
|
||||
Data.MyField.ToString();
|
||||
this.Data.MyField.ToString();
|
||||
obj.Data.MyField.ToString();
|
||||
|
||||
// All of these accesses should be fine.
|
||||
MyMethod2();
|
||||
this.MyMethod2();
|
||||
obj.MyMethod2();
|
||||
|
||||
Data2.MyMethod();
|
||||
this.Data2.MyMethod();
|
||||
obj.Data2.MyMethod();
|
||||
|
||||
Data2.MyField.ToString();
|
||||
this.Data2.ToString();
|
||||
obj.Data2.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.Execute,
|
||||
Friend = AccessPermissions.Execute,
|
||||
Other = AccessPermissions.Execute)]
|
||||
public sealed class MemberNobodyCanExecute
|
||||
{
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.None,
|
||||
Friend = AccessPermissions.None,
|
||||
Other = AccessPermissions.None)]
|
||||
public MyData Data = default;
|
||||
|
||||
public MyData Data2 = default;
|
||||
|
||||
[Access(typeof(FriendlyClass),
|
||||
Self = AccessPermissions.None,
|
||||
Friend = AccessPermissions.None,
|
||||
Other = AccessPermissions.None)]
|
||||
public void MyMethod() {}
|
||||
|
||||
public void MyMethod2() {}
|
||||
|
||||
public void TestMemberNobodyCanExecute(TypeNobodyCanExecute obj)
|
||||
{
|
||||
// None of these accesses should be allowed.
|
||||
MyMethod();
|
||||
this.MyMethod();
|
||||
obj.MyMethod();
|
||||
|
||||
Data.MyMethod();
|
||||
this.Data.MyMethod();
|
||||
obj.Data.MyMethod();
|
||||
|
||||
Data.MyField.ToString();
|
||||
this.Data.MyField.ToString();
|
||||
obj.Data.MyField.ToString();
|
||||
|
||||
// All of these accesses should be fine.
|
||||
MyMethod2();
|
||||
this.MyMethod2();
|
||||
obj.MyMethod2();
|
||||
|
||||
Data2.MyMethod();
|
||||
this.Data2.MyMethod();
|
||||
obj.Data2.MyMethod();
|
||||
|
||||
Data2.MyField.ToString();
|
||||
this.Data2.ToString();
|
||||
obj.Data2.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class FriendlyClass
|
||||
{
|
||||
public void TestTypeNobodyCanExecute(TypeNobodyCanExecute obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, even if we're a friend..
|
||||
obj.MyMethod();
|
||||
obj.Data.MyMethod();
|
||||
obj.Data.MyField.ToString();
|
||||
|
||||
// We should be allowed to access all of these, we're friends!
|
||||
obj.MyMethod2();
|
||||
obj.Data2.MyMethod();
|
||||
obj.Data2.MyField.ToString();
|
||||
}
|
||||
|
||||
public void TestMemberNobodyCanExecute(MemberNobodyCanExecute obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, even if we're a friend..
|
||||
obj.MyMethod();
|
||||
obj.Data.MyMethod();
|
||||
obj.Data.MyField.ToString();
|
||||
|
||||
// We should be allowed to access all of these, we're friends!
|
||||
obj.MyMethod2();
|
||||
obj.Data2.MyMethod();
|
||||
obj.Data2.MyField.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class OtherClass
|
||||
{
|
||||
public void TestTypeNobodyCanExecute(TypeNobodyCanExecute obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, as 'other types' can't..
|
||||
obj.MyMethod();
|
||||
obj.Data.MyMethod();
|
||||
obj.Data.MyField.ToString();
|
||||
|
||||
// We should be allowed to access all of these, they let others Execute!
|
||||
obj.MyMethod2();
|
||||
obj.Data2.MyMethod();
|
||||
obj.Data2.MyField.ToString();
|
||||
}
|
||||
|
||||
public void TestMemberNobodyCanExecute(MemberNobodyCanExecute obj)
|
||||
{
|
||||
// We shouldn't be able to access any of these, as 'other types' can't..
|
||||
obj.MyMethod();
|
||||
obj.Data.MyMethod();
|
||||
obj.Data.MyField.ToString();
|
||||
|
||||
// We should be allowed to access all of these, they let others Execute!
|
||||
obj.MyMethod2();
|
||||
obj.Data2.MyMethod();
|
||||
obj.Data2.MyField.ToString();
|
||||
}
|
||||
}";
|
||||
|
||||
await Verifier(code,
|
||||
// AUTO-GENERATED DIAGNOSTICS BELOW //
|
||||
// /0/Test0.cs(44,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'MyMethod' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(44, 9, 44, 19).WithArguments("an 'Execute' same-type", "MyMethod", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(45,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'MyMethod' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(45, 9, 45, 24).WithArguments("an 'Execute' same-type", "MyMethod", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(46,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'MyMethod' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(46, 9, 46, 23).WithArguments("an 'Execute' same-type", "MyMethod", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(48,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(48, 9, 48, 13).WithArguments("an 'Execute' same-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(49,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(49, 9, 49, 18).WithArguments("an 'Execute' same-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(50,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(50, 9, 50, 17).WithArguments("an 'Execute' same-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(52,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(52, 9, 52, 13).WithArguments("an 'Execute' same-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(53,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(53, 9, 53, 18).WithArguments("an 'Execute' same-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(54,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(54, 9, 54, 17).WithArguments("an 'Execute' same-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(96,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'MyMethod' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(96, 9, 96, 19).WithArguments("an 'Execute' same-type", "MyMethod", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(97,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'MyMethod' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(97, 9, 97, 24).WithArguments("an 'Execute' same-type", "MyMethod", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(98,9): error RA0002: Tried to perform an 'Execute' other-type access to member 'MyMethod' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(98, 9, 98, 23).WithArguments("an 'Execute' other-type", "MyMethod", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(100,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'Data' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(100, 9, 100, 13).WithArguments("an 'Execute' same-type", "Data", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(101,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'Data' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(101, 9, 101, 18).WithArguments("an 'Execute' same-type", "Data", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(102,9): error RA0002: Tried to perform an 'Execute' other-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(102, 9, 102, 17).WithArguments("an 'Execute' other-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(104,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'Data' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(104, 9, 104, 13).WithArguments("an 'Execute' same-type", "Data", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(105,9): error RA0002: Tried to perform an 'Execute' same-type access to member 'Data' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(105, 9, 105, 18).WithArguments("an 'Execute' same-type", "Data", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(106,9): error RA0002: Tried to perform an 'Execute' other-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(106, 9, 106, 17).WithArguments("an 'Execute' other-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(128,9): error RA0002: Tried to perform an 'Execute' friend-type access to member 'MyMethod' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(128, 9, 128, 23).WithArguments("an 'Execute' friend-type", "MyMethod", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(129,9): error RA0002: Tried to perform an 'Execute' friend-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(129, 9, 129, 17).WithArguments("an 'Execute' friend-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(130,9): error RA0002: Tried to perform an 'Execute' friend-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(130, 9, 130, 17).WithArguments("an 'Execute' friend-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(141,9): error RA0002: Tried to perform an 'Execute' friend-type access to member 'MyMethod' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(141, 9, 141, 23).WithArguments("an 'Execute' friend-type", "MyMethod", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(142,9): error RA0002: Tried to perform an 'Execute' friend-type access to member 'Data' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(142, 9, 142, 17).WithArguments("an 'Execute' friend-type", "Data", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(143,9): error RA0002: Tried to perform an 'Execute' friend-type access to member 'Data' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(143, 9, 143, 17).WithArguments("an 'Execute' friend-type", "Data", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(157,9): error RA0002: Tried to perform an 'Execute' other-type access to member 'MyMethod' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(157, 9, 157, 23).WithArguments("an 'Execute' other-type", "MyMethod", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(158,9): error RA0002: Tried to perform an 'Execute' other-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(158, 9, 158, 17).WithArguments("an 'Execute' other-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(159,9): error RA0002: Tried to perform an 'Execute' other-type access to member 'Data' in type 'TypeNobodyCanExecute', despite having no access. Type Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(159, 9, 159, 17).WithArguments("an 'Execute' other-type", "Data", "TypeNobodyCanExecute", "having no", "Type Permissions: ---------"),
|
||||
// /0/Test0.cs(170,9): error RA0002: Tried to perform an 'Execute' other-type access to member 'MyMethod' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(170, 9, 170, 23).WithArguments("an 'Execute' other-type", "MyMethod", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(171,9): error RA0002: Tried to perform an 'Execute' other-type access to member 'Data' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(171, 9, 171, 17).WithArguments("an 'Execute' other-type", "Data", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------"),
|
||||
// /0/Test0.cs(172,9): error RA0002: Tried to perform an 'Execute' other-type access to member 'Data' in type 'MemberNobodyCanExecute', despite having no access. Member Permissions: ---------
|
||||
VerifyCS.Diagnostic().WithSpan(172, 9, 172, 17).WithArguments("an 'Execute' other-type", "Data", "MemberNobodyCanExecute", "having no", "Member Permissions: ---------")
|
||||
);
|
||||
}
|
||||
}
|
||||
24
Robust.Analyzers.Tests/Robust.Analyzers.Tests.csproj
Normal file
24
Robust.Analyzers.Tests/Robust.Analyzers.Tests.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\MSBuild\Robust.Properties.targets" />
|
||||
<Import Project="..\MSBuild\Robust.Engine.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzer.Testing" Version="1.1.1"/>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1"/>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.NUnit" Version="1.1.1"/>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.1"/>
|
||||
<PackageReference Include="NUnit" Version="3.13.2"/>
|
||||
<PackageReference Include="NUnit.ConsoleRunner" Version="3.15.0"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.3.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Robust.Analyzers\Robust.Analyzers.csproj"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
253
Robust.Analyzers/AccessAnalyzer.cs
Normal file
253
Robust.Analyzers/AccessAnalyzer.cs
Normal file
@@ -0,0 +1,253 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
using Microsoft.CodeAnalysis.Operations;
|
||||
using Robust.Shared.Analyzers.Implementation;
|
||||
|
||||
namespace Robust.Analyzers
|
||||
{
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public class AccessAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
private const string AccessAttributeType = "Robust.Shared.Analyzers.AccessAttribute";
|
||||
private const string PureAttributeType = "System.Diagnostics.Contracts.PureAttribute";
|
||||
|
||||
[SuppressMessage("ReSharper", "RS2008")]
|
||||
private static readonly DiagnosticDescriptor AccessRule = new (
|
||||
Diagnostics.IdAccess,
|
||||
"Invalid access",
|
||||
"Tried to perform {0} access to member '{1}' in type '{2}', despite {3} access. {4}.",
|
||||
"Usage",
|
||||
DiagnosticSeverity.Error,
|
||||
true,
|
||||
"Make sure to give the accessing type the correct access permissions.");
|
||||
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
|
||||
ImmutableArray.Create(AccessRule);
|
||||
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
|
||||
context.EnableConcurrentExecution();
|
||||
context.RegisterOperationAction(CheckFriendship,
|
||||
OperationKind.FieldReference,
|
||||
OperationKind.PropertyReference,
|
||||
OperationKind.MethodReference,
|
||||
OperationKind.Invocation);
|
||||
}
|
||||
|
||||
private void CheckFriendship(OperationAnalysisContext context)
|
||||
{
|
||||
var operation = context.Operation;
|
||||
|
||||
// The symbol representing the member being accessed.
|
||||
ISymbol member;
|
||||
|
||||
// The operation to target when determining access type.
|
||||
IOperation targetAccess;
|
||||
|
||||
switch (operation)
|
||||
{
|
||||
case IMemberReferenceOperation memberRef:
|
||||
{
|
||||
member = memberRef.Member;
|
||||
targetAccess = memberRef.Parent;
|
||||
break;
|
||||
}
|
||||
|
||||
case IInvocationOperation invocation:
|
||||
{
|
||||
member = invocation.TargetMethod;
|
||||
targetAccess = invocation;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the info of the type defining the member, so we can check the attributes later...
|
||||
var accessedType = member.ContainingType;
|
||||
|
||||
// Get the attributes
|
||||
var friendAttribute = context.Compilation.GetTypeByMetadataName(AccessAttributeType);
|
||||
|
||||
// Get the type that is containing this expression, or, the type where this is happening.
|
||||
if (context.ContainingSymbol?.ContainingType is not {} accessingType)
|
||||
return;
|
||||
|
||||
// Determine which type of access is happening here... Read, write or execute?
|
||||
var accessAttempt = DetermineAccess(context, targetAccess, operation);
|
||||
|
||||
// Check whether this is a "self" access, including inheritors.
|
||||
var selfAccess = InheritsFromOrEquals(accessingType, accessedType);
|
||||
|
||||
// Helper function to deduplicate attribute-checking code.
|
||||
bool CheckAttributeFriendship(AttributeData attribute, bool isMemberAttribute)
|
||||
{
|
||||
// If the attribute isn't the friend attribute, we don't care about it.
|
||||
if (!SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, friendAttribute))
|
||||
return false;
|
||||
|
||||
var self = AccessAttribute.SelfDefaultPermissions;
|
||||
var friends = AccessAttribute.FriendDefaultPermissions;
|
||||
var others = AccessAttribute.OtherDefaultPermissions;
|
||||
|
||||
foreach (var kv in attribute.NamedArguments)
|
||||
{
|
||||
if (kv.Value.Value is not byte value)
|
||||
continue;
|
||||
|
||||
var permissions = (AccessPermissions) value;
|
||||
|
||||
switch (kv.Key)
|
||||
{
|
||||
case nameof(AccessAttribute.Self):
|
||||
{
|
||||
self = permissions;
|
||||
break;
|
||||
}
|
||||
|
||||
case nameof(AccessAttribute.Friend):
|
||||
{
|
||||
friends = permissions;
|
||||
break;
|
||||
}
|
||||
|
||||
case nameof(AccessAttribute.Other):
|
||||
{
|
||||
others = permissions;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// By default, we will check the "other" permissions unless we find we're dealing with a friend or self.
|
||||
var permissionCheck = others;
|
||||
|
||||
// Human-readable relation between accessing and accessed types.
|
||||
var accessingRelation = "other-type";
|
||||
|
||||
if (!selfAccess)
|
||||
{
|
||||
// This is not a self-access, so we need to determine whether the accessing type is a friend.
|
||||
// Check all types allowed in the friend attribute. (We assume there's only one constructor arg.)
|
||||
var types = attribute.ConstructorArguments[0].Values;
|
||||
|
||||
foreach (var constant in types)
|
||||
{
|
||||
// Check if the value is a type...
|
||||
if (constant.Value is not INamedTypeSymbol friendType)
|
||||
continue;
|
||||
|
||||
// Check if the accessing type is specified in the attribute...
|
||||
if (!InheritsFromOrEquals(accessingType, friendType))
|
||||
continue;
|
||||
|
||||
// Set the permissions check to the friend permissions!
|
||||
permissionCheck = friends;
|
||||
accessingRelation = "friend-type";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Self-access, so simply set the permissions check to self.
|
||||
permissionCheck = self;
|
||||
accessingRelation = "same-type";
|
||||
}
|
||||
|
||||
// If we allow this access, return! All is good.
|
||||
if ((accessAttempt & permissionCheck) != 0)
|
||||
return true;
|
||||
|
||||
// Access denied! Report an error.
|
||||
context.ReportDiagnostic(
|
||||
Diagnostic.Create(AccessRule, operation.Syntax.GetLocation(),
|
||||
$"a{(accessAttempt == AccessPermissions.Execute ? "n" : "")} '{accessAttempt}' {accessingRelation}",
|
||||
$"{member.Name}",
|
||||
$"{accessedType.Name}",
|
||||
$"{(permissionCheck == AccessPermissions.None ? "having no" : $"only having '{permissionCheck}'")}",
|
||||
$"{(isMemberAttribute ? "Member" : "Type")} Permissions: {self.ToUnixPermissions()}{friends.ToUnixPermissions()}{others.ToUnixPermissions()}"));
|
||||
|
||||
// Only return ONE error.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check attributes in the member first, since they take priority and can override type restrictions.
|
||||
foreach (var attribute in member.GetAttributes())
|
||||
{
|
||||
if(CheckAttributeFriendship(attribute, true))
|
||||
return;
|
||||
}
|
||||
|
||||
// Check attributes in the type containing the member last.
|
||||
foreach (var attribute in accessedType.GetAttributes())
|
||||
{
|
||||
if(CheckAttributeFriendship(attribute, false))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static AccessPermissions DetermineAccess(OperationAnalysisContext context, IOperation operation, IOperation original)
|
||||
{
|
||||
switch (operation)
|
||||
{
|
||||
case IAssignmentOperation assign:
|
||||
{
|
||||
return assign.Target.Equals(original) ? AccessPermissions.Write : AccessPermissions.Read;
|
||||
}
|
||||
|
||||
case IInvocationOperation invoke:
|
||||
{
|
||||
var pureAttribute = context.Compilation.GetTypeByMetadataName(PureAttributeType);
|
||||
|
||||
foreach (var attribute in invoke.TargetMethod.GetAttributes())
|
||||
{
|
||||
// Pure methods are treated as read accesses.
|
||||
if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, pureAttribute))
|
||||
return AccessPermissions.Read;
|
||||
}
|
||||
|
||||
return AccessPermissions.Execute;
|
||||
}
|
||||
|
||||
case IMemberReferenceOperation member:
|
||||
{
|
||||
return DetermineAccess(context, member.Parent, operation);
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
return AccessPermissions.Read;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool InheritsFromOrEquals(INamedTypeSymbol type, INamedTypeSymbol baseType)
|
||||
{
|
||||
foreach (var otherType in GetBaseTypesAndThis(type))
|
||||
{
|
||||
if (SymbolEqualityComparer.Default.Equals(otherType, baseType))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private IEnumerable<INamedTypeSymbol> GetBaseTypesAndThis(INamedTypeSymbol namedType)
|
||||
{
|
||||
var current = namedType;
|
||||
while (current != null)
|
||||
{
|
||||
yield return current;
|
||||
current = current.BaseType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,9 @@ public static class Diagnostics
|
||||
{
|
||||
public const string IdExplicitInterface = "RA0000";
|
||||
public const string IdSerializable = "RA0001";
|
||||
public const string IdFriend = "RA0002";
|
||||
public const string IdAccess = "RA0002";
|
||||
public const string IdExplicitVirtual = "RA0003";
|
||||
public const string IdTaskResult = "RA0004";
|
||||
|
||||
public static SuppressionDescriptor MeansImplicitAssignment =>
|
||||
new SuppressionDescriptor("RADC1000", "CS0649", "Marked as implicitly assigned.");
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
namespace Robust.Analyzers
|
||||
{
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public class FriendAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
const string FriendAttribute = "Robust.Shared.Analyzers.FriendAttribute";
|
||||
|
||||
[SuppressMessage("ReSharper", "RS2008")]
|
||||
private static readonly DiagnosticDescriptor Rule = new (
|
||||
Diagnostics.IdFriend,
|
||||
"Tried to access friend-only member",
|
||||
"Tried to access member \"{0}\" in class \"{1}\" which can only be accessed by friend classes",
|
||||
"Usage",
|
||||
DiagnosticSeverity.Error,
|
||||
true,
|
||||
"Make sure to specify the accessing class in the friends attribute.");
|
||||
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);
|
||||
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
|
||||
context.EnableConcurrentExecution();
|
||||
context.RegisterSyntaxNodeAction(CheckFriendship, SyntaxKind.SimpleMemberAccessExpression);
|
||||
}
|
||||
|
||||
private void CheckFriendship(SyntaxNodeAnalysisContext context)
|
||||
{
|
||||
if (context.Node is not MemberAccessExpressionSyntax memberAccess)
|
||||
return;
|
||||
|
||||
// We only do something if our parent is one of a few types.
|
||||
switch (context.Node.Parent)
|
||||
{
|
||||
// If we're being assigned...
|
||||
case AssignmentExpressionSyntax assignParent:
|
||||
{
|
||||
if (assignParent.Left != memberAccess)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
// If we're being invoked...
|
||||
case InvocationExpressionSyntax:
|
||||
break;
|
||||
|
||||
// Otherwise, do nothing.
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the friend attribute
|
||||
var friendAttr = context.Compilation.GetTypeByMetadataName(FriendAttribute);
|
||||
|
||||
// Get the type that is containing this expression, or, the class where this is happening.
|
||||
if (context.ContainingSymbol?.ContainingType is not { } containingType)
|
||||
return;
|
||||
|
||||
// We check all of our children and get only the identifiers.
|
||||
foreach (var identifier in memberAccess.ChildNodes().Select(node => node as IdentifierNameSyntax))
|
||||
{
|
||||
if (identifier == null) continue;
|
||||
|
||||
// Get the type info of the identifier, so we can check the attributes...
|
||||
if (context.SemanticModel.GetTypeInfo(identifier).ConvertedType is not { } type)
|
||||
continue;
|
||||
|
||||
// Same-type access is always fine.
|
||||
if (SymbolEqualityComparer.Default.Equals(type, containingType))
|
||||
continue;
|
||||
|
||||
// Finally, get all attributes of the type, to check if we have any friend classes.
|
||||
foreach (var attribute in type.GetAttributes())
|
||||
{
|
||||
// If the attribute isn't the friend attribute, continue.
|
||||
if (!SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, friendAttr))
|
||||
continue;
|
||||
|
||||
// Check all types allowed in the friend attribute. (We assume there's only one constructor arg.)
|
||||
foreach (var constant in attribute.ConstructorArguments[0].Values)
|
||||
{
|
||||
// Check if the value is a type...
|
||||
if (constant.Value is not INamedTypeSymbol t)
|
||||
continue;
|
||||
|
||||
// If we find that the containing class is specified in the attribute, return! All is good.
|
||||
if (InheritsFromOrEquals(containingType, t))
|
||||
return;
|
||||
}
|
||||
|
||||
// Not in a friend class! Report an error.
|
||||
context.ReportDiagnostic(
|
||||
Diagnostic.Create(Rule, context.Node.GetLocation(),
|
||||
$"{context.Node.ToString().Split('.').LastOrDefault()}", $"{type.Name}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool InheritsFromOrEquals(INamedTypeSymbol type, INamedTypeSymbol baseType)
|
||||
{
|
||||
foreach (var otherType in GetBaseTypesAndThis(type))
|
||||
{
|
||||
if (SymbolEqualityComparer.Default.Equals(otherType, baseType))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private IEnumerable<INamedTypeSymbol> GetBaseTypesAndThis(INamedTypeSymbol namedType)
|
||||
{
|
||||
var current = namedType;
|
||||
while (current != null)
|
||||
{
|
||||
yield return current;
|
||||
current = current.BaseType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,15 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="3.8.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Needed for FriendAnalyzer. -->
|
||||
<Compile Include="..\Robust.Shared\Analyzers\AccessAttribute.cs" />
|
||||
<Compile Include="..\Robust.Shared\Analyzers\AccessPermissions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
44
Robust.Analyzers/TaskResultAnalyzer.cs
Normal file
44
Robust.Analyzers/TaskResultAnalyzer.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
using Microsoft.CodeAnalysis.Operations;
|
||||
|
||||
namespace Robust.Analyzers;
|
||||
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class TaskResultAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
[SuppressMessage("ReSharper", "RS2008")]
|
||||
private static readonly DiagnosticDescriptor ResultRule = new DiagnosticDescriptor(
|
||||
Diagnostics.IdTaskResult,
|
||||
"Risk of deadlock from accessing Task<T>.Result",
|
||||
"Accessing Task<T>.Result is dangerous and can cause deadlocks in some contexts. If you understand how this works and are certain that you aren't causing a deadlock here, mute this error with #pragma.",
|
||||
"Usage",
|
||||
DiagnosticSeverity.Error,
|
||||
true);
|
||||
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
|
||||
ImmutableArray.Create(ResultRule);
|
||||
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
|
||||
context.EnableConcurrentExecution();
|
||||
context.RegisterOperationAction(Check, OperationKind.PropertyReference);
|
||||
}
|
||||
|
||||
private static void Check(OperationAnalysisContext context)
|
||||
{
|
||||
var taskType = context.Compilation.GetTypeByMetadataName("System.Threading.Tasks.Task`1");
|
||||
|
||||
var operation = (IPropertyReferenceOperation) context.Operation;
|
||||
var member = operation.Member;
|
||||
|
||||
if (member.Name == "Result" && taskType.Equals(member.ContainingType.ConstructedFrom, SymbolEqualityComparer.Default))
|
||||
{
|
||||
var diag = Diagnostic.Create(ResultRule, operation.Syntax.GetLocation());
|
||||
context.ReportDiagnostic(diag);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
Robust.Benchmarks/Configs/DefaultSQLConfig.cs
Normal file
53
Robust.Benchmarks/Configs/DefaultSQLConfig.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using BenchmarkDotNet.Analysers;
|
||||
using BenchmarkDotNet.Columns;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Diagnosers;
|
||||
using BenchmarkDotNet.Exporters;
|
||||
using BenchmarkDotNet.Filters;
|
||||
using BenchmarkDotNet.Jobs;
|
||||
using BenchmarkDotNet.Loggers;
|
||||
using BenchmarkDotNet.Order;
|
||||
using BenchmarkDotNet.Reports;
|
||||
using BenchmarkDotNet.Validators;
|
||||
using Robust.Benchmarks.Exporters;
|
||||
|
||||
namespace Robust.Benchmarks.Configs;
|
||||
|
||||
public sealed class DefaultSQLConfig : IConfig
|
||||
{
|
||||
public static readonly IConfig Instance = new DefaultSQLConfig();
|
||||
|
||||
private DefaultSQLConfig(){}
|
||||
|
||||
public IEnumerable<IExporter> GetExporters()
|
||||
{
|
||||
yield return SQLExporter.Default;
|
||||
}
|
||||
|
||||
public IEnumerable<IColumnProvider> GetColumnProviders() => DefaultConfig.Instance.GetColumnProviders();
|
||||
|
||||
public IEnumerable<ILogger> GetLoggers() => DefaultConfig.Instance.GetLoggers();
|
||||
|
||||
public IEnumerable<IDiagnoser> GetDiagnosers() => DefaultConfig.Instance.GetDiagnosers();
|
||||
|
||||
public IEnumerable<IAnalyser> GetAnalysers() => DefaultConfig.Instance.GetAnalysers();
|
||||
|
||||
public IEnumerable<Job> GetJobs() => DefaultConfig.Instance.GetJobs();
|
||||
|
||||
public IEnumerable<IValidator> GetValidators() => DefaultConfig.Instance.GetValidators();
|
||||
|
||||
public IEnumerable<HardwareCounter> GetHardwareCounters() => DefaultConfig.Instance.GetHardwareCounters();
|
||||
|
||||
public IEnumerable<IFilter> GetFilters() => DefaultConfig.Instance.GetFilters();
|
||||
|
||||
public IEnumerable<BenchmarkLogicalGroupRule> GetLogicalGroupRules() => DefaultConfig.Instance.GetLogicalGroupRules();
|
||||
|
||||
public IOrderer Orderer => DefaultConfig.Instance.Orderer!;
|
||||
public SummaryStyle SummaryStyle => DefaultConfig.Instance.SummaryStyle;
|
||||
public ConfigUnionRule UnionRule => DefaultConfig.Instance.UnionRule;
|
||||
public string ArtifactsPath => DefaultConfig.Instance.ArtifactsPath;
|
||||
public CultureInfo CultureInfo => DefaultConfig.Instance.CultureInfo!;
|
||||
public ConfigOptions Options => DefaultConfig.Instance.Options;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
namespace Robust.Benchmarks.EntityManager;
|
||||
|
||||
[Virtual]
|
||||
public class AddRemoveComponentBenchmark
|
||||
{
|
||||
private ISimulation _simulation = default!;
|
||||
private IEntityManager _entityManager = default!;
|
||||
|
||||
[UsedImplicitly]
|
||||
[Params(1, 10, 100, 1000)]
|
||||
public int N;
|
||||
|
||||
[GlobalSetup]
|
||||
public void GlobalSetup()
|
||||
{
|
||||
_simulation = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
.RegisterComponents(f => f.RegisterClass<A>())
|
||||
.InitializeInstance();
|
||||
|
||||
_entityManager = _simulation.Resolve<IEntityManager>();
|
||||
|
||||
var coords = new MapCoordinates(0, 0, new MapId(1));
|
||||
_simulation.AddMap(coords.MapId);
|
||||
|
||||
for (var i = 0; i < N; i++)
|
||||
{
|
||||
_entityManager.SpawnEntity(null, coords);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void AddRemoveComponent()
|
||||
{
|
||||
for (var i = 2; i <= N+1; i++)
|
||||
{
|
||||
var uid = new EntityUid(i);
|
||||
_entityManager.AddComponent<A>(uid);
|
||||
_entityManager.RemoveComponent<A>(uid);
|
||||
}
|
||||
}
|
||||
|
||||
[ComponentProtoName("A")]
|
||||
public sealed class A : Component
|
||||
{
|
||||
}
|
||||
}
|
||||
225
Robust.Benchmarks/EntityManager/ComponentIndexBenchmark.cs
Normal file
225
Robust.Benchmarks/EntityManager/ComponentIndexBenchmark.cs
Normal file
@@ -0,0 +1,225 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Robust.Benchmarks.EntityManager;
|
||||
|
||||
public class ComponentIndexBenchmark
|
||||
{
|
||||
// Just a bunch of types to bloat the test lists.
|
||||
|
||||
private readonly CompIndexFetcher _compIndexFetcherDirect;
|
||||
private readonly IFetcher _compIndexFetcher;
|
||||
private readonly DictFetcher _dictFetcherDirect;
|
||||
private readonly IFetcher _dictFetcher;
|
||||
|
||||
|
||||
public ComponentIndexBenchmark()
|
||||
{
|
||||
_compIndexFetcherDirect = new CompIndexFetcher();
|
||||
_compIndexFetcher = _compIndexFetcherDirect;
|
||||
_dictFetcherDirect = new DictFetcher();
|
||||
_dictFetcher = _dictFetcherDirect;
|
||||
}
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
var types = typeof(ComponentIndexBenchmark)
|
||||
.GetNestedTypes(BindingFlags.NonPublic)
|
||||
.Where(t => t.Name.StartsWith("TestType"))
|
||||
.ToArray();
|
||||
|
||||
_compIndexFetcher.Init(types);
|
||||
_dictFetcher.Init(types);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int BenchCompIndex() => _compIndexFetcher.Get<TestType50>();
|
||||
|
||||
[Benchmark]
|
||||
public int BenchDict() => _dictFetcher.Get<TestType50>();
|
||||
|
||||
[Benchmark]
|
||||
public int BenchCompIndexDirect() => _compIndexFetcherDirect.Get<TestType50>();
|
||||
|
||||
[Benchmark]
|
||||
public int BenchDictDirect() => _dictFetcherDirect.Get<TestType50>();
|
||||
|
||||
private static CompIdx ArrayIndexFor<T>() => CompArrayIndex<T>.Idx;
|
||||
|
||||
private static int _compIndexMaster = -1;
|
||||
|
||||
private static class CompArrayIndex<T>
|
||||
{
|
||||
// ReSharper disable once StaticMemberInGenericType
|
||||
public static readonly CompIdx Idx = new(Interlocked.Increment(ref _compIndexMaster));
|
||||
}
|
||||
|
||||
private static CompIdx GetCompIdIndex(Type type)
|
||||
{
|
||||
return (CompIdx)typeof(CompArrayIndex<>)
|
||||
.MakeGenericType(type)
|
||||
.GetField(nameof(CompArrayIndex<int>.Idx), BindingFlags.Static | BindingFlags.Public)!
|
||||
.GetValue(null)!;
|
||||
}
|
||||
|
||||
private interface IFetcher
|
||||
{
|
||||
void Init(Type[] types);
|
||||
|
||||
int Get<T>();
|
||||
}
|
||||
|
||||
private sealed class CompIndexFetcher : IFetcher
|
||||
{
|
||||
private int[] _values = Array.Empty<int>();
|
||||
|
||||
public void Init(Type[] types)
|
||||
{
|
||||
var max = types.Max(t => GetCompIdIndex(t).Value);
|
||||
|
||||
_values = new int[max + 1];
|
||||
|
||||
var i = 0;
|
||||
foreach (var type in types)
|
||||
{
|
||||
_values[GetCompIdIndex(type).Value] = i++;
|
||||
}
|
||||
}
|
||||
|
||||
public int Get<T>()
|
||||
{
|
||||
return _values[CompArrayIndex<T>.Idx.Value];
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class DictFetcher : IFetcher
|
||||
{
|
||||
private readonly Dictionary<Type, int> _values = new();
|
||||
|
||||
public void Init(Type[] types)
|
||||
{
|
||||
var i = 0;
|
||||
foreach (var type in types)
|
||||
{
|
||||
_values[type] = i++;
|
||||
}
|
||||
}
|
||||
|
||||
public int Get<T>()
|
||||
{
|
||||
return _values[typeof(T)];
|
||||
}
|
||||
}
|
||||
|
||||
// Just a bunch of types to pad the size of the arrays and such.
|
||||
|
||||
// @formatter:off
|
||||
// ReSharper disable UnusedType.Local
|
||||
private sealed class TestType1{}
|
||||
private sealed class TestType2{}
|
||||
private sealed class TestType3{}
|
||||
private sealed class TestType4{}
|
||||
private sealed class TestType5{}
|
||||
private sealed class TestType6{}
|
||||
private sealed class TestType7{}
|
||||
private sealed class TestType8{}
|
||||
private sealed class TestType9{}
|
||||
private sealed class TestType10{}
|
||||
private sealed class TestType11{}
|
||||
private sealed class TestType12{}
|
||||
private sealed class TestType13{}
|
||||
private sealed class TestType14{}
|
||||
private sealed class TestType15{}
|
||||
private sealed class TestType16{}
|
||||
private sealed class TestType17{}
|
||||
private sealed class TestType18{}
|
||||
private sealed class TestType19{}
|
||||
private sealed class TestType20{}
|
||||
private sealed class TestType21{}
|
||||
private sealed class TestType22{}
|
||||
private sealed class TestType23{}
|
||||
private sealed class TestType24{}
|
||||
private sealed class TestType25{}
|
||||
private sealed class TestType26{}
|
||||
private sealed class TestType27{}
|
||||
private sealed class TestType28{}
|
||||
private sealed class TestType29{}
|
||||
private sealed class TestType30{}
|
||||
private sealed class TestType31{}
|
||||
private sealed class TestType32{}
|
||||
private sealed class TestType33{}
|
||||
private sealed class TestType34{}
|
||||
private sealed class TestType35{}
|
||||
private sealed class TestType36{}
|
||||
private sealed class TestType37{}
|
||||
private sealed class TestType38{}
|
||||
private sealed class TestType39{}
|
||||
private sealed class TestType40{}
|
||||
private sealed class TestType41{}
|
||||
private sealed class TestType42{}
|
||||
private sealed class TestType43{}
|
||||
private sealed class TestType44{}
|
||||
private sealed class TestType45{}
|
||||
private sealed class TestType46{}
|
||||
private sealed class TestType47{}
|
||||
private sealed class TestType48{}
|
||||
private sealed class TestType49{}
|
||||
private sealed class TestType50{}
|
||||
private sealed class TestType51{}
|
||||
private sealed class TestType52{}
|
||||
private sealed class TestType53{}
|
||||
private sealed class TestType54{}
|
||||
private sealed class TestType55{}
|
||||
private sealed class TestType56{}
|
||||
private sealed class TestType57{}
|
||||
private sealed class TestType58{}
|
||||
private sealed class TestType59{}
|
||||
private sealed class TestType60{}
|
||||
private sealed class TestType61{}
|
||||
private sealed class TestType62{}
|
||||
private sealed class TestType63{}
|
||||
private sealed class TestType64{}
|
||||
private sealed class TestType65{}
|
||||
private sealed class TestType66{}
|
||||
private sealed class TestType67{}
|
||||
private sealed class TestType68{}
|
||||
private sealed class TestType69{}
|
||||
private sealed class TestType70{}
|
||||
private sealed class TestType71{}
|
||||
private sealed class TestType72{}
|
||||
private sealed class TestType73{}
|
||||
private sealed class TestType74{}
|
||||
private sealed class TestType75{}
|
||||
private sealed class TestType76{}
|
||||
private sealed class TestType77{}
|
||||
private sealed class TestType78{}
|
||||
private sealed class TestType79{}
|
||||
private sealed class TestType80{}
|
||||
private sealed class TestType81{}
|
||||
private sealed class TestType82{}
|
||||
private sealed class TestType83{}
|
||||
private sealed class TestType84{}
|
||||
private sealed class TestType85{}
|
||||
private sealed class TestType86{}
|
||||
private sealed class TestType87{}
|
||||
private sealed class TestType88{}
|
||||
private sealed class TestType89{}
|
||||
private sealed class TestType90{}
|
||||
private sealed class TestType91{}
|
||||
private sealed class TestType92{}
|
||||
private sealed class TestType93{}
|
||||
private sealed class TestType94{}
|
||||
private sealed class TestType95{}
|
||||
private sealed class TestType96{}
|
||||
private sealed class TestType97{}
|
||||
private sealed class TestType98{}
|
||||
private sealed class TestType99{}
|
||||
// ReSharper restore UnusedType.Local
|
||||
// @formatter:on
|
||||
}
|
||||
61
Robust.Benchmarks/EntityManager/GetComponentBenchmark.cs
Normal file
61
Robust.Benchmarks/EntityManager/GetComponentBenchmark.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
namespace Robust.Benchmarks.EntityManager;
|
||||
|
||||
[Virtual]
|
||||
public class GetComponentBenchmark
|
||||
{
|
||||
private ISimulation _simulation = default!;
|
||||
private IEntityManager _entityManager = default!;
|
||||
|
||||
[UsedImplicitly]
|
||||
[Params(1, 10, 100, 1000)]
|
||||
public int N;
|
||||
|
||||
public A[] Comps = default!;
|
||||
|
||||
[GlobalSetup]
|
||||
public void GlobalSetup()
|
||||
{
|
||||
_simulation = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
.RegisterComponents(f => f.RegisterClass<A>())
|
||||
.InitializeInstance();
|
||||
|
||||
_entityManager = _simulation.Resolve<IEntityManager>();
|
||||
|
||||
Comps = new A[N+2];
|
||||
|
||||
var coords = new MapCoordinates(0, 0, new MapId(1));
|
||||
_simulation.AddMap(coords.MapId);
|
||||
|
||||
for (var i = 0; i < N; i++)
|
||||
{
|
||||
var uid = _entityManager.SpawnEntity(null, coords);
|
||||
_entityManager.AddComponent<A>(uid);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public A[] GetComponent()
|
||||
{
|
||||
for (var i = 2; i <= N+1; i++)
|
||||
{
|
||||
Comps[i] = _entityManager.GetComponent<A>(new EntityUid(i));
|
||||
}
|
||||
|
||||
// Return something so the JIT doesn't optimize out all the GetComponent calls.
|
||||
return Comps;
|
||||
}
|
||||
|
||||
[ComponentProtoName("A")]
|
||||
public sealed class A : Component
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.UnitTesting.Server;
|
||||
|
||||
namespace Robust.Benchmarks.EntityManager;
|
||||
|
||||
[Virtual]
|
||||
public class SpawnDeleteEntityBenchmark
|
||||
{
|
||||
private ISimulation _simulation = default!;
|
||||
private IEntityManager _entityManager = default!;
|
||||
|
||||
private MapCoordinates _mapCoords = MapCoordinates.Nullspace;
|
||||
private EntityCoordinates _entCoords = EntityCoordinates.Invalid;
|
||||
|
||||
[UsedImplicitly]
|
||||
[Params(1, 10, 100, 1000)]
|
||||
public int N;
|
||||
|
||||
[GlobalSetup]
|
||||
public void GlobalSetup()
|
||||
{
|
||||
_simulation = RobustServerSimulation
|
||||
.NewSimulation()
|
||||
.RegisterComponents(f => f.RegisterClass<A>())
|
||||
.InitializeInstance();
|
||||
|
||||
_entityManager = _simulation.Resolve<IEntityManager>();
|
||||
|
||||
_mapCoords = new MapCoordinates(0, 0, new MapId(1));
|
||||
var uid = _simulation.AddMap(_mapCoords.MapId);
|
||||
_entCoords = new EntityCoordinates(uid, 0, 0);
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void SpawnDeleteEntityMapCoords()
|
||||
{
|
||||
for (var i = 0; i < N; i++)
|
||||
{
|
||||
var uid = _entityManager.SpawnEntity(null, _mapCoords);
|
||||
_entityManager.DeleteEntity(uid);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void SpawnDeleteEntityEntCoords()
|
||||
{
|
||||
for (var i = 0; i < N; i++)
|
||||
{
|
||||
var uid = _entityManager.SpawnEntity(null, _entCoords);
|
||||
_entityManager.DeleteEntity(uid);
|
||||
}
|
||||
}
|
||||
|
||||
[ComponentProtoName("A")]
|
||||
public sealed class A : Component
|
||||
{
|
||||
}
|
||||
}
|
||||
195
Robust.Benchmarks/Exporters/SQLExporter.cs
Normal file
195
Robust.Benchmarks/Exporters/SQLExporter.cs
Normal file
@@ -0,0 +1,195 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using BenchmarkDotNet.Exporters;
|
||||
using BenchmarkDotNet.Loggers;
|
||||
using BenchmarkDotNet.Mathematics;
|
||||
using BenchmarkDotNet.Reports;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Npgsql;
|
||||
using Npgsql.Internal;
|
||||
using Npgsql.Internal.TypeHandlers;
|
||||
using Npgsql.Internal.TypeHandling;
|
||||
|
||||
namespace Robust.Benchmarks.Exporters;
|
||||
|
||||
public sealed class SQLExporter : IExporter
|
||||
{
|
||||
public static readonly IExporter Default = new SQLExporter();
|
||||
|
||||
private SQLExporter(){}
|
||||
|
||||
public void ExportToLog(Summary summary, ILogger logger)
|
||||
{
|
||||
Export(summary, logger);
|
||||
}
|
||||
|
||||
public IEnumerable<string> ExportToFiles(Summary summary, ILogger consoleLogger)
|
||||
{
|
||||
Export(summary, consoleLogger);
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
private bool TryGetEnvironmentVariable(string name, ILogger logger, [NotNullWhen(true)] out string? value)
|
||||
{
|
||||
value = Environment.GetEnvironmentVariable(name);
|
||||
if (value == null)
|
||||
logger.WriteError($"ROBUST_BENCHMARKS_ENABLE_SQL is set, but {name} is missing.");
|
||||
return value != null;
|
||||
}
|
||||
|
||||
private void Export(Summary summary, ILogger logger)
|
||||
{
|
||||
if (!TryGetEnvironmentVariable("ROBUST_BENCHMARKS_SQL_ADDRESS", logger, out var address) ||
|
||||
!TryGetEnvironmentVariable("ROBUST_BENCHMARKS_SQL_PORT", logger, out var rawPort) ||
|
||||
!TryGetEnvironmentVariable("ROBUST_BENCHMARKS_SQL_USER", logger, out var user) ||
|
||||
!TryGetEnvironmentVariable("ROBUST_BENCHMARKS_SQL_PASSWORD", logger, out var password) ||
|
||||
!TryGetEnvironmentVariable("ROBUST_BENCHMARKS_SQL_DATABASE", logger, out var db) ||
|
||||
!TryGetEnvironmentVariable("GITHUB_SHA", logger, out var gitHash))
|
||||
return;
|
||||
|
||||
if (!int.TryParse(rawPort, out var port))
|
||||
{
|
||||
logger.WriteError("Failed parsing ROBUST_BENCHMARKS_SQL_PORT to int.");
|
||||
return;
|
||||
}
|
||||
|
||||
var builder = new DbContextOptionsBuilder<BenchmarkContext>();
|
||||
var connectionString = new NpgsqlConnectionStringBuilder
|
||||
{
|
||||
Host = address,
|
||||
Port = port,
|
||||
Database = db,
|
||||
Username = user,
|
||||
Password = password
|
||||
}.ConnectionString;
|
||||
builder.UseNpgsql(connectionString);
|
||||
using var ctx = new BenchmarkContext(builder.Options);
|
||||
try
|
||||
{
|
||||
ctx.Database.OpenConnection();
|
||||
var con = (NpgsqlConnection) ctx.Database.GetDbConnection();
|
||||
con.TypeMapper.AddTypeResolverFactory(new JsonOverrideTypeHandlerResolverFactory(new JsonSerializerOptions
|
||||
{
|
||||
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals
|
||||
}));
|
||||
|
||||
ctx.Database.Migrate();
|
||||
ctx.BenchmarkRuns.Add(BenchmarkRun.FromSummary(summary, gitHash));
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
finally
|
||||
{
|
||||
ctx.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public string Name => "sql";
|
||||
}
|
||||
|
||||
// https://github.com/npgsql/efcore.pg/issues/1107#issuecomment-945126627
|
||||
class JsonOverrideTypeHandlerResolverFactory : TypeHandlerResolverFactory
|
||||
{
|
||||
private readonly JsonSerializerOptions _options;
|
||||
|
||||
public JsonOverrideTypeHandlerResolverFactory(JsonSerializerOptions options)
|
||||
=> _options = options;
|
||||
|
||||
public override TypeHandlerResolver Create(NpgsqlConnector connector)
|
||||
=> new JsonOverrideTypeHandlerResolver(connector, _options);
|
||||
|
||||
public override string? GetDataTypeNameByClrType(Type clrType)
|
||||
=> null;
|
||||
|
||||
public override TypeMappingInfo? GetMappingByDataTypeName(string dataTypeName)
|
||||
=> null;
|
||||
|
||||
class JsonOverrideTypeHandlerResolver : TypeHandlerResolver
|
||||
{
|
||||
readonly JsonHandler _jsonbHandler;
|
||||
|
||||
internal JsonOverrideTypeHandlerResolver(NpgsqlConnector connector, JsonSerializerOptions options)
|
||||
=> _jsonbHandler ??= new JsonHandler(
|
||||
connector.DatabaseInfo.GetPostgresTypeByName("jsonb"),
|
||||
connector.TextEncoding,
|
||||
isJsonb: true,
|
||||
options);
|
||||
|
||||
public override NpgsqlTypeHandler? ResolveByDataTypeName(string typeName)
|
||||
=> typeName == "jsonb" ? _jsonbHandler : null;
|
||||
|
||||
public override NpgsqlTypeHandler? ResolveByClrType(Type type)
|
||||
// You can add any user-defined CLR types which you want mapped to jsonb
|
||||
=> type == typeof(JsonDocument) ? _jsonbHandler : null;
|
||||
|
||||
public override TypeMappingInfo? GetMappingByDataTypeName(string dataTypeName)
|
||||
=> null; // Let the built-in resolver do this
|
||||
}
|
||||
}
|
||||
public sealed class DesignTimeContextFactoryPostgres : IDesignTimeDbContextFactory<BenchmarkContext>
|
||||
{
|
||||
public BenchmarkContext CreateDbContext(string[] args)
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<BenchmarkContext>();
|
||||
optionsBuilder.UseNpgsql("Server=localhost");
|
||||
return new BenchmarkContext(optionsBuilder.Options);
|
||||
}
|
||||
}
|
||||
|
||||
public class BenchmarkContext : DbContext
|
||||
{
|
||||
public DbSet<BenchmarkRun> BenchmarkRuns { get; set; } = default!;
|
||||
|
||||
public BenchmarkContext() { }
|
||||
public BenchmarkContext(DbContextOptions<BenchmarkContext> options) : base(options) { }
|
||||
}
|
||||
|
||||
public class BenchmarkRun
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string GitHash { get; set; } = string.Empty;
|
||||
|
||||
[Column(TypeName = "timestamptz")]
|
||||
public DateTime RunDate { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[Column(TypeName = "jsonb")]
|
||||
public BenchmarkRunReport[] Reports { get; set; } = Array.Empty<BenchmarkRunReport>();
|
||||
|
||||
public static BenchmarkRun FromSummary(Summary summary, string gitHash)
|
||||
{
|
||||
return new BenchmarkRun
|
||||
{
|
||||
Reports = summary.Reports.Select(r => new BenchmarkRunReport
|
||||
{
|
||||
Parameters = r.BenchmarkCase.Parameters.Items.Select(p => new BenchmarkRunParameter
|
||||
{
|
||||
Name = p.Name,
|
||||
Value = p.Value
|
||||
}).ToArray(),
|
||||
Statistics = r.ResultStatistics
|
||||
}).ToArray(),
|
||||
Name = summary.BenchmarksCases.First().FolderInfo,
|
||||
RunDate = DateTime.UtcNow,
|
||||
GitHash = gitHash
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class BenchmarkRunReport
|
||||
{
|
||||
public BenchmarkRunParameter[] Parameters { get; set; } = Array.Empty<BenchmarkRunParameter>();
|
||||
public Statistics Statistics { get; set; } = default!;
|
||||
}
|
||||
|
||||
public class BenchmarkRunParameter
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public object Value { get; set; } = default!;
|
||||
}
|
||||
55
Robust.Benchmarks/Migrations/20220328231938_InitialCreate.Designer.cs
generated
Normal file
55
Robust.Benchmarks/Migrations/20220328231938_InitialCreate.Designer.cs
generated
Normal file
@@ -0,0 +1,55 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using Robust.Benchmarks.Exporters;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Robust.Benchmarks.Migrations
|
||||
{
|
||||
[DbContext(typeof(BenchmarkContext))]
|
||||
[Migration("20220328231938_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Robust.Benchmarks.Exporters.BenchmarkRun", b =>
|
||||
{
|
||||
b.Property<decimal>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("numeric(20,0)");
|
||||
|
||||
b.Property<string>("GitHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<BenchmarkRunReport[]>("Reports")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<DateTime>("RunDate")
|
||||
.HasColumnType("Date");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("BenchmarkRuns");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Robust.Benchmarks/Migrations/20220328231938_InitialCreate.cs
Normal file
35
Robust.Benchmarks/Migrations/20220328231938_InitialCreate.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Robust.Benchmarks.Exporters;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Robust.Benchmarks.Migrations
|
||||
{
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BenchmarkRuns",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
|
||||
GitHash = table.Column<string>(type: "text", nullable: false),
|
||||
RunDate = table.Column<DateTime>(type: "Date", nullable: false),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Reports = table.Column<BenchmarkRunReport[]>(type: "jsonb", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BenchmarkRuns", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "BenchmarkRuns");
|
||||
}
|
||||
}
|
||||
}
|
||||
57
Robust.Benchmarks/Migrations/20220510131430_fix-pk.Designer.cs
generated
Normal file
57
Robust.Benchmarks/Migrations/20220510131430_fix-pk.Designer.cs
generated
Normal file
@@ -0,0 +1,57 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using Robust.Benchmarks.Exporters;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Robust.Benchmarks.Migrations
|
||||
{
|
||||
[DbContext(typeof(BenchmarkContext))]
|
||||
[Migration("20220510131430_fix-pk")]
|
||||
partial class fixpk
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Robust.Benchmarks.Exporters.BenchmarkRun", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("GitHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<BenchmarkRunReport[]>("Reports")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<DateTime>("RunDate")
|
||||
.HasColumnType("timestamptz");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("BenchmarkRuns");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
51
Robust.Benchmarks/Migrations/20220510131430_fix-pk.cs
Normal file
51
Robust.Benchmarks/Migrations/20220510131430_fix-pk.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Robust.Benchmarks.Migrations
|
||||
{
|
||||
public partial class fixpk : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "RunDate",
|
||||
table: "BenchmarkRuns",
|
||||
type: "timestamptz",
|
||||
nullable: false,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "Date");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "Id",
|
||||
table: "BenchmarkRuns",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
oldClrType: typeof(decimal),
|
||||
oldType: "numeric(20,0)")
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "RunDate",
|
||||
table: "BenchmarkRuns",
|
||||
type: "Date",
|
||||
nullable: false,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "timestamptz");
|
||||
|
||||
migrationBuilder.AlterColumn<decimal>(
|
||||
name: "Id",
|
||||
table: "BenchmarkRuns",
|
||||
type: "numeric(20,0)",
|
||||
nullable: false,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "integer")
|
||||
.OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using Robust.Benchmarks.Exporters;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Robust.Benchmarks.Migrations
|
||||
{
|
||||
[DbContext(typeof(BenchmarkContext))]
|
||||
partial class BenchmarkContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Robust.Benchmarks.Exporters.BenchmarkRun", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("GitHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<BenchmarkRunReport[]>("Reports")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<DateTime>("RunDate")
|
||||
.HasColumnType("timestamptz");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("BenchmarkRuns");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,9 @@ namespace Robust.Benchmarks.NumericsHelpers
|
||||
[Params(32, 128)]
|
||||
public int N { get; set; }
|
||||
|
||||
[Params(1,2)]
|
||||
public int T { get; set; }
|
||||
|
||||
private float[] _inputA = default!;
|
||||
private float[] _inputB = default!;
|
||||
private float[] _output = default!;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Running;
|
||||
using System;
|
||||
using Robust.Benchmarks.Configs;
|
||||
using Robust.Benchmarks.Exporters;
|
||||
|
||||
namespace Robust.Benchmarks
|
||||
{
|
||||
@@ -16,7 +18,8 @@ namespace Robust.Benchmarks
|
||||
Console.WriteLine("THE DEBUG BUILD IS ONLY GOOD FOR FIXING A CRASHING BENCHMARK\n");
|
||||
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, new DebugInProcessConfig());
|
||||
#else
|
||||
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
|
||||
var config = Environment.GetEnvironmentVariable("ROBUST_BENCHMARKS_ENABLE_SQL") != null ? DefaultSQLConfig.Instance : null;
|
||||
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,20 @@
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<OutputPath>../bin/Benchmarks</OutputPath>
|
||||
<OutputType>Exe</OutputType>
|
||||
<NoWarn>RA0003</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Robust.Server\Robust.Server.csproj" />
|
||||
<ProjectReference Include="..\Robust.Shared\Robust.Shared.csproj" />
|
||||
<ProjectReference Include="..\Robust.UnitTesting\Robust.UnitTesting.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.4" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\MSBuild\Robust.Engine.targets" />
|
||||
</Project>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Globalization;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Result;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
using Robust.Shared.Serialization.Markdown.Validation;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
@@ -19,10 +18,10 @@ namespace Robust.Benchmarks.Serialization
|
||||
: new ErrorNode(node, $"Failed parsing int value: {node.Value}");
|
||||
}
|
||||
|
||||
public DeserializationResult Read(ISerializationManager serializationManager, ValueDataNode node,
|
||||
IDependencyCollection dependencies, bool skipHook, ISerializationContext? context = null)
|
||||
public int Read(ISerializationManager serializationManager, ValueDataNode node,
|
||||
IDependencyCollection dependencies, bool skipHook, ISerializationContext? context = null, int _ = default)
|
||||
{
|
||||
return new DeserializedValue<int>(int.Parse(node.Value, CultureInfo.InvariantCulture));
|
||||
return int.Parse(node.Value, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public DataNode Write(ISerializationManager serializationManager, int value, bool alwaysWrite = false,
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Robust.Benchmarks.Serialization.Copy
|
||||
|
||||
var seedMapping = yamlStream.Documents[0].RootNode.ToDataNodeCast<SequenceDataNode>().Cast<MappingDataNode>(0);
|
||||
|
||||
Seed = SerializationManager.ReadValueOrThrow<SeedDataDefinition>(seedMapping);
|
||||
Seed = SerializationManager.Read<SeedDataDefinition>(seedMapping);
|
||||
}
|
||||
|
||||
private const string String = "ABC";
|
||||
@@ -46,25 +46,25 @@ namespace Robust.Benchmarks.Serialization.Copy
|
||||
[Benchmark]
|
||||
public string? CreateCopyString()
|
||||
{
|
||||
return SerializationManager.CreateCopy(String);
|
||||
return SerializationManager.Copy(String);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int? CreateCopyInteger()
|
||||
{
|
||||
return SerializationManager.CreateCopy(Integer);
|
||||
return SerializationManager.Copy(Integer);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public DataDefinitionWithString? CreateCopyDataDefinitionWithString()
|
||||
{
|
||||
return SerializationManager.CreateCopy(DataDefinitionWithString);
|
||||
return SerializationManager.Copy(DataDefinitionWithString);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public SeedDataDefinition? CreateCopySeedDataDefinition()
|
||||
{
|
||||
return SerializationManager.CreateCopy(Seed);
|
||||
return SerializationManager.Copy(Seed);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace Robust.Benchmarks.Serialization.Definitions
|
||||
name: tobacco
|
||||
seedName: tobacco
|
||||
displayName: tobacco plant
|
||||
plantRsi: Objects/Specific/Hydroponics/tobacco.rsi
|
||||
productPrototypes:
|
||||
- LeavesTobacco
|
||||
harvestRepeat: Repeat
|
||||
@@ -36,7 +37,7 @@ namespace Robust.Benchmarks.Serialization.Definitions
|
||||
Max: 10
|
||||
PotencyDivisor: 10";
|
||||
|
||||
[DataField("id", required: true)] public string ID { get; set; } = default!;
|
||||
[IdDataFieldAttribute] public string ID { get; set; } = default!;
|
||||
|
||||
#region Tracking
|
||||
[DataField("name")] public string Name { get; set; } = string.Empty;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Robust.Benchmarks.Serialization.Definitions;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.Serialization.Manager.Result;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
using Robust.Shared.Serialization.Markdown.Mapping;
|
||||
using Robust.Shared.Serialization.Markdown.Sequence;
|
||||
@@ -42,32 +41,32 @@ namespace Robust.Benchmarks.Serialization.Read
|
||||
private ValueDataNode FlagThirtyOne { get; } = new("ThirtyOne");
|
||||
|
||||
[Benchmark]
|
||||
public string? ReadString()
|
||||
public string ReadString()
|
||||
{
|
||||
return SerializationManager.ReadValue<string>(StringNode);
|
||||
return SerializationManager.Read<string>(StringNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int? ReadInteger()
|
||||
public int ReadInteger()
|
||||
{
|
||||
return SerializationManager.ReadValue<int>(IntNode);
|
||||
return SerializationManager.Read<int>(IntNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public DataDefinitionWithString? ReadDataDefinitionWithString()
|
||||
public DataDefinitionWithString ReadDataDefinitionWithString()
|
||||
{
|
||||
return SerializationManager.ReadValue<DataDefinitionWithString>(StringDataDefNode);
|
||||
return SerializationManager.Read<DataDefinitionWithString>(StringDataDefNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public SeedDataDefinition? ReadSeedDataDefinition()
|
||||
public SeedDataDefinition ReadSeedDataDefinition()
|
||||
{
|
||||
return SerializationManager.ReadValue<SeedDataDefinition>(SeedNode);
|
||||
return SerializationManager.Read<SeedDataDefinition>(SeedNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("flag")]
|
||||
public DeserializationResult ReadFlagZero()
|
||||
public object? ReadFlagZero()
|
||||
{
|
||||
return SerializationManager.ReadWithTypeSerializer(
|
||||
typeof(int),
|
||||
@@ -77,7 +76,7 @@ namespace Robust.Benchmarks.Serialization.Read
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("flag")]
|
||||
public DeserializationResult ReadThirtyOne()
|
||||
public object? ReadThirtyOne()
|
||||
{
|
||||
return SerializationManager.ReadWithTypeSerializer(
|
||||
typeof(int),
|
||||
@@ -87,7 +86,7 @@ namespace Robust.Benchmarks.Serialization.Read
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("customTypeSerializer")]
|
||||
public DeserializationResult ReadIntegerCustomSerializer()
|
||||
public object? ReadIntegerCustomSerializer()
|
||||
{
|
||||
return SerializationManager.ReadWithTypeSerializer(
|
||||
typeof(int),
|
||||
|
||||
@@ -46,84 +46,84 @@ namespace Robust.Benchmarks.Serialization
|
||||
[BenchmarkCategory("read")]
|
||||
public string[]? ReadEmptyString()
|
||||
{
|
||||
return SerializationManager.ReadValue<string[]>(EmptyNode);
|
||||
return SerializationManager.Read<string[]>(EmptyNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("read")]
|
||||
public string[]? ReadOneString()
|
||||
{
|
||||
return SerializationManager.ReadValue<string[]>(OneIntNode);
|
||||
return SerializationManager.Read<string[]>(OneIntNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("read")]
|
||||
public string[]? ReadTenStrings()
|
||||
{
|
||||
return SerializationManager.ReadValue<string[]>(TenIntsNode);
|
||||
return SerializationManager.Read<string[]>(TenIntsNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("read")]
|
||||
public int[]? ReadEmptyInt()
|
||||
{
|
||||
return SerializationManager.ReadValue<int[]>(EmptyNode);
|
||||
return SerializationManager.Read<int[]>(EmptyNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("read")]
|
||||
public int[]? ReadOneInt()
|
||||
{
|
||||
return SerializationManager.ReadValue<int[]>(OneIntNode);
|
||||
return SerializationManager.Read<int[]>(OneIntNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("read")]
|
||||
public int[]? ReadTenInts()
|
||||
{
|
||||
return SerializationManager.ReadValue<int[]>(TenIntsNode);
|
||||
return SerializationManager.Read<int[]>(TenIntsNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("read")]
|
||||
public DataDefinitionWithString[]? ReadEmptyStringDataDef()
|
||||
{
|
||||
return SerializationManager.ReadValue<DataDefinitionWithString[]>(EmptyNode);
|
||||
return SerializationManager.Read<DataDefinitionWithString[]>(EmptyNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("read")]
|
||||
public DataDefinitionWithString[]? ReadOneStringDataDef()
|
||||
{
|
||||
return SerializationManager.ReadValue<DataDefinitionWithString[]>(OneStringDefNode);
|
||||
return SerializationManager.Read<DataDefinitionWithString[]>(OneStringDefNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("read")]
|
||||
public DataDefinitionWithString[]? ReadTenStringDataDefs()
|
||||
{
|
||||
return SerializationManager.ReadValue<DataDefinitionWithString[]>(TenStringDefsNode);
|
||||
return SerializationManager.Read<DataDefinitionWithString[]>(TenStringDefsNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("read")]
|
||||
public SealedDataDefinitionWithString[]? ReadEmptySealedStringDataDef()
|
||||
{
|
||||
return SerializationManager.ReadValue<SealedDataDefinitionWithString[]>(EmptyNode);
|
||||
return SerializationManager.Read<SealedDataDefinitionWithString[]>(EmptyNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("read")]
|
||||
public SealedDataDefinitionWithString[]? ReadOneSealedStringDataDef()
|
||||
{
|
||||
return SerializationManager.ReadValue<SealedDataDefinitionWithString[]>(OneStringDefNode);
|
||||
return SerializationManager.Read<SealedDataDefinitionWithString[]>(OneStringDefNode);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("read")]
|
||||
public SealedDataDefinitionWithString[]? ReadTenSealedStringDataDefs()
|
||||
{
|
||||
return SerializationManager.ReadValue<SealedDataDefinitionWithString[]>(TenStringDefsNode);
|
||||
return SerializationManager.Read<SealedDataDefinitionWithString[]>(TenStringDefsNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Robust.Benchmarks.Serialization.Write
|
||||
|
||||
var seedMapping = yamlStream.Documents[0].RootNode.ToDataNodeCast<SequenceDataNode>().Cast<MappingDataNode>(0);
|
||||
|
||||
Seed = SerializationManager.ReadValueOrThrow<SeedDataDefinition>(seedMapping);
|
||||
Seed = SerializationManager.Read<SeedDataDefinition>(seedMapping);
|
||||
}
|
||||
|
||||
private const string String = "ABC";
|
||||
|
||||
11
Robust.Benchmarks/add-migration.ps1
Normal file
11
Robust.Benchmarks/add-migration.ps1
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
param([String]$name)
|
||||
|
||||
if ($name -eq "")
|
||||
{
|
||||
Write-Error "must specify migration name"
|
||||
exit
|
||||
}
|
||||
|
||||
dotnet ef migrations add --context BenchmarkContext -o Migrations $name
|
||||
8
Robust.Benchmarks/add-migration.sh
Normal file
8
Robust.Benchmarks/add-migration.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ -z "$1" ] ; then
|
||||
echo "Must specify migration name"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
dotnet ef migrations add --context BenchmarkContext -o Migrations "$1"
|
||||
@@ -6,7 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Build.Framework" Version="16.8.0" />
|
||||
<PackageReference Include="Microsoft.Build.Framework" Version="17.0.0" />
|
||||
<PackageReference Include="Mono.Cecil" Version="0.11.3" />
|
||||
<PackageReference Include="Pidgin" Version="2.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Robust.Build.Tasks
|
||||
},
|
||||
ContentAttributes =
|
||||
{
|
||||
typeSystem.GetType("Robust.Client.UserInterface.XAML.ContentAttribute")
|
||||
typeSystem.GetType("Avalonia.Metadata.ContentAttribute")
|
||||
},
|
||||
UsableDuringInitializationAttributes =
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.WebView.Cef
|
||||
@@ -19,24 +16,11 @@ namespace Robust.Client.WebView.Cef
|
||||
Array.Copy(args, 0, argv, 1, args.Length);
|
||||
argv[0] = "-";
|
||||
}
|
||||
/*
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
// Chromium tries to load libEGL.so and libGLESv2.so relative to the process executable on Linux.
|
||||
// (Compared to Windows where it is relative to Chromium's *module*)
|
||||
// There is a TODO "is this correct?" in the Chromium code for this.
|
||||
// Great.
|
||||
|
||||
//CopyDllToExecutableDir("libEGL.so");
|
||||
//CopyDllToExecutableDir("libGLESv2.so");
|
||||
|
||||
// System.Threading.Thread.Sleep(200000);
|
||||
}
|
||||
*/
|
||||
var mainArgs = new CefMainArgs(argv);
|
||||
|
||||
// This will block executing until the subprocess is shut down.
|
||||
var code = CefRuntime.ExecuteProcess(mainArgs, null, IntPtr.Zero);
|
||||
var code = CefRuntime.ExecuteProcess(mainArgs, new RobustCefApp(), IntPtr.Zero);
|
||||
|
||||
if (code != 0)
|
||||
{
|
||||
@@ -45,44 +29,5 @@ namespace Robust.Client.WebView.Cef
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
/* private static void CopyDllToExecutableDir(string dllName)
|
||||
{
|
||||
var executableDir = PathHelpers.GetExecutableDirectory();
|
||||
var targetPath = Path.Combine(executableDir, dllName);
|
||||
if (File.Exists(targetPath))
|
||||
return;
|
||||
|
||||
// Find source file.
|
||||
string? srcFile = null;
|
||||
foreach (var searchDir in WebViewManagerCef.NativeDllSearchDirectories())
|
||||
{
|
||||
var searchPath = Path.Combine(searchDir, dllName);
|
||||
if (File.Exists(searchPath))
|
||||
{
|
||||
srcFile = searchPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (srcFile == null)
|
||||
return;
|
||||
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(targetPath))
|
||||
return;
|
||||
|
||||
File.Copy(srcFile, targetPath);
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Catching race condition lock errors and stuff I guess.
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
internal class RobustCefApp : CefApp
|
||||
internal sealed class RobustCefApp : CefApp
|
||||
{
|
||||
private readonly BrowserProcessHandler _browserProcessHandler = new();
|
||||
private readonly RenderProcessHandler _renderProcessHandler = new();
|
||||
@@ -24,12 +24,12 @@ namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
// Disable zygote on Linux.
|
||||
commandLine.AppendSwitch("--no-zygote");
|
||||
|
||||
|
||||
// Work around https://bitbucket.org/chromiumembedded/cef/issues/3213/ozone-egl-initialization-does-not-have
|
||||
// Desktop GL force makes Chromium not try to load its own ANGLE/Swiftshader so load paths aren't problematic.
|
||||
if (OperatingSystem.IsLinux())
|
||||
commandLine.AppendSwitch("--use-gl", "desktop");
|
||||
|
||||
|
||||
// commandLine.AppendSwitch("--single-process");
|
||||
|
||||
//commandLine.AppendSwitch("--disable-gpu");
|
||||
@@ -43,12 +43,18 @@ namespace Robust.Client.WebView.Cef
|
||||
Logger.Debug($"{commandLine}");
|
||||
}
|
||||
|
||||
private class BrowserProcessHandler : CefBrowserProcessHandler
|
||||
protected override void OnRegisterCustomSchemes(CefSchemeRegistrar registrar)
|
||||
{
|
||||
registrar.AddCustomScheme("res", CefSchemeOptions.Secure | CefSchemeOptions.Standard);
|
||||
registrar.AddCustomScheme("usr", CefSchemeOptions.Secure | CefSchemeOptions.Standard);
|
||||
}
|
||||
|
||||
private sealed class BrowserProcessHandler : CefBrowserProcessHandler
|
||||
{
|
||||
}
|
||||
|
||||
// TODO CEF: Research - Is this even needed?
|
||||
private class RenderProcessHandler : CefRenderProcessHandler
|
||||
private sealed class RenderProcessHandler : CefRenderProcessHandler
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Xilium.CefGlue;
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
// Simple CEF client.
|
||||
internal class RobustCefClient : CefClient
|
||||
internal sealed class RobustCefClient : CefClient
|
||||
{
|
||||
private readonly CefRenderHandler _renderHandler;
|
||||
private readonly CefRequestHandler _requestHandler;
|
||||
|
||||
@@ -57,6 +57,14 @@ namespace Robust.Client.WebView.Cef
|
||||
string requestInitiator,
|
||||
ref bool disableDefaultHandling)
|
||||
{
|
||||
var url = new Uri(request.Url);
|
||||
if (url.Scheme == "file")
|
||||
{
|
||||
// Deny file:// access.
|
||||
disableDefaultHandling = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
lock (_resourceRequestHandlers)
|
||||
{
|
||||
_sawmill.Debug($"HANDLING REQUEST: {request.Url}");
|
||||
@@ -113,7 +121,7 @@ namespace Robust.Client.WebView.Cef
|
||||
CefFrame frame,
|
||||
CefRequest request)
|
||||
{
|
||||
return null;
|
||||
return new CookieHandler();
|
||||
}
|
||||
|
||||
protected override CefResourceHandler GetResourceHandler(
|
||||
@@ -124,5 +132,18 @@ namespace Robust.Client.WebView.Cef
|
||||
return _handler;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class CookieHandler : CefCookieAccessFilter
|
||||
{
|
||||
protected override bool CanSendCookie(CefBrowser browser, CefFrame frame, CefRequest request, CefCookie cookie)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool CanSaveCookie(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response, CefCookie cookie)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
75
Robust.Client.WebView/Cef/WebViewManagerCef.Mime.cs
Normal file
75
Robust.Client.WebView/Cef/WebViewManagerCef.Mime.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.WebView.Cef;
|
||||
|
||||
internal sealed partial class WebViewManagerCef
|
||||
{
|
||||
// Loosely based on:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
||||
private readonly Dictionary<string, string> _resourceMimeTypes = new()
|
||||
{
|
||||
{ "aac", "audio/aac" },
|
||||
{ "avif", "image/avif" },
|
||||
{ "avi", "video/x-msvideo" },
|
||||
{ "bmp", "image/bmp" },
|
||||
{ "css", "text/css" },
|
||||
{ "gif", "image/gif" },
|
||||
{ "htm", "text/html" },
|
||||
{ "html", "text/html" },
|
||||
{ "ico", "image/vnd.microsoft.icon" },
|
||||
{ "jpeg", "image/jpeg" },
|
||||
{ "jpg", "image/jpeg" },
|
||||
{ "js", "text/javascript" },
|
||||
{ "json", "application/json" },
|
||||
{ "jsonld", "application/ld+json" },
|
||||
{ "midi", "audio/midi" },
|
||||
{ "mid", "audio/midi" },
|
||||
{ "mjs", "text/javascript" },
|
||||
{ "mp3", "audio/mpeg" },
|
||||
{ "mp4", "video/mp4" },
|
||||
{ "mpeg", "video/mpeg" },
|
||||
{ "oga", "audio/ogg" },
|
||||
{ "ogg", "audio/ogg" },
|
||||
{ "ogv", "video/ogg" },
|
||||
{ "ogx", "application/ogg" },
|
||||
{ "opus", "audio/opus" },
|
||||
{ "otf", "font/otf" },
|
||||
{ "png", "image/png" },
|
||||
{ "pdf", "application/pdf" },
|
||||
{ "svg", "image/svg+xml" },
|
||||
{ "tiff", "image/tiff" },
|
||||
{ "tif", "image/tiff" },
|
||||
{ "ts", "video/mp2t" },
|
||||
{ "ttf", "font/ttf" },
|
||||
{ "txt", "text/plain" },
|
||||
{ "wav", "audio/wav" },
|
||||
{ "weba", "audio/webm" },
|
||||
{ "webm", "video/webm" },
|
||||
{ "webp", "image/webp" },
|
||||
{ "woff", "font/woff" },
|
||||
{ "woff2", "font/woff2" },
|
||||
{ "xhtml", "application/xhtml+xml" },
|
||||
{ "xml", "application/xml" },
|
||||
{ "zip", "application/zip" },
|
||||
};
|
||||
|
||||
public void SetResourceMimeType(string extension, string mimeType)
|
||||
{
|
||||
DebugTools.Assert(!extension.StartsWith("."), "SetResourceMimeType extension must not include starting dot.");
|
||||
|
||||
lock (_resourceMimeTypes)
|
||||
{
|
||||
_resourceMimeTypes[extension] = mimeType;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetResourceMimeType(string extension, [NotNullWhen(true)] out string? mimeType)
|
||||
{
|
||||
lock (_resourceMimeTypes)
|
||||
{
|
||||
return _resourceMimeTypes.TryGetValue(extension, out mimeType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,21 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
internal partial class WebViewManagerCef : IWebViewManagerImpl
|
||||
internal sealed partial class WebViewManagerCef : IWebViewManagerImpl
|
||||
{
|
||||
private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location!)!;
|
||||
|
||||
@@ -17,11 +23,19 @@ namespace Robust.Client.WebView.Cef
|
||||
|
||||
[Dependency] private readonly IDependencyCollection _dependencyCollection = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IResourceManagerInternal _resourceManager = default!;
|
||||
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
IoCManager.Instance!.InjectDependencies(this, oneOff: true);
|
||||
|
||||
_consoleHost.RegisterCommand("flushcookies", Loc.GetString("cmd-flushcookies-desc"), Loc.GetString("cmd-flushcookies-help"), (_, _, _) =>
|
||||
{
|
||||
CefCookieManager.GetGlobal(null).FlushStore(null);
|
||||
});
|
||||
|
||||
string subProcessName;
|
||||
if (OperatingSystem.IsWindows())
|
||||
subProcessName = "Robust.Client.WebView.exe";
|
||||
@@ -38,6 +52,10 @@ namespace Robust.Client.WebView.Cef
|
||||
if (cefResourcesPath == null)
|
||||
throw new InvalidOperationException("Unable to locate cef_resources directory!");
|
||||
|
||||
var cachePath = "";
|
||||
if (_resourceManager.UserData is WritableDirProvider userData)
|
||||
cachePath = userData.GetFullPath(new ResourcePath("/cef_cache"));
|
||||
|
||||
var settings = new CefSettings()
|
||||
{
|
||||
WindowlessRenderingEnabled = true, // So we can render to our UI controls.
|
||||
@@ -47,6 +65,8 @@ namespace Robust.Client.WebView.Cef
|
||||
LocalesDirPath = Path.Combine(cefResourcesPath, "locales"),
|
||||
ResourcesDirPath = cefResourcesPath,
|
||||
RemoteDebuggingPort = 9222,
|
||||
CookieableSchemesList = "usr,res",
|
||||
CachePath = cachePath,
|
||||
};
|
||||
|
||||
Logger.Info($"CEF Version: {CefRuntime.ChromeVersion}");
|
||||
@@ -59,6 +79,12 @@ namespace Robust.Client.WebView.Cef
|
||||
// TODO CEF: After this point, debugging breaks. No, literally. My client crashes but ONLY with the debugger.
|
||||
// I have tried using the DEBUG and RELEASE versions of libcef.so, stripped or non-stripped...
|
||||
// And nothing seemed to work. Odd.
|
||||
|
||||
if (_cfg.GetCVar(WCVars.WebResProtocol))
|
||||
{
|
||||
var handler = new ResourceSchemeFactoryHandler(this, _resourceManager, Logger.GetSawmill("web.res"));
|
||||
CefRuntime.RegisterSchemeHandlerFactory("res", "", handler);
|
||||
}
|
||||
}
|
||||
|
||||
private static string? LocateCefResources()
|
||||
@@ -102,5 +128,48 @@ namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
CefRuntime.Shutdown();
|
||||
}
|
||||
|
||||
private sealed class ResourceSchemeFactoryHandler : CefSchemeHandlerFactory
|
||||
{
|
||||
private readonly WebViewManagerCef _parent;
|
||||
private readonly IResourceManager _resourceManager;
|
||||
private readonly ISawmill _sawmill;
|
||||
|
||||
public ResourceSchemeFactoryHandler(
|
||||
WebViewManagerCef parent,
|
||||
IResourceManager resourceManager,
|
||||
ISawmill sawmill)
|
||||
{
|
||||
_parent = parent;
|
||||
_resourceManager = resourceManager;
|
||||
_sawmill = sawmill;
|
||||
}
|
||||
|
||||
protected override CefResourceHandler Create(
|
||||
CefBrowser browser,
|
||||
CefFrame frame,
|
||||
string schemeName,
|
||||
CefRequest request)
|
||||
{
|
||||
var uri = new Uri(request.Url);
|
||||
|
||||
_sawmill.Debug($"HANDLING: {request.Url}");
|
||||
|
||||
var resourcePath = new ResourcePath(uri.AbsolutePath);
|
||||
if (_resourceManager.TryContentFileRead(resourcePath, out var stream))
|
||||
{
|
||||
if (!_parent.TryGetResourceMimeType(resourcePath.Extension, out var mime))
|
||||
mime = "application/octet-stream";
|
||||
|
||||
return new RequestResultStream(stream, mime, HttpStatusCode.OK).MakeHandler();
|
||||
}
|
||||
|
||||
var notFoundStream = new MemoryStream();
|
||||
notFoundStream.Write(Encoding.UTF8.GetBytes("Not found"));
|
||||
notFoundStream.Position = 0;
|
||||
|
||||
return new RequestResultStream(notFoundStream, "text/plain", HttpStatusCode.NotFound).MakeHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
@@ -11,6 +12,17 @@ namespace Robust.Client.WebView.Headless
|
||||
return new WebViewWindowDummy();
|
||||
}
|
||||
|
||||
public void SetResourceMimeType(string extension, string mimeType)
|
||||
{
|
||||
// Nop
|
||||
}
|
||||
|
||||
public bool TryGetResourceMimeType(string extension, [NotNullWhen(true)] out string? mimeType)
|
||||
{
|
||||
mimeType = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public IWebViewControlImpl MakeControlImpl(WebViewControl owner)
|
||||
{
|
||||
return new WebViewControlImplDummy();
|
||||
|
||||
@@ -1,7 +1,40 @@
|
||||
namespace Robust.Client.WebView
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
public interface IWebViewManager
|
||||
{
|
||||
IWebViewWindow CreateBrowserWindow(BrowserWindowCreateParameters createParams);
|
||||
|
||||
/// <summary>
|
||||
/// Overrides file extension -> mime type mappings for the <c>res://</c> protocol.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The built-in <c>res://</c> protocol needs to guess MIME types to report to CEF when resolving files.
|
||||
/// A limited set of extensions have pre-set MIME types in the engine.
|
||||
/// This method allows you to replace or add entries if need be.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This method is thread safe.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <param name="extension">
|
||||
/// The extension to specify the MIME type for.
|
||||
/// The argument must not include the starting "." of the file extension.
|
||||
/// </param>
|
||||
/// <param name="mimeType">The mime type for this file extension.</param>
|
||||
/// <seealso cref="TryGetResourceMimeType"/>
|
||||
void SetResourceMimeType(string extension, string mimeType);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to resolve an entry from the <see cref="SetResourceMimeType"/> list.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This method is thread safe.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
bool TryGetResourceMimeType(string extension, [NotNullWhen(true)] out string? mimeType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
|
||||
<PackageReference Include="Robust.Natives.Cef" Version="95.7.14" />
|
||||
<PackageReference Include="Robust.Natives.Cef" Version="102.0.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
17
Robust.Client.WebView/WCVars.cs
Normal file
17
Robust.Client.WebView/WCVars.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Robust.Shared.Configuration;
|
||||
|
||||
namespace Robust.Client.WebView;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
/// <summary>
|
||||
/// CVars for <c>Robust.Client.WebView</c>
|
||||
/// </summary>
|
||||
[CVarDefs]
|
||||
public static class WCVars
|
||||
{
|
||||
/// <summary>
|
||||
/// Enable the <c>res://</c> protocol inside WebView browsers, allowing access to the Robust resources.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> WebResProtocol =
|
||||
CVarDef.Create("web.res_protocol", true, CVar.CLIENTONLY);
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using Robust.Client.WebView;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Client.WebView;
|
||||
using Robust.Client.WebView.Cef;
|
||||
using Robust.Client.WebView.Headless;
|
||||
using Robust.Client.WebViewHook;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -17,6 +19,9 @@ namespace Robust.Client.WebView
|
||||
{
|
||||
DebugTools.Assert(_impl == null, "WebViewManager has already been initialized!");
|
||||
|
||||
var cfg = IoCManager.Resolve<IConfigurationManagerInternal>();
|
||||
cfg.LoadCVarsFromAssembly(typeof(WebViewManager).Assembly);
|
||||
|
||||
IoCManager.RegisterInstance<IWebViewManager>(this);
|
||||
IoCManager.RegisterInstance<IWebViewManagerInternal>(this);
|
||||
|
||||
@@ -49,6 +54,20 @@ namespace Robust.Client.WebView
|
||||
return _impl!.CreateBrowserWindow(createParams);
|
||||
}
|
||||
|
||||
public void SetResourceMimeType(string extension, string mimeType)
|
||||
{
|
||||
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
|
||||
|
||||
_impl!.SetResourceMimeType(extension, mimeType);
|
||||
}
|
||||
|
||||
public bool TryGetResourceMimeType(string extension, [NotNullWhen(true)] out string? mimeType)
|
||||
{
|
||||
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
|
||||
|
||||
return _impl!.TryGetResourceMimeType(extension, out mimeType);
|
||||
}
|
||||
|
||||
public IWebViewControlImpl MakeControlImpl(WebViewControl owner)
|
||||
{
|
||||
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Robust.Client.Animations
|
||||
|
||||
var keyFrame = KeyFrames[keyFrameIndex];
|
||||
|
||||
SoundSystem.Play(Filter.Local(), keyFrame.Resource, entity, keyFrame.AudioParamsFunc.Invoke());
|
||||
SoundSystem.Play(keyFrame.Resource, Filter.Local(), entity, keyFrame.AudioParamsFunc.Invoke());
|
||||
}
|
||||
|
||||
return (keyFrameIndex, playingTime);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Animations;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -101,7 +101,7 @@ namespace Robust.Client.Animations
|
||||
case double d:
|
||||
return MathHelper.Lerp(d, (double) b, t);
|
||||
case Angle angle:
|
||||
return (Angle) MathHelper.Lerp(angle, (Angle) b, t);
|
||||
return Angle.Lerp(angle, (Angle) b, t);
|
||||
case Color color:
|
||||
return Color.InterpolateBetween(color, (Color) b, t);
|
||||
case int i:
|
||||
|
||||
22
Robust.Client/Audio/Midi/Commands/MidiPanicCommand.cs
Normal file
22
Robust.Client/Audio/Midi/Commands/MidiPanicCommand.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Robust.Client.Audio.Midi.Commands;
|
||||
|
||||
public sealed class MidiPanicCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IMidiManager _midiManager = default!;
|
||||
|
||||
public string Command => "midipanic";
|
||||
public string Description => Loc.GetString("midi-panic-command-description");
|
||||
public string Help => $"{Command}";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
foreach (var renderer in _midiManager.Renderers)
|
||||
{
|
||||
renderer.StopAllNotes();
|
||||
}
|
||||
}
|
||||
}
|
||||
62
Robust.Client/Audio/Midi/IMidiManager.cs
Normal file
62
Robust.Client/Audio/Midi/IMidiManager.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
using NFluidsynth;
|
||||
using Robust.Shared.Audio.Midi;
|
||||
|
||||
namespace Robust.Client.Audio.Midi;
|
||||
|
||||
public interface IMidiManager
|
||||
{
|
||||
/// <summary>
|
||||
/// A read-only list of all existing MIDI Renderers.
|
||||
/// </summary>
|
||||
IReadOnlyList<IMidiRenderer> Renderers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// If true, MIDI support is available.
|
||||
/// </summary>
|
||||
bool IsAvailable { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Volume, in db.
|
||||
/// </summary>
|
||||
float Volume { get; set; }
|
||||
|
||||
public int OcclusionCollisionMask { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This method tries to return a midi renderer ready to be used.
|
||||
/// You only need to set the <see cref="IMidiRenderer.MidiProgram"/> afterwards.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method can fail if MIDI support is not available.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// <c>null</c> if MIDI support is not available.
|
||||
/// </returns>
|
||||
IMidiRenderer? GetNewRenderer(bool mono = true);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RobustMidiEvent"/> given a <see cref="MidiEvent"/> and a sequencer tick.
|
||||
/// </summary>
|
||||
RobustMidiEvent FromFluidEvent(MidiEvent midiEvent, uint tick);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="SequencerEvent"/> given a <see cref="RobustMidiEvent"/>.
|
||||
/// Be sure to dispose of the result after you've used it.
|
||||
/// </summary>
|
||||
SequencerEvent ToSequencerEvent(RobustMidiEvent midiEvent);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RobustMidiEvent"/> given a <see cref="SequencerEvent"/> and a sequencer tick.
|
||||
/// </summary>
|
||||
RobustMidiEvent FromSequencerEvent(SequencerEvent midiEvent, uint tick);
|
||||
|
||||
/// <summary>
|
||||
/// Method called every frame.
|
||||
/// Should be used to update positional audio.
|
||||
/// </summary>
|
||||
/// <param name="frameTime"></param>
|
||||
void FrameUpdate(float frameTime);
|
||||
|
||||
void Shutdown();
|
||||
}
|
||||
181
Robust.Client/Audio/Midi/IMidiRenderer.cs
Normal file
181
Robust.Client/Audio/Midi/IMidiRenderer.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Audio.Midi;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Robust.Client.Audio.Midi;
|
||||
|
||||
public enum MidiRendererStatus : byte
|
||||
{
|
||||
None,
|
||||
Input,
|
||||
File,
|
||||
}
|
||||
|
||||
public interface IMidiRenderer : IDisposable
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The buffered audio source of this renderer.
|
||||
/// </summary>
|
||||
internal IClydeBufferedAudioSource Source { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this renderer has been disposed or not.
|
||||
/// </summary>
|
||||
bool Disposed { get; }
|
||||
|
||||
/// <summary>
|
||||
/// This controls whether the midi file being played will loop or not.
|
||||
/// </summary>
|
||||
bool LoopMidi { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This increases all note on velocities to 127.
|
||||
/// </summary>
|
||||
bool VolumeBoost { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The midi program (instrument) the renderer is using.
|
||||
/// </summary>
|
||||
byte MidiProgram { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The instrument bank the renderer is using.
|
||||
/// </summary>
|
||||
byte MidiBank { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The soundfont currently selected by the renderer.
|
||||
/// </summary>
|
||||
uint MidiSoundfont { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The current status of the renderer.
|
||||
/// "None" if the renderer isn't playing from input or a midi file.
|
||||
/// "Input" if the renderer is playing from midi input.
|
||||
/// "File" if the renderer is playing from a midi file.
|
||||
/// </summary>
|
||||
MidiRendererStatus Status { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the sound will play in stereo or mono.
|
||||
/// </summary>
|
||||
bool Mono { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to drop messages on the percussion channel.
|
||||
/// </summary>
|
||||
bool DisablePercussionChannel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to drop messages for program change events.
|
||||
/// </summary>
|
||||
bool DisableProgramChangeEvent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total number of ticks possible for the MIDI player.
|
||||
/// </summary>
|
||||
int PlayerTotalTick { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets (seeks) the current tick of the MIDI player.
|
||||
/// </summary>
|
||||
int PlayerTick { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current tick of the sequencer.
|
||||
/// </summary>
|
||||
uint SequencerTick { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Time Scale of the sequencer in ticks per second. Default is 1000 for 1 tick per millisecond.
|
||||
/// </summary>
|
||||
double SequencerTimeScale { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Start listening for midi input.
|
||||
/// </summary>
|
||||
bool OpenInput();
|
||||
|
||||
/// <summary>
|
||||
/// Start playing a midi file.
|
||||
/// </summary>
|
||||
/// <param name="buffer">Bytes of the midi file</param>
|
||||
bool OpenMidi(ReadOnlySpan<byte> buffer);
|
||||
|
||||
/// <summary>
|
||||
/// Stops listening for midi input.
|
||||
/// </summary>
|
||||
bool CloseInput();
|
||||
|
||||
/// <summary>
|
||||
/// Stops playing midi files.
|
||||
/// </summary>
|
||||
bool CloseMidi();
|
||||
|
||||
/// <summary>
|
||||
/// Stops all notes being played currently.
|
||||
/// </summary>
|
||||
void StopAllNotes();
|
||||
|
||||
/// <summary>
|
||||
/// Render and play MIDI to the audio source.
|
||||
/// </summary>
|
||||
internal void Render();
|
||||
|
||||
/// <summary>
|
||||
/// Loads a new soundfont into the renderer.
|
||||
/// </summary>
|
||||
void LoadSoundfont(string filename, bool resetPresets = false);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked whenever a new midi event is registered.
|
||||
/// </summary>
|
||||
event Action<RobustMidiEvent> OnMidiEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the midi player finishes playing a song.
|
||||
/// </summary>
|
||||
event Action OnMidiPlayerFinished;
|
||||
|
||||
/// <summary>
|
||||
/// The entity whose position will be used for positional audio.
|
||||
/// This is only used if <see cref="Mono"/> is set to True.
|
||||
/// </summary>
|
||||
EntityUid? TrackingEntity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The position that will be used for positional audio.
|
||||
/// This is only used if <see cref="Mono"/> is set to True
|
||||
/// and <see cref="TrackingEntity"/> is null.
|
||||
/// </summary>
|
||||
EntityCoordinates? TrackingCoordinates { get; set; }
|
||||
|
||||
MidiRendererState RendererState { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Send a midi event for the renderer to play.
|
||||
/// </summary>
|
||||
/// <param name="midiEvent">The midi event to be played</param>
|
||||
void SendMidiEvent(RobustMidiEvent midiEvent);
|
||||
|
||||
/// <summary>
|
||||
/// Schedule a MIDI event to be played at a later time.
|
||||
/// </summary>
|
||||
/// <param name="midiEvent">the midi event in question</param>
|
||||
/// <param name="time"></param>
|
||||
/// <param name="absolute"></param>
|
||||
void ScheduleMidiEvent(RobustMidiEvent midiEvent, uint time, bool absolute);
|
||||
|
||||
/// <summary>
|
||||
/// Apply a certain state to the renderer.
|
||||
/// </summary>
|
||||
void ApplyState(MidiRendererState state);
|
||||
|
||||
/// <summary>
|
||||
/// Actually disposes of this renderer. Do NOT use outside the MIDI thread.
|
||||
/// </summary>
|
||||
internal void InternalDispose();
|
||||
}
|
||||
155
Robust.Client/Audio/Midi/MidiManager.Conversion.cs
Normal file
155
Robust.Client/Audio/Midi/MidiManager.Conversion.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
using NFluidsynth;
|
||||
using Robust.Shared.Audio.Midi;
|
||||
|
||||
namespace Robust.Client.Audio.Midi;
|
||||
|
||||
internal sealed partial class MidiManager
|
||||
{
|
||||
public RobustMidiEvent FromFluidEvent(MidiEvent midiEvent, uint tick)
|
||||
{
|
||||
var status = RobustMidiEvent.MakeStatus((byte) midiEvent.Channel, (byte) midiEvent.Type);
|
||||
|
||||
// Control is always the first data byte. Value is always the second data byte. Fluidsynth's API ain't great.
|
||||
var data1 = (byte) midiEvent.Control;
|
||||
var data2 = (byte) midiEvent.Value;
|
||||
|
||||
// PitchBend is handled specially.
|
||||
if (midiEvent.Type == (int) RobustMidiCommand.PitchBend)
|
||||
{
|
||||
// We pack pitch into both data values.
|
||||
var pitch = (ushort) midiEvent.Pitch;
|
||||
data1 = (byte) pitch;
|
||||
data2 = (byte) (pitch >> 8);
|
||||
}
|
||||
|
||||
return new RobustMidiEvent(status, data1, data2, tick);
|
||||
}
|
||||
|
||||
public SequencerEvent ToSequencerEvent(RobustMidiEvent midiEvent)
|
||||
{
|
||||
var sequencerEvent = new SequencerEvent();
|
||||
|
||||
switch (midiEvent.MidiCommand)
|
||||
{
|
||||
case RobustMidiCommand.NoteOff:
|
||||
sequencerEvent.NoteOff(midiEvent.Channel, midiEvent.Key);
|
||||
break;
|
||||
|
||||
case RobustMidiCommand.NoteOn:
|
||||
sequencerEvent.NoteOn(midiEvent.Channel, midiEvent.Key, midiEvent.Velocity);
|
||||
break;
|
||||
|
||||
case RobustMidiCommand.AfterTouch:
|
||||
sequencerEvent.KeyPressure(midiEvent.Channel, midiEvent.Key, midiEvent.Value);
|
||||
break;
|
||||
|
||||
case RobustMidiCommand.ControlChange:
|
||||
sequencerEvent.ControlChange(midiEvent.Channel, midiEvent.Control, midiEvent.Value);
|
||||
break;
|
||||
|
||||
case RobustMidiCommand.ProgramChange:
|
||||
sequencerEvent.ProgramChange(midiEvent.Channel, midiEvent.Program);
|
||||
break;
|
||||
|
||||
case RobustMidiCommand.ChannelPressure:
|
||||
sequencerEvent.ChannelPressure(midiEvent.Channel, midiEvent.Value);
|
||||
break;
|
||||
|
||||
case RobustMidiCommand.PitchBend:
|
||||
sequencerEvent.PitchBend(midiEvent.Channel, midiEvent.Pitch);
|
||||
break;
|
||||
|
||||
case RobustMidiCommand.SystemMessage:
|
||||
switch (midiEvent.Control)
|
||||
{
|
||||
case 0x0 when midiEvent.Status == 0xFF:
|
||||
sequencerEvent.SystemReset();
|
||||
break;
|
||||
|
||||
case 0x0B:
|
||||
sequencerEvent.AllNotesOff(midiEvent.Channel);
|
||||
break;
|
||||
|
||||
default:
|
||||
_midiSawmill.Warning($"Tried to convert unsupported event to sequencer event:\n{midiEvent}");
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
_midiSawmill.Warning($"Tried to convert unsupported event to sequencer event:\n{midiEvent}");
|
||||
break;
|
||||
}
|
||||
|
||||
return sequencerEvent;
|
||||
}
|
||||
|
||||
public RobustMidiEvent FromSequencerEvent(SequencerEvent midiEvent, uint tick)
|
||||
{
|
||||
byte channel = (byte) midiEvent.Channel;
|
||||
RobustMidiCommand command = 0x0;
|
||||
byte data1 = 0;
|
||||
byte data2 = 0;
|
||||
|
||||
switch (midiEvent.Type)
|
||||
{
|
||||
case FluidSequencerEventType.NoteOn:
|
||||
command = RobustMidiCommand.NoteOn;
|
||||
data1 = (byte) midiEvent.Key;
|
||||
data2 = (byte) midiEvent.Velocity;
|
||||
break;
|
||||
|
||||
case FluidSequencerEventType.NoteOff:
|
||||
command = RobustMidiCommand.NoteOff;
|
||||
data1 = (byte) midiEvent.Key;
|
||||
break;
|
||||
|
||||
case FluidSequencerEventType.PitchBend:
|
||||
command = RobustMidiCommand.PitchBend;
|
||||
// We pack pitch into both data values
|
||||
var pitch = (ushort) midiEvent.Pitch;
|
||||
data1 = (byte) pitch;
|
||||
data2 = (byte) (pitch >> 8);
|
||||
break;
|
||||
|
||||
case FluidSequencerEventType.ProgramChange:
|
||||
command = RobustMidiCommand.ProgramChange;
|
||||
data1 = (byte) midiEvent.Program;
|
||||
break;
|
||||
|
||||
case FluidSequencerEventType.KeyPressure:
|
||||
command = RobustMidiCommand.AfterTouch;
|
||||
data1 = (byte) midiEvent.Key;
|
||||
data2 = (byte) midiEvent.Value;
|
||||
break;
|
||||
|
||||
case FluidSequencerEventType.ControlChange:
|
||||
command = RobustMidiCommand.ControlChange;
|
||||
data1 = (byte) midiEvent.Control;
|
||||
data2 = (byte) midiEvent.Value;
|
||||
break;
|
||||
|
||||
case FluidSequencerEventType.ChannelPressure:
|
||||
command = RobustMidiCommand.ChannelPressure;
|
||||
data1 = (byte) midiEvent.Value;
|
||||
break;
|
||||
|
||||
case FluidSequencerEventType.AllNotesOff:
|
||||
command = RobustMidiCommand.SystemMessage;
|
||||
data1 = 0x0B;
|
||||
break;
|
||||
|
||||
case FluidSequencerEventType.SystemReset:
|
||||
command = RobustMidiCommand.SystemMessage;
|
||||
channel = 0x0F;
|
||||
break;
|
||||
|
||||
default:
|
||||
_midiSawmill.Error($"Unsupported Sequencer Event: {tick:D8}: {SequencerEventToString(midiEvent)}");
|
||||
break;
|
||||
}
|
||||
|
||||
return new RobustMidiEvent(RobustMidiEvent.MakeStatus(channel, (byte)command), data1, data2, tick);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using NFluidsynth;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Asynchronous;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -15,269 +16,279 @@ using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Logger = Robust.Shared.Log.Logger;
|
||||
|
||||
namespace Robust.Client.Audio.Midi
|
||||
namespace Robust.Client.Audio.Midi;
|
||||
|
||||
internal sealed partial class MidiManager : IMidiManager
|
||||
{
|
||||
public interface IMidiManager
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IResourceManagerInternal _resourceManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfgMan = default!;
|
||||
[Dependency] private readonly IClydeAudio _clydeAudio = default!;
|
||||
[Dependency] private readonly ITaskManager _taskManager = default!;
|
||||
[Dependency] private readonly ILogManager _logger = default!;
|
||||
|
||||
private SharedPhysicsSystem _broadPhaseSystem = default!;
|
||||
|
||||
public IReadOnlyList<IMidiRenderer> Renderers
|
||||
{
|
||||
/// <summary>
|
||||
/// This method tries to return a midi renderer ready to be used.
|
||||
/// You only need to set the <see cref="IMidiRenderer.MidiProgram"/> afterwards.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method can fail if MIDI support is not available.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// <c>null</c> if MIDI support is not available.
|
||||
/// </returns>
|
||||
IMidiRenderer? GetNewRenderer();
|
||||
|
||||
/// <summary>
|
||||
/// Method called every frame.
|
||||
/// Should be used to update positional audio.
|
||||
/// </summary>
|
||||
/// <param name="frameTime"></param>
|
||||
void FrameUpdate(float frameTime);
|
||||
|
||||
/// <summary>
|
||||
/// Volume, in db.
|
||||
/// </summary>
|
||||
float Volume { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If true, MIDI support is available.
|
||||
/// </summary>
|
||||
bool IsAvailable { get; }
|
||||
|
||||
public int OcclusionCollisionMask { get; set; }
|
||||
|
||||
void Shutdown();
|
||||
get
|
||||
{
|
||||
lock (_renderers)
|
||||
{
|
||||
// Perform a copy. Sadly, we can't return a reference to the original list due to threading concerns.
|
||||
return _renderers.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class MidiManager : IMidiManager
|
||||
[ViewVariables]
|
||||
public bool IsAvailable
|
||||
{
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IResourceManagerInternal _resourceManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfgMan = default!;
|
||||
|
||||
private SharedPhysicsSystem _broadPhaseSystem = default!;
|
||||
|
||||
[ViewVariables]
|
||||
public bool IsAvailable
|
||||
get
|
||||
{
|
||||
get
|
||||
{
|
||||
InitializeFluidsynth();
|
||||
InitializeFluidsynth();
|
||||
|
||||
return FluidsynthInitialized;
|
||||
}
|
||||
return FluidsynthInitialized;
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
private readonly List<IMidiRenderer> _renderers = new();
|
||||
|
||||
private bool _alive = true;
|
||||
private Settings? _settings;
|
||||
private Thread? _midiThread;
|
||||
private ISawmill _midiSawmill = default!;
|
||||
private float _volume = 0f;
|
||||
private bool _volumeDirty = true;
|
||||
|
||||
// Not reliable until Fluidsynth is initialized!
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Volume
|
||||
{
|
||||
get => _volume;
|
||||
set
|
||||
{
|
||||
if (MathHelper.CloseToPercent(_volume, value))
|
||||
return;
|
||||
|
||||
_cfgMan.SetCVar(CVars.MidiVolume, value);
|
||||
_volumeDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly string[] LinuxSoundfonts =
|
||||
{
|
||||
"/usr/share/soundfonts/default.sf2",
|
||||
"/usr/share/soundfonts/default.dls",
|
||||
"/usr/share/soundfonts/FluidR3_GM.sf2",
|
||||
"/usr/share/soundfonts/freepats-general-midi.sf2",
|
||||
"/usr/share/sounds/sf2/default.sf2",
|
||||
"/usr/share/sounds/sf2/default.dls",
|
||||
"/usr/share/sounds/sf2/FluidR3_GM.sf2",
|
||||
"/usr/share/sounds/sf2/TimGM6mb.sf2",
|
||||
};
|
||||
|
||||
private const string WindowsSoundfont = @"C:\WINDOWS\system32\drivers\gm.dls";
|
||||
|
||||
private const string OsxSoundfont =
|
||||
"/System/Library/Components/CoreAudio.component/Contents/Resources/gs_instruments.dls";
|
||||
|
||||
private const string FallbackSoundfont = "/Midi/fallback.sf2";
|
||||
|
||||
private const float MaxDistanceForOcclusion = 1000;
|
||||
|
||||
private static ResourcePath CustomSoundfontDirectory = new ResourcePath("/soundfonts/");
|
||||
|
||||
private readonly ResourceLoaderCallbacks _soundfontLoaderCallbacks = new();
|
||||
|
||||
private bool FluidsynthInitialized;
|
||||
private bool _failedInitialize;
|
||||
|
||||
private NFluidsynth.Logger.LoggerDelegate _loggerDelegate = default!;
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int OcclusionCollisionMask { get; set; }
|
||||
|
||||
private void InitializeFluidsynth()
|
||||
{
|
||||
if (FluidsynthInitialized || _failedInitialize) return;
|
||||
|
||||
_volume = _cfgMan.GetCVar(CVars.MidiVolume);
|
||||
_cfgMan.OnValueChanged(CVars.MidiVolume, value =>
|
||||
{
|
||||
_volume = value;
|
||||
_volumeDirty = true;
|
||||
}, true);
|
||||
|
||||
_midiSawmill = _logger.GetSawmill("midi");
|
||||
_midiSawmill.Level = LogLevel.Info;
|
||||
_sawmill = _logger.GetSawmill("midi.fluidsynth");
|
||||
_loggerDelegate = LoggerDelegate;
|
||||
|
||||
if (!_resourceManager.UserData.Exists(CustomSoundfontDirectory))
|
||||
{
|
||||
_resourceManager.UserData.CreateDir(CustomSoundfontDirectory);
|
||||
}
|
||||
// not a directory, preserve the old file and create an actual directory
|
||||
else if (!_resourceManager.UserData.IsDir(CustomSoundfontDirectory))
|
||||
{
|
||||
_resourceManager.UserData.Rename(CustomSoundfontDirectory, CustomSoundfontDirectory.WithName(CustomSoundfontDirectory.Filename + ".old"));
|
||||
_resourceManager.UserData.CreateDir(CustomSoundfontDirectory);
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
private readonly List<IMidiRenderer> _renderers = new();
|
||||
|
||||
private bool _alive = true;
|
||||
private Settings? _settings;
|
||||
private Thread? _midiThread;
|
||||
private ISawmill _midiSawmill = default!;
|
||||
private float _volume = 0f;
|
||||
private bool _volumeDirty = true;
|
||||
|
||||
// Not reliable until Fluidsynth is initialized!
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Volume
|
||||
try
|
||||
{
|
||||
get => _volume;
|
||||
set
|
||||
{
|
||||
if (MathHelper.CloseToPercent(_volume, value))
|
||||
return;
|
||||
NFluidsynth.Logger.SetLoggerMethod(_loggerDelegate); // Will cause a safe DllNotFoundException if not available.
|
||||
|
||||
_cfgMan.SetCVar(CVars.MidiVolume, value);
|
||||
_volumeDirty = true;
|
||||
}
|
||||
_settings = new Settings();
|
||||
_settings["synth.sample-rate"].DoubleValue = 44100;
|
||||
_settings["player.timing-source"].StringValue = "sample";
|
||||
_settings["synth.lock-memory"].IntValue = 0;
|
||||
_settings["synth.threadsafe-api"].IntValue = 1;
|
||||
_settings["synth.gain"].DoubleValue = 1.0d;
|
||||
_settings["synth.polyphony"].IntValue = 1024;
|
||||
_settings["synth.cpu-cores"].IntValue = 2;
|
||||
_settings["synth.midi-channels"].IntValue = 16;
|
||||
_settings["synth.overflow.age"].DoubleValue = 3000;
|
||||
_settings["audio.driver"].StringValue = "file";
|
||||
_settings["audio.periods"].IntValue = 8;
|
||||
_settings["audio.period-size"].IntValue = 4096;
|
||||
_settings["midi.autoconnect"].IntValue = 1;
|
||||
_settings["player.reset-synth"].IntValue = 0;
|
||||
_settings["synth.midi-bank-select"].StringValue = "gm";
|
||||
//_settings["synth.verbose"].IntValue = 1; // Useful for debugging.
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_midiSawmill.Warning(
|
||||
"Failed to initialize fluidsynth due to exception, disabling MIDI support:\n{0}", e);
|
||||
_failedInitialize = true;
|
||||
return;
|
||||
}
|
||||
|
||||
private static readonly string[] LinuxSoundfonts =
|
||||
{
|
||||
"/usr/share/soundfonts/default.sf2",
|
||||
"/usr/share/soundfonts/FluidR3_GM.sf2",
|
||||
"/usr/share/soundfonts/freepats-general-midi.sf2",
|
||||
"/usr/share/sounds/sf2/default.sf2",
|
||||
"/usr/share/sounds/sf2/FluidR3_GM.sf2",
|
||||
"/usr/share/sounds/sf2/TimGM6mb.sf2",
|
||||
_midiThread = new Thread(ThreadUpdate);
|
||||
_midiThread.Start();
|
||||
|
||||
_broadPhaseSystem = EntitySystem.Get<SharedPhysicsSystem>();
|
||||
FluidsynthInitialized = true;
|
||||
}
|
||||
|
||||
private void LoggerDelegate(NFluidsynth.Logger.LogLevel level, string message, IntPtr data)
|
||||
{
|
||||
var rLevel = level switch {
|
||||
NFluidsynth.Logger.LogLevel.Panic => LogLevel.Error,
|
||||
NFluidsynth.Logger.LogLevel.Error => LogLevel.Error,
|
||||
NFluidsynth.Logger.LogLevel.Warning => LogLevel.Warning,
|
||||
NFluidsynth.Logger.LogLevel.Information => LogLevel.Info,
|
||||
NFluidsynth.Logger.LogLevel.Debug => LogLevel.Debug,
|
||||
_ => LogLevel.Debug
|
||||
};
|
||||
_sawmill.Log(rLevel, message);
|
||||
}
|
||||
|
||||
private const string WindowsSoundfont = @"C:\WINDOWS\system32\drivers\gm.dls";
|
||||
|
||||
private const string OsxSoundfont =
|
||||
"/System/Library/Components/CoreAudio.component/Contents/Resources/gs_instruments.dls";
|
||||
|
||||
private const string FallbackSoundfont = "/Midi/fallback.sf2";
|
||||
|
||||
private readonly ResourceLoaderCallbacks _soundfontLoaderCallbacks = new();
|
||||
|
||||
private bool FluidsynthInitialized;
|
||||
private bool _failedInitialize;
|
||||
|
||||
private NFluidsynth.Logger.LoggerDelegate _loggerDelegate = default!;
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int OcclusionCollisionMask { get; set; }
|
||||
|
||||
private void InitializeFluidsynth()
|
||||
public IMidiRenderer? GetNewRenderer(bool mono = true)
|
||||
{
|
||||
if (!FluidsynthInitialized)
|
||||
{
|
||||
if (FluidsynthInitialized || _failedInitialize) return;
|
||||
InitializeFluidsynth();
|
||||
|
||||
_volume = _cfgMan.GetCVar(CVars.MidiVolume);
|
||||
_cfgMan.OnValueChanged(CVars.MidiVolume, value =>
|
||||
if (!FluidsynthInitialized) // init failed
|
||||
{
|
||||
_volume = value;
|
||||
_volumeDirty = true;
|
||||
}, true);
|
||||
|
||||
_midiSawmill = Logger.GetSawmill("midi");
|
||||
_sawmill = Logger.GetSawmill("midi.fluidsynth");
|
||||
_loggerDelegate = LoggerDelegate;
|
||||
|
||||
try
|
||||
{
|
||||
NFluidsynth.Logger.SetLoggerMethod(_loggerDelegate); // Will cause a safe DllNotFoundException if not available.
|
||||
|
||||
_settings = new Settings();
|
||||
_settings["synth.sample-rate"].DoubleValue = 44100;
|
||||
_settings["player.timing-source"].StringValue = "sample";
|
||||
_settings["synth.lock-memory"].IntValue = 0;
|
||||
_settings["synth.threadsafe-api"].IntValue = 1;
|
||||
_settings["synth.gain"].DoubleValue = 1.0d;
|
||||
_settings["synth.polyphony"].IntValue = 1024;
|
||||
_settings["synth.cpu-cores"].IntValue = 2;
|
||||
_settings["synth.overflow.age"].DoubleValue = 3000;
|
||||
_settings["audio.driver"].StringValue = "file";
|
||||
_settings["audio.periods"].IntValue = 8;
|
||||
_settings["audio.period-size"].IntValue = 4096;
|
||||
_settings["midi.autoconnect"].IntValue = 1;
|
||||
_settings["player.reset-synth"].IntValue = 0;
|
||||
_settings["synth.midi-bank-select"].StringValue = "gm";
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.WarningS("midi",
|
||||
"Failed to initialize fluidsynth due to exception, disabling MIDI support:\n{0}", e);
|
||||
_failedInitialize = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_midiThread = new Thread(ThreadUpdate);
|
||||
_midiThread.Start();
|
||||
|
||||
_broadPhaseSystem = EntitySystem.Get<SharedPhysicsSystem>();
|
||||
FluidsynthInitialized = true;
|
||||
}
|
||||
|
||||
private void LoggerDelegate(NFluidsynth.Logger.LogLevel level, string message, IntPtr data)
|
||||
var soundfontLoader = SoundFontLoader.NewDefaultSoundFontLoader(_settings);
|
||||
|
||||
// Just making double sure these don't get GC'd.
|
||||
// They shouldn't, MidiRenderer keeps a ref, but making sure...
|
||||
var handle = GCHandle.Alloc(soundfontLoader);
|
||||
|
||||
try
|
||||
{
|
||||
var rLevel = level switch {
|
||||
NFluidsynth.Logger.LogLevel.Panic => LogLevel.Error,
|
||||
NFluidsynth.Logger.LogLevel.Error => LogLevel.Error,
|
||||
NFluidsynth.Logger.LogLevel.Warning => LogLevel.Warning,
|
||||
NFluidsynth.Logger.LogLevel.Information => LogLevel.Info,
|
||||
NFluidsynth.Logger.LogLevel.Debug => LogLevel.Debug,
|
||||
_ => LogLevel.Debug
|
||||
};
|
||||
_sawmill.Log(rLevel, message);
|
||||
}
|
||||
soundfontLoader.SetCallbacks(_soundfontLoaderCallbacks);
|
||||
|
||||
public IMidiRenderer? GetNewRenderer()
|
||||
{
|
||||
if (!FluidsynthInitialized)
|
||||
var renderer = new MidiRenderer(_settings!, soundfontLoader, mono, this, _clydeAudio, _taskManager, _midiSawmill);
|
||||
|
||||
// Since the last loaded soundfont takes priority, we load the fallback soundfont before the soundfont.
|
||||
renderer.LoadSoundfont(FallbackSoundfont);
|
||||
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
InitializeFluidsynth();
|
||||
|
||||
if (!FluidsynthInitialized) // init failed
|
||||
foreach (var filepath in LinuxSoundfonts)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!File.Exists(filepath) || !SoundFont.IsSoundFont(filepath)) continue;
|
||||
|
||||
var soundfontLoader = SoundFontLoader.NewDefaultSoundFontLoader(_settings);
|
||||
|
||||
// Just making double sure these don't get GC'd.
|
||||
// They shouldn't, MidiRenderer keeps a ref, but making sure...
|
||||
var handle = GCHandle.Alloc(soundfontLoader);
|
||||
|
||||
try
|
||||
{
|
||||
soundfontLoader.SetCallbacks(_soundfontLoaderCallbacks);
|
||||
|
||||
var renderer = new MidiRenderer(_settings!, soundfontLoader);
|
||||
|
||||
foreach (var file in _resourceManager.ContentFindFiles(("/Audio/MidiCustom/")))
|
||||
{
|
||||
if (file.Extension != "sf2" && file.Extension != "dls") continue;
|
||||
renderer.LoadSoundfont(file.ToString());
|
||||
}
|
||||
|
||||
// Since the last loaded soundfont takes priority, we load the fallback soundfont before the soundfont.
|
||||
renderer.LoadSoundfont(FallbackSoundfont);
|
||||
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
foreach (var filepath in LinuxSoundfonts)
|
||||
try
|
||||
{
|
||||
if (!File.Exists(filepath) || !SoundFont.IsSoundFont(filepath)) continue;
|
||||
|
||||
try
|
||||
{
|
||||
renderer.LoadSoundfont(filepath, true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
renderer.LoadSoundfont(filepath, true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
if (File.Exists(OsxSoundfont) && SoundFont.IsSoundFont(OsxSoundfont))
|
||||
renderer.LoadSoundfont(OsxSoundfont, true);
|
||||
}
|
||||
else if (OperatingSystem.IsWindows())
|
||||
{
|
||||
if (File.Exists(WindowsSoundfont) && SoundFont.IsSoundFont(WindowsSoundfont))
|
||||
renderer.LoadSoundfont(WindowsSoundfont, true);
|
||||
}
|
||||
|
||||
renderer.Source.SetVolume(Volume);
|
||||
|
||||
lock (_renderers)
|
||||
{
|
||||
_renderers.Add(renderer);
|
||||
break;
|
||||
}
|
||||
return renderer;
|
||||
}
|
||||
finally
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
handle.Free();
|
||||
if (File.Exists(OsxSoundfont) && SoundFont.IsSoundFont(OsxSoundfont))
|
||||
renderer.LoadSoundfont(OsxSoundfont, true);
|
||||
}
|
||||
else if (OperatingSystem.IsWindows())
|
||||
{
|
||||
if (File.Exists(WindowsSoundfont) && SoundFont.IsSoundFont(WindowsSoundfont))
|
||||
renderer.LoadSoundfont(WindowsSoundfont, true);
|
||||
}
|
||||
|
||||
// Load content-specific custom soundfonts, which could override the system/fallback soundfont.
|
||||
foreach (var file in _resourceManager.ContentFindFiles(("/Audio/MidiCustom/")))
|
||||
{
|
||||
if (file.Extension != "sf2" && file.Extension != "dls") continue;
|
||||
renderer.LoadSoundfont(file.ToString());
|
||||
}
|
||||
|
||||
// Load every soundfont from the user data directory last, since those may override any other soundfont.
|
||||
_midiSawmill.Debug($"loading soundfonts from {CustomSoundfontDirectory.ToRelativePath().ToString()}/*");
|
||||
var enumerator = _resourceManager.UserData.Find($"{CustomSoundfontDirectory.ToRelativePath().ToString()}/*").Item1;
|
||||
foreach (var soundfont in enumerator)
|
||||
{
|
||||
if (soundfont.Extension != "sf2" && soundfont.Extension != "dls") continue;
|
||||
_midiSawmill.Debug($"loading soundfont {soundfont}");
|
||||
renderer.LoadSoundfont(soundfont.ToString());
|
||||
}
|
||||
|
||||
renderer.Source.SetVolume(Volume);
|
||||
|
||||
lock (_renderers)
|
||||
{
|
||||
_renderers.Add(renderer);
|
||||
}
|
||||
return renderer;
|
||||
}
|
||||
finally
|
||||
{
|
||||
handle.Free();
|
||||
}
|
||||
}
|
||||
|
||||
public void FrameUpdate(float frameTime)
|
||||
{
|
||||
if (!FluidsynthInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void FrameUpdate(float frameTime)
|
||||
// Update positions of streams every frame.
|
||||
lock (_renderers)
|
||||
{
|
||||
if (!FluidsynthInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Update positions of streams every frame.
|
||||
foreach (var renderer in _renderers)
|
||||
{
|
||||
if (renderer.Disposed)
|
||||
@@ -318,7 +329,7 @@ namespace Robust.Client.Audio.Midi
|
||||
pos.Position,
|
||||
sourceRelative.Normalized,
|
||||
OcclusionCollisionMask),
|
||||
sourceRelative.Length,
|
||||
MathF.Min(sourceRelative.Length, MaxDistanceForOcclusion),
|
||||
renderer.TrackingEntity);
|
||||
}
|
||||
|
||||
@@ -339,80 +350,109 @@ namespace Robust.Client.Audio.Midi
|
||||
renderer.Source.SetOcclusion(float.MaxValue);
|
||||
}
|
||||
}
|
||||
|
||||
_volumeDirty = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Main method for the thread rendering the midi audio.
|
||||
/// </summary>
|
||||
private void ThreadUpdate()
|
||||
_volumeDirty = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Main method for the thread rendering the midi audio.
|
||||
/// </summary>
|
||||
private void ThreadUpdate()
|
||||
{
|
||||
while (_alive)
|
||||
{
|
||||
while (_alive)
|
||||
{
|
||||
lock (_renderers)
|
||||
{
|
||||
for (var i = 0; i < _renderers.Count; i++)
|
||||
{
|
||||
var renderer = _renderers[i];
|
||||
if (!renderer.Disposed)
|
||||
renderer.Render();
|
||||
else
|
||||
{
|
||||
renderer.InternalDispose();
|
||||
_renderers.Remove(renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
_alive = false;
|
||||
_midiThread?.Join();
|
||||
_settings?.Dispose();
|
||||
|
||||
lock (_renderers)
|
||||
{
|
||||
foreach (var renderer in _renderers)
|
||||
for (var i = 0; i < _renderers.Count; i++)
|
||||
{
|
||||
renderer?.Dispose();
|
||||
var renderer = _renderers[i];
|
||||
if (!renderer.Disposed)
|
||||
renderer.Render();
|
||||
else
|
||||
{
|
||||
renderer.InternalDispose();
|
||||
_renderers.Remove(renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (FluidsynthInitialized && !_failedInitialize)
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
_alive = false;
|
||||
_midiThread?.Join();
|
||||
_settings?.Dispose();
|
||||
|
||||
lock (_renderers)
|
||||
{
|
||||
foreach (var renderer in _renderers)
|
||||
{
|
||||
NFluidsynth.Logger.SetLoggerMethod(null);
|
||||
renderer?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class is used to load soundfonts.
|
||||
/// </summary>
|
||||
private sealed class ResourceLoaderCallbacks : SoundFontLoaderCallbacks
|
||||
if (FluidsynthInitialized && !_failedInitialize)
|
||||
{
|
||||
private readonly Dictionary<int, Stream> _openStreams = new();
|
||||
private int _nextStreamId = 1;
|
||||
NFluidsynth.Logger.SetLoggerMethod(null);
|
||||
}
|
||||
}
|
||||
|
||||
public override IntPtr Open(string filename)
|
||||
/// <summary>
|
||||
/// Internal method to get a human-readable representation of a <see cref="SequencerEvent"/>.
|
||||
/// </summary>
|
||||
internal static string SequencerEventToString(SequencerEvent midiEvent)
|
||||
{
|
||||
// ReSharper disable once UseStringInterpolation
|
||||
return string.Format(
|
||||
"{0} chan:{1:D2} key:{2:D5} bank:{3:D2} ctrl:{4:D5} dur:{5:D5} pitch:{6:D5} prog:{7:D3} val:{8:D5} vel:{9:D5}",
|
||||
midiEvent.Type.ToString().PadLeft(22),
|
||||
midiEvent.Channel,
|
||||
midiEvent.Key,
|
||||
midiEvent.Bank,
|
||||
midiEvent.Control,
|
||||
midiEvent.Duration,
|
||||
midiEvent.Pitch,
|
||||
midiEvent.Program,
|
||||
midiEvent.Value,
|
||||
midiEvent.Velocity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class is used to load soundfonts.
|
||||
/// </summary>
|
||||
private sealed class ResourceLoaderCallbacks : SoundFontLoaderCallbacks
|
||||
{
|
||||
private readonly Dictionary<int, Stream> _openStreams = new();
|
||||
private int _nextStreamId = 1;
|
||||
|
||||
public override IntPtr Open(string filename)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
{
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
Stream? stream;
|
||||
var resourceCache = IoCManager.Resolve<IResourceCache>();
|
||||
var resourcePath = new ResourcePath(filename);
|
||||
Stream? stream;
|
||||
var resourceCache = IoCManager.Resolve<IResourceCache>();
|
||||
var resourcePath = new ResourcePath(filename);
|
||||
|
||||
if (resourcePath.IsRooted && resourceCache.ContentFileExists(filename))
|
||||
if (resourcePath.IsRooted)
|
||||
{
|
||||
// is it in content?
|
||||
if (resourceCache.ContentFileExists(filename))
|
||||
{
|
||||
if (!resourceCache.TryContentFileRead(filename, out stream))
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
// is it in userdata?
|
||||
else if (resourceCache.UserData.Exists(resourcePath))
|
||||
{
|
||||
stream = resourceCache.UserData.OpenRead(resourcePath);
|
||||
}
|
||||
else if (File.Exists(filename))
|
||||
{
|
||||
stream = File.OpenRead(filename);
|
||||
@@ -421,73 +461,81 @@ namespace Robust.Client.Audio.Midi
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
var id = _nextStreamId++;
|
||||
|
||||
_openStreams.Add(id, stream);
|
||||
|
||||
return (IntPtr) id;
|
||||
}
|
||||
else if (File.Exists(filename))
|
||||
{
|
||||
stream = File.OpenRead(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
public override unsafe int Read(IntPtr buf, long count, IntPtr sfHandle)
|
||||
{
|
||||
var length = (int) count;
|
||||
var span = new Span<byte>(buf.ToPointer(), length);
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
var id = _nextStreamId++;
|
||||
|
||||
// Fluidsynth's docs state that this method should leave the buffer unmodified if it fails. (returns -1)
|
||||
try
|
||||
_openStreams.Add(id, stream);
|
||||
|
||||
return (IntPtr) id;
|
||||
}
|
||||
|
||||
public override unsafe int Read(IntPtr buf, long count, IntPtr sfHandle)
|
||||
{
|
||||
var length = (int) count;
|
||||
var span = new Span<byte>(buf.ToPointer(), length);
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
|
||||
// Fluidsynth's docs state that this method should leave the buffer unmodified if it fails. (returns -1)
|
||||
try
|
||||
{
|
||||
// Fluidsynth does a LOT of tiny allocations (frankly, way too much).
|
||||
if (count < 1024)
|
||||
{
|
||||
// Fluidsynth does a LOT of tiny allocations (frankly, way too much).
|
||||
if (count < 1024)
|
||||
{
|
||||
// ReSharper disable once SuggestVarOrType_Elsewhere
|
||||
Span<byte> buffer = stackalloc byte[(int)count];
|
||||
// ReSharper disable once SuggestVarOrType_Elsewhere
|
||||
Span<byte> buffer = stackalloc byte[(int)count];
|
||||
|
||||
stream.ReadExact(buffer);
|
||||
stream.ReadExact(buffer);
|
||||
|
||||
buffer.CopyTo(span);
|
||||
}
|
||||
else
|
||||
{
|
||||
var buffer = stream.ReadExact(length);
|
||||
|
||||
buffer.CopyTo(span);
|
||||
}
|
||||
buffer.CopyTo(span);
|
||||
}
|
||||
catch (EndOfStreamException)
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
var buffer = stream.ReadExact(length);
|
||||
|
||||
buffer.CopyTo(span);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override int Seek(IntPtr sfHandle, int offset, SeekOrigin origin)
|
||||
catch (EndOfStreamException)
|
||||
{
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
|
||||
stream.Seek(offset, origin);
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public override int Tell(IntPtr sfHandle)
|
||||
{
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) stream.Position;
|
||||
}
|
||||
public override int Seek(IntPtr sfHandle, int offset, SeekOrigin origin)
|
||||
{
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
|
||||
public override int Close(IntPtr sfHandle)
|
||||
{
|
||||
if (!_openStreams.Remove((int) sfHandle, out var stream))
|
||||
return -1;
|
||||
stream.Seek(offset, origin);
|
||||
|
||||
stream.Dispose();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override int Tell(IntPtr sfHandle)
|
||||
{
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
|
||||
return (int) stream.Position;
|
||||
}
|
||||
|
||||
public override int Close(IntPtr sfHandle)
|
||||
{
|
||||
if (!_openStreams.Remove((int) sfHandle, out var stream))
|
||||
return -1;
|
||||
|
||||
stream.Dispose();
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
80
Robust.Client/Audio/Midi/MidiRendererState.cs
Normal file
80
Robust.Client/Audio/Midi/MidiRendererState.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.Audio.Midi;
|
||||
|
||||
public struct MidiRendererState
|
||||
{
|
||||
internal FixedArray16<FixedArray128<byte>> NoteVelocities;
|
||||
internal FixedArray16<FixedArray128<byte>> Controllers;
|
||||
internal FixedArray16<byte> Program;
|
||||
internal FixedArray16<byte> ChannelPressure;
|
||||
internal FixedArray16<ushort> PitchBend;
|
||||
|
||||
internal Span<byte> AsSpan => MemoryMarshal.CreateSpan(ref NoteVelocities._00._00, 4160);
|
||||
|
||||
static unsafe MidiRendererState()
|
||||
{
|
||||
var s = new MidiRendererState();
|
||||
DebugTools.Assert(s.AsSpan.Length == sizeof(MidiRendererState),
|
||||
$"{nameof(MidiRendererState)}'s {nameof(AsSpan)} length does not match struct size! Was: {s.AsSpan.Length} Expected: {sizeof(MidiRendererState)}");
|
||||
}
|
||||
|
||||
public MidiRendererState()
|
||||
{
|
||||
NoteVelocities = default;
|
||||
Program = default;
|
||||
ChannelPressure = default;
|
||||
PitchBend = default;
|
||||
Controllers = default;
|
||||
|
||||
// PitchBend is at 8192 by default.
|
||||
PitchBend.AsSpan.Fill(8192);
|
||||
|
||||
// Controller defaults
|
||||
Controllers.AsSpan.Fill(new FixedArray128<byte>
|
||||
{
|
||||
// Bank selection default
|
||||
_00 = 0,
|
||||
|
||||
// Volume controller default
|
||||
_07 = 100,
|
||||
|
||||
// Balance controller default
|
||||
_08 = 64,
|
||||
|
||||
// Pan controller default
|
||||
_10 = 64,
|
||||
|
||||
// Expression controller default
|
||||
_11 = 127,
|
||||
|
||||
// Controller 11 default
|
||||
_43 = 127,
|
||||
|
||||
// Sound controllers 1 to 10 defaults
|
||||
_70 = 64,
|
||||
_71 = 64,
|
||||
_72 = 64,
|
||||
_73 = 64,
|
||||
_74 = 64,
|
||||
_75 = 64,
|
||||
_76 = 64,
|
||||
_77 = 64,
|
||||
_78 = 64,
|
||||
_79 = 64,
|
||||
|
||||
// Portamento default
|
||||
_84 = 255,
|
||||
|
||||
// Non-Registered Parameter Number defaults
|
||||
_98 = 127, // LSB
|
||||
_99 = 127, // MSB
|
||||
|
||||
// Registered Parameter Number defaults
|
||||
_100 = 127, // LSB
|
||||
_101 = 127, // MSB
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Net;
|
||||
using Robust.Client.Debugging;
|
||||
using Robust.Client.GameObjects;
|
||||
@@ -13,6 +13,7 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Network.Messages;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -45,6 +46,8 @@ namespace Robust.Client
|
||||
|
||||
public string? LastDisconnectReason { get; private set; }
|
||||
|
||||
private (TimeSpan, GameTick) _timeBase;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -52,20 +55,34 @@ namespace Robust.Client
|
||||
_net.ConnectFailed += OnConnectFailed;
|
||||
_net.Disconnect += OnNetDisconnect;
|
||||
|
||||
_net.RegisterNetMessage<MsgSyncTimeBase>(
|
||||
SyncTimeBase,
|
||||
NetMessageAccept.Handshake | NetMessageAccept.Client);
|
||||
|
||||
_configManager.OnValueChanged(CVars.NetTickrate, TickRateChanged, invokeImmediately: true);
|
||||
|
||||
_playMan.Initialize();
|
||||
Reset();
|
||||
}
|
||||
|
||||
private void TickRateChanged(int tickrate)
|
||||
private void SyncTimeBase(MsgSyncTimeBase message)
|
||||
{
|
||||
Logger.DebugS("client", $"Synchronized time base: {message.Tick}: {message.Time}");
|
||||
|
||||
if (RunLevel >= ClientRunLevel.Connected)
|
||||
_timing.TimeBase = (message.Time, message.Tick);
|
||||
else
|
||||
_timeBase = (message.Time, message.Tick);
|
||||
}
|
||||
|
||||
private void TickRateChanged(int tickrate, in CVarChangeInfo info)
|
||||
{
|
||||
if (GameInfo != null)
|
||||
{
|
||||
GameInfo.TickRate = (byte) tickrate;
|
||||
}
|
||||
|
||||
_timing.TickRate = (byte) tickrate;
|
||||
_timing.SetTickRateAt((byte) tickrate, info.TickChanged);
|
||||
Logger.InfoS("client", $"Tickrate changed to: {tickrate} on tick {_timing.CurTick}");
|
||||
}
|
||||
|
||||
@@ -74,7 +91,7 @@ namespace Robust.Client
|
||||
{
|
||||
if (RunLevel == ClientRunLevel.Connecting)
|
||||
{
|
||||
_net.Shutdown("Client mashing that connect button.");
|
||||
_net.Reset("Client mashing that connect button.");
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -202,7 +219,9 @@ namespace Robust.Client
|
||||
{
|
||||
DebugTools.Assert(RunLevel > ClientRunLevel.Initialize);
|
||||
|
||||
PlayerLeaveServer?.Invoke(this, new PlayerEventArgs(_playMan.LocalPlayer?.Session));
|
||||
// Don't invoke PlayerLeaveServer if PlayerJoinedServer & GameStartedSetup hasn't been called yet.
|
||||
if (RunLevel > ClientRunLevel.Connecting)
|
||||
PlayerLeaveServer?.Invoke(this, new PlayerEventArgs(_playMan.LocalPlayer?.Session));
|
||||
|
||||
LastDisconnectReason = args.Reason;
|
||||
GameStoppedReset();
|
||||
@@ -213,7 +232,7 @@ namespace Robust.Client
|
||||
_entityManager.Startup();
|
||||
_mapManager.Startup();
|
||||
|
||||
_timing.ResetSimTime();
|
||||
_timing.ResetSimTime(_timeBase);
|
||||
_timing.Paused = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ using Robust.Client.Input;
|
||||
using Robust.Client.Map;
|
||||
using Robust.Client.Placement;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.Profiling;
|
||||
using Robust.Client.Prototypes;
|
||||
using Robust.Client.Reflection;
|
||||
using Robust.Client.ResourceManagement;
|
||||
@@ -61,6 +62,8 @@ namespace Robust.Client
|
||||
IoCManager.Register<IResourceCache, ResourceCache>();
|
||||
IoCManager.Register<IResourceCacheInternal, ResourceCache>();
|
||||
IoCManager.Register<IClientNetManager, NetManager>();
|
||||
IoCManager.Register<EntityManager, ClientEntityManager>();
|
||||
IoCManager.Register<ClientEntityManager>();
|
||||
IoCManager.Register<IClientEntityManager, ClientEntityManager>();
|
||||
IoCManager.Register<IClientEntityManagerInternal, ClientEntityManager>();
|
||||
IoCManager.Register<IEntityNetworkManager, ClientEntityManager>();
|
||||
@@ -75,6 +78,7 @@ namespace Robust.Client
|
||||
IoCManager.Register<IDiscordRichPresence, DiscordRichPresence>();
|
||||
IoCManager.Register<IMidiManager, MidiManager>();
|
||||
IoCManager.Register<IAuthManager, AuthManager>();
|
||||
IoCManager.Register<ProfViewManager>();
|
||||
IoCManager.Register<IPhysicsManager, PhysicsManager>();
|
||||
switch (mode)
|
||||
{
|
||||
|
||||
98
Robust.Client/Console/ClientConsoleHost.Completions.cs
Normal file
98
Robust.Client/Console/ClientConsoleHost.Completions.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Network.Messages;
|
||||
|
||||
namespace Robust.Client.Console;
|
||||
|
||||
internal sealed partial class ClientConsoleHost
|
||||
{
|
||||
private readonly Dictionary<int, PendingCompletion> _completionsPending = new();
|
||||
private int _completionSeq;
|
||||
|
||||
|
||||
public async Task<CompletionResult> GetCompletions(List<string> args, CancellationToken cancel)
|
||||
{
|
||||
// Last element is the command currently being typed. May be empty.
|
||||
|
||||
// Logger.Debug($"Running completions: {string.Join(", ", args)}");
|
||||
|
||||
var delay = _cfg.GetCVar(CVars.ConCompletionDelay);
|
||||
if (delay > 0)
|
||||
await Task.Delay((int)(delay * 1000), cancel);
|
||||
|
||||
return await CalcCompletions(args, cancel);
|
||||
}
|
||||
|
||||
private Task<CompletionResult> CalcCompletions(List<string> args, CancellationToken cancel)
|
||||
{
|
||||
if (args.Count == 1)
|
||||
{
|
||||
// Typing out command name, handle this ourselves.
|
||||
var cmdOptions = CompletionResult.FromOptions(
|
||||
RegisteredCommands.Values
|
||||
.Where(c => CanExecute(c.Command))
|
||||
.OrderBy(c => c.Command)
|
||||
.Select(c => new CompletionOption(c.Command, c.Description)));
|
||||
|
||||
return Task.FromResult(cmdOptions);
|
||||
}
|
||||
|
||||
if (!RegisteredCommands.TryGetValue(args[0], out var cmd))
|
||||
return Task.FromResult(CompletionResult.Empty);
|
||||
|
||||
return cmd.GetCompletionAsync(LocalShell, args.ToArray()[1..], cancel).AsTask();
|
||||
}
|
||||
|
||||
private Task<CompletionResult> DoServerCompletions(List<string> args, CancellationToken cancel)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<CompletionResult>();
|
||||
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel);
|
||||
var seq = _completionSeq++;
|
||||
|
||||
var pending = new PendingCompletion
|
||||
{
|
||||
Cts = cts,
|
||||
Tcs = tcs
|
||||
};
|
||||
|
||||
var msg = new MsgConCompletion
|
||||
{
|
||||
Args = args.ToArray(),
|
||||
Seq = seq
|
||||
};
|
||||
|
||||
cts.Token.Register(() =>
|
||||
{
|
||||
tcs.SetCanceled(cts.Token);
|
||||
cts.Dispose();
|
||||
_completionsPending.Remove(seq);
|
||||
}, true);
|
||||
|
||||
NetManager.ClientSendMessage(msg);
|
||||
|
||||
_completionsPending.Add(seq, pending);
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
private void ProcessCompletionResp(MsgConCompletionResp message)
|
||||
{
|
||||
if (!_completionsPending.TryGetValue(message.Seq, out var pending))
|
||||
return;
|
||||
|
||||
pending.Cts.Dispose();
|
||||
pending.Tcs.SetResult(message.Result);
|
||||
|
||||
_completionsPending.Remove(message.Seq);
|
||||
}
|
||||
|
||||
private struct PendingCompletion
|
||||
{
|
||||
public TaskCompletionSource<CompletionResult> Tcs;
|
||||
public CancellationTokenSource Cts;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Robust.Client.Log;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Network.Messages;
|
||||
@@ -41,18 +46,24 @@ namespace Robust.Client.Console
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IClientConsoleHost" />
|
||||
internal sealed class ClientConsoleHost : ConsoleHost, IClientConsoleHost
|
||||
internal sealed partial class ClientConsoleHost : ConsoleHost, IClientConsoleHost, IConsoleHostInternal
|
||||
{
|
||||
[Dependency] private readonly IClientConGroupController _conGroup = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
|
||||
private bool _requestedCommands;
|
||||
|
||||
public ClientConsoleHost() : base(isServer: false) {}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Initialize()
|
||||
{
|
||||
NetManager.RegisterNetMessage<MsgConCmdReg>(HandleConCmdReg);
|
||||
NetManager.RegisterNetMessage<MsgConCmdAck>(HandleConCmdAck);
|
||||
NetManager.RegisterNetMessage<MsgConCmd>(ProcessCommand);
|
||||
NetManager.RegisterNetMessage<MsgConCompletion>();
|
||||
NetManager.RegisterNetMessage<MsgConCompletionResp>(ProcessCompletionResp);
|
||||
|
||||
_requestedCommands = false;
|
||||
NetManager.Connected += OnNetworkConnected;
|
||||
@@ -88,6 +99,11 @@ namespace Robust.Client.Console
|
||||
OutputText(text, true, true);
|
||||
}
|
||||
|
||||
public bool IsCmdServer(IConsoleCommand cmd)
|
||||
{
|
||||
return cmd is ServerDummyCommand;
|
||||
}
|
||||
|
||||
public override event ConAnyCommandCallback? AnyCommandExecuted;
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -108,14 +124,12 @@ namespace Robust.Client.Console
|
||||
|
||||
if (AvailableCommands.ContainsKey(commandName))
|
||||
{
|
||||
var playerManager = IoCManager.Resolve<IPlayerManager>();
|
||||
#if !DEBUG
|
||||
if (!_conGroup.CanCommand(commandName) && playerManager.LocalPlayer?.Session.Status > SessionStatus.Connecting)
|
||||
if (!CanExecute(commandName))
|
||||
{
|
||||
WriteError(null, $"Insufficient perms for command: {commandName}");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
var command1 = AvailableCommands[commandName];
|
||||
args.RemoveAt(0);
|
||||
var shell = new ConsoleShell(this, null);
|
||||
@@ -128,13 +142,23 @@ namespace Robust.Client.Console
|
||||
WriteError(null, "Unknown command: " + commandName);
|
||||
}
|
||||
|
||||
private bool CanExecute(string cmdName)
|
||||
{
|
||||
// When not connected to a server, you can run all local commands.
|
||||
// When connected to a server, you can only run commands according to the con group controller.
|
||||
|
||||
return _player.LocalPlayer == null
|
||||
|| _player.LocalPlayer.Session.Status <= SessionStatus.Connecting
|
||||
|| _conGroup.CanCommand(cmdName);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void RemoteExecuteCommand(ICommonSession? session, string command)
|
||||
{
|
||||
if (!NetManager.IsConnected) // we don't care about session on client
|
||||
return;
|
||||
|
||||
var msg = NetManager.CreateNetMessage<MsgConCmd>();
|
||||
var msg = new MsgConCmd();
|
||||
msg.Text = command;
|
||||
NetManager.ClientSendMessage(msg);
|
||||
}
|
||||
@@ -198,36 +222,69 @@ namespace Robust.Client.Console
|
||||
if (!NetManager.IsConnected)
|
||||
return;
|
||||
|
||||
var msg = NetManager.CreateNetMessage<MsgConCmdReg>();
|
||||
var msg = new MsgConCmdReg();
|
||||
NetManager.ClientSendMessage(msg);
|
||||
|
||||
_requestedCommands = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// These dummies are made purely so list and help can list server-side commands.
|
||||
/// </summary>
|
||||
[Reflect(false)]
|
||||
internal sealed class ServerDummyCommand : IConsoleCommand
|
||||
{
|
||||
internal ServerDummyCommand(string command, string help, string description)
|
||||
/// <summary>
|
||||
/// These dummies are made purely so list and help can list server-side commands.
|
||||
/// </summary>
|
||||
[Reflect(false)]
|
||||
private sealed class ServerDummyCommand : IConsoleCommand
|
||||
{
|
||||
Command = command;
|
||||
Help = help;
|
||||
Description = description;
|
||||
internal ServerDummyCommand(string command, string help, string description)
|
||||
{
|
||||
Command = command;
|
||||
Help = help;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public string Command { get; }
|
||||
|
||||
public string Description { get; }
|
||||
|
||||
public string Help { get; }
|
||||
|
||||
// Always forward to server.
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
shell.RemoteExecuteCommand(argStr);
|
||||
}
|
||||
|
||||
public async ValueTask<CompletionResult> GetCompletionAsync(
|
||||
IConsoleShell shell,
|
||||
string[] args,
|
||||
CancellationToken cancel)
|
||||
{
|
||||
var host = (ClientConsoleHost)shell.ConsoleHost;
|
||||
var argsList = args.ToList();
|
||||
argsList.Insert(0, Command);
|
||||
|
||||
return await host.DoServerCompletions(argsList, cancel);
|
||||
}
|
||||
}
|
||||
|
||||
public string Command { get; }
|
||||
|
||||
public string Description { get; }
|
||||
|
||||
public string Help { get; }
|
||||
|
||||
// Always forward to server.
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
private sealed class RemoteExecCommand : IConsoleCommand
|
||||
{
|
||||
shell.RemoteExecuteCommand(argStr);
|
||||
public string Command => ">";
|
||||
public string Description => Loc.GetString("cmd-remoteexec-desc");
|
||||
public string Help => Loc.GetString("cmd-remoteexec-help");
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
shell.RemoteExecuteCommand(argStr["> ".Length..]);
|
||||
}
|
||||
|
||||
public async ValueTask<CompletionResult> GetCompletionAsync(
|
||||
IConsoleShell shell,
|
||||
string[] args,
|
||||
CancellationToken cancel)
|
||||
{
|
||||
var host = (ClientConsoleHost)shell.ConsoleHost;
|
||||
return await host.DoServerCompletions(args.ToList(), cancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Console;
|
||||
@@ -7,57 +5,6 @@ using Robust.Shared.IoC;
|
||||
|
||||
namespace Robust.Client.Console.Commands
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class CVarCommand : SharedCVarCommand, IConsoleCommand
|
||||
{
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length < 1 || args.Length > 2)
|
||||
{
|
||||
shell.WriteError("Must provide exactly one or two arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
||||
var name = args[0];
|
||||
|
||||
if (name == "?")
|
||||
{
|
||||
var cvars = configManager.GetRegisteredCVars().OrderBy(c => c);
|
||||
shell.WriteLine(string.Join("\n", cvars));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!configManager.IsCVarRegistered(name))
|
||||
{
|
||||
shell.WriteError($"CVar '{name}' is not registered. Use 'cvar ?' to get a list of all registered CVars.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length == 1)
|
||||
{
|
||||
// Read CVar
|
||||
var value = configManager.GetCVar<object>(name);
|
||||
shell.WriteLine(value.ToString() ?? "");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write CVar
|
||||
var value = args[1];
|
||||
var type = configManager.GetCVarType(name);
|
||||
try
|
||||
{
|
||||
var parsed = ParseObject(type, value);
|
||||
configManager.SetCVar(name, parsed);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
shell.WriteLine($"Input value is in incorrect format for type {type}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class SaveConfig : IConsoleCommand
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@ using Robust.Shared.Console;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
@@ -97,54 +98,72 @@ namespace Robust.Client.Console.Commands
|
||||
{
|
||||
public string Command => "monitor";
|
||||
|
||||
public string Help =>
|
||||
"Usage: monitor <name>\nPossible monitors are: fps, net, bandwidth, coord, time, frames, mem, clyde, input";
|
||||
public string Description => Loc.GetString("cmd-monitor-desc");
|
||||
|
||||
public string Description => "Toggles a debug monitor in the F3 menu.";
|
||||
public string Help
|
||||
{
|
||||
get
|
||||
{
|
||||
var monitors = string.Join(", ", Enum.GetNames<DebugMonitor>());
|
||||
return Loc.GetString("cmd-monitor-help", ("monitors", monitors));
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var monitor = IoCManager.Resolve<IUserInterfaceManager>().DebugMonitors;
|
||||
var monitors = IoCManager.Resolve<IUserInterfaceManager>().DebugMonitors;
|
||||
|
||||
if (args.Length != 1)
|
||||
{
|
||||
shell.WriteLine(Help);
|
||||
shell.WriteLine(Loc.GetString("cmd-monitor-arg-count"));
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[0])
|
||||
var monitorArg = args[0];
|
||||
if (monitorArg.Equals("-all", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
case "fps":
|
||||
monitor.ShowFPS ^= true;
|
||||
break;
|
||||
case "net":
|
||||
monitor.ShowNet ^= true;
|
||||
break;
|
||||
case "bandwidth":
|
||||
monitor.ShowNetBandwidth ^= true;
|
||||
break;
|
||||
case "coord":
|
||||
monitor.ShowCoords ^= true;
|
||||
break;
|
||||
case "time":
|
||||
monitor.ShowTime ^= true;
|
||||
break;
|
||||
case "frames":
|
||||
monitor.ShowFrameGraph ^= true;
|
||||
break;
|
||||
case "mem":
|
||||
monitor.ShowMemory ^= true;
|
||||
break;
|
||||
case "clyde":
|
||||
monitor.ShowClyde ^= true;
|
||||
break;
|
||||
case "input":
|
||||
monitor.ShowInput ^= true;
|
||||
break;
|
||||
default:
|
||||
shell.WriteLine($"Invalid key: {args[0]}");
|
||||
break;
|
||||
foreach (var monitor in Enum.GetValues<DebugMonitor>())
|
||||
{
|
||||
monitors.SetMonitor(monitor, false);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (monitorArg.Equals("+all", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
foreach (var monitor in Enum.GetValues<DebugMonitor>())
|
||||
{
|
||||
monitors.SetMonitor(monitor, true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Enum.TryParse(monitorArg, true, out DebugMonitor parsedMonitor))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("cmd-monitor-invalid-name"));
|
||||
return;
|
||||
}
|
||||
|
||||
monitors.ToggleMonitor(parsedMonitor);
|
||||
}
|
||||
|
||||
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
var allOptions = new CompletionOption[]
|
||||
{
|
||||
new("-all", Loc.GetString("cmd-monitor-minus-all-hint")),
|
||||
new("+all", Loc.GetString("cmd-monitor-plus-all-hint"))
|
||||
};
|
||||
|
||||
var options = allOptions.Concat(Enum.GetNames<DebugMonitor>().Select(c => new CompletionOption(c)));
|
||||
return CompletionResult.FromHintOptions(options, Loc.GetString("cmd-monitor-arg-monitor"));
|
||||
}
|
||||
|
||||
return CompletionResult.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -739,103 +758,6 @@ namespace Robust.Client.Console.Commands
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class GcCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "gc";
|
||||
public string Description => "Run the GC.";
|
||||
public string Help => "gc [generation]";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
GC.Collect();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (int.TryParse(args[0], out int result))
|
||||
GC.Collect(result);
|
||||
else
|
||||
shell.WriteError("Failed to parse argument.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class GcFullCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "gcf";
|
||||
public string Description => "Run the GC, fully, compacting LOH and everything.";
|
||||
public string Help => "gcf";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
|
||||
GC.Collect(2, GCCollectionMode.Forced, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class GcModeCommand : IConsoleCommand
|
||||
{
|
||||
|
||||
public string Command => "gc_mode";
|
||||
|
||||
public string Description => "Change/Read the GC Latency mode.";
|
||||
|
||||
public string Help => "gc_mode\nSee current GC Latencymode\ngc_mode [type]\n Change GC Latency mode to [type]";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var prevMode = GCSettings.LatencyMode;
|
||||
if (args.Length == 0)
|
||||
{
|
||||
shell.WriteLine($"current gc latency mode: {(int) prevMode} ({prevMode})");
|
||||
shell.WriteLine("possible modes:");
|
||||
foreach (int mode in (int[]) Enum.GetValues(typeof(GCLatencyMode)))
|
||||
{
|
||||
shell.WriteLine($" {mode}: {Enum.GetName(typeof(GCLatencyMode), mode)}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GCLatencyMode mode;
|
||||
if (char.IsDigit(args[0][0]) && int.TryParse(args[0], out var modeNum))
|
||||
{
|
||||
mode = (GCLatencyMode) modeNum;
|
||||
}
|
||||
else if (!Enum.TryParse(args[0], true, out mode))
|
||||
{
|
||||
shell.WriteLine($"unknown gc latency mode: {args[0]}");
|
||||
return;
|
||||
}
|
||||
|
||||
shell.WriteLine($"attempting gc latency mode change: {(int) prevMode} ({prevMode}) -> {(int) mode} ({mode})");
|
||||
GCSettings.LatencyMode = mode;
|
||||
shell.WriteLine($"resulting gc latency mode: {(int) GCSettings.LatencyMode} ({GCSettings.LatencyMode})");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal sealed class SerializeStatsCommand : IConsoleCommand
|
||||
{
|
||||
|
||||
public string Command => "szr_stats";
|
||||
|
||||
public string Description => "Report serializer statistics.";
|
||||
|
||||
public string Help => "szr_stats";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
|
||||
shell.WriteLine($"serialized: {RobustSerializer.BytesSerialized} bytes, {RobustSerializer.ObjectsSerialized} objects");
|
||||
shell.WriteLine($"largest serialized: {RobustSerializer.LargestObjectSerializedBytes} bytes, {RobustSerializer.LargestObjectSerializedType} objects");
|
||||
shell.WriteLine($"deserialized: {RobustSerializer.BytesDeserialized} bytes, {RobustSerializer.ObjectsDeserialized} objects");
|
||||
shell.WriteLine($"largest serialized: {RobustSerializer.LargestObjectDeserializedBytes} bytes, {RobustSerializer.LargestObjectDeserializedType} objects");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal sealed class ChunkInfoCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "chunkinfo";
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
using System.Linq;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Robust.Client.Console.Commands
|
||||
{
|
||||
sealed class HelpCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "help";
|
||||
public string Help => "When no arguments are provided, displays a generic help text. When an argument is passed, display the help text for the command with that name.";
|
||||
public string Description => "Display help text.";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
switch (args.Length)
|
||||
{
|
||||
case 0:
|
||||
shell.WriteLine("To display help for a specific command, write 'help <command>'. To list all available commands, write 'list'.");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
string commandname = args[0];
|
||||
if (!shell.ConsoleHost.RegisteredCommands.ContainsKey(commandname))
|
||||
{
|
||||
if (!IoCManager.Resolve<IClientNetManager>().IsConnected)
|
||||
{
|
||||
// No server so nothing to respond with unknown command.
|
||||
shell.WriteError("Unknown command: " + commandname);
|
||||
return;
|
||||
}
|
||||
// TODO: Maybe have a server side help?
|
||||
return;
|
||||
}
|
||||
IConsoleCommand command = shell.ConsoleHost.RegisteredCommands[commandname];
|
||||
shell.WriteLine(string.Format("{0} - {1}", command.Command, command.Description));
|
||||
shell.WriteLine(command.Help);
|
||||
break;
|
||||
|
||||
default:
|
||||
shell.WriteError("Invalid amount of arguments.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ListCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "list";
|
||||
public string Help => "Usage: list [filter]\n" +
|
||||
"Lists all available commands, and their short descriptions.\n" +
|
||||
"If a filter is provided, " +
|
||||
"only commands that contain the given string in their name will be listed.";
|
||||
public string Description => "List all commands, optionally with a filter.";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var filter = "";
|
||||
if (args.Length == 1)
|
||||
{
|
||||
filter = args[0];
|
||||
}
|
||||
|
||||
var conGroup = IoCManager.Resolve<IClientConGroupController>();
|
||||
foreach (var command in shell.ConsoleHost.RegisteredCommands.Values
|
||||
.Where(p => p.Command.Contains(filter) && (p is not ServerDummyCommand || conGroup.CanCommand(p.Command)))
|
||||
.OrderBy(c => c.Command))
|
||||
{
|
||||
shell.WriteLine(command.Command + ": " + command.Description);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Runtime.Loader;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Robust.Client.Console.Commands
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class ListAssembliesCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "lsasm";
|
||||
public string Description => "Lists loaded assemblies by load context.";
|
||||
public string Help => Command;
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
foreach (var context in AssemblyLoadContext.All)
|
||||
{
|
||||
shell.WriteLine($"{context.Name}:");
|
||||
foreach (var assembly in context.Assemblies.OrderBy(a => a.FullName))
|
||||
{
|
||||
shell.WriteLine($" {assembly.FullName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
using Robust.Shared.Log;
|
||||
using System;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Robust.Client.Console.Commands
|
||||
{
|
||||
sealed class LogSetLevelCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "loglevel";
|
||||
public string Description => "Changes the log level for a provided sawmill.";
|
||||
public string Help => "Usage: loglevel <sawmill> <level>"
|
||||
+ "\n sawmill: A label prefixing log messages. This is the one you're setting the level for."
|
||||
+ "\n level: The log level. Must match one of the values of the LogLevel enum.";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
shell.WriteError("Invalid argument amount. Expected 2 arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
var name = args[0];
|
||||
var levelname = args[1];
|
||||
LogLevel? level;
|
||||
if (levelname == "null")
|
||||
{
|
||||
level = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Enum.TryParse<LogLevel>(levelname, out var result))
|
||||
{
|
||||
shell.WriteLine("Failed to parse 2nd argument. Must be one of the values of the LogLevel enum.");
|
||||
return;
|
||||
}
|
||||
level = result;
|
||||
}
|
||||
Logger.GetSawmill(name).Level = level;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class TestLog : IConsoleCommand
|
||||
{
|
||||
public string Command => "testlog";
|
||||
public string Description => "Writes a test log to a sawmill.";
|
||||
public string Help => "Usage: testlog <sawmill> <level> <message>"
|
||||
+ "\n sawmill: A label prefixing the logged message."
|
||||
+ "\n level: The log level. Must match one of the values of the LogLevel enum."
|
||||
+ "\n message: The message to be logged. Wrap this in double quotes if you want to use spaces.";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 3)
|
||||
{
|
||||
shell.WriteError("Invalid argument amount. Expected 3 arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
var name = args[0];
|
||||
var levelname = args[1];
|
||||
var message = args[2]; // yes this doesn't support spaces idgaf.
|
||||
if (!Enum.TryParse<LogLevel>(levelname, out var result))
|
||||
{
|
||||
shell.WriteLine("Failed to parse 2nd argument. Must be one of the values of the LogLevel enum.");
|
||||
return;
|
||||
}
|
||||
var level = result;
|
||||
|
||||
Logger.LogS(level, name, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Robust.Client.Debugging;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Robust.Client.Console.Commands
|
||||
{
|
||||
@@ -8,12 +9,13 @@ namespace Robust.Client.Console.Commands
|
||||
{
|
||||
public string Command => "physics";
|
||||
public string Description => $"Shows a debug physics overlay. The arg supplied specifies the overlay.";
|
||||
public string Help => $"{Command} <aabbs / contactnormals / contactpoints / joints / shapeinfo / shapes>";
|
||||
public string Help => $"{Command} <aabbs / com / contactnormals / contactpoints / joints / shapeinfo / shapes>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 1)
|
||||
{
|
||||
shell.WriteLine($"Invalid number of args supplied");
|
||||
shell.WriteError(Loc.GetString("shell-wrong-arguments-number-need-specific", ("properAmount", 1), ("currentAmount", args.Length)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,11 +45,27 @@ namespace Robust.Client.Console.Commands
|
||||
system.Flags ^= PhysicsDebugFlags.Shapes;
|
||||
break;
|
||||
default:
|
||||
shell.WriteLine($"{args[0]} is not a recognised overlay");
|
||||
shell.WriteError(Loc.GetString("cmd-physics-overlay", ("overlay", args[0])));
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
if (args.Length != 1) return CompletionResult.Empty;
|
||||
|
||||
return CompletionResult.FromOptions(new[]
|
||||
{
|
||||
"aabbs",
|
||||
"com",
|
||||
"contactnormals",
|
||||
"contactpoints",
|
||||
"joints",
|
||||
"shapeinfo",
|
||||
"shapes",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Robust.Client.Console.Commands
|
||||
// MsgStringTableEntries is registered as NetMessageAccept.Client so the server will immediately deny it.
|
||||
// And kick us.
|
||||
var net = IoCManager.Resolve<IClientNetManager>();
|
||||
var msg = net.CreateNetMessage<MsgStringTableEntries>();
|
||||
var msg = new MsgStringTableEntries();
|
||||
msg.Entries = new MsgStringTableEntries.Entry[0];
|
||||
net.ClientSendMessage(msg);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -15,5 +18,7 @@ namespace Robust.Client.Console
|
||||
event EventHandler<AddFormattedMessageArgs> AddFormatted;
|
||||
|
||||
void AddFormattedLine(FormattedMessage message);
|
||||
|
||||
Task<CompletionResult> GetCompletions(List<string> args, CancellationToken cancel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Robust.Client.Console
|
||||
|
||||
RunButton.Disabled = true;
|
||||
|
||||
var msg = _client._netManager.CreateNetMessage<MsgScriptEval>();
|
||||
var msg = new MsgScriptEval();
|
||||
msg.ScriptSession = _session;
|
||||
msg.Code = _lastEnteredText = InputBar.Text;
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Robust.Client.Console
|
||||
|
||||
protected override void Complete()
|
||||
{
|
||||
var msg = _client._netManager.CreateNetMessage<MsgScriptCompletion>();
|
||||
var msg = new MsgScriptCompletion();
|
||||
msg.ScriptSession = _session;
|
||||
msg.Code = InputBar.Text;
|
||||
msg.Cursor = InputBar.CursorPosition;
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Robust.Client.Console
|
||||
throw new InvalidOperationException("We do not have scripting permission.");
|
||||
}
|
||||
|
||||
var msg = _netManager.CreateNetMessage<MsgScriptStart>();
|
||||
var msg = new MsgScriptStart();
|
||||
msg.ScriptSession = _nextSessionId++;
|
||||
_netManager.ClientSendMessage(msg);
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace Robust.Client.Console
|
||||
{
|
||||
_activeConsoles.Remove(session);
|
||||
|
||||
var msg = _netManager.CreateNetMessage<MsgScriptStop>();
|
||||
var msg = new MsgScriptStop();
|
||||
msg.ScriptSession = session;
|
||||
_netManager.ClientSendMessage(msg);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
@@ -88,6 +89,7 @@ namespace Robust.Client.Debugging
|
||||
EntityManager,
|
||||
IoCManager.Resolve<IEyeManager>(),
|
||||
IoCManager.Resolve<IInputManager>(),
|
||||
IoCManager.Resolve<IMapManager>(),
|
||||
IoCManager.Resolve<IResourceCache>(),
|
||||
this,
|
||||
Get<SharedPhysicsSystem>()));
|
||||
@@ -151,10 +153,12 @@ namespace Robust.Client.Debugging
|
||||
/// Shows the world point for each contact in the viewport.
|
||||
/// </summary>
|
||||
ContactPoints = 1 << 0,
|
||||
|
||||
/// <summary>
|
||||
/// Shows the world normal for each contact in the viewport.
|
||||
/// </summary>
|
||||
ContactNormals = 1 << 1,
|
||||
|
||||
/// <summary>
|
||||
/// Shows all physics shapes in the viewport.
|
||||
/// </summary>
|
||||
@@ -162,6 +166,10 @@ namespace Robust.Client.Debugging
|
||||
ShapeInfo = 1 << 3,
|
||||
Joints = 1 << 4,
|
||||
AABBs = 1 << 5,
|
||||
|
||||
/// <summary>
|
||||
/// Shows Center of Mass for all bodies in the viewport.
|
||||
/// </summary>
|
||||
COM = 1 << 6,
|
||||
}
|
||||
|
||||
@@ -170,6 +178,7 @@ namespace Robust.Client.Debugging
|
||||
private IEntityManager _entityManager = default!;
|
||||
private IEyeManager _eyeManager = default!;
|
||||
private IInputManager _inputManager = default!;
|
||||
private IMapManager _mapManager = default!;
|
||||
private DebugPhysicsSystem _debugPhysicsSystem = default!;
|
||||
private SharedPhysicsSystem _physicsSystem = default!;
|
||||
|
||||
@@ -181,11 +190,12 @@ namespace Robust.Client.Debugging
|
||||
|
||||
private HashSet<Joint> _drawnJoints = new();
|
||||
|
||||
public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IResourceCache cache, DebugPhysicsSystem system, SharedPhysicsSystem physicsSystem)
|
||||
public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IMapManager mapManager, IResourceCache cache, DebugPhysicsSystem system, SharedPhysicsSystem physicsSystem)
|
||||
{
|
||||
_entityManager = entityManager;
|
||||
_eyeManager = eyeManager;
|
||||
_inputManager = inputManager;
|
||||
_mapManager = mapManager;
|
||||
_debugPhysicsSystem = system;
|
||||
_physicsSystem = physicsSystem;
|
||||
_font = new VectorFont(cache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
|
||||
@@ -240,26 +250,21 @@ namespace Robust.Client.Debugging
|
||||
|
||||
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.COM) != 0)
|
||||
{
|
||||
const float Alpha = 0.25f;
|
||||
|
||||
foreach (var physBody in _physicsSystem.GetCollidingEntities(mapId, viewBounds))
|
||||
{
|
||||
Color color;
|
||||
const float Alpha = 0.25f;
|
||||
float size;
|
||||
|
||||
if (_entityManager.HasComponent<MapGridComponent>(physBody.Owner))
|
||||
{
|
||||
color = Color.Orange.WithAlpha(Alpha);
|
||||
size = 1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = Color.Purple.WithAlpha(Alpha);
|
||||
size = 0.2f;
|
||||
}
|
||||
|
||||
var color = Color.Purple.WithAlpha(Alpha);
|
||||
var transform = physBody.GetTransform();
|
||||
worldHandle.DrawCircle(Transform.Mul(transform, physBody.LocalCenter), 0.2f, color);
|
||||
}
|
||||
|
||||
worldHandle.DrawCircle(Transform.Mul(transform, physBody.LocalCenter), size, color);
|
||||
foreach (var grid in _mapManager.FindGridsIntersecting(mapId, viewBounds))
|
||||
{
|
||||
var physBody = _entityManager.GetComponent<PhysicsComponent>(grid.GridEntityId);
|
||||
var color = Color.Orange.WithAlpha(Alpha);
|
||||
var transform = physBody.GetTransform();
|
||||
worldHandle.DrawCircle(Transform.Mul(transform, physBody.LocalCenter), 1f, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Debugging;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -12,7 +13,7 @@ using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Client.Debugging
|
||||
{
|
||||
internal sealed class DebugRayDrawingSystem : EntitySystem
|
||||
internal sealed class DebugRayDrawingSystem : SharedDebugRayDrawingSystem
|
||||
{
|
||||
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTimer = default!;
|
||||
@@ -57,11 +58,9 @@ namespace Robust.Client.Debugging
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeNetworkEvent<MsgRay>(HandleDrawRay);
|
||||
// To catch anything that's client-only and not sent by the server.
|
||||
SubscribeLocalEvent<DebugDrawRayMessage>(OnDebugDrawRay);
|
||||
}
|
||||
|
||||
private void OnDebugDrawRay(DebugDrawRayMessage ev)
|
||||
protected override void ReceiveLocalRayAtMainThread(DebugRayData ev)
|
||||
{
|
||||
if (!_debugDrawRays)
|
||||
{
|
||||
@@ -70,9 +69,9 @@ namespace Robust.Client.Debugging
|
||||
|
||||
var newRayWithLifetime = new RayWithLifetime
|
||||
{
|
||||
DidActuallyHit = ev.Data.Results != null,
|
||||
RayOrigin = ev.Data.Ray.Position,
|
||||
RayHit = ev.Data.Results?.HitPos ?? ev.Data.Ray.Direction * ev.Data.MaxLength + ev.Data.Ray.Position,
|
||||
DidActuallyHit = ev.Results != null,
|
||||
RayOrigin = ev.Ray.Position,
|
||||
RayHit = ev.Results?.HitPos ?? ev.Ray.Direction * ev.MaxLength + ev.Ray.Position,
|
||||
LifeTime = _gameTimer.RealTime + DebugRayLifetime
|
||||
};
|
||||
|
||||
|
||||
67
Robust.Client/GameController/GameController.Redialler.cs
Normal file
67
Robust.Client/GameController/GameController.Redialler.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Robust.LoaderApi;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client;
|
||||
|
||||
internal partial class GameController
|
||||
{
|
||||
// A little paranoia goes a long way.
|
||||
// This is static on purpose - the whole process shouldn't redial more than once, ever.
|
||||
private static int _hasRedialled = 0;
|
||||
|
||||
public void Redial(string address, string? text = null)
|
||||
{
|
||||
// -- ATTENTION, YE WOULD-BE TRESPASSERS! --
|
||||
// This code is the least testable code ever (because it's in-engine code that requires the Launcher), so don't make it do too much.
|
||||
// This checks for some obvious requirements and then forwards to RedialApi which does the actual work.
|
||||
// Testing of RedialApi is doable in the SS14.Launcher project, this is why it has a fake RobustToolbox build.
|
||||
// -- THANK YE, NOW KINDLY MOVE ALONG! --
|
||||
|
||||
// We don't ever want to successfully redial more than once, and we want to shutdown once we've redialled.
|
||||
// Otherwise abuse could happen.
|
||||
DebugTools.AssertNotNull(_mainLoop);
|
||||
|
||||
Logger.Info($"Attempting redial of {address}: {text ?? "no reason given"}");
|
||||
|
||||
if (!_mainLoop!.Running)
|
||||
{
|
||||
throw new Exception("Attempted a redial during shutdown, this is not acceptable - redial first and if you succeed it'll shutdown anyway.");
|
||||
}
|
||||
|
||||
if (_loaderArgs == null)
|
||||
{
|
||||
throw new Exception("Attempted a redial when the game was not run from the launcher (_loaderArgs == null)");
|
||||
}
|
||||
|
||||
if (_loaderArgs!.RedialApi == null)
|
||||
{
|
||||
throw new Exception("Attempted a redial when redialling was not supported by the loader (Outdated launcher?)");
|
||||
}
|
||||
|
||||
if (Interlocked.Increment(ref _hasRedialled) != 1)
|
||||
{
|
||||
// Don't let it overflow or anything
|
||||
Interlocked.Decrement(ref _hasRedialled);
|
||||
throw new Exception("Attempted a redial after one already succeeded or while one is in progress, this is never acceptable");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_loaderArgs!.RedialApi!.Redial(new Uri(address), text ?? "");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Interlocked.Decrement(ref _hasRedialled);
|
||||
throw;
|
||||
}
|
||||
|
||||
Shutdown("Redial");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace Robust.Client
|
||||
throw new InvalidOperationException("Cannot start twice!");
|
||||
}
|
||||
|
||||
GlibcBug.Check();
|
||||
|
||||
_hasStarted = true;
|
||||
|
||||
if (CommandLineArgs.TryParse(args, out var parsed))
|
||||
@@ -101,7 +103,7 @@ namespace Robust.Client
|
||||
ContinueStartupAndLoop(mode);
|
||||
}
|
||||
|
||||
Cleanup();
|
||||
CleanupWindowThread();
|
||||
|
||||
Logger.Debug("Goodbye");
|
||||
IoCManager.Clear();
|
||||
@@ -127,6 +129,8 @@ namespace Robust.Client
|
||||
|
||||
DebugTools.AssertNotNull(_mainLoop);
|
||||
_mainLoop!.Run();
|
||||
|
||||
CleanupGameThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,16 @@ using Robust.Shared;
|
||||
using Robust.Shared.Asynchronous;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Exceptions;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Profiling;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Threading;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
@@ -66,6 +68,9 @@ namespace Robust.Client
|
||||
[Dependency] private readonly IAuthManager _authManager = default!;
|
||||
[Dependency] private readonly IMidiManager _midiManager = default!;
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IParallelManagerInternal _parallelMgr = default!;
|
||||
[Dependency] private readonly ProfManager _prof = default!;
|
||||
[Dependency] private readonly IRuntimeLog _runtimeLog = default!;
|
||||
|
||||
private IWebViewManagerHook? _webViewHook;
|
||||
|
||||
@@ -91,7 +96,8 @@ namespace Robust.Client
|
||||
|
||||
_clyde.InitializePostWindowing();
|
||||
_clydeAudio.InitializePostWindowing();
|
||||
_clyde.SetWindowTitle(Options.DefaultWindowTitle ?? _resourceManifest!.DefaultWindowTitle ?? "RobustToolbox");
|
||||
_clyde.SetWindowTitle(
|
||||
Options.DefaultWindowTitle ?? _resourceManifest!.DefaultWindowTitle ?? "RobustToolbox");
|
||||
|
||||
_taskManager.Initialize();
|
||||
_fontManager.SetFontDpi((uint)_configurationManager.GetCVar(CVars.DisplayFontDpi));
|
||||
@@ -102,7 +108,8 @@ namespace Robust.Client
|
||||
// Disable load context usage on content start.
|
||||
// This prevents Content.Client being loaded twice and things like csi blowing up because of it.
|
||||
_modLoader.SetUseLoadContext(!ContentStart);
|
||||
_modLoader.SetEnableSandboxing(Options.Sandboxing);
|
||||
var disableSandbox = Environment.GetEnvironmentVariable("ROBUST_DISABLE_SANDBOX") == "1";
|
||||
_modLoader.SetEnableSandboxing(!disableSandbox && Options.Sandboxing);
|
||||
|
||||
var assemblyPrefix = Options.ContentModulePrefix ?? _resourceManifest!.AssemblyPrefix ?? "Content.";
|
||||
if (!_modLoader.TryLoadModulesFrom(Options.AssemblyDirectory, assemblyPrefix))
|
||||
@@ -131,8 +138,9 @@ namespace Robust.Client
|
||||
_inputManager.Initialize();
|
||||
_console.Initialize();
|
||||
_prototypeManager.Initialize();
|
||||
_prototypeManager.LoadDirectory(new ResourcePath("/EnginePrototypes/"));
|
||||
_prototypeManager.LoadDirectory(Options.PrototypeDirectory);
|
||||
_prototypeManager.Resync();
|
||||
_prototypeManager.ResolveResults();
|
||||
_entityManager.Initialize();
|
||||
_mapManager.Initialize();
|
||||
_gameStateManager.Initialize();
|
||||
@@ -157,7 +165,7 @@ namespace Robust.Client
|
||||
// Setup main loop
|
||||
if (_mainLoop == null)
|
||||
{
|
||||
_mainLoop = new GameLoop(_gameTiming)
|
||||
_mainLoop = new GameLoop(_gameTiming, _runtimeLog, _prof)
|
||||
{
|
||||
SleepMode = displayMode == DisplayMode.Headless ? SleepMode.Delay : SleepMode.None
|
||||
};
|
||||
@@ -197,7 +205,7 @@ namespace Robust.Client
|
||||
|
||||
_clyde.Ready();
|
||||
|
||||
if (!Options.DisableCommandLineConnect &&
|
||||
if (_resourceManifest!.AutoConnect &&
|
||||
(_commandLineArgs?.Connect == true || _commandLineArgs?.Launcher == true)
|
||||
&& LaunchState.ConnectEndpoint != null)
|
||||
{
|
||||
@@ -213,7 +221,7 @@ namespace Robust.Client
|
||||
{
|
||||
// Parses /manifest.yml for game-specific settings that cannot be exclusively set up by content code.
|
||||
if (!_resourceCache.TryContentFileRead("/manifest.yml", out var stream))
|
||||
return new ResourceManifestData(Array.Empty<string>(), null, null, null, null);
|
||||
return new ResourceManifestData(Array.Empty<string>(), null, null, null, null, true);
|
||||
|
||||
var yamlStream = new YamlStream();
|
||||
using (stream)
|
||||
@@ -223,7 +231,7 @@ namespace Robust.Client
|
||||
}
|
||||
|
||||
if (yamlStream.Documents.Count == 0)
|
||||
return new ResourceManifestData(Array.Empty<string>(), null, null, null, null);
|
||||
return new ResourceManifestData(Array.Empty<string>(), null, null, null, null, true);
|
||||
|
||||
if (yamlStream.Documents.Count != 1 || yamlStream.Documents[0].RootNode is not YamlMappingNode mapping)
|
||||
{
|
||||
@@ -258,7 +266,11 @@ namespace Robust.Client
|
||||
if (mapping.TryGetNode("splashLogo", out var splashNode))
|
||||
splashLogo = splashNode.AsString();
|
||||
|
||||
return new ResourceManifestData(modules, assemblyPrefix, defaultWindowTitle, windowIconSet, splashLogo);
|
||||
bool autoConnect = true;
|
||||
if (mapping.TryGetNode("autoConnect", out var autoConnectNode))
|
||||
autoConnect = autoConnectNode.AsBool();
|
||||
|
||||
return new ResourceManifestData(modules, assemblyPrefix, defaultWindowTitle, windowIconSet, splashLogo, autoConnect);
|
||||
}
|
||||
|
||||
internal bool StartupSystemSplash(GameControllerOptions options, Func<ILogHandler>? logHandlerFactory)
|
||||
@@ -326,6 +338,12 @@ namespace Robust.Client
|
||||
|
||||
ProfileOptSetup.Setup(_configurationManager);
|
||||
|
||||
_parallelMgr.Initialize();
|
||||
_prof.Initialize();
|
||||
#if !FULL_RELEASE
|
||||
_configurationManager.OverrideDefault(CVars.ProfEnabled, true);
|
||||
#endif
|
||||
|
||||
_resourceCache.Initialize(Options.LoadConfigAndUserData ? userDataDir : null);
|
||||
|
||||
var mountOptions = _commandLineArgs != null
|
||||
@@ -446,52 +464,127 @@ namespace Robust.Client
|
||||
|
||||
private void Input(FrameEventArgs frameEventArgs)
|
||||
{
|
||||
_clyde.ProcessInput(frameEventArgs);
|
||||
_networkManager.ProcessPackets();
|
||||
_taskManager.ProcessPendingTasks(); // tasks like connect
|
||||
using (_prof.Group("Input Events"))
|
||||
{
|
||||
_clyde.ProcessInput(frameEventArgs);
|
||||
}
|
||||
|
||||
using (_prof.Group("Network"))
|
||||
{
|
||||
_networkManager.ProcessPackets();
|
||||
}
|
||||
|
||||
using (_prof.Group("Async"))
|
||||
{
|
||||
_taskManager.ProcessPendingTasks(); // tasks like connect
|
||||
}
|
||||
}
|
||||
|
||||
private void Tick(FrameEventArgs frameEventArgs)
|
||||
{
|
||||
_modLoader.BroadcastUpdate(ModUpdateLevel.PreEngine, frameEventArgs);
|
||||
_console.CommandBufferExecute();
|
||||
_timerManager.UpdateTimers(frameEventArgs);
|
||||
_taskManager.ProcessPendingTasks();
|
||||
using (_prof.Group("Content pre engine"))
|
||||
{
|
||||
_modLoader.BroadcastUpdate(ModUpdateLevel.PreEngine, frameEventArgs);
|
||||
}
|
||||
|
||||
using (_prof.Group("Console"))
|
||||
{
|
||||
_console.CommandBufferExecute();
|
||||
}
|
||||
|
||||
using (_prof.Group("Timers"))
|
||||
{
|
||||
_timerManager.UpdateTimers(frameEventArgs);
|
||||
}
|
||||
|
||||
using (_prof.Group("Async"))
|
||||
{
|
||||
_taskManager.ProcessPendingTasks();
|
||||
}
|
||||
|
||||
// GameStateManager is in full control of the simulation update in multiplayer.
|
||||
if (_client.RunLevel == ClientRunLevel.InGame || _client.RunLevel == ClientRunLevel.Connected)
|
||||
{
|
||||
_gameStateManager.ApplyGameState();
|
||||
using (_prof.Group("Game state"))
|
||||
{
|
||||
_gameStateManager.ApplyGameState();
|
||||
}
|
||||
}
|
||||
|
||||
// In singleplayer, however, we're in full control instead.
|
||||
else if (_client.RunLevel == ClientRunLevel.SinglePlayerGame)
|
||||
{
|
||||
// The last real tick is the current tick! This way we won't be in "prediction" mode.
|
||||
_gameTiming.LastRealTick = _gameTiming.CurTick;
|
||||
_entityManager.TickUpdate(frameEventArgs.DeltaSeconds, noPredictions: false);
|
||||
using (_prof.Group("Entity"))
|
||||
{
|
||||
// The last real tick is the current tick! This way we won't be in "prediction" mode.
|
||||
_gameTiming.LastRealTick = _gameTiming.CurTick;
|
||||
_entityManager.TickUpdate(frameEventArgs.DeltaSeconds, noPredictions: false);
|
||||
}
|
||||
}
|
||||
|
||||
_modLoader.BroadcastUpdate(ModUpdateLevel.PostEngine, frameEventArgs);
|
||||
using (_prof.Group("Content post engine"))
|
||||
{
|
||||
_modLoader.BroadcastUpdate(ModUpdateLevel.PostEngine, frameEventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update(FrameEventArgs frameEventArgs)
|
||||
{
|
||||
_webViewHook?.Update();
|
||||
_clydeAudio.FrameProcess(frameEventArgs);
|
||||
_clyde.FrameProcess(frameEventArgs);
|
||||
_modLoader.BroadcastUpdate(ModUpdateLevel.FramePreEngine, frameEventArgs);
|
||||
_stateManager.FrameUpdate(frameEventArgs);
|
||||
if (_webViewHook != null)
|
||||
{
|
||||
using (_prof.Group("WebView"))
|
||||
{
|
||||
_webViewHook?.Update();
|
||||
}
|
||||
}
|
||||
|
||||
using (_prof.Group("ClydeAudio"))
|
||||
{
|
||||
_clydeAudio.FrameProcess(frameEventArgs);
|
||||
}
|
||||
|
||||
using (_prof.Group("Clyde"))
|
||||
{
|
||||
_clyde.FrameProcess(frameEventArgs);
|
||||
}
|
||||
|
||||
using (_prof.Group("Content Pre Engine"))
|
||||
{
|
||||
_modLoader.BroadcastUpdate(ModUpdateLevel.FramePreEngine, frameEventArgs);
|
||||
}
|
||||
|
||||
using (_prof.Group("State"))
|
||||
{
|
||||
_stateManager.FrameUpdate(frameEventArgs);
|
||||
}
|
||||
|
||||
if (_client.RunLevel >= ClientRunLevel.Connected)
|
||||
{
|
||||
_placementManager.FrameUpdate(frameEventArgs);
|
||||
_entityManager.FrameUpdate(frameEventArgs.DeltaSeconds);
|
||||
using (_prof.Group("Placement"))
|
||||
{
|
||||
_placementManager.FrameUpdate(frameEventArgs);
|
||||
}
|
||||
|
||||
using (_prof.Group("Entity"))
|
||||
{
|
||||
_entityManager.FrameUpdate(frameEventArgs.DeltaSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
_overlayManager.FrameUpdate(frameEventArgs);
|
||||
_userInterfaceManager.FrameUpdate(frameEventArgs);
|
||||
_modLoader.BroadcastUpdate(ModUpdateLevel.FramePostEngine, frameEventArgs);
|
||||
using (_prof.Group("Overlay"))
|
||||
{
|
||||
_overlayManager.FrameUpdate(frameEventArgs);
|
||||
}
|
||||
|
||||
using (_prof.Group("UI"))
|
||||
{
|
||||
_userInterfaceManager.FrameUpdate(frameEventArgs);
|
||||
}
|
||||
|
||||
using (_prof.Group("Content Post Engine"))
|
||||
{
|
||||
_modLoader.BroadcastUpdate(ModUpdateLevel.FramePostEngine, frameEventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SetupLogging(ILogManager logManager, Func<ILogHandler> logHandlerFactory)
|
||||
@@ -566,15 +659,20 @@ namespace Robust.Client
|
||||
Clyde,
|
||||
}
|
||||
|
||||
internal void Cleanup()
|
||||
internal void CleanupGameThread()
|
||||
{
|
||||
_modLoader.Shutdown();
|
||||
|
||||
// CEF specifically makes a massive silent stink of it if we don't shut it down from the correct thread.
|
||||
_webViewHook?.Shutdown();
|
||||
|
||||
_networkManager.Shutdown("Client shutting down");
|
||||
_midiManager.Shutdown();
|
||||
_entityManager.Shutdown();
|
||||
}
|
||||
|
||||
internal void CleanupWindowThread()
|
||||
{
|
||||
_clyde.Shutdown();
|
||||
_clydeAudio.Shutdown();
|
||||
}
|
||||
@@ -584,7 +682,8 @@ namespace Robust.Client
|
||||
string? AssemblyPrefix,
|
||||
string? DefaultWindowTitle,
|
||||
string? WindowIconSet,
|
||||
string? SplashLogo
|
||||
string? SplashLogo,
|
||||
bool AutoConnect
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,10 +82,5 @@ namespace Robust.Client
|
||||
/// Whether to load config and user data.
|
||||
/// </summary>
|
||||
public bool LoadConfigAndUserData { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to disable command line args server auto-connecting.
|
||||
/// </summary>
|
||||
public bool DisableCommandLineConnect { get; init; } = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -8,8 +7,8 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
internal sealed class ClientComponentFactory : ComponentFactory
|
||||
{
|
||||
public ClientComponentFactory(IDynamicTypeFactoryInternal typeFactory, IReflectionManager reflectionManager, IConsoleHost conHost)
|
||||
: base(typeFactory, reflectionManager, conHost)
|
||||
public ClientComponentFactory(IDynamicTypeFactoryInternal typeFactory, IReflectionManager reflectionManager)
|
||||
: base(typeFactory, reflectionManager)
|
||||
{
|
||||
// Required for the engine to work
|
||||
RegisterIgnore("KeyBindingInput");
|
||||
|
||||
@@ -27,7 +27,6 @@ namespace Robust.Client.GameObjects
|
||||
public override void Initialize()
|
||||
{
|
||||
SetupNetworking();
|
||||
ReceivedComponentMessage += (_, compMsg) => DispatchComponentMessage(compMsg);
|
||||
ReceivedSystemMessage += (_, systemMsg) => EventBus.RaiseEvent(EventSource.Network, systemMsg);
|
||||
|
||||
base.Initialize();
|
||||
@@ -38,9 +37,9 @@ namespace Robust.Client.GameObjects
|
||||
return base.CreateEntity(prototypeName, uid);
|
||||
}
|
||||
|
||||
void IClientEntityManagerInternal.InitializeEntity(EntityUid entity)
|
||||
void IClientEntityManagerInternal.InitializeEntity(EntityUid entity, MetaDataComponent? meta)
|
||||
{
|
||||
base.InitializeEntity(entity);
|
||||
base.InitializeEntity(entity, meta);
|
||||
}
|
||||
|
||||
void IClientEntityManagerInternal.StartEntity(EntityUid entity)
|
||||
@@ -52,9 +51,6 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
public override IEntityNetworkManager EntityNetManager => this;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<NetworkComponentMessage>? ReceivedComponentMessage;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<object>? ReceivedSystemMessage;
|
||||
|
||||
@@ -90,7 +86,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
public void SendSystemNetworkMessage(EntityEventArgs message, uint sequence)
|
||||
{
|
||||
var msg = _networkManager.CreateNetMessage<MsgEntity>();
|
||||
var msg = new MsgEntity();
|
||||
msg.Type = EntityMessageType.SystemMessage;
|
||||
msg.SystemMessage = message;
|
||||
msg.SourceTick = _gameTiming.CurTick;
|
||||
@@ -105,26 +101,6 @@ namespace Robust.Client.GameObjects
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
|
||||
public void SendComponentNetworkMessage(INetChannel? channel, EntityUid entity, IComponent component, ComponentMessage message)
|
||||
{
|
||||
var componentType = component.GetType();
|
||||
var netId = ComponentFactory.GetRegistration(componentType).NetID;
|
||||
|
||||
if (!netId.HasValue)
|
||||
throw new ArgumentException($"Component {componentType} does not have a NetID.", nameof(component));
|
||||
|
||||
var msg = _networkManager.CreateNetMessage<MsgEntity>();
|
||||
msg.Type = EntityMessageType.ComponentMessage;
|
||||
msg.EntityUid = entity;
|
||||
msg.NetId = netId.Value;
|
||||
msg.ComponentMessage = message;
|
||||
msg.SourceTick = _gameTiming.CurTick;
|
||||
|
||||
_networkManager.ClientSendMessage(msg);
|
||||
}
|
||||
|
||||
private void HandleEntityNetworkMessage(MsgEntity message)
|
||||
{
|
||||
if (message.SourceTick <= _gameStateManager.CurServerTick)
|
||||
@@ -143,10 +119,6 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
switch (message.Type)
|
||||
{
|
||||
case EntityMessageType.ComponentMessage:
|
||||
ReceivedComponentMessage?.Invoke(this, new NetworkComponentMessage(message));
|
||||
return;
|
||||
|
||||
case EntityMessageType.SystemMessage:
|
||||
var msg = message.SystemMessage;
|
||||
var sessionType = typeof(EntitySessionMessage<>).MakeGenericType(msg.GetType());
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Robust.Client.GameObjects;
|
||||
/// This is the client instance of <see cref="AppearanceComponent"/>.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(AppearanceComponent)), Friend(typeof(AppearanceSystem))]
|
||||
[ComponentReference(typeof(AppearanceComponent)), Access(typeof(AppearanceSystem))]
|
||||
public sealed class ClientAppearanceComponent : AppearanceComponent
|
||||
{
|
||||
[ViewVariables]
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static Robust.Shared.GameObjects.SharedSpriteComponent;
|
||||
|
||||
namespace Robust.Client.GameObjects;
|
||||
|
||||
/// <summary>
|
||||
/// This component can be used to apply generic changes to an entity's sprite component as a result of appearance
|
||||
/// data changes.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(GenericVisualizerSystem))]
|
||||
public sealed class GenericVisualizerComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// This is a nested dictionary that maps appearance data keys -> sprite layer keys -> appearance data values -> layer data.
|
||||
/// While somewhat convoluted, this enables the sprite layer data to be completely modified using only yaml.
|
||||
///
|
||||
/// In most instances, each of these dictionaries will probably only have a single entry.
|
||||
/// </summary>
|
||||
[DataField("visuals", required:true)]
|
||||
public Dictionary<Enum, Dictionary<string, Dictionary<string, PrototypeLayerData>>> Visuals = default!;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.Utility;
|
||||
@@ -32,11 +33,13 @@ namespace Robust.Client.GameObjects
|
||||
public const string LogCategory = "go.comp.icon";
|
||||
const string SerializationCache = "icon";
|
||||
|
||||
[Obsolete("Use SpriteSystem instead.")]
|
||||
private static IRsiStateLike TextureForConfig(IconComponent compData, IResourceCache resourceCache)
|
||||
{
|
||||
return compData.Icon?.Default ?? resourceCache.GetFallback<TextureResource>().Texture;
|
||||
}
|
||||
|
||||
[Obsolete("Use SpriteSystem instead.")]
|
||||
public static IRsiStateLike? GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
|
||||
{
|
||||
if (!prototype.Components.TryGetValue("Icon", out var compData))
|
||||
@@ -44,7 +47,7 @@ namespace Robust.Client.GameObjects
|
||||
return null;
|
||||
}
|
||||
|
||||
return TextureForConfig((IconComponent)compData, resourceCache);
|
||||
return TextureForConfig((IconComponent)compData.Component, resourceCache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Robust.Client.GameObjects
|
||||
Component = xform,
|
||||
};
|
||||
|
||||
_entityManager.EventBus.RaiseLocalEvent(Owner, ref ev);
|
||||
_entityManager.EventBus.RaiseLocalEvent(Owner, ref ev, true);
|
||||
|
||||
if (ev.Handled)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedPointLightComponent))]
|
||||
public sealed class PointLightComponent : SharedPointLightComponent, ISerializationHooks
|
||||
public sealed class PointLightComponent : SharedPointLightComponent
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
if (_enabled == value) return;
|
||||
base.Enabled = value;
|
||||
_entityManager.EventBus.RaiseLocalEvent(Owner, new PointLightUpdateEvent());
|
||||
_entityManager.EventBus.RaiseLocalEvent(Owner, new PointLightUpdateEvent(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Robust.Client.GameObjects
|
||||
if (_containerOccluded == value) return;
|
||||
|
||||
_containerOccluded = value;
|
||||
_entityManager.EventBus.RaiseLocalEvent(Owner, new PointLightUpdateEvent());
|
||||
_entityManager.EventBus.RaiseLocalEvent(Owner, new PointLightUpdateEvent(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace Robust.Client.GameObjects
|
||||
[Animatable]
|
||||
Vector2 Scale { get; set; }
|
||||
|
||||
Box2 Bounds { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A rotation applied to all layers.
|
||||
/// </summary>
|
||||
|
||||
@@ -35,6 +35,6 @@ namespace Robust.Client.GameObjects
|
||||
/// Calculate layer bounding box in sprite local-space coordinates.
|
||||
/// </summary>
|
||||
/// <returns>Bounding box in sprite local-space coordinates.</returns>
|
||||
Box2 CalculateBoundingBox(Angle worldAngle);
|
||||
Box2 CalculateBoundingBox();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,16 +75,16 @@ namespace Robust.Client.GameObjects
|
||||
protected internal override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
var handle = args.WorldHandle;
|
||||
var currentMap = _eyeManager.CurrentMap;
|
||||
var viewport = _eyeManager.GetWorldViewbounds();
|
||||
var currentMap = args.MapId;
|
||||
var viewport = args.WorldBounds;
|
||||
|
||||
foreach (var comp in _renderTree.GetRenderTrees(currentMap, viewport))
|
||||
{
|
||||
var localAABB = _entityManager.GetComponent<TransformComponent>(comp.Owner).InvWorldMatrix.TransformBox(viewport);
|
||||
|
||||
foreach (var sprite in comp.SpriteTree.QueryAabb(localAABB))
|
||||
foreach (var (sprite, xform) in comp.SpriteTree.QueryAabb(localAABB))
|
||||
{
|
||||
var (worldPos, worldRot) = _entityManager.GetComponent<TransformComponent>(sprite.Owner).GetWorldPositionRotation();
|
||||
var (worldPos, worldRot) = xform.GetWorldPositionRotation();
|
||||
var bounds = sprite.CalculateRotatedBoundingBox(worldPos, worldRot);
|
||||
|
||||
// Get scaled down bounds used to indicate the "south" of a sprite.
|
||||
|
||||
@@ -19,6 +19,7 @@ using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using TerraFX.Interop.Windows;
|
||||
using DrawDepthTag = Robust.Shared.GameObjects.DrawDepth;
|
||||
using RSIDirection = Robust.Client.Graphics.RSI.State.Direction;
|
||||
|
||||
@@ -47,7 +48,7 @@ namespace Robust.Client.GameObjects
|
||||
if (_visible == value) return;
|
||||
_visible = value;
|
||||
|
||||
entities.EventBus.RaiseLocalEvent(Owner, new SpriteUpdateEvent());
|
||||
entities.EventBus.RaiseLocalEvent(Owner, new SpriteUpdateEvent(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,11 +169,12 @@ namespace Robust.Client.GameObjects
|
||||
get => _baseRsi;
|
||||
set
|
||||
{
|
||||
if (value == _baseRsi)
|
||||
return;
|
||||
|
||||
_baseRsi = value;
|
||||
if (value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < Layers.Count; i++)
|
||||
{
|
||||
@@ -182,6 +184,8 @@ namespace Robust.Client.GameObjects
|
||||
continue;
|
||||
}
|
||||
|
||||
layer.UpdateActualState();
|
||||
|
||||
if (value.TryGetState(layer.State, out var state))
|
||||
{
|
||||
layer.AnimationTimeLeft = state.GetDelay(0);
|
||||
@@ -203,45 +207,73 @@ namespace Robust.Client.GameObjects
|
||||
[DataField("state", readOnly: true)] private string? state;
|
||||
[DataField("texture", readOnly: true)] private string? texture;
|
||||
|
||||
/// <summary>
|
||||
/// Should this entity show up in containers regardless of whether the container can show contents?
|
||||
/// </summary>
|
||||
[DataField("overrideContainerOcclusion")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool OverrideContainerOcclusion;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool ContainerOccluded
|
||||
{
|
||||
get => _containerOccluded;
|
||||
get => _containerOccluded && !OverrideContainerOcclusion;
|
||||
set
|
||||
{
|
||||
if (_containerOccluded == value) return;
|
||||
_containerOccluded = value;
|
||||
entities.EventBus.RaiseLocalEvent(Owner, new SpriteUpdateEvent());
|
||||
entities.EventBus.RaiseLocalEvent(Owner, new SpriteUpdateEvent(), true);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _containerOccluded;
|
||||
|
||||
private Box2 _bounds;
|
||||
|
||||
public Box2 Bounds => _bounds;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool TreeUpdateQueued { get; set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] private bool _inertUpdateQueued;
|
||||
|
||||
/// <summary>
|
||||
/// Shader instance to use when drawing the final sprite to the world.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public ShaderInstance? PostShader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not to pass the screen texture to the <see cref="PostShader"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Should be false unless you really need it.
|
||||
/// </remarks>
|
||||
[DataField("getScreenTexture")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private bool _getScreenTexture = false;
|
||||
public bool GetScreenTexture
|
||||
{
|
||||
get => _getScreenTexture && PostShader != null;
|
||||
set => _getScreenTexture = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If true, this raise a entity system event before rendering this sprite, allowing systems to modify the
|
||||
/// shader parameters. Usually this can just be done via a frame-update, but some shaders require
|
||||
/// information about the viewport / eye.
|
||||
/// </summary>
|
||||
[DataField("raiseShaderEvent")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool RaiseShaderEvent = false;
|
||||
|
||||
[ViewVariables] private Dictionary<object, int> LayerMap = new();
|
||||
[ViewVariables] private bool _layerMapShared;
|
||||
[ViewVariables] private List<Layer> Layers = new();
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] public uint RenderOrder { get; set; }
|
||||
|
||||
// TODO: this should absolutely not be static.
|
||||
private static ShaderInstance? _defaultShader;
|
||||
|
||||
[ViewVariables]
|
||||
private ShaderInstance? DefaultShader => _defaultShader ??= prototypes
|
||||
.Index<ShaderPrototype>("shaded")
|
||||
.Instance();
|
||||
|
||||
public const string LogCategory = "go.comp.sprite";
|
||||
const string LayerSerializationCache = "spritelayer";
|
||||
const string LayerMapSerializationCache = "spritelayermap";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] public bool IsInert { get; private set; }
|
||||
|
||||
@@ -299,6 +331,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
//deep copying things to avoid entanglement
|
||||
_baseRsi = other._baseRsi;
|
||||
_bounds = other._bounds;
|
||||
_visible = other._visible;
|
||||
_layerMapShared = other._layerMapShared;
|
||||
color = other.color;
|
||||
@@ -398,7 +431,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
public int AddBlankLayer(int? newIndex = null)
|
||||
{
|
||||
var layer = new Layer(this) { Visible = false };
|
||||
var layer = new Layer(this);
|
||||
return AddLayer(layer, newIndex);
|
||||
}
|
||||
|
||||
@@ -548,6 +581,7 @@ namespace Robust.Client.GameObjects
|
||||
index = Layers.Count - 1;
|
||||
}
|
||||
|
||||
RebuildBounds();
|
||||
QueueUpdateIsInert();
|
||||
return index;
|
||||
}
|
||||
@@ -575,6 +609,7 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
RebuildBounds();
|
||||
QueueUpdateIsInert();
|
||||
}
|
||||
|
||||
@@ -590,6 +625,17 @@ namespace Robust.Client.GameObjects
|
||||
RemoveLayer(layer);
|
||||
}
|
||||
|
||||
private void RebuildBounds()
|
||||
{
|
||||
_bounds = new Box2();
|
||||
foreach (var layer in Layers)
|
||||
{
|
||||
if (!layer.Visible || layer.Blank) continue;
|
||||
|
||||
_bounds = _bounds.Union(layer.CalculateBoundingBox());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills in a layer's values using some <see cref="PrototypeLayerData"/>.
|
||||
/// </summary>
|
||||
@@ -604,8 +650,6 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
var layer = Layers[index];
|
||||
|
||||
var anyTextureAttempted = false;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(layerDatum.RsiPath))
|
||||
{
|
||||
var path = TextureRoot / layerDatum.RsiPath;
|
||||
@@ -622,7 +666,6 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(layerDatum.State))
|
||||
{
|
||||
anyTextureAttempted = true;
|
||||
var theRsi = layer.RSI ?? BaseRSI;
|
||||
if (theRsi == null)
|
||||
{
|
||||
@@ -638,6 +681,8 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
// Always use south because this layer will be cached in the serializer.
|
||||
layer.AnimationTimeLeft = state.GetDelay(0);
|
||||
layer.AnimationTime = 0;
|
||||
layer.AnimationFrame = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -650,7 +695,6 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(layerDatum.TexturePath))
|
||||
{
|
||||
anyTextureAttempted = true;
|
||||
if (layer.State.IsValid)
|
||||
{
|
||||
Logger.ErrorS(LogCategory,
|
||||
@@ -705,14 +749,16 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
layer.Color = layerDatum.Color;
|
||||
layer._rotation = layerDatum.Rotation;
|
||||
layer._offset = layerDatum.Offset;
|
||||
layer._scale = layerDatum.Scale;
|
||||
layer.Color = layerDatum.Color ?? layer.Color;
|
||||
layer._rotation = layerDatum.Rotation ?? layer._rotation;
|
||||
layer._offset = layerDatum.Offset ?? layer._offset;
|
||||
layer._scale = layerDatum.Scale ?? layer._scale;
|
||||
layer.UpdateLocalMatrix();
|
||||
|
||||
// If neither state: nor texture: were provided we assume that they want a blank invisible layer.
|
||||
layer.Visible = anyTextureAttempted && layerDatum.Visible;
|
||||
layer.Visible = layerDatum.Visible ?? layer.Visible;
|
||||
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetData(object layerKey, PrototypeLayerData data)
|
||||
@@ -799,6 +845,8 @@ namespace Robust.Client.GameObjects
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetSprite(object layerKey, SpriteSpecifier specifier)
|
||||
@@ -824,6 +872,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
var theLayer = Layers[layer];
|
||||
theLayer.SetTexture(texture);
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetTexture(object layerKey, Texture texture)
|
||||
@@ -889,6 +938,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
var theLayer = Layers[layer];
|
||||
theLayer.SetState(stateId);
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetState(object layerKey, RSI.StateId stateId)
|
||||
@@ -936,6 +986,8 @@ namespace Robust.Client.GameObjects
|
||||
theLayer.Texture = null;
|
||||
}
|
||||
}
|
||||
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetState(object layerKey, RSI.StateId stateId, RSI rsi)
|
||||
@@ -993,6 +1045,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
var theLayer = Layers[layer];
|
||||
theLayer.SetRsi(rsi);
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetRSI(object layerKey, RSI rsi)
|
||||
@@ -1050,6 +1103,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
var theLayer = Layers[layer];
|
||||
theLayer.Scale = scale;
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetScale(object layerKey, Vector2 scale)
|
||||
@@ -1076,6 +1130,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
var theLayer = Layers[layer];
|
||||
theLayer.Rotation = rotation;
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetRotation(object layerKey, Angle rotation)
|
||||
@@ -1125,6 +1180,8 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
var theLayer = Layers[layer];
|
||||
theLayer.Color = color;
|
||||
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetColor(object layerKey, Color color)
|
||||
@@ -1150,6 +1207,8 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
var theLayer = Layers[layer];
|
||||
theLayer.DirOffset = offset;
|
||||
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetDirOffset(object layerKey, DirectionOffset offset)
|
||||
@@ -1201,6 +1260,8 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
|
||||
Layers[layer].SetAutoAnimated(autoAnimated);
|
||||
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetAutoAnimated(object layerKey, bool autoAnimated)
|
||||
@@ -1226,6 +1287,8 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
|
||||
Layers[layer].Offset = layerOffset;
|
||||
|
||||
RebuildBounds();
|
||||
}
|
||||
|
||||
public void LayerSetOffset(object layerKey, Vector2 layerOffset)
|
||||
@@ -1319,7 +1382,7 @@ namespace Robust.Client.GameObjects
|
||||
// However, at some point later the eye-matrix is applied separately, so we subtract -eye rotation for now:
|
||||
var entityMatrix = Matrix3.CreateTransform(worldPosition, NoRotation ? -eyeRotation : worldRotation);
|
||||
|
||||
Matrix3.Multiply(ref LocalMatrix, ref entityMatrix, out var transform);
|
||||
Matrix3.Multiply(in LocalMatrix, in entityMatrix, out var transform);
|
||||
|
||||
var angle = worldRotation + eyeRotation; // angle on-screen. Used to decide the direction of 4/8 directional RSIs
|
||||
foreach (var layer in Layers)
|
||||
@@ -1366,7 +1429,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
var layer = t;
|
||||
// Since StateId is a struct, we can't null-check it directly.
|
||||
if (!layer.State.IsValid || !layer.Visible || !layer.AutoAnimated)
|
||||
if (!layer.State.IsValid || !layer.Visible || !layer.AutoAnimated || layer.Blank)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -1465,7 +1528,7 @@ namespace Robust.Client.GameObjects
|
||||
foreach (var layer in Layers)
|
||||
{
|
||||
// Since StateId is a struct, we can't null-check it directly.
|
||||
if (!layer.State.IsValid || !layer.Visible || !layer.AutoAnimated)
|
||||
if (!layer.State.IsValid || !layer.Visible || !layer.AutoAnimated || layer.Blank)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -1484,6 +1547,7 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use SpriteSystem instead.")]
|
||||
internal static RSI.State GetFallbackState(IResourceCache cache)
|
||||
{
|
||||
var rsi = cache.GetResource<RSIResource>("/Textures/error.rsi").RSI;
|
||||
@@ -1536,24 +1600,10 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
eye ??= eyeManager.CurrentEye;
|
||||
|
||||
// Need relative angle on screen for determining the sprite rsi direction.
|
||||
Angle relativeRotation = NoRotation
|
||||
? Angle.Zero
|
||||
: worldRotation + eye.Rotation;
|
||||
|
||||
// we need to calculate bounding box taking into account all nested layers
|
||||
// because layers can have offsets, scale or rotation, we need to calculate a new BB
|
||||
// based on lowest bottomLeft and highest topRight points from all layers
|
||||
var box = Layers[0].CalculateBoundingBox(relativeRotation);
|
||||
|
||||
for (int i = 1; i < Layers.Count; i++)
|
||||
{
|
||||
var layer = Layers[i];
|
||||
if (!layer.Visible) continue;
|
||||
var layerBB = layer.CalculateBoundingBox(relativeRotation);
|
||||
|
||||
box = box.Union(layerBB);
|
||||
}
|
||||
var box = Bounds;
|
||||
|
||||
// Next, what we do is take the box2 and apply the sprite's transform, and then the entity's transform. We
|
||||
// could do this via Matrix3.TransformBox, but that only yields bounding boxes. So instead we manually
|
||||
@@ -1576,7 +1626,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
internal void UpdateBounds()
|
||||
{
|
||||
entities.EventBus.RaiseLocalEvent(Owner, new SpriteUpdateEvent());
|
||||
entities.EventBus.RaiseLocalEvent(Owner, new SpriteUpdateEvent(), true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1613,12 +1663,41 @@ namespace Robust.Client.GameObjects
|
||||
[ViewVariables] public ShaderInstance? Shader;
|
||||
[ViewVariables] public Texture? Texture;
|
||||
|
||||
[ViewVariables] public RSI? RSI;
|
||||
[ViewVariables] public RSI.StateId State;
|
||||
private RSI? _rsi;
|
||||
[ViewVariables] public RSI? RSI
|
||||
{
|
||||
get => _rsi;
|
||||
set
|
||||
{
|
||||
if (_rsi == value)
|
||||
return;
|
||||
|
||||
_rsi = value;
|
||||
UpdateActualState();
|
||||
}
|
||||
}
|
||||
|
||||
private RSI.StateId _state;
|
||||
[ViewVariables] public RSI.StateId State
|
||||
{
|
||||
get => _state;
|
||||
set
|
||||
{
|
||||
if (_state == value)
|
||||
return;
|
||||
|
||||
_state = value;
|
||||
UpdateActualState();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables] public float AnimationTimeLeft;
|
||||
[ViewVariables] public float AnimationTime;
|
||||
[ViewVariables] public int AnimationFrame;
|
||||
|
||||
private RSI.State? _actualState;
|
||||
[ViewVariables] public RSI.State? ActualState => _actualState;
|
||||
|
||||
public Matrix3 LocalMatrix = Matrix3.Identity;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
@@ -1654,6 +1733,9 @@ namespace Robust.Client.GameObjects
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Visible = true;
|
||||
|
||||
[ViewVariables]
|
||||
public bool Blank => !State.IsValid && Texture == null;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Color Color { get; set; } = Color.White;
|
||||
|
||||
@@ -1849,6 +1931,7 @@ namespace Robust.Client.GameObjects
|
||||
Visible = value;
|
||||
|
||||
_parent.QueueUpdateIsInert();
|
||||
_parent.RebuildBounds();
|
||||
}
|
||||
|
||||
public void SetRsi(RSI? rsi)
|
||||
@@ -1943,54 +2026,57 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Box2 CalculateBoundingBox(Angle angle)
|
||||
public Box2 CalculateBoundingBox()
|
||||
{
|
||||
// Other than some special cases for simple layers, this will basically just apply the matrix obtained
|
||||
// via GetLayerDrawMatrix() to this layer's bounding box.
|
||||
var textureSize = (Vector2) PixelSize / EyeManager.PixelsPerMeter;
|
||||
|
||||
var rsiState = GetActualState();
|
||||
|
||||
var dir = (rsiState == null || rsiState.Directions == RSI.State.DirectionType.Dir1)
|
||||
? RSIDirection.South
|
||||
: angle.ToRsiDirection(rsiState.Directions);
|
||||
|
||||
// special case for simple layers. The vast majority of layers are like this.
|
||||
if (_rotation == Angle.Zero)
|
||||
// If the parent has locked rotation and we don't have any rotation,
|
||||
// we can take the quick path of just making a box the size of the texture.
|
||||
if (_parent.NoRotation && _rotation != 0)
|
||||
{
|
||||
var textureSize = PixelSize / EyeManager.PixelsPerMeter;
|
||||
|
||||
// this switch block is basically an explicit version of the `rsiDirectionMatrix` in `GetLayerDrawMatrix()`.
|
||||
var box = dir switch
|
||||
{
|
||||
// No rotation:
|
||||
RSIDirection.South or RSIDirection.North => Box2.CenteredAround(Offset, textureSize),
|
||||
// rotate 90 degrees:
|
||||
RSIDirection.East or RSIDirection.West => Box2.CenteredAround(Offset, (textureSize.Y, textureSize.X)),
|
||||
// rotated 45 degrees (any 45 degree rotated rectangle has a square bounding box with sides of length (x+y)/sqrt(2) )
|
||||
_ => Box2.CenteredAround(Offset, Vector2.One * (textureSize.X + textureSize.Y) / MathF.Sqrt(2))
|
||||
};
|
||||
|
||||
return _scale == Vector2.One ? box : box.Scale(_scale);
|
||||
return Box2.CenteredAround(Offset, textureSize).Scale(_scale);
|
||||
}
|
||||
|
||||
// Welp we have some non-zero _rotation, so lets just apply the generalized layer transform and get the bounding box from where;
|
||||
GetLayerDrawMatrix(dir, out var layerDrawMatrix);
|
||||
return layerDrawMatrix.TransformBox(Box2.CentredAroundZero(PixelSize / EyeManager.PixelsPerMeter));
|
||||
var longestSide = MathF.Max(textureSize.X, textureSize.Y);
|
||||
var longestRotatedSide = Math.Max(longestSide, (textureSize.X + textureSize.Y) / MathF.Sqrt(2));
|
||||
|
||||
// Build the bounding box based on how many directions the sprite has
|
||||
var box = (_rotation != 0, _actualState) switch
|
||||
{
|
||||
// If this layer has any form of arbitrary rotation, return a bounding box big enough to cover
|
||||
// any possible rotation.
|
||||
(true, _) => Box2.CenteredAround(Offset, new Vector2(longestRotatedSide, longestRotatedSide)),
|
||||
|
||||
// Otherwise...
|
||||
// If we have only one direction or an invalid RSI state, create a simple bounding box with the size of the texture.
|
||||
(_, {Directions: RSI.State.DirectionType.Dir1} or null) => Box2.CenteredAround(Offset, textureSize),
|
||||
// If we have four cardinal directions, take the longest side of our texture and square it, then turn that into our bounding box.
|
||||
// This accounts for all possible rotations.
|
||||
(_, {Directions: RSI.State.DirectionType.Dir4}) => Box2.CenteredAround(Offset, new Vector2(longestSide, longestSide)),
|
||||
// If we have eight directions, find the maximum length of the texture (accounting for rotation), then square it to make
|
||||
// our bounding box.
|
||||
(_, {Directions: RSI.State.DirectionType.Dir8}) => Box2.CenteredAround(Offset, new Vector2(longestRotatedSide, longestRotatedSide)),
|
||||
};
|
||||
return _scale == Vector2.One ? box : box.Scale(_scale);
|
||||
}
|
||||
|
||||
internal RSI.State? GetActualState()
|
||||
/// <summary>
|
||||
/// Update Cached RSI state. State is cached to avoid calling this every time an entity gets drawn.
|
||||
/// </summary>
|
||||
internal void UpdateActualState()
|
||||
{
|
||||
if (!State.IsValid)
|
||||
return null;
|
||||
{
|
||||
_actualState = null;
|
||||
return;
|
||||
}
|
||||
|
||||
// Pull texture from RSI state
|
||||
var rsi = RSI ?? _parent.BaseRSI;
|
||||
if (rsi == null || !rsi.TryGetState(State, out var rsiState))
|
||||
if (rsi == null || !rsi.TryGetState(State, out _actualState))
|
||||
{
|
||||
rsiState = GetFallbackState(_parent.resourceCache);
|
||||
_actualState = GetFallbackState(_parent.resourceCache);
|
||||
}
|
||||
|
||||
return rsiState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1999,39 +2085,49 @@ namespace Robust.Client.GameObjects
|
||||
/// </summary>
|
||||
public void GetLayerDrawMatrix(RSIDirection dir, out Matrix3 layerDrawMatrix)
|
||||
{
|
||||
if (_parent.NoRotation)
|
||||
if (_parent.NoRotation || dir == RSIDirection.South)
|
||||
layerDrawMatrix = LocalMatrix;
|
||||
else
|
||||
{
|
||||
var rsiDirectionMatrix = Matrix3.CreateTransform(Vector2.Zero, -dir.Convert().ToAngle());
|
||||
Matrix3.Multiply(ref rsiDirectionMatrix, ref LocalMatrix, out layerDrawMatrix);
|
||||
Matrix3.Multiply(in _rsiDirectionMatrices[(int)dir], in LocalMatrix, out layerDrawMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
private static Matrix3[] _rsiDirectionMatrices = new Matrix3[]
|
||||
{
|
||||
// array order chosen such that this array can be indexed by casing an RSI direction to an int
|
||||
Matrix3.Identity, // should probably just avoid matrix multiplication altogether if the direction is south.
|
||||
Matrix3.CreateRotation(-Direction.North.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.East.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.West.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.SouthEast.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.SouthWest.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.NorthEast.ToAngle()),
|
||||
Matrix3.CreateRotation(-Direction.NorthWest.ToAngle())
|
||||
};
|
||||
|
||||
internal void Render(DrawingHandleWorld drawingHandle, ref Matrix3 spriteMatrix, Angle angle, Direction? overrideDirection)
|
||||
{
|
||||
if (!Visible)
|
||||
if (!Visible || Blank)
|
||||
return;
|
||||
|
||||
var rsiState = GetActualState();
|
||||
|
||||
var dir = (rsiState == null || rsiState.Directions == RSI.State.DirectionType.Dir1)
|
||||
var dir = (_actualState == null || _actualState.Directions == RSI.State.DirectionType.Dir1)
|
||||
? RSIDirection.South
|
||||
: angle.ToRsiDirection(rsiState.Directions);
|
||||
: angle.ToRsiDirection(_actualState.Directions);
|
||||
|
||||
// Set the drawing transform for this layer
|
||||
GetLayerDrawMatrix(dir, out var layerMatrix);
|
||||
Matrix3.Multiply(ref layerMatrix, ref spriteMatrix, out var transformMatrix);
|
||||
Matrix3.Multiply(in layerMatrix, in spriteMatrix, out var transformMatrix);
|
||||
drawingHandle.SetTransform(in transformMatrix);
|
||||
|
||||
// The direction used to draw the sprite can differ from the one that the angle would naively suggest,
|
||||
// due to direction overrides or offsets.
|
||||
if (overrideDirection != null && rsiState != null)
|
||||
dir = overrideDirection.Value.Convert(rsiState.Directions);
|
||||
if (overrideDirection != null && _actualState != null)
|
||||
dir = overrideDirection.Value.Convert(_actualState.Directions);
|
||||
dir = dir.OffsetRsiDir(DirOffset);
|
||||
|
||||
// Get the correct directional texture from the state, and draw it!
|
||||
var texture = GetRenderTexture(rsiState, dir);
|
||||
var texture = GetRenderTexture(_actualState, dir);
|
||||
RenderTexture(drawingHandle, texture);
|
||||
}
|
||||
|
||||
@@ -2041,10 +2137,8 @@ namespace Robust.Client.GameObjects
|
||||
drawingHandle.UseShader(Shader);
|
||||
|
||||
var layerColor = _parent.color * Color;
|
||||
|
||||
var position = -(Vector2)texture.Size / (2f * EyeManager.PixelsPerMeter);
|
||||
var textureSize = texture.Size / (float)EyeManager.PixelsPerMeter;
|
||||
var quad = Box2.FromDimensions(position, textureSize);
|
||||
var quad = Box2.FromDimensions(textureSize/-2, textureSize);
|
||||
|
||||
drawingHandle.DrawTextureRectRegion(texture, quad, layerColor);
|
||||
|
||||
@@ -2138,14 +2232,19 @@ namespace Robust.Client.GameObjects
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var dummy = entityManager.SpawnEntity(prototype.ID, MapCoordinates.Nullspace);
|
||||
var spriteComponent = entityManager.EnsureComponent<SpriteComponent>(dummy);
|
||||
EntitySystem.Get<AppearanceSystem>().OnChangeData(dummy);
|
||||
EntitySystem.Get<AppearanceSystem>().OnChangeData(dummy, spriteComponent);
|
||||
|
||||
var anyTexture = false;
|
||||
foreach (var layer in spriteComponent.AllLayers)
|
||||
{
|
||||
if (!layer.Visible) continue;
|
||||
|
||||
if (layer.Texture != null)
|
||||
{
|
||||
results.Add(layer.Texture);
|
||||
if (!layer.RsiState.IsValid || !layer.Visible) continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!layer.RsiState.IsValid) continue;
|
||||
|
||||
var rsi = layer.Rsi ?? spriteComponent.BaseRSI;
|
||||
if (rsi == null ||
|
||||
@@ -2153,15 +2252,15 @@ namespace Robust.Client.GameObjects
|
||||
continue;
|
||||
|
||||
results.Add(state);
|
||||
anyTexture = true;
|
||||
}
|
||||
|
||||
noRot = spriteComponent.NoRotation;
|
||||
|
||||
entityManager.DeleteEntity(dummy);
|
||||
|
||||
if (!anyTexture)
|
||||
if (results.Count == 0)
|
||||
results.Add(resourceCache.GetFallback<TextureResource>().Texture);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user