Compare commits

...

128 Commits

Author SHA1 Message Date
Pieter-Jan Briers
17164ead34 Fix release compile. 2021-11-09 15:35:37 +01:00
Vera Aguilera Puerto
079e099a3b Makes many things use OwnerUid instead of Owner.Uid 2021-11-09 15:11:02 +01:00
Javier Guardia Fernández
1c8ed1c5b2 Update to .NET 6 and C# 10 (#2211)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2021-11-09 14:59:19 +01:00
Vera Aguilera Puerto
d4cdb7ff3b Tumbler command uses EntityUid 2021-11-09 13:02:01 +01:00
Vera Aguilera Puerto
31d301b91f ActorSystem and PlayerSession partially use EntityUid
Non-breaking changes
2021-11-09 12:54:18 +01:00
Vera Aguilera Puerto
07c65474cb LocalPlayer EntityUid 2021-11-09 12:38:25 +01:00
Vera Aguilera Puerto
8c3c8fceea ViewSubscriberSystem uses EntityUid for everything 2021-11-09 11:37:31 +01:00
Vera Aguilera Puerto
ee894d8a8e Move the last responsabilities from Entity to EntityManager. 2021-11-08 16:09:12 +01:00
Vera Aguilera Puerto
ce169ed15e Move LastModifiedTick out of Entity and into MetaDataComponent. (#2209) 2021-11-08 15:56:49 +01:00
Vera Aguilera Puerto
9b215098e4 Remove ITransformComponent. 2021-11-08 12:49:55 +01:00
Vera Aguilera Puerto
78d01fd25d Remove every ITransformComponent usage. 2021-11-08 12:44:03 +01:00
Vera Aguilera Puerto
8e8bfbe0cc Obsolete ITransformComponent 2021-11-08 12:28:49 +01:00
Vera Aguilera Puerto
45b0a49ffb Fix build 2021-11-08 12:23:22 +01:00
Vera Aguilera Puerto
58638c9109 Make TransformComponent public, IEntity keeps a reference to TransformComponent. 2021-11-08 12:21:34 +01:00
Vera Aguilera Puerto
2f2a397ecf Fix TransformComponent access modifiers (#2207)
Part 1 of ITransformComponent removal.
2021-11-08 12:18:53 +01:00
Vera Aguilera Puerto
78c551d854 Remove DummyIconEntity, use actual entities instead. (#2206) 2021-11-08 12:17:13 +01:00
Azzy
679e07d9ea Fixes ViewVariables sprite rotation bug (#2202) 2021-11-07 18:47:27 +11:00
DrSmugleaf
fa5d0235ec Prepend Client and Server to tests ran message 2021-11-06 11:42:01 +01:00
Javier Guardia Fernández
04d029b9a2 Add test pooling (#2146)
* Add test pooling and global test setup

* WIP test pooling changes

* Make asynchronous tests the default again

* Finish fixing tests, make test threads background threads

* Un-pool tests with custom cvars

* Fix not changing FailureLogLevel cvar on instance return

* Fix error when overriding already overriden cvar

* Don't pool some physics integration tests

* Unpool engine tests, the technology just isn't there yet

* Remove explicit Pool = false from physics tests

* Change default pooling setting to false

* Didn't need this anyway

* Remove ConfigurationManager.ResetOverrides

* Bring back enum cvar override parsing

* Make integrationInstances name clearer > notPooledInstaces
Make clients ready and servers ready internal

* Add logging test instances

* Give more info on ran tests

* Show total clients and servers in test output

* Wipe LayerMap on SpriteComponent.AfterDeserialize

* Fix server not properly kicking clients

* Rider shut

* Make all test metrics report totals

* Format tests ran better

* Replace Console.WriteLine with TestContext.Out.WriteLine

* Fix two server test pooling info prints using total clients instead of total servers

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2021-11-06 11:18:18 +01:00
Pieter-Jan Briers
6e84821233 Package CEF as NuGet package, does not need to be manually downloaded anymore. 2021-11-05 14:50:47 +01:00
Pieter-Jan Briers
881cfeb9a9 Small IRawInputControl doc. 2021-11-05 14:50:47 +01:00
Pieter-Jan Briers
0187e85700 Eye offset no longer offsets FOV.
This means camera recoil in SS14 won't clip into walls.
2021-11-04 17:37:00 +01:00
Pieter-Jan Briers
dee8a87acd Use headless WebViewManager on headless clients. 2021-11-03 15:26:52 +01:00
Pieter-Jan Briers
d4a7e8f3e0 Move CEF RequestResult to correct folder. 2021-11-03 15:14:46 +01:00
Pieter-Jan Briers
dae6424667 Allow swapping out internal WebViewManager implementation.
Everything moved to interfaces.
2021-11-03 15:12:49 +01:00
Pieter-Jan Briers
3770149cfc Update CefGlue 2021-11-03 15:03:25 +01:00
Alex Evgrashin
341c279265 Bandaid sprite animation in SpriteView (#2181) 2021-11-02 19:50:29 +01:00
metalgearsloth
37c20723ab Add WorldBounds as an arg for overlays (#2190) 2021-11-02 18:00:06 +01:00
ike709
c3e4a64ad7 Makes client connection timeout a cvar (#2186) 2021-11-02 17:56:17 +01:00
metalgearsloth
225446920a Make transform delete entity if parent invalid (#2193) 2021-11-02 17:54:48 +01:00
Saphire Lattice
9b2a50b1a8 Make camera lerp towards the grid rotation, and keep rotation when stepping off onto the world grid (#2187)
* Make camera lerp towards the grid rotation, and keep rotation when stepping off onto the world grid

* Fix lerp targeting, add a bunch of comments
2021-11-02 13:49:28 +01:00
metalgearsloth
b4ed513e8c Optimise anchor snap 2021-11-02 16:55:12 +11:00
20kdc
c28f2d77c3 Placement Manager: Spin Cycle 2 (#2184) 2021-11-02 16:21:03 +11:00
metalgearsloth
3e344d00a8 Move PVS to a system (#2189) 2021-11-02 16:19:11 +11:00
moonheart08
c321400347 Fix savemap/loadmap arguments. (#2055) 2021-11-02 16:07:31 +11:00
metalgearsloth
a4ff5d65ec Dirty changes (#2174) 2021-11-02 16:05:45 +11:00
Pieter-Jan Briers
97c70124a5 [CEF] properly close streams when loading from res:// and such. 2021-11-02 01:53:38 +01:00
Pieter-Jan Briers
cdcc5239ab Rename WebView control to WebViewControl to avoid namespace name clash. 2021-11-01 21:06:30 +01:00
Pieter-Jan Briers
ba2f464249 Restructure CEF stuff in preparation for launcher packaging.
Robust.Client.CEF Renamed to Robust.Client.WebView since CEF should really be an implementation detail.
Content is no longer responsible for initializing and managing the module, this is done automatically by the engine.
WebView is initialized by declaring it in a manifest.yml file in the game resources. In the future the launcher will read this same file to manage WebView module versions.
CefManager has been made private and the content-visible API is now IWebViewManager.
2021-11-01 21:03:51 +01:00
Paul
4210f30460 fixes positional audio not accounting for rotation 2021-10-31 22:49:05 +01:00
moonheart08
9fc95591d9 Introduce BQLv2, part 1 (#2170) 2021-10-31 20:23:13 +01:00
E F R
0a59079a4a Graphics: add a Font variant that supports font stacking (#2182) 2021-10-31 14:48:58 +01:00
20kdc
89f168c04d Improves PlacementManager (construction/etc.) handling of parent world rotation (#2165) 2021-10-31 14:47:18 +01:00
Visne
f11ac39cd5 Fix all warnings (#2171) 2021-10-31 12:22:58 +01:00
metalgearsloth
380de8c4c3 Expose OwnerUid on Component (#2183) 2021-10-31 11:35:21 +01:00
Vera Aguilera Puerto
539c161ea3 Fix client build when scripting is disabled. 2021-10-31 10:55:31 +01:00
metalgearsloth
b07187459b Fix physics for invalid parents 2021-10-31 15:24:12 +11:00
Pieter-Jan Briers
97fb54b6d7 Registry based HWIDs for Windows. 2021-10-30 14:21:23 +02:00
wixoa
fe30d974ca Add ImageSharp's Image.Load<>() to the sandbox (#2179) 2021-10-30 13:26:42 +02:00
E F R
884fade25a Add tab "completion" for the server-side C# console (#2176) 2021-10-30 13:26:23 +02:00
Pieter-Jan Briers
a3ab745121 Fix debug console not animating when dropping down for the first time. 2021-10-29 17:41:51 +02:00
ShadowCommander
4e0ad23272 Fix sound orientation when eye is rotated (#2177) 2021-10-29 16:49:16 +02:00
Vera Aguilera Puerto
b9b9cd0711 Revert "Fix PVS crash (#2173)"
This reverts commit b05b1a7c86.
2021-10-28 17:58:23 +02:00
metalgearsloth
b05b1a7c86 Fix PVS crash (#2173) 2021-10-29 01:26:39 +11:00
Visne
4ced901358 Remove SpriteComponent.Directional (#2172) 2021-10-28 13:20:06 +02:00
metalgearsloth
898d5a3ba5 Spaghettifix GetEntitiesIntersecting (#2167) 2021-10-27 08:55:24 +02:00
Visne
068c05c355 Use enum for access level in XamlUiPartialClassGenerator (#2161) 2021-10-27 08:52:09 +02:00
Saphire Lattice
cd693875e6 Fix resizing (#2160)
* Fix resizing moving the window beyond its minimum size and causing it to move visually

* Do a NaN-check the SetSize when resizing

* Use float instead to avoid conversion

As per PJB3005's suggestion

Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>

Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
2021-10-27 12:45:36 +11:00
20kdc
e2723a83b3 Revert "Technically fixes lathes, but not properly, but doesn't make things worse." :D (#2166)
This reverts commit cb19430d5c.
2021-10-27 12:44:34 +11:00
20kdc
f6ac8fbe1f Expose the Box2Rotated intersecting function in IEntityLookup for Content use (#2164) 2021-10-26 00:27:55 +11:00
metalgearsloth
a1e0f18bd6 Add Box2Rotated support to EntityLookup (#2163) 2021-10-25 15:00:18 +02:00
moonheart08
1e7a481911 better spawn command (#2156)
* better spawn command

* Update Robust.Server/Console/Commands/SpawnCommand.cs

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>

* Update Robust.Server/Console/Commands/SpawnCommand.cs

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>

* ok help

this is a web edit, sue me!

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
2021-10-24 22:15:47 -07:00
ShadowCommander
331f14b31a Fix audio warnings (#2158) 2021-10-24 23:43:04 +02:00
metalgearsloth
88660e1958 Use layer rotations for sprites (#2159) 2021-10-24 23:42:43 +02:00
Visne
d9af00c931 Make autogenerated XAML UI fields access level settable (#2148)
* Make autogenerated XAML fields public instead of protected

* Make field always public, remove stray commented out code

* Remove encapsulation for previously protected XAML UI fields

* Make access level settable

* Set access to public for DebugConsole LineEdit

* Address reviews and add documentation

* Remove documentation

* Address reviews
2021-10-24 23:20:27 +02:00
ShadowCommander
b8cb037151 Fix _enableAllKeybinds buttons breaking due to Use (#2157) 2021-10-24 01:43:46 -07:00
20kdc
32d8bd8600 Apply MIDI volume properly on initializtion of FluidSynth (#2153) 2021-10-24 00:12:30 +02:00
mirrorcult
f5a1e06f21 Merge pull request #2051 from Visne/sizeflags
Remove SizeFlags
2021-10-23 15:00:49 -07:00
Visne
48a5cb75d6 Restart tests 2021-10-23 23:54:55 +02:00
E F R
3e6b5a7739 UserInterfaceSystem: fail gracefully if the ClientUserInterfaceComponent goes away (#2155) 2021-10-23 19:38:44 +02:00
ShadowCommander
9ac0aa4cd6 Improve tpto (#2150)
Add teleporting other players to a target player
2021-10-23 10:22:40 -07:00
metalgearsloth
50fb8ca9e5 Fix sprite rounding issues (#2152)
* Fix sprite rounding issues

Should fix all of the issues at exactly 45 degrees

* Do Paul's review
2021-10-23 23:48:26 +11:00
metalgearsloth
7da89765ac Fix half of 45 degree sprite issues 2021-10-23 14:43:27 +11:00
Vera Aguilera Puerto
ce58c6688f Fix rare exception with QueueDelete modified collection
Now we use an actual queue for the deletion order, and the hashset for occupancy.
2021-10-23 00:08:04 +02:00
Vera Aguilera Puerto
2f03640200 Removing a component from an entity removes & deletes it immediately. (#2151) 2021-10-22 23:38:37 +02:00
20kdc
55fecc95a9 MIDI VolumeBoost property (#2141) 2021-10-22 09:09:24 +02:00
Alex Evgrashin
8b54ad79cf Int slider with input field (#2142) 2021-10-22 09:07:45 +02:00
Vera Aguilera Puerto
88dec23a03 Fix wrong logic with protected component removal, use fancy pattern. 2021-10-21 15:10:38 +02:00
20kdc
079702347d Show current rotation in entity spawn window (#2129) 2021-10-21 14:24:56 +02:00
metalgearsloth
d18bf3d5ac Force joint bodies awake
Woops
2021-10-21 20:47:17 +11:00
Pieter-Jan Briers
ed832748b1 list command now shows client commands again. 2021-10-21 01:39:16 +02:00
metalgearsloth
6491e51f3d Reduce FindGridsIntersecting allocations (#2119)
* Reduce FindGridsIntersecting allocations

I love struct enumerators

* Do slightly smarter pooling in EntityViewCulling

Even more alloc reductions

* Forgot to re-add this pooling

* Fix missing chunks
2021-10-19 13:30:52 +11:00
Pieter-Jan Briers
58e7fb3a17 Work around PEReader crashes on Linux.
Fixes #2130
2021-10-18 14:11:07 +02:00
mirrorcult
a9c7926226 Merge pull request #1942 from ShadowCommander/fix-sound
Change Audio to also use Grid Coordinates as a fallback
2021-10-18 00:28:11 -07:00
metalgearsloth
241dc0b752 Remove empty joint components (#2139) 2021-10-17 22:45:15 +02:00
Javier Guardia Fernández
566948f1c0 Add a virtual array of assemblies for SerializationTest to load so content can use it (#2137) 2021-10-16 15:38:18 +02:00
Javier Guardia Fernández
dbba440f7e Fix deserializing null structs (#2138)
* Fix deserializing null structs

* Fix deserializing for not nullable structs

* Add tests
2021-10-16 15:38:06 +02:00
Vera Aguilera Puerto
5b1e9eec27 Fixes component deletion/removal not being synced with clients. (#2128) 2021-10-15 23:52:09 +02:00
Pieter-Jan Briers
8ef95f0199 Update Lidgren 2021-10-15 15:59:44 +02:00
Leon Friedrich
b71e8f140a fix GridTileToWorldPos (#2134) 2021-10-15 22:59:44 +11:00
metalgearsloth
f8397099de Add a good GetCollidingEntities method that takes in body 2021-10-15 13:40:08 +11:00
metalgearsloth
5bbf1703ac Hack to avoid eye flicker on parent change 2021-10-15 11:55:47 +11:00
metalgearsloth
1357e38759 Fix controlmob crash (#2133) 2021-10-15 11:01:35 +11:00
Pieter-Jan Briers
655ecbab45 Update Lidgren submodule 2021-10-14 19:18:35 +02:00
Vera Aguilera Puerto
a0ef63bd4a Makes RemoveComponentImmediate more like RemoveComponentDeferred. (#2126)
- Exception tolerance added
- UID is now passed in the arguments
- Is able to remove protected components if needed.
- Actually calls `ComponentDependencyManager` to let it know the component has been removed.
2021-10-14 00:41:57 +02:00
Pieter-Jan Briers
f34763f11e Don't pack natives with engine client builds.
These are never used by the launcher due to the deployment model, so removing these saves quite a few megabytes.
2021-10-13 20:13:59 +02:00
Pieter-Jan Briers
b1f6b4cbe0 Remove .appveyor.yml
I doubt we'll ever use appveyor again, so...
2021-10-13 15:56:32 +02:00
Pieter-Jan Briers
94708881b3 Update Lidgren.
Optimizes Socket usage to remove allocations, minor bugfixes.
2021-10-13 15:55:04 +02:00
metalgearsloth
0f6dbac51c Fix gridbuffer broadphase (#2116)
It's for shuttle movement; it's getting bulldozed someday anyway but this fixes it.
2021-10-13 11:16:06 +11:00
metalgearsloth
e67de121ca Use spans for chunk mesh (#2124) 2021-10-11 17:06:21 +02:00
20kdc
17979db216 Technically fixes lathes, but not properly, but doesn't make things worse. (#2123)
I am aware this PR is terrible, but you saw what happened to the proper fix.
2021-10-11 16:10:38 +02:00
Pieter-Jan Briers
8d0070b5c3 Add IsUiOpen helper to UISystem. 2021-10-11 01:50:34 +02:00
Pieter-Jan Briers
034c392cbe Add GetComponentOrNull extension method. 2021-10-11 01:37:19 +02:00
Pieter-Jan Briers
160bbc3a72 Fix layout of entity spawn window. 2021-10-11 01:36:59 +02:00
metalgearsloth
3a4d228e94 Fix container manager deserialization 2021-10-11 02:56:37 +11:00
metalgearsloth
57f57f9d9f Fix PVS dumbdumb (#2122)
Was wondering why this was showing up on the profiler, woops
2021-10-11 02:27:04 +11:00
ShadowCommander
0592444252 Merge branch 'fix-sound' of github.com:ShadowCommander/RobustToolbox into fix-sound 2021-10-10 02:26:00 -07:00
ShadowCommander
d8499f2e60 Merge branch 'master' into fix-sound 2021-10-10 02:24:55 -07:00
metalgearsloth
476b5182f8 Fix y-sorting on rotated grids 2021-10-10 17:36:51 +11:00
metalgearsloth
6c7ab1bd82 Add AABBs to the physics debug drawing 2021-10-10 16:54:22 +11:00
metalgearsloth
526ed31b0d Re-parent unanchored entities (#2046) 2021-10-10 14:27:19 +11:00
metalgearsloth
3ac5552276 Cache more broadphase stuff internally (#2071)
* Don't generate physics contacts for non-predicted bodies

These are all just handled on the server anyway so it's a significant waste of performance on the client for busy scenes.

* Significantly optimise broadphase updates

Cache all of the broadphase data properly now and also save the cache for physics step to boot.

* Fix cross-map broadphases

* Remove unnecessary clear

* fix

* Fixes

* Numerous ray fixes
2021-10-10 14:18:10 +11:00
Flipp Syder
7a51c22514 Fixes SpriteComponent.AddLayer for specific RSI definition (#2115) 2021-10-09 20:21:12 +02:00
metalgearsloth
aa339eb504 Add component that toggles collision on anchoring (#2113) 2021-10-09 18:27:31 +02:00
mirrorcult
ffb3800664 Opt out of shadow casting for some lights (#2085)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2021-10-09 18:21:22 +02:00
Pieter-Jan Briers
39eb1a7d75 Clyde RenderOverlays now calls FlushRenderQueue.
This fixes association of API calls with the correct debug groups, and reduces (error prone) boilerplate.
2021-10-09 18:20:37 +02:00
20kdc
c25ab2fcb1 Fix FOV wall shadowing not working properly due to broken fov-lighting (#2114) 2021-10-09 17:27:36 +02:00
Vera Aguilera Puerto
22e0fbc6c1 The descendants of my friends are also my friends! Improves FriendAnalyzer.
In short, if you specify a shared type as a friend, any inheriting types will also count as friends, automatically. This could be abused but... That's why "sealed" exists, r-r-right?
2021-10-09 16:04:09 +02:00
Paul Ritter
72071826a4 fix placement grid (#2072) 2021-10-09 15:19:06 +02:00
Pieter-Jan Briers
8b9c1ab9a1 Fix warnings in Robust.Client 2021-10-09 15:08:08 +02:00
Vera Aguilera Puerto
16d5da5414 Check that parent uid is valid before dirtying oneself. 2021-10-09 12:41:57 +02:00
Visne
58ea614c1f Specify defaults for alignment explicitly 2021-09-29 19:12:17 +02:00
Visne
5cbad8b3d9 Remove SizeFlags 2021-09-20 02:15:14 +02:00
metalgearsloth
e7e08e5dd6 Merge branch 'master' into fix-sound 2021-09-13 20:39:42 +10:00
ShadowCommander
9ac8db37cc Add invalid check 2021-08-28 02:37:20 -07:00
ShadowCommander
2d6eebfae2 Rename GridCoordinates to FallbackCoordinates and move GetFallbackCoordinates to shared 2021-08-28 02:29:47 -07:00
ShadowCommander
5540d643ef Change from MapCoordinates to GridCoordinates 2021-08-12 01:45:07 -07:00
ShadowCommander
76c1d9f97b Change Audio to also use MapCoordinates as a fallback 2021-08-10 20:42:46 -07:00
225 changed files with 5930 additions and 2928 deletions

View File

@@ -1,52 +0,0 @@
environment:
sonarqubekey:
secure: h3llq6OeVa94hJ71UOEQSQDq75vFt+doso7iFry0gvt/fFcyeonY9wY+ETOIVITK
global:
PYTHONUNBUFFERED: True
HEADLESS: 1 # For the unit tests.
version: 0.1.0.{build}
pull_requests:
do_not_increment_build_number: true
image: Visual Studio 2019
install:
- ps: >
if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER -And $env:APPVEYOR_REPO_BRANCH -Eq "master")
{
cinst msbuild-sonarqube-runner;
}
before_build:
- cmd: py -3.5 -m pip install --user requests
- cmd: git submodule update --init --recursive
- ps: >
if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER -And $env:APPVEYOR_REPO_BRANCH -Eq "master")
{
SonarScanner.MSBuild.exe begin /k:"ss14" /d:"sonar.host.url=https://sonarcloud.io" /d:"sonar.login=$env:sonarqubekey" /o:"space-wizards" /d:sonar.cs.nunit.reportsPaths="$(Get-Location)\nunitTestResult.xml";
}
platform: x64
configuration: Debug
cache:
- packages -> **\*.csproj
- Dependencies
build:
project: RobustToolbox.sln
parallel: false
verbosity: minimal
build_script:
- ps: dotnet build RobustToolbox.sln /p:AppVeyor=yes
test_script:
- ps: dotnet test Robust.UnitTesting/Robust.UnitTesting.csproj
after_test:
- ps: >
if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER -And $env:APPVEYOR_REPO_BRANCH -Eq "master")
{
SonarScanner.MSBuild.exe end /d:"sonar.login=$env:sonarqubekey";
}

View File

@@ -22,7 +22,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.100
- name: Install dependencies
run: dotnet restore
- name: Build

View File

@@ -42,7 +42,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.100
- name: Build
run: dotnet build

View File

@@ -23,7 +23,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.100
- name: Package client
run: Tools/package_client_build.py -p windows mac linux

View File

@@ -21,7 +21,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.100
- name: Disable submodule autoupdate
run: touch BuildChecker/DISABLE_SUBMODULE_AUTOUPDATE
@@ -38,4 +38,4 @@ jobs:
- name: Content.Tests
run: dotnet test --no-build Content.Tests/Content.Tests.csproj -v n
- name: Content.IntegrationTests
run: COMPlus_gcServer=1 dotnet test --no-build Content.IntegrationTests/Content.IntegrationTests.csproj -v n
run: COMPlus_gcServer=1 dotnet test --no-build Content.IntegrationTests/Content.IntegrationTests.csproj -v n

View File

@@ -3,10 +3,10 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<DefineConstants Condition="'$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'netcoreapp3.1'">$(DefineConstants);HAS_FULL_SPAN</DefineConstants>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<DefaultItemExcludes>Lidgren.Network/**/*</DefaultItemExcludes>
<DefineConstants>$(DefineConstants);USE_RELEASE_STATISTICS</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>

View File

@@ -1,8 +1,8 @@
<Project>
<!-- Engine-specific properties. Content should not use this file. -->
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>9</LangVersion>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
</PropertyGroup>

View File

@@ -26,7 +26,7 @@
<TargetOS Condition="'$(TargetOS)' == ''">$(ActualOS)</TargetOS>
<Python>python3</Python>
<Python Condition="'$(ActualOS)' == 'Windows'">py -3</Python>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<EnableClientScripting>True</EnableClientScripting>
<!-- Client scripting is disabled on full release builds for security and size reasons. -->
<EnableClientScripting Condition="'$(FullRelease)' == 'True'">False</EnableClientScripting>

View File

@@ -2,29 +2,15 @@ preset raw;
#include "/Shaders/Internal/shadow_cast_shared.swsl"
#include "/Shaders/Internal/fov_shared.swsl"
const highp float g_MinVariance = 0.0;
varying highp vec2 worldPosition;
// Center of the FOV, in world coordinates.
uniform highp vec2 center;
void vertex()
{
highp vec3 transformed = modelMatrix * vec3(VERTEX, 1.0);
worldPosition = transformed.xy;
transformed = projectionMatrix * viewMatrix * transformed;
VERTEX = transformed.xy;
}
void fragment()
{
highp vec2 diff = worldPosition - center;
highp float ourDist = length(worldSpaceDiff);
highp float ourDist = length(diff);
highp vec2 occlDist = occludeDepth(diff, TEXTURE, 0.25);
highp vec2 occlDist = occludeDepth(worldSpaceDiff, TEXTURE, 0.25);
highp float occlusion = ChebyshevUpperBound(occlDist, ourDist);

View File

@@ -2,21 +2,10 @@ preset raw;
#include "/Shaders/Internal/shadow_cast_shared.swsl"
#include "/Shaders/Internal/fov_shared.swsl"
const highp float g_MinVariance = 0.0;
// World-space position offset from centre to pixel.
varying highp vec2 worldSpaceDiff;
// Inverted transformation matrix from clip coordinates to difference coordinates.
uniform highp mat3 clipToDiff;
void vertex()
{
// Convert quad-space (0.0 to 1.0) to clip-space (-1.0 to 1.0)
VERTEX = (VERTEX.xy - 0.5) * 2.0;
worldSpaceDiff = (clipToDiff * vec3(VERTEX, 1.0)).xy;
}
void fragment()
{
highp float ourDist = length(worldSpaceDiff);

View File

@@ -0,0 +1,16 @@
// Shared between fov-lighting.swsl and fov.swsl, which both use the Clyde quad,
// manually transformed into clip-space to cover the entire viewport
// World-space position offset from centre to pixel.
varying highp vec2 worldSpaceDiff;
// Inverted transformation matrix from clip coordinates to difference coordinates.
uniform highp mat3 clipToDiff;
void vertex()
{
// Convert quad-space (0.0 to 1.0) to clip-space (-1.0 to 1.0)
VERTEX = (VERTEX.xy - 0.5) * 2.0;
worldSpaceDiff = (clipToDiff * vec3(VERTEX, 1.0)).xy;
}

View File

@@ -40,7 +40,7 @@ void fragment()
highp vec2 diff = worldPosition - lightCenter;
// Totally not hacky PCF on top of VSM.
highp float occlusion = createOcclusion(diff);
highp float occlusion = lightIndex < 0.0 ? 1.0 : createOcclusion(diff);
if (occlusion == 0.0)
{

View File

@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -92,7 +93,7 @@ namespace Robust.Analyzers
continue;
// If we find that the containing class is specified in the attribute, return! All is good.
if (SymbolEqualityComparer.Default.Equals(containingType, t))
if (InheritsFromOrEquals(containingType, t))
return;
}
@@ -103,5 +104,26 @@ namespace Robust.Analyzers
}
}
}
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;
}
}
}
}

View File

@@ -1,593 +0,0 @@
using System;
using System.Collections.Generic;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using SixLabors.ImageSharp.PixelFormats;
using Xilium.CefGlue;
using static Robust.Client.CEF.CefKeyCodes;
using static Robust.Client.CEF.CefKeyCodes.ChromiumKeyboardCode;
using static Robust.Client.Input.Keyboard;
namespace Robust.Client.CEF
{
// Funny browser control to integrate in UI.
public class BrowserControl : Control, IBrowserControl, IRawInputControl
{
private const int ScrollSpeed = 50;
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IInputManager _inputMgr = default!;
[Dependency] private readonly CefManager _cef = default!;
private RobustRequestHandler _requestHandler = new RobustRequestHandler(Logger.GetSawmill("root"));
private LiveData? _data;
private string _startUrl = "about:blank";
[ViewVariables(VVAccess.ReadWrite)]
public string Url
{
get => _data == null ? _startUrl : _data.Browser.GetMainFrame().Url;
set
{
if (_data == null)
_startUrl = value;
else
_data.Browser.GetMainFrame().LoadUrl(value);
}
}
[ViewVariables] public bool IsLoading => _data?.Browser.IsLoading ?? false;
private readonly Dictionary<Key, ChromiumKeyboardCode> _keyMap = new()
{
[Key.A] = VKEY_A,
[Key.B] = VKEY_B,
[Key.C] = VKEY_C,
[Key.D] = VKEY_D,
[Key.E] = VKEY_E,
[Key.F] = VKEY_F,
[Key.G] = VKEY_G,
[Key.H] = VKEY_H,
[Key.I] = VKEY_I,
[Key.J] = VKEY_J,
[Key.K] = VKEY_K,
[Key.L] = VKEY_L,
[Key.M] = VKEY_M,
[Key.N] = VKEY_N,
[Key.O] = VKEY_O,
[Key.P] = VKEY_P,
[Key.Q] = VKEY_Q,
[Key.R] = VKEY_R,
[Key.S] = VKEY_S,
[Key.T] = VKEY_T,
[Key.U] = VKEY_U,
[Key.V] = VKEY_V,
[Key.W] = VKEY_W,
[Key.X] = VKEY_X,
[Key.Y] = VKEY_Y,
[Key.Z] = VKEY_Z,
[Key.Num0] = VKEY_0,
[Key.Num1] = VKEY_1,
[Key.Num2] = VKEY_2,
[Key.Num3] = VKEY_3,
[Key.Num4] = VKEY_4,
[Key.Num5] = VKEY_5,
[Key.Num6] = VKEY_6,
[Key.Num7] = VKEY_7,
[Key.Num8] = VKEY_8,
[Key.Num9] = VKEY_9,
[Key.NumpadNum0] = VKEY_NUMPAD0,
[Key.NumpadNum1] = VKEY_NUMPAD1,
[Key.NumpadNum2] = VKEY_NUMPAD2,
[Key.NumpadNum3] = VKEY_NUMPAD3,
[Key.NumpadNum4] = VKEY_NUMPAD4,
[Key.NumpadNum5] = VKEY_NUMPAD5,
[Key.NumpadNum6] = VKEY_NUMPAD6,
[Key.NumpadNum7] = VKEY_NUMPAD7,
[Key.NumpadNum8] = VKEY_NUMPAD8,
[Key.NumpadNum9] = VKEY_NUMPAD9,
[Key.Escape] = VKEY_ESCAPE,
[Key.Control] = VKEY_CONTROL,
[Key.Shift] = VKEY_SHIFT,
[Key.Alt] = VKEY_MENU,
[Key.LSystem] = VKEY_LWIN,
[Key.RSystem] = VKEY_RWIN,
[Key.LBracket] = VKEY_OEM_4,
[Key.RBracket] = VKEY_OEM_6,
[Key.SemiColon] = VKEY_OEM_1,
[Key.Comma] = VKEY_OEM_COMMA,
[Key.Period] = VKEY_OEM_PERIOD,
[Key.Apostrophe] = VKEY_OEM_7,
[Key.Slash] = VKEY_OEM_2,
[Key.BackSlash] = VKEY_OEM_5,
[Key.Tilde] = VKEY_OEM_3,
[Key.Equal] = VKEY_OEM_PLUS,
[Key.Space] = VKEY_SPACE,
[Key.Return] = VKEY_RETURN,
[Key.BackSpace] = VKEY_BACK,
[Key.Tab] = VKEY_TAB,
[Key.PageUp] = VKEY_PRIOR,
[Key.PageDown] = VKEY_NEXT,
[Key.End] = VKEY_END,
[Key.Home] = VKEY_HOME,
[Key.Insert] = VKEY_INSERT,
[Key.Delete] = VKEY_DELETE,
[Key.Minus] = VKEY_OEM_MINUS,
[Key.NumpadAdd] = VKEY_ADD,
[Key.NumpadSubtract] = VKEY_SUBTRACT,
[Key.NumpadDivide] = VKEY_DIVIDE,
[Key.NumpadMultiply] = VKEY_MULTIPLY,
[Key.NumpadDecimal] = VKEY_DECIMAL,
[Key.Left] = VKEY_LEFT,
[Key.Right] = VKEY_RIGHT,
[Key.Up] = VKEY_UP,
[Key.Down] = VKEY_DOWN,
[Key.F1] = VKEY_F1,
[Key.F2] = VKEY_F2,
[Key.F3] = VKEY_F3,
[Key.F4] = VKEY_F4,
[Key.F5] = VKEY_F5,
[Key.F6] = VKEY_F6,
[Key.F7] = VKEY_F7,
[Key.F8] = VKEY_F8,
[Key.F9] = VKEY_F9,
[Key.F10] = VKEY_F10,
[Key.F11] = VKEY_F11,
[Key.F12] = VKEY_F12,
[Key.F13] = VKEY_F13,
[Key.F14] = VKEY_F14,
[Key.F15] = VKEY_F15,
[Key.Pause] = VKEY_PAUSE,
};
public BrowserControl()
{
CanKeyboardFocus = true;
KeyboardFocusOnClick = true;
MouseFilter = MouseFilterMode.Stop;
IoCManager.InjectDependencies(this);
}
protected override void EnteredTree()
{
base.EnteredTree();
_cef.CheckInitialized();
DebugTools.AssertNull(_data);
// A funny render handler that will allow us to render to the control.
var renderer = new ControlRenderHandler(this);
// A funny web cef client. This can actually be shared by multiple browsers, but I'm not sure how the
// rendering would work in that case? TODO CEF: Investigate a way to share the web client?
var client = new RobustCefClient(renderer, _requestHandler, new RobustLoadHandler());
var info = CefWindowInfo.Create();
// FUNFACT: If you DO NOT set these below and set info.Width/info.Height instead, you get an external window
// Good to know, huh? Setup is the same, except you can pass a dummy render handler to the CEF client.
info.SetAsWindowless(IntPtr.Zero, false); // TODO CEF: Pass parent handle?
info.WindowlessRenderingEnabled = true;
var settings = new CefBrowserSettings()
{
WindowlessFrameRate = 60
};
// Create the web browser! And by default, we go to about:blank.
var browser = CefBrowserHost.CreateBrowserSync(info, client, settings, _startUrl);
var texture = _clyde.CreateBlankTexture<Bgra32>(Vector2i.One);
_data = new LiveData(texture, client, browser, renderer);
}
protected override void ExitedTree()
{
base.ExitedTree();
DebugTools.AssertNotNull(_data);
_data!.Texture.Dispose();
_data.Browser.GetHost().CloseBrowser(true);
_data = null;
}
protected internal override void MouseMove(GUIMouseMoveEventArgs args)
{
base.MouseMove(args);
if (_data == null)
return;
// Logger.Debug();
var modifiers = CalcMouseModifiers();
var mouseEvent = new CefMouseEvent(
(int) args.RelativePosition.X, (int) args.RelativePosition.Y,
modifiers);
_data.Browser.GetHost().SendMouseMoveEvent(mouseEvent, false);
}
protected internal override void MouseExited()
{
base.MouseExited();
if (_data == null)
return;
var modifiers = CalcMouseModifiers();
_data.Browser.GetHost().SendMouseMoveEvent(new CefMouseEvent(0, 0, modifiers), true);
}
protected internal override void MouseWheel(GUIMouseWheelEventArgs args)
{
base.MouseWheel(args);
if (_data == null)
return;
var modifiers = CalcMouseModifiers();
var mouseEvent = new CefMouseEvent(
(int) args.RelativePosition.X, (int) args.RelativePosition.Y,
modifiers);
_data.Browser.GetHost().SendMouseWheelEvent(
mouseEvent,
(int) args.Delta.X * ScrollSpeed,
(int) args.Delta.Y * ScrollSpeed);
}
bool IRawInputControl.RawKeyEvent(in GuiRawKeyEvent guiRawEvent)
{
if (_data == null)
return false;
var host = _data.Browser.GetHost();
if (guiRawEvent.Key is Key.MouseLeft or Key.MouseMiddle or Key.MouseRight)
{
var key = guiRawEvent.Key switch
{
Key.MouseLeft => CefMouseButtonType.Left,
Key.MouseMiddle => CefMouseButtonType.Middle,
Key.MouseRight => CefMouseButtonType.Right,
_ => default // not possible
};
var mouseEvent = new CefMouseEvent(
guiRawEvent.MouseRelative.X, guiRawEvent.MouseRelative.Y,
CefEventFlags.None);
// Logger.Debug($"MOUSE: {guiRawEvent.Action} {guiRawEvent.Key} {guiRawEvent.ScanCode} {key}");
// TODO: double click support?
host.SendMouseClickEvent(mouseEvent, key, guiRawEvent.Action == RawKeyAction.Up, 1);
}
else
{
// TODO: Handle left/right modifier keys??
if (!_keyMap.TryGetValue(guiRawEvent.Key, out var vkKey))
vkKey = default;
// Logger.Debug($"{guiRawEvent.Action} {guiRawEvent.Key} {guiRawEvent.ScanCode} {vkKey}");
var lParam = 0;
lParam |= (guiRawEvent.ScanCode & 0xFF) << 16;
if (guiRawEvent.Action != RawKeyAction.Down)
lParam |= 1 << 30;
if (guiRawEvent.Action == RawKeyAction.Up)
lParam |= 1 << 31;
var modifiers = CalcModifiers(guiRawEvent.Key);
host.SendKeyEvent(new CefKeyEvent
{
// Repeats are sent as key downs, I guess?
EventType = guiRawEvent.Action == RawKeyAction.Up
? CefKeyEventType.KeyUp
: CefKeyEventType.RawKeyDown,
NativeKeyCode = lParam,
// NativeKeyCode = guiRawEvent.ScanCode,
WindowsKeyCode = (int) vkKey,
IsSystemKey = false, // TODO
Modifiers = modifiers
});
if (guiRawEvent.Action != RawKeyAction.Up && guiRawEvent.Key == Key.Return)
{
host.SendKeyEvent(new CefKeyEvent
{
EventType = CefKeyEventType.Char,
WindowsKeyCode = '\r',
NativeKeyCode = lParam,
Modifiers = modifiers
});
}
}
return true;
}
private CefEventFlags CalcModifiers(Key key)
{
CefEventFlags modifiers = default;
if (_inputMgr.IsKeyDown(Key.Control))
modifiers |= CefEventFlags.ControlDown;
if (_inputMgr.IsKeyDown(Key.Alt))
modifiers |= CefEventFlags.AltDown;
if (_inputMgr.IsKeyDown(Key.Shift))
modifiers |= CefEventFlags.ShiftDown;
if (_inputMgr.IsKeyDown(Key.Shift))
modifiers |= CefEventFlags.ShiftDown;
return modifiers;
}
private CefEventFlags CalcMouseModifiers()
{
CefEventFlags modifiers = default;
if (_inputMgr.IsKeyDown(Key.Control))
modifiers |= CefEventFlags.ControlDown;
if (_inputMgr.IsKeyDown(Key.Alt))
modifiers |= CefEventFlags.AltDown;
if (_inputMgr.IsKeyDown(Key.Shift))
modifiers |= CefEventFlags.ShiftDown;
if (_inputMgr.IsKeyDown(Key.Shift))
modifiers |= CefEventFlags.ShiftDown;
if (_inputMgr.IsKeyDown(Key.MouseLeft))
modifiers |= CefEventFlags.LeftMouseButton;
if (_inputMgr.IsKeyDown(Key.MouseMiddle))
modifiers |= CefEventFlags.MiddleMouseButton;
if (_inputMgr.IsKeyDown(Key.MouseRight))
modifiers |= CefEventFlags.RightMouseButton;
return modifiers;
}
protected internal override void TextEntered(GUITextEventArgs args)
{
base.TextEntered(args);
if (_data == null)
return;
var host = _data.Browser.GetHost();
Span<char> buf = stackalloc char[2];
var written = args.AsRune.EncodeToUtf16(buf);
for (var i = 0; i < written; i++)
{
host.SendKeyEvent(new CefKeyEvent
{
EventType = CefKeyEventType.Char,
WindowsKeyCode = buf[i],
Character = buf[i],
UnmodifiedCharacter = buf[i]
});
}
}
protected override void Resized()
{
base.Resized();
if (_data == null)
return;
_data.Browser.GetHost().NotifyMoveOrResizeStarted();
_data.Browser.GetHost().WasResized();
_data.Texture.Dispose();
_data.Texture = _clyde.CreateBlankTexture<Bgra32>((PixelWidth, PixelHeight));
}
protected internal override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
if (_data == null)
return;
var bufImg = _data.Renderer.Buffer.Buffer;
_data.Texture.SetSubImage(
Vector2i.Zero,
bufImg,
new UIBox2i(
0, 0,
Math.Min(PixelWidth, bufImg.Width),
Math.Min(PixelHeight, bufImg.Height)));
handle.DrawTexture(_data.Texture, Vector2.Zero);
}
public void StopLoad()
{
if (_data == null)
throw new InvalidOperationException();
_data.Browser.StopLoad();
}
public void Reload()
{
if (_data == null)
throw new InvalidOperationException();
_data.Browser.Reload();
}
public bool GoBack()
{
if (_data == null)
throw new InvalidOperationException();
if (!_data.Browser.CanGoBack)
return false;
_data.Browser.GoBack();
return true;
}
public bool GoForward()
{
if (_data == null)
throw new InvalidOperationException();
if (!_data.Browser.CanGoForward)
return false;
_data.Browser.GoForward();
return true;
}
public void ExecuteJavaScript(string code)
{
if (_data == null)
throw new InvalidOperationException();
// TODO: this should not run until the browser is done loading seriously does this even work?
_data.Browser.GetMainFrame().ExecuteJavaScript(code, string.Empty, 1);
}
public void AddResourceRequestHandler(Action<RequestHandlerContext> handler)
{
_requestHandler.AddResourceRequestHandler(handler);
}
public void RemoveResourceRequestHandler(Action<RequestHandlerContext> handler)
{
_requestHandler.RemoveResourceRequestHandler(handler);
}
public void AddBeforeBrowseHandler(Action<BeforeBrowseContext> handler)
{
_requestHandler.AddBeforeBrowseHandler(handler);
}
public void RemoveBeforeBrowseHandler(Action<BeforeBrowseContext> handler)
{
_requestHandler.RemoveBeforeBrowseHandler(handler);
}
private sealed class LiveData
{
public OwnedTexture Texture;
public readonly RobustCefClient Client;
public readonly CefBrowser Browser;
public readonly ControlRenderHandler Renderer;
public LiveData(
OwnedTexture texture,
RobustCefClient client,
CefBrowser browser,
ControlRenderHandler renderer)
{
Texture = texture;
Client = client;
Browser = browser;
Renderer = renderer;
}
}
}
internal class ControlRenderHandler : CefRenderHandler
{
public ImageBuffer Buffer { get; }
private Control _control;
internal ControlRenderHandler(Control control)
{
Buffer = new ImageBuffer(control);
_control = control;
}
protected override CefAccessibilityHandler? GetAccessibilityHandler() => null;
protected override void GetViewRect(CefBrowser browser, out CefRectangle rect)
{
if (_control.Disposed)
{
rect = new CefRectangle();
return;
}
// TODO CEF: Do we need to pass real screen coords? Cause what we do already works...
//var screenCoords = _control.ScreenCoordinates;
//rect = new CefRectangle((int) screenCoords.X, (int) screenCoords.Y, (int)Math.Max(_control.Size.X, 1), (int)Math.Max(_control.Size.Y, 1));
// We do the max between size and 1 because it will LITERALLY CRASH WITHOUT AN ERROR otherwise.
rect = new CefRectangle(0, 0, (int) Math.Max(_control.Size.X, 1), (int) Math.Max(_control.Size.Y, 1));
}
protected override bool GetScreenInfo(CefBrowser browser, CefScreenInfo screenInfo)
{
if (_control.Disposed)
return false;
// TODO CEF: Get actual scale factor?
screenInfo.DeviceScaleFactor = 1.0f;
return true;
}
protected override void OnPopupSize(CefBrowser browser, CefRectangle rect)
{
if (_control.Disposed)
return;
}
protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects,
IntPtr buffer, int width, int height)
{
if (_control.Disposed)
return;
foreach (var dirtyRect in dirtyRects)
{
Buffer.UpdateBuffer(width, height, buffer, dirtyRect);
}
}
protected override void OnAcceleratedPaint(CefBrowser browser, CefPaintElementType type,
CefRectangle[] dirtyRects, IntPtr sharedHandle)
{
// Unused, but we're forced to implement it so.. NOOP.
}
protected override void OnScrollOffsetChanged(CefBrowser browser, double x, double y)
{
if (_control.Disposed)
return;
}
protected override void OnImeCompositionRangeChanged(CefBrowser browser, CefRange selectedRange,
CefRectangle[] characterBounds)
{
if (_control.Disposed)
return;
}
}
}

View File

@@ -1,101 +0,0 @@
using System;
using System.IO;
using JetBrains.Annotations;
using Robust.Shared.ContentPack;
using Robust.Shared.Log;
using Robust.Shared.Utility;
// The library we're using right now. TODO CEF: Do we want to use something else? We will need to ship it ourselves if so.
using Xilium.CefGlue;
namespace Robust.Client.CEF
{
// Register this with IoC.
// TODO CEF: think if making this inherit CefApp is a good idea...
// TODO CEF: A way to handle external window browsers...
[UsedImplicitly]
public partial class CefManager
{
private CefApp _app = default!;
private bool _initialized = false;
/// <summary>
/// Call this to initialize CEF.
/// </summary>
public void Initialize()
{
DebugTools.Assert(!_initialized);
string subProcessName;
if (OperatingSystem.IsWindows())
subProcessName = "Robust.Client.CEF.exe";
else if (OperatingSystem.IsLinux())
subProcessName = "Robust.Client.CEF";
else
throw new NotSupportedException("Unsupported platform for CEF!");
var subProcessPath = PathHelpers.ExecutableRelativeFile(subProcessName);
var settings = new CefSettings()
{
WindowlessRenderingEnabled = true, // So we can render to our UI controls.
ExternalMessagePump = false, // Unsure, honestly. TODO CEF: Research this?
NoSandbox = true, // Not disabling the sandbox crashes CEF.
BrowserSubprocessPath = subProcessPath,
LocalesDirPath = Path.Combine(PathHelpers.GetExecutableDirectory(), "locales"),
ResourcesDirPath = PathHelpers.GetExecutableDirectory(),
RemoteDebuggingPort = 9222
};
Logger.Info($"CEF Version: {CefRuntime.ChromeVersion}");
// --------------------------- README --------------------------------------------------
// By the way! You're gonna need the CEF binaries in your client's bin folder.
// More specifically, version cef_binary_94.4.1+g4b61a8c+chromium-94.0.4606.54
// Windows: https://cef-builds.spotifycdn.com/cef_binary_94.4.1%2Bg4b61a8c%2Bchromium-94.0.4606.54_windows64_minimal.tar.bz2
// Linux: https://cef-builds.spotifycdn.com/cef_binary_94.4.1%2Bg4b61a8c%2Bchromium-94.0.4606.54_linux64_minimal.tar.bz2
// Here's how to get it to work:
// 1. Copy all the contents of "Release" to the bin/Content.Client folder.
// 2. Copy all the contents of "Resources" to the bin/Content.Client folder.
// -------------------------------------------------------------------------------------
_app = new RobustCefApp();
// We pass no main arguments...
CefRuntime.Initialize(new CefMainArgs(null), settings, _app, IntPtr.Zero);
// 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.
_initialized = true;
}
public void CheckInitialized()
{
if (!_initialized)
throw new InvalidOperationException("CefManager has not been initialized!");
}
/// <summary>
/// Needs to be called regularly for CEF to keep working.
/// </summary>
public void Update()
{
DebugTools.Assert(_initialized);
// Calling this makes CEF do its work, without using its own update loop.
CefRuntime.DoMessageLoopWork();
}
/// <summary>
/// Call before program shutdown.
/// </summary>
public void Shutdown()
{
DebugTools.Assert(_initialized);
CefRuntime.Shutdown();
}
}
}

View File

@@ -1,9 +0,0 @@
using System;
namespace Robust.Client.CEF
{
public interface IBrowserWindow : IBrowserControl, IDisposable
{
bool Closed { get; }
}
}

View File

@@ -1,33 +0,0 @@
using System;
using Xilium.CefGlue;
namespace Robust.Client.CEF
{
public static class Program
{
// This was supposed to be the main entry for the subprocess program... It doesn't work.
public static int Main(string[] args)
{
// This is a workaround for this to work on UNIX.
var argv = args;
if (CefRuntime.Platform != CefRuntimePlatform.Windows)
{
argv = new string[args.Length + 1];
Array.Copy(args, 0, argv, 1, args.Length);
argv[0] = "-";
}
var mainArgs = new CefMainArgs(argv);
// This will block executing until the subprocess is shut down.
var code = CefRuntime.ExecuteProcess(mainArgs, null, IntPtr.Zero);
if (code != 0)
{
System.Console.WriteLine($"CEF Subprocess exited unsuccessfully with exit code {code}! Arguments: {string.Join(' ', argv)}");
}
return code;
}
}
}

View File

@@ -1,25 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\MSBuild\Robust.Properties.targets" />
<Import Project="..\MSBuild\Robust.Engine.props" />
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputType>WinExe</OutputType>
</PropertyGroup>
<Import Project="..\MSBuild\Robust.DefineConstants.targets" />
<Target Name="RobustAfterBuild" AfterTargets="Build" />
<Import Project="..\MSBuild\Robust.Engine.targets" />
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\cefglue\CefGlue\CefGlue.csproj" />
<ProjectReference Include="..\Robust.Client\Robust.Client.csproj" />
</ItemGroup>
</Project>

View File

@@ -13,5 +13,6 @@
<Compile Link="XamlX\filename" Include="../XamlX/src/XamlX/**/*.cs" />
<Compile Remove="../XamlX/src/XamlX/**/SreTypeSystem.cs" />
<Compile Remove="../XamlX/src/XamlX/obj/**" />
<Compile Include="..\Robust.Client\UserInterface\ControlPropertyAccess.cs" />
</ItemGroup>
</Project>

View File

@@ -6,6 +6,7 @@ using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Text;
using Robust.Client.UserInterface;
using XamlX.Ast;
using XamlX.Emit;
using XamlX.IL;
@@ -37,9 +38,10 @@ namespace Robust.Client.AutoGenerated
class NameVisitor : IXamlAstVisitor
{
private List<(string name, string type)> _names = new List<(string name, string type)>();
private readonly List<(string name, string type, AccessLevel access)> _names =
new List<(string name, string type, AccessLevel access)>();
public static List<(string name, string type)> GetNames(IXamlAstNode node)
public static List<(string name, string type, AccessLevel access)> GetNames(IXamlAstNode node)
{
var visitor = new NameVisitor();
node.Visit(visitor);
@@ -56,27 +58,42 @@ namespace Robust.Client.AutoGenerated
{
var clrtype = objectNode.Type.GetClrType();
var isControl = IsControl(clrtype);
//clrtype.Interfaces.Any(i =>
//i.IsInterface && i.FullName == "Robust.Client.UserInterface.IControl");
if (!isControl)
return node;
// Find Name and Access properties
XamlAstTextNode nameText = null;
XamlAstTextNode accessText = null;
foreach (var child in objectNode.Children)
{
if (child is XamlAstXamlPropertyValueNode propertyValueNode &&
propertyValueNode.Property is XamlAstNamePropertyReference namedProperty &&
namedProperty.Name == "Name" &&
propertyValueNode.Values.Count > 0 &&
propertyValueNode.Values[0] is XamlAstTextNode text)
{
var reg = (text.Text, $@"{clrtype.Namespace}.{clrtype.Name}");
if (!_names.Contains(reg))
switch (namedProperty.Name)
{
_names.Add(reg);
case "Name":
nameText = text;
break;
case "Access":
accessText = text;
break;
}
}
}
if (nameText == null)
return node;
var reg = (nameText.Text,
$@"{clrtype.Namespace}.{clrtype.Name}",
accessText != null ? (AccessLevel) Enum.Parse(typeof(AccessLevel), accessText.Text) : AccessLevel.Protected);
if (!_names.Contains(reg))
{
_names.Add(reg);
}
}
return node;
@@ -94,7 +111,8 @@ namespace Robust.Client.AutoGenerated
private static string GenerateSourceCode(
INamedTypeSymbol classSymbol,
string xamlFile,
CSharpCompilation comp)
CSharpCompilation comp,
string fileName)
{
var className = classSymbol.Name;
var nameSpace = classSymbol.ContainingNamespace.ToDisplayString();
@@ -118,11 +136,42 @@ namespace Robust.Client.AutoGenerated
if (classSymbol.ToString() != rootTypeString && classSymbol.BaseType?.ToString() != rootTypeString)
throw new InvalidXamlRootTypeException(rootType, classSymbol, classSymbol.BaseType);
var fieldAccess = classSymbol.IsSealed ? "private" : "protected";
//var names = NameVisitor.GetNames((XamlAstObjectNode)XDocumentXamlParser.Parse(xamlFile).Root);
var namedControls = names.Select(info => " " +
$"{fieldAccess} global::{info.type} {info.name} => " +
$"this.FindControl<global::{info.type}>(\"{info.name}\");");
var namedControls = names.Select(info =>
{
(string name, string type, AccessLevel access) = info;
string accessStr;
switch (access)
{
case AccessLevel.Public:
accessStr = "public";
break;
case AccessLevel.Protected when classSymbol.IsSealed:
case AccessLevel.PrivateProtected when classSymbol.IsSealed:
case AccessLevel.Private:
accessStr = "private";
break;
case AccessLevel.Protected:
accessStr = "protected";
break;
case AccessLevel.PrivateProtected:
accessStr = "private protected";
break;
case AccessLevel.Internal:
case AccessLevel.ProtectedInternal when classSymbol.IsSealed:
accessStr = "internal";
break;
case AccessLevel.ProtectedInternal:
accessStr = "protected internal";
break;
default:
throw new ArgumentException($"Invalid access level \"{Enum.GetName(typeof(AccessLevel), access)}\" " +
$"for control {name} in file {fileName}.");
}
return $" {accessStr} global::{type} {name} => this.FindControl<global::{type}>(\"{name}\");";
});
return $@"// <auto-generated />
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
@@ -136,7 +185,6 @@ namespace {nameSpace}
";
}
public void Execute(GeneratorExecutionContext context)
{
var comp = (CSharpCompilation) context.Compilation;
@@ -207,7 +255,7 @@ namespace {nameSpace}
try
{
var sourceCode = GenerateSourceCode(typeSymbol, txt, comp);
var sourceCode = GenerateSourceCode(typeSymbol, txt, comp, xamlFileName);
context.AddSource($"{typeSymbol.Name}.g.cs", SourceText.From(sourceCode, Encoding.UTF8));
}
catch (InvalidXamlRootTypeException invRootType)

View File

@@ -1,4 +1,4 @@
namespace Robust.Client.CEF
namespace Robust.Client.WebView
{
public sealed class BrowserWindowCreateParameters
{

View File

@@ -1,8 +1,8 @@
using Xilium.CefGlue;
namespace Robust.Client.CEF
namespace Robust.Client.WebView.Cef
{
public sealed class BeforeBrowseContext
internal sealed class CefBeforeBrowseContext : IBeforeBrowseContext
{
internal readonly CefRequest CefRequest;
@@ -14,7 +14,7 @@ namespace Robust.Client.CEF
public bool IsCancelled { get; private set; }
internal BeforeBrowseContext(
internal CefBeforeBrowseContext(
bool isRedirect,
bool userGesture,
CefRequest cefRequest)

View File

@@ -1,7 +1,7 @@

using System.Diagnostics.CodeAnalysis;
namespace Robust.Client.CEF
namespace Robust.Client.WebView.Cef
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "UnusedMember.Global")]

View File

@@ -3,9 +3,9 @@ using System.IO;
using System.Net;
using Xilium.CefGlue;
namespace Robust.Client.CEF
namespace Robust.Client.WebView.Cef
{
public sealed class RequestHandlerContext
internal sealed class CefRequestHandlerContext : IRequestHandlerContext
{
internal readonly CefRequest CefRequest;
@@ -22,7 +22,7 @@ namespace Robust.Client.CEF
internal IRequestResult? Result { get; private set; }
internal RequestHandlerContext(
internal CefRequestHandlerContext(
bool isNavigation,
bool isDownload,
string requestInitiator,

View File

@@ -1,22 +1,14 @@
using System;
using Robust.Client.UserInterface;
using Robust.Client.Utility;
using Robust.Shared.Maths;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using Xilium.CefGlue;
namespace Robust.Client.CEF
namespace Robust.Client.WebView.Cef
{
internal sealed class ImageBuffer
{
private readonly Control _control;
public ImageBuffer(Control control)
{
_control = control;
}
public Image<Bgra32> Buffer { get; private set; } = new(1, 1);
public unsafe void UpdateBuffer(int width, int height, IntPtr buffer, CefRectangle dirtyRect)

View File

@@ -0,0 +1,88 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Robust.Shared.ContentPack;
using Xilium.CefGlue;
namespace Robust.Client.WebView.Cef
{
public static class Program
{
// This was supposed to be the main entry for the subprocess program... It doesn't work.
public static int Main(string[] args)
{
// This is a workaround for this to work on UNIX.
var argv = args;
if (CefRuntime.Platform != CefRuntimePlatform.Windows)
{
argv = new string[args.Length + 1];
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);
if (code != 0)
{
System.Console.WriteLine($"CEF Subprocess exited unsuccessfully with exit code {code}! Arguments: {string.Join(' ', argv)}");
}
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.
}
}
} */
}
}

View File

@@ -3,7 +3,7 @@ using System.IO;
using System.Net;
using Xilium.CefGlue;
namespace Robust.Client.CEF
namespace Robust.Client.WebView.Cef
{
internal interface IRequestResult
{
@@ -88,6 +88,13 @@ namespace Robust.Client.CEF
protected override void Cancel()
{
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_stream.Dispose();
}
}
}
}

View File

@@ -3,7 +3,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Log;
using Xilium.CefGlue;
namespace Robust.Client.CEF
namespace Robust.Client.WebView.Cef
{
internal class RobustCefApp : CefApp
{
@@ -24,6 +24,13 @@ namespace Robust.Client.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");
//commandLine.AppendSwitch("--disable-gpu-compositing");

View File

@@ -1,6 +1,6 @@
using Xilium.CefGlue;
namespace Robust.Client.CEF
namespace Robust.Client.WebView.Cef
{
// Simple CEF client.
internal class RobustCefClient : CefClient

View File

@@ -1,6 +1,6 @@
using Xilium.CefGlue;
namespace Robust.Client.CEF
namespace Robust.Client.WebView.Cef
{
public sealed class RobustLoadHandler : CefLoadHandler
{

View File

@@ -3,20 +3,20 @@ using System.Collections.Generic;
using Robust.Shared.Log;
using Xilium.CefGlue;
namespace Robust.Client.CEF
namespace Robust.Client.WebView.Cef
{
internal sealed class RobustRequestHandler : CefRequestHandler
{
private readonly ISawmill _sawmill;
private readonly List<Action<RequestHandlerContext>> _resourceRequestHandlers = new();
private readonly List<Action<BeforeBrowseContext>> _beforeBrowseHandlers = new();
private readonly List<Action<IRequestHandlerContext>> _resourceRequestHandlers = new();
private readonly List<Action<IBeforeBrowseContext>> _beforeBrowseHandlers = new();
public RobustRequestHandler(ISawmill sawmill)
{
_sawmill = sawmill;
}
public void AddResourceRequestHandler(Action<RequestHandlerContext> handler)
public void AddResourceRequestHandler(Action<IRequestHandlerContext> handler)
{
lock (_resourceRequestHandlers)
{
@@ -24,7 +24,7 @@ namespace Robust.Client.CEF
}
}
public void RemoveResourceRequestHandler(Action<RequestHandlerContext> handler)
public void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler)
{
lock (_resourceRequestHandlers)
{
@@ -32,7 +32,7 @@ namespace Robust.Client.CEF
}
}
public void AddBeforeBrowseHandler(Action<BeforeBrowseContext> handler)
public void AddBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
{
lock (_beforeBrowseHandlers)
{
@@ -40,7 +40,7 @@ namespace Robust.Client.CEF
}
}
public void RemoveBeforeBrowseHandler(Action<BeforeBrowseContext> handler)
public void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
{
lock (_beforeBrowseHandlers)
{
@@ -61,7 +61,7 @@ namespace Robust.Client.CEF
{
_sawmill.Debug($"HANDLING REQUEST: {request.Url}");
var context = new RequestHandlerContext(isNavigation, isDownload, requestInitiator, request);
var context = new CefRequestHandlerContext(isNavigation, isDownload, requestInitiator, request);
foreach (var handler in _resourceRequestHandlers)
{
@@ -85,7 +85,7 @@ namespace Robust.Client.CEF
{
lock (_beforeBrowseHandlers)
{
var context = new BeforeBrowseContext(isRedirect, userGesture, request);
var context = new CefBeforeBrowseContext(isRedirect, userGesture, request);
foreach (var handler in _beforeBrowseHandlers)
{

View File

@@ -6,26 +6,25 @@ using Robust.Shared.Log;
using Robust.Shared.ViewVariables;
using Xilium.CefGlue;
namespace Robust.Client.CEF
namespace Robust.Client.WebView.Cef
{
public partial class CefManager
internal partial class WebViewManagerCef
{
[Dependency] private readonly IClydeInternal _clyde = default!;
private readonly List<BrowserWindowImpl> _browserWindows = new();
private readonly List<WebViewWindowImpl> _browserWindows = new();
public IEnumerable<IBrowserWindow> AllBrowserWindows => _browserWindows;
public IEnumerable<IWebViewWindow> AllBrowserWindows => _browserWindows;
public IBrowserWindow CreateBrowserWindow(BrowserWindowCreateParameters createParams)
public IWebViewWindow CreateBrowserWindow(BrowserWindowCreateParameters createParams)
{
var mainHWnd = (_clyde.MainWindow as IClydeWindowInternal)?.WindowsHWnd ?? 0;
var info = CefWindowInfo.Create();
info.Width = createParams.Width;
info.Height = createParams.Height;
info.Bounds = new CefRectangle(0, 0, createParams.Width, createParams.Height);
info.SetAsPopup(mainHWnd, "ss14cef");
var impl = new BrowserWindowImpl(this);
var impl = new WebViewWindowImpl(this);
var lifeSpanHandler = new WindowLifeSpanHandler(impl);
var reqHandler = new RobustRequestHandler(Logger.GetSawmill("root"));
@@ -40,13 +39,13 @@ namespace Robust.Client.CEF
return impl;
}
private sealed class BrowserWindowImpl : IBrowserWindow
private sealed class WebViewWindowImpl : IWebViewWindow
{
private readonly CefManager _manager;
private readonly WebViewManagerCef _manager;
internal CefBrowser Browser = default!;
internal RobustRequestHandler RequestHandler = default!;
public Action<RequestHandlerContext>? OnResourceRequest { get; set; }
public Action<CefRequestHandlerContext>? OnResourceRequest { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public string Url
@@ -73,7 +72,7 @@ namespace Robust.Client.CEF
}
}
public BrowserWindowImpl(CefManager manager)
public WebViewWindowImpl(WebViewManagerCef manager)
{
_manager = manager;
}
@@ -116,12 +115,12 @@ namespace Robust.Client.CEF
Browser.GetMainFrame().ExecuteJavaScript(code, string.Empty, 1);
}
public void AddResourceRequestHandler(Action<RequestHandlerContext> handler)
public void AddResourceRequestHandler(Action<IRequestHandlerContext> handler)
{
RequestHandler.AddResourceRequestHandler(handler);
}
public void RemoveResourceRequestHandler(Action<RequestHandlerContext> handler)
public void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler)
{
RequestHandler.RemoveResourceRequestHandler(handler);
}
@@ -168,9 +167,9 @@ namespace Robust.Client.CEF
private sealed class WindowLifeSpanHandler : CefLifeSpanHandler
{
private readonly BrowserWindowImpl _windowImpl;
private readonly WebViewWindowImpl _windowImpl;
public WindowLifeSpanHandler(BrowserWindowImpl windowImpl)
public WindowLifeSpanHandler(WebViewWindowImpl windowImpl)
{
_windowImpl = windowImpl;
}

View File

@@ -0,0 +1,580 @@
using System;
using System.Collections.Generic;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using SixLabors.ImageSharp.PixelFormats;
using Xilium.CefGlue;
using static Robust.Client.WebView.Cef.CefKeyCodes.ChromiumKeyboardCode;
using static Robust.Client.Input.Keyboard;
namespace Robust.Client.WebView.Cef
{
internal partial class WebViewManagerCef
{
public IWebViewControlImpl MakeControlImpl(WebViewControl owner)
{
var impl = new ControlImpl(owner);
_dependencyCollection.InjectDependencies(impl);
return impl;
}
private sealed class ControlImpl : IWebViewControlImpl
{
private static readonly Dictionary<Key, CefKeyCodes.ChromiumKeyboardCode> KeyMap = new()
{
[Key.A] = VKEY_A,
[Key.B] = VKEY_B,
[Key.C] = VKEY_C,
[Key.D] = VKEY_D,
[Key.E] = VKEY_E,
[Key.F] = VKEY_F,
[Key.G] = VKEY_G,
[Key.H] = VKEY_H,
[Key.I] = VKEY_I,
[Key.J] = VKEY_J,
[Key.K] = VKEY_K,
[Key.L] = VKEY_L,
[Key.M] = VKEY_M,
[Key.N] = VKEY_N,
[Key.O] = VKEY_O,
[Key.P] = VKEY_P,
[Key.Q] = VKEY_Q,
[Key.R] = VKEY_R,
[Key.S] = VKEY_S,
[Key.T] = VKEY_T,
[Key.U] = VKEY_U,
[Key.V] = VKEY_V,
[Key.W] = VKEY_W,
[Key.X] = VKEY_X,
[Key.Y] = VKEY_Y,
[Key.Z] = VKEY_Z,
[Key.Num0] = VKEY_0,
[Key.Num1] = VKEY_1,
[Key.Num2] = VKEY_2,
[Key.Num3] = VKEY_3,
[Key.Num4] = VKEY_4,
[Key.Num5] = VKEY_5,
[Key.Num6] = VKEY_6,
[Key.Num7] = VKEY_7,
[Key.Num8] = VKEY_8,
[Key.Num9] = VKEY_9,
[Key.NumpadNum0] = VKEY_NUMPAD0,
[Key.NumpadNum1] = VKEY_NUMPAD1,
[Key.NumpadNum2] = VKEY_NUMPAD2,
[Key.NumpadNum3] = VKEY_NUMPAD3,
[Key.NumpadNum4] = VKEY_NUMPAD4,
[Key.NumpadNum5] = VKEY_NUMPAD5,
[Key.NumpadNum6] = VKEY_NUMPAD6,
[Key.NumpadNum7] = VKEY_NUMPAD7,
[Key.NumpadNum8] = VKEY_NUMPAD8,
[Key.NumpadNum9] = VKEY_NUMPAD9,
[Key.Escape] = VKEY_ESCAPE,
[Key.Control] = VKEY_CONTROL,
[Key.Shift] = VKEY_SHIFT,
[Key.Alt] = VKEY_MENU,
[Key.LSystem] = VKEY_LWIN,
[Key.RSystem] = VKEY_RWIN,
[Key.LBracket] = VKEY_OEM_4,
[Key.RBracket] = VKEY_OEM_6,
[Key.SemiColon] = VKEY_OEM_1,
[Key.Comma] = VKEY_OEM_COMMA,
[Key.Period] = VKEY_OEM_PERIOD,
[Key.Apostrophe] = VKEY_OEM_7,
[Key.Slash] = VKEY_OEM_2,
[Key.BackSlash] = VKEY_OEM_5,
[Key.Tilde] = VKEY_OEM_3,
[Key.Equal] = VKEY_OEM_PLUS,
[Key.Space] = VKEY_SPACE,
[Key.Return] = VKEY_RETURN,
[Key.BackSpace] = VKEY_BACK,
[Key.Tab] = VKEY_TAB,
[Key.PageUp] = VKEY_PRIOR,
[Key.PageDown] = VKEY_NEXT,
[Key.End] = VKEY_END,
[Key.Home] = VKEY_HOME,
[Key.Insert] = VKEY_INSERT,
[Key.Delete] = VKEY_DELETE,
[Key.Minus] = VKEY_OEM_MINUS,
[Key.NumpadAdd] = VKEY_ADD,
[Key.NumpadSubtract] = VKEY_SUBTRACT,
[Key.NumpadDivide] = VKEY_DIVIDE,
[Key.NumpadMultiply] = VKEY_MULTIPLY,
[Key.NumpadDecimal] = VKEY_DECIMAL,
[Key.Left] = VKEY_LEFT,
[Key.Right] = VKEY_RIGHT,
[Key.Up] = VKEY_UP,
[Key.Down] = VKEY_DOWN,
[Key.F1] = VKEY_F1,
[Key.F2] = VKEY_F2,
[Key.F3] = VKEY_F3,
[Key.F4] = VKEY_F4,
[Key.F5] = VKEY_F5,
[Key.F6] = VKEY_F6,
[Key.F7] = VKEY_F7,
[Key.F8] = VKEY_F8,
[Key.F9] = VKEY_F9,
[Key.F10] = VKEY_F10,
[Key.F11] = VKEY_F11,
[Key.F12] = VKEY_F12,
[Key.F13] = VKEY_F13,
[Key.F14] = VKEY_F14,
[Key.F15] = VKEY_F15,
[Key.Pause] = VKEY_PAUSE,
};
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IInputManager _inputMgr = default!;
public readonly WebViewControl Owner;
public ControlImpl(WebViewControl owner)
{
Owner = owner;
}
private const int ScrollSpeed = 50;
private readonly RobustRequestHandler _requestHandler = new(Logger.GetSawmill("root"));
private LiveData? _data;
private string _startUrl = "about:blank";
public string Url
{
get => _data == null ? _startUrl : _data.Browser.GetMainFrame().Url;
set
{
if (_data == null)
_startUrl = value;
else
_data.Browser.GetMainFrame().LoadUrl(value);
}
}
public bool IsLoading => _data?.Browser.IsLoading ?? false;
public void EnteredTree()
{
DebugTools.AssertNull(_data);
// A funny render handler that will allow us to render to the control.
var renderer = new ControlRenderHandler(this);
// A funny web cef client. This can actually be shared by multiple browsers, but I'm not sure how the
// rendering would work in that case? TODO CEF: Investigate a way to share the web client?
var client = new RobustCefClient(renderer, _requestHandler, new RobustLoadHandler());
var info = CefWindowInfo.Create();
// FUNFACT: If you DO NOT set these below and set info.Width/info.Height instead, you get an external window
// Good to know, huh? Setup is the same, except you can pass a dummy render handler to the CEF client.
info.SetAsWindowless(IntPtr.Zero, false); // TODO CEF: Pass parent handle?
info.WindowlessRenderingEnabled = true;
var settings = new CefBrowserSettings()
{
WindowlessFrameRate = 60
};
// Create the web browser! And by default, we go to about:blank.
var browser = CefBrowserHost.CreateBrowserSync(info, client, settings, _startUrl);
var texture = _clyde.CreateBlankTexture<Bgra32>(Vector2i.One);
_data = new LiveData(texture, client, browser, renderer);
}
public void ExitedTree()
{
DebugTools.AssertNotNull(_data);
_data!.Texture.Dispose();
_data.Browser.GetHost().CloseBrowser(true);
_data = null;
}
public void MouseMove(GUIMouseMoveEventArgs args)
{
if (_data == null)
return;
// Logger.Debug();
var modifiers = CalcMouseModifiers();
var mouseEvent = new CefMouseEvent(
(int)args.RelativePosition.X, (int)args.RelativePosition.Y,
modifiers);
_data.Browser.GetHost().SendMouseMoveEvent(mouseEvent, false);
}
public void MouseExited()
{
if (_data == null)
return;
var modifiers = CalcMouseModifiers();
_data.Browser.GetHost().SendMouseMoveEvent(new CefMouseEvent(0, 0, modifiers), true);
}
public void MouseWheel(GUIMouseWheelEventArgs args)
{
if (_data == null)
return;
var modifiers = CalcMouseModifiers();
var mouseEvent = new CefMouseEvent(
(int)args.RelativePosition.X, (int)args.RelativePosition.Y,
modifiers);
_data.Browser.GetHost().SendMouseWheelEvent(
mouseEvent,
(int)args.Delta.X * ScrollSpeed,
(int)args.Delta.Y * ScrollSpeed);
}
public bool RawKeyEvent(in GuiRawKeyEvent guiRawEvent)
{
if (_data == null)
return false;
var host = _data.Browser.GetHost();
if (guiRawEvent.Key is Key.MouseLeft or Key.MouseMiddle or Key.MouseRight)
{
var key = guiRawEvent.Key switch
{
Key.MouseLeft => CefMouseButtonType.Left,
Key.MouseMiddle => CefMouseButtonType.Middle,
Key.MouseRight => CefMouseButtonType.Right,
_ => default // not possible
};
var mouseEvent = new CefMouseEvent(
guiRawEvent.MouseRelative.X, guiRawEvent.MouseRelative.Y,
CefEventFlags.None);
// Logger.Debug($"MOUSE: {guiRawEvent.Action} {guiRawEvent.Key} {guiRawEvent.ScanCode} {key}");
// TODO: double click support?
host.SendMouseClickEvent(mouseEvent, key, guiRawEvent.Action == RawKeyAction.Up, 1);
}
else
{
// TODO: Handle left/right modifier keys??
if (!KeyMap.TryGetValue(guiRawEvent.Key, out var vkKey))
vkKey = default;
// Logger.Debug($"{guiRawEvent.Action} {guiRawEvent.Key} {guiRawEvent.ScanCode} {vkKey}");
var lParam = 0;
lParam |= (guiRawEvent.ScanCode & 0xFF) << 16;
if (guiRawEvent.Action != RawKeyAction.Down)
lParam |= 1 << 30;
if (guiRawEvent.Action == RawKeyAction.Up)
lParam |= 1 << 31;
var modifiers = CalcModifiers(guiRawEvent.Key);
host.SendKeyEvent(new CefKeyEvent
{
// Repeats are sent as key downs, I guess?
EventType = guiRawEvent.Action == RawKeyAction.Up
? CefKeyEventType.KeyUp
: CefKeyEventType.RawKeyDown,
NativeKeyCode = lParam,
// NativeKeyCode = guiRawEvent.ScanCode,
WindowsKeyCode = (int)vkKey,
IsSystemKey = false, // TODO
Modifiers = modifiers
});
if (guiRawEvent.Action != RawKeyAction.Up && guiRawEvent.Key == Key.Return)
{
host.SendKeyEvent(new CefKeyEvent
{
EventType = CefKeyEventType.Char,
WindowsKeyCode = '\r',
NativeKeyCode = lParam,
Modifiers = modifiers
});
}
}
return true;
}
private CefEventFlags CalcModifiers(Key key)
{
CefEventFlags modifiers = default;
if (_inputMgr.IsKeyDown(Key.Control))
modifiers |= CefEventFlags.ControlDown;
if (_inputMgr.IsKeyDown(Key.Alt))
modifiers |= CefEventFlags.AltDown;
if (_inputMgr.IsKeyDown(Key.Shift))
modifiers |= CefEventFlags.ShiftDown;
if (_inputMgr.IsKeyDown(Key.Shift))
modifiers |= CefEventFlags.ShiftDown;
return modifiers;
}
private CefEventFlags CalcMouseModifiers()
{
CefEventFlags modifiers = default;
if (_inputMgr.IsKeyDown(Key.Control))
modifiers |= CefEventFlags.ControlDown;
if (_inputMgr.IsKeyDown(Key.Alt))
modifiers |= CefEventFlags.AltDown;
if (_inputMgr.IsKeyDown(Key.Shift))
modifiers |= CefEventFlags.ShiftDown;
if (_inputMgr.IsKeyDown(Key.Shift))
modifiers |= CefEventFlags.ShiftDown;
if (_inputMgr.IsKeyDown(Key.MouseLeft))
modifiers |= CefEventFlags.LeftMouseButton;
if (_inputMgr.IsKeyDown(Key.MouseMiddle))
modifiers |= CefEventFlags.MiddleMouseButton;
if (_inputMgr.IsKeyDown(Key.MouseRight))
modifiers |= CefEventFlags.RightMouseButton;
return modifiers;
}
public void TextEntered(GUITextEventArgs args)
{
if (_data == null)
return;
var host = _data.Browser.GetHost();
Span<char> buf = stackalloc char[2];
var written = args.AsRune.EncodeToUtf16(buf);
for (var i = 0; i < written; i++)
{
host.SendKeyEvent(new CefKeyEvent
{
EventType = CefKeyEventType.Char,
WindowsKeyCode = buf[i],
Character = buf[i],
UnmodifiedCharacter = buf[i]
});
}
}
public void Resized()
{
if (_data == null)
return;
_data.Browser.GetHost().NotifyMoveOrResizeStarted();
_data.Browser.GetHost().WasResized();
_data.Texture.Dispose();
_data.Texture = _clyde.CreateBlankTexture<Bgra32>((Owner.PixelWidth, Owner.PixelHeight));
}
public void Draw(DrawingHandleScreen handle)
{
if (_data == null)
return;
var bufImg = _data.Renderer.Buffer.Buffer;
_data.Texture.SetSubImage(
Vector2i.Zero,
bufImg,
new UIBox2i(
0, 0,
Math.Min(Owner.PixelWidth, bufImg.Width),
Math.Min(Owner.PixelHeight, bufImg.Height)));
handle.DrawTexture(_data.Texture, Vector2.Zero);
}
public void StopLoad()
{
if (_data == null)
throw new InvalidOperationException();
_data.Browser.StopLoad();
}
public void Reload()
{
if (_data == null)
throw new InvalidOperationException();
_data.Browser.Reload();
}
public bool GoBack()
{
if (_data == null)
throw new InvalidOperationException();
if (!_data.Browser.CanGoBack)
return false;
_data.Browser.GoBack();
return true;
}
public bool GoForward()
{
if (_data == null)
throw new InvalidOperationException();
if (!_data.Browser.CanGoForward)
return false;
_data.Browser.GoForward();
return true;
}
public void ExecuteJavaScript(string code)
{
if (_data == null)
throw new InvalidOperationException();
// TODO: this should not run until the browser is done loading seriously does this even work?
_data.Browser.GetMainFrame().ExecuteJavaScript(code, string.Empty, 1);
}
public void AddResourceRequestHandler(Action<IRequestHandlerContext> handler)
{
_requestHandler.AddResourceRequestHandler(handler);
}
public void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler)
{
_requestHandler.RemoveResourceRequestHandler(handler);
}
public void AddBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
{
_requestHandler.AddBeforeBrowseHandler(handler);
}
public void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
{
_requestHandler.RemoveBeforeBrowseHandler(handler);
}
private sealed class LiveData
{
public OwnedTexture Texture;
public readonly RobustCefClient Client;
public readonly CefBrowser Browser;
public readonly ControlRenderHandler Renderer;
public LiveData(
OwnedTexture texture,
RobustCefClient client,
CefBrowser browser,
ControlRenderHandler renderer)
{
Texture = texture;
Client = client;
Browser = browser;
Renderer = renderer;
}
}
}
private sealed class ControlRenderHandler : CefRenderHandler
{
public ImageBuffer Buffer { get; }
private ControlImpl _control;
internal ControlRenderHandler(ControlImpl control)
{
Buffer = new ImageBuffer();
_control = control;
}
protected override CefAccessibilityHandler? GetAccessibilityHandler() => null;
protected override void GetViewRect(CefBrowser browser, out CefRectangle rect)
{
if (_control.Owner.Disposed)
{
rect = new CefRectangle();
return;
}
// TODO CEF: Do we need to pass real screen coords? Cause what we do already works...
//var screenCoords = _control.ScreenCoordinates;
//rect = new CefRectangle((int) screenCoords.X, (int) screenCoords.Y, (int)Math.Max(_control.Size.X, 1), (int)Math.Max(_control.Size.Y, 1));
// We do the max between size and 1 because it will LITERALLY CRASH WITHOUT AN ERROR otherwise.
rect = new CefRectangle(
0, 0,
(int)Math.Max(_control.Owner.Size.X, 1), (int)Math.Max(_control.Owner.Size.Y, 1));
}
protected override bool GetScreenInfo(CefBrowser browser, CefScreenInfo screenInfo)
{
if (_control.Owner.Disposed)
return false;
// TODO CEF: Get actual scale factor?
screenInfo.DeviceScaleFactor = 1.0f;
return true;
}
protected override void OnPopupSize(CefBrowser browser, CefRectangle rect)
{
if (_control.Owner.Disposed)
return;
}
protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects,
IntPtr buffer, int width, int height)
{
if (_control.Owner.Disposed)
return;
foreach (var dirtyRect in dirtyRects)
{
Buffer.UpdateBuffer(width, height, buffer, dirtyRect);
}
}
protected override void OnAcceleratedPaint(CefBrowser browser, CefPaintElementType type,
CefRectangle[] dirtyRects, IntPtr sharedHandle)
{
// Unused, but we're forced to implement it so.. NOOP.
}
protected override void OnScrollOffsetChanged(CefBrowser browser, double x, double y)
{
if (_control.Owner.Disposed)
return;
}
protected override void OnImeCompositionRangeChanged(CefBrowser browser, CefRange selectedRange,
CefRectangle[] characterBounds)
{
if (_control.Owner.Disposed)
return;
}
}
}
}

View File

@@ -0,0 +1,101 @@
using System;
using System.IO;
using Robust.Shared.ContentPack;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Xilium.CefGlue;
namespace Robust.Client.WebView.Cef
{
internal partial class WebViewManagerCef : IWebViewManagerImpl
{
private CefApp _app = default!;
[Dependency] private readonly IDependencyCollection _dependencyCollection = default!;
public void Initialize()
{
IoCManager.Instance!.InjectDependencies(this, oneOff: true);
string subProcessName;
if (OperatingSystem.IsWindows())
subProcessName = "Robust.Client.WebView.exe";
else if (OperatingSystem.IsLinux())
subProcessName = "Robust.Client.WebView";
else
throw new NotSupportedException("Unsupported platform for CEF!");
var subProcessPath = PathHelpers.ExecutableRelativeFile(subProcessName);
var cefResourcesPath = LocateCefResources();
// System.Console.WriteLine(AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES"));
if (cefResourcesPath == null)
throw new InvalidOperationException("Unable to locate cef_resources directory!");
var settings = new CefSettings()
{
WindowlessRenderingEnabled = true, // So we can render to our UI controls.
ExternalMessagePump = false, // Unsure, honestly. TODO CEF: Research this?
NoSandbox = true, // Not disabling the sandbox crashes CEF.
BrowserSubprocessPath = subProcessPath,
LocalesDirPath = Path.Combine(cefResourcesPath, "locales"),
ResourcesDirPath = cefResourcesPath,
RemoteDebuggingPort = 9222,
};
Logger.Info($"CEF Version: {CefRuntime.ChromeVersion}");
_app = new RobustCefApp();
// We pass no main arguments...
CefRuntime.Initialize(new CefMainArgs(null), settings, _app, IntPtr.Zero);
// 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.
}
private static string? LocateCefResources()
{
if (ProbeDir(PathHelpers.GetExecutableDirectory(), out var path))
return path;
foreach (var searchDir in NativeDllSearchDirectories())
{
if (ProbeDir(searchDir, out path))
return path;
}
return null;
static bool ProbeDir(string dir, out string path)
{
path = Path.Combine(dir, "cef_resources");
return Directory.Exists(path);
}
}
internal static string[] NativeDllSearchDirectories()
{
var sepChar = OperatingSystem.IsWindows() ? ';' : ':';
var searchDirectories = ((string)AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES")!)
.Split(sepChar, StringSplitOptions.RemoveEmptyEntries);
return searchDirectories;
}
public void Update()
{
// Calling this makes CEF do its work, without using its own update loop.
CefRuntime.DoMessageLoopWork();
}
public void Shutdown()
{
CefRuntime.Shutdown();
}
}
}

View File

@@ -0,0 +1,127 @@
using System;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
namespace Robust.Client.WebView.Headless
{
internal sealed class WebViewManagerHeadless : IWebViewManagerImpl
{
public IWebViewWindow CreateBrowserWindow(BrowserWindowCreateParameters createParams)
{
return new WebViewWindowDummy();
}
public IWebViewControlImpl MakeControlImpl(WebViewControl owner)
{
return new WebViewControlImplDummy();
}
public void Initialize()
{
// Nop
}
public void Update()
{
// Nop
}
public void Shutdown()
{
// Nop
}
private abstract class DummyBase : IWebViewControl
{
public string Url { get; set; } = "about:blank";
public bool IsLoading => true;
public void StopLoad()
{
}
public void Reload()
{
}
public bool GoBack()
{
return false;
}
public bool GoForward()
{
return false;
}
public void ExecuteJavaScript(string code)
{
}
public void AddResourceRequestHandler(Action<IRequestHandlerContext> handler)
{
}
public void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler)
{
}
}
private sealed class WebViewControlImplDummy : DummyBase, IWebViewControlImpl
{
public void EnteredTree()
{
}
public void ExitedTree()
{
}
public void MouseMove(GUIMouseMoveEventArgs args)
{
}
public void MouseExited()
{
}
public void MouseWheel(GUIMouseWheelEventArgs args)
{
}
public bool RawKeyEvent(in GuiRawKeyEvent guiRawEvent)
{
return false;
}
public void TextEntered(GUITextEventArgs args)
{
}
public void Resized()
{
}
public void Draw(DrawingHandleScreen handle)
{
}
public void AddBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
{
}
public void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
{
}
}
private sealed class WebViewWindowDummy : DummyBase, IWebViewWindow
{
public void Dispose()
{
}
public bool Closed => false;
}
}
}

View File

@@ -0,0 +1,12 @@
namespace Robust.Client.WebView
{
public interface IBeforeBrowseContext
{
string Url { get; }
string Method { get; }
bool IsRedirect { get; }
bool UserGesture { get; }
bool IsCancelled { get; }
void DoCancel();
}
}

View File

@@ -0,0 +1,18 @@
using System.IO;
using System.Net;
namespace Robust.Client.WebView
{
public interface IRequestHandlerContext
{
bool IsNavigation { get; }
bool IsDownload { get; }
string RequestInitiator { get; }
string Url { get; }
string Method { get; }
bool IsHandled { get; }
bool IsCancelled { get; }
void DoCancel();
void DoRespondStream(Stream stream, string contentType, HttpStatusCode code = HttpStatusCode.OK);
}
}

View File

@@ -1,8 +1,9 @@
using System;
using Robust.Client.WebView.Cef;
namespace Robust.Client.CEF
namespace Robust.Client.WebView
{
public interface IBrowserControl
public interface IWebViewControl
{
/// <summary>
/// Current URL of the browser. Set to load a new page.
@@ -42,7 +43,7 @@ namespace Robust.Client.CEF
/// <param name="code">JavaScript code.</param>
void ExecuteJavaScript(string code);
void AddResourceRequestHandler(Action<RequestHandlerContext> handler);
void RemoveResourceRequestHandler(Action<RequestHandlerContext> handler);
void AddResourceRequestHandler(Action<IRequestHandlerContext> handler);
void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler);
}
}

View File

@@ -0,0 +1,24 @@
using System;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
namespace Robust.Client.WebView
{
/// <summary>
/// Internal swappable implementation of <see cref="WebViewControl"/>.
/// </summary>
internal interface IWebViewControlImpl : IWebViewControl
{
void EnteredTree();
void ExitedTree();
void MouseMove(GUIMouseMoveEventArgs args);
void MouseExited();
void MouseWheel(GUIMouseWheelEventArgs args);
bool RawKeyEvent(in GuiRawKeyEvent guiRawEvent);
void TextEntered(GUITextEventArgs args);
void Resized();
void Draw(DrawingHandleScreen handle);
void AddBeforeBrowseHandler(Action<IBeforeBrowseContext> handler);
void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler);
}
}

View File

@@ -0,0 +1,7 @@
namespace Robust.Client.WebView
{
public interface IWebViewManager
{
IWebViewWindow CreateBrowserWindow(BrowserWindowCreateParameters createParams);
}
}

View File

@@ -0,0 +1,14 @@
using Robust.Client.WebViewHook;
namespace Robust.Client.WebView
{
/// <summary>
/// Internal implementation of WebViewManager that is switched out by <see cref="IWebViewManagerHook"/>.
/// </summary>
internal interface IWebViewManagerImpl : IWebViewManagerInternal
{
void Initialize();
void Update();
void Shutdown();
}
}

View File

@@ -0,0 +1,7 @@
namespace Robust.Client.WebView
{
internal interface IWebViewManagerInternal : IWebViewManager
{
IWebViewControlImpl MakeControlImpl(WebViewControl owner);
}
}

View File

@@ -0,0 +1,9 @@
using System;
namespace Robust.Client.WebView
{
public interface IWebViewWindow : IWebViewControl, IDisposable
{
bool Closed { get; }
}
}

View File

@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\MSBuild\Robust.Properties.targets" />
<Import Project="..\MSBuild\Robust.Engine.props" />
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputType>WinExe</OutputType>
</PropertyGroup>
<Import Project="..\MSBuild\Robust.DefineConstants.targets" />
<Target Name="RobustAfterBuild" AfterTargets="Build" />
<Import Project="..\MSBuild\Robust.Engine.targets" />
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
<PackageReference Include="Robust.Natives.Cef" Version="95.7.14" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\cefglue\CefGlue\CefGlue.csproj" />
<ProjectReference Include="..\Robust.Client\Robust.Client.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,145 @@
using System;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.WebView.Cef;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
namespace Robust.Client.WebView
{
/// <summary>
/// An UI control that presents web content.
/// </summary>
public sealed class WebViewControl : Control, IWebViewControl, IRawInputControl
{
[Dependency] private readonly IWebViewManagerInternal _webViewManager = default!;
private readonly IWebViewControlImpl _controlImpl;
[ViewVariables(VVAccess.ReadWrite)]
public string Url
{
get => _controlImpl.Url;
set => _controlImpl.Url = value;
}
[ViewVariables] public bool IsLoading => _controlImpl.IsLoading;
public WebViewControl()
{
CanKeyboardFocus = true;
KeyboardFocusOnClick = true;
MouseFilter = MouseFilterMode.Stop;
IoCManager.InjectDependencies(this);
_controlImpl = _webViewManager.MakeControlImpl(this);
}
protected override void EnteredTree()
{
base.EnteredTree();
_controlImpl.EnteredTree();
}
protected override void ExitedTree()
{
base.ExitedTree();
_controlImpl.ExitedTree();
}
protected internal override void MouseMove(GUIMouseMoveEventArgs args)
{
base.MouseMove(args);
_controlImpl.MouseMove(args);
}
protected internal override void MouseExited()
{
base.MouseExited();
_controlImpl.MouseExited();
}
protected internal override void MouseWheel(GUIMouseWheelEventArgs args)
{
base.MouseWheel(args);
_controlImpl.MouseWheel(args);
}
bool IRawInputControl.RawKeyEvent(in GuiRawKeyEvent guiRawEvent)
{
return _controlImpl.RawKeyEvent(guiRawEvent);
}
protected internal override void TextEntered(GUITextEventArgs args)
{
base.TextEntered(args);
_controlImpl.TextEntered(args);
}
protected override void Resized()
{
base.Resized();
_controlImpl.Resized();
}
protected internal override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
_controlImpl.Draw(handle);
}
public void StopLoad()
{
_controlImpl.StopLoad();
}
public void Reload()
{
_controlImpl.Reload();
}
public bool GoBack()
{
return _controlImpl.GoBack();
}
public bool GoForward()
{
return _controlImpl.GoForward();
}
public void ExecuteJavaScript(string code)
{
_controlImpl.ExecuteJavaScript(code);
}
public void AddResourceRequestHandler(Action<IRequestHandlerContext> handler)
{
_controlImpl.AddResourceRequestHandler(handler);
}
public void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler)
{
_controlImpl.RemoveResourceRequestHandler(handler);
}
public void AddBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
{
_controlImpl.AddBeforeBrowseHandler(handler);
}
public void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
{
_controlImpl.RemoveBeforeBrowseHandler(handler);
}
}
}

View File

@@ -0,0 +1,59 @@
using Robust.Client.WebView;
using Robust.Client.WebView.Cef;
using Robust.Client.WebView.Headless;
using Robust.Client.WebViewHook;
using Robust.Shared.IoC;
using Robust.Shared.Utility;
[assembly: WebViewManagerImpl(typeof(WebViewManager))]
namespace Robust.Client.WebView
{
internal sealed class WebViewManager : IWebViewManagerInternal, IWebViewManagerHook
{
private IWebViewManagerImpl? _impl;
public void Initialize(GameController.DisplayMode mode)
{
DebugTools.Assert(_impl == null, "WebViewManager has already been initialized!");
IoCManager.RegisterInstance<IWebViewManager>(this);
IoCManager.RegisterInstance<IWebViewManagerInternal>(this);
if (mode == GameController.DisplayMode.Headless)
_impl = new WebViewManagerHeadless();
else
_impl = new WebViewManagerCef();
_impl.Initialize();
}
public void Update()
{
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
_impl!.Update();
}
public void Shutdown()
{
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
_impl!.Shutdown();
}
public IWebViewWindow CreateBrowserWindow(BrowserWindowCreateParameters createParams)
{
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
return _impl!.CreateBrowserWindow(createParams);
}
public IWebViewControlImpl MakeControlImpl(WebViewControl owner)
{
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
return _impl!.MakeControlImpl(owner);
}
}
}

View File

@@ -65,7 +65,7 @@ namespace Robust.Client.Audio.Midi
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IConfigurationManager _cfgMan = default!;
private SharedBroadphaseSystem _broadPhaseSystem = default!;
private SharedPhysicsSystem _broadPhaseSystem = default!;
[ViewVariables]
public bool IsAvailable
@@ -88,6 +88,7 @@ namespace Robust.Client.Audio.Midi
private float _volume = 0f;
private bool _volumeDirty = true;
// Not reliable until Fluidsynth is initialized!
[ViewVariables(VVAccess.ReadWrite)]
public float Volume
{
@@ -134,6 +135,7 @@ namespace Robust.Client.Audio.Midi
{
if (FluidsynthInitialized || _failedInitialize) return;
_volume = _cfgMan.GetCVar(CVars.MidiVolume);
_cfgMan.OnValueChanged(CVars.MidiVolume, value =>
{
_volume = value;
@@ -175,7 +177,7 @@ namespace Robust.Client.Audio.Midi
_midiThread = new Thread(ThreadUpdate);
_midiThread.Start();
_broadPhaseSystem = EntitySystem.Get<SharedBroadphaseSystem>();
_broadPhaseSystem = EntitySystem.Get<SharedPhysicsSystem>();
FluidsynthInitialized = true;
}
@@ -254,11 +256,12 @@ namespace Robust.Client.Audio.Midi
renderer.LoadSoundfont(WindowsSoundfont, true);
}
renderer.Source.SetVolume(Volume);
lock (_renderers)
{
_renderers.Add(renderer);
}
return renderer;
}
finally

View File

@@ -37,6 +37,11 @@ namespace Robust.Client.Audio.Midi
/// </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>
@@ -297,6 +302,9 @@ namespace Robust.Client.Audio.Midi
}
}
[ViewVariables(VVAccess.ReadWrite)]
public bool VolumeBoost { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public IEntity? TrackingEntity { get; set; } = null;
@@ -539,6 +547,8 @@ namespace Robust.Client.Audio.Midi
// Note On 0x90
case 144:
if (VolumeBoost)
midiEvent.Velocity = 127;
_synth.NoteOn(midiEvent.Channel, midiEvent.Key, midiEvent.Velocity);
break;

View File

@@ -31,7 +31,6 @@ namespace Robust.Client
[Dependency] private readonly IDiscordRichPresence _discord = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IClientGameStateManager _gameStates = default!;
[Dependency] private readonly IDebugDrawingManager _debugDrawMan = default!;
/// <inheritdoc />
public ushort DefaultPort { get; } = 1212;
@@ -57,7 +56,6 @@ namespace Robust.Client
_configManager.OnValueChanged(CVars.NetTickrate, TickRateChanged, invokeImmediately: true);
_playMan.Initialize();
_debugDrawMan.Initialize();
Reset();
}

View File

@@ -72,7 +72,6 @@ namespace Robust.Client
IoCManager.Register<IUserInterfaceManager, UserInterfaceManager>();
IoCManager.Register<IUserInterfaceManagerInternal, UserInterfaceManager>();
IoCManager.Register<IDebugDrawing, DebugDrawing>();
IoCManager.Register<IDebugDrawingManager, DebugDrawingManager>();
IoCManager.Register<ILightManager, LightManager>();
IoCManager.Register<IDiscordRichPresence, DiscordRichPresence>();
IoCManager.Register<IMidiManager, MidiManager>();

View File

@@ -188,16 +188,16 @@ namespace Robust.Client.Console.Commands
return;
}
if (!int.TryParse(args[0], out var id))
if (!float.TryParse(args[0], out var duration))
{
shell.WriteError($"{args[0]} is not a valid integer.");
shell.WriteError($"{args[0]} is not a valid float.");
return;
}
var mgr = IoCManager.Resolve<IDebugDrawingManager>();
var mgr = EntitySystem.Get<DebugRayDrawingSystem>();
mgr.DebugDrawRays = !mgr.DebugDrawRays;
shell.WriteError("Toggled showing rays to:" + mgr.DebugDrawRays.ToString());
mgr.DebugRayLifetime = TimeSpan.FromSeconds((double)int.Parse(args[0], CultureInfo.InvariantCulture));
shell.WriteError("Toggled showing rays to:" + mgr.DebugDrawRays);
mgr.DebugRayLifetime = TimeSpan.FromSeconds(duration);
}
}

View File

@@ -63,7 +63,7 @@ namespace Robust.Client.Console.Commands
var conGroup = IoCManager.Resolve<IClientConGroupController>();
foreach (var command in shell.ConsoleHost.RegisteredCommands.Values
.Where(p => p.Command.Contains(filter) && conGroup.CanCommand(p.Command))
.Where(p => p.Command.Contains(filter) && (p is not ServerDummyCommand || conGroup.CanCommand(p.Command)))
.OrderBy(c => c.Command))
{
shell.WriteLine(command.Command + ": " + command.Description);

View File

@@ -8,7 +8,7 @@ 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} <contactnormals / contactpoints / joints / shapeinfo / shapes>";
public string Help => $"{Command} <aabbs / contactnormals / contactpoints / joints / shapeinfo / shapes>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
@@ -21,6 +21,9 @@ namespace Robust.Client.Console.Commands
switch (args[0])
{
case "aabbs":
system.Flags ^= PhysicsDebugFlags.AABBs;
break;
case "contactnormals":
system.Flags ^= PhysicsDebugFlags.ContactNormals;
break;

View File

@@ -0,0 +1,127 @@
using System;
using System.Collections.Immutable;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Input;
using Robust.Shared.Maths;
using Robust.Shared.Network.Messages;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BoxContainer;
using static Robust.Shared.Network.Messages.MsgScriptCompletionResponse;
namespace Robust.Client.Console
{
public class Completions : SS14Window
{
private HistoryLineEdit _textBar;
private ScrollContainer _suggestPanel = new()
{
HScrollEnabled = false,
};
private BoxContainer _suggestBox = new()
{
Orientation = LayoutOrientation.Vertical,
HorizontalAlignment = HAlignment.Left,
};
public Completions(HistoryLineEdit textBar) : base()
{
Title = "Suggestions";
MouseFilter = MouseFilterMode.Pass;
_textBar = textBar;
_suggestPanel.AddChild(_suggestBox);
ContentsContainer.AddChild(_suggestPanel);
}
private bool _firstopen = true;
public void OpenAt(Vector2 position, Vector2 size)
{
if (_firstopen)
{
SetSize = size;
LayoutContainer.SetPosition(this, position);
_firstopen = false;
}
Open();
}
private ImmutableArray<LiteResult> _results;
public void Update()
{
_suggestBox.RemoveAllChildren();
foreach (var res in _results)
{
var label = new Entry(res);
label.OnKeyBindDown += ev =>
{
if (ev.Function == EngineKeyFunctions.UIClick)
_textBar.InsertAtCursor(label.Result.Properties["InsertionText"]);
};
_suggestBox.AddChild(label);
}
}
public void TextChanged() => Close();
public void SetSuggestions(MsgScriptCompletionResponse response)
{
_results = response.Results;
Update();
}
// Label and ghetto button.
public class Entry : RichTextLabel
{
public readonly LiteResult Result;
public Entry(LiteResult result)
{
MouseFilter = MouseFilterMode.Stop;
Result = result;
var compl = new FormattedMessage();
var dim = Color.FromHsl((0f, 0f, 0.8f, 1f));
// warning: ew ahead
string basen = "default";
if (Result.Tags.Contains("Interface"))
basen = "interface name";
else if (Result.Tags.Contains("Class"))
basen = "class name";
else if (Result.Tags.Contains("Struct"))
basen = "struct name";
else if (Result.Tags.Contains("Keyword"))
basen = "keyword";
else if (Result.Tags.Contains("Namespace"))
basen = "namespace name";
else if (Result.Tags.Contains("Method"))
basen = "method name";
else if (Result.Tags.Contains("Property"))
basen = "property name";
else if (Result.Tags.Contains("Field"))
basen = "field name";
Color basec = ScriptingColorScheme.ColorScheme[basen];
compl.PushColor(basec * dim);
compl.AddText(Result.DisplayTextPrefix);
compl.PushColor(basec);
compl.AddText(Result.DisplayText);
compl.PushColor(basec * dim);
compl.AddText(Result.DisplayTextSuffix);
compl.AddText(" [" + String.Join(", ", Result.Tags) + "]");
if (Result.InlineDescription.Length != 0)
{
compl.PushNewline();
compl.AddText(": ");
compl.PushColor(Color.LightSlateGray);
compl.AddText(Result.InlineDescription);
}
SetMessage(compl);
}
}
}
}

View File

@@ -46,6 +46,16 @@ namespace Robust.Client.Console
}
protected override void Complete()
{
var msg = _client._netManager.CreateNetMessage<MsgScriptCompletion>();
msg.ScriptSession = _session;
msg.Code = InputBar.Text;
msg.Cursor = InputBar.CursorPosition;
_client._netManager.ClientSendMessage(msg);
}
public override void Close()
{
base.Close();
@@ -95,6 +105,12 @@ namespace Robust.Client.Console
OutputPanel.AddText(">");
}
public void ReceiveCompletionResponse(MsgScriptCompletionResponse response)
{
Suggestions.SetSuggestions(response);
Suggestions.OpenAt((Position.X + Size.X, Position.Y), (Size.X / 2, Size.Y));
}
}
}
}

View File

@@ -20,6 +20,8 @@ namespace Robust.Client.Console
_netManager.RegisterNetMessage<MsgScriptStop>();
_netManager.RegisterNetMessage<MsgScriptEval>();
_netManager.RegisterNetMessage<MsgScriptStart>();
_netManager.RegisterNetMessage<MsgScriptCompletion>();
_netManager.RegisterNetMessage<MsgScriptCompletionResponse>(ReceiveScriptCompletionResponse);
_netManager.RegisterNetMessage<MsgScriptResponse>(ReceiveScriptResponse);
_netManager.RegisterNetMessage<MsgScriptStartAck>(ReceiveScriptStartAckResponse);
}
@@ -44,6 +46,16 @@ namespace Robust.Client.Console
console.ReceiveResponse(message);
}
private void ReceiveScriptCompletionResponse(MsgScriptCompletionResponse message)
{
if (!_activeConsoles.TryGetValue(message.ScriptSession, out var console))
{
return;
}
console.ReceiveCompletionResponse(message);
}
public bool CanScript => _conGroupController.CanScript();
public void StartSession()

View File

@@ -53,6 +53,9 @@ namespace Robust.Client.Console
OutputPanel.AddText(">");
}
// No-op for now.
protected override void Complete() { }
protected override async void Run()
{
var code = InputBar.Text;

View File

@@ -90,7 +90,7 @@ namespace Robust.Client.Debugging
IoCManager.Resolve<IInputManager>(),
IoCManager.Resolve<IResourceCache>(),
this,
Get<SharedBroadphaseSystem>()));
Get<SharedPhysicsSystem>()));
if (value == PhysicsDebugFlags.None)
IoCManager.Resolve<IOverlayManager>().RemoveOverlay(typeof(PhysicsDebugOverlay));
@@ -161,6 +161,7 @@ namespace Robust.Client.Debugging
Shapes = 1 << 2,
ShapeInfo = 1 << 3,
Joints = 1 << 4,
AABBs = 1 << 5,
}
internal sealed class PhysicsDebugOverlay : Overlay
@@ -168,8 +169,8 @@ namespace Robust.Client.Debugging
private IEntityManager _entityManager = default!;
private IEyeManager _eyeManager = default!;
private IInputManager _inputManager = default!;
private DebugPhysicsSystem _physics = default!;
private SharedBroadphaseSystem _broadphaseSystem = default!;
private DebugPhysicsSystem _debugPhysicsSystem = default!;
private SharedPhysicsSystem _physicsSystem = default!;
public override OverlaySpace Space => OverlaySpace.WorldSpace | OverlaySpace.ScreenSpace;
@@ -179,13 +180,13 @@ namespace Robust.Client.Debugging
private HashSet<Joint> _drawnJoints = new();
public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IResourceCache cache, DebugPhysicsSystem system, SharedBroadphaseSystem broadphaseSystem)
public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IResourceCache cache, DebugPhysicsSystem system, SharedPhysicsSystem physicsSystem)
{
_entityManager = entityManager;
_eyeManager = eyeManager;
_inputManager = inputManager;
_physics = system;
_broadphaseSystem = broadphaseSystem;
_debugPhysicsSystem = system;
_physicsSystem = physicsSystem;
_font = new VectorFont(cache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
}
@@ -195,9 +196,9 @@ namespace Robust.Client.Debugging
var viewBounds = _eyeManager.GetWorldViewbounds();
var mapId = _eyeManager.CurrentMap;
if ((_physics.Flags & PhysicsDebugFlags.Shapes) != 0 && !viewport.IsEmpty())
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.Shapes) != 0 && !viewport.IsEmpty())
{
foreach (var physBody in _broadphaseSystem.GetCollidingEntities(mapId, viewBounds))
foreach (var physBody in _physicsSystem.GetCollidingEntities(mapId, viewBounds))
{
if (physBody.Owner.HasComponent<MapGridComponent>()) continue;
@@ -236,7 +237,33 @@ namespace Robust.Client.Debugging
}
}
if ((_physics.Flags & PhysicsDebugFlags.Joints) != 0x0)
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.AABBs) != 0 && !viewport.IsEmpty())
{
foreach (var physBody in _physicsSystem.GetCollidingEntities(mapId, viewBounds))
{
if (physBody.Owner.HasComponent<MapGridComponent>()) continue;
var xform = physBody.GetTransform();
const float AlphaModifier = 0.2f;
Box2? aabb = null;
foreach (var fixture in physBody.Fixtures)
{
for (var i = 0; i < fixture.Shape.ChildCount; i++)
{
var shapeBB = fixture.Shape.ComputeAABB(xform, i);
aabb = aabb?.Union(shapeBB) ?? shapeBB;
}
}
if (aabb == null) continue;
worldHandle.DrawRect(aabb.Value, Color.Red.WithAlpha(AlphaModifier), false);
}
}
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.Joints) != 0x0)
{
_drawnJoints.Clear();
@@ -255,17 +282,17 @@ namespace Robust.Client.Debugging
}
}
if ((_physics.Flags & (PhysicsDebugFlags.ContactPoints | PhysicsDebugFlags.ContactNormals)) != 0)
if ((_debugPhysicsSystem.Flags & (PhysicsDebugFlags.ContactPoints | PhysicsDebugFlags.ContactNormals)) != 0)
{
const float axisScale = 0.3f;
for (var i = 0; i < _physics.PointCount; ++i)
for (var i = 0; i < _debugPhysicsSystem.PointCount; ++i)
{
var point = _physics.Points[i];
var point = _debugPhysicsSystem.Points[i];
const float radius = 0.1f;
if ((_physics.Flags & PhysicsDebugFlags.ContactPoints) != 0)
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.ContactPoints) != 0)
{
if (point.State == PointState.Add)
worldHandle.DrawCircle(point.Position, radius, new Color(255, 77, 243, 255));
@@ -273,7 +300,7 @@ namespace Robust.Client.Debugging
worldHandle.DrawCircle(point.Position, radius, new Color(255, 77, 77, 255));
}
if ((_physics.Flags & PhysicsDebugFlags.ContactNormals) != 0)
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.ContactNormals) != 0)
{
Vector2 p1 = point.Position;
Vector2 p2 = p1 + point.Normal * axisScale;
@@ -281,7 +308,7 @@ namespace Robust.Client.Debugging
}
}
_physics.PointCount = 0;
_debugPhysicsSystem.PointCount = 0;
}
}
@@ -290,12 +317,12 @@ namespace Robust.Client.Debugging
var mapId = _eyeManager.CurrentMap;
var mousePos = _inputManager.MouseScreenPosition;
if ((_physics.Flags & PhysicsDebugFlags.ShapeInfo) != 0x0)
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.ShapeInfo) != 0x0)
{
var hoverBodies = new List<PhysicsComponent>();
var bounds = Box2.UnitCentered.Translated(_eyeManager.ScreenToMap(mousePos.Position).Position);
foreach (var physBody in _broadphaseSystem.GetCollidingEntities(mapId, bounds))
foreach (var physBody in _physicsSystem.GetCollidingEntities(mapId, bounds))
{
if (physBody.Owner.HasComponent<MapGridComponent>()) continue;
hoverBodies.Add(physBody);
@@ -327,7 +354,7 @@ namespace Robust.Client.Debugging
protected internal override void Draw(in OverlayDrawArgs args)
{
if (_physics.Flags == PhysicsDebugFlags.None) return;
if (_debugPhysicsSystem.Flags == PhysicsDebugFlags.None) return;
switch (args.Space)
{

View File

@@ -2,21 +2,22 @@ using System;
using System.Collections.Generic;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Network.Messages;
using Robust.Shared.Physics;
using Robust.Shared.Timing;
namespace Robust.Client.Debugging
{
internal class DebugDrawingManager : IDebugDrawingManager
internal sealed class DebugRayDrawingSystem : EntitySystem
{
[Dependency] private readonly IClientNetManager _net = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly IGameTiming _gameTimer = default!;
private readonly List<RayWithLifetime> raysWithLifeTime = new();
private readonly List<RayWithLifetime> _raysWithLifeTime = new();
private bool _debugDrawRays;
private struct RayWithLifetime
@@ -52,9 +53,30 @@ namespace Robust.Client.Debugging
public TimeSpan DebugRayLifetime { get; set; } = TimeSpan.FromSeconds(5);
public void Initialize()
public override void Initialize()
{
_net.RegisterNetMessage<MsgRay>(HandleDrawRay);
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)
{
if (!_debugDrawRays)
{
return;
}
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,
LifeTime = _gameTimer.RealTime + DebugRayLifetime
};
_raysWithLifeTime.Add(newRayWithLifetime);
}
private void HandleDrawRay(MsgRay msg)
@@ -74,15 +96,15 @@ namespace Robust.Client.Debugging
LifeTime = _gameTimer.RealTime + DebugRayLifetime
};
raysWithLifeTime.Add(newRayWithLifetime);
_raysWithLifeTime.Add(newRayWithLifetime);
}
private sealed class DebugDrawRayOverlay : Overlay
{
private readonly DebugDrawingManager _owner;
private readonly DebugRayDrawingSystem _owner;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
public DebugDrawRayOverlay(DebugDrawingManager owner)
public DebugDrawRayOverlay(DebugRayDrawingSystem owner)
{
_owner = owner;
}
@@ -90,7 +112,7 @@ namespace Robust.Client.Debugging
protected internal override void Draw(in OverlayDrawArgs args)
{
var handle = args.WorldHandle;
foreach (var ray in _owner.raysWithLifeTime)
foreach (var ray in _owner._raysWithLifeTime)
{
handle.DrawLine(
ray.RayOrigin,
@@ -103,7 +125,7 @@ namespace Robust.Client.Debugging
{
base.FrameUpdate(args);
_owner.raysWithLifeTime.RemoveAll(r => r.LifeTime < _owner._gameTimer.RealTime);
_owner._raysWithLifeTime.RemoveAll(r => r.LifeTime < _owner._gameTimer.RealTime);
}
}
}

View File

@@ -1,11 +0,0 @@
using System;
namespace Robust.Client.Debugging
{
public interface IDebugDrawingManager
{
bool DebugDrawRays { get; set; }
TimeSpan DebugRayLifetime { get; set; }
void Initialize();
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.Reflection;
using Robust.Client.WebViewHook;
using Robust.Shared.Log;
using Robust.Shared.Utility;
namespace Robust.Client
{
internal sealed partial class GameController
{
private void LoadOptionalRobustModules(GameController.DisplayMode mode)
{
// In the future, this manifest should be loaded somewhere else and used for more parts of init.
// For now, this is fine.
var manifest = LoadResourceManifest();
foreach (var module in manifest.Modules)
{
switch (module)
{
case "Robust.Client.WebView":
LoadRobustWebView(mode);
break;
default:
Logger.Error($"Unknown Robust module: {module}");
return;
}
}
}
private void LoadRobustWebView(GameController.DisplayMode mode)
{
Logger.Debug("Loading Robust.Client.WebView");
var assembly = LoadRobustModuleAssembly("Robust.Client.WebView");
var attribute = assembly.GetCustomAttribute<WebViewManagerImplAttribute>()!;
DebugTools.AssertNotNull(attribute);
var managerType = attribute.ImplementationType;
_webViewHook = (IWebViewManagerHook)Activator.CreateInstance(managerType)!;
_webViewHook.Initialize(mode);
Logger.Debug("Done initializing Robust.Client.WebView");
}
private Assembly LoadRobustModuleAssembly(string assemblyName)
{
// TODO: Launcher distribution and all that stuff.
return Assembly.Load(assemblyName);
}
}
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime;
@@ -11,12 +10,12 @@ using Robust.Client.GameStates;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Placement;
using Robust.Client.Player;
using Robust.Client.ResourceManagement;
using Robust.Client.State;
using Robust.Client.UserInterface;
using Robust.Client.Utility;
using Robust.Client.ViewVariables;
using Robust.Client.WebViewHook;
using Robust.LoaderApi;
using Robust.Shared;
using Robust.Shared.Asynchronous;
@@ -32,6 +31,7 @@ using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using YamlDotNet.RepresentationModel;
namespace Robust.Client
{
@@ -67,6 +67,8 @@ namespace Robust.Client
[Dependency] private readonly IMidiManager _midiManager = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
private IWebViewManagerHook? _webViewHook;
private CommandLineArgs? _commandLineArgs;
// Arguments for loader-load. Not used otherwise.
@@ -87,7 +89,7 @@ namespace Robust.Client
_clyde.SetWindowTitle(Options.DefaultWindowTitle);
_taskManager.Initialize();
_fontManager.SetFontDpi((uint) _configurationManager.GetCVar(CVars.DisplayFontDpi));
_fontManager.SetFontDpi((uint)_configurationManager.GetCVar(CVars.DisplayFontDpi));
// Disable load context usage on content start.
// This prevents Content.Client being loaded twice and things like csi blowing up because of it.
@@ -107,6 +109,9 @@ namespace Robust.Client
IoCManager.Resolve<ISerializationManager>().Initialize();
// Load optional Robust modules.
LoadOptionalRobustModules(displayMode);
// Call Init in game assemblies.
_modLoader.BroadcastRunLevel(ModRunLevel.PreInit);
_modLoader.BroadcastRunLevel(ModRunLevel.Init);
@@ -196,6 +201,39 @@ namespace Robust.Client
return true;
}
private ResourceManifestData LoadResourceManifest()
{
// 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>());
var yamlStream = new YamlStream();
using (stream)
{
using var streamReader = new StreamReader(stream, EncodingHelpers.UTF8);
yamlStream.Load(streamReader);
}
if (yamlStream.Documents.Count != 1 || yamlStream.Documents[0].RootNode is not YamlMappingNode mapping)
{
throw new InvalidOperationException(
"Expected a single YAML document with root mapping for /manifest.yml");
}
var modules = Array.Empty<string>();
if (mapping.TryGetNode("modules", out var modulesMap))
{
var sequence = (YamlSequenceNode)modulesMap;
modules = new string[sequence.Children.Count];
for (var i = 0; i < modules.Length; i++)
{
modules[i] = sequence[i].AsString();
}
}
return new ResourceManifestData(modules);
}
internal bool StartupSystemSplash(GameControllerOptions options, Func<ILogHandler>? logHandlerFactory)
{
Options = options;
@@ -217,8 +255,10 @@ namespace Robust.Client
System.Console.WriteLine($"LogLevel {level} does not exist!");
continue;
}
logLevel = result;
}
_logManager.GetSawmill(sawmill).Level = logLevel;
}
}
@@ -259,7 +299,7 @@ namespace Robust.Client
{
// Handle GameControllerOptions implicit CVar overrides.
_configurationManager.OverrideConVars(new []
_configurationManager.OverrideConVars(new[]
{
(CVars.DisplayWindowIconSet.Name, options.WindowIconSet.ToString()),
(CVars.DisplaySplashLogo.Name, options.SplashLogo.ToString())
@@ -271,9 +311,11 @@ namespace Robust.Client
_resourceCache.Initialize(Options.LoadConfigAndUserData ? userDataDir : null);
var mountOptions = _commandLineArgs != null
? MountOptions.Merge(_commandLineArgs.MountOptions, Options.MountOptions) : Options.MountOptions;
? MountOptions.Merge(_commandLineArgs.MountOptions, Options.MountOptions)
: Options.MountOptions;
ProgramShared.DoMounts(_resourceCache, mountOptions, Options.ContentBuildDirectory, Options.AssemblyDirectory,
ProgramShared.DoMounts(_resourceCache, mountOptions, Options.ContentBuildDirectory,
Options.AssemblyDirectory,
Options.LoadContentResources, _loaderArgs != null && !Options.ResourceMountDisabled, ContentStart);
if (_loaderArgs != null)
@@ -394,6 +436,7 @@ namespace Robust.Client
private void Update(FrameEventArgs frameEventArgs)
{
_webViewHook?.Update();
_clyde.FrameProcess(frameEventArgs);
_modLoader.BroadcastUpdate(ModUpdateLevel.FramePreEngine, frameEventArgs);
_stateManager.FrameUpdate(frameEventArgs);
@@ -442,7 +485,7 @@ namespace Robust.Client
var uh = logManager.GetSawmill("unhandled");
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
{
var message = ((Exception) args.ExceptionObject).ToString();
var message = ((Exception)args.ExceptionObject).ToString();
uh.Log(args.IsTerminating ? LogLevel.Fatal : LogLevel.Error, message);
};
@@ -485,11 +528,15 @@ namespace Robust.Client
{
_modLoader.Shutdown();
_webViewHook?.Shutdown();
_networkManager.Shutdown("Client shutting down");
_midiManager.Shutdown();
IoCManager.Resolve<IEntityLookup>().Shutdown();
_entityManager.Shutdown();
_clyde.Shutdown();
}
private sealed record ResourceManifestData(string[] Modules);
}
}

View File

@@ -52,7 +52,9 @@ namespace Robust.Client.GameObjects
/// </summary>
internal void AnimationComplete(string key)
{
#pragma warning disable 618
AnimationCompleted?.Invoke(key);
#pragma warning restore 618
}
[Obsolete("Use AnimationCompletedEvent instead")]

View File

@@ -27,7 +27,6 @@ namespace Robust.Client.GameObjects
private bool _setDrawFovOnInitialize = true;
[DataField("zoom")]
private Vector2 _setZoomOnInitialize = Vector2.One;
private Vector2 _offset = Vector2.Zero;
public IEye? Eye => _eye;
@@ -85,14 +84,11 @@ namespace Robust.Client.GameObjects
public override Vector2 Offset
{
get => _offset;
get => _eye?.Offset ?? default;
set
{
if(_offset.EqualsApprox(value))
return;
_offset = value;
UpdateEyePosition();
if (_eye != null)
_eye.Offset = value;
}
}
@@ -171,7 +167,7 @@ namespace Robust.Client.GameObjects
{
if (_eye == null) return;
var mapPos = Owner.Transform.MapPosition;
_eye.Position = new MapCoordinates(mapPos.Position + _offset, mapPos.MapId);
_eye.Position = new MapCoordinates(mapPos.Position, mapPos.MapId);
}
}
}

View File

@@ -120,6 +120,12 @@ namespace Robust.Client.GameObjects
set => _visibleNested = value;
}
/// <summary>
/// Whether this pointlight should cast shadows
/// </summary>
[DataField("castShadows")]
public bool CastShadows = true;
[DataField("nestedvisible")]
private bool _visibleNested = true;
[DataField("autoRot")]

View File

@@ -43,15 +43,6 @@ namespace Robust.Client.GameObjects
[Animatable]
Color Color { get; set; }
/// <summary>
/// Controls whether we use RSI directions to rotate, or just get angular rotation applied.
/// If true, all rotation to this sprite component is negated (that is rotation from say the owner being rotated).
/// Rotation transformations on individual layers still apply.
/// If false, all layers get locked to south and rotation is a transformation.
/// </summary>
[Obsolete("Use NoRotation and/or DirectionOverride")]
bool Directional { get; set; }
/// <summary>
/// All sprite rotation is locked, and will always be drawn upright on
/// the screen, regardless of world or view orientation.

View File

@@ -47,7 +47,7 @@ namespace Robust.Client.GameObjects
if (_visible == value) return;
_visible = value;
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new SpriteUpdateEvent());
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new SpriteUpdateEvent());
}
}
@@ -114,23 +114,6 @@ namespace Robust.Client.GameObjects
set => color = value;
}
/// <summary>
/// Controls whether we use RSI directions to rotate, or just get angular rotation applied.
/// If true, all rotation to this sprite component is negated (that is rotation from say the owner being rotated).
/// Rotation transformations on individual layers still apply.
/// If false, all layers get locked to south and rotation is a transformation.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[Obsolete("Use NoRotation and/or DirectionOverride")]
public bool Directional
{
get => _directional;
set => _directional = value;
}
[DataField("directional")]
private bool _directional = true;
[ViewVariables]
internal RenderingTreeComponent? RenderTree { get; set; } = null;
@@ -319,7 +302,7 @@ namespace Robust.Client.GameObjects
{
if (_containerOccluded == value) return;
_containerOccluded = value;
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new SpriteUpdateEvent());
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new SpriteUpdateEvent());
}
}
@@ -389,6 +372,7 @@ namespace Robust.Client.GameObjects
if (layerDatums.Count != 0)
{
LayerMap.Clear();
LayerDatums = layerDatums;
}
}
@@ -402,7 +386,6 @@ namespace Robust.Client.GameObjects
{
//deep copying things to avoid entanglement
_baseRsi = other._baseRsi;
_directional = other._directional;
_visible = other._visible;
_layerMapShared = other._layerMapShared;
color = other.color;
@@ -564,7 +547,7 @@ namespace Robust.Client.GameObjects
Logger.ErrorS(LogCategory, "Unable to load RSI '{0}'. Trace:\n{1}", rsiPath, Environment.StackTrace);
}
return AddLayer(stateId, res?.RSI);
return AddLayer(stateId, res?.RSI, newIndex);
}
public int AddLayerState(string stateId, ResourcePath rsiPath, int? newIndex = null)
@@ -1270,6 +1253,12 @@ namespace Robust.Client.GameObjects
private void RenderInternal(DrawingHandleWorld drawingHandle, Angle eyeRotation, Angle worldRotation, Vector2 worldPosition, Direction? overrideDirection)
{
// Reduce the angles to fix math shenanigans
worldRotation = worldRotation.Reduced();
if (worldRotation.Theta < 0)
worldRotation = new Angle(worldRotation.Theta + Math.Tau);
var localMatrix = GetLocalMatrix();
foreach (var layer in Layers)
@@ -1280,12 +1269,13 @@ namespace Robust.Client.GameObjects
}
var numDirs = GetLayerDirectionCount(layer);
var layerRotation = worldRotation + layer.Rotation;
CalcModelMatrix(numDirs, eyeRotation, worldRotation, worldPosition, out var modelMatrix);
CalcModelMatrix(numDirs, eyeRotation, layerRotation, worldPosition, out var modelMatrix);
Matrix3.Multiply(ref localMatrix, ref modelMatrix, out var transformMatrix);
drawingHandle.SetTransform(in transformMatrix);
RenderLayer(drawingHandle, layer, eyeRotation, worldRotation, overrideDirection);
RenderLayer(drawingHandle, layer, eyeRotation, layerRotation, overrideDirection);
}
}
@@ -1321,7 +1311,7 @@ namespace Robust.Client.GameObjects
public static Angle CalcRectWorldAngle(Angle worldAngle, int numDirections)
{
var theta = worldAngle.Theta;
var segSize = (MathF.PI * 2) / (numDirections * 2);
var segSize = (Math.PI * 2) / (numDirections * 2);
var segments = (int)(theta / segSize);
var odd = segments % 2;
var result = theta - (segments * segSize) - (odd * segSize);
@@ -1663,7 +1653,7 @@ namespace Robust.Client.GameObjects
internal void UpdateBounds()
{
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new SpriteUpdateEvent());
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new SpriteUpdateEvent());
}
/// <summary>
@@ -2061,36 +2051,35 @@ namespace Robust.Client.GameObjects
public static IEnumerable<IDirectionalTextureProvider> GetPrototypeTextures(EntityPrototype prototype, IResourceCache resourceCache)
{
return GetPrototypeTextures(prototype, resourceCache, out var _);
}
public static IEnumerable<IDirectionalTextureProvider> GetPrototypeTextures(EntityPrototype prototype, IResourceCache resourceCache, out bool noRot)
{
var results = new List<IDirectionalTextureProvider>();
noRot = false;
var icon = IconComponent.GetPrototypeIcon(prototype, resourceCache);
if (icon != null)
{
yield return icon;
yield break;
results.Add(icon);
return results;
}
if (!prototype.Components.TryGetValue("Sprite", out _))
{
yield return resourceCache.GetFallback<TextureResource>().Texture;
yield break;
results.Add(resourceCache.GetFallback<TextureResource>().Texture);
return results;
}
var dummy = new DummyIconEntity { Prototype = prototype };
var spriteComponent = dummy.AddComponent<SpriteComponent>();
if (prototype.Components.TryGetValue("Appearance", out _))
{
var appearanceComponent = dummy.AddComponent<AppearanceComponent>();
foreach (var layer in appearanceComponent.Visualizers)
{
layer.InitializeEntity(dummy);
layer.OnChangeData(appearanceComponent);
}
}
var entityManager = IoCManager.Resolve<IEntityManager>();
var dummy = entityManager.SpawnEntity(prototype.ID, MapCoordinates.Nullspace).Uid;
var spriteComponent = entityManager.EnsureComponent<SpriteComponent>(dummy);
var anyTexture = false;
foreach (var layer in spriteComponent.AllLayers)
{
if (layer.Texture != null) yield return layer.Texture;
if (layer.Texture != null)
results.Add(layer.Texture);
if (!layer.RsiState.IsValid || !layer.Visible) continue;
var rsi = layer.Rsi ?? spriteComponent.BaseRSI;
@@ -2098,14 +2087,17 @@ namespace Robust.Client.GameObjects
!rsi.TryGetState(layer.RsiState, out var state))
continue;
yield return state;
results.Add(state);
anyTexture = true;
}
dummy.Delete();
noRot = spriteComponent.NoRotation;
entityManager.DeleteEntity(dummy);
if (!anyTexture)
yield return resourceCache.GetFallback<TextureResource>().Texture;
results.Add(resourceCache.GetFallback<TextureResource>().Texture);
return results;
}
public static IRsiStateLike GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
@@ -2118,144 +2110,14 @@ namespace Robust.Client.GameObjects
return GetFallbackState(resourceCache);
}
var dummy = new DummyIconEntity { Prototype = prototype };
var spriteComponent = dummy.AddComponent<SpriteComponent>();
dummy.Delete();
var entityManager = IoCManager.Resolve<IEntityManager>();
var dummy = entityManager.SpawnEntity(prototype.ID, MapCoordinates.Nullspace).Uid;
var spriteComponent = entityManager.EnsureComponent<SpriteComponent>(dummy);
var result = spriteComponent.Icon ?? GetFallbackState(resourceCache);
entityManager.DeleteEntity(dummy);
return spriteComponent.Icon ?? GetFallbackState(resourceCache);
return result;
}
#region DummyIconEntity
private class DummyIconEntity : IEntity
{
public GameTick LastModifiedTick { get; } = GameTick.Zero;
public IEntityManager EntityManager { get; } = null!;
public string Name { get; set; } = string.Empty;
public EntityUid Uid { get; } = EntityUid.Invalid;
EntityLifeStage IEntity.LifeStage { get => _lifeStage; set => _lifeStage = value; }
public bool Initialized { get; } = false;
public bool Initializing { get; } = false;
public bool Deleted { get; } = true;
public bool Paused { get; set; }
public EntityPrototype? Prototype { get; set; }
public string Description { get; set; } = string.Empty;
public bool IsValid()
{
return false;
}
public ITransformComponent Transform { get; } = null!;
public MetaDataComponent MetaData { get; } = null!;
private Dictionary<Type, IComponent> _components = new();
private EntityLifeStage _lifeStage;
public T AddComponent<T>() where T : Component, new()
{
var typeFactory = IoCManager.Resolve<IDynamicTypeFactoryInternal>();
var serializationManager = IoCManager.Resolve<ISerializationManager>();
var comp = (T)typeFactory.CreateInstanceUnchecked(typeof(T));
_components[typeof(T)] = comp;
comp.Owner = this;
if (typeof(ISpriteComponent).IsAssignableFrom(typeof(T)))
{
_components[typeof(ISpriteComponent)] = comp;
}
if (Prototype != null && Prototype.TryGetComponent<T>(comp.Name, out var node))
{
comp = serializationManager.Copy(node, comp)!;
}
return comp;
}
public void RemoveComponent<T>()
{
_components.Remove(typeof(T));
}
public bool HasComponent<T>()
{
return _components.ContainsKey(typeof(T));
}
public bool HasComponent(Type type)
{
return _components.ContainsKey(type);
}
public T GetComponent<T>()
{
return (T)_components[typeof(T)];
}
public IComponent GetComponent(Type type)
{
return null!;
}
public bool TryGetComponent<T>([NotNullWhen(true)] out T? component) where T : class
{
component = null;
if (!_components.TryGetValue(typeof(T), out var value)) return false;
component = (T)value;
return true;
}
public T? GetComponentOrNull<T>() where T : class
{
return null;
}
public bool TryGetComponent(Type type, [NotNullWhen(true)] out IComponent? component)
{
component = null;
if (!_components.TryGetValue(type, out var value)) return false;
component = value;
return true;
}
public IComponent? GetComponentOrNull(Type type)
{
return null;
}
public void QueueDelete()
{
}
public void Delete()
{
}
public IEnumerable<IComponent> GetAllComponents()
{
return Enumerable.Empty<IComponent>();
}
public IEnumerable<T> GetAllComponents<T>()
{
return Enumerable.Empty<T>();
}
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public void SendMessage(IComponent? owner, ComponentMessage message)
{
}
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public void SendNetworkMessage(IComponent owner, ComponentMessage message, INetChannel? channel = null)
{
}
public void Dirty()
{
}
}
#endregion
}
internal sealed class SpriteUpdateEvent : EntityEventArgs

View File

@@ -12,21 +12,20 @@ using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.Player;
using Robust.Shared.Utility;
namespace Robust.Client.GameObjects
{
[UsedImplicitly]
public class AudioSystem : EntitySystem, IAudioSystem
public class AudioSystem : SharedAudioSystem, IAudioSystem
{
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IClydeAudio _clyde = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly SharedBroadphaseSystem _broadPhaseSystem = default!;
[Dependency] private readonly SharedPhysicsSystem _broadPhaseSystem = default!;
private readonly List<PlayingStream> _playingClydeStreams = new();
@@ -65,7 +64,7 @@ namespace Robust.Client.GameObjects
return;
}
var stream = (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.AudioParams);
var stream = (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.FallbackCoordinates, ev.AudioParams);
if (stream != null)
{
stream.NetIdentifier = ev.Identifier;
@@ -84,8 +83,8 @@ namespace Robust.Client.GameObjects
private void PlayAudioEntityHandler(PlayAudioEntityMessage ev)
{
var stream = EntityManager.TryGetEntity(ev.EntityUid, out var entity) ?
(PlayingStream?) Play(ev.FileName, entity, ev.AudioParams)
: (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.AudioParams);
(PlayingStream?) Play(ev.FileName, entity, ev.FallbackCoordinates, ev.AudioParams)
: (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.FallbackCoordinates, ev.AudioParams);
if (stream != null)
{
@@ -135,6 +134,10 @@ namespace Robust.Client.GameObjects
mapPos = stream.TrackingEntity.Transform.MapPosition;
}
// TODO Remove when coordinates can't be NaN
if (mapPos == null || !float.IsFinite(mapPos.Value.X) || !float.IsFinite(mapPos.Value.Y))
mapPos = stream.TrackingFallbackCoordinates?.ToMap(_entityManager);
if (mapPos != null)
{
var pos = mapPos.Value;
@@ -212,7 +215,6 @@ namespace Robust.Client.GameObjects
{
stream.Source.SetVelocity(stream.TrackingEntity.GlobalLinearVelocity());
}
}
}
}
@@ -277,12 +279,14 @@ namespace Robust.Client.GameObjects
/// </summary>
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="entity">The entity "emitting" the audio.</param>
/// <param name="fallbackCoordinates">The map or grid coordinates at which to play the audio when entity is invalid.</param>
/// <param name="audioParams"></param>
private IPlayingAudioStream? Play(string filename, IEntity entity, AudioParams? audioParams = null)
private IPlayingAudioStream? Play(string filename, IEntity entity, EntityCoordinates fallbackCoordinates,
AudioParams? audioParams = null)
{
if (_resourceCache.TryGetResource<AudioResource>(new ResourcePath(filename), out var audio))
{
return Play(audio, entity, audioParams);
return Play(audio, entity, fallbackCoordinates, audioParams);
}
Logger.Error($"Server tried to play audio file {filename} which does not exist.");
@@ -294,15 +298,15 @@ namespace Robust.Client.GameObjects
/// </summary>
/// <param name="stream">The audio stream to play.</param>
/// <param name="entity">The entity "emitting" the audio.</param>
/// <param name="fallbackCoordinates">The map or grid coordinates at which to play the audio when entity is invalid.</param>
/// <param name="audioParams"></param>
private IPlayingAudioStream? Play(AudioStream stream, IEntity entity, AudioParams? audioParams = null)
private IPlayingAudioStream? Play(AudioStream stream, IEntity entity, EntityCoordinates fallbackCoordinates,
AudioParams? audioParams = null)
{
var source = _clyde.CreateAudioSource(stream);
if (!source.SetPosition(entity.Transform.WorldPosition))
{
source.Dispose();
Logger.Warning($"Can't play positional audio \"{stream.Name}\", can't set position.");
return null;
return Play(stream, fallbackCoordinates, fallbackCoordinates, audioParams);
}
ApplyAudioParams(audioParams, source);
@@ -312,6 +316,7 @@ namespace Robust.Client.GameObjects
{
Source = source,
TrackingEntity = entity,
TrackingFallbackCoordinates = fallbackCoordinates != EntityCoordinates.Invalid ? fallbackCoordinates : null,
Attenuation = audioParams?.Attenuation ?? Attenuation.Default,
MaxDistance = audioParams?.MaxDistance ?? float.MaxValue,
ReferenceDistance = audioParams?.ReferenceDistance ?? 1f,
@@ -327,12 +332,14 @@ namespace Robust.Client.GameObjects
/// </summary>
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="coordinates">The coordinates at which to play the audio.</param>
/// <param name="fallbackCoordinates">The map or grid coordinates at which to play the audio when coordinates are invalid.</param>
/// <param name="audioParams"></param>
private IPlayingAudioStream? Play(string filename, EntityCoordinates coordinates, AudioParams? audioParams = null)
private IPlayingAudioStream? Play(string filename, EntityCoordinates coordinates, EntityCoordinates fallbackCoordinates,
AudioParams? audioParams = null)
{
if (_resourceCache.TryGetResource<AudioResource>(new ResourcePath(filename), out var audio))
{
return Play(audio, coordinates, audioParams);
return Play(audio, coordinates, fallbackCoordinates, audioParams);
}
Logger.Error($"Server tried to play audio file {filename} which does not exist.");
@@ -344,18 +351,24 @@ namespace Robust.Client.GameObjects
/// </summary>
/// <param name="stream">The audio stream to play.</param>
/// <param name="coordinates">The coordinates at which to play the audio.</param>
/// <param name="fallbackCoordinates">The map or grid coordinates at which to play the audio when coordinates are invalid.</param>
/// <param name="audioParams"></param>
private IPlayingAudioStream? Play(AudioStream stream, EntityCoordinates coordinates,
AudioParams? audioParams = null)
EntityCoordinates fallbackCoordinates, AudioParams? audioParams = null)
{
var source = _clyde.CreateAudioSource(stream);
if (!source.SetPosition(coordinates.ToMapPos(EntityManager)))
if (!source.SetPosition(fallbackCoordinates.Position))
{
source.Dispose();
Logger.Warning($"Can't play positional audio \"{stream.Name}\", can't set position.");
return null;
}
if (!coordinates.IsValid(_entityManager))
{
coordinates = fallbackCoordinates;
}
ApplyAudioParams(audioParams, source);
source.StartPlaying();
@@ -363,6 +376,7 @@ namespace Robust.Client.GameObjects
{
Source = source,
TrackingCoordinates = coordinates,
TrackingFallbackCoordinates = fallbackCoordinates != EntityCoordinates.Invalid ? fallbackCoordinates : null,
Attenuation = audioParams?.Attenuation ?? Attenuation.Default,
MaxDistance = audioParams?.MaxDistance ?? float.MaxValue,
ReferenceDistance = audioParams?.ReferenceDistance ?? 1f,
@@ -395,6 +409,7 @@ namespace Robust.Client.GameObjects
public IClydeAudioSource Source = default!;
public IEntity TrackingEntity = default!;
public EntityCoordinates? TrackingCoordinates;
public EntityCoordinates? TrackingFallbackCoordinates;
public bool Done;
public float Volume;
@@ -440,19 +455,19 @@ namespace Robust.Client.GameObjects
/// <inheritdoc />
public IPlayingAudioStream? Play(Filter playerFilter, string filename, IEntity entity, AudioParams? audioParams = null)
{
return Play(filename, entity, audioParams);
return Play(filename, entity, GetFallbackCoordinates(entity.Transform.MapPosition), audioParams);
}
public IPlayingAudioStream? Play(Filter playerFilter, string filename, EntityUid uid, AudioParams? audioParams = null)
{
return EntityManager.TryGetEntity(uid, out var entity)
? Play(filename, entity, audioParams) : null;
? Play(filename, entity, GetFallbackCoordinates(entity.Transform.MapPosition), audioParams) : null;
}
/// <inheritdoc />
public IPlayingAudioStream? Play(Filter playerFilter, string filename, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
return Play(filename, coordinates, audioParams);
return Play(filename, coordinates, GetFallbackCoordinates(coordinates.ToMap(_entityManager)), audioParams);
}
}
}

View File

@@ -9,6 +9,7 @@ using Robust.Shared.Input.Binding;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
#nullable enable
@@ -20,14 +21,23 @@ namespace Robust.Client.GameObjects
[UsedImplicitly]
internal class EyeUpdateSystem : EntitySystem
{
// How fast the camera rotates in radians
private const float CameraRotateSpeed = MathF.PI;
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
private bool _isLerping = false;
private TransformComponent? _lastParent;
private TransformComponent? _lerpTo;
private Angle LerpStartRotation;
private float _accumulator;
public bool IsLerping { get => _lerpTo != null; }
// How fast the camera rotates in radians / s
private const float CameraRotateSpeed = MathF.PI;
// PER THIS AMOUNT OF TIME MILLISECONDS
private const float CameraRotateTimeUnit = 1.2f;
// Safety override
private const float _lerpTimeMax = CameraRotateTimeUnit + 0.4f;
/// <inheritdoc />
public override void Initialize()
@@ -59,27 +69,6 @@ namespace Robust.Client.GameObjects
var currentEye = _eyeManager.CurrentEye;
// TODO: Content should have its own way of handling this. We should have a default behavior that they can overwrite.
/*
var inputSystem = EntitySystemManager.GetEntitySystem<InputSystem>();
var direction = 0;
if (inputSystem.CmdStates[EngineKeyFunctions.CameraRotateRight] == BoundKeyState.Down)
{
direction += 1;
}
if (inputSystem.CmdStates[EngineKeyFunctions.CameraRotateLeft] == BoundKeyState.Down)
{
direction -= 1;
}
// apply camera rotation
if(direction != 0)
{
currentEye.Rotation += CameraRotateSpeed * frameTime * direction;
currentEye.Rotation = currentEye.Rotation.Reduced();
}
*/
var playerTransform = _playerManager.LocalPlayer?.ControlledEntity?.Transform;
@@ -91,13 +80,55 @@ namespace Robust.Client.GameObjects
gridEnt.Transform
: _mapManager.GetMapEntity(playerTransform.MapID).Transform;
if (!_isLerping)
// Make sure that we don't fire the vomit carousel when we spawn in
if (_lastParent is null)
_lastParent = parent;
// Set a default for target rotation
var parentRotation = -parent.WorldRotation;
// Reuse current rotation when stepping into space
if (parent.GridID == GridId.Invalid)
parentRotation = currentEye.Rotation;
// Handle grid change in general
if (_lastParent != parent)
_lerpTo = parent;
// And we are up and running!
if (_lerpTo is not null)
{
// TODO: Detect parent change and start lerping
var parentRotation = parent.WorldRotation;
currentEye.Rotation = -parentRotation;
// Handle a case where we have beeing spinning around, but suddenly got off onto a different grid
if (parent != _lerpTo) {
LerpStartRotation = currentEye.Rotation;
_lerpTo = parent;
_accumulator = 0f;
}
_accumulator += frameTime;
var changeNeeded = (float) (LerpStartRotation - parentRotation).Theta;
var changeLerp = _accumulator / (Math.Abs(changeNeeded % MathF.PI) / CameraRotateSpeed * CameraRotateTimeUnit);
currentEye.Rotation = Angle.Lerp(LerpStartRotation, parentRotation, changeLerp);
// Either we have overshot, or we have taken way too long on this, emergency reset time
if (changeLerp > 1.0f || _accumulator >= _lerpTimeMax)
{
_lastParent = parent;
_lerpTo = null;
_accumulator = 0f;
}
}
// We are just fine, or we finished a lerp (and probably overshot)
if (_lerpTo is null)
{
currentEye.Rotation = parentRotation;
LerpStartRotation = parentRotation;
}
foreach (var eyeComponent in EntityManager.EntityQuery<EyeComponent>(true))
{
eyeComponent.UpdateEyePosition();

View File

@@ -109,7 +109,7 @@ namespace Robust.Client.GameObjects
AnythingMovedSubHandler(args.Sender.Transform);
}
private void AnythingMovedSubHandler(ITransformComponent sender)
private void AnythingMovedSubHandler(TransformComponent sender)
{
// To avoid doing redundant updates (and we don't need to update a grid's children ever)
if (!_checkedChildren.Add(sender.Owner.Uid) ||
@@ -125,7 +125,7 @@ namespace Robust.Client.GameObjects
if (sender.Owner.TryGetComponent(out PointLightComponent? light))
QueueLightUpdate(light);
foreach (ITransformComponent child in sender.Children)
foreach (TransformComponent child in sender.Children)
{
AnythingMovedSubHandler(child);
}

View File

@@ -17,6 +17,7 @@ namespace Robust.Client.GameObjects
[Dependency] private readonly RenderingTreeSystem _treeSystem = default!;
private readonly Queue<SpriteComponent> _inertUpdateQueue = new();
private HashSet<ISpriteComponent> _manualUpdate = new();
public override void Initialize()
{
@@ -38,6 +39,12 @@ namespace Robust.Client.GameObjects
sprite.DoUpdateIsInert();
}
foreach (var sprite in _manualUpdate)
{
if (!sprite.Deleted && !sprite.IsInert)
sprite.FrameUpdate(frameTime);
}
var pvsBounds = _eyeManager.GetWorldViewbounds();
var currentMap = _eyeManager.CurrentMap;
@@ -57,10 +64,21 @@ namespace Robust.Client.GameObjects
return true;
}
value.FrameUpdate(state);
if (!_manualUpdate.Contains(value))
value.FrameUpdate(state);
return true;
}, bounds, true);
}
_manualUpdate.Clear();
}
/// <summary>
/// Force update of the sprite component next frame
/// </summary>
public void ForceUpdate(ISpriteComponent sprite)
{
_manualUpdate.Add(sprite);
}
}
}

View File

@@ -29,7 +29,8 @@ namespace Robust.Client.GameObjects
private void MessageReceived(BoundUIWrapMessage ev)
{
var uid = ev.Entity;
var cmp = EntityManager.GetComponent<ClientUserInterfaceComponent>(uid);
if (!EntityManager.TryGetComponent<ClientUserInterfaceComponent>(uid, out var cmp))
return;
var message = ev.Message;
// This should probably not happen at this point, but better make extra sure!

View File

@@ -25,6 +25,9 @@ namespace Robust.Client.Graphics
internal set => _coords = value;
}
[ViewVariables(VVAccess.ReadWrite)]
public Vector2 Offset { get; set; }
/// <inheritdoc />
[ViewVariables(VVAccess.ReadWrite)]
public Angle Rotation
@@ -51,6 +54,15 @@ namespace Robust.Client.Graphics
/// <inheritdoc />
public void GetViewMatrix(out Matrix3 viewMatrix, Vector2 renderScale)
{
var scaleMat = Matrix3.CreateScale(_scale.X * renderScale.X, _scale.Y * renderScale.Y);
var rotMat = Matrix3.CreateRotation(_rotation);
var transMat = Matrix3.CreateTranslation(-_coords.Position - Offset);
viewMatrix = transMat * rotMat * scaleMat;
}
public void GetViewMatrixNoOffset(out Matrix3 viewMatrix, Vector2 renderScale)
{
var scaleMat = Matrix3.CreateScale(_scale.X * renderScale.X, _scale.Y * renderScale.Y);
var rotMat = Matrix3.CreateRotation(_rotation);

View File

@@ -21,6 +21,11 @@ namespace Robust.Client.Graphics
/// </summary>
MapCoordinates Position { get; }
/// <summary>
/// Translation offset from <see cref="Position"/>. Does not influence the center of FOV.
/// </summary>
Vector2 Offset { get; set; }
/// <summary>
/// Rotation of the camera around the Z axis.
/// </summary>
@@ -51,5 +56,7 @@ namespace Robust.Client.Graphics
/// <param name="viewMatrixInv">Inverted view matrix for this camera.</param>
/// <param name="renderScale"></param>
void GetViewMatrixInv(out Matrix3 viewMatrixInv, Vector2 renderScale);
void GetViewMatrixNoOffset(out Matrix3 viewMatrix, Vector2 renderScale);
}
}

View File

@@ -54,6 +54,8 @@ namespace Robust.Client.Graphics
/// <returns>Corresponding point in UI screen space.</returns>
ScreenCoordinates CoordinatesToScreen(EntityCoordinates point);
ScreenCoordinates MapToScreen(MapCoordinates point);
/// <summary>
/// Unprojects a point from UI screen space to world space using the viewport under the screen coordinates.
/// </summary>

View File

@@ -7,6 +7,7 @@ using System.Runtime.CompilerServices;
using System.Threading;
using OpenToolkit.Audio.OpenAL;
using OpenToolkit.Audio.OpenAL.Extensions.Creative.EFX;
using OpenToolkit.Mathematics;
using Robust.Client.Audio;
using Robust.Shared;
using Robust.Shared.Audio;
@@ -155,6 +156,14 @@ namespace Robust.Client.Graphics.Clyde
var eye = _eyeManager.CurrentEye;
var (x, y) = eye.Position.Position;
AL.Listener(ALListener3f.Position, x, y, -5);
var rot2d = eye.Rotation.ToVec();
AL.Listener(ALListenerfv.Orientation, new []{0, 0, -1, rot2d.X, rot2d.Y, 0});
// Default orientation: at: (0, 0, -1) up: (0, 1, 0)
var (rotX, rotY) = eye.Rotation.ToVec();
var at = new Vector3(0f, 0f, -1f);
var up = new Vector3(rotY, rotX, 0f);
AL.Listener(ALListenerfv.Orientation, ref at, ref up);
// Clear out finalized audio sources.
while (_sourceDisposeQueue.TryDequeue(out var handles))

View File

@@ -1,6 +1,7 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using OpenToolkit.Graphics.OpenGL4;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -49,10 +50,11 @@ namespace Robust.Client.Graphics.Clyde
continue;
}
var transform = _entityManager.GetComponent<ITransformComponent>(grid.GridEntityId);
var transform = _entityManager.GetComponent<TransformComponent>(grid.GridEntityId);
gridProgram.SetUniform(UniIModelMatrix, transform.WorldMatrix);
grid.GetMapChunks(worldBounds, out var enumerator);
foreach (var chunk in grid.GetMapChunks(worldBounds))
while (enumerator.MoveNext(out var chunk))
{
if (_isChunkDirty(grid, chunk))
{
@@ -85,50 +87,39 @@ namespace Robust.Client.Graphics.Clyde
datum = _initChunkBuffers(grid, chunk);
}
var vertexPool = ArrayPool<Vertex2D>.Shared;
var indexPool = ArrayPool<ushort>.Shared;
Span<ushort> indexBuffer = stackalloc ushort[_indicesPerChunk(chunk)];
Span<Vertex2D> vertexBuffer = stackalloc Vertex2D[_verticesPerChunk(chunk)];
var vertexBuffer = vertexPool.Rent(_verticesPerChunk(chunk));
var indexBuffer = indexPool.Rent(_indicesPerChunk(chunk));
try
var i = 0;
foreach (var tile in chunk)
{
var i = 0;
foreach (var tile in chunk)
var regionMaybe = _tileDefinitionManager.TileAtlasRegion(tile.Tile);
if (regionMaybe == null)
{
var regionMaybe = _tileDefinitionManager.TileAtlasRegion(tile.Tile);
if (regionMaybe == null)
{
continue;
}
var region = regionMaybe.Value;
var vIdx = i * 4;
vertexBuffer[vIdx + 0] = new Vertex2D(tile.X, tile.Y, region.Left, region.Bottom);
vertexBuffer[vIdx + 1] = new Vertex2D(tile.X + 1, tile.Y, region.Right, region.Bottom);
vertexBuffer[vIdx + 2] = new Vertex2D(tile.X + 1, tile.Y + 1, region.Right, region.Top);
vertexBuffer[vIdx + 3] = new Vertex2D(tile.X, tile.Y + 1, region.Left, region.Top);
var nIdx = i * GetQuadBatchIndexCount();
var tIdx = (ushort) (i * 4);
QuadBatchIndexWrite(indexBuffer, ref nIdx, tIdx);
i += 1;
continue;
}
GL.BindVertexArray(datum.VAO);
CheckGlError();
datum.EBO.Use();
datum.VBO.Use();
datum.EBO.Reallocate(new Span<ushort>(indexBuffer, 0, i * GetQuadBatchIndexCount()));
datum.VBO.Reallocate(new Span<Vertex2D>(vertexBuffer, 0, i * 4));
datum.Dirty = false;
datum.TileCount = i;
}
finally
{
vertexPool.Return(vertexBuffer);
indexPool.Return(indexBuffer);
var region = regionMaybe.Value;
var vIdx = i * 4;
vertexBuffer[vIdx + 0] = new Vertex2D(tile.X, tile.Y, region.Left, region.Bottom);
vertexBuffer[vIdx + 1] = new Vertex2D(tile.X + 1, tile.Y, region.Right, region.Bottom);
vertexBuffer[vIdx + 2] = new Vertex2D(tile.X + 1, tile.Y + 1, region.Right, region.Top);
vertexBuffer[vIdx + 3] = new Vertex2D(tile.X, tile.Y + 1, region.Left, region.Top);
var nIdx = i * GetQuadBatchIndexCount();
var tIdx = (ushort) (i * 4);
QuadBatchIndexWrite(indexBuffer, ref nIdx, tIdx);
i += 1;
}
GL.BindVertexArray(datum.VAO);
CheckGlError();
datum.EBO.Use();
datum.VBO.Use();
datum.EBO.Reallocate(indexBuffer[..(i * GetQuadBatchIndexCount())]);
datum.VBO.Reallocate(vertexBuffer[..(i * 4)]);
datum.Dirty = false;
datum.TileCount = i;
}
private MapChunkData _initChunkBuffers(IMapGrid grid, IMapChunk chunk)

View File

@@ -98,7 +98,7 @@ namespace Robust.Client.Graphics.Clyde
SwapAllBuffers();
}
private void RenderOverlays(Viewport vp, OverlaySpace space, in Box2 worldBox)
private void RenderOverlays(Viewport vp, OverlaySpace space, in Box2 worldBox, in Box2Rotated worldBounds)
{
using (DebugGroup($"Overlays: {space}"))
{
@@ -116,8 +116,10 @@ namespace Robust.Client.Graphics.Clyde
ClearFramebuffer(default);
}
overlay.ClydeRender(_renderHandle, space, null, vp, new UIBox2i((0, 0), vp.Size), worldBox);
overlay.ClydeRender(_renderHandle, space, null, vp, new UIBox2i((0, 0), vp.Size), worldBox, worldBounds);
}
FlushRenderQueue();
}
}
@@ -130,8 +132,9 @@ namespace Robust.Client.Graphics.Clyde
{
var list = GetOverlaysForSpace(space);
var worldBounds = CalcWorldAABB(vp);
var args = new OverlayDrawArgs(space, vpControl, vp, handle, bounds, worldBounds);
var worldAABB = CalcWorldAABB(vp);
var worldBounds = CalcWorldBounds(vp);
var args = new OverlayDrawArgs(space, vpControl, vp, handle, bounds, worldAABB, worldBounds);
foreach (var overlay in list)
{
@@ -209,11 +212,12 @@ namespace Robust.Client.Graphics.Clyde
return;
}
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowEntities, worldAABB);
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowEntities, worldAABB, worldBounds);
var screenSize = viewport.Size;
eye.GetViewMatrix(out var eyeMatrix, eye.Scale);
ProcessSpriteEntities(mapId, worldBounds, _drawingSpriteList);
ProcessSpriteEntities(mapId, eyeMatrix, worldBounds, _drawingSpriteList);
var worldOverlays = new List<Overlay>();
@@ -261,7 +265,8 @@ namespace Robust.Client.Graphics.Clyde
null,
viewport,
new UIBox2i((0, 0), viewport.Size),
worldAABB);
worldAABB,
worldBounds);
overlayIndex = j;
continue;
}
@@ -362,7 +367,7 @@ namespace Robust.Client.Graphics.Clyde
}
[MethodImpl(MethodImplOptions.NoInlining)]
private void ProcessSpriteEntities(MapId map, Box2Rotated worldBounds,
private void ProcessSpriteEntities(MapId map, Matrix3 eyeMatrix, Box2Rotated worldBounds,
RefList<(SpriteComponent sprite, Matrix3 matrix, Angle worldRot, float yWorldPos)> list)
{
foreach (var comp in _entitySystemManager.GetEntitySystem<RenderingTreeSystem>().GetRenderTrees(map, worldBounds))
@@ -380,10 +385,10 @@ namespace Robust.Client.Graphics.Clyde
entry.sprite = value;
entry.worldRot = transform.WorldRotation;
entry.matrix = transform.WorldMatrix;
var worldPos = new Vector2(entry.matrix.R0C2, entry.matrix.R1C2);
var eyePos = eyeMatrix.Transform(new Vector2(entry.matrix.R0C2, entry.matrix.R1C2));
// Didn't use the bounds from the query as that has to be re-calculated (and is probably more expensive than this).
var bounds = value.CalculateBoundingBox(worldPos);
entry.yWorldPos = worldPos.Y - bounds.Extents.Y;
var bounds = value.CalculateBoundingBox(eyePos);
entry.yWorldPos = eyePos.Y - bounds.Extents.Y;
return true;
}, bounds, true);
@@ -468,8 +473,7 @@ namespace Robust.Client.Graphics.Clyde
DrawLightsAndFov(viewport, worldBounds, worldAABB, eye);
}
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowWorld, worldAABB);
FlushRenderQueue();
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowWorld, worldAABB, worldBounds);
using (DebugGroup("Grids"))
{
@@ -482,8 +486,7 @@ namespace Robust.Client.Graphics.Clyde
DrawEntities(viewport, worldBounds, worldAABB, eye);
}
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowFOV, worldAABB);
FlushRenderQueue();
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowFOV, worldAABB, worldBounds);
if (_lightManager.Enabled && _lightManager.DrawHardFov && eye.DrawFov)
{
@@ -516,8 +519,7 @@ namespace Robust.Client.Graphics.Clyde
UIBox2.FromDimensions(Vector2.Zero, viewport.Size), new Color(1, 1, 1, 0.5f));
}
RenderOverlays(viewport, OverlaySpace.WorldSpace, worldAABB);
FlushRenderQueue();
RenderOverlays(viewport, OverlaySpace.WorldSpace, worldAABB, worldBounds);
_currentViewport = oldVp;
});
@@ -529,12 +531,13 @@ namespace Robust.Client.Graphics.Clyde
if (eye == null)
return default;
return GetAABB(eye, viewport);
// Will be larger than the actual viewport due to rotation.
return CalcWorldBounds(viewport).CalcBoundingBox();
}
private static Box2 GetAABB(IEye eye, Viewport viewport)
{
return Box2.CenteredAround(eye.Position.Position,
return Box2.CenteredAround(eye.Position.Position + eye.Offset,
viewport.Size / viewport.RenderScale / EyeManager.PixelsPerMeter * eye.Zoom);
}

View File

@@ -335,7 +335,7 @@ namespace Robust.Client.Graphics.Clyde
}
var (lights, count, expandedBounds) = GetLightsToRender(mapId, worldBounds, worldAABB);
eye.GetViewMatrix(out var eyeTransform, eye.Scale);
eye.GetViewMatrixNoOffset(out var eyeTransform, eye.Scale);
UpdateOcclusionGeometry(mapId, expandedBounds, eyeTransform);
@@ -361,6 +361,8 @@ namespace Robust.Client.Graphics.Clyde
{
var (light, lightPos, _) = lights[i];
if (!light.CastShadows) continue;
DrawOcclusionDepth(lightPos, ShadowMapSize, light.Radius, i);
}
}
@@ -459,7 +461,7 @@ namespace Robust.Client.Graphics.Clyde
}
lightShader.SetUniformMaybe("lightCenter", lightPos);
lightShader.SetUniformMaybe("lightIndex", (i + 0.5f) / ShadowTexture.Height);
lightShader.SetUniformMaybe("lightIndex", component.CastShadows ? (i + 0.5f) / ShadowTexture.Height : -1);
var offset = new Vector2(component.Radius, component.Radius);

View File

@@ -273,7 +273,11 @@ namespace Robust.Client.Graphics.Clyde
public Vector2i Size;
public bool IsSrgb;
#pragma warning disable 649
// Gets assigned by (currently commented out) GLContextAngle.
// It's fine don't worry about it.
public bool FlipY;
#pragma warning restore 649
public RTCF ColorFormat;

View File

@@ -28,7 +28,10 @@ namespace Robust.Client.Graphics.Clyde
private WindowReg? _mainWindow;
private IWindowingImpl? _windowing;
#pragma warning disable 414
// Keeping this for if/when we ever get a new renderer.
private Renderer _chosenRenderer;
#pragma warning restore 414
private ResourcePath? _windowIconPath;
private Thread? _windowingThread;

View File

@@ -136,7 +136,7 @@ namespace Robust.Client.Graphics.Clyde
if (_clyde._windowMode == WindowMode.Fullscreen)
{
win.PrevWindowSize = win.WindowSize;
win.PrevWindowPos = win.PrevWindowPos;
win.PrevWindowPos = win.WindowPos;
SendCmd(new CmdWinSetFullscreen((nint) win.GlfwWindow));
}
@@ -262,7 +262,10 @@ namespace Robust.Client.Graphics.Clyde
var (reg, errorResult) = task.Result;
if (reg != null)
{
reg.Owner = reg.Handle;
return (reg, null);
}
var (desc, errCode) = errorResult!.Value;
return (null, $"[{errCode}]: {desc}");

View File

@@ -1,4 +1,5 @@
using System.Text;
using System;
using System.Text;
using Robust.Client.ResourceManagement;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
@@ -143,6 +144,61 @@ namespace Robust.Client.Graphics
}
}
public sealed class StackedFont : Font
{
// _main is the "default" font; the top of the Stack.
public readonly Font _main;
public readonly Font[] Stack;
public StackedFont(params Font[] args)
{
if (args.Length < 1)
throw new ArgumentException("At least one font is required");
Stack = args;
_main = args[0];
}
// All metrics methods use the default font (_main).
// Technically these could vary between stacked fonts, but that is a case
// that really should already be avoided for so many other reasons.
public override int GetAscent(float scale) => _main.GetAscent(scale);
public override int GetHeight(float scale) => _main.GetHeight(scale);
public override int GetDescent(float scale) => _main.GetDescent(scale);
public override int GetLineHeight(float scale) => _main.GetLineHeight(scale);
// DrawChar just proxies to the stack, or invokes _main's fallback.
public override float DrawChar(DrawingHandleScreen handle, Rune rune, Vector2 baseline, float scale, Color color, bool fallback=true)
{
foreach (var f in Stack)
{
var w = f.DrawChar(handle, rune, baseline, scale, color, fallback: false);
if (w != 0f)
return w;
}
if (fallback)
return _main.DrawChar(handle, rune, baseline, scale, color, fallback: true);
return 0f;
}
public override CharMetrics? GetCharMetrics(Rune rune, float scale, bool fallback=true)
{
foreach (var f in Stack)
{
var m = f.GetCharMetrics(rune, scale, fallback: false);
if (m != null)
return m;
}
if (!Rune.IsWhiteSpace(rune) && fallback)
return _main.GetCharMetrics(rune, scale, fallback: true);
return null;
}
}
public sealed class DummyFont : Font
{
public override int GetAscent(float scale) => default;

View File

@@ -84,7 +84,8 @@ namespace Robust.Client.Graphics
IViewportControl? vpControl,
IClydeViewport vp,
in UIBox2i screenBox,
in Box2 worldBox)
in Box2 worldBox,
in Box2Rotated worldBounds)
{
DrawingHandleBase handle;
if (currentSpace == OverlaySpace.ScreenSpace || currentSpace == OverlaySpace.ScreenSpaceBelowWorld)
@@ -97,7 +98,7 @@ namespace Robust.Client.Graphics
handle = renderHandle.DrawingHandleWorld;
}
var args = new OverlayDrawArgs(currentSpace, vpControl, vp, handle, screenBox, worldBox);
var args = new OverlayDrawArgs(currentSpace, vpControl, vp, handle, screenBox, worldBox, worldBounds);
Draw(args);
}

