0.2.0-dev Download ZIP
44 lines ·1.4 KB Raw
| 1 | using Godot; |
| 2 | |
| 3 | namespace EvilEngine.Shared.World; |
| 4 | |
| 5 | public sealed partial class WorldFrames : Node |
| 6 | { |
| 7 | private int[]? _shown; |
| 8 | private double _time; |
| 9 | |
| 10 | public IReadOnlyList<DrivenFrame> Frames { get; init; } = []; |
| 11 | |
| 12 | public IReadOnlyList<DrivenScroll> Scrolls { get; init; } = []; |
| 13 | |
| 14 | public override void _Process(double delta) |
| 15 | { |
| 16 | _time += delta; |
| 17 | if (_shown is null) |
| 18 | { |
| 19 | _shown = new int[Frames.Count]; |
| 20 | Array.Fill(_shown, -1); |
| 21 | } |
| 22 | |
| 23 | for (var i = 0; i < Frames.Count; i++) |
| 24 | { |
| 25 | var frame = Frames[i]; |
| 26 | var index = frame.Frames <= 1 ? 0 : (int)(Math.Floor(_time * frame.Rate) % frame.Frames); |
| 27 | if (_shown[i] == index) |
| 28 | continue; |
| 29 | _shown[i] = index; |
| 30 | frame.Material.SetShaderParameter(frame.Parameter, index); |
| 31 | } |
| 32 | |
| 33 | foreach (var scroll in Scrolls) |
| 34 | { |
| 35 | var radians = scroll.Angle * Math.PI / 180; |
| 36 | var u = (float)(Math.Cos(radians) * scroll.Rate * _time % 1.0); |
| 37 | var v = (float)(Math.Sin(radians) * scroll.Rate * _time % 1.0); |
| 38 | var scale = (float)scroll.Scale; |
| 39 | scroll.Material.SetShaderParameter(scroll.Parameter, |
| 40 | new Projection(new Vector4(scale, 0, 0, 0), new Vector4(0, scale, 0, 0), new Vector4(0, 0, 1, 0), |
| 41 | new Vector4(u, v, 0, 1))); |
| 42 | } |
| 43 | } |
| 44 | } |