Skip to content

Commit

Permalink
zzre: Fix some parts of MovingPlanes
Browse files Browse the repository at this point in the history
  • Loading branch information
Helco committed Mar 23, 2024
1 parent fb8da51 commit 7cd37e1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
24 changes: 10 additions & 14 deletions zzre/game/systems/effect/MovingPlanes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ protected override void HandleAddedComponent(in DefaultEcs.Entity entity, in zzi
{
var playback = entity.Get<components.Parent>().Entity.Get<components.effect.CombinerPlayback>();
var vertexRange = effectMesh.RentVertices(data.disableSecondPlane ? 4 : 8);
var indexRange = effectMesh.RentQuadIndices(vertexRange);
var isBillboard = !data.circlesAround && !data.useDirection;
var indexRange = effectMesh.RentQuadIndices(vertexRange, doubleSided: !isBillboard);
entity.Set(new components.effect.MovingPlanesState(
vertexRange,
indexRange,
Expand All @@ -30,13 +31,10 @@ protected override void HandleAddedComponent(in DefaultEcs.Entity entity, in zzi
PrevProgress = playback.CurProgress
});
Reset(ref entity.Get<components.effect.MovingPlanesState>(), data);

var billboardMode = data.circlesAround || data.useDirection
? EffectMaterial.BillboardMode.None
: EffectMaterial.BillboardMode.View;

assetRegistry.LoadEffectMaterial(entity,
data.texName,
billboardMode,
isBillboard ? EffectMaterial.BillboardMode.View : EffectMaterial.BillboardMode.None,
data.renderMode,
playback.DepthTest);
entity.Set(new components.effect.RenderIndices(indexRange));
Expand Down Expand Up @@ -114,9 +112,8 @@ private static void AddScale(
float amount)
{
var shouldGrow = data.targetSize > data.width;
var curSize = new Vector2(data.width, data.height) * state.CurScale;
if ((shouldGrow && curSize.MaxComponent() < data.targetSize) ||
(!shouldGrow && curSize.MinComponent() > data.targetSize))
if ((shouldGrow && state.CurScale < data.targetSize) ||
(!shouldGrow && state.CurScale > data.targetSize))
state.CurScale += amount;
}

Expand Down Expand Up @@ -161,18 +158,17 @@ private void UpdateQuad(
else if (data.useDirection)
{
// what even is this rotation, only used in e5021...
var dir = location.GlobalForward;
var dir = location.InnerForward;
var rotUp = Vector3.Cross(dir, Vector3.One * 0.42340001f);
var rotRight = Vector3.Cross(dir, rotUp);
var rotForward = Vector3.Cross(rotUp, rotRight);
var rotMatrix = new Matrix4x4(
var rotMatrix = Matrix4x4.CreateFromAxisAngle(Vector3.UnitZ, angle) * new Matrix4x4(
rotRight.X, rotRight.Y, rotRight.Z, 0f,
rotUp.X, rotUp.Y, rotUp.Z, 0f,
rotForward.X, rotForward.Y, rotForward.Z, 0f,
0f, 0f, 0f, 1f);
rotMatrix = Matrix4x4.Transform(rotMatrix, Quaternion.CreateFromAxisAngle(Vector3.UnitZ, angle));
right = Vector3.Transform(Vector3.UnitX * w, rotMatrix);
up = Vector3.Transform(Vector3.UnitY * h, rotMatrix);
right = Vector3.TransformNormal(Vector3.UnitX * w, rotMatrix);
up = Vector3.TransformNormal(Vector3.UnitY * h, rotMatrix);
}
else
{
Expand Down
9 changes: 6 additions & 3 deletions zzre/materials/EffectMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ public Range RentPatternIndices(Range vertexRange, IReadOnlyList<ushort> pattern
return indexRange;
}

private static readonly ushort[] QuadIndexPattern = [0, 2, 1, 0, 3, 2];
public Range RentQuadIndices(Range vertexRange) =>
RentPatternIndices(vertexRange, QuadIndexPattern);
private static readonly ushort[] SingleSidedQuadIndexPattern = [0, 2, 1, 0, 3, 2];
private static readonly ushort[] DoubleSidedQuadIndexPattern = [0, 2, 1, 0, 3, 2, 0, 1, 2, 0, 2, 3];
public Range RentQuadIndices(Range vertexRange, bool doubleSided = false) =>
RentPatternIndices(vertexRange, doubleSided
? DoubleSidedQuadIndexPattern
: SingleSidedQuadIndexPattern);

public void SetQuad(Range vertexRange, int offset, bool applyCenter, Vector3 center, Vector3 right, Vector3 up, IColor color, Rect texCoords)
{
Expand Down
7 changes: 2 additions & 5 deletions zzre/tools/ECSExplorer/ECSExplorer.Standard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
using zzio;
using zzio.db;
using zzio.scn;
using DefaultEcs.Resource;

using EffectCombinerResource = DefaultEcs.Resource.ManagedResource<string, zzio.effect.EffectCombiner>;
using zzre.game.components.effect;

namespace zzre.tools;
Expand Down Expand Up @@ -40,7 +38,7 @@ private static void AddStandardEntityNaming()
AddEntityNamerByComponent<CollectionFairy>(Highest, e => $"CollectionFairy \"{e.Get<InventoryFairy>().name}\" {e}");

AddEntityNamerByComponent<LensFlare>(Highest, e => $"LensFlare {e}");
AddEntityNamerByComponent<EffectCombinerResource>(Highest, (e, c) => $"EffectCombiner {c.Info} {e}");
AddEntityNamerByComponent<zzio.effect.EffectCombiner>(Highest, (e, c) => $"EffectCombiner {c.description} {e}");
AddEntityNamerByComponent<zzio.effect.parts.BeamStar>(Highest, (e, c) => $"BeamStar {c.Name} {e}");
AddEntityNamerByComponent<zzio.effect.parts.ElectricBolt>(Highest, (e, c) => $"ElectricBolt {c.Name} {e}");
AddEntityNamerByComponent<zzio.effect.parts.Models>(Highest, (e, c) => $"Models {c.Name} {e}");
Expand All @@ -67,7 +65,6 @@ private static void AddStandardEntityNaming()

AddEntityNamer(High, e => e.Has<Rect>() || !e.TryGet<TileSheet>(out var res) ? null
: $"Preload {(res.IsFont ? "font" : "tilesheet")} {res.Name}");
AddEntityNamer(Def, e => e.Has<Rect>() || !e.TryGet<ManagedResource<string, UIMaterial>>(out var res) ? null : $"Preload bitmap {res.Info}");
AddEntityNamerByComponent<ButtonTiles>(High, e => $"Button #{e.TryGet<ElementId>().GetValueOrDefault(default).Value} {e}");
AddEntityNamerByComponent<TooltipTarget>(High, e => $"Tooltip Target {e}");
AddEntityNamerByComponent<Fade>(High, e => $"Fade {e}");
Expand Down Expand Up @@ -101,7 +98,7 @@ private static void AddStandardEntityGrouping()
AddEntityGrouperByComponent<CirclingBird>(1000, Animals);
AddEntityGrouperByComponent<AnimalWaypointAI>(1000, Animals);
AddEntityGrouperByComponent<CollectionFairy>(1000, Animals);
AddEntityGrouperByComponent<EffectCombinerResource>(1000, Effects);
AddEntityGrouperByComponent<zzio.effect.EffectCombiner>(1000, Effects);
AddEntityGrouperByComponent<LensFlare>(1000, Effects);
AddEntityGrouperByComponent<ClumpMesh>(0, Models);
AddEntityGrouperByComponent<Trigger>(-1, Triggers);
Expand Down

0 comments on commit 7cd37e1

Please sign in to comment.