View File

@@ -41,7 +41,12 @@ namespace Robust.Client.Graphics
/// <summary>
/// AABB enclosing the area visible in the viewport.
/// </summary>
public readonly Box2 WorldBounds;
public readonly Box2 WorldAABB;
/// <summary>
/// <see cref="Box2Rotated"/> of the area visible in the viewport.
/// </summary>
public readonly Box2Rotated WorldBounds;
public DrawingHandleScreen ScreenHandle => (DrawingHandleScreen) DrawingHandle;
public DrawingHandleWorld WorldHandle => (DrawingHandleWorld) DrawingHandle;
@@ -52,13 +57,15 @@ namespace Robust.Client.Graphics
IClydeViewport viewport,
DrawingHandleBase drawingHandle,
in UIBox2i viewportBounds,
in Box2 worldBounds)
in Box2 worldAabb,
in Box2Rotated worldBounds)
{
Space = space;
ViewportControl = viewportControl;
Viewport = viewport;
DrawingHandle = drawingHandle;
ViewportBounds = viewportBounds;
WorldAABB = worldAabb;
WorldBounds = worldBounds;
}
}

View File

@@ -24,13 +24,14 @@ namespace Robust.Client.Graphics
// 2D array for the texture to use for each animation frame at each direction.
public readonly Texture[][] Icons;
internal State(Vector2i size, StateId stateId, DirectionType direction, float[] delays, Texture[][] icons)
internal State(Vector2i size, RSI rsi, StateId stateId, DirectionType direction, float[] delays, Texture[][] icons)
{
DebugTools.Assert(size.X > 0);
DebugTools.Assert(size.Y > 0);
DebugTools.Assert(stateId.IsValid);
Size = size;
RSI = rsi;
StateId = stateId;
Directions = direction;
Delays = delays;
@@ -47,6 +48,11 @@ namespace Robust.Client.Graphics
/// </summary>
public Vector2i Size { get; }
/// <summary>
/// The source RSI of this state.
/// </summary>
public RSI RSI { get; }
/// <summary>
/// The identifier for this state inside an RSI.
/// </summary>

View File

@@ -60,6 +60,7 @@ namespace Robust.Client.Input
common.AddFunction(EngineKeyFunctions.TextReleaseFocus);
common.AddFunction(EngineKeyFunctions.TextScrollToBottom);
common.AddFunction(EngineKeyFunctions.TextDelete);
common.AddFunction(EngineKeyFunctions.TextTabComplete);
var editor = contexts.New("editor", common);
editor.AddFunction(EngineKeyFunctions.EditorLinePlace);

View File

@@ -1,5 +1,6 @@
using System;
using Robust.Shared.Enums;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
namespace Robust.Client.Placement
@@ -12,6 +13,16 @@ namespace Robust.Client.Placement
PlacementMode? CurrentMode { get; set; }
PlacementInformation? CurrentPermission { get; set; }
/// <summary>
/// The direction to spawn the entity in (presently exposed for EntitySpawnWindow UI)
/// </summary>
Direction Direction { get; set; }
/// <summary>
/// Gets called when Direction changed (presently for EntitySpawnWindow UI)
/// </summary>
event EventHandler DirectionChanged;
/// <summary>
/// Gets called when the PlacementManager changed its build/erase mode or when the hijacks changed
/// </summary>

View File

@@ -5,11 +5,8 @@ using Robust.Shared.Maths;
namespace Robust.Client.Placement.Modes
{
public class SnapgridBorder : PlacementMode
public class SnapgridBorder : SnapgridCenter
{
private bool onGrid;
private float snapSize;
public override bool HasLineMode => true;
public override bool HasGridMode => true;
@@ -17,79 +14,33 @@ namespace Robust.Client.Placement.Modes
{
}
public override void Render(DrawingHandleWorld handle)
{
if (onGrid)
{
const int ppm = EyeManager.PixelsPerMeter;
var viewportSize = (Vector2)pManager._clyde.ScreenSize;
var position = pManager.eyeManager.ScreenToMap(Vector2.Zero);
var gridstartx = (float) MathF.Round(position.X / snapSize, MidpointRounding.AwayFromZero) * snapSize;
var gridstarty = (float) MathF.Round(position.Y / snapSize, MidpointRounding.AwayFromZero) * snapSize;
var gridstart = pManager.eyeManager.WorldToScreen(
new Vector2( //Find snap grid closest to screen origin and convert back to screen coords
gridstartx,
gridstarty));
for (var a = gridstart.X;
a < viewportSize.X;
a += snapSize * ppm) //Iterate through screen creating gridlines
{
var from = ScreenToWorld(new Vector2(a, 0));
var to = ScreenToWorld(new Vector2(a, viewportSize.Y));
handle.DrawLine(from, to, new Color(0, 0, 1f));
}
for (var a = gridstart.Y; a < viewportSize.Y; a += snapSize * ppm)
{
var from = ScreenToWorld(new Vector2(0, a));
var to = ScreenToWorld(new Vector2(viewportSize.X, a));
handle.DrawLine(from, to, new Color(0, 0, 1f));
}
}
// Draw grid BELOW the ghost.
base.Render(handle);
}
public override void AlignPlacementMode(ScreenCoordinates mouseScreen)
{
MouseCoords = ScreenToCursorGrid(mouseScreen);
snapSize = 1f;
var gridId = MouseCoords.GetGridId(pManager.EntityManager);
SnapSize = 1f;
if (gridId.IsValid())
{
snapSize = pManager.MapManager.GetGrid(gridId).TileSize; //Find snap size for the grid.
onGrid = true;
Grid = pManager.MapManager.GetGrid(gridId);
SnapSize = Grid.TileSize; //Find snap size for the grid.
}
else
{
onGrid = false;
Grid = null;
}
GridDistancing = snapSize;
GridDistancing = SnapSize;
var mouselocal = new Vector2( //Round local coordinates onto the snap grid
(float) MathF.Round(MouseCoords.X / snapSize, MidpointRounding.AwayFromZero) * snapSize,
(float) MathF.Round(MouseCoords.Y / snapSize, MidpointRounding.AwayFromZero) * snapSize);
(float) MathF.Round(MouseCoords.X / SnapSize, MidpointRounding.AwayFromZero) * SnapSize,
(float) MathF.Round(MouseCoords.Y / SnapSize, MidpointRounding.AwayFromZero) * SnapSize);
//Convert back to original world and screen coordinates after applying offset
MouseCoords =
new EntityCoordinates(
MouseCoords.EntityId, mouselocal + new Vector2(pManager.PlacementOffset.X, pManager.PlacementOffset.Y));
}
public override bool IsValidPosition(EntityCoordinates position)
{
if (!RangeCheck(position))
{
return false;
}
return true;
}
}
}

