Snap to nearest cardinal on traversal (#10869)
This commit is contained in:
@@ -11,7 +11,6 @@ namespace Content.Client.Decals
|
||||
public sealed class DecalOverlay : Overlay
|
||||
{
|
||||
private readonly DecalSystem _decals;
|
||||
private readonly SharedTransformSystem _transform;
|
||||
private readonly SpriteSystem _sprites;
|
||||
private readonly IEntityManager _entManager;
|
||||
private readonly IPrototypeManager _prototypeManager;
|
||||
@@ -22,13 +21,11 @@ namespace Content.Client.Decals
|
||||
|
||||
public DecalOverlay(
|
||||
DecalSystem decals,
|
||||
SharedTransformSystem transforms,
|
||||
SpriteSystem sprites,
|
||||
IEntityManager entManager,
|
||||
IPrototypeManager prototypeManager)
|
||||
{
|
||||
_decals = decals;
|
||||
_transform = transforms;
|
||||
_sprites = sprites;
|
||||
_entManager = entManager;
|
||||
_prototypeManager = prototypeManager;
|
||||
@@ -39,10 +36,12 @@ namespace Content.Client.Decals
|
||||
// Shouldn't need to clear cached textures unless the prototypes get reloaded.
|
||||
var handle = args.WorldHandle;
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
var eyeAngle = args.Viewport.Eye?.Rotation ?? Angle.Zero;
|
||||
|
||||
foreach (var (gridId, zIndexDictionary) in _decals.DecalRenderIndex)
|
||||
{
|
||||
if (zIndexDictionary.Count == 0) continue;
|
||||
if (zIndexDictionary.Count == 0)
|
||||
continue;
|
||||
|
||||
if (!xformQuery.TryGetComponent(gridId, out var xform))
|
||||
{
|
||||
@@ -53,7 +52,9 @@ namespace Content.Client.Decals
|
||||
if (xform.MapID != args.MapId)
|
||||
continue;
|
||||
|
||||
handle.SetTransform(_transform.GetWorldMatrix(xform, xformQuery));
|
||||
var (_, worldRot, worldMatrix) = xform.GetWorldPositionRotationMatrix(xformQuery);
|
||||
|
||||
handle.SetTransform(worldMatrix);
|
||||
|
||||
foreach (var (_, decals) in zIndexDictionary)
|
||||
{
|
||||
@@ -66,10 +67,23 @@ namespace Content.Client.Decals
|
||||
_cachedTextures[decal.Id] = texture;
|
||||
}
|
||||
|
||||
if (decal.Angle.Equals(Angle.Zero))
|
||||
if (!_prototypeManager.TryIndex<DecalPrototype>(decal.Id, out var decalProto))
|
||||
continue;
|
||||
|
||||
var cardinal = Angle.Zero;
|
||||
|
||||
if (decalProto.SnapCardinals)
|
||||
{
|
||||
var worldAngle = eyeAngle + worldRot;
|
||||
cardinal = worldAngle.GetCardinalDir().ToAngle();
|
||||
}
|
||||
|
||||
var angle = decal.Angle - cardinal;
|
||||
|
||||
if (angle.Equals(Angle.Zero))
|
||||
handle.DrawTexture(texture, decal.Coordinates, decal.Color);
|
||||
else
|
||||
handle.DrawTexture(texture, decal.Coordinates, decal.Angle, decal.Color);
|
||||
handle.DrawTexture(texture, decal.Coordinates, angle, decal.Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,11 +95,9 @@ namespace Content.Client.Decals
|
||||
{
|
||||
if (_prototypeManager.TryIndex<DecalPrototype>(id, out var proto))
|
||||
return proto.Sprite;
|
||||
else
|
||||
{
|
||||
Logger.Error($"Unknown decal prototype: {id}");
|
||||
return new SpriteSpecifier.Texture(new ResourcePath("/Textures/noSprite.png"));
|
||||
}
|
||||
|
||||
Logger.Error($"Unknown decal prototype: {id}");
|
||||
return new SpriteSpecifier.Texture(new ResourcePath("/Textures/noSprite.png"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,18 +8,17 @@ namespace Content.Client.Decals
|
||||
public sealed class DecalSystem : SharedDecalSystem
|
||||
{
|
||||
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transforms = default!;
|
||||
[Dependency] private readonly SpriteSystem _sprites = default!;
|
||||
|
||||
private DecalOverlay _overlay = default!;
|
||||
public Dictionary<EntityUid, SortedDictionary<int, SortedDictionary<uint, Decal>>> DecalRenderIndex = new();
|
||||
private Dictionary<EntityUid, Dictionary<uint, int>> _decalZIndexIndex = new();
|
||||
public readonly Dictionary<EntityUid, SortedDictionary<int, SortedDictionary<uint, Decal>>> DecalRenderIndex = new();
|
||||
private readonly Dictionary<EntityUid, Dictionary<uint, int>> _decalZIndexIndex = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_overlay = new DecalOverlay(this, _transforms, _sprites, EntityManager, PrototypeManager);
|
||||
_overlay = new DecalOverlay(this, _sprites, EntityManager, PrototypeManager);
|
||||
_overlayManager.AddOverlay(_overlay);
|
||||
|
||||
SubscribeNetworkEvent<DecalChunkUpdateEvent>(OnChunkUpdate);
|
||||
@@ -108,7 +107,7 @@ namespace Content.Client.Decals
|
||||
chunkCollection[indices] = newChunkData;
|
||||
|
||||
foreach (var (uid, decal) in newChunkData)
|
||||
{
|
||||
{
|
||||
if (zIndexIndex.TryGetValue(uid, out var zIndex))
|
||||
renderIndex[zIndex].Remove(uid);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user