-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
antitryaska #7
Merged
RedFoxIV
merged 3 commits into
master
from
sidestream-this-branch-is-not-a-branch-of-honor
Feb 16, 2025
Merged
antitryaska #7
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
Content.Client/_White/AntiParkinsons/AntiParkinsonsRevertSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Content.Shared._White; | ||
using Content.Shared.CCVar; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Configuration; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Player; | ||
using Robust.Shared.Reflection; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Numerics; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Content.Client._White.AntiParkinsons; | ||
|
||
// The following code is slightly esoteric and higly schizophrenic. You have been warned. | ||
|
||
#pragma warning disable RA0002 | ||
|
||
public sealed class AntiParkinsonsRevertSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IReflectionManager _refl = default!; | ||
[Dependency] private readonly IEyeManager _eye = default!; | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
|
||
|
||
public override void Initialize() | ||
{ | ||
UpdatesOutsidePrediction = true; | ||
|
||
// dnas tae | ||
foreach (Type sys in _refl.GetAllChildren<EntitySystem>()) | ||
{ | ||
if (sys.IsAbstract || sys == typeof(AntiParkinsonsRevertSystem)) | ||
continue; | ||
|
||
UpdatesBefore.Add(sys); | ||
} | ||
} | ||
|
||
// dnas tae | ||
public override void FrameUpdate(float frameTime) | ||
{ | ||
var query = AllEntityQuery<PixelSnapEyeComponent>(); | ||
|
||
while (query.MoveNext(out var uid, out var ppComp)) | ||
{ | ||
if (!TryComp<EyeComponent>(uid, out var eyeComp) || eyeComp.Eye == null) | ||
continue; | ||
|
||
eyeComp.Eye.Position = PPCamHelper.CheckForChange(eyeComp.Eye.Position, ppComp.EyePositionModified, ppComp.EyePosition); | ||
eyeComp.Eye.Offset = PPCamHelper.CheckForChange(eyeComp.Eye.Offset, ppComp.EyeOffsetModified, ppComp.EyeOffset); | ||
eyeComp.Offset = eyeComp.Eye.Offset; | ||
|
||
if(TryComp<SpriteComponent>(uid, out var sprite)) | ||
sprite.Offset = PPCamHelper.CheckForChange(sprite.Offset, ppComp.SpriteOffsetModified, ppComp.SpriteOffset); | ||
} | ||
} | ||
} | ||
|
||
#pragma warning restore RA0002 |
163 changes: 163 additions & 0 deletions
163
Content.Client/_White/AntiParkinsons/AntiParkinsonsSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
using Content.Shared._White; | ||
using Content.Shared.CCVar; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Configuration; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Player; | ||
using Robust.Shared.Reflection; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Numerics; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Content.Client._White.AntiParkinsons; | ||
|
||
// The following code is slightly esoteric and higly schizophrenic. You have been warned. | ||
|
||
#pragma warning disable RA0002 | ||
|
||
public sealed class AntiParkinsonsSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IReflectionManager _refl = default!; | ||
[Dependency] private readonly IEyeManager _eye = default!; | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
[Dependency] private readonly IConfigurationManager _cfg = default!; | ||
[Dependency] private readonly SharedTransformSystem _transform = default!; | ||
|
||
|
||
private bool _enabled = false; | ||
|
||
public override void Initialize() | ||
{ | ||
UpdatesOutsidePrediction = true; | ||
_cfg.OnValueChanged(WhiteCVars.PixelSnapCamera, OnEnabledDisabled, true); | ||
// eat sand | ||
foreach(Type sys in _refl.GetAllChildren<EntitySystem>()) | ||
{ | ||
if (sys.IsAbstract || sys == typeof(AntiParkinsonsSystem)) | ||
continue; | ||
|
||
UpdatesAfter.Add(sys); | ||
} | ||
|
||
SubscribeLocalEvent<LocalPlayerAttachedEvent>(OnAttached); | ||
SubscribeLocalEvent<PixelSnapEyeComponent, LocalPlayerDetachedEvent>(OnDetached); | ||
} | ||
|
||
private void OnEnabledDisabled(bool val) | ||
{ | ||
_enabled = val; | ||
if (_enabled) | ||
{ | ||
if (_player.LocalEntity is not EntityUid player) | ||
return; | ||
|
||
var ppComp = EnsureComp<PixelSnapEyeComponent>(player); | ||
if (TryComp<EyeComponent>(player, out var eyeComp) && eyeComp.Eye != null) | ||
{ | ||
ppComp.EyePosition = eyeComp.Eye.Position; | ||
ppComp.EyePositionModified = eyeComp.Eye.Position; | ||
ppComp.EyeOffset = eyeComp.Eye.Offset; | ||
ppComp.EyeOffsetModified = eyeComp.Eye.Offset; | ||
} | ||
if (TryComp<SpriteComponent>(player, out var sprite)) | ||
ppComp.SpriteOffset = sprite.Offset; | ||
|
||
} | ||
else | ||
{ | ||
if (_player.LocalEntity is not EntityUid player || !TryComp<PixelSnapEyeComponent>(player, out var ppComp)) | ||
return; | ||
|
||
if (TryComp<EyeComponent>(player, out var eyeComp) && eyeComp.Eye != null) | ||
{ | ||
eyeComp.Eye.Position = ppComp.EyePosition; | ||
eyeComp.Eye.Offset = ppComp.EyeOffset; | ||
eyeComp.Offset = ppComp.EyeOffset; | ||
} | ||
|
||
if (TryComp<SpriteComponent>(player, out var sprite) && ppComp.SpriteOffset is System.Numerics.Vector2 orig) | ||
sprite.Offset = orig; | ||
|
||
RemComp<PixelSnapEyeComponent>(player); | ||
} | ||
} | ||
|
||
private void OnAttached(LocalPlayerAttachedEvent args) | ||
{ | ||
if (!_enabled) | ||
return; | ||
|
||
EnsureComp<PixelSnapEyeComponent>(args.Entity); | ||
} | ||
|
||
private void OnDetached(EntityUid uid, PixelSnapEyeComponent comp, LocalPlayerDetachedEvent args) | ||
{ | ||
if (!_enabled) | ||
return; | ||
|
||
if (TryComp<EyeComponent>(uid, out var eyeComp) && eyeComp.Eye != null) | ||
{ | ||
eyeComp.Eye.Position = comp.EyePosition; | ||
eyeComp.Eye.Offset = comp.EyeOffset; | ||
eyeComp.Offset = comp.EyeOffset; | ||
} | ||
|
||
if (TryComp<SpriteComponent>(uid, out var sprite) && comp.SpriteOffset is System.Numerics.Vector2 orig) | ||
sprite.Offset = orig; | ||
|
||
RemComp<PixelSnapEyeComponent>(uid); | ||
} | ||
|
||
public override void FrameUpdate(float frameTime) | ||
{ | ||
var query = AllEntityQuery<PixelSnapEyeComponent>(); | ||
|
||
while (query.MoveNext(out var uid, out var ppComp)) | ||
{ | ||
if (!TryComp<EyeComponent>(uid, out var eyeComp) || eyeComp.Eye == null) | ||
continue; | ||
|
||
if (!TryComp<TransformComponent>(eyeComp.Target, out var xform)) | ||
xform = Transform(uid); | ||
|
||
if (xform.GridUid.HasValue && xform.GridUid.Value.IsValid()) | ||
ppComp.LastParent = xform.GridUid.Value; | ||
else | ||
if (!ppComp.LastParent.IsValid()) | ||
ppComp.LastParent = xform.ParentUid; // fallback to whatever parent we have (in this case this will probably end up being the map) | ||
|
||
var vec = xform.LocalPosition; | ||
var offset = Vector2.Zero; | ||
|
||
ppComp.EyePosition = eyeComp.Eye.Position; | ||
ppComp.EyeOffset = eyeComp.Eye.Offset; | ||
|
||
var eyePos = PPCamHelper.WorldPosPixelRoundToParent(eyeComp.Eye.Position.Position, ppComp.LastParent, _transform); | ||
var eyeOffset = PPCamHelper.WorldPosPixelRoundToParent(eyeComp.Eye.Offset, ppComp.LastParent, _transform); | ||
//var eyePosDiff = eyePos - eyeComp.Eye.Position.Position; | ||
|
||
eyeComp.Eye.Position = new(eyePos, xform.MapID); | ||
eyeComp.Eye.Offset = eyeOffset; | ||
eyeComp.Offset = eyeOffset; | ||
|
||
ppComp.EyePositionModified = eyeComp.Eye.Position; | ||
ppComp.EyeOffsetModified = eyeComp.Eye.Offset; | ||
|
||
if (!TryComp<SpriteComponent>(uid, out var sprite)) | ||
continue; | ||
|
||
ppComp.SpriteOffset = sprite.Offset; | ||
|
||
var (_, diff) = PPCamHelper.WorldPosPixelRoundToParentWithDiff(xform.WorldPosition, ppComp.LastParent, _transform); | ||
sprite.Offset += diff; | ||
ppComp.SpriteOffsetModified = sprite.Offset; | ||
} | ||
} | ||
} | ||
|
||
#pragma warning restore RA0002 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Content.Shared._White; | ||
using Content.Shared.CCVar; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Configuration; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Player; | ||
using Robust.Shared.Reflection; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Numerics; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Content.Client._White.AntiParkinsons; | ||
|
||
public static class PPCamHelper | ||
{ | ||
private static int roundFactor => EyeManager.PixelsPerMeter; | ||
|
||
public static Vector2 RoundXY(Vector2 vec) => new Vector2(MathF.Round(vec.X * roundFactor) / roundFactor, MathF.Round(vec.Y * roundFactor) / roundFactor); | ||
|
||
/// <summary> | ||
/// Translates world vector into local (to parent) vector, rounds it to a 1 over <see cref="EyeManager.PixelsPerMeter"/> and translates back to world space. | ||
/// </summary> | ||
/// <param name="worldPos"></param> | ||
/// <param name="parentXform"></param> | ||
/// <returns></returns> | ||
public static Vector2 WorldPosPixelRoundToParent(Vector2 worldPos, EntityUid parent, SharedTransformSystem xformSystem) | ||
{ | ||
var (_, _, mat, invmat) = xformSystem.GetWorldPositionRotationMatrixWithInv(parent); | ||
Vector2 localSpacePos = Vector2.Transform(worldPos, invmat); | ||
localSpacePos = RoundXY(localSpacePos); | ||
Vector2 worldRoundedPos = Vector2.Transform(localSpacePos, mat); | ||
return worldRoundedPos; | ||
} | ||
|
||
public static (Vector2 roundedWorldPos, Vector2 LocalSpaceDiff) WorldPosPixelRoundToParentWithDiff(Vector2 worldPos, EntityUid parent, SharedTransformSystem xformSystem) | ||
{ | ||
var (_, _, mat, invmat) = xformSystem.GetWorldPositionRotationMatrixWithInv(parent); | ||
Vector2 localSpacePos = Vector2.Transform(worldPos, invmat); | ||
var roundedLocalSpacePos = RoundXY(localSpacePos); | ||
Vector2 worldRoundedPos = Vector2.Transform(localSpacePos, mat); | ||
return (worldRoundedPos, roundedLocalSpacePos - localSpacePos); | ||
} | ||
|
||
public static T CheckForChange<T>(T currentValue, T modifiedValue, T originalValue) where T : IEquatable<T> | ||
{ | ||
// if this is false, this means that the value tracked was changed outside | ||
// of the engine's FrameUpdate loop, and this change should be preserved. | ||
if (currentValue.Equals(modifiedValue)) | ||
return originalValue; | ||
return currentValue; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Content.Client/_White/AntiParkinsons/PixelSnapEyeComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Content.Shared._White; | ||
using Content.Shared.CCVar; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Configuration; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Player; | ||
using Robust.Shared.Reflection; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Numerics; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Content.Client._White.AntiParkinsons; | ||
|
||
[RegisterComponent] | ||
[UnsavedComponent] | ||
public sealed partial class PixelSnapEyeComponent : Component | ||
{ | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
public EntityUid LastParent; | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
public System.Numerics.Vector2 SpriteOffset, SpriteOffsetModified; | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
public MapCoordinates EyePosition, EyePositionModified; | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
public System.Numerics.Vector2 EyeOffset, EyeOffsetModified; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
АААА?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
уээээ