View File

@@ -1,5 +1,7 @@
using System;
using Robust.Client.Graphics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -7,8 +9,8 @@ namespace Robust.Client.Placement.Modes
{
public class SnapgridCenter : PlacementMode
{
bool onGrid;
float snapSize;
protected IMapGrid? Grid;
protected float SnapSize;
public override bool HasLineMode => true;
public override bool HasGridMode => true;
@@ -17,22 +19,22 @@ namespace Robust.Client.Placement.Modes
public override void Render(DrawingHandleWorld handle)
{
if (onGrid)
if (Grid != null)
{
var viewportSize = (Vector2)pManager._clyde.ScreenSize;
var position = pManager.eyeManager.ScreenToMap(Vector2.Zero);
var gridPosition = Grid.MapToGrid(pManager.eyeManager.ScreenToMap(Vector2.Zero));
var gridstart = pManager.eyeManager.WorldToScreen(new Vector2( //Find snap grid closest to screen origin and convert back to screen coords
(float)(MathF.Round(position.X / snapSize - 0.5f, MidpointRounding.AwayFromZero) + 0.5f) * snapSize,
(float)(MathF.Round(position.Y / snapSize - 0.5f, MidpointRounding.AwayFromZero) + 0.5f) * snapSize));
for (var a = gridstart.X; a < viewportSize.X; a += snapSize * 32) //Iterate through screen creating gridlines
var gridstart = pManager.eyeManager.CoordinatesToScreen(
gridPosition.WithPosition(new Vector2(MathF.Floor(gridPosition.X), MathF.Floor(gridPosition.Y))));
for (var a = gridstart.X; a < viewportSize.X; a += SnapSize * EyeManager.PixelsPerMeter) //Iterate through screen creating gridlines
{
var from = ScreenToWorld(new Vector2(a, 0));
var to = ScreenToWorld(new Vector2(a, viewportSize.Y));
handle.DrawLine(from, to, new Color(0, 0, 1f));
}
for (var a = gridstart.Y; a < viewportSize.Y; a += snapSize * 32)
for (var a = gridstart.Y; a < viewportSize.Y; a += SnapSize * EyeManager.PixelsPerMeter)
{
var from = ScreenToWorld(new Vector2(0, a));
var to = ScreenToWorld(new Vector2(viewportSize.X, a));
@@ -49,22 +51,22 @@ namespace Robust.Client.Placement.Modes
MouseCoords = ScreenToCursorGrid(mouseScreen);
var gridId = MouseCoords.GetGridId(pManager.EntityManager);
snapSize = 1f;
SnapSize = 1f;
if (gridId.IsValid())
{
snapSize = pManager.MapManager.GetGrid(gridId).TileSize; //Find snap size for the grid.
onGrid = true;
Grid = pManager.MapManager.GetGrid(gridId);
SnapSize = Grid.TileSize; //Find snap size for the grid.
}
else
{
onGrid = false;
Grid = null;
}
GridDistancing = snapSize;
GridDistancing = SnapSize;
var mouseLocal = new Vector2( //Round local coordinates onto the snap grid
(float)(MathF.Round((MouseCoords.Position.X / snapSize - 0.5f), MidpointRounding.AwayFromZero) + 0.5) * snapSize,
(float)(MathF.Round((MouseCoords.Position.Y / snapSize - 0.5f), MidpointRounding.AwayFromZero) + 0.5) * snapSize);
(float)(MathF.Round((MouseCoords.Position.X / SnapSize - 0.5f), MidpointRounding.AwayFromZero) + 0.5) * SnapSize,
(float)(MathF.Round((MouseCoords.Position.Y / SnapSize - 0.5f), MidpointRounding.AwayFromZero) + 0.5) * SnapSize);
//Adjust mouseCoords to new calculated position
MouseCoords = new EntityCoordinates(MouseCoords.EntityId, mouseLocal + new Vector2(pManager.PlacementOffset.X, pManager.PlacementOffset.Y));

View File

@@ -95,9 +95,21 @@ namespace Robust.Client.Placement
private ShaderInstance? _drawingShader { get; set; }
/// <summary>
/// The texture we use to show from our placement manager to represent the entity to place
/// The entity for placement overlay.
/// Colour of this gets swapped around in PlacementMode.
/// This entity needs to stay in nullspace.
/// </summary>
public List<IDirectionalTextureProvider>? CurrentTextures { get; set; }
public IEntity? CurrentPlacementOverlayEntity { get; set; }
/// <summary>
/// A BAD way to explicitly control the icons used!!!
/// Need to fix Content for this
/// </summary>
public List<IDirectionalTextureProvider>? CurrentTextures {
set {
PreparePlacementTexList(value, value != null);
}
}
/// <summary>
/// Which of the placement orientations we are trying to place with
@@ -143,10 +155,21 @@ namespace Robust.Client.Placement
set => _colliderAABB = value;
}
/// <summary>
/// The directional to spawn the entity in
/// </summary>
public Direction Direction { get; set; } = Direction.South;
private Direction _direction = Direction.South;
/// <inheritdoc />
public Direction Direction
{
get => _direction;
set
{
_direction = value;
DirectionChanged?.Invoke(this, EventArgs.Empty);
}
}
/// <inheritdoc />
public event EventHandler? DirectionChanged;
private PlacementOverlay _drawOverlay = default!;
private bool _isActive;
@@ -319,7 +342,7 @@ namespace Robust.Client.Placement
{
PlacementChanged?.Invoke(this, EventArgs.Empty);
Hijack = null;
CurrentTextures = null;
EnsureNoPlacementOverlayEntity();
CurrentPrototype = null;
CurrentPermission = null;
CurrentMode = null;
@@ -351,8 +374,6 @@ namespace Robust.Client.Placement
Direction = Direction.North;
break;
}
CurrentMode?.SetSprite();
}
public void HandlePlacement()
@@ -636,21 +657,64 @@ namespace Robust.Client.Placement
BeginPlacing(CurrentPermission);
}
private void EnsureNoPlacementOverlayEntity()
{
if (CurrentPlacementOverlayEntity != null)
{
if (!CurrentPlacementOverlayEntity.Deleted)
CurrentPlacementOverlayEntity.Delete();
CurrentPlacementOverlayEntity = null;
}
}
private SpriteComponent SetupPlacementOverlayEntity()
{
EnsureNoPlacementOverlayEntity();
CurrentPlacementOverlayEntity = EntityManager.SpawnEntity(null, MapCoordinates.Nullspace);
return CurrentPlacementOverlayEntity.EnsureComponent<SpriteComponent>();
}
private void PreparePlacement(string templateName)
{
var prototype = _prototypeManager.Index<EntityPrototype>(templateName);
CurrentTextures = SpriteComponent.GetPrototypeTextures(prototype, ResourceCache).ToList();
CurrentPrototype = prototype;
IsActive = true;
var lst = SpriteComponent.GetPrototypeTextures(prototype, ResourceCache, out var noRot).ToList();
PreparePlacementTexList(lst, noRot);
}
public void PreparePlacementTexList(List<IDirectionalTextureProvider>? texs, bool noRot)
{
var sc = SetupPlacementOverlayEntity();
if (texs != null)
{
// This one covers most cases (including Construction)
foreach (var v in texs)
{
if (v is RSI.State)
{
var st = (RSI.State) v;
sc.AddLayer(st.StateId, st.RSI);
}
else
{
// Fallback
sc.AddLayer(v.Default);
}
}
}
else
{
sc.AddLayer(new ResourcePath("/Textures/UserInterface/tilebuildoverlay.png"));
}
sc.NoRotation = noRot;
}
private void PreparePlacementTile()
{
CurrentTextures = new List<IDirectionalTextureProvider>
{ResourceCache
.GetResource<TextureResource>(new ResourcePath("/Textures/UserInterface/tilebuildoverlay.png")).Texture};
var sc = SetupPlacementOverlayEntity();
sc.AddLayer(new ResourcePath("/Textures/UserInterface/tilebuildoverlay.png"));
IsActive = true;
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Robust.Client.Graphics;
using Robust.Client.GameObjects;
using Robust.Client.ResourceManagement;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
@@ -85,14 +86,10 @@ namespace Robust.Client.Placement
public virtual void Render(DrawingHandleWorld handle)
{
if (TexturesToDraw == null)
{
SetSprite();
DebugTools.AssertNotNull(TexturesToDraw);
}
if (TexturesToDraw == null || TexturesToDraw.Count == 0)
var sce = pManager.CurrentPlacementOverlayEntity;
if (sce == null || sce.Deleted)
return;
var sc = sce.GetComponent<SpriteComponent>();
IEnumerable<EntityCoordinates> locationcollection;
switch (pManager.PlacementType)
@@ -111,17 +108,17 @@ namespace Robust.Client.Placement
break;
}
var size = TexturesToDraw[0].Size;
var dirAng = pManager.Direction.ToAngle();
foreach (var coordinate in locationcollection)
{
if (!coordinate.IsValid(pManager.EntityManager))
return; // Just some paranoia just in case
var entity = coordinate.GetEntity(pManager.EntityManager);
var worldPos = coordinate.ToMapPos(pManager.EntityManager);
var pos = worldPos - (size/(float)EyeManager.PixelsPerMeter) / 2f;
var color = IsValidPosition(coordinate) ? ValidPlaceColor : InvalidPlaceColor;
var worldRot = entity.Transform.WorldRotation + dirAng;
foreach (var texture in TexturesToDraw)
{
handle.DrawTexture(texture, pos, color);
}
sc.Color = IsValidPosition(coordinate) ? ValidPlaceColor : InvalidPlaceColor;
sc.Render(handle, pManager.eyeManager.CurrentEye.Rotation, worldRot, worldPos);
}
}
@@ -193,14 +190,6 @@ namespace Robust.Client.Placement
return pManager.ResourceCache.TryGetResource(new ResourcePath(@"/Textures/") / key, out sprite);
}
public void SetSprite()
{
if (pManager.CurrentTextures == null)
return;
TexturesToDraw = pManager.CurrentTextures.Select(o => o.TextureFor(pManager.Direction)).ToList();
}
/// <summary>
/// Checks if the player is spawning within a certain range of his character if range is required on this mode
/// </summary>
@@ -233,7 +222,7 @@ namespace Robust.Client.Placement
bounds.Width,
bounds.Height);
return EntitySystem.Get<SharedBroadphaseSystem>().TryCollideRect(collisionBox, mapCoords.MapId);
return EntitySystem.Get<SharedPhysicsSystem>().TryCollideRect(collisionBox, mapCoords.MapId);
}
protected Vector2 ScreenToWorld(Vector2 point)

