-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* zzre: Refactor HoverOffset out of HoverBehind component * zzre: Add KeepLastHover system * ease debugging * Fix NPCLookAtPlayer for fairy npcs * Fix fairy npc selection * Fix marker position for flying npcs * Fix dialog face and name for flying npcs
- Loading branch information
Showing
12 changed files
with
178 additions
and
55 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace zzre.game.systems; | ||
using System; | ||
using System.Numerics; | ||
using DefaultEcs.System; | ||
|
||
public partial class FairyHoverOffset : AEntitySetSystem<float> | ||
{ | ||
private readonly Random random = Random.Shared; | ||
private readonly GameTime time; | ||
|
||
public FairyHoverOffset(ITagContainer diContainer) : base(diContainer.GetTag<DefaultEcs.World>(), CreateEntityContainer, useBuffer: false) | ||
{ | ||
time = diContainer.GetTag<GameTime>(); | ||
} | ||
|
||
[WithPredicate] | ||
private bool IsInRelevantStates(in components.FairyHoverState state) => state == components.FairyHoverState.Behind; | ||
|
||
[Update] | ||
private void Update(float elapsedTime, ref components.FairyHoverOffset component) | ||
{ | ||
var offset = component.Value; | ||
if (offset == Vector3.Zero) | ||
{ | ||
offset = new( | ||
random.InLine() * 10f, | ||
0f, | ||
random.InLine() * 10f); | ||
} | ||
|
||
float sinDelta = MathF.Sin(elapsedTime), cosDelta = MathF.Cos(elapsedTime); | ||
var oldOffsetX = offset.X; | ||
offset.X = cosDelta * oldOffsetX - sinDelta * offset.Z; | ||
offset.Y = 0.01f; | ||
offset.Z = sinDelta * oldOffsetX + cosDelta * offset.Z; | ||
offset = Vector3.Normalize(offset) * elapsedTime * 0.4f; // yes, there is basically no non-vertical movement | ||
offset.Y = MathF.Cos(time.TotalElapsed / 100f) * (elapsedTime * 0.3f); // TODO: Fix framerate-dependent vertical fairy hovering | ||
// ^ this is framerate-dependent as an absolute value depends on a single frame delta | ||
|
||
component = new(offset); | ||
} | ||
} |
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,59 @@ | ||
namespace zzre.game.systems; | ||
using System; | ||
using System.Numerics; | ||
using DefaultEcs.System; | ||
|
||
public partial class FairyKeepLastHover : AEntitySetSystem<float> | ||
{ | ||
private const float HoverDistance = -0.7f; | ||
private const float HoverRadius = 0.2f; | ||
private const float BounceMagnitude = 0.05f; | ||
private readonly GameTime time; | ||
|
||
public FairyKeepLastHover(ITagContainer diContainer) | ||
: base(diContainer.GetTag<DefaultEcs.World>(), CreateEntityContainer, useBuffer: false) | ||
{ | ||
time = diContainer.GetTag<GameTime>(); | ||
Set.EntityAdded += HandleAdded; | ||
} | ||
|
||
private void HandleAdded(in DefaultEcs.Entity entity) | ||
{ | ||
var location = entity.Get<Location>(); | ||
entity.Set(new components.Velocity(new(0f, 0.01f, 0f))); | ||
entity.Set(new components.FairyHoverStart(location.LocalPosition)); | ||
// ^ this is not modifying the set as fairies should already have this component | ||
} | ||
|
||
[WithPredicate] | ||
private bool IsInState(in components.FairyHoverState state) => state == components.FairyHoverState.KeepLastHover; | ||
|
||
[Update] | ||
private void Update( | ||
float elapsedTime, | ||
in components.Parent parent, | ||
in components.FairyHoverStart hoverStart, | ||
ref components.FairyHoverOffset hoverOffset, | ||
Location location) | ||
{ | ||
// similar but not equal to the FairyHoverOffset update | ||
float sinDelta = MathF.Sin(elapsedTime), cosDelta = MathF.Cos(elapsedTime); | ||
var offset = hoverOffset.Value; | ||
var oldOffsetX = offset.X; | ||
offset.X = cosDelta * oldOffsetX - sinDelta * offset.Z; | ||
offset.Y = 0f; | ||
offset.Z = cosDelta * offset.Z + sinDelta * oldOffsetX; | ||
if (MathEx.CmpZero(offset.X)) | ||
offset.X = 0.1f; | ||
if (MathEx.CmpZero(offset.Z)) | ||
offset.Z = 0.1f; | ||
offset = Vector3.Normalize(offset) * HoverRadius; | ||
offset.Y = MathF.Cos(time.TotalElapsed) * BounceMagnitude; | ||
location.LocalPosition = hoverStart.Value + offset; | ||
hoverOffset = new(offset); | ||
|
||
var parentDirection = parent.Entity.Get<Location>().InnerForward; | ||
location.LookIn(parentDirection with { Y = 0f }); | ||
location.LocalPosition += location.InnerForward * HoverDistance; | ||
} | ||
} |
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
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.