Compare commits

...

122 Commits

Author SHA1 Message Date
metalgearsloth
6e25ead588 Version: 233.0.2 2024-08-31 18:39:01 +10:00
metalgearsloth
cfae6e1f95 Don't rely on client for grid fixture rebuilds (#5348)
* Don't rely on client for grid fixture rebuilds

Server is already networking fixture data and this has a chance to go bad.
Easier to just stop this entirely and remove the fixture references to just network the relevant ones for each chunk. Performance impact should pretty much be non-existent and it should be less buggy.

* a

* weh notes

* fix aabb update

* Fix AABB gen

* weh

* More networking
2024-08-31 18:37:43 +10:00
metalgearsloth
da56851846 Version: 233.0.1 2024-08-31 18:22:39 +10:00
metalgearsloth
69ed2c3c33 Fix IsHardCollidable (#5416) 2024-08-31 17:49:59 +10:00
metalgearsloth
c558a0327b Version: 233.0.0 2024-08-31 14:37:23 +10:00
metalgearsloth
3bb7df3254 Relative lookup fix (#5415)
* Relative lookup fix

Some of the transforms weren't being transformed, added another test.

* test

* better test

* Reduce any-entities-intersecting tests
2024-08-31 14:35:17 +10:00
metalgearsloth
ab6bd19817 Fix mouse hover not updating for new controls (#5313)
* Fix mouse hover not updating for new controls

It only ever updated on movement previously. The issue is for example if a new window shows up where the mouse is (or any control) it doesn't handle it. Just checking it every frame AFAIK shouldn't be that expensive. Worst case we just have some flag to check it that gets set on <mouse movement OR controls changed>.

* review
2024-08-31 11:45:59 +10:00
Leon Friedrich
73ef69aa94 Try and ensure that parents are always initialized before children (#5343)
* Try and ensure that parents are always initialized before children

* release notes
2024-08-31 11:05:56 +10:00
nikthechampiongr
656835e7fa Change EntityRenamedEvents arguments and make it broadcast (#5413) 2024-08-31 11:04:44 +10:00
Pieter-Jan Briers
26c87b5858 Make tests run parallelizable (#5412)
Hope this won't cause issues.

Massively improves test speed.
2024-08-31 11:04:21 +10:00
Pieter-Jan Briers
be36001ab8 Add thread check assert to core entity mutation commands. (#5411)
* Add thread check assert to core entity mutation commands.

Creation of entities and components is now checked to happen from the main thread.

This is already catching multiple buggy integration tests, these will be addressed in separate commits.

* Fix broken tests directly mutating entities from wrong thread.
2024-08-31 11:04:02 +10:00
Pieter-Jan Briers
2002402af8 Version script now supports dash versions 2024-08-29 12:52:52 +02:00
metalgearsloth
f659b2b58c Version: 232.0.0 2024-08-29 12:55:51 +10:00
metalgearsloth
b1e13f5b13 Fix BUI interfaces not deep copying (#5410)
* Fix BUI interfaces not deep copying

Didn't think I'd need to on a getstate but client state moment.

* less shitcodey
2024-08-29 12:47:32 +10:00
SlamBamActionman
e5995d4edc Add ObjectSerializer, AppearanceComponent.AppearanceDataInit, and AppearanceSystem.AppendData (#5324)
* V1 commit

* V2 Commit, ObjectSerializer

* Make sure write for objects have the !type:<T> set

* Added AppearanceDataInit

* Change to AppearanceDataInit setting to AppearanceData the moment it itself gets set; ComponentInit is too late. Forgive me sloth.

* RELEASE-NOTES.md

* Fix release notes

* Fix release-notes for realsies
2024-08-28 22:43:58 +10:00
Winkarst
6eb080a277 Add Robust.Xaml.csproj to the solution (#5408) 2024-08-28 13:49:42 +02:00
metalgearsloth
b0cb41e94a Version: 231.1.1 2024-08-28 12:23:04 +10:00
Leon Friedrich
23a23f7c22 Misc toolshed fixes (#5340)
* Prevent map/emplace command errors from locking up the server

* Fix EmplaceCommand

* Fix sort commands

* Fix JoinCommand

* changelog

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2024-08-28 12:22:47 +10:00
Pieter-Jan Briers
ec3a74d268 Version: 231.1.0 2024-08-27 17:47:25 +02:00
Pieter-Jan Briers
12b0bc4e0a Add way for content to write arbitrary files into replay. (#5405)
Added a new RecordingStopped2 event that receives a IReplayFileWriter object that can be used to write arbitrary files into the replay zip file.

Fixes #5261
2024-08-27 17:38:48 +02:00
metalgearsloth
903041dfd1 Add storage BUI bandaid (#5401) 2024-08-27 17:36:54 +02:00
metalgearsloth
b96419f0b2 Add mapmanager query tests (#5403)
Sanity
2024-08-28 00:24:24 +10:00
metalgearsloth
fe33ad2652 Add physicshull tests (#5404) 2024-08-27 23:24:23 +10:00
metalgearsloth
057a68b366 Minor allocs reductions (#5330)
* Minor allocs reductions

Added a poly struct with the intention of replacing the existing one whenever I finish box2c port.

* fix merges

* Revert some stuff

* Poly tests
2024-08-27 22:58:42 +10:00
metalgearsloth
1a2c9008fe Add Box matrix tests (#5402)
Thought we had but apparently not.
2024-08-27 22:21:48 +10:00
metalgearsloth
cd95929ebe Heavily optimise entitylookup (#5400)
* Heavily optimise entitylookup

Previously I made it so MOST of entitylookup goes through the same 4 or 5 codepaths and uses shapes. The downside was some codepaths were made much slower in the process.

This fixes most of the going up and down lookups that some codepaths did. It should also be faster than the pre-shapes version because GetLocalPhysicsTransform is being used for the non-approx queries and most entities are parented directly to their broadphase.

* Tests and confidence

* code

* dang
2024-08-27 21:32:50 +10:00
Nyeogmi
6396ec472d XAML hot reloading (#5350)
* Move RobustXaml to a shared package

In a near-future change, I'll make it possible to optionally link to
this from Robust.Client, which will allow JIT compiling XAML.

Also upgrade it to a version of .NET that supports nullability
annotations.

* Re-namespace packages

* Add a JIT compiler, plus hooks that call into it

In Debug, after this change, all XAML will be hot reloaded once every
time an assembly is reloaded.

The new code is compiled with SRE and is _not_ sandboxed -- this is not
suitable to run against prod.

In Release, the hot reload path is totally skipped, using the same trick
as SmugLeaf used in an earlier attempt to implement this functionality.

* Hot reload: watcher

This is a bit of a horror, but there's not in-engine support for
identifying the source tree or the XAML files in it.

* Put everything dangerous behind conditional comp

* Code cleanup, docs

* Fix a bad comment

* Deal a little better with crashes in the watcher

* Make reload failures Info, since they're expected

They were previously causing the integration tests to flag, even though
"a few types fail hot reloading because they're internal" is expected
behavior.

* Fix an unnecessary null check

I removed the ability for CompileCore to return null.

* injectors: null! strings, default primitives

* Tidy documentation (thanks, PJB!)

* Reinstate netstandard2.0, abolish Pidgin

* Internal-ize all of Robust.Xaml

* Add a cautionary note to Sandbox.yml

* Shuffle around where conditional compilation occurs

* Privatize fields in XamlImplementationStorage

* Internalize XamlJitDelegate

* Inline some remarks. No cond. comp in Robust.Xaml

* Use file-scoped namespaces

They aren't allowed at Language Level 8.0. (which I arbitrarily picked
for Robust.Xaml because it's the oldest one that would work)

* Bump language level for R.Xaml, file namespaces

* Force hot reloading off for integration tests

* Fix bizarre comment/behavior in XamlImplementationStorage

* Consistently use interfaces, even in generated code

* Update Robust.Client/ClientIoC.cs

---------

Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
2024-08-27 02:16:57 +02:00
Stalen
d7aa5daf6a Add decimal type to sandbox whitelist (#5396) 2024-08-27 01:35:42 +02:00
metalgearsloth
e3819f8245 Network interfacedata (#5399)
If UIs are dynamically changed this fixes it.
2024-08-26 18:48:15 +10:00
metalgearsloth
57f133b742 Version: 231.0.1 2024-08-26 14:41:40 +10:00
metalgearsloth
04344ffe19 Make PVS exception log better (#5397) 2024-08-26 14:31:05 +10:00
metalgearsloth
f2ee9a43f9 Version: 231.0.0 2024-08-25 22:48:51 +10:00
metalgearsloth
8d5ebd830a Add CompRegistry methods to EntManager / CompFac (#5379)
* Add CompRegistry methods to EntManager / CompFac

CompRegistries are nice to use and this just makes it a bit easier to extend functionality.

* fix bad pull
2024-08-25 21:37:14 +10:00
metalgearsloth
4d265b2210 Add methods to get entity sprite position (#5381)
* Add methods to get entity sprite position

No easy way to get this in world-terms and I want a control to track it.

* invalid
2024-08-25 21:24:37 +10:00
metalgearsloth
e04caf7eb4 Add OpenScreenAt for windows (#5387)
If I want to open it at a particular position. Takes in clyde ref so not every single screen needs to keep the ref.
2024-08-25 20:32:28 +10:00
metalgearsloth
a4c54d3602 Make pointlight setting use an attempt event (#5378)
Makes it easy for content to add functionality if multiple things try to set it without having to funnel every piece of code through a content system.
2024-08-25 20:27:58 +10:00
metalgearsloth
43fd6bc764 Add FixturesChangeComponent (#5383)
* Add FixturesChangeComponent

Adds / removes fixtures. Useful when used in conjunction with EntProtoId to dynamically add / remove fixtures.

* Move to system

* Fix allcomps test
2024-08-25 20:25:19 +10:00
metalgearsloth
ff056552fe Don't spam BUI closing in state handling (#5382)
We just do what content does and defer it until update. Saves performance + we don't have some BUIs that do special logic on open re-running it constantly (e.g. open on mouse position).
2024-08-25 20:08:19 +10:00
metalgearsloth
3014d9880e Fix prototype flag add not actually working (#5376)
tryindex was inverted and causing issues with tools.
2024-08-25 20:03:09 +10:00
metalgearsloth
679c31199d Add comments to sermanager attributes (#5384)
I always forget which is which.
2024-08-25 20:02:31 +10:00
metalgearsloth
0bc3c51707 Contact QOL stuff (#5385)
* Contact QOL stuff

Only just made the enumerator version need to test with AI branch had an IEnumerable before.

* Fix
2024-08-25 11:54:05 +10:00
metalgearsloth
140767c262 Move viewsubscriber to shared + handle eye targets (#5362)
* Move viewsubscriber to shared + handle eye targets

Need this stuff for AI.

* Fix dumb

* review
2024-08-23 18:29:57 +10:00
metalgearsloth
36a5b672e5 Version: 230.2.0 2024-08-23 14:36:00 +10:00
metalgearsloth
1eb63cb616 Stop inheriting IThreadPoolWorkitem (#5377)
More annoying with internal changes.
2024-08-23 14:33:36 +10:00
metalgearsloth
c14689f233 Add more directions for Vector2i (#5386)
Convenient.
2024-08-23 14:33:08 +10:00
Pieter-Jan Briers
f03c006129 Version: 230.1.0 2024-08-22 01:49:43 +02:00
qwerltaz
0d53c5e329 add bool[] support to shaders (#5373)
* Add bool array support to shaders

* better setUniform

* less unsafe

* stackalloc, less pointer
2024-08-21 22:36:03 +02:00
metalgearsloth
5cb1901870 Fix local tile enlargement (#5349)
* Fix local tile enlargement

Not used.

* release notes

---------

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2024-08-21 02:52:41 +02:00
Pieter-Jan Briers
d46885b96d Fix LocalizedEntityCommands breaking content unit tests. (#5375)
They are now not loaded inside content unit tests.

Fixes #5374
2024-08-21 02:43:46 +02:00
DrSmugleaf
0553600c9a Add cvar to limit entities passed into nearby command (#5355)
* Add cvar to limit entities passed into nearby command

* Fix double enumeration
2024-08-21 02:43:19 +02:00
DrSmugleaf
580dd5f1a6 Fix RichTextLabel.Text property not setting _message if null (#5361) 2024-08-21 02:40:50 +02:00
metalgearsloth
d47d488ce7 Broadphase init fixes (#5367)
1 for replays 1 for loadmap.
The replay one is kinda sussy but physicamap is supposed to get dumped at some point so.
2024-08-21 02:39:23 +02:00
Pieter-Jan Briers
d584e51de6 Revert LocalizedCommands Loc change.
This is what I get for ragecoding at 1 AM.
2024-08-21 02:03:16 +02:00
Pieter-Jan Briers
2f85b94ea2 Use new LocalizedCommands.Loc property in engine
Also made BaseReplayCommand.Loc an explicit hide of the base property.
2024-08-21 01:23:25 +02:00
Pieter-Jan Briers
046f7a2e55 Add "Loc" property to LocalizedCommands
Intended to match the localization manager in EntitySystem, much more convenient than the existing one.
2024-08-21 01:16:43 +02:00
c4llv07e
5f2881e3e4 Add completion support for the change state command (#5368) 2024-08-20 22:38:28 +02:00
DrSmugleaf
cdb94748c8 Make resetting contacts on the client only set is touching if it is true (#5372) 2024-08-20 19:35:14 +10:00
Stalen
53516d6389 Fixed client crash on devwindow inspect control's property which throws exception (#5370)
* Fixed client crash on devwindow inspect control property which throws exception

* Display inner exception only in case of TargetInvocationException
2024-08-19 00:55:04 +02:00
metalgearsloth
efa3e010a6 Add Flip method to SplitContainer (#5333) 2024-08-14 22:59:20 +02:00
faint
4b12ff8574 fix loadprototype (#5359) 2024-08-14 14:52:09 +02:00
Pieter-Jan Briers
59ed76c66f Remove obsolete usages of *Variant prototype manager functions
Replaced with *Kind
2024-08-13 11:45:40 +02:00
Tayrtahn
9781405f5e Better location reporting for DataField analyzers (#5344)
* Better location reporting for DataField analyzers

* Update test

* Use const string in both methods
2024-08-13 11:40:23 +02:00
Pieter-Jan Briers
2178707937 Version: 230.0.1 2024-08-11 19:49:23 +02:00
Pieter-Jan Briers
0284eb0430 Use absolute path for explorer.exe
frick me
2024-08-11 19:48:48 +02:00
Pieter-Jan Briers
2c3cc070a6 Fix oopsie from me using version.py on an existing version 2024-08-11 16:33:00 +02:00
Pieter-Jan Briers
6599f9565e Version: 230.0.0 2024-08-11 16:26:47 +02:00
Pieter-Jan Briers
85abcff5ea Version: 223.0.0 2024-08-11 16:26:32 +02:00
Pieter-Jan Briers
5b5894e2d5 Release notes 2024-08-11 16:26:25 +02:00
Pieter-Jan Briers
7d778248ee Security updates (#5353)
* Fix security bug in WritableDirProvider.OpenOsWindow()

Reported by @NarryG and @nyeogmi

* Sandbox updates

* Update ImageSharp again
2024-08-11 16:21:54 +02:00
DrSmugleaf
672819d525 Add missing return calls for positions and angles in SolveIsland (#5327) 2024-08-10 11:15:02 +10:00
Nemanja
99e4910440 Fix TimedDespawnComponent causing a crash if spawning another entity with TimedDespawnComponent (#5345) 2024-08-10 11:12:44 +10:00
Leon Friedrich
b503390837 Add InterpolatedStringHandlerArgumentAttribute to sandbox whitelist (#5339) 2024-08-08 19:10:23 +02:00
Repo
87725f27c3 Add a copy to clipboard button on alert popups. (#5336)
* Add a copy button to clipboard on Alert Popups.

* ButtonFlag and better formatting.

* Localization and style cleanup
2024-08-08 18:56:32 +02:00
metalgearsloth
49c831b48d Version: 229.1.2 2024-08-08 12:15:46 +10:00
Leon Friedrich
60a29933d8 Try fix broadphase bug (#5342)
* Try fix broadphase

* I love initialization pasta
2024-08-07 20:07:57 +10:00
metalgearsloth
5729e8eb19 Version: 229.1.1 2024-08-07 10:56:07 +10:00
Leon Friedrich
42da4b1287 Fix replay teleportation command exception (#5337) 2024-08-06 20:56:20 +10:00
metalgearsloth
3342e1272f Add audio filename to entity name (#5338)
Will make debugging tests easier.
2024-08-06 20:54:17 +10:00
metalgearsloth
5c0ce43e6c Version: 229.1.0 2024-08-05 14:54:28 +10:00
metalgearsloth
0717b1fced Avoid resolve in VV prop editor (#5335) 2024-08-05 14:53:55 +10:00
Pieter-Jan Briers
68c03196e6 Fix IPv6-only hosts in HappyEyeballsHttp
Copy paste xd
2024-08-05 00:32:33 +02:00
Pieter-Jan Briers
31292fe4b8 Do network message encryption concurrently. (#5328)
In profiles of RMC-14, encrypting network messages accounted for ~8% of main thread time. That's a lot.

Each NetChannel has an "encryption channel" which gets processed on the thread pool.
2024-08-03 15:21:54 +02:00
Pieter-Jan Briers
865348550f Fix warnings in ClientOccluderSystem.cs
PROJECT ZERO WARNINGS
2024-08-02 15:48:38 +02:00
Pieter-Jan Briers
7372233782 Fix client crash if networking handshake fails
MapManager would get an NRE access its sawmill during client reset because it depends on the uninitialized entity system.
2024-08-02 15:18:50 +02:00
Vasilis
7ebfc82dd6 Reduce the default TPS (#5326)
It is our suggestion for a long while to keep the TPS at 30 for servers. However the default was always 60.

I believe its better to have it as a default.
2024-08-02 00:27:46 +10:00
metalgearsloth
807e7e888a Fix chunkenumerator allocs (#5325)
* Fix chunkenumerator allocs

This was number 2 to pathfinding sitting afk on a server. I thought the property would cache it but apparently not. Ref struct is just nicety and it's internal and not exposed to content anyway so.

* also dis
2024-08-01 14:06:22 +02:00
Stalen
39fefcb9c8 Fixed data race in ParallelTracker (#5311)
* Fixed data race in ParallelTracker

* Added ParallelTracker fix release note
2024-07-30 15:08:58 +10:00
Tayrtahn
b6548c870c Add analyzer/fixer for replacing ProtoId<EntityPrototype> with EntProtoId (#5312)
* Add PreferOtherTypeAttribute, analyzer, and test.

* nullable enable

* Add nuget package for CodeFix verifier

* Add fixer for PreferOtherType

* Rename arguments

* Adjust diagnostic message

* Move attribute lookup
2024-07-23 19:01:43 +02:00
Pieter-Jan Briers
cf230b3454 Warning fixes centered around Clyde
Pulling entity systems into direct fields in Clyde to make it now painful. This required adding an event to ClientEntityManager when these become available, as they are only available when the client is in a server/single player.
2024-07-23 17:49:56 +02:00
Pieter-Jan Briers
16a93e86f6 Add obsoletion warning on control dispose
this shouldn't be used anymore
2024-07-21 01:45:24 +02:00
metalgearsloth
2e4275a7f3 Version: 229.0.0 2024-07-20 15:38:53 +10:00
metalgearsloth
176ca6c578 Add window helper for BUIs (#5183)
* Add window helper for BUIs

Automatically does OnClose and just makes content slightly nicer.

* more

* Add prototype reload helper

* Add Box2i Center

* weh
2024-07-20 14:50:15 +10:00
metalgearsloth
2664061993 Make PhysicsHull a ref struct (#5297)
* Make PhysicsHull a ref struct

First time I've used it but seemed like a good candidate considering it's temporary.

* weh

---------

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2024-07-15 17:43:33 +02:00
Pieter-Jan Briers
033699d7d6 Fix spawn menu breaking on larger entities
Fixes #5304
2024-07-15 16:23:25 +02:00
metalgearsloth
f696edaa0c Clamp audio tickrate (#5296)
* Clamp audio tickrate

I am reasonably sure I saw a recommended 30TPS figure somewhere but I cannot find it again. At any rate I can't notice this but imagine it provides significant benefits for people on 144hz+ monitors.

* rn

---------

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2024-07-13 20:09:49 +02:00
SlamBamActionman
4920ecaa64 Add AppearanceSystem Data dictionaries and RemoveData (#5288)
* Improved Appearance

* PR changes
2024-07-13 15:33:05 +10:00
Pieter-Jan Briers
b8924a04cf Fix RaisePredictiveEvent prediction checks (#5294)
RaisePredictiveEvent was made to not check whether prediction is enabled in #3534. This doesn't make much sense to me and is causing various SS14 game logic to erroneously run when prediction is disabled.

Here's the fix PR. Also fixes the assert to actually work (checking Connected is wrong, it should've been InGame) and makes the new check also account for SinglePlayerGame.
2024-07-13 15:30:20 +10:00
Plykiya
be11cb4bca Update GridSplit_Tests.cs to not use Component.Owner (#5300)
Co-authored-by: plykiya <plykiya@protonmail.com>
2024-07-13 15:28:47 +10:00
Plykiya
eafe395273 Update PlayerManager.cs to not use Component.Owner (#5299)
Co-authored-by: plykiya <plykiya@protonmail.com>
2024-07-13 15:28:02 +10:00
Pieter-Jan Briers
05cdb99252 Warning fixes around IMapManager.GetMapEntityId (#5298)
* Add MapSystem.GetMapOrInvalid

This is effectively the same exact behavior as IMapManager.GetMapEntityId. Adding this so I don't have to consider whether warning fixes using MapSystem.GetMap() instead would change behavior.

* Warning fixes around IMapManager.GetMapEntityId

* Fix tests
2024-07-13 15:27:32 +10:00
Plykiya
d4c6b4a828 Update MapGrid_Tests to use MapSystem functions (#5301)
* Update MapGrid_Tests.cs

* missed one

* remove unused entman

---------

Co-authored-by: plykiya <plykiya@protonmail.com>
2024-07-13 14:30:19 +10:00
metalgearsloth
fc1cca4f48 Version: 228.0.0 2024-07-12 21:50:15 +10:00
Pieter-Jan Briers
3657b0a424 Strongly order network prototypes and resources. (#5293)
* Strongly order network prototypes and resources.

When a new client connects, both the uploaded prototypes and resources get sent at once. There was no ordering here, which means that prototypes could easily load before resources. This would then obviously give load errors at runtime. In practice though this seemed fine because the RSI or something would just load fine after when spawned or something.

This was then broken by ae1051e813, which made ResourceCache start caching "that RSI doesn't exist" so it never really tried again.

I originally tried to fix this by adding an API to IResourceManager that allows content to invalidate the aforementioned cache (commit 316a7e4ac10100593202ff7f53dc2992611bbd1e, for however GitHub will track that) but then realized resource uploading isn't part of content like I first thought. Lol whoops. That API might still be useful for other dynamic content use cases, but I'm not committing it for now. That fix still caused errors to be spammed if the prototype was loaded before the resources were ready.

The new fix is to just load resources before prototypes. This is done by making them both ordered relative to each other, and running resources first.

Fixes #5291

* Release notes
2024-07-12 09:12:58 +02:00
Tayrtahn
c3d8080a8e Add PreferNonGenericVariantFor attribute and analyzer (#5190)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2024-07-10 12:33:56 +02:00
Tayrtahn
8e50924607 Add analyzer/fixer for DataFields with ReadWrite VV (#5164)
* Add analyzer/fixer for datafields with ReadWrite VV

* Nothing to see here
2024-07-10 02:04:55 +02:00
Leon Friedrich
7fdd5c9d1c Make color equality exact (#5253) 2024-07-10 01:43:12 +02:00
Pieter-Jan Briers
7fbcfeaa8f Warning fixes (#5275)
* Warning fixes in Robust.Shared

* Robust.Client warning fixes

* Fix test failure

Test failures were due to broken system registrations for the client RobustUnitTest. It was accidentally registering some server systems, which means DebugPhysicsSystem wasn't gettings its dependencies properly.

Fixing this meant pulling half a dozen extra dependencies that client ContainerSystem and TransformSystem are supposed to have, but didn't.
2024-07-10 01:38:32 +02:00
eoineoineoin
b82bc258db Add styleclass to OptionsButton popup background widget (#5290)
* Add styleclass to OptionsButton popup background widget

* Update Robust.Client/UserInterface/Controls/OptionButton.cs

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

---------

Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es>
Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
2024-07-09 23:33:16 +02:00
metalgearsloth
7ad2925f2c Add TryQueueDeleteEntity (#5281)
Having to check deleted by hand up front is annoying.
2024-07-09 23:32:17 +02:00
CaasGit
4091ad4837 Fixes two moderate security issues in ImageSharp (#5257)
Two moderate issues were fixed in ImageSharp 3.1.4:
* https://github.com/SixLabors/ImageSharp/security/advisories/GHSA-g85r-6x2q-45w7
* https://github.com/SixLabors/ImageSharp/security/advisories/GHSA-5x7m-6737-26cr
2024-07-09 23:31:49 +02:00
metalgearsloth
35881d7a6a Add SpriteSystem.IsVisible (#5283)
So content doesn't need to manually check in the rare case we update this.
2024-07-09 22:37:35 +02:00
Pieter-Jan Briers
2d28ac35d8 Interpolated string handler for AudioManager.LogALError
This reduces a decent chunk of useless log allocations.
2024-07-09 17:12:06 +02:00
Pieter-Jan Briers
8b5ad938d5 Fix a closure allocation in physics
Makes InternalParallel a static function. This makes the sort delegate on line 609 statically cacheable by the compiler as it has no state.
2024-07-09 17:00:17 +02:00
Pieter-Jan Briers
723f936a33 Add full caps doc comment about VisibilityComponent
Brought to you by "why does disabling PVS make ghosts visible in SS14"
2024-07-07 20:37:12 +02:00
ShadowCommander
2636879860 ViewVariables UI for Flags Enum and fixes enums with duplicate values (#5287)
* Add editor dropdown for large enums

* Add enum flag selection buttons

* Cleanup
2024-07-07 16:27:17 +10:00
ShadowCommander
dad1da507c Toolshed command help usage (#5274)
* Add usage to toolshed help

* Add name to toolshed usage help

* Better formatting

* Localize toolshed command usage

* Remove unnecessary call

* Cleanup

* Add release notes

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2024-07-07 16:19:56 +10:00
DrSmugleaf
145c190800 Add cvar to limit nearby command range (#5282)
* Add cvar to limit nearby command range

* Release notes

* More comment

* Fix release note

* Update Robust.Shared/CVars.cs
2024-07-07 13:54:34 +10:00
TemporalOroboros
b7cc0ec629 Adds event for mass and angular inertia changes. (#5286)
* Adds MassDataChangedEvent to physics
This event is raised in response to changes to an entities innate mass/angular inertia/center of mass

* Use properties to fetch data from component

* Comp1

* Vector2

* I sure love an analyzer that doesn't work half the time
2024-07-06 17:34:50 +10:00
Amy
ad329a6b58 whitelist (#5285)
Co-authored-by: amylizzle <amylizzle@users.noreply.github.com>
2024-07-04 15:29:03 +02:00
Guillaume E
4deba4b866 Darken SnapgridCenter placement grid (#5279)
In SS14, the bright blue placement grid was making other game objects
difficult to see in low lighting conditions.
2024-07-04 09:55:46 +10:00
deathride58
4c31083186 Replaces the entity spawn window's bespoke method of object icon rendering with entityprototypeview (#5277) 2024-07-03 21:37:18 +10:00
DrSmugleaf
d31e7ccb55 Add Text property to RichTextLabel (#5280) 2024-07-03 13:02:41 +02:00
264 changed files with 7080 additions and 1664 deletions

View File

@@ -19,6 +19,7 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzer.Testing" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.NUnit" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.NUnit" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Features" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.8.0" />
@@ -55,7 +56,7 @@
<PackageVersion Include="Serilog" Version="3.1.1" />
<PackageVersion Include="Serilog.Sinks.Loki" Version="4.0.0-beta3" />
<PackageVersion Include="SharpZstd.Interop" Version="1.5.2-beta2" />
<PackageVersion Include="SixLabors.ImageSharp" Version="3.1.3" />
<PackageVersion Include="SixLabors.ImageSharp" Version="3.1.5" />
<PackageVersion Include="SpaceWizards.HttpListener" Version="0.1.1" />
<PackageVersion Include="SpaceWizards.NFluidsynth" Version="0.1.1" />
<PackageVersion Include="SpaceWizards.SharpFont" Version="1.0.2" />

View File

@@ -1,4 +1,4 @@
<Project>
<!-- This file automatically reset by Tools/version.py -->
<!-- This file automatically reset by Tools/version.py -->

View File

@@ -54,6 +54,242 @@ END TEMPLATE-->
*None yet*
## 233.0.2
### Bugfixes
* Fix exceptions in client game state handling for grids. Now they will rely upon the networked fixture data and not try to rebuild in the grid state handler.
## 233.0.1
### Bugfixes
* Fix IsHardCollidable component to EntityUid references.
## 233.0.0
### Breaking changes
* Made EntityRenamed a broadcast event & added additional args.
* Made test runs parallelizable.
* Added a debug assert that other threads aren't touching entities.
### Bugfixes
* Fix some entitylookup method transformations and add more tests.
* Fix mousehover not updating if new controls showed up under the mouse.
### Internal
* `ClientGameStateManager` now only initialises or starts entities after their parents have already been initialized. There are also some new debug asserts to try ensure that this rule isn't broken elsewhere.
* Engine version script now supports dashes.
## 232.0.0
### Breaking changes
* Obsolete method `AppearanceComponent.TryGetData` is now access-restricted to `SharedAppearanceSystem`; use `SharedAppearanceSystem.TryGetData` instead.
### New features
* Added `SharedAppearanceSystem.AppendData`, which appends non-existing `AppearanceData` from one `AppearanceComponent` to another.
* Added `AppearanceComponent.AppearanceDataInit`, which can be used to set initial `AppearanceData` entries in .yaml.
### Bugfixes
* Fix BUI interfaces not deep-copying in state handling.
* Add Robust.Xaml.csproj to the solution to fix some XAML issues.
### Other
* Serialization will now add type tags (`!type:<T>`) for necessary `NodeData` when writing (currently only for `object` nodes).
### Internal
* Added `ObjectSerializer`, which handles serialization of the generic `object` type.
## 231.1.1
### Bugfixes
* Fixed a bug where the client might not add entities to the broadphase/lookup components.
* Fixed various toolshed commands not working, including `sort`, `sortdown` `join` (for strings), and `emplace`
### Other
* Toolshed command blocks now stop executing if previous errors were not handled / cleared.
## 231.1.0
### New features
* Network `InterfaceData` on `UserInterfaceComponent`.
* Added `System.Decimal` to sandbox.
* Added XAML hot reloading.
* Added API for content to write custom files into replay through `IReplayFileWriter`.
### Other
* Optimized `EntityLookup` and other physics systems.
### Internal
* Added more tests related to physics.
## 231.0.1
### Other
* Add better logging to failed PVS sends.
## 231.0.0
### Breaking changes
* ViewSubscriber has been moved to shared; it doesn't actually do anything on the client but makes shared code easier.
### New features
* ContactEnumreator exists to iterate the contacts of a particular entity.
* Add FixturesChangeComponent as a generic way to add and remove fixtures easily.
* PointLightComponent enabling / disabling now has an attempt event if you wish to block it on content side.
* There's an OpenScreenAt overload for screen-relative coordinates.
* SpriteSystem has methods to get an entity's position in sprite terms.
* EntityManager and ComponentFactory now have additional methods that interact with ComponentRegistry and ComponentRegistryEntry.
### Bugfixes
* Fix PrototypeFlags Add not actually working.
* Fix BUIs going BRRT opening and closing repeatedly upon prediction. The closing now gets deferred to the update loop if it's still closed at the end of prediction.
## 230.2.0
### New features
* Add ProcessNow for IRobustJob as a convenience method where you may not want to run a job in the background sometimes.
* Add Vector2i helpers to all 8 neighbouring directions.
### Other
* Remove IThreadPoolWorkItem interface from IRobustJob.
## 230.1.0
### New features
* You can now pass `bool[]` parameters to shaders.
* Added `toolshed.nearby_entities_limit` CVar.
* Fix `RichTextLabel.Text` to clear and reset the message properly in all cases.
* `scene` command has tab completion now.
* `devwindow` UI inspector property catches exceptions for read properties.
* `SplitContainer.Flip()`
### Bugfixes
* Fix tile enlargement not being applied for some EntityLookup queries.
* `LocalizedEntityCommands` are now not initialized inside `RobustUnitTest`, fixing guaranteed test failures.
* Fixed issues with broadphase init breaking replays frequently.
* Fix uploaded prototypes and resources for clients connecting to a server.
### Other
* Improved error reporting for DataField analyzer.
## 230.0.1
## 230.0.0
### New features
* Added `InterpolatedStringHandlerArgumentAttribute` to the sandbox whitelist.
* `IUserInterfaceManager.Popup()` popups now have a copy to clipboard button.
### Bugfixes
* Security fixes
* Fix exception in `TimedDespawnComponent` spawning another `TimedDespawnComponent`.
* Fixed pool memory leak in physics `SolveIsland`.
## 229.1.2
### Bugfixes
* Fixed a bug where the client might not add entities to the broadphase/lookup components.
## 229.1.1
### Bugfixes
* Fix some teleportation commands not working in singleplayer or replays
### Other
* Audio entity names now include the filepath of the audio being played if relevant for debugging.
## 229.1.0
### Bugfixes
* Fix multithreading bug in ParallelTracker that caused the game to crash randomly.
* Fixed IPv6-only hosts not working properly with built-in HTTP clients.
### Other
* Added obsoletion warning for `Control.Dispose()`. New code should not rely on it.
* Reduced the default tickrate to 30 ticks.
* Encryption of network messages is now done concurrently to avoid spending main thread time. In profiles, this added up to ~8% of main thread time on RMC-14.
## 229.0.0
### Breaking changes
* Fixes large entities causing entity spawn menu to break.
* Made PhysicsHull an internal ref struct for some PolygonShape speedup.
### New features
* Audio ticks-per-second is now capped at 30 by default and controlled via `audio.tick_rate` cvar.
* Add CreateWindow and CreateDisposableControl helpers for BUIs.
* Add OnProtoReload virtual method to BUIs that gets called on prototype reloads.
* Add RemoveData to AppearanceSystem data.
## 228.0.0
### Breaking changes
* The `Color` struct's equality methods now check for exact equality. Use `MathHelper.CloseToPercent(Color, Color)` for the previous functionality.
* Added a toolshed.nearby_limit cvar to limit the maximum range of the nearby command. Defaults to 200.
### New features
* Added command usage with types to Toolshed command help.
* Add Text property to RichTextLabel.
* Whitelist System.Net.IPEndPoint.
* Add event for mass & angular inertia changes.
* Add SpriteSystem.IsVisible for layers.
* Add TryQueueDeleteEntity that checks if the entity is already deleted / queuedeleted first.
### Bugfixes
* Clients connecting to a server now always load prototype uploads after resource uploads, fixing ordering bugs that could cause various errors.
## 227.0.0
### Breaking changes

View File

@@ -0,0 +1,2 @@
popup-copy-button = Copy
popup-title = Alert!

View File

@@ -0,0 +1,91 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using NUnit.Framework;
using VerifyCS =
Microsoft.CodeAnalysis.CSharp.Testing.NUnit.AnalyzerVerifier<Robust.Analyzers.DataDefinitionAnalyzer>;
namespace Robust.Analyzers.Tests;
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)]
[TestFixture]
public sealed class DataDefinitionAnalyzerTest
{
private static Task Verifier(string code, params DiagnosticResult[] expected)
{
var test = new CSharpAnalyzerTest<DataDefinitionAnalyzer, NUnitVerifier>()
{
TestState =
{
Sources = { code }
},
};
// ExpectedDiagnostics cannot be set, so we need to AddRange here...
test.TestState.ExpectedDiagnostics.AddRange(expected);
return test.RunAsync();
}
[Test]
public async Task Test()
{
const string code = """
using System;
using Robust.Shared.ViewVariables;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Robust.Shared.ViewVariables
{
public sealed class ViewVariablesAttribute : Attribute
{
public readonly VVAccess Access = VVAccess.ReadOnly;
public ViewVariablesAttribute() { }
public ViewVariablesAttribute(VVAccess access)
{
Access = access;
}
}
public enum VVAccess : byte
{
ReadOnly = 0,
ReadWrite = 1,
}
}
namespace Robust.Shared.Serialization.Manager.Attributes
{
public class DataFieldBaseAttribute : Attribute;
public class DataFieldAttribute : DataFieldBaseAttribute;
public sealed class DataDefinitionAttribute : Attribute;
}
[DataDefinition]
public sealed partial class Foo
{
[DataField, ViewVariables(VVAccess.ReadWrite)]
public int Bad;
[DataField]
public int Good;
[DataField, ViewVariables]
public int Good2;
[DataField, ViewVariables(VVAccess.ReadOnly)]
public int Good3;
[ViewVariables]
public int Good4;
}
""";
await Verifier(code,
// /0/Test0.cs(35,17): info RA0028: Data field Bad in data definition Foo has ViewVariables attribute with ReadWrite access, which is redundant
VerifyCS.Diagnostic(DataDefinitionAnalyzer.DataFieldNoVVReadWriteRule).WithSpan(35, 17, 35, 50).WithArguments("Bad", "Foo")
);
}
}

View File

@@ -0,0 +1,71 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using NUnit.Framework;
using VerifyCS =
Microsoft.CodeAnalysis.CSharp.Testing.NUnit.AnalyzerVerifier<Robust.Analyzers.PreferNonGenericVariantForAnalyzer>;
namespace Robust.Analyzers.Tests;
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)]
[TestFixture]
public sealed class PreferNonGenericVariantForTest
{
private static Task Verifier(string code, params DiagnosticResult[] expected)
{
var test = new CSharpAnalyzerTest<PreferNonGenericVariantForAnalyzer, NUnitVerifier>()
{
TestState =
{
Sources = { code },
},
};
TestHelper.AddEmbeddedSources(
test.TestState,
"Robust.Shared.Analyzers.PreferNonGenericVariantForAttribute.cs"
);
// ExpectedDiagnostics cannot be set, so we need to AddRange here...
test.TestState.ExpectedDiagnostics.AddRange(expected);
return test.RunAsync();
}
[Test]
public async Task Test()
{
const string code = """
using Robust.Shared.Analyzers;
public class Bar { };
public class Baz { };
public class Okay { };
public static class Foo
{
[PreferNonGenericVariantFor(typeof(Bar), typeof(Baz))]
public static void DoFoo<T>() { }
}
public class Test
{
public void DoBad()
{
Foo.DoFoo<Bar>();
}
public void DoGood()
{
Foo.DoFoo<Okay>();
}
}
""";
await Verifier(code,
// /0/Test0.cs(17,9): warning RA0029: Use the non-generic variant of this method for type Bar
VerifyCS.Diagnostic().WithSpan(17, 9, 17, 25).WithArguments("Bar")
);
}
}

View File

@@ -0,0 +1,62 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using NUnit.Framework;
using VerifyCS =
Microsoft.CodeAnalysis.CSharp.Testing.NUnit.AnalyzerVerifier<Robust.Analyzers.PreferOtherTypeAnalyzer>;
namespace Robust.Analyzers.Tests;
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)]
[TestFixture]
public sealed class PreferOtherTypeAnalyzerTest
{
private static Task Verifier(string code, params DiagnosticResult[] expected)
{
var test = new CSharpAnalyzerTest<PreferOtherTypeAnalyzer, NUnitVerifier>()
{
TestState =
{
Sources = { code },
},
};
TestHelper.AddEmbeddedSources(
test.TestState,
"Robust.Shared.Analyzers.PreferOtherTypeAttribute.cs"
);
// ExpectedDiagnostics cannot be set, so we need to AddRange here...
test.TestState.ExpectedDiagnostics.AddRange(expected);
return test.RunAsync();
}
[Test]
public async Task Test()
{
const string code = """
using Robust.Shared.Analyzers;
public class EntityPrototype { };
public class EntProtoId { };
public class ReagentPrototype { };
[PreferOtherType(typeof(EntityPrototype), typeof(EntProtoId))]
public class ProtoId<T> { };
public class Test
{
public ProtoId<EntityPrototype> Bad = new();
public ProtoId<ReagentPrototype> Good = new();
}
""";
await Verifier(code,
// /0/Test0.cs(12,12): warning RA0031: Use the specific type EntProtoId instead of ProtoId when the type argument is EntityPrototype
VerifyCS.Diagnostic().WithSpan(12, 12, 12, 48).WithArguments("EntProtoId", "ProtoId", "EntityPrototype")
);
}
}

View File

@@ -0,0 +1,81 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using NUnit.Framework;
using VerifyCS =
Microsoft.CodeAnalysis.CSharp.Testing.NUnit.AnalyzerVerifier<Robust.Analyzers.PreferOtherTypeAnalyzer>;
namespace Robust.Analyzers.Tests;
public sealed class PreferOtherTypeFixerTest
{
private static Task Verifier(string code, string fixedCode, params DiagnosticResult[] expected)
{
var test = new CSharpCodeFixTest<PreferOtherTypeAnalyzer, PreferOtherTypeFixer, NUnitVerifier>()
{
TestState =
{
Sources = { code },
},
FixedState =
{
Sources = { fixedCode },
}
};
TestHelper.AddEmbeddedSources(
test.TestState,
"Robust.Shared.Analyzers.PreferOtherTypeAttribute.cs"
);
TestHelper.AddEmbeddedSources(
test.FixedState,
"Robust.Shared.Analyzers.PreferOtherTypeAttribute.cs"
);
test.TestState.ExpectedDiagnostics.AddRange(expected);
return test.RunAsync();
}
[Test]
public async Task Test()
{
const string code = """
using Robust.Shared.Analyzers;
public class EntityPrototype { };
public class EntProtoId { };
public class ReagentPrototype { };
[PreferOtherType(typeof(EntityPrototype), typeof(EntProtoId))]
public class ProtoId<T> { };
public class Test
{
public ProtoId<EntityPrototype> Foo = new();
}
""";
const string fixedCode = """
using Robust.Shared.Analyzers;
public class EntityPrototype { };
public class EntProtoId { };
public class ReagentPrototype { };
[PreferOtherType(typeof(EntityPrototype), typeof(EntProtoId))]
public class ProtoId<T> { };
public class Test
{
public EntProtoId Foo = new();
}
""";
await Verifier(code, fixedCode,
// /0/Test0.cs(12,12): error RA0031: Use the specific type EntProtoId instead of ProtoId when the type argument is EntityPrototype
VerifyCS.Diagnostic().WithSpan(12, 12, 12, 48).WithArguments("EntProtoId", "ProtoId", "EntityPrototype"));
}
}

View File

@@ -11,6 +11,8 @@
<EmbeddedResource Include="..\Robust.Shared\Analyzers\AccessAttribute.cs" LogicalName="Robust.Shared.Analyzers.AccessAttribute.cs" LinkBase="Implementations" />
<EmbeddedResource Include="..\Robust.Shared\Analyzers\AccessPermissions.cs" LogicalName="Robust.Shared.Analyzers.AccessPermissions.cs" LinkBase="Implementations" />
<EmbeddedResource Include="..\Robust.Shared\Analyzers\MustCallBaseAttribute.cs" LogicalName="Robust.Shared.IoC.MustCallBaseAttribute.cs" LinkBase="Implementations" />
<EmbeddedResource Include="..\Robust.Shared\Analyzers\PreferNonGenericVariantForAttribute.cs" LogicalName="Robust.Shared.Analyzers.PreferNonGenericVariantForAttribute.cs" LinkBase="Implementations" />
<EmbeddedResource Include="..\Robust.Shared\Analyzers\PreferOtherTypeAttribute.cs" LogicalName="Robust.Shared.Analyzers.PreferOtherTypeAttribute.cs" LinkBase="Implementations" />
<EmbeddedResource Include="..\Robust.Shared\IoC\DependencyAttribute.cs" LogicalName="Robust.Shared.IoC.DependencyAttribute.cs" LinkBase="Implementations" />
</ItemGroup>
@@ -26,6 +28,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.Analyzer.Testing"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.NUnit"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.NUnit"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces"/>
<PackageReference Include="NUnit"/>
<PackageReference Include="NUnit3TestAdapter"/>

View File

@@ -7,6 +7,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Robust.Roslyn.Shared;
using Robust.Shared.Serialization.Manager.Definition;
using Robust.Shared.ViewVariables;
namespace Robust.Analyzers;
@@ -16,6 +17,9 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
private const string DataDefinitionNamespace = "Robust.Shared.Serialization.Manager.Attributes.DataDefinitionAttribute";
private const string ImplicitDataDefinitionNamespace = "Robust.Shared.Serialization.Manager.Attributes.ImplicitDataDefinitionForInheritorsAttribute";
private const string DataFieldBaseNamespace = "Robust.Shared.Serialization.Manager.Attributes.DataFieldBaseAttribute";
private const string ViewVariablesNamespace = "Robust.Shared.ViewVariables.ViewVariablesAttribute";
private const string DataFieldAttributeName = "DataField";
private const string ViewVariablesAttributeName = "ViewVariables";
private static readonly DiagnosticDescriptor DataDefinitionPartialRule = new(
Diagnostics.IdDataDefinitionPartial,
@@ -66,9 +70,20 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
true,
"Make sure to remove the tag string from the data field attribute."
);
public static readonly DiagnosticDescriptor DataFieldNoVVReadWriteRule = new(
Diagnostics.IdDataFieldNoVVReadWrite,
"Data field has VV ReadWrite",
"Data field {0} in data definition {1} has ViewVariables attribute with ReadWrite access, which is redundant",
"Usage",
DiagnosticSeverity.Info,
true,
"Make sure to remove the ViewVariables attribute."
);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(
DataDefinitionPartialRule, NestedDataDefinitionPartialRule, DataFieldWritableRule, DataFieldPropertyWritableRule,
DataFieldRedundantTagRule
DataFieldRedundantTagRule, DataFieldNoVVReadWriteRule
);
public override void Initialize(AnalysisContext context)
@@ -139,7 +154,14 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
if (HasRedundantTag(fieldSymbol))
{
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, context.Node.GetLocation(), fieldSymbol.Name, type.Name));
TryGetAttributeLocation(field, DataFieldAttributeName, out var location);
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, location, fieldSymbol.Name, type.Name));
}
if (HasVVReadWrite(fieldSymbol))
{
TryGetAttributeLocation(field, ViewVariablesAttributeName, out var location);
context.ReportDiagnostic(Diagnostic.Create(DataFieldNoVVReadWriteRule, location, fieldSymbol.Name, type.Name));
}
}
}
@@ -168,7 +190,14 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
if (HasRedundantTag(propertySymbol))
{
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, context.Node.GetLocation(), propertySymbol.Name, type.Name));
TryGetAttributeLocation(property, DataFieldAttributeName, out var location);
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, location, propertySymbol.Name, type.Name));
}
if (HasVVReadWrite(propertySymbol))
{
TryGetAttributeLocation(property, ViewVariablesAttributeName, out var location);
context.ReportDiagnostic(Diagnostic.Create(DataFieldNoVVReadWriteRule, location, propertySymbol.Name, type.Name));
}
}
@@ -238,6 +267,24 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
return false;
}
private static bool TryGetAttributeLocation(MemberDeclarationSyntax syntax, string attributeName, out Location location)
{
foreach (var attributeList in syntax.AttributeLists)
{
foreach (var attribute in attributeList.Attributes)
{
if (attribute.Name.ToString() != attributeName)
continue;
location = attribute.GetLocation();
return true;
}
}
// Default to the declaration syntax's location
location = syntax.GetLocation();
return false;
}
private static bool IsReadOnlyMember(ITypeSymbol type, ISymbol member)
{
if (member is IFieldSymbol field)
@@ -292,6 +339,34 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
return explicitName == automaticName;
}
private static bool HasVVReadWrite(ISymbol symbol)
{
if (!IsDataField(symbol, out _, out _))
return false;
// Make sure it has ViewVariablesAttribute
AttributeData? viewVariablesAttribute = null;
foreach (var attr in symbol.GetAttributes())
{
if (attr.AttributeClass?.ToDisplayString() == ViewVariablesNamespace)
{
viewVariablesAttribute = attr;
}
}
if (viewVariablesAttribute == null)
return false;
// Default is ReadOnly, which is fine
if (viewVariablesAttribute.ConstructorArguments.Length == 0)
return false;
var accessArgument = viewVariablesAttribute.ConstructorArguments[0];
if (accessArgument.Value is not byte accessByte)
return false;
return (VVAccess)accessByte == VVAccess.ReadWrite;
}
private static bool IsImplicitDataDefinition(ITypeSymbol type)
{
if (HasAttribute(type, ImplicitDataDefinitionNamespace))

View File

@@ -15,9 +15,11 @@ public sealed class DefinitionFixer : CodeFixProvider
{
private const string DataFieldAttributeName = "DataField";
private const string ViewVariablesAttributeName = "ViewVariables";
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(
IdDataDefinitionPartial, IdNestedDataDefinitionPartial, IdDataFieldWritable, IdDataFieldPropertyWritable,
IdDataFieldRedundantTag
IdDataFieldRedundantTag, IdDataFieldNoVVReadWrite
);
public override Task RegisterCodeFixesAsync(CodeFixContext context)
@@ -36,6 +38,8 @@ public sealed class DefinitionFixer : CodeFixProvider
return RegisterDataFieldPropertyFix(context, diagnostic);
case IdDataFieldRedundantTag:
return RegisterRedundantTagFix(context, diagnostic);
case IdDataFieldNoVVReadWrite:
return RegisterVVReadWriteFix(context, diagnostic);
}
}
@@ -136,6 +140,48 @@ public sealed class DefinitionFixer : CodeFixProvider
return document.WithSyntaxRoot(root);
}
private static async Task RegisterVVReadWriteFix(CodeFixContext context, Diagnostic diagnostic)
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
var span = diagnostic.Location.SourceSpan;
var token = root?.FindToken(span.Start).Parent?.AncestorsAndSelf().OfType<MemberDeclarationSyntax>().First();
if (token == null)
return;
context.RegisterCodeFix(CodeAction.Create(
"Remove ViewVariables attribute",
c => RemoveVVAttribute(context.Document, token, c),
"Remove ViewVariables attribute"
), diagnostic);
}
private static async Task<Document> RemoveVVAttribute(Document document, MemberDeclarationSyntax syntax, CancellationToken cancellation)
{
var root = (CompilationUnitSyntax?) await document.GetSyntaxRootAsync(cancellation);
var newLists = new SyntaxList<AttributeListSyntax>();
foreach (var attributeList in syntax.AttributeLists)
{
var attributes = new SeparatedSyntaxList<AttributeSyntax>();
foreach (var attribute in attributeList.Attributes)
{
if (attribute.Name.ToString() != ViewVariablesAttributeName)
{
attributes = attributes.Add(attribute);
}
}
// Don't add empty lists []
if (attributes.Count > 0)
newLists = newLists.Add(attributeList.WithAttributes(attributes));
}
var newSyntax = syntax.WithAttributeLists(newLists);
root = root!.ReplaceNode(syntax, newSyntax);
return document.WithSyntaxRoot(root);
}
private static async Task RegisterDataFieldFix(CodeFixContext context, Diagnostic diagnostic)
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken);

View File

@@ -0,0 +1,65 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Operations;
using Robust.Roslyn.Shared;
namespace Robust.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class PreferNonGenericVariantForAnalyzer : DiagnosticAnalyzer
{
private const string AttributeType = "Robust.Shared.Analyzers.PreferNonGenericVariantForAttribute";
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(
UseNonGenericVariantDescriptor
);
private static readonly DiagnosticDescriptor UseNonGenericVariantDescriptor = new(
Diagnostics.IdUseNonGenericVariant,
"Consider using the non-generic variant of this method",
"Use the non-generic variant of this method for type {0}",
"Usage",
DiagnosticSeverity.Warning,
true,
"Use the generic variant of this method.");
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.ReportDiagnostics | GeneratedCodeAnalysisFlags.Analyze);
context.EnableConcurrentExecution();
context.RegisterOperationAction(CheckForNonGenericVariant, OperationKind.Invocation);
}
private void CheckForNonGenericVariant(OperationAnalysisContext obj)
{
if (obj.Operation is not IInvocationOperation invocationOperation) return;
var preferNonGenericAttribute = obj.Compilation.GetTypeByMetadataName(AttributeType);
HashSet<ITypeSymbol> forTypes = [];
foreach (var attribute in invocationOperation.TargetMethod.GetAttributes())
{
if (!SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, preferNonGenericAttribute))
continue;
foreach (var type in attribute.ConstructorArguments[0].Values)
forTypes.Add((ITypeSymbol)type.Value);
break;
}
if (forTypes == null)
return;
foreach (var typeArg in invocationOperation.TargetMethod.TypeArguments)
{
if (forTypes.Contains(typeArg))
{
obj.ReportDiagnostic(
Diagnostic.Create(UseNonGenericVariantDescriptor,
invocationOperation.Syntax.GetLocation(), typeArg.Name));
}
}
}
}

View File

@@ -0,0 +1,75 @@
#nullable enable
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Robust.Roslyn.Shared;
namespace Robust.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class PreferOtherTypeAnalyzer : DiagnosticAnalyzer
{
private const string AttributeType = "Robust.Shared.Analyzers.PreferOtherTypeAttribute";
private static readonly DiagnosticDescriptor PreferOtherTypeDescriptor = new(
Diagnostics.IdPreferOtherType,
"Use the specific type",
"Use the specific type {0} instead of {1} when the type argument is {2}",
"Usage",
DiagnosticSeverity.Error,
true,
"Use the specific type.");
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(
PreferOtherTypeDescriptor
);
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.ReportDiagnostics | GeneratedCodeAnalysisFlags.Analyze);
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzeField, SyntaxKind.VariableDeclaration);
}
private void AnalyzeField(SyntaxNodeAnalysisContext context)
{
if (context.Node is not VariableDeclarationSyntax node)
return;
// Get the type of the generic being used
if (node.Type is not GenericNameSyntax genericName)
return;
var genericSyntax = genericName.TypeArgumentList.Arguments[0];
if (context.SemanticModel.GetSymbolInfo(genericSyntax).Symbol is not { } genericType)
return;
// Look for the PreferOtherTypeAttribute
var symbolInfo = context.SemanticModel.GetSymbolInfo(node.Type);
if (symbolInfo.Symbol?.GetAttributes() is not { } attributes)
return;
var preferOtherTypeAttribute = context.Compilation.GetTypeByMetadataName(AttributeType);
foreach (var attribute in attributes)
{
if (!SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, preferOtherTypeAttribute))
continue;
// See if the generic type argument matches the type the attribute specifies
if (attribute.ConstructorArguments[0].Value is not ITypeSymbol checkedType)
return;
if (!SymbolEqualityComparer.Default.Equals(checkedType, genericType))
continue;
if (attribute.ConstructorArguments[1].Value is not ITypeSymbol replacementType)
continue;
context.ReportDiagnostic(Diagnostic.Create(PreferOtherTypeDescriptor,
context.Node.GetLocation(),
replacementType.Name,
symbolInfo.Symbol.Name,
genericType.Name));
}
}
}

View File

@@ -0,0 +1,97 @@
#nullable enable
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Robust.Roslyn.Shared.Diagnostics;
namespace Robust.Analyzers;
[ExportCodeFixProvider(LanguageNames.CSharp)]
public sealed class PreferOtherTypeFixer : CodeFixProvider
{
private const string PreferOtherTypeAttributeName = "PreferOtherTypeAttribute";
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(
IdPreferOtherType
);
public override FixAllProvider GetFixAllProvider()
{
return WellKnownFixAllProviders.BatchFixer;
}
public override Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
switch (diagnostic.Id)
{
case IdPreferOtherType:
return RegisterReplaceType(context, diagnostic);
}
}
return Task.CompletedTask;
}
private static async Task RegisterReplaceType(CodeFixContext context, Diagnostic diagnostic)
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
var span = diagnostic.Location.SourceSpan;
var token = root?.FindToken(span.Start).Parent?.AncestorsAndSelf().OfType<VariableDeclarationSyntax>().First();
if (token == null)
return;
context.RegisterCodeFix(CodeAction.Create(
"Replace type",
c => ReplaceType(context.Document, token, c),
"Replace type"
), diagnostic);
}
private static async Task<Document> ReplaceType(Document document, VariableDeclarationSyntax syntax, CancellationToken cancellation)
{
var root = (CompilationUnitSyntax?) await document.GetSyntaxRootAsync(cancellation);
var model = await document.GetSemanticModelAsync(cancellation);
if (model == null)
return document;
if (syntax.Type is not GenericNameSyntax genericNameSyntax)
return document;
var genericTypeSyntax = genericNameSyntax.TypeArgumentList.Arguments[0];
if (model.GetSymbolInfo(genericTypeSyntax).Symbol is not {} genericTypeSymbol)
return document;
var symbolInfo = model.GetSymbolInfo(syntax.Type);
if (symbolInfo.Symbol?.GetAttributes() is not { } attributes)
return document;
foreach (var attribute in attributes)
{
if (attribute.AttributeClass?.Name != PreferOtherTypeAttributeName)
continue;
if (attribute.ConstructorArguments[0].Value is not ITypeSymbol checkedTypeSymbol)
continue;
if (!SymbolEqualityComparer.Default.Equals(checkedTypeSymbol, genericTypeSymbol))
continue;
if (attribute.ConstructorArguments[1].Value is not ITypeSymbol replacementTypeSymbol)
continue;
var replacementIdentifier = SyntaxFactory.IdentifierName(replacementTypeSymbol.Name);
var replacementSyntax = syntax.WithType(replacementIdentifier);
root = root!.ReplaceNode(syntax, replacementSyntax);
return document.WithSyntaxRoot(root);
}
return document;
}
}

View File

@@ -16,9 +16,21 @@
<Compile Include="..\Robust.Shared\Analyzers\PreferGenericVariantAttribute.cs" LinkBase="Implementations" />
</ItemGroup>
<ItemGroup>
<!-- Needed for PreferNonGenericVariantAnalyzer. -->
<Compile Include="..\Robust.Shared\Analyzers\PreferNonGenericVariantForAttribute.cs" LinkBase="Implementations" />
</ItemGroup>
<ItemGroup>
<!-- Needed for PreferOtherTypeAnalyzer. -->
<Compile Include="..\Robust.Shared\Analyzers\PreferOtherTypeAttribute.cs" LinkBase="Implementations" />
</ItemGroup>
<ItemGroup>
<!-- Needed for DataDefinitionAnalyzer. -->
<Compile Include="..\Robust.Shared\Serialization\Manager\Definition\DataDefinitionUtility.cs" LinkBase="Implementations" />
<Compile Include="..\Robust.Shared\ViewVariables\ViewVariablesAttribute.cs" LinkBase="Implementations" />
<Compile Include="..\Robust.Shared\Serialization\NetSerializableAttribute.cs" LinkBase="Implementations" />
</ItemGroup>
<Import Project="../Robust.Roslyn.Shared/Robust.Roslyn.Shared.props" />

View File

@@ -1,8 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Robust.Xaml;
namespace Robust.Build.Tasks
{
@@ -37,10 +37,12 @@ namespace Robust.Build.Tasks
var msg = $"CompileRobustXamlTask -> AssemblyFile:{AssemblyFile}, ProjectDirectory:{ProjectDirectory}, OutputPath:{OutputPath}";
BuildEngine.LogMessage(msg, MessageImportance.High);
var res = XamlCompiler.Compile(BuildEngine, input,
var res = XamlAotCompiler.Compile(
BuildEngine, input,
File.ReadAllLines(ReferencesFilePath).Where(l => !string.IsNullOrWhiteSpace(l)).ToArray(),
ProjectDirectory, OutputPath,
(SignAssembly && !DelaySign) ? AssemblyOriginatorKeyFile : null);
OutputPath,
(SignAssembly && !DelaySign) ? AssemblyOriginatorKeyFile : null
);
if (!res.success)
return false;
if (!res.writtentofile)
@@ -65,22 +67,24 @@ namespace Robust.Build.Tasks
return true;
}
// PYREX NOTE: This project was comically null-unsafe before I touched it. I'm just marking what it did accurately
[Required]
public string ReferencesFilePath { get; set; }
public string ReferencesFilePath { get; set; } = null!;
[Required]
public string ProjectDirectory { get; set; }
public string ProjectDirectory { get; set; } = null!;
[Required]
public string AssemblyFile { get; set; }
public string AssemblyFile { get; set; } = null!;
[Required]
public string OriginalCopyPath { get; set; }
public string? OriginalCopyPath { get; set; } = null;
public string OutputPath { get; set; }
public string UpdateBuildIndicator { get; set; }
public string? OutputPath { get; set; }
public string UpdateBuildIndicator { get; set; } = null!;
public string AssemblyOriginatorKeyFile { get; set; }
public string AssemblyOriginatorKeyFile { get; set; } = null!;
public bool SignAssembly { get; set; }
public bool DelaySign { get; set; }
@@ -95,7 +99,7 @@ namespace Robust.Build.Tasks
return rv;
}
public IBuildEngine BuildEngine { get; set; }
public ITaskHost HostObject { get; set; }
public IBuildEngine BuildEngine { get; set; } = null!;
public ITaskHost HostObject { get; set; } = null!;
}
}

View File

@@ -1,37 +0,0 @@
using System.Linq;
using Pidgin;
using static Pidgin.Parser;
namespace Robust.Build.Tasks
{
public static class MathParsing
{
public static Parser<char, float> Single { get; } = Real.Select(c => (float) c);
public static Parser<char, float> Single1 { get; }
= Single.Between(SkipWhitespaces);
public static Parser<char, (float, float)> Single2 { get; }
= Single.Before(SkipWhitespaces).Repeat(2).Select(e =>
{
var arr = e.ToArray();
return (arr[0], arr[1]);
});
public static Parser<char, (float, float, float, float)> Single4 { get; }
= Single.Before(SkipWhitespaces).Repeat(4).Select(e =>
{
var arr = e.ToArray();
return (arr[0], arr[1], arr[2], arr[3]);
});
public static Parser<char, float[]> Thickness { get; }
= SkipWhitespaces.Then(
OneOf(
Try(Single4.Select(c => new[] {c.Item1, c.Item2, c.Item3, c.Item4})),
Try(Single2.Select(c => new[] {c.Item1, c.Item2})),
Try(Single1.Select(c => new[] {c}))
));
}
}

View File

@@ -55,9 +55,11 @@ namespace Robust.Build.Tasks
public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties,
IDictionary targetOutputs) => throw new NotSupportedException();
public bool ContinueOnError { get; }
public int LineNumberOfTaskNode { get; }
public int ColumnNumberOfTaskNode { get; }
public string ProjectFileOfTaskNode { get; }
// PYREX NOTE: This project was extremely null-unsafe before I touched it. I'm just marking what it did already
// Here's the broken interface of IBuildEngine that we started with
public bool ContinueOnError => default;
public int LineNumberOfTaskNode => default;
public int ColumnNumberOfTaskNode => default;
public string ProjectFileOfTaskNode => null!;
}
}

View File

@@ -1,17 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\MSBuild\Robust.Engine.props" />
<!--
PJB3005 (2024-08-24)
So the reason that Robust.Client.Injectors is NS2.0 is that Visual Studio
still ships a .NET FX based MSBuild for some godforsaken reason. This means
that when having Robust.Client.Injectors loaded directly by the main MSBuild
process... that would break.
Except we don't do that anyways right now due to file locking issues, so maybe
it's fine to give up on that. Whatever.
-->
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="17.8.3" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
<PackageReference Include="Pidgin" Version="2.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XamlX\src\XamlX.IL.Cecil\XamlX.IL.Cecil.csproj" />
<ProjectReference Include="..\Robust.Xaml\Robust.Xaml.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,389 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using Pidgin;
using XamlX;
using XamlX.Ast;
using XamlX.Emit;
using XamlX.IL;
using XamlX.Parsers;
using XamlX.Transform;
using XamlX.TypeSystem;
namespace Robust.Build.Tasks
{
/// <summary>
/// Based on https://github.com/AvaloniaUI/Avalonia/blob/c85fa2b9977d251a31886c2534613b4730fbaeaf/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs
/// Adjusted for our UI-Framework
/// </summary>
public partial class XamlCompiler
{
public static (bool success, bool writtentofile) Compile(IBuildEngine engine, string input, string[] references,
string projectDirectory, string output, string strongNameKey)
{
var typeSystem = new CecilTypeSystem(references
.Where(r => !r.ToLowerInvariant().EndsWith("robust.build.tasks.dll"))
.Concat(new[] { input }), input);
var asm = typeSystem.TargetAssemblyDefinition;
if (asm.MainModule.GetType("CompiledRobustXaml", "XamlIlContext") != null)
{
// If this type exists, the assembly has already been processed by us.
// Do not run again, it would corrupt the file.
// This *shouldn't* be possible due to Inputs/Outputs dependencies in the build system,
// but better safe than sorry eh?
engine.LogWarningEvent(new BuildWarningEventArgs("XAMLIL", "", "", 0, 0, 0, 0, "Ran twice on same assembly file; ignoring.", "", ""));
return (true, false);
}
var compileRes = CompileCore(engine, typeSystem);
if (compileRes == null)
return (true, false);
if (compileRes == false)
return (false, false);
var writerParameters = new WriterParameters { WriteSymbols = asm.MainModule.HasSymbols };
if (!string.IsNullOrWhiteSpace(strongNameKey))
writerParameters.StrongNameKeyBlob = File.ReadAllBytes(strongNameKey);
asm.Write(output, writerParameters);
return (true, true);
}
static bool? CompileCore(IBuildEngine engine, CecilTypeSystem typeSystem)
{
var asm = typeSystem.TargetAssemblyDefinition;
var embrsc = new EmbeddedResources(asm);
if (embrsc.Resources.Count(CheckXamlName) == 0)
// Nothing to do
return null;
var xamlLanguage = new XamlLanguageTypeMappings(typeSystem)
{
XmlnsAttributes =
{
typeSystem.GetType("Avalonia.Metadata.XmlnsDefinitionAttribute"),
},
ContentAttributes =
{
typeSystem.GetType("Avalonia.Metadata.ContentAttribute")
},
UsableDuringInitializationAttributes =
{
typeSystem.GetType("Robust.Client.UserInterface.XAML.UsableDuringInitializationAttribute")
},
DeferredContentPropertyAttributes =
{
typeSystem.GetType("Robust.Client.UserInterface.XAML.DeferredContentAttribute")
},
RootObjectProvider = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestRootObjectProvider"),
UriContextProvider = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestUriContext"),
ProvideValueTarget = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestProvideValueTarget"),
};
var emitConfig = new XamlLanguageEmitMappings<IXamlILEmitter, XamlILNodeEmitResult>
{
ContextTypeBuilderCallback = (b,c) => EmitNameScopeField(xamlLanguage, typeSystem, b, c)
};
var transformerconfig = new TransformerConfiguration(
typeSystem,
typeSystem.TargetAssembly,
xamlLanguage,
XamlXmlnsMappings.Resolve(typeSystem, xamlLanguage), CustomValueConverter);
var contextDef = new TypeDefinition("CompiledRobustXaml", "XamlIlContext",
TypeAttributes.Class, asm.MainModule.TypeSystem.Object);
asm.MainModule.Types.Add(contextDef);
var contextClass = XamlILContextDefinition.GenerateContextClass(typeSystem.CreateTypeBuilder(contextDef), typeSystem,
xamlLanguage, emitConfig);
var compiler =
new RobustXamlILCompiler(transformerconfig, emitConfig, true);
bool CompileGroup(IResourceGroup group)
{
var typeDef = new TypeDefinition("CompiledRobustXaml", "!" + group.Name, TypeAttributes.Class,
asm.MainModule.TypeSystem.Object);
//typeDef.CustomAttributes.Add(new CustomAttribute(ed));
asm.MainModule.Types.Add(typeDef);
var builder = typeSystem.CreateTypeBuilder(typeDef);
foreach (var res in group.Resources.Where(CheckXamlName))
{
try
{
engine.LogMessage($"XAMLIL: {res.Name} -> {res.Uri}", MessageImportance.Low);
var xaml = new StreamReader(new MemoryStream(res.FileContents)).ReadToEnd();
var parsed = XDocumentXamlParser.Parse(xaml);
var initialRoot = (XamlAstObjectNode) parsed.Root;
var classDirective = initialRoot.Children.OfType<XamlAstXmlDirective>()
.FirstOrDefault(d => d.Namespace == XamlNamespaces.Xaml2006 && d.Name == "Class");
string classname;
if (classDirective != null && classDirective.Values[0] is XamlAstTextNode tn)
{
classname = tn.Text;
}
else
{
classname = res.Name.Replace(".xaml","");
}
var classType = typeSystem.TargetAssembly.FindType(classname);
if (classType == null)
throw new Exception($"Unable to find type '{classname}'");
compiler.Transform(parsed);
var populateName = $"Populate:{res.Name}";
var buildName = $"Build:{res.Name}";
var classTypeDefinition = typeSystem.GetTypeReference(classType).Resolve();
var populateBuilder = typeSystem.CreateTypeBuilder(classTypeDefinition);
compiler.Compile(parsed, contextClass,
compiler.DefinePopulateMethod(populateBuilder, parsed, populateName,
classTypeDefinition == null),
compiler.DefineBuildMethod(builder, parsed, buildName, true),
null,
(closureName, closureBaseType) =>
populateBuilder.DefineSubType(closureBaseType, closureName, false),
res.Uri, res
);
//add compiled populate method
var compiledPopulateMethod = typeSystem.GetTypeReference(populateBuilder).Resolve().Methods
.First(m => m.Name == populateName);
const string TrampolineName = "!XamlIlPopulateTrampoline";
var trampoline = new MethodDefinition(TrampolineName,
MethodAttributes.Static | MethodAttributes.Private, asm.MainModule.TypeSystem.Void);
trampoline.Parameters.Add(new ParameterDefinition(classTypeDefinition));
classTypeDefinition.Methods.Add(trampoline);
trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ldnull));
trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Call, compiledPopulateMethod));
trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
var foundXamlLoader = false;
// Find RobustXamlLoader.Load(this) and replace it with !XamlIlPopulateTrampoline(this)
foreach (var method in classTypeDefinition.Methods
.Where(m => !m.Attributes.HasFlag(MethodAttributes.Static)))
{
var i = method.Body.Instructions;
for (var c = 1; c < i.Count; c++)
{
if (i[c].OpCode == OpCodes.Call)
{
var op = i[c].Operand as MethodReference;
if (op != null
&& op.Name == TrampolineName)
{
foundXamlLoader = true;
break;
}
if (op != null
&& op.Name == "Load"
&& op.Parameters.Count == 1
&& op.Parameters[0].ParameterType.FullName == "System.Object"
&& op.DeclaringType.FullName == "Robust.Client.UserInterface.XAML.RobustXamlLoader")
{
if (MatchThisCall(i, c - 1))
{
i[c].Operand = trampoline;
foundXamlLoader = true;
}
}
}
}
}
if (!foundXamlLoader)
{
var ctors = classTypeDefinition.GetConstructors()
.Where(c => !c.IsStatic).ToList();
// We can inject xaml loader into default constructor
if (ctors.Count == 1 && ctors[0].Body.Instructions.Count(o=>o.OpCode != OpCodes.Nop) == 3)
{
var i = ctors[0].Body.Instructions;
var retIdx = i.IndexOf(i.Last(x => x.OpCode == OpCodes.Ret));
i.Insert(retIdx, Instruction.Create(OpCodes.Call, trampoline));
i.Insert(retIdx, Instruction.Create(OpCodes.Ldarg_0));
}
else
{
throw new InvalidProgramException(
$"No call to RobustXamlLoader.Load(this) call found anywhere in the type {classType.FullName} and type seems to have custom constructors.");
}
}
}
catch (Exception e)
{
engine.LogErrorEvent(new BuildErrorEventArgs("XAMLIL", "", res.FilePath, 0, 0, 0, 0,
$"{res.FilePath}: {e.Message}", "", "CompileRobustXaml"));
}
res.Remove();
}
return true;
}
if (embrsc.Resources.Count(CheckXamlName) != 0)
{
if (!CompileGroup(embrsc))
return false;
}
return true;
}
private static bool CustomValueConverter(
AstTransformationContext context,
IXamlAstValueNode node,
IXamlType type,
out IXamlAstValueNode result)
{
if (!(node is XamlAstTextNode textNode))
{
result = null;
return false;
}
var text = textNode.Text;
var types = context.GetRobustTypes();
if (type.Equals(types.Vector2))
{
var foo = MathParsing.Single2.Parse(text);
if (!foo.Success)
throw new XamlLoadException($"Unable to parse \"{text}\" as a Vector2", node);
var (x, y) = foo.Value;
result = new RXamlSingleVecLikeConstAstNode(
node,
types.Vector2, types.Vector2ConstructorFull,
types.Single, new[] {x, y});
return true;
}
if (type.Equals(types.Thickness))
{
var foo = MathParsing.Thickness.Parse(text);
if (!foo.Success)
throw new XamlLoadException($"Unable to parse \"{text}\" as a Thickness", node);
var val = foo.Value;
float[] full;
if (val.Length == 1)
{
var u = val[0];
full = new[] {u, u, u, u};
}
else if (val.Length == 2)
{
var h = val[0];
var v = val[1];
full = new[] {h, v, h, v};
}
else // 4
{
full = val;
}
result = new RXamlSingleVecLikeConstAstNode(
node,
types.Thickness, types.ThicknessConstructorFull,
types.Single, full);
return true;
}
if (type.Equals(types.Thickness))
{
var foo = MathParsing.Thickness.Parse(text);
if (!foo.Success)
throw new XamlLoadException($"Unable to parse \"{text}\" as a Thickness", node);
var val = foo.Value;
float[] full;
if (val.Length == 1)
{
var u = val[0];
full = new[] {u, u, u, u};
}
else if (val.Length == 2)
{
var h = val[0];
var v = val[1];
full = new[] {h, v, h, v};
}
else // 4
{
full = val;
}
result = new RXamlSingleVecLikeConstAstNode(
node,
types.Thickness, types.ThicknessConstructorFull,
types.Single, full);
return true;
}
if (type.Equals(types.Color))
{
// TODO: Interpret these colors at XAML compile time instead of at runtime.
result = new RXamlColorAstNode(node, types, text);
return true;
}
result = null;
return false;
}
public const string ContextNameScopeFieldName = "RobustNameScope";
private static void EmitNameScopeField(XamlLanguageTypeMappings xamlLanguage, CecilTypeSystem typeSystem, IXamlTypeBuilder<IXamlILEmitter> typeBuilder, IXamlILEmitter constructor)
{
var nameScopeType = typeSystem.FindType("Robust.Client.UserInterface.XAML.NameScope");
var field = typeBuilder.DefineField(nameScopeType,
ContextNameScopeFieldName, true, false);
constructor
.Ldarg_0()
.Newobj(nameScopeType.GetConstructor())
.Stfld(field);
}
}
interface IResource : IFileSource
{
string Uri { get; }
string Name { get; }
void Remove();
}
interface IResourceGroup
{
string Name { get; }
IEnumerable<IResource> Resources { get; }
}
}

View File

@@ -302,7 +302,7 @@ internal partial class AudioManager
}
/// <inheritdoc/>
IBufferedAudioSource? IAudioInternal.CreateBufferedAudioSource(int buffers, bool floatAudio=false)
IBufferedAudioSource? IAudioInternal.CreateBufferedAudioSource(int buffers, bool floatAudio)
{
var source = AL.GenSource();

View File

@@ -143,12 +143,11 @@ internal sealed partial class AudioManager : IAudioInternal
/// <summary>
/// Like _checkAlError but allows custom data to be passed in as relevant.
/// </summary>
internal void LogALError(string message, [CallerMemberName] string callerMember = "", [CallerLineNumber] int callerLineNumber = -1)
internal void LogALError(ALErrorInterpolatedStringHandler message, [CallerMemberName] string callerMember = "", [CallerLineNumber] int callerLineNumber = -1)
{
var error = AL.GetError();
if (error != ALError.NoError)
if (message.Error != ALError.NoError)
{
OpenALSawmill.Error("[{0}:{1}] AL error: {2}, {3}. Stacktrace is {4}", callerMember, callerLineNumber, error, message, Environment.StackTrace);
OpenALSawmill.Error("[{0}:{1}] AL error: {2}, {3}. Stacktrace is {4}", callerMember, callerLineNumber, message.Error, message.ToStringAndClear(), Environment.StackTrace);
}
}
@@ -170,4 +169,32 @@ internal sealed partial class AudioManager : IAudioInternal
BufferHandle = bufferHandle;
}
}
[InterpolatedStringHandler]
internal ref struct ALErrorInterpolatedStringHandler
{
private DefaultInterpolatedStringHandler _handler;
public ALError Error;
public ALErrorInterpolatedStringHandler(int literalLength, int formattedCount, out bool shouldAppend)
{
Error = AL.GetError();
if (Error == ALError.NoError)
{
shouldAppend = false;
_handler = default;
}
else
{
shouldAppend = true;
_handler = new DefaultInterpolatedStringHandler(literalLength, formattedCount);
}
}
public string ToStringAndClear() => _handler.ToStringAndClear();
public override string ToString() => _handler.ToString();
public void AppendLiteral(string value) => _handler.AppendLiteral(value);
public void AppendFormatted<T>(T value) => _handler.AppendFormatted(value);
public void AppendFormatted<T>(T value, string? format) => _handler.AppendFormatted(value, format);
}
}

View File

@@ -46,7 +46,7 @@ public sealed class AudioOverlay : Overlay
var screenHandle = args.ScreenHandle;
var output = new StringBuilder();
var listenerPos = _entManager.GetComponent<TransformComponent>(localPlayer.Value).MapPosition;
var listenerPos = _transform.GetMapCoordinates(_entManager.GetComponent<TransformComponent>(localPlayer.Value));
if (listenerPos.MapId != args.MapId)
return;

View File

@@ -37,7 +37,6 @@ public sealed partial class AudioSystem : SharedAudioSystem
[Dependency] private readonly IReplayRecordingManager _replayRecording = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IParallelManager _parMan = default!;
[Dependency] private readonly IRuntimeLog _runtimeLog = default!;
[Dependency] private readonly IAudioInternal _audio = default!;
@@ -49,9 +48,10 @@ public sealed partial class AudioSystem : SharedAudioSystem
/// Per-tick cache of relevant streams.
/// </summary>
private readonly List<(EntityUid Entity, AudioComponent Component, TransformComponent Xform)> _streams = new();
private EntityUid? _listenerGrid;
private UpdateAudioJob _updateAudioJob;
private float _audioFrameTime;
private float _audioFrameTimeRemaining;
private EntityQuery<PhysicsComponent> _physicsQuery;
@@ -110,9 +110,16 @@ public sealed partial class AudioSystem : SharedAudioSystem
Subs.CVar(CfgManager, CVars.AudioAttenuation, OnAudioAttenuation, true);
Subs.CVar(CfgManager, CVars.AudioRaycastLength, OnRaycastLengthChanged, true);
Subs.CVar(CfgManager, CVars.AudioTickRate, OnAudioTickRate, true);
InitializeLimit();
}
private void OnAudioTickRate(int obj)
{
_audioFrameTime = 1f / obj;
_audioFrameTimeRemaining = MathF.Min(_audioFrameTimeRemaining, _audioFrameTime);
}
private void OnAudioState(EntityUid uid, AudioComponent component, ref AfterAutoHandleStateEvent args)
{
ApplyAudioParams(component.Params, component);
@@ -254,6 +261,13 @@ public sealed partial class AudioSystem : SharedAudioSystem
public override void FrameUpdate(float frameTime)
{
_audioFrameTimeRemaining -= frameTime;
if (_audioFrameTimeRemaining > 0f)
return;
// Clamp to 0 in case we have a really long frame.
_audioFrameTimeRemaining = MathF.Max(0f, _audioFrameTime + _audioFrameTimeRemaining);
var eye = _eyeManager.CurrentEye;
var localEntity = _playerManager.LocalEntity;
Vector2 listenerVelocity;
@@ -277,9 +291,6 @@ public sealed partial class AudioSystem : SharedAudioSystem
_streams.Add((uid, comp, xform));
}
_mapManager.TryFindGridAt(ourPos, out var gridUid, out _);
_listenerGrid = gridUid == EntityUid.Invalid ? null : gridUid;
try
{
_updateAudioJob.OurPosition = ourPos;
@@ -332,7 +343,6 @@ public sealed partial class AudioSystem : SharedAudioSystem
Vector2 worldPos;
component.Volume = component.Params.Volume;
Vector2 delta;
// Handle grid audio differently by using grid position.
if ((component.Flags & AudioFlags.GridAudio) != 0x0)
@@ -346,7 +356,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
}
// Max distance check
delta = worldPos - listener.Position;
var delta = worldPos - listener.Position;
var distance = delta.Length();
// Out of range so just clip it for us.

View File

@@ -1,24 +1,18 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using OpenTK.Audio.OpenAL;
using OpenTK.Audio.OpenAL.Extensions.Creative.EFX;
using Robust.Client.Graphics;
using Robust.Shared.Audio.Sources;
using Robust.Shared.Maths;
namespace Robust.Client.Audio.Sources;
internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSource
{
private int? SourceHandle = null;
private int[] BufferHandles;
private Dictionary<int, int> BufferMap = new();
private readonly AudioManager _master;
private bool _mono = true;
private bool _float = false;
private int FilterHandle;
public int SampleRate { get; set; } = 44100;
@@ -43,7 +37,7 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
get
{
_checkDisposed();
var state = AL.GetSourceState(SourceHandle!.Value);
var state = AL.GetSourceState(SourceHandle);
_master._checkAlError();
return state == ALSourceState.Playing;
}
@@ -53,7 +47,7 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
{
_checkDisposed();
// IDK why this stackallocs but gonna leave it for now.
AL.SourcePlay(stackalloc int[] {SourceHandle!.Value});
AL.SourcePlay(stackalloc int[] {SourceHandle});
_master._checkAlError();
}
else
@@ -61,7 +55,7 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
if (_isDisposed())
return;
AL.SourceStop(SourceHandle!.Value);
AL.SourceStop(SourceHandle);
_master._checkAlError();
}
}
@@ -74,13 +68,13 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
protected override void Dispose(bool disposing)
{
if (SourceHandle == null)
if (SourceHandle == -1)
return;
if (!_master.IsMainThread())
{
// We can't run this code inside another thread so tell Clyde to clear it up later.
_master.DeleteBufferedSourceOnMainThread(SourceHandle.Value, FilterHandle);
_master.DeleteBufferedSourceOnMainThread(SourceHandle, FilterHandle);
foreach (var handle in BufferHandles)
{
@@ -92,21 +86,21 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
if (FilterHandle != 0)
EFX.DeleteFilter(FilterHandle);
AL.DeleteSource(SourceHandle.Value);
AL.DeleteSource(SourceHandle);
AL.DeleteBuffers(BufferHandles);
_master.RemoveBufferedAudioSource(SourceHandle.Value);
_master.RemoveBufferedAudioSource(SourceHandle);
_master._checkAlError();
}
FilterHandle = 0;
SourceHandle = null;
SourceHandle = -1;
}
public int GetNumberOfBuffersProcessed()
{
_checkDisposed();
// ReSharper disable once PossibleInvalidOperationException
AL.GetSource(SourceHandle!.Value, ALGetSourcei.BuffersProcessed, out var buffersProcessed);
AL.GetSource(SourceHandle, ALGetSourcei.BuffersProcessed, out var buffersProcessed);
return buffersProcessed;
}
@@ -116,7 +110,7 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
var entries = Math.Min(Math.Min(handles.Length, BufferHandles.Length), GetNumberOfBuffersProcessed());
fixed (int* ptr = handles)
{
AL.SourceUnqueueBuffers(SourceHandle!.Value, entries, ptr);
AL.SourceUnqueueBuffers(SourceHandle, entries, ptr);
}
for (var i = 0; i < entries; i++)
@@ -183,7 +177,7 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
fixed (int* ptr = realHandles)
// ReSharper disable once PossibleInvalidOperationException
{
AL.SourceQueueBuffers(SourceHandle!.Value, handles.Length, ptr);
AL.SourceQueueBuffers(SourceHandle, handles.Length, ptr);
}
}

View File

@@ -26,6 +26,7 @@ using Robust.Client.Upload;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.RichText;
using Robust.Client.UserInterface.Themes;
using Robust.Client.UserInterface.XAML.Proxy;
using Robust.Client.Utility;
using Robust.Client.ViewVariables;
using Robust.Shared;
@@ -146,6 +147,16 @@ namespace Robust.Client
deps.Register<IConfigurationManagerInternal, ClientNetConfigurationManager>();
deps.Register<IClientNetConfigurationManager, ClientNetConfigurationManager>();
deps.Register<INetConfigurationManagerInternal, ClientNetConfigurationManager>();
#if TOOLS
deps.Register<IXamlProxyManager, XamlProxyManager>();
deps.Register<IXamlHotReloadManager, XamlHotReloadManager>();
#else
deps.Register<IXamlProxyManager, XamlProxyManagerStub>();
deps.Register<IXamlHotReloadManager, XamlHotReloadManagerStub>();
#endif
deps.Register<IXamlProxyHelper, XamlProxyHelper>();
deps.Register<MarkupTagManager>();
}
}

View File

@@ -291,9 +291,9 @@ namespace Robust.Client.Console.Commands
}
}
internal sealed class SnapGridGetCell : LocalizedCommands
internal sealed class SnapGridGetCell : LocalizedEntityCommands
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
public override string Command => "sggcell";
@@ -319,9 +319,10 @@ namespace Robust.Client.Console.Commands
return;
}
if (_entManager.TryGetComponent<MapGridComponent>(_entManager.GetEntity(gridNet), out var grid))
var gridEnt = EntityManager.GetEntity(gridNet);
if (EntityManager.TryGetComponent<MapGridComponent>(gridEnt, out var grid))
{
foreach (var entity in grid.GetAnchoredEntities(new Vector2i(
foreach (var entity in _map.GetAnchoredEntities(gridEnt, grid, new Vector2i(
int.Parse(indices.Split(',')[0], CultureInfo.InvariantCulture),
int.Parse(indices.Split(',')[1], CultureInfo.InvariantCulture))))
{
@@ -425,9 +426,9 @@ namespace Robust.Client.Console.Commands
}
}
internal sealed class GridTileCount : LocalizedCommands
internal sealed class GridTileCount : LocalizedEntityCommands
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
public override string Command => "gridtc";
@@ -440,15 +441,15 @@ namespace Robust.Client.Console.Commands
}
if (!NetEntity.TryParse(args[0], out var gridUidNet) ||
!_entManager.TryGetEntity(gridUidNet, out var gridUid))
!EntityManager.TryGetEntity(gridUidNet, out var gridUid))
{
shell.WriteLine($"{args[0]} is not a valid entity UID.");
return;
}
if (_entManager.TryGetComponent<MapGridComponent>(gridUid, out var grid))
if (EntityManager.TryGetComponent<MapGridComponent>(gridUid, out var grid))
{
shell.WriteLine(grid.GetAllTiles().Count().ToString());
shell.WriteLine(_map.GetAllTiles(gridUid.Value, grid).Count().ToString());
}
else
{
@@ -578,7 +579,20 @@ namespace Robust.Client.Console.Commands
private static string GetMemberValue(MemberInfo? member, Control control, string separator, string
wrap = "{0}")
{
var value = member?.GetValue(control);
object? value = null;
try
{
value = member?.GetValue(control);
}
catch (TargetInvocationException exception)
{
var exceptionToPrint = exception.InnerException ?? exception;
value = $"{exceptionToPrint.GetType()}: {exceptionToPrint.Message}";
}
catch (Exception exception)
{
value = $"{exception.GetType()}: {exception.Message}";
}
var o = value switch
{
ICollection<Control> controls => string.Join(separator,
@@ -680,12 +694,12 @@ namespace Robust.Client.Console.Commands
}
}
internal sealed class ChunkInfoCommand : LocalizedCommands
internal sealed class ChunkInfoCommand : LocalizedEntityCommands
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly IInputManager _input = default!;
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
public override string Command => "chunkinfo";
@@ -699,8 +713,8 @@ namespace Robust.Client.Console.Commands
return;
}
var mapSystem = _entManager.System<SharedMapSystem>();
var chunkIndex = mapSystem.LocalToChunkIndices(gridUid, grid, grid.MapToGrid(mousePos));
var mapSystem = EntityManager.System<SharedMapSystem>();
var chunkIndex = mapSystem.LocalToChunkIndices(gridUid, grid, _mapSystem.MapToGrid(gridUid, mousePos));
var chunk = mapSystem.GetOrAddChunk(gridUid, grid, chunkIndex);
shell.WriteLine($"worldBounds: {mapSystem.CalcWorldAABB(gridUid, grid, chunk)} localBounds: {chunk.CachedBounds}");

View File

@@ -11,7 +11,7 @@ namespace Robust.Client.Console.Commands
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var type = Type.GetType(args[0]);
var type = GetType(args[0]);
if (type == null)
{
@@ -25,6 +25,17 @@ namespace Robust.Client.Console.Commands
shell.WriteLine(sig);
}
}
private Type? GetType(string name)
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (assembly.GetType(name) is { } type)
return type;
}
return null;
}
}
#endif
}

View File

@@ -1,16 +1,19 @@
using Robust.Client.GameObjects;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Robust.Client.Console.Commands
{
public sealed class GridChunkBBCommand : LocalizedCommands
public sealed class GridChunkBBCommand : LocalizedEntityCommands
{
[Dependency] private readonly GridChunkBoundsDebugSystem _system = default!;
public override string Command => "showchunkbb";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
EntitySystem.Get<GridChunkBoundsDebugSystem>().Enabled ^= true;
_system.Enabled ^= true;
}
}
}

View File

@@ -204,7 +204,7 @@ Suspendisse hendrerit blandit urna ut laoreet. Suspendisse ac elit at erat males
private Control TabRichText()
{
var label = new RichTextLabel();
label.SetMessage(FormattedMessage.FromMarkup(Lipsum));
label.SetMessage(FormattedMessage.FromMarkupOrThrow(Lipsum));
TabContainer.SetTabTitle(label, "RichText");
return label;

View File

@@ -1,4 +1,5 @@
using System.Numerics;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
@@ -14,6 +15,8 @@ namespace Robust.Client.Debugging
{
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly TransformSystem _transform = default!;
private bool _debugPositions;
private bool _debugRotations;
@@ -35,7 +38,7 @@ namespace Robust.Client.Debugging
if (value && !_overlayManager.HasOverlay<EntityPositionOverlay>())
{
_overlayManager.AddOverlay(new EntityPositionOverlay(_lookup, EntityManager));
_overlayManager.AddOverlay(new EntityPositionOverlay(_lookup, EntityManager, _transform));
}
else
{
@@ -74,13 +77,15 @@ namespace Robust.Client.Debugging
{
private readonly EntityLookupSystem _lookup;
private readonly IEntityManager _entityManager;
private readonly SharedTransformSystem _transform;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
public EntityPositionOverlay(EntityLookupSystem lookup, IEntityManager entityManager)
public EntityPositionOverlay(EntityLookupSystem lookup, IEntityManager entityManager, SharedTransformSystem transform)
{
_lookup = lookup;
_entityManager = entityManager;
_transform = transform;
}
protected internal override void Draw(in OverlayDrawArgs args)
@@ -88,11 +93,10 @@ namespace Robust.Client.Debugging
const float stubLength = 0.25f;
var worldHandle = (DrawingHandleWorld) args.DrawingHandle;
var xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
foreach (var entity in _lookup.GetEntitiesIntersecting(args.MapId, args.WorldBounds))
{
var (center, worldRotation) = xformQuery.GetComponent(entity).GetWorldPositionRotation();
var (center, worldRotation) = _transform.GetWorldPositionRotation(entity);
var xLine = worldRotation.RotateVec(Vector2.UnitX);
var yLine = worldRotation.RotateVec(Vector2.UnitY);

View File

@@ -47,6 +47,7 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
@@ -78,6 +79,14 @@ namespace Robust.Client.Debugging
internal int PointCount;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly IOverlayManager _overlay = default!;
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly IInputManager _input = default!;
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
internal ContactPoint[] Points = new ContactPoint[MaxContactPoints];
@@ -89,20 +98,21 @@ namespace Robust.Client.Debugging
if (value == _flags) return;
if (_flags == PhysicsDebugFlags.None)
IoCManager.Resolve<IOverlayManager>().AddOverlay(
_overlay.AddOverlay(
new PhysicsDebugOverlay(
EntityManager,
IoCManager.Resolve<IEyeManager>(),
IoCManager.Resolve<IInputManager>(),
IoCManager.Resolve<IMapManager>(),
IoCManager.Resolve<IPlayerManager>(),
IoCManager.Resolve<IResourceCache>(),
_eye,
_input,
_map,
_player,
_resourceCache,
this,
Get<EntityLookupSystem>(),
Get<SharedPhysicsSystem>()));
_entityLookup,
_physics,
_transform));
if (value == PhysicsDebugFlags.None)
IoCManager.Resolve<IOverlayManager>().RemoveOverlay(typeof(PhysicsDebugOverlay));
_overlay.RemoveOverlay(typeof(PhysicsDebugOverlay));
_flags = value;
}
@@ -198,6 +208,7 @@ namespace Robust.Client.Debugging
private readonly DebugPhysicsSystem _debugPhysicsSystem;
private readonly EntityLookupSystem _lookup;
private readonly SharedPhysicsSystem _physicsSystem;
private readonly SharedTransformSystem _transformSystem;
public override OverlaySpace Space => OverlaySpace.WorldSpace | OverlaySpace.ScreenSpace;
@@ -208,7 +219,7 @@ namespace Robust.Client.Debugging
private HashSet<Joint> _drawnJoints = new();
private List<Entity<MapGridComponent>> _grids = new();
public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IMapManager mapManager, IPlayerManager playerManager, IResourceCache cache, DebugPhysicsSystem system, EntityLookupSystem lookup, SharedPhysicsSystem physicsSystem)
public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IMapManager mapManager, IPlayerManager playerManager, IResourceCache cache, DebugPhysicsSystem system, EntityLookupSystem lookup, SharedPhysicsSystem physicsSystem, SharedTransformSystem transformSystem)
{
_entityManager = entityManager;
_eyeManager = eyeManager;
@@ -218,6 +229,7 @@ namespace Robust.Client.Debugging
_debugPhysicsSystem = system;
_lookup = lookup;
_physicsSystem = physicsSystem;
_transformSystem = transformSystem;
_font = new VectorFont(cache.GetResource<FontResource>("/EngineFonts/NotoSans/NotoSans-Regular.ttf"), 10);
}
@@ -327,7 +339,7 @@ namespace Robust.Client.Debugging
{
if (jointComponent.JointCount == 0 ||
!_entityManager.TryGetComponent(uid, out TransformComponent? xf1) ||
!viewAABB.Contains(xf1.WorldPosition)) continue;
!viewAABB.Contains(_transformSystem.GetWorldPosition(xf1))) continue;
foreach (var (_, joint) in jointComponent.Joints)
{
@@ -517,8 +529,8 @@ namespace Robust.Client.Debugging
if (!_entityManager.TryGetComponent(joint.BodyAUid, out TransformComponent? xform1) ||
!_entityManager.TryGetComponent(joint.BodyBUid, out TransformComponent? xform2)) return;
var matrix1 = xform1.WorldMatrix;
var matrix2 = xform2.WorldMatrix;
var matrix1 = _transformSystem.GetWorldMatrix(xform1);
var matrix2 = _transformSystem.GetWorldMatrix(xform2);
var xf1 = new Vector2(matrix1.M31, matrix1.M32);
var xf2 = new Vector2(matrix2.M31, matrix2.M32);
@@ -526,8 +538,8 @@ namespace Robust.Client.Debugging
var p1 = Vector2.Transform(joint.LocalAnchorA, matrix1);
var p2 = Vector2.Transform(joint.LocalAnchorB, matrix2);
var xfa = new Transform(xf1, xform1.WorldRotation);
var xfb = new Transform(xf2, xform2.WorldRotation);
var xfa = new Transform(xf1, _transformSystem.GetWorldRotation(xform1));
var xfb = new Transform(xf2, _transformSystem.GetWorldRotation(xform2));
switch (joint)
{

View File

@@ -19,6 +19,7 @@ using Robust.Client.State;
using Robust.Client.Upload;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.RichText;
using Robust.Client.UserInterface.XAML.Proxy;
using Robust.Client.Utility;
using Robust.Client.ViewVariables;
using Robust.Client.WebViewHook;
@@ -53,6 +54,8 @@ namespace Robust.Client
[Dependency] private readonly IResourceCacheInternal _resourceCache = default!;
[Dependency] private readonly IResourceManagerInternal _resManager = default!;
[Dependency] private readonly IRobustSerializer _serializer = default!;
[Dependency] private readonly IXamlProxyManager _xamlProxyManager = default!;
[Dependency] private readonly IXamlHotReloadManager _xamlHotReloadManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IClientNetManager _networkManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
@@ -171,6 +174,8 @@ namespace Robust.Client
_reflectionManager.Initialize();
_prototypeManager.Initialize();
_prototypeManager.LoadDefaultPrototypes();
_xamlProxyManager.Initialize();
_xamlHotReloadManager.Initialize();
_userInterfaceManager.Initialize();
_eyeManager.Initialize();
_entityManager.Initialize();

View File

@@ -26,6 +26,9 @@ namespace Robust.Client.GameObjects
[Dependency] private readonly IBaseClient _client = default!;
[Dependency] private readonly IReplayRecordingManager _replayRecording = default!;
internal event Action? AfterStartup;
internal event Action? AfterShutdown;
public override void Initialize()
{
SetupNetworking();
@@ -34,6 +37,20 @@ namespace Robust.Client.GameObjects
base.Initialize();
}
public override void Startup()
{
base.Startup();
AfterStartup?.Invoke();
}
public override void Shutdown()
{
base.Shutdown();
AfterShutdown?.Invoke();
}
public override void FlushEntities()
{
// Server doesn't network deletions on client shutdown so we need to
@@ -48,16 +65,6 @@ namespace Robust.Client.GameObjects
return base.CreateEntity(prototypeName, out metadata);
}
void IClientEntityManagerInternal.InitializeEntity(EntityUid entity, MetaDataComponent? meta)
{
base.InitializeEntity(entity, meta);
}
void IClientEntityManagerInternal.StartEntity(EntityUid entity)
{
base.StartEntity(entity);
}
/// <inheritdoc />
public override void DirtyEntity(EntityUid uid, MetaDataComponent? meta = null)
{
@@ -128,7 +135,10 @@ namespace Robust.Client.GameObjects
var sequence = _stateMan.SystemMessageDispatched(msg);
EntityNetManager?.SendSystemNetworkMessage(msg, sequence);
DebugTools.Assert(!_stateMan.IsPredictionEnabled || _gameTiming.InPrediction && _gameTiming.IsFirstTimePredicted || _client.RunLevel != ClientRunLevel.Connected);
if (!_stateMan.IsPredictionEnabled && _client.RunLevel != ClientRunLevel.SinglePlayerGame)
return;
DebugTools.Assert(_gameTiming.InPrediction && _gameTiming.IsFirstTimePredicted || _client.RunLevel == ClientRunLevel.SinglePlayerGame);
var eventArgs = new EntitySessionEventArgs(session!);
EventBus.RaiseEvent(EventSource.Local, msg);

View File

@@ -2,8 +2,11 @@ using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;
using Robust.Shared.Serialization.Manager;
namespace Robust.Client.GameObjects
{
@@ -11,6 +14,7 @@ namespace Robust.Client.GameObjects
public sealed class AppearanceSystem : SharedAppearanceSystem
{
private readonly Queue<(EntityUid uid, AppearanceComponent)> _queuedUpdates = new();
[Dependency] private readonly ISerializationManager _serialization = default!;
public override void Initialize()
{
@@ -74,10 +78,13 @@ namespace Robust.Client.GameObjects
foreach (var (key, value) in data)
{
object? serializationObject;
if (value.GetType().IsValueType)
newDict[key] = value;
else if (value is ICloneable cloneable)
newDict[key] = cloneable.Clone();
else if ((serializationObject = _serialization.CreateCopy(value)) != null)
newDict[key] = serializationObject;
else
throw new NotSupportedException("Invalid object in appearance data dictionary. Appearance data must be cloneable");
}

View File

@@ -6,6 +6,7 @@ using Robust.Shared.Maths;
using Robust.Shared.Utility;
using System;
using System.Collections.Generic;
using Robust.Shared.IoC;
using static Robust.Shared.GameObjects.OccluderComponent;
namespace Robust.Client.GameObjects;
@@ -20,6 +21,7 @@ namespace Robust.Client.GameObjects;
internal sealed class ClientOccluderSystem : OccluderSystem
{
private readonly HashSet<EntityUid> _dirtyEntities = new();
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
/// <inheritdoc />
public override void Initialize()
@@ -102,7 +104,8 @@ internal sealed class ClientOccluderSystem : OccluderSystem
if (occluder.Enabled && xform.Anchored && TryComp(xform.GridUid, out grid))
{
pos = grid.TileIndicesFor(xform.Coordinates);
gridId = xform.GridUid.Value;
pos = _mapSystem.TileIndicesFor(gridId, grid, xform.Coordinates);
_dirtyEntities.Add(sender);
}
else if (occluder.LastPosition != null)
@@ -117,10 +120,10 @@ internal sealed class ClientOccluderSystem : OccluderSystem
return;
}
DirtyNeighbours(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(0, 1)), query);
DirtyNeighbours(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(0, -1)), query);
DirtyNeighbours(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(1, 0)), query);
DirtyNeighbours(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(-1, 0)), query);
DirtyNeighbours(_mapSystem.GetAnchoredEntitiesEnumerator(gridId, grid, pos + new Vector2i(0, 1)), query);
DirtyNeighbours(_mapSystem.GetAnchoredEntitiesEnumerator(gridId, grid, pos + new Vector2i(0, -1)), query);
DirtyNeighbours(_mapSystem.GetAnchoredEntitiesEnumerator(gridId, grid, pos + new Vector2i(1, 0)), query);
DirtyNeighbours(_mapSystem.GetAnchoredEntitiesEnumerator(gridId, grid, pos + new Vector2i(-1, 0)), query);
}
private void DirtyNeighbours(AnchoredEntitiesEnumerator enumerator, EntityQuery<OccluderComponent> occluderQuery)
@@ -166,7 +169,7 @@ internal sealed class ClientOccluderSystem : OccluderSystem
return;
}
var tile = grid.TileIndicesFor(xform.Coordinates);
var tile = _mapSystem.TileIndicesFor(xform.GridUid.Value, grid, xform.Coordinates);
// TODO: Sub to parent changes instead or something.
// DebugTools.Assert(occluder.LastPosition == null
@@ -175,16 +178,16 @@ internal sealed class ClientOccluderSystem : OccluderSystem
// dir starts at the relative effective south direction;
var dir = xform.LocalRotation.GetCardinalDir();
CheckDir(dir, OccluderDir.South, tile, occluder, grid, occluders, xforms);
CheckDir(dir, OccluderDir.South, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
dir = dir.GetClockwise90Degrees();
CheckDir(dir, OccluderDir.West, tile, occluder, grid, occluders, xforms);
CheckDir(dir, OccluderDir.West, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
dir = dir.GetClockwise90Degrees();
CheckDir(dir, OccluderDir.North, tile, occluder, grid, occluders, xforms);
CheckDir(dir, OccluderDir.North, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
dir = dir.GetClockwise90Degrees();
CheckDir(dir, OccluderDir.East, tile, occluder, grid, occluders, xforms);
CheckDir(dir, OccluderDir.East, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
}
private void CheckDir(
@@ -192,6 +195,7 @@ internal sealed class ClientOccluderSystem : OccluderSystem
OccluderDir occDir,
Vector2i tile,
OccluderComponent occluder,
EntityUid gridUid,
MapGridComponent grid,
EntityQuery<OccluderComponent> query,
EntityQuery<TransformComponent> xforms)
@@ -199,7 +203,7 @@ internal sealed class ClientOccluderSystem : OccluderSystem
if ((occluder.Occluding & occDir) != 0)
return;
foreach (var neighbor in grid.GetAnchoredEntities(tile.Offset(dir)))
foreach (var neighbor in _mapSystem.GetAnchoredEntities(gridUid, grid, tile.Offset(dir)))
{
if (!query.TryGetComponent(neighbor, out var otherOccluder) || !otherOccluder.Enabled)
continue;

View File

@@ -18,6 +18,8 @@ namespace Robust.Client.GameObjects
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
private GridChunkBoundsOverlay? _overlay;
@@ -36,7 +38,9 @@ namespace Robust.Client.GameObjects
_overlay = new GridChunkBoundsOverlay(
EntityManager,
_eyeManager,
_mapManager);
_mapManager,
_transform,
_map);
_overlayManager.AddOverlay(_overlay);
}
@@ -56,16 +60,20 @@ namespace Robust.Client.GameObjects
private readonly IEntityManager _entityManager;
private readonly IEyeManager _eyeManager;
private readonly IMapManager _mapManager;
private readonly SharedTransformSystem _transformSystem;
private readonly SharedMapSystem _mapSystem;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private List<Entity<MapGridComponent>> _grids = new();
public GridChunkBoundsOverlay(IEntityManager entManager, IEyeManager eyeManager, IMapManager mapManager)
public GridChunkBoundsOverlay(IEntityManager entManager, IEyeManager eyeManager, IMapManager mapManager, SharedTransformSystem transformSystem, SharedMapSystem mapSystem)
{
_entityManager = entManager;
_eyeManager = eyeManager;
_mapManager = mapManager;
_transformSystem = transformSystem;
_mapSystem = mapSystem;
}
protected internal override void Draw(in OverlayDrawArgs args)
@@ -74,20 +82,23 @@ namespace Robust.Client.GameObjects
var viewport = args.WorldBounds;
var worldHandle = args.WorldHandle;
var fixturesQuery = _entityManager.GetEntityQuery<FixturesComponent>();
_grids.Clear();
_mapManager.FindGridsIntersecting(currentMap, viewport, ref _grids);
foreach (var grid in _grids)
{
var worldMatrix = _entityManager.GetComponent<TransformComponent>(grid).WorldMatrix;
var worldMatrix = _transformSystem.GetWorldMatrix(grid);
worldHandle.SetTransform(worldMatrix);
var transform = new Transform(Vector2.Zero, Angle.Zero);
var fixtures = fixturesQuery.Comp(grid.Owner);
var chunkEnumerator = grid.Comp.GetMapChunks(viewport);
var chunkEnumerator = _mapSystem.GetMapChunks(grid.Owner, grid.Comp, viewport);
while (chunkEnumerator.MoveNext(out var chunk))
{
foreach (var fixture in chunk.Fixtures.Values)
foreach (var id in chunk.Fixtures)
{
var fixture = fixtures.Fixtures[id];
var poly = (PolygonShape) fixture.Shape;
var verts = new Vector2[poly.VertexCount];

View File

@@ -196,7 +196,7 @@ namespace Robust.Client.GameObjects
wOffset = new Vector2(wX, wY);
}
var coords = EntityCoordinates.FromMap(pent, _transform.GetMapCoordinates(pent).Offset(wOffset), _transform, EntityManager);
var coords = _transform.ToCoordinates(pent, _transform.GetMapCoordinates(pent).Offset(wOffset));
var funcId = _inputManager.NetworkBindMap.KeyFunctionID(keyFunction);
var message = new ClientFullInputCmdMessage(_timing.CurTick,

View File

@@ -0,0 +1,43 @@
using System.Numerics;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
namespace Robust.Client.GameObjects;
public sealed partial class SpriteSystem
{
/// <summary>
/// Gets an entity's sprite position in world terms.
/// </summary>
public Vector2 GetSpriteWorldPosition(Entity<SpriteComponent?, TransformComponent?> entity)
{
if (!Resolve(entity, ref entity.Comp2))
return Vector2.Zero;
var (worldPos, worldRot) = _xforms.GetWorldPositionRotation(entity.Owner);
if (!Resolve(entity, ref entity.Comp1, false))
{
return worldPos;
}
if (entity.Comp1.NoRotation)
{
return worldPos + entity.Comp1.Offset;
}
return worldPos + worldRot.RotateVec(entity.Comp1.Rotation.RotateVec(entity.Comp1.Offset));
}
/// <summary>
/// Gets an entity's sprite position in screen coordinates.
/// </summary>
public ScreenCoordinates GetSpriteScreenCoordinates(Entity<SpriteComponent?, TransformComponent?> entity)
{
if (!Resolve(entity, ref entity.Comp2))
return ScreenCoordinates.Invalid;
var spriteCoords = GetSpriteWorldPosition(entity);
return _eye.MapToScreen(new MapCoordinates(spriteCoords, entity.Comp2.MapID));
}
}

View File

@@ -30,10 +30,12 @@ namespace Robust.Client.GameObjects
public sealed partial class SpriteSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly SharedTransformSystem _xforms = default!;
private readonly Queue<SpriteComponent> _inertUpdateQueue = new();
@@ -66,6 +68,11 @@ namespace Robust.Client.GameObjects
_sawmill = _logManager.GetSawmill("sprite");
}
public bool IsVisible(Layer layer)
{
return layer.Visible && layer.CopyToShaderParameters == null;
}
private void OnInit(EntityUid uid, SpriteComponent component, ComponentInit args)
{
// I'm not 100% this is needed, but I CBF with this ATM. Somebody kill server sprite component please.

View File

@@ -1,8 +1,38 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
namespace Robust.Client.GameObjects;
public sealed class UserInterfaceSystem : SharedUserInterfaceSystem
{
public override void Initialize()
{
base.Initialize();
ProtoManager.PrototypesReloaded += OnProtoReload;
}
public override void Shutdown()
{
base.Shutdown();
ProtoManager.PrototypesReloaded -= OnProtoReload;
}
private void OnProtoReload(PrototypesReloadedEventArgs obj)
{
var player = Player.LocalEntity;
if (!UserQuery.TryComp(player, out var userComp))
return;
foreach (var uid in userComp.OpenInterfaces.Keys)
{
if (!UIQuery.TryComp(uid, out var uiComp))
continue;
foreach (var bui in uiComp.ClientOpenInterfaces.Values)
{
bui.OnProtoReload(obj);
}
}
}
}

View File

@@ -14,6 +14,7 @@ namespace Robust.Client.GameObjects
{
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly TransformSystem _transform = default!;
internal bool Enabled { get; set; }
@@ -43,7 +44,7 @@ namespace Robust.Client.GameObjects
return;
}
var screenPos = _eyeManager.WorldToScreen(EntityManager.GetComponent<TransformComponent>(player.Value).WorldPosition);
var screenPos = _eyeManager.WorldToScreen(_transform.GetWorldPosition(Transform(player.Value)));
LayoutContainer.SetPosition(_label, screenPos + new Vector2(0, 50));
_label.Visible = true;

View File

@@ -0,0 +1,5 @@
using Robust.Shared.GameObjects;
namespace Robust.Client.GameObjects;
public sealed class ViewSubscriberSystem : SharedViewSubscriberSystem;

View File

@@ -7,9 +7,5 @@ namespace Robust.Client.GameObjects
// These methods are used by the Game State Manager.
EntityUid CreateEntity(string? prototypeName, out MetaDataComponent metadata);
void InitializeEntity(EntityUid entity, MetaDataComponent? meta = null);
void StartEntity(EntityUid entity);
}
}

View File

@@ -960,7 +960,7 @@ namespace Robust.Client.GameStates
// Initialize and start the newly created entities.
if (_toCreate.Count > 0)
InitializeAndStart(_toCreate);
InitializeAndStart(_toCreate, metas, xforms);
_prof.WriteValue("State Size", ProfData.Int32(curSpan.Length));
_prof.WriteValue("Entered PVS", ProfData.Int32(enteringPvs));
@@ -1188,7 +1188,10 @@ namespace Robust.Client.GameStates
}
}
private void InitializeAndStart(Dictionary<NetEntity, EntityState> toCreate)
private void InitializeAndStart(
Dictionary<NetEntity, EntityState> toCreate,
EntityQuery<MetaDataComponent> metas,
EntityQuery<TransformComponent> xforms)
{
_toStart.Clear();
@@ -1197,22 +1200,8 @@ namespace Robust.Client.GameStates
EntityUid entity = default;
foreach (var netEntity in toCreate.Keys)
{
try
{
(entity, var meta) = _entityManager.GetEntityData(netEntity);
_entities.InitializeEntity(entity, meta);
_toStart.Add((entity, netEntity));
}
catch (Exception e)
{
_sawmill.Error($"Server entity threw in Init: nent={netEntity}, ent={_entities.ToPrettyString(entity)}");
_runtimeLog.LogException(e, $"{nameof(ClientGameStateManager)}.{nameof(InitializeAndStart)}");
_toCreate.Remove(netEntity);
_brokenEnts.Add(entity);
#if !EXCEPTION_TOLERANCE
throw;
#endif
}
(entity, var meta) = _entityManager.GetEntityData(netEntity);
InitializeRecursive(entity, meta, metas, xforms);
}
}
@@ -1244,6 +1233,44 @@ namespace Robust.Client.GameStates
_brokenEnts.Clear();
}
private void InitializeRecursive(
EntityUid entity,
MetaDataComponent meta,
EntityQuery<MetaDataComponent> metas,
EntityQuery<TransformComponent> xforms)
{
var xform = xforms.GetComponent(entity);
if (xform.ParentUid is {Valid: true} parent)
{
var parentMeta = metas.GetComponent(parent);
if (parentMeta.EntityLifeStage < EntityLifeStage.Initialized)
InitializeRecursive(parent, parentMeta, metas, xforms);
}
if (meta.EntityLifeStage >= EntityLifeStage.Initialized)
{
// Was probably already initialized because one of its children appeared earlier in the list.
DebugTools.AssertEqual(_toStart.Count(x => x.Item1 == entity), 1);
return;
}
try
{
_entities.InitializeEntity(entity, meta);
_toStart.Add((entity, meta.NetEntity));
}
catch (Exception e)
{
_sawmill.Error($"Server entity threw in Init: nent={meta.NetEntity}, ent={_entities.ToPrettyString(entity)}");
_runtimeLog.LogException(e, $"{nameof(ClientGameStateManager)}.{nameof(InitializeAndStart)}");
_toCreate.Remove(meta.NetEntity);
_brokenEnts.Add(entity);
#if !EXCEPTION_TOLERANCE
throw;
#endif
}
}
private void HandleEntityState(EntityUid uid, NetEntity netEntity, MetaDataComponent meta, IEventBus bus, EntityState? curState,
EntityState? nextState, GameTick lastApplied, GameTick toTick, bool enteringPvs)
{

View File

@@ -33,7 +33,7 @@ namespace Robust.Client.Graphics.Clyde
#if EXCEPTION_TOLERANCE_LOCAL
catch (Exception e)
{
Logger.ErrorS("clyde.win", $"Error dispatching window event {ev.GetType().Name}:\n{e}");
_sawmillWin.Error($"Error dispatching window event {ev.GetType().Name}:\n{e}");
}
#endif
}

View File

@@ -5,7 +5,6 @@ using OpenToolkit.Graphics.OpenGL4;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Graphics;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
@@ -15,8 +14,6 @@ namespace Robust.Client.Graphics.Clyde
{
internal partial class Clyde
{
[Dependency] private readonly IEntityManager _entityManager = default!;
private readonly Dictionary<EntityUid, Dictionary<Vector2i, MapChunkData>> _mapChunkData =
new();
@@ -67,7 +64,7 @@ namespace Robust.Client.Graphics.Clyde
}
var transform = _entityManager.GetComponent<TransformComponent>(mapGrid);
gridProgram.SetUniform(UniIModelMatrix, transform.WorldMatrix);
gridProgram.SetUniform(UniIModelMatrix, _transformSystem.GetWorldMatrix(transform));
var enumerator = mapSystem.GetMapChunks(mapGrid.Owner, mapGrid.Comp, worldBounds);
while (enumerator.MoveNext(out var chunk))

View File

@@ -9,6 +9,7 @@ using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Graphics;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
@@ -513,7 +514,7 @@ namespace Robust.Client.Graphics.Clyde
if (_lightManager.Enabled && _lightManager.DrawHardFov && eye.DrawLight && eye.DrawFov)
{
var mapUid = _mapManager.GetMapEntityId(eye.Position.MapId);
var mapUid = _mapSystem.GetMap(eye.Position.MapId);
if (_entityManager.GetComponent<MapComponent>(mapUid).LightingEnabled)
ApplyFovToBuffer(viewport, eye);
}

View File

@@ -203,7 +203,7 @@ namespace Robust.Client.Graphics.Clyde
return resource.ClydeHandle;
}
Logger.Warning($"Can't load shader {path}\n");
_clydeSawmill.Warning($"Can't load shader {path}\n");
return default;
}
@@ -345,13 +345,12 @@ namespace Robust.Client.Graphics.Clyde
return;
// If this map has lighting disabled, return
var mapUid = _mapManager.GetMapEntityId(mapId);
var mapUid = _mapSystem.GetMapOrInvalid(mapId);
if (!_entityManager.TryGetComponent<MapComponent>(mapUid, out var map) || !map.LightingEnabled)
{
return;
}
(PointLightComponent light, Vector2 pos, float distanceSquared, Angle rot)[] lights;
int count;
Box2 expandedBounds;
using (_prof.Group("LightsToRender"))
@@ -541,7 +540,6 @@ namespace Robust.Client.Graphics.Clyde
Clyde clyde,
int count,
int shadowCastingCount,
TransformSystem xformSystem,
EntityQuery<TransformComponent> xforms,
Box2 worldAABB) state,
in ComponentTreeEntry<PointLightComponent> value)
@@ -554,7 +552,7 @@ namespace Robust.Client.Graphics.Clyde
return false;
var (light, transform) = value;
var (lightPos, rot) = state.xformSystem.GetWorldPositionRotation(transform, state.xforms);
var (lightPos, rot) = state.clyde._transformSystem.GetWorldPositionRotation(transform, state.xforms);
lightPos += rot.RotateVec(light.Offset);
var circle = new Circle(lightPos, light.Radius);
@@ -600,16 +598,13 @@ namespace Robust.Client.Graphics.Clyde
in Box2Rotated worldBounds,
in Box2 worldAABB)
{
var lightTreeSys = _entitySystemManager.GetEntitySystem<LightTreeSystem>();
var xformSystem = _entitySystemManager.GetEntitySystem<TransformSystem>();
// Use worldbounds for this one as we only care if the light intersects our actual bounds
var xforms = _entityManager.GetEntityQuery<TransformComponent>();
var state = (this, count: 0, shadowCastingCount: 0, xformSystem, xforms, worldAABB);
var state = (this, count: 0, shadowCastingCount: 0, xforms, worldAABB);
foreach (var (uid, comp) in lightTreeSys.GetIntersectingTrees(map, worldAABB))
foreach (var (uid, comp) in _lightTreeSystem.GetIntersectingTrees(map, worldAABB))
{
var bounds = xformSystem.GetInvWorldMatrix(uid, xforms).TransformBox(worldBounds);
var bounds = _transformSystem.GetInvWorldMatrix(uid, xforms).TransformBox(worldBounds);
comp.Tree.QueryAabb(ref state, LightQuery, bounds);
}
@@ -941,18 +936,16 @@ namespace Robust.Client.Graphics.Clyde
var imi = 0;
var amiMax = _maxOccluders * 4;
var occluderSystem = _entitySystemManager.GetEntitySystem<OccluderSystem>();
var xformSystem = _entitySystemManager.GetEntitySystem<TransformSystem>();
var xforms = _entityManager.GetEntityQuery<TransformComponent>();
try
{
foreach (var (uid, comp) in occluderSystem.GetIntersectingTrees(map, expandedBounds))
foreach (var (uid, comp) in _occluderSystem.GetIntersectingTrees(map, expandedBounds))
{
if (ami >= amiMax)
break;
var treeBounds = xforms.GetComponent(uid).InvWorldMatrix.TransformBox(expandedBounds);
var treeBounds = _transformSystem.GetInvWorldMatrix(uid).TransformBox(expandedBounds);
comp.Tree.QueryAabb((in ComponentTreeEntry<OccluderComponent> entry) =>
{
@@ -965,7 +958,7 @@ namespace Robust.Client.Graphics.Clyde
if (ami >= amiMax)
return false;
var worldTransform = xformSystem.GetWorldMatrix(transform, xforms);
var worldTransform = _transformSystem.GetWorldMatrix(transform, xforms);
var box = occluder.BoundingBox;
var tl = Vector2.Transform(box.TopLeft, worldTransform);

View File

@@ -496,6 +496,9 @@ namespace Robust.Client.Graphics.Clyde
case bool b:
program.SetUniform(name, b ? 1 : 0);
break;
case bool[] bArr:
program.SetUniform(name, bArr);
break;
case Matrix3x2 matrix3:
program.SetUniform(name, matrix3);
break;

View File

@@ -506,6 +506,14 @@ namespace Robust.Client.Graphics.Clyde
data.Parameters[name] = value;
}
private protected override void SetParameterImpl(string name, bool[] value)
{
var data = Parent._shaderInstances[Handle];
data.ParametersDirty = true;
data.Parameters[name] = value;
}
private protected override void SetParameterImpl(string name, in Matrix3x2 value)
{
var data = Parent._shaderInstances[Handle];

View File

@@ -61,12 +61,11 @@ internal partial class Clyde
var index = 0;
var added = 0;
var opts = new ParallelOptions { MaxDegreeOfParallelism = _parMan.ParallelProcessCount };
var xformSystem = _entitySystemManager.GetEntitySystem<SharedTransformSystem>();
foreach (var (treeOwner, comp) in _entitySystemManager.GetEntitySystem<SpriteTreeSystem>().GetIntersectingTrees(map, worldBounds))
foreach (var (treeOwner, comp) in _spriteTreeSystem.GetIntersectingTrees(map, worldBounds))
{
var treeXform = query.GetComponent(treeOwner);
var bounds = xformSystem.GetInvWorldMatrix(treeOwner).TransformBox(worldBounds);
var bounds = _transformSystem.GetInvWorldMatrix(treeOwner).TransformBox(worldBounds);
DebugTools.Assert(treeXform.MapUid == treeXform.ParentUid || !treeXform.ParentUid.IsValid());
treeData = treeData with

View File

@@ -0,0 +1,39 @@
using Robust.Client.ComponentTrees;
using Robust.Client.GameObjects;
namespace Robust.Client.Graphics.Clyde;
internal sealed partial class Clyde
{
// Caches entity systems required by Clyde.
private MapSystem _mapSystem = default!;
private LightTreeSystem _lightTreeSystem = default!;
private TransformSystem _transformSystem = default!;
private SpriteTreeSystem _spriteTreeSystem = default!;
private ClientOccluderSystem _occluderSystem = default!;
private void InitSystems()
{
_entityManager.AfterStartup += EntityManagerOnAfterStartup;
_entityManager.AfterShutdown += EntityManagerOnAfterShutdown;
}
private void EntityManagerOnAfterStartup()
{
_mapSystem = _entitySystemManager.GetEntitySystem<MapSystem>();
_lightTreeSystem = _entitySystemManager.GetEntitySystem<LightTreeSystem>();
_transformSystem = _entitySystemManager.GetEntitySystem<TransformSystem>();
_spriteTreeSystem = _entitySystemManager.GetEntitySystem<SpriteTreeSystem>();
_occluderSystem = _entitySystemManager.GetEntitySystem<ClientOccluderSystem>();
}
private void EntityManagerOnAfterShutdown()
{
_mapSystem = null!;
_lightTreeSystem = null!;
_transformSystem = null!;
_spriteTreeSystem = null!;
_occluderSystem = null!;
}
}

View File

@@ -188,7 +188,7 @@ namespace Robust.Client.Graphics.Clyde
{
if (!TryInitMainWindow(glSpec, out lastError))
{
Logger.DebugS("clyde.win", $"OpenGL {glSpec.OpenGLVersion} unsupported: {lastError}");
_sawmillWin.Debug($"OpenGL {glSpec.OpenGLVersion} unsupported: {lastError}");
continue;
}
@@ -199,7 +199,7 @@ namespace Robust.Client.Graphics.Clyde
else
{
if (!TryInitMainWindow(null, out lastError))
Logger.DebugS("clyde.win", $"Failed to create window: {lastError}");
_sawmillWin.Debug($"Failed to create window: {lastError}");
else
succeeded = true;
}
@@ -230,8 +230,7 @@ namespace Robust.Client.Graphics.Clyde
}
}
Logger.FatalS("clyde.win",
"Failed to create main game window! " +
_sawmillWin.Fatal("Failed to create main game window! " +
"This probably means your GPU is too old to run the game. " +
$"That or update your graphics drivers. {lastError}");

View File

@@ -5,6 +5,7 @@ using System.Runtime.InteropServices;
using System.Threading;
using OpenToolkit;
using OpenToolkit.Graphics.OpenGL4;
using Robust.Client.GameObjects;
using Robust.Client.Input;
using Robust.Client.Map;
using Robust.Client.ResourceManagement;
@@ -46,6 +47,7 @@ namespace Robust.Client.Graphics.Clyde
[Dependency] private readonly IDependencyCollection _deps = default!;
[Dependency] private readonly ILocalizationManager _loc = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly ClientEntityManager _entityManager = default!;
private GLUniformBuffer<ProjViewMatrices> ProjViewUBO = default!;
private GLUniformBuffer<UniformConstants> UniformConstantsUBO = default!;
@@ -78,6 +80,7 @@ namespace Robust.Client.Graphics.Clyde
private ISawmill _clydeSawmill = default!;
private ISawmill _sawmillOgl = default!;
private ISawmill _sawmillWin = default!;
private IBindingsContext _glBindingsContext = default!;
private bool _earlyGLInit;
@@ -94,6 +97,7 @@ namespace Robust.Client.Graphics.Clyde
{
_clydeSawmill = _logManager.GetSawmill("clyde");
_sawmillOgl = _logManager.GetSawmill("clyde.ogl");
_sawmillWin = _logManager.GetSawmill("clyde.win");
_cfg.OnValueChanged(CVars.DisplayOGLCheckErrors, b => _checkGLErrors = b, true);
_cfg.OnValueChanged(CVars.DisplayVSync, VSyncChanged, true);
@@ -122,6 +126,8 @@ namespace Robust.Client.Graphics.Clyde
{
_gameThread = Thread.CurrentThread;
InitSystems();
InitGLContextManager();
if (!InitMainWindowAndRenderer())
return false;

View File

@@ -361,6 +361,10 @@ namespace Robust.Client.Graphics.Clyde
{
}
private protected override void SetParameterImpl(string name, bool[] value)
{
}
private protected override void SetParameterImpl(string name, in Matrix3x2 value)
{
}

View File

@@ -37,6 +37,8 @@ namespace Robust.Client.Graphics.Clyde
// NOTE: This class only handles GLES3/D3D11.
// For anything lower we just let ANGLE fall back and do the work 100%.
private readonly ISawmill _sawmill;
private IDXGIFactory1* _factory;
private IDXGIAdapter1* _adapter;
private ID3D11Device* _device;
@@ -58,6 +60,7 @@ namespace Robust.Client.Graphics.Clyde
public GLContextAngle(Clyde clyde) : base(clyde)
{
_sawmill = clyde._logManager.GetSawmill("clyde.ogl.angle");
}
public override GLContextSpec? SpecWithOpenGLVersion(RendererOpenGLVersion version)
@@ -187,7 +190,7 @@ namespace Robust.Client.Graphics.Clyde
}
catch (Exception e)
{
Logger.ErrorS("clyde.ogl.angle", $"Failed to initialize custom ANGLE: {e}");
_sawmill.Error($"Failed to initialize custom ANGLE: {e}");
Shutdown();
return false;
}
@@ -207,7 +210,7 @@ namespace Robust.Client.Graphics.Clyde
private void TryInitializeCore()
{
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(null, EGL_EXTENSIONS));
Logger.DebugS("clyde.ogl.angle", $"EGL client extensions: {extensions}!");
_sawmill.Debug($"EGL client extensions: {extensions}!");
CreateD3D11Device();
CreateEglContext();
@@ -232,10 +235,10 @@ namespace Robust.Client.Graphics.Clyde
var version = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_VERSION));
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_EXTENSIONS));
Logger.DebugS("clyde.ogl.angle", "EGL initialized!");
Logger.DebugS("clyde.ogl.angle", $"EGL vendor: {vendor}!");
Logger.DebugS("clyde.ogl.angle", $"EGL version: {version}!");
Logger.DebugS("clyde.ogl.angle", $"EGL extensions: {extensions}!");
_sawmill.Debug("EGL initialized!");
_sawmill.Debug($"EGL vendor: {vendor}!");
_sawmill.Debug($"EGL version: {version}!");
_sawmill.Debug($"EGL extensions: {extensions}!");
if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE)
throw new Exception("eglBindAPI failed.");
@@ -262,11 +265,11 @@ namespace Robust.Client.Graphics.Clyde
if (numConfigs == 0)
throw new Exception("No compatible EGL configurations returned!");
Logger.DebugS("clyde.ogl.angle", $"{numConfigs} EGL configs possible!");
_sawmill.Debug($"{numConfigs} EGL configs possible!");
for (var i = 0; i < numConfigs; i++)
{
Logger.DebugS("clyde.ogl.angle", DumpEglConfig(_eglDisplay, configs[i]));
_sawmill.Debug(DumpEglConfig(_eglDisplay, configs[i]));
}
_eglConfig = configs[0];
@@ -286,7 +289,7 @@ namespace Robust.Client.Graphics.Clyde
if (_eglContext == (void*) EGL_NO_CONTEXT)
throw new Exception("eglCreateContext failed!");
Logger.DebugS("clyde.ogl.angle", "EGL context created!");
_sawmill.Debug("EGL context created!");
Clyde._openGLVersion = _es3 ? RendererOpenGLVersion.GLES3 : RendererOpenGLVersion.GLES2;
}
@@ -311,11 +314,10 @@ namespace Robust.Client.Graphics.Clyde
if (_adapter == null)
{
Logger.WarningS("clyde.ogl.angle",
$"Unable to find display adapter with requested name: {adapterName}");
_sawmill.Warning($"Unable to find display adapter with requested name: {adapterName}");
}
Logger.DebugS("clyde.ogl.angle", $"Found display adapter with name: {adapterName}");
_sawmill.Debug($"Found display adapter with name: {adapterName}");
}
#pragma warning disable CA1416
@@ -415,9 +417,9 @@ namespace Robust.Client.Graphics.Clyde
var descName = ((ReadOnlySpan<char>)desc.Description).TrimEnd('\0');
Logger.DebugS("clyde.ogl.angle", "Successfully created D3D11 device!");
Logger.DebugS("clyde.ogl.angle", $"D3D11 Device Adapter: {descName.ToString()}");
Logger.DebugS("clyde.ogl.angle", $"D3D11 Device FL: {_deviceFl}");
_sawmill.Debug("Successfully created D3D11 device!");
_sawmill.Debug($"D3D11 Device Adapter: {descName.ToString()}");
_sawmill.Debug($"D3D11 Device FL: {_deviceFl}");
if (_deviceFl == D3D_FEATURE_LEVEL_9_1)
{

View File

@@ -22,6 +22,8 @@ namespace Robust.Client.Graphics.Clyde
private readonly Dictionary<WindowId, WindowData> _windowData = new();
private readonly ISawmill _sawmill;
private void* _eglDisplay;
private void* _eglContext;
private void* _eglConfig;
@@ -30,6 +32,7 @@ namespace Robust.Client.Graphics.Clyde
public GLContextEgl(Clyde clyde) : base(clyde)
{
_sawmill = clyde._logManager.GetSawmill("clyde.ogl.egl");
}
public override GLContextSpec? SpecWithOpenGLVersion(RendererOpenGLVersion version)
@@ -47,7 +50,7 @@ namespace Robust.Client.Graphics.Clyde
public void InitializePublic()
{
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(null, EGL_EXTENSIONS));
Logger.DebugS("clyde.ogl.egl", $"EGL client extensions: {extensions}!");
_sawmill.Debug($"EGL client extensions: {extensions}!");
}
public override void WindowCreated(GLContextSpec? spec, WindowReg reg)
@@ -133,10 +136,10 @@ namespace Robust.Client.Graphics.Clyde
var version = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_VERSION));
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_EXTENSIONS));
Logger.DebugS("clyde.ogl.egl", "EGL initialized!");
Logger.DebugS("clyde.ogl.egl", $"EGL vendor: {vendor}!");
Logger.DebugS("clyde.ogl.egl", $"EGL version: {version}!");
Logger.DebugS("clyde.ogl.egl", $"EGL extensions: {extensions}!");
_sawmill.Debug("EGL initialized!");
_sawmill.Debug($"EGL vendor: {vendor}!");
_sawmill.Debug($"EGL version: {version}!");
_sawmill.Debug($"EGL extensions: {extensions}!");
if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE)
throw new Exception("eglBindAPI failed.");
@@ -164,11 +167,11 @@ namespace Robust.Client.Graphics.Clyde
if (numConfigs == 0)
throw new Exception("No compatible EGL configurations returned!");
Logger.DebugS("clyde.ogl.egl", $"{numConfigs} EGL configs possible!");
_sawmill.Debug($"{numConfigs} EGL configs possible!");
for (var i = 0; i < numConfigs; i++)
{
Logger.DebugS("clyde.ogl.egl", DumpEglConfig(_eglDisplay, configs[i]));
_sawmill.Debug(DumpEglConfig(_eglDisplay, configs[i]));
}
_eglConfig = configs[0];
@@ -183,7 +186,7 @@ namespace Robust.Client.Graphics.Clyde
if (_eglContext == (void*) EGL_NO_CONTEXT)
throw new Exception("eglCreateContext failed!");
Logger.DebugS("clyde.ogl.egl", "EGL context created!");
_sawmill.Debug("EGL context created!");
}
public override void Shutdown()

View File

@@ -418,6 +418,37 @@ namespace Robust.Client.Graphics.Clyde
}
}
public void SetUniform(string uniformName, bool[] bools)
{
var uniformId = GetUniform(uniformName);
SetUniformDirect(uniformId, bools);
}
public void SetUniform(int uniformName, bool[] bools)
{
var uniformId = GetUniform(uniformName);
SetUniformDirect(uniformId, bools);
}
private void SetUniformDirect(int slot, bool[] bools)
{
Span<int> intBools = stackalloc int[bools.Length];
for (var i = 0; i < bools.Length; i++)
{
intBools[i] = bools[i] ? 1 : 0;
}
unsafe
{
fixed (int* intBoolsPtr = intBools)
{
GL.Uniform1(slot, bools.Length, intBoolsPtr);
_clyde.CheckGlError();
}
}
}
public void SetUniformTexture(string uniformName, TextureUnit textureUnit)
{
var uniformId = GetUniform(uniformName);

View File

@@ -224,7 +224,8 @@ namespace Robust.Client.Graphics
// TODO: add support for int, and vec3/4 arrays
return
(type == ShaderDataType.Float) ||
(type == ShaderDataType.Vec2);
(type == ShaderDataType.Vec2) ||
(type == ShaderDataType.Bool);
}
[SuppressMessage("ReSharper", "StringLiteralTypo")]

View File

@@ -148,6 +148,13 @@ namespace Robust.Client.Graphics
SetParameterImpl(name, value);
}
public void SetParameter(string name, bool[] value)
{
EnsureAlive();
EnsureMutable();
SetParameterImpl(name, value);
}
public void SetParameter(string name, in Matrix3x2 value)
{
EnsureAlive();
@@ -219,6 +226,7 @@ namespace Robust.Client.Graphics
private protected abstract void SetParameterImpl(string name, int value);
private protected abstract void SetParameterImpl(string name, Vector2i value);
private protected abstract void SetParameterImpl(string name, bool value);
private protected abstract void SetParameterImpl(string name, bool[] value);
private protected abstract void SetParameterImpl(string name, in Matrix3x2 value);
private protected abstract void SetParameterImpl(string name, in Matrix4 value);
private protected abstract void SetParameterImpl(string name, Texture value);

View File

@@ -21,9 +21,12 @@ using SixLabors.ImageSharp.PixelFormats;
namespace Robust.Client.Map
{
internal sealed class ClydeTileDefinitionManager : TileDefinitionManager, IClydeTileDefinitionManager
internal sealed class ClydeTileDefinitionManager : TileDefinitionManager, IClydeTileDefinitionManager, IPostInjectInit
{
[Dependency] private readonly IResourceManager _manager = default!;
[Dependency] private readonly ILogManager _logManager = default!;
private ISawmill _sawmill = default!;
private Texture? _tileTextureAtlas;
@@ -98,8 +101,7 @@ namespace Robust.Client.Map
if (imgWidth >= 2048 || imgHeight >= 2048)
{
// Sanity warning, some machines don't have textures larger than this and need multiple atlases.
Logger.WarningS("clyde",
$"Tile texture atlas is ({imgWidth} x {imgHeight}), larger than 2048 x 2048. If you really need {tileCount} tiles, file an issue on RobustToolbox.");
_sawmill.Warning($"Tile texture atlas is ({imgWidth} x {imgHeight}), larger than 2048 x 2048. If you really need {tileCount} tiles, file an issue on RobustToolbox.");
}
var column = 1;
@@ -151,6 +153,11 @@ namespace Robust.Client.Map
_tileTextureAtlas = Texture.LoadFromImage(sheet, "Tile Atlas");
}
void IPostInjectInit.PostInject()
{
_sawmill = _logManager.GetSawmill("clyde");
}
}
public sealed class ReloadTileTexturesCommand : LocalizedCommands

View File

@@ -34,13 +34,13 @@ namespace Robust.Client.Placement.Modes
{
var from = ScreenToWorld(new Vector2(a, 0));
var to = ScreenToWorld(new Vector2(a, viewportSize.Y));
args.WorldHandle.DrawLine(from, to, new Color(0, 0, 1f));
args.WorldHandle.DrawLine(from, to, new Color(0, 0, 0.3f));
}
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));
args.WorldHandle.DrawLine(from, to, new Color(0, 0, 1f));
args.WorldHandle.DrawLine(from, to, new Color(0, 0, 0.3f));
}
}

View File

@@ -167,7 +167,6 @@ namespace Robust.Client.Player
if (_client.RunLevel != ClientRunLevel.SinglePlayerGame)
Sawmill.Warning($"Attaching local player to an entity {EntManager.ToPrettyString(uid)} without an eye. This eye will not be netsynced and may cause issues.");
var eye = (EyeComponent) Factory.GetComponent(typeof(EyeComponent));
eye.Owner = uid.Value;
eye.NetSyncEnabled = false;
EntManager.AddComponent(uid.Value, eye);
}

View File

@@ -44,6 +44,10 @@
<ProjectReference Include="..\Robust.Shared\Robust.Shared.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(RobustToolsBuild)' == 'True'">
<ProjectReference Include="..\Robust.Xaml\Robust.Xaml.csproj" />
</ItemGroup>
<!-- Shader embedding -->
<ItemGroup>
<EmbeddedResource Include="Graphics\Clyde\Shaders\*" />

View File

@@ -0,0 +1,33 @@
using System;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
namespace Robust.Client.UserInterface;
public static class BoundUserInterfaceExt
{
/// <summary>
/// Helper method to create a window and also handle closing the BUI when it's closed.
/// </summary>
public static T CreateWindow<T>(this BoundUserInterface bui) where T : BaseWindow, new()
{
var window = bui.CreateDisposableControl<T>();
window.OpenCentered();
window.OnClose += bui.Close;
return window;
}
/// <summary>
/// Creates a control for this BUI that will be disposed when it is disposed.
/// </summary>
/// <param name="bui"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T CreateDisposableControl<T>(this BoundUserInterface bui) where T : Control, IDisposable, new()
{
var control = new T();
bui.Disposals ??= [];
bui.Disposals.Add(control);
return control;
}
}

View File

@@ -602,6 +602,7 @@ namespace Robust.Client.UserInterface
/// Dispose this control, its own scene control, and all its children.
/// Basically the big delete button.
/// </summary>
[Obsolete("Controls should only be removed from UI tree instead of being disposed")]
public void Dispose()
{
if (Disposed)
@@ -613,6 +614,7 @@ namespace Robust.Client.UserInterface
Disposed = true;
}
[Obsolete("Controls should only be removed from UI tree instead of being disposed")]
protected virtual void Dispose(bool disposing)
{
if (!disposing)

View File

@@ -327,8 +327,7 @@ public sealed class EntitySpawningUIController : UIController
if (_window == null || _window.Disposed)
return;
var textures = SpriteComponent.GetPrototypeTextures(prototype, _resources).Select(o => o.Default).ToList();
var button = _window.InsertEntityButton(prototype, insertFirst, index, textures);
var button = _window.InsertEntityButton(prototype, insertFirst, index);
button.ActualButton.OnToggled += OnEntityButtonToggled;
}

View File

@@ -33,10 +33,7 @@ public class EntityPrototypeView : SpriteView
_currentPrototype = entProto;
SetEntity(null);
if (_ourEntity != null)
{
EntMan.DeleteEntity(_ourEntity);
}
EntMan.DeleteEntity(_ourEntity);
if (_currentPrototype != null)
{
@@ -57,8 +54,6 @@ public class EntityPrototypeView : SpriteView
protected override void ExitedTree()
{
base.ExitedTree();
if (!EntMan.Deleted(_ourEntity))
EntMan.QueueDeleteEntity(_ourEntity);
EntMan.TryQueueDeleteEntity(_ourEntity);
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Numerics;
using Robust.Client.Graphics;
@@ -14,6 +14,7 @@ namespace Robust.Client.UserInterface.Controls
public const string StyleClassOptionButton = "optionButton";
public const string StyleClassPopup = "optionButtonPopup";
public const string StyleClassOptionTriangle = "optionTriangle";
public const string StyleClassOptionsBackground = "optionButtonBackground";
public readonly ScrollContainer OptionsScroll;
private readonly List<ButtonData> _buttonData = new();
@@ -75,7 +76,12 @@ namespace Robust.Client.UserInterface.Controls
_popup = new Popup()
{
Children = { new PanelContainer(), OptionsScroll },
Children = {
new PanelContainer {
StyleClasses = { StyleClassOptionsBackground }
},
OptionsScroll
},
StyleClasses = { StyleClassPopup }
};
_popup.OnPopupHide += OnPopupHide;

View File

@@ -38,6 +38,21 @@ namespace Robust.Client.UserInterface.Controls
}
}
public string? Text
{
get => _message?.ToMarkup();
set
{
if (value == null)
{
_message?.Clear();
return;
}
SetMessage(FormattedMessage.FromMarkupPermissive(value));
}
}
public RichTextLabel()
{
IoCManager.InjectDependencies(this);

View File

@@ -191,6 +191,19 @@ namespace Robust.Client.UserInterface.Controls
_splitDragArea.OnMouseMove += OnMove;
}
/// <summary>
/// Swaps the position of the first and zeroeth children; for a 2-control viewport it effectively flips them.
/// </summary>
public void Flip()
{
if (ChildCount < 3)
return;
DebugTools.Assert(ChildCount <= 3);
GetChild(1).SetPositionFirst();
InvalidateArrange();
}
private void OnMove(GUIMouseMoveEventArgs args)
{
if (ResizeMode == SplitResizeMode.NotResizable)

View File

@@ -1,5 +1,6 @@
using System;
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;
using Robust.Shared.IoC;
@@ -235,6 +236,15 @@ namespace Robust.Client.UserInterface.CustomControls
public void OpenToRight() => OpenCenteredAt(new Vector2(1, 0.5f));
public void OpenCenteredRight() => OpenCenteredAt(new Vector2(0.75f, 0.5f));
/// <summary>
/// Opens a window and centers it relative to the screen position.
/// </summary>
public void OpenScreenAt(Vector2 relativePosition, IClyde clyde)
{
var adjusted = relativePosition / clyde.ScreenSize;
OpenCenteredAt(adjusted);
}
/// <summary>
/// Opens a window, attempting to place the center of the window at some relative point on the screen.
/// </summary>

View File

@@ -83,7 +83,7 @@ namespace Robust.Client.UserInterface.CustomControls.DebugMonitorControls
}
else
{
mouseGridPos = new EntityCoordinates(_mapManager.GetMapEntityId(mouseWorldMap.MapId),
mouseGridPos = new EntityCoordinates(mapSystem.GetMapOrInvalid(mouseWorldMap.MapId),
mouseWorldMap.Position);
tile = new TileRef(EntityUid.Invalid,
mouseGridPos.ToVector2i(_entityManager, _mapManager, xformSystem), Tile.Empty);

View File

@@ -12,7 +12,7 @@ public sealed class EntitySpawnButton : Control
public EntityPrototype Prototype { get; set; } = default!;
public Button ActualButton { get; private set; }
public Label EntityLabel { get; private set; }
public LayeredTextureRect EntityTextureRects { get; private set; }
public EntityPrototypeView EntityTextureRects {get; private set; }
public int Index { get; set; }
public EntitySpawnButton()
@@ -27,13 +27,12 @@ public sealed class EntitySpawnButton : Control
Orientation = BoxContainer.LayoutOrientation.Horizontal,
Children =
{
(EntityTextureRects = new LayeredTextureRect
(EntityTextureRects = new EntityPrototypeView
{
MinSize = new Vector2(32, 32),
SetSize = new Vector2(32, 32),
HorizontalAlignment = HAlignment.Center,
VerticalAlignment = VAlignment.Center,
Stretch = TextureRect.StretchMode.KeepAspectCentered,
CanShrink = true
Stretch = SpriteView.StretchMode.Fill
}),
(EntityLabel = new Label
{

View File

@@ -44,7 +44,7 @@ namespace Robust.Client.UserInterface.CustomControls
}
// Create a spawn button and insert it into the start or end of the list.
public EntitySpawnButton InsertEntityButton(EntityPrototype prototype, bool insertFirst, int index, List<Texture> textures)
public EntitySpawnButton InsertEntityButton(EntityPrototype prototype, bool insertFirst, int index)
{
var button = new EntitySpawnButton
{
@@ -67,7 +67,7 @@ namespace Robust.Client.UserInterface.CustomControls
}
var rect = button.EntityTextureRects;
rect.Textures = textures;
rect.SetPrototype(prototype.ID);
PrototypeList.AddChild(button);
if (insertFirst)

View File

@@ -64,7 +64,7 @@ namespace Robust.Client.UserInterface
IDebugMonitors DebugMonitors { get; }
void Popup(string contents, string title = "Alert!");
void Popup(string contents, string? title = null, bool clipboardButton = true);
Control? MouseGetControl(ScreenCoordinates coordinates);

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Robust.Client.State;
using Robust.Shared.Console;
using Robust.Shared.IoC;
@@ -7,11 +8,12 @@ namespace Robust.Client.UserInterface
{
sealed class ChangeSceneCommpand : LocalizedCommands
{
[Dependency] private readonly IReflectionManager _reflection = default!;
public override string Command => "scene";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var reflection = IoCManager.Resolve<IReflectionManager>();
var types = reflection.GetAllChildren(typeof(State.State));
var types = _reflection.GetAllChildren(typeof(State.State));
foreach (var tryType in types)
{
@@ -26,5 +28,13 @@ namespace Robust.Client.UserInterface
shell.WriteError($"No scene child class type ends with {args[0]}");
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length != 1)
return CompletionResult.Empty;
var types = _reflection.GetAllChildren(typeof(State.State));
return CompletionResult.FromHintOptions(types.Select(x => x.Name), "[State name]");
}
}
}

View File

@@ -148,7 +148,7 @@ internal partial class UserInterfaceManager
var newHovered = MouseGetControl(mouseMoveEventArgs.Position);
SetHovered(newHovered);
var target = ControlFocused ?? newHovered;
var target = ControlFocused ?? CurrentlyHovered;
if (target != null)
{
var pos = mouseMoveEventArgs.Position.Position;
@@ -164,7 +164,7 @@ internal partial class UserInterfaceManager
public void UpdateHovered()
{
var ctrl = MouseGetControl(_inputManager.MouseScreenPosition);
var ctrl = MouseGetControl(_inputManager.MouseScreenPosition);
SetHovered(ctrl);
}

View File

@@ -4,6 +4,7 @@ using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Profiling;
@@ -53,14 +54,47 @@ internal sealed partial class UserInterfaceManager
}
}
public void Popup(string contents, string title = "Alert!")
public void Popup(string contents, string? title = null, bool clipboardButton = true)
{
var popup = new DefaultWindow
{
Title = title
Title = string.IsNullOrEmpty(title) ? Loc.GetString("popup-title") : title,
};
popup.Contents.AddChild(new Label {Text = contents});
var label = new Label { Text = contents };
var vBox = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
};
vBox.AddChild(label);
if (clipboardButton)
{
var copyButton = new Button
{
Text = Loc.GetString("popup-copy-button"),
HorizontalExpand = true,
};
copyButton.OnPressed += _ =>
{
_clipboard.SetText(contents);
};
var hBox = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
HorizontalAlignment = Control.HAlignment.Right,
};
hBox.AddChild(copyButton);
vBox.AddChild(hBox);
}
popup.Contents.AddChild(vBox);
popup.OpenCentered();
}

View File

@@ -54,6 +54,7 @@ namespace Robust.Client.UserInterface
[Dependency] private readonly IEntitySystemManager _systemManager = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IRuntimeLog _runtime = default!;
[Dependency] private readonly IClipboardManager _clipboard = null!;
private IAudioSource? _clickSource;
private IAudioSource? _hoverSource;
@@ -214,6 +215,9 @@ namespace Robust.Client.UserInterface
{
using (_prof.Group("Update"))
{
// Update hovered. Can't rely upon mouse movement due to New controls potentially coming up.
UpdateHovered();
foreach (var root in _roots)
{
CheckRootUIScaleUpdate(root);

View File

@@ -0,0 +1,20 @@
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// This service locates the SS14 source tree and watches for changes to its xaml files.
/// </summary>
/// <remarks>
/// It then reloads them instantly.
///
/// It depends on <see cref="IXamlProxyManager"/> and is stubbed on non-TOOLS builds.
/// </remarks>
interface IXamlHotReloadManager
{
/// <summary>
/// Initialize the hot reload manager.
/// </summary>
/// <remarks>
/// You can't do anything with this once it's started, including turn it off.
/// </remarks>
void Initialize();
}

View File

@@ -0,0 +1,11 @@
using System;
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// Reexport the Populate method of <see cref="IXamlProxyManager"/> and nothing else.
/// </summary>
public interface IXamlProxyHelper
{
bool Populate(Type t, object o);
}

View File

@@ -0,0 +1,76 @@
using System;
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// This service provides a proxy for Populate, which is the generated function that
/// initializes the UI objects of a Xaml widget.
/// </summary>
/// <remarks>
/// The proxy can always return false: in that case, a Xaml widget will self-populate
/// as usual. This is the behavior on Release builds.
///
/// However, it can also call into an externally-provided implementation of the Xaml
/// widget.
///
/// No source of externally-provided implementations actually exists, by default --
/// you will need to call SetImplementation with a blob of xaml source code to provide
/// one. <see cref="IXamlHotReloadManager" /> is an example of a service that calls into
/// that functionality.
/// </remarks>
internal interface IXamlProxyManager
{
/// <summary>
/// Initialize creates the <see cref="IXamlProxyManager"/>.
/// </summary>
/// <remarks>
/// If the <see cref="IXamlProxyManager" /> is not a stub, then it will spy on the
/// assembly list (from <see cref="Robust.Shared.Reflection.IReflectionManager" />)
/// and find <see cref="XamlMetadataAttribute" /> entries on the loaded types.
/// </remarks>
void Initialize();
/// <summary>
/// Return true if at least one <see cref="Type"/> in the current project expects its XAML
/// to come from a file with the given name.
/// </summary>
/// <remarks>
/// This method supports code that is trying to figure out what name the build process
/// would have assigned to a resource file. A caller can try a few candidate names and use
/// its "yes" to continue.
///
/// This method is very fast, so it's OK to hammer it!
///
/// Also, on a non-tools build, this always returns false.
/// </remarks>
/// <param name="fileName">the filename</param>
/// <returns>true if expected</returns>
bool CanSetImplementation(string fileName);
/// <summary>
/// Replace the implementation of <paramref name="fileName"/> with <paramref name="fileContent" />,
/// compiling it if needed.
///
/// All types based on <paramref name="fileName" /> will be recompiled.
/// </summary>
/// <remarks>
/// This may fail and the caller won't be notified. (There will usually be logs.)
///
/// On a non-tools build, this fails silently.
/// </remarks>
/// <param name="fileName">the name of the file</param>
/// <param name="fileContent">the new content of the file</param>
void SetImplementation(string fileName, string fileContent);
/// <summary>
/// If we have a JIT version of the XAML code for <paramref name="t" />, then call
/// the new implementation on <paramref name="o" />.
/// </summary>
/// <remarks>
/// <paramref name="o" /> may be a subclass of <paramref name="t" />.
/// </remarks>
/// <param name="t">the static type of the object</param>
/// <param name="o">the object</param>
/// <returns>true if we called a hot reloaded implementation</returns>
bool Populate(Type t, object o);
}

View File

@@ -0,0 +1,195 @@
#if TOOLS
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Robust.Shared.Asynchronous;
using Robust.Shared.ContentPack;
using Robust.Shared.IoC;
using Robust.Shared.Log;
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// The real implementation of <see cref="IXamlHotReloadManager" />.
/// </summary>
/// <remarks>
/// Its behavior is described there.
/// </remarks>
internal sealed class XamlHotReloadManager : IXamlHotReloadManager
{
private const string MarkerFileName = "SpaceStation14.sln";
[Dependency] ILogManager _logManager = null!;
[Dependency] private readonly IResourceManager _resources = null!;
[Dependency] private readonly ITaskManager _taskManager = null!;
[Dependency] private readonly IXamlProxyManager _xamlProxyManager = null!;
private ISawmill _sawmill = null!;
private FileSystemWatcher? _watcher;
public void Initialize()
{
_sawmill = _logManager.GetSawmill("xamlhotreload");
var codeLocation = InferCodeLocation();
if (codeLocation == null)
{
_sawmill.Warning($"could not find code -- where is {MarkerFileName}?");
return;
}
_sawmill.Info($"code location: {codeLocation}");
// must not be gc'ed or else it will stop reporting
// therefore: keep a reference
_watcher = CreateWatcher(codeLocation);
}
/// <summary>
/// Create a file system watcher that identifies XAML changes in a given
/// location.
/// </summary>
/// <param name="location">the location (a real path on the OS file system)</param>
/// <returns>the new watcher</returns>
/// <exception cref="ArgumentOutOfRangeException">if <see cref="FileSystemWatcher"/> violates its type-related postconditions</exception>
private FileSystemWatcher CreateWatcher(string location)
{
var watcher = new FileSystemWatcher(location)
{
IncludeSubdirectories = true,
NotifyFilter = NotifyFilters.LastWrite,
};
watcher.Changed += (_, args) =>
{
switch (args.ChangeType)
{
case WatcherChangeTypes.Renamed:
case WatcherChangeTypes.Deleted:
return;
case WatcherChangeTypes.Created:
case WatcherChangeTypes.Changed:
case WatcherChangeTypes.All:
break;
default:
throw new ArgumentOutOfRangeException(nameof(args));
}
_taskManager.RunOnMainThread(() =>
{
var resourceFileName =
ResourceFileName(location, args.FullPath, _xamlProxyManager.CanSetImplementation);
if (resourceFileName == null)
{
return;
}
string newText;
try
{
newText = File.ReadAllText(args.FullPath);
}
catch (IOException ie)
{
_sawmill.Warning($"error attempting a hot reload -- skipped: {ie}");
return;
}
_xamlProxyManager.SetImplementation(resourceFileName, newText);
});
};
watcher.EnableRaisingEvents = true;
return watcher;
}
/// <summary>
/// Using the content roots of the project, infer the location of its code.
/// </summary>
/// <remarks>
/// This kind of introspection is almost universally a bad idea, but we don't
/// feasibly have other options, so I've buried it in a private method.
/// </remarks>
/// <returns>the inferred code location or null</returns>
private string? InferCodeLocation()
{
// ascend upwards from each content root until the solution file is found
foreach (var contentRoot in _resources.GetContentRoots())
{
var systemPath = contentRoot.ToRelativeSystemPath();
while (true)
{
var files = Array.Empty<string>();
try
{
files = Directory.GetFiles(systemPath);
}
catch (IOException) { } // this is allowed to fail, and if so we just keep going up
if (files.Any(f => Path.GetFileName(f).Equals(MarkerFileName, StringComparison.InvariantCultureIgnoreCase)))
{
return systemPath;
}
DirectoryInfo? newPath = null;
try
{
newPath = Directory.GetParent(systemPath);
}
catch (IOException) { } // ditto here. if we don't find it, we're in the wrong place
if (newPath == null)
{
break;
}
systemPath = newPath.FullName;
}
}
return null;
}
/// <summary>
/// Infer the name of the resource file associated with the XAML item at the given path.
/// </summary>
/// <param name="codeLocation">the code location</param>
/// <param name="realPath">the real path of the file</param>
/// <param name="isDesired">a function returning true if something expects this file</param>
/// <returns>the name of a desired resource that matches this file, or null</returns>
private string? ResourceFileName(string codeLocation, string realPath, Predicate<string> isDesired)
{
// start with the name of the file and systematically add each super-directory until we reach
// the inferred code location.
//
// for /home/pyrex/ss14/Content.Client/Instruments/UI/InstrumentMenu.xaml, the following names
// will be tried:
//
// - InstrumentMenu.xaml
// - UI.InstrumentMenu.xaml
// - Instruments.UI.InstrumentMenu.xaml
// - Content.Client.Instruments.UI.InstrumentMenu.xaml
var resourceFileName = Path.GetFileName(realPath);
var super = Directory.GetParent(realPath);
var canonicalCodeLocation = Path.GetFullPath(codeLocation);
while (true)
{
// did someone want it: OK, jump out
if (isDesired(resourceFileName))
{
return resourceFileName;
}
if (super == null || Path.GetFullPath(super.FullName) == canonicalCodeLocation)
{
return null;
}
resourceFileName = super.Name + "." + resourceFileName;
super = super.Parent;
}
}
}
#endif

View File

@@ -0,0 +1,15 @@
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// A stub implementation of <see cref="XamlHotReloadManager"/>. Its
/// behavior is to do nothing.
/// </summary>
internal sealed class XamlHotReloadManagerStub : IXamlHotReloadManager
{
/// <summary>
/// Do nothing.
/// </summary>
public void Initialize()
{
}
}

View File

@@ -0,0 +1,221 @@
#if TOOLS
using System;
using System.Collections.Generic;
using System.Reflection;
using Robust.Shared.Log;
using Robust.Xaml;
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// This is a utility class that tracks the relationship between resource file names,
/// Xamlx-compatible <see cref="Uri"/>s, <see cref="Type"/>s that are interested in a
/// given file, and implementations of Populate.
/// </summary>
internal sealed class XamlImplementationStorage
{
/// <summary>
/// For each filename, we store its last known <see cref="Uri"/>.
/// </summary>
/// <remarks>
/// When we compile the new implementation, we will use the same <see cref="Uri"/>.
/// </remarks>
private readonly Dictionary<string, Uri> _fileUri = new();
/// <summary>
/// For each filename, we store its last known content.
/// </summary>
/// <remarks>
/// This is known even for AOT-compiled code -- therefore, we can use this table
/// to convert an AOT-compiled Control to a JIT-compiled one.
/// </remarks>
private readonly Dictionary<string, string> _fileContent = new();
/// <summary>
/// For each filename, we store the type interested in this file.
/// </summary>
private readonly Dictionary<string, Type> _fileType = new();
/// <summary>
/// For each type, store the JIT-compiled implementation of Populate.
/// </summary>
/// <remarks>
/// If no such implementation exists, then methods that would normally
/// find and call a JIT'ed implementation will do nothing and return
/// false instead. As an ultimate result, the AOT'ed implementation
/// will be used.
/// </remarks>
private readonly Dictionary<Type, MethodInfo> _populateImplementations = new();
private readonly ISawmill _sawmill;
private readonly XamlJitDelegate _jitDelegate;
/// <summary>
/// Create the storage.
/// </summary>
/// <remarks>
/// It would be weird to call this from any type outside of
/// <see cref="Robust.Client.UserInterface.XAML.Proxy" />.
/// </remarks>
/// <param name="sawmill">the (shared) logger</param>
/// <param name="jitDelegate">
/// a delegate that calls the
/// <see cref="XamlJitCompiler"/>, possibly handling errors
/// </param>
public XamlImplementationStorage(ISawmill sawmill, XamlJitDelegate jitDelegate)
{
_sawmill = sawmill;
_jitDelegate = jitDelegate;
}
/// <summary>
/// Inspect <paramref name="assembly" /> for types that declare a <see cref="XamlMetadataAttribute"/>.
/// </summary>
/// <remarks>
/// We can only do hot reloading if we know this basic information.
///
/// Note that even release-mode content artifacts contain this attribute.
/// </remarks>
/// <param name="assembly">the assembly</param>
/// <returns>an IEnumerable of types with xaml metadata</returns>
private IEnumerable<(Type, XamlMetadataAttribute)> TypesWithXamlMetadata(Assembly assembly)
{
foreach (var type in assembly.GetTypes())
{
if (type.GetCustomAttribute<XamlMetadataAttribute>() is not { } attr)
{
continue;
}
yield return (type, attr);
}
}
/// <summary>
/// Add all Xaml-annotated types from <paramref name="assembly" /> to this storage.
/// </summary>
/// <remarks>
/// We don't JIT these types, but we store enough info that we could JIT
/// them if we wanted to.
/// </remarks>
/// <param name="assembly">an assembly</param>
public void Add(Assembly assembly)
{
foreach (var (type, metadata) in TypesWithXamlMetadata(assembly))
{
// this can fail, but if it does, that means something is _really_ wrong
// with the compiler, or someone tried to write their own Xaml metadata
Uri uri;
try
{
uri = new Uri(metadata.Uri);
}
catch (UriFormatException)
{
throw new InvalidProgramException(
$"XamlImplementationStorage encountered an malformed Uri in the metadata for {type.FullName}: " +
$"{metadata.Uri}. this is a bug in XamlAotCompiler"
);
}
var fileName = metadata.FileName;
var content = metadata.Content;
_fileUri[fileName] = uri;
_fileContent[fileName] = content;
if (!_fileType.TryAdd(fileName, type))
{
throw new InvalidProgramException(
$"XamlImplementationStorage observed that two types were interested in the same Xaml filename: " +
$"{fileName}. ({type.FullName} and {_fileType[fileName].FullName}). this is a bug in XamlAotCompiler"
);
}
}
}
/// <summary>
/// Quietly JIT every type with XAML metadata.
/// </summary>
/// <remarks>
/// This should have no visible effect except that the <see cref="XamlJitDelegate"/>
/// may dump some info messages into the terminal about cases where the
/// hot reload failed.
/// </remarks>
public void ForceReloadAll()
{
foreach (var (fileName, fileContent) in _fileContent)
{
SetImplementation(fileName, fileContent, true);
}
}
/// <summary>
/// Return true if calling <see cref="SetImplementation" /> on <paramref name="fileName" /> would not be a no-op.
/// </summary>
/// <remarks>
/// That is: if some type cares about the contents of <paramref name="fileName" />.
/// </remarks>
/// <param name="fileName">the filename</param>
/// <returns>true if not a no-op</returns>
public bool CanSetImplementation(string fileName)
{
return _fileType.ContainsKey(fileName);
}
/// <summary>
/// Replace the implementation of <paramref name="fileName"/> by JIT-ing
/// <paramref name="fileContent"/>.
/// </summary>
/// <remarks>
/// If nothing cares about the implementation of <paramref name="fileName"/>, then this will do nothing.
/// </remarks>
/// <param name="fileName">the name of the file whose implementation should be replaced</param>
/// <param name="fileContent">the new implementation</param>
/// <param name="quiet">if true, then don't bother to log</param>
public void SetImplementation(string fileName, string fileContent, bool quiet)
{
if (!_fileType.TryGetValue(fileName, out var type))
{
_sawmill.Warning($"SetImplementation called with {fileName}, but no types care about its contents");
return;
}
var uri =
_fileUri.GetValueOrDefault(fileName) ??
throw new InvalidProgramException("file URI missing (this is a bug in ImplementationStorage)");
if (!quiet)
{
_sawmill.Debug($"replacing {fileName} for {type}");
}
var impl = _jitDelegate(type, uri, fileName, fileContent);
if (impl != null)
{
_populateImplementations[type] = impl;
}
_fileContent[fileName] = fileContent;
}
/// <summary>
/// Call the JITed implementation of Populate on a XAML-associated object <paramref name="o"/>.
///
/// If no JITed implementation exists, return false.
/// </summary>
/// <param name="t">the static type of <paramref name="o"/></param>
/// <param name="o">an instance of <paramref name="t"/> (can be a subclass)</param>
/// <returns>true if a JITed implementation existed</returns>
public bool Populate(Type t, object o)
{
if (!_populateImplementations.TryGetValue(t, out var implementation))
{
// pop out if we never JITed anything
return false;
}
implementation.Invoke(null, [null, o]);
return true;
}
}
#endif

View File

@@ -0,0 +1,17 @@
using System;
using System.Reflection;
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// This callback has the approximate type of <see cref="Robust.Xaml.XamlJitCompiler.Compile"/>,
/// but it has no error-signaling faculty.
/// </summary>
/// <remarks>
/// Implementors of this delegate should inform the users of errors in their own way.
///
/// Hot reloading failures should not directly take down the process, so implementors
/// should not rethrow exceptions unless they have a strong reason to believe they
/// will be caught.
/// </remarks>
internal delegate MethodInfo? XamlJitDelegate(Type type, Uri uri, string filename, string content);

View File

@@ -0,0 +1,29 @@
using System;
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// Metadata to support JIT compilation of XAML resources for a type.
/// </summary>
/// <remarks>
/// We can feed XamlX data from this type, along with new content, to get new XAML
/// resources.
///
/// This type is inert and is generated for release artifacts too, not just debug
/// artifacts. Released content should support hot reloading if loaded in a debug
/// client, but this is untested.
/// </remarks>
[AttributeUsage(validOn: AttributeTargets.Class, Inherited = false)]
public sealed class XamlMetadataAttribute: System.Attribute
{
public readonly string Uri;
public readonly string FileName;
public readonly string Content;
public XamlMetadataAttribute(string uri, string fileName, string content)
{
Uri = uri;
FileName = fileName;
Content = content;
}
}

View File

@@ -0,0 +1,14 @@
using System;
using Robust.Shared.IoC;
namespace Robust.Client.UserInterface.XAML.Proxy;
internal sealed class XamlProxyHelper: IXamlProxyHelper
{
[Dependency] private IXamlProxyManager _xamlProxyManager = default!;
public bool Populate(Type t, object o)
{
return _xamlProxyManager.Populate(t, o);
}
}

View File

@@ -0,0 +1,127 @@
#if TOOLS
using System;
using System.Collections.Generic;
using System.Reflection;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Reflection;
using Robust.Xaml;
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// The real implementation of <see cref="IXamlProxyManager"/>.
/// </summary>
public sealed class XamlProxyManager: IXamlProxyManager
{
ISawmill _sawmill = null!;
[Dependency] IReflectionManager _reflectionManager = null!;
[Dependency] ILogManager _logManager = null!;
XamlImplementationStorage _xamlImplementationStorage = null!;
List<Assembly> _knownAssemblies = [];
XamlJitCompiler? _xamlJitCompiler;
/// <summary>
/// Initialize this, subscribing to assembly changes.
/// </summary>
public void Initialize()
{
_sawmill = _logManager.GetSawmill("xamlhotreload");
_xamlImplementationStorage = new XamlImplementationStorage(_sawmill, Compile);
AddAssemblies();
_reflectionManager.OnAssemblyAdded += (_, _) => { AddAssemblies(); };
}
/// <summary>
/// Return true if setting the implementation of <paramref name="fileName" />
/// would not be a no-op.
/// </summary>
/// <param name="fileName">the file name</param>
/// <returns>true or false</returns>
public bool CanSetImplementation(string fileName)
{
return _xamlImplementationStorage.CanSetImplementation(fileName);
}
/// <summary>
/// Replace the implementation of <paramref name="fileName" />, failing
/// silently if the new content does not compile. (but still logging)
/// </summary>
/// <param name="fileName">the file name</param>
/// <param name="fileContent">the new content</param>
public void SetImplementation(string fileName, string fileContent)
{
_xamlImplementationStorage.SetImplementation(fileName, fileContent, false);
}
/// <summary>
/// Add all the types from all known assemblies, then force-JIT everything
/// again.
/// </summary>
private void AddAssemblies()
{
foreach (var a in _reflectionManager.Assemblies)
{
if (!_knownAssemblies.Contains(a))
{
_knownAssemblies.Add(a);
_xamlImplementationStorage.Add(a);
_xamlJitCompiler = null;
}
}
// Always use the JITed versions on debug builds
_xamlImplementationStorage.ForceReloadAll();
}
/// <summary>
/// Populate <paramref name="o" /> using the JIT compiler, if possible.
/// </summary>
/// <param name="t">the static type of <paramref name="o" /></param>
/// <param name="o">a <paramref name="t" /> instance or subclass</param>
/// <returns>true if there was a JITed implementation</returns>
public bool Populate(Type t, object o)
{
return _xamlImplementationStorage.Populate(t, o);
}
/// <summary>
/// Calls <see cref="XamlJitCompiler.Compile"/> using a stored
/// <see cref="XamlJitCompiler"/> instance.
/// </summary>
/// <param name="t">the <see cref="Type"/> that cares about this Xaml</param>
/// <param name="uri">the <see cref="Uri" /> of this xaml (from the type's metadata)</param>
/// <param name="fileName">the filename of this xaml (from the type's metadata)</param>
/// <param name="content">the new content of the xaml file</param>
/// <returns>the MethodInfo for the new JITed implementation</returns>
private MethodInfo? Compile(Type t, Uri uri, string fileName, string content)
{
// initialize XamlJitCompiler lazily because constructing it has
// very high CPU cost
XamlJitCompiler xjit;
lock(this)
{
xjit = _xamlJitCompiler ??= new XamlJitCompiler();
}
var result = xjit.Compile(t, uri, fileName, content);
if (result is XamlJitCompilerResult.Error e)
{
_sawmill.Info($"hot reloading failed: {t.FullName}; {fileName}; {e.Raw.Message} {e.Hint ?? ""}");
return null;
}
if (result is XamlJitCompilerResult.Success s)
{
return s.MethodInfo;
}
throw new InvalidOperationException($"totally unexpected result from compiler operation: {result}");
}
}
#endif

View File

@@ -0,0 +1,50 @@
using System;
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// The stub implementation of <see cref="IXamlProxyManager"/>.
/// </summary>
public sealed class XamlProxyManagerStub: IXamlProxyManager
{
/// <summary>
/// Do nothing.
/// </summary>
public void Initialize()
{
}
/// <summary>
/// Return false. Nothing is ever interested in a Xaml content update when
/// hot reloading is off.
/// </summary>
/// <param name="fileName">the filename</param>
/// <returns>false</returns>
public bool CanSetImplementation(string fileName)
{
return false;
}
/// <summary>
/// Do nothing. A hot reload will always silently fail if hot reloading is off.
/// </summary>
/// <param name="fileName"></param>
/// <param name="fileContent"></param>
public void SetImplementation(string fileName, string fileContent)
{
}
/// <summary>
/// Return false.
/// </summary>
/// <remarks>
/// There will never be a JIT-ed implementation of Populate if hot reloading is off.
/// </remarks>
/// <param name="t">the static type of <paramref name="o" /></param>
/// <param name="o">an instance of <paramref name="t" /> or a subclass</param>
/// <returns>false</returns>
public bool Populate(Type t, object o)
{
return false;
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Utility;
@@ -7,41 +8,135 @@ namespace Robust.Client.ViewVariables.Editors
{
sealed class VVPropEditorEnum : VVPropEditor
{
private readonly Dictionary<int, int> _idToValue = new();
private readonly Dictionary<int, int> _valueToId = new();
private readonly Dictionary<int, Button> _buttons = new();
private int _invalidOptionId;
private int _value;
private bool _flagEnum;
protected override Control MakeUI(object? value)
{
DebugTools.Assert(value!.GetType().IsEnum);
var enumType = value.GetType();
var enumList = Enum.GetValues(enumType);
var enumNames = Enum.GetNames(enumType);
var underlyingType = Enum.GetUnderlyingType(enumType);
var convertedValue = Convert.ToInt32(value);
var hBoxContainer = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
};
var optionButton = new OptionButton();
bool hasValue = false;
hBoxContainer.AddChild(optionButton);
var hasValue = false;
var selectedId = 0;
var i = 0;
foreach (var val in enumList)
{
var label = val?.ToString();
if (label == null)
continue;
optionButton.AddItem(label, Convert.ToInt32(val));
hasValue |= Convert.ToInt32(val) == Convert.ToInt32(value);
var label = enumNames[i];
var entry = Convert.ToInt32(val);
_idToValue.Add(i, entry);
_valueToId.TryAdd(entry, i);
optionButton.AddItem(label, i);
if (entry == convertedValue)
{
hasValue = true;
selectedId = i;
}
i += 1;
}
// TODO properly support enum flags
if (!hasValue)
optionButton.AddItem(value.ToString() ?? string.Empty, Convert.ToInt32(value));
var isFlags = enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0;
optionButton.SelectId(Convert.ToInt32(value));
// Handle unnamed enum values.
if (!hasValue || isFlags)
{
_invalidOptionId = i;
_idToValue.Add(_invalidOptionId, convertedValue);
optionButton.AddItem(string.Empty, _invalidOptionId);
if (!hasValue)
selectedId = _invalidOptionId;
}
optionButton.SelectId(selectedId);
optionButton.Disabled = ReadOnly;
// Flags
if (isFlags)
{
_flagEnum = true;
var flags = 0;
foreach (var val in enumList)
{
var entry = Convert.ToInt32(val);
if ((entry & flags) != 0 || entry == 0)
continue;
flags |= entry;
var button = new Button
{
Text = enumNames[_valueToId[entry]],
};
_buttons.Add(entry, button);
hBoxContainer.AddChild(button);
button.ToggleMode = true;
if (!ReadOnly)
{
button.OnToggled += args =>
{
if (args.Pressed)
SelectButtons(_value | entry);
else
SelectButtons(_value & ~entry);
};
}
}
}
if (!ReadOnly)
{
var underlyingType = Enum.GetUnderlyingType(value.GetType());
optionButton.OnItemSelected += e =>
{
optionButton.SelectId(e.Id);
ValueChanged(Convert.ChangeType(e.Id, underlyingType));
if (e.Id == _invalidOptionId)
{
optionButton.SelectId(_invalidOptionId);
return;
}
SelectButtons(_idToValue[e.Id]);
};
}
return optionButton;
SelectButtons(convertedValue, false);
return hBoxContainer;
void SelectButtons(int flags, bool changeValue = true)
{
_value = flags;
if (_flagEnum)
{
foreach (var (buttonFlags, button) in _buttons)
{
button.Pressed = (buttonFlags & flags) != 0;
}
}
if (!_valueToId.TryGetValue(flags, out var id)
|| !optionButton.TrySelectId(id))
optionButton.SelectId(_invalidOptionId);
if (changeValue)
ValueChanged(Convert.ChangeType(flags, underlyingType));
}
}
}
}

View File

@@ -77,7 +77,7 @@ namespace Robust.Client.ViewVariables.Editors
{
var protoMan = IoCManager.Resolve<IPrototypeManager>();
if (!protoMan.TryGetVariantFrom(typeof(T), out var variant)) return;
if (!protoMan.TryGetKindFrom(typeof(T), out var variant)) return;
var list = new List<string>();

View File

@@ -8,9 +8,16 @@ namespace Robust.Client.ViewVariables.Editors
{
internal sealed class VVPropEditorReference : VVPropEditor
{
[Dependency] private readonly IClientViewVariablesManager _vvMan = default!;
private object? _localValue;
private ViewVariablesObjectSelector? _selector;
public VVPropEditorReference()
{
IoCManager.InjectDependencies(this);
}
protected override Control MakeUI(object? value)
{
if (value == null)
@@ -36,14 +43,13 @@ namespace Robust.Client.ViewVariables.Editors
private void ButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
{
var vvm = IoCManager.Resolve<IClientViewVariablesManager>();
if (_selector != null)
{
vvm.OpenVV(_selector);
_vvMan.OpenVV(_selector);
}
else if (_localValue != null)
{
vvm.OpenVV(_localValue);
_vvMan.OpenVV(_localValue);
}
}

View File

@@ -32,6 +32,9 @@ public static class Diagnostics
public const string IdUncachedRegex = "RA0026";
public const string IdDataFieldRedundantTag = "RA0027";
public const string IdMustCallBase = "RA0028";
public const string IdDataFieldNoVVReadWrite = "RA0029";
public const string IdUseNonGenericVariant = "RA0030";
public const string IdPreferOtherType = "RA0031";
public static SuppressionDescriptor MeansImplicitAssignment =>
new SuppressionDescriptor("RADC1000", "CS0649", "Marked as implicitly assigned.");

View File

@@ -104,6 +104,7 @@ namespace Robust.Server
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly IReplayRecordingManagerInternal _replay = default!;
[Dependency] private readonly IGamePrototypeLoadManager _protoLoadMan = default!;
[Dependency] private readonly UploadedContentManager _uploadedContMan = default!;
[Dependency] private readonly NetworkResourceManager _netResMan = default!;
[Dependency] private readonly IReflectionManager _refMan = default!;
@@ -393,6 +394,7 @@ namespace Robust.Server
_scriptHost.Initialize();
_protoLoadMan.Initialize();
_netResMan.Initialize();
_uploadedContMan.Initialize();
// String serializer has to be locked before PostInit as content can depend on it (e.g., replays that start
// automatically recording on startup).

View File

@@ -1,12 +0,0 @@
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Player;
namespace Robust.Server.GameObjects
{
[RegisterComponent]
internal sealed partial class ViewSubscriberComponent : Component
{
internal readonly HashSet<ICommonSession> SubscribedSessions = new();
}
}

View File

@@ -3,6 +3,10 @@ using Robust.Shared.Serialization.Manager.Attributes;
namespace Robust.Server.GameObjects
{
/// <summary>
/// Controls PVS visibility of entities. THIS COMPONENT CONTROLS WHETHER ENTITIES ARE NETWORKED TO PLAYERS
/// AND SHOULD NOT BE USED AS THE SOLE WAY TO HIDE AN ENTITY FROM A PLAYER.
/// </summary>
[RegisterComponent]
[Access(typeof(VisibilitySystem))]
public sealed partial class VisibilityComponent : Component

View File

@@ -155,7 +155,7 @@ public sealed class MapLoaderSystem : EntitySystem
result = Deserialize(data);
_logLoader.Debug($"Loaded map in {sw.Elapsed}");
var mapEnt = _mapManager.GetMapEntityId(mapId);
var mapEnt = _mapSystem.GetMapOrInvalid(mapId);
var xformQuery = _serverEntityManager.GetEntityQuery<TransformComponent>();
var rootEnts = new List<EntityUid>();
// aeoeoeieioe content
@@ -217,13 +217,13 @@ public sealed class MapLoaderSystem : EntitySystem
public void SaveMap(MapId mapId, string ymlPath)
{
if (!_mapManager.MapExists(mapId))
if (!_mapSystem.TryGetMap(mapId, out var mapUid))
{
_logLoader.Error($"Unable to find map {mapId}");
return;
}
Save(_mapManager.GetMapEntityId(mapId), ymlPath);
Save(mapUid.Value, ymlPath);
}
#endregion
@@ -422,7 +422,7 @@ public sealed class MapLoaderSystem : EntitySystem
private HashSet<EntityUid> AllocEntities(MapData data, BeforeEntityReadEvent ev)
{
_stopwatch.Restart();
var mapUid = _mapManager.GetMapEntityId(data.TargetMap);
var mapUid = _mapSystem.GetMapOrInvalid(data.TargetMap);
var pauseTime = mapUid.IsValid() ? _meta.GetPauseTime(mapUid) : TimeSpan.Zero;
_context.Set(data.UidEntityMap, new Dictionary<EntityUid, int>(), data.MapIsPostInit, pauseTime, null);
HashSet<EntityUid> deletedPrototypeUids = new();

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