View File

@@ -24,11 +24,13 @@ namespace Robust.Client.Player
public event Action<EntityDetachedEventArgs>? EntityDetached;
/// <summary>
/// Game entity that the local player is controlling. If this is null, the player
/// is in free/spectator cam.
/// Game entity that the local player is controlling. If this is null, the player is not attached to any
/// entity at all.
/// </summary>
[ViewVariables] public IEntity? ControlledEntity { get; private set; }
[ViewVariables] public EntityUid? ControlledEntityUid => ControlledEntity?.Uid;
[ViewVariables] public NetUserId UserId { get; set; }

View File

@@ -1,7 +1,7 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Robust.UnitTesting")]
[assembly: InternalsVisibleTo("Robust.Client.CEF")]
[assembly: InternalsVisibleTo("Robust.Client.WebView")]
[assembly: InternalsVisibleTo("Robust.Lite")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
[assembly: InternalsVisibleTo("Robust.Benchmarks")]

View File

@@ -125,7 +125,7 @@ namespace Robust.Client.ResourceManagement
reg.Indices = foldedIndices;
reg.Offsets = callbackOffset;
var state = new RSI.State(frameSize, stateObject.StateId, stateObject.DirType, foldedDelays,
var state = new RSI.State(frameSize, rsi, stateObject.StateId, stateObject.DirType, foldedDelays,
textures);
rsi.AddState(state);

View File

@@ -17,7 +17,7 @@
<PackageReference Include="nfluidsynth" Version="0.3.1" />
<PackageReference Include="NVorbis" Version="0.10.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
<PackageReference Include="OpenToolkit.Graphics" Version="4.0.0-pre9.1" />
<PackageReference Include="OpenToolkit.OpenAL" Version="4.0.0-pre9.1" />
<PackageReference Include="SpaceWizards.SharpFont" Version="1.0.1" />

View File

@@ -1,5 +1,4 @@
using System;
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Map;
@@ -28,8 +27,8 @@ namespace Robust.Client.UserInterface
private bool _horizontalExpand;
private bool _verticalExpand;
private HAlignment _horizontalAlignment;
private VAlignment _verticalAlignment;
private HAlignment _horizontalAlignment = HAlignment.Stretch;
private VAlignment _verticalAlignment = VAlignment.Stretch;
private Thickness _margin;
private bool _measuring;
@@ -225,80 +224,6 @@ namespace Robust.Client.UserInterface
/// <seealso cref="Rect"/>
public UIBox2i PixelRect => UIBox2i.FromDimensions(PixelPosition, PixelSize);
/// <summary>
/// Horizontal size flags for container layout.
/// </summary>
[ViewVariables]
[Obsolete("Use HorizontalAlignment and HorizontalExpand instead.")]
public SizeFlags SizeFlagsHorizontal
{
get
{
var flags = HorizontalAlignment switch
{
HAlignment.Stretch => SizeFlags.Fill,
HAlignment.Left => SizeFlags.None,
HAlignment.Center => SizeFlags.ShrinkCenter,
HAlignment.Right => SizeFlags.ShrinkEnd,
_ => throw new ArgumentOutOfRangeException()
};
if (_horizontalExpand)
flags |= SizeFlags.Expand;
return flags;
}
set
{
HorizontalExpand = (value & SizeFlags.Expand) != 0;
HorizontalAlignment = (value & ~SizeFlags.Expand) switch
{
SizeFlags.None => HAlignment.Left,
SizeFlags.Fill => HAlignment.Stretch,
SizeFlags.ShrinkCenter => HAlignment.Center,
SizeFlags.ShrinkEnd => HAlignment.Right,
_ => throw new ArgumentOutOfRangeException()
};
}
}
/// <summary>
/// Vertical size flags for container layout.
/// </summary>
[Obsolete("Use VerticalAlignment and VerticalExpand instead.")]
[ViewVariables]
public SizeFlags SizeFlagsVertical
{
get
{
var flags = _verticalAlignment switch
{
VAlignment.Stretch => SizeFlags.Fill,
VAlignment.Top => SizeFlags.None,
VAlignment.Center => SizeFlags.ShrinkCenter,
VAlignment.Bottom => SizeFlags.ShrinkEnd,
_ => throw new ArgumentOutOfRangeException()
};
if (_verticalExpand)
flags |= SizeFlags.Expand;
return flags;
}
set
{
VerticalExpand = (value & SizeFlags.Expand) != 0;
VerticalAlignment = (value & ~SizeFlags.Expand) switch
{
SizeFlags.None => VAlignment.Top,
SizeFlags.Fill => VAlignment.Stretch,
SizeFlags.ShrinkCenter => VAlignment.Center,
SizeFlags.ShrinkEnd => VAlignment.Bottom,
_ => throw new ArgumentOutOfRangeException()
};
}
}
/// <summary>
/// Horizontal alignment mode.
/// This determines how the control should be laid out horizontally
@@ -788,46 +713,6 @@ namespace Robust.Client.UserInterface
Math.Clamp(avail.Y, minH, maxH));
}
/// <summary>
/// Controls how a control changes size when inside a container.
/// </summary>
[Flags]
[PublicAPI]
[Obsolete("Use HAlignment/VAlignment/VerticalExpand/HorizontalExpand instead")]
public enum SizeFlags : byte
{
/// <summary>
/// Shrink to the begin of the specified axis.
/// </summary>
None = 0,
/// <summary>
/// Fill as much space as possible in a container, without pushing others.
/// </summary>
Fill = 1,
/// <summary>
/// Fill as much space as possible in a container, pushing other nodes.
/// The ratio of pushing if there's multiple set to expand is dependant on <see cref="SizeFlagsStretchRatio" />
/// </summary>
Expand = 2,
/// <summary>
/// Combination of <see cref="Fill" /> and <see cref="Expand" />.
/// </summary>
FillExpand = 3,
/// <summary>
/// Shrink inside a container, aligning to the center.
/// </summary>
ShrinkCenter = 4,
/// <summary>
/// Shrink inside a container, aligning to the end.
/// </summary>
ShrinkEnd = 8,
}
/// <summary>
/// Specifies horizontal alignment modes.
/// </summary>

View File

@@ -40,6 +40,9 @@ namespace Robust.Client.UserInterface
[ViewVariables]
public string? Name { get; set; }
// ReSharper disable once ValueParameterNotUsed
public AccessLevel? Access { set { } }
/// <summary>
/// If true, this control will always be rendered, even if other UI rendering is disabled.
/// </summary>

View File

@@ -0,0 +1,12 @@
namespace Robust.Client.UserInterface
{
public enum AccessLevel
{
Public,
Protected,
Internal,
ProtectedInternal,
Private,
PrivateProtected,
}
}

Some files were not shown because too many files have changed in this diff Show More