Skip to content
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

Move parts of SpriteComponent to SpriteSystem #5602

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
428173d
Partial sprite component ECS
ElectroJr Jan 12, 2025
1d117ca
release notes
ElectroJr Jan 12, 2025
86dfefa
Merge branch 'master' of https://github.com/space-wizards/RobustToolb…
ElectroJr Jan 13, 2025
47940dc
tests
ElectroJr Jan 13, 2025
1eef1aa
Why
ElectroJr Jan 13, 2025
1b61680
SetSnapCardinals
ElectroJr Jan 13, 2025
62c7f5f
NoRotation
ElectroJr Jan 13, 2025
81b0145
DirectionOverride
ElectroJr Jan 13, 2025
e7f3970
This is why I love distinct overrides that take in object
ElectroJr Jan 13, 2025
8cb2283
LayerSetData
ElectroJr Jan 13, 2025
33d3b7e
ISerializationHooks continue to haunt me
ElectroJr Jan 13, 2025
3b31b49
Relocate SetShader
ElectroJr Jan 13, 2025
d14931c
LayerSetSprite
ElectroJr Jan 13, 2025
1484d43
LayerSetTexture
ElectroJr Jan 13, 2025
7212a20
yipeeeee
ElectroJr Jan 13, 2025
ba54d92
LayerSetRsi
ElectroJr Jan 13, 2025
5111655
Remove GetFallbackState
ElectroJr Jan 13, 2025
2c8a421
LayerSet Scale,Rotation,Color,Visible
ElectroJr Jan 13, 2025
5b39b2d
Fix LayerSetRsi
ElectroJr Jan 13, 2025
e34ae6c
LayerSetOffset
ElectroJr Jan 13, 2025
3209113
LayerSetDirOffset
ElectroJr Jan 13, 2025
4059cfa
Add overrides that take in a Layer
ElectroJr Jan 13, 2025
35d1798
LayerSetAnimationTime
ElectroJr Jan 13, 2025
299ae1c
LayerSetRenderingStrategy
ElectroJr Jan 13, 2025
2eb303c
Reduce Resolves, Add Layer.Index
ElectroJr Jan 13, 2025
5bc336b
Access
ElectroJr Jan 13, 2025
c3ec771
Try fix NREs
ElectroJr Jan 13, 2025
954c3bb
Asserts
ElectroJr Jan 13, 2025
5955933
LayerGetState
ElectroJr Jan 14, 2025
d717172
Cleanup
ElectroJr Jan 14, 2025
4a2b3ee
Merge helper partial classes
ElectroJr Jan 14, 2025
517b262
partial rendering
ElectroJr Jan 14, 2025
9681e08
GetLayerDirectionCount
ElectroJr Jan 14, 2025
09aa985
Cache local bounds
ElectroJr Jan 14, 2025
0a2753f
RenderLayer
ElectroJr Jan 14, 2025
6a2b369
RefreshCachedState
ElectroJr Jan 14, 2025
d268a1c
RoundToCardinalAngle
ElectroJr Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
RoundToCardinalAngle
  • Loading branch information
ElectroJr committed Jan 14, 2025
commit d268a1c4fd9310784f3f3515928c25333b06a9f7
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ public bool SnapCardinals
[DataField("noRot")]
public bool NoRotation;

// TODO SPRITE
// When refactoring, make this nullable and remove EnableDirectionOverride
[DataField("overrideDir")]
public Direction DirectionOverride = Direction.East;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void RenderSprite(

// If we have a 1-directional sprite then snap it to try and always face it south if applicable.
if (sprite.Comp is {NoRotation: false, SnapCardinals: true})
cardinal = angle.GetCardinalDir().ToAngle();
cardinal = angle.RoundToCardinalAngle();

// worldRotation + eyeRotation should be the angle of the entity on-screen. If no-rot is enabled this is just set to zero.
// However, at some point later the eye-matrix is applied separately, so we subtract -eye rotation for now:
Expand All @@ -70,14 +70,12 @@ public void RenderSprite(
return;
}

// TODO sprite optimize angle.GetCardinalDir().ToAngle()

//Default rendering (NoRotation = false)
entityMatrix = Matrix3Helpers.CreateTransform(worldPosition, worldRotation);
var transformDefault = Matrix3x2.Multiply(sprite.Comp.LocalMatrix, entityMatrix);

//Snap to cardinals
entityMatrix = Matrix3Helpers.CreateTransform(worldPosition, worldRotation - angle.GetCardinalDir().ToAngle());
entityMatrix = Matrix3Helpers.CreateTransform(worldPosition, worldRotation - angle.RoundToCardinalAngle());
var transformSnap = Matrix3x2.Multiply(sprite.Comp.LocalMatrix, entityMatrix);

//No rotation
Expand Down
10 changes: 10 additions & 0 deletions Robust.Shared.Maths/Angle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ public readonly Direction GetCardinalDir()
return (Direction) (Math.Floor((ang + CardinalOffset) / CardinalSegment) * 2 % 8);
}

/// <summary>
/// Rounds the angle to the nearest cardinal direction. This behaves similarly to a combination of
/// <see cref="GetCardinalDir"/> and Direction.ToAngle(), however this may return an angle outside of the range
/// returned by those methods (-pi to pi).
/// </summary>
public Angle RoundToCardinalAngle()
{
return new Angle(CardinalSegment * Math.Floor((Theta + CardinalOffset) / CardinalSegment));
}

/// <summary>
/// Rotates the vector counter-clockwise around its origin by the value of Theta.
/// </summary>
Expand Down
Loading