diff --git a/src/Conveyors/ConveyorBeltStraight/ConveyorBeltStraight.cs b/src/Conveyors/ConveyorBeltStraight/ConveyorBeltStraight.cs index 9b96600..3a8016d 100644 --- a/src/Conveyors/ConveyorBeltStraight/ConveyorBeltStraight.cs +++ b/src/Conveyors/ConveyorBeltStraight/ConveyorBeltStraight.cs @@ -1,7 +1,11 @@ +namespace FoodFactory.Conveyors; + using System.Diagnostics; -using ChickenGameTest; using Chickensoft.AutoInject; using Chickensoft.Introspection; +using FoodFactory.Items; +using FoodFactory.Math; +using FoodFactory.Voxel; using Godot; [Meta(typeof(IAutoNode))] public partial class ConveyorBeltStraight : Node3D, IProvide diff --git a/src/VoxelGrid/ConveyorItemRender.cs b/src/Conveyors/ConveyorItemRender.cs similarity index 73% rename from src/VoxelGrid/ConveyorItemRender.cs rename to src/Conveyors/ConveyorItemRender.cs index fc32f23..a132dc3 100644 --- a/src/VoxelGrid/ConveyorItemRender.cs +++ b/src/Conveyors/ConveyorItemRender.cs @@ -1,9 +1,11 @@ -namespace ChickenGameTest; +namespace FoodFactory.Conveyors; using System.Collections.Generic; +using System.Linq; using System.Runtime.CompilerServices; using Chickensoft.AutoInject; using Chickensoft.Introspection; +using FoodFactory.Items; using Godot; [Meta(typeof(IAutoNode))] @@ -13,7 +15,7 @@ public partial class ConveyorItemRender : Node [Export] protected Path3D Path3D { get; set; } = default!; [Export] protected TestItemConveyor ItemConveyor { get; set; } = default!; [Chickensoft.AutoInject.Dependency] protected IItemRenderer Items => this.DependOn(); - private Chickensoft.Sync.Primitives.AutoList.Binding _binding = default!; + // private Chickensoft.Sync.Primitives.AutoList.Binding _binding = default!; public override async void _Ready() { base._Ready(); @@ -21,7 +23,10 @@ public partial class ConveyorItemRender : Node { await ToSignal(ItemConveyor, Node.SignalName.Ready); } - _binding = ItemConveyor.Items.Items.Bind(); + await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame); + ItemConveyor.GetChildren().OfType().First().Timeout += () => offset = 0; + return; + // _binding = ItemConveyor.Items.Items.Bind(); // binding.OnRemove(callback => // { // Items.Remove(callback.Item); @@ -33,14 +38,25 @@ public partial class ConveyorItemRender : Node // // node.QueueFree(); // // } // }); - _binding.OnAdd((i, v) => Items.UpdateTransform(i.Item, Path3D.GlobalTransform * Path3D.Curve.SampleBakedWithRotation(i.BeltT))); - _binding.OnUpdate((a, b) => Items.UpdateTransform(a.Item, Path3D.GlobalTransform * Path3D.Curve.SampleBakedWithRotation(b.BeltT).Translated(-Path3D.Curve.SampleBakedWithRotation(b.BeltT).Basis.X * b.LaneSpan.Start))); + // _binding.OnAdd((i, v) => Items.UpdateTransform(i.Item, Path3D.GlobalTransform * Path3D.Curve.SampleBakedWithRotation(i.BeltT))); + // _binding.OnUpdate((a, b) => Items.UpdateTransform(a.Item, Path3D.GlobalTransform * Path3D.Curve.SampleBakedWithRotation(b.BeltT).Translated(-Path3D.Curve.SampleBakedWithRotation(b.BeltT).Basis.X * b.LaneSpan.Start))); } + float offset = 0; + public override void _Process(double delta) + { + offset += (float)delta; + base._Process(delta); + var e = ItemConveyor.EnumerateTowardStart(); + while (e.MoveNext()) + { + Items.UpdateTransform(e.Current.Value, Path3D.GlobalTransform * Path3D.Curve.SampleBakedWithRotation(e.Current.Position + (ItemConveyor.SignedSpeed * offset))); + } + } protected override void Dispose(bool disposing) { - _binding.Dispose(); + // _binding.Dispose(); base.Dispose(disposing); } } @@ -54,7 +70,7 @@ public interface IItemRenderer } public partial class ItemRenderSimple : Node3D, IItemRenderer { - public Dictionary _items = []; + private Dictionary _items = []; public void Remove(IBeltItem beltItem) { if (_items.TryGetValue(beltItem, out var node)) diff --git a/src/VoxelGrid/ConveyorItemRender.cs.uid b/src/Conveyors/ConveyorItemRender.cs.uid similarity index 100% rename from src/VoxelGrid/ConveyorItemRender.cs.uid rename to src/Conveyors/ConveyorItemRender.cs.uid diff --git a/src/VoxelGrid/ItemConveyor.cs b/src/Conveyors/ItemConveyor.cs similarity index 92% rename from src/VoxelGrid/ItemConveyor.cs rename to src/Conveyors/ItemConveyor.cs index 0274269..ef9fccd 100644 --- a/src/VoxelGrid/ItemConveyor.cs +++ b/src/Conveyors/ItemConveyor.cs @@ -1,4 +1,4 @@ -namespace ChickenGameTest; +namespace FoodFactory.Conveyors; using Godot; using System; @@ -6,6 +6,9 @@ using System.Collections.Generic; using System.Linq; using Chickensoft.Sync.Primitives; using SJK.Functional; +using SJK.Math; +using FoodFactory.Items; +using FoodFactory.Voxel; public interface IMovementConveyor { @@ -30,8 +33,8 @@ public interface IMovementConveyor // Option GetItemTowardEnd(); // Option GetItemTowardInput(); // Option GetItemTowardOutput(); - IEnumerable.ItemHandle> EnumerateTowardEnd(); - IEnumerable.ItemHandle> EnumerateTowardStart(); + Ordered1DList.Enumerator EnumerateTowardEnd(); + Ordered1DList.Enumerator EnumerateTowardStart(); IBeltMovement GetMovementPolicy(); // IList Items { get; } IOption GetPortFacing(IBeltPort slot); @@ -73,10 +76,12 @@ public sealed class IndividualMovement : IBeltMovement } // GD.Print("hello"); var towardStart = conveyor.GetBeltDirection() == BeltDirection.TowardStart; - foreach (var itemRef in towardStart ? conveyor.EnumerateTowardStart() : conveyor.EnumerateTowardEnd()) + var enumerator = towardStart ? conveyor.EnumerateTowardStart() : conveyor.EnumerateTowardEnd(); + while (enumerator.MoveNext()) { + var itemRef = enumerator.Current; float maxMove = conveyor.SpeedMagnitude * delta; - var space = conveyor.GetDistanceToNextItem(conveyor.GetBeltDirection(), itemRef.Value.BeltT, maxMove, itemRef.Value.LaneSpan); + var space = conveyor.GetDistanceToNextItem(conveyor.GetBeltDirection(), itemRef.Position, maxMove, LaneSpan.One); // space -= ITEMSIZE;//AcountForSPacing @@ -91,21 +96,23 @@ public sealed class IndividualMovement : IBeltMovement } float amountToMove = Mathf.Min(space.Distance, maxMove); - itemRef.Replace(itemRef.Value with { BeltT = itemRef.Value.BeltT + amountToMove * Mathf.Sign(conveyor.SignedSpeed) }); + enumerator.Set(itemRef.Position + amountToMove * Mathf.Sign(conveyor.SignedSpeed)); + // itemRef.Replace(itemRef.Value with { BeltT = itemRef.Value.BeltT + amountToMove * Mathf.Sign(conveyor.SignedSpeed) }); // GD.PrintS(conveyor.Items.Count,space,amountToMove," "+ itemRef.BeltT,itemRef.Item,conveyor.GetBeltDirection(),towardStart); - if (towardStart ? itemRef.Value.BeltT <= 0 : itemRef.Value.BeltT >= conveyor.Length) + if (towardStart ? itemRef.Position <= 0 : itemRef.Position >= conveyor.Length) { var facing = conveyor.GetPortFacing(towardStart ? conveyor.StartPort : conveyor.EndPort); // GD.Print(facing.HasValue(out var slot2),slot2);// , slot2.CanAccept(new TestItem(),LaneSpan.One,0)); - if (facing.HasValue(out var slot) && slot.TryInsert(itemRef.Value.Item, space is PortBeltObstacle portO ? portO.LaneSpan : itemRef.Value.LaneSpan, 0)) + if (facing.HasValue(out var slot) && slot.TryInsert(itemRef.Value, LaneSpan.One, 0)) { // GD.Print(space is PortBeltObstacle port?port.LaneSpan:itemRef.Value.LaneSpan); // GD.PrintS(itemRef.Value.LaneSpan,itemRef.Value.LaneSpan); // GD.Print(itemRef.Item); - itemRef.Remove(); + enumerator.Remove(); } } } + enumerator.SortAll(); } } public sealed class StrictMovement : IBeltMovement diff --git a/src/VoxelGrid/ItemConveyor.cs.uid b/src/Conveyors/ItemConveyor.cs.uid similarity index 100% rename from src/VoxelGrid/ItemConveyor.cs.uid rename to src/Conveyors/ItemConveyor.cs.uid diff --git a/src/VoxelGrid/TestItemConveyor.cs b/src/Conveyors/TestItemConveyor.cs similarity index 72% rename from src/VoxelGrid/TestItemConveyor.cs rename to src/Conveyors/TestItemConveyor.cs index 477412b..20d09b3 100644 --- a/src/VoxelGrid/TestItemConveyor.cs +++ b/src/Conveyors/TestItemConveyor.cs @@ -1,4 +1,4 @@ -namespace ChickenGameTest; +namespace FoodFactory.Conveyors; using Chickensoft.Introspection; using Chickensoft.AutoInject; @@ -8,176 +8,10 @@ using System.Collections.Generic; using System.Linq; using Chickensoft.Sync.Primitives; using SJK.Functional; -using FoodFactory.Recipes; -using Arch.Core; +using SJK.Math; +using FoodFactory.Items; +using FoodFactory.Voxel; -public class Sorted1DList -{ - private readonly AutoList _items = []; -#if DEBUG - private readonly AutoList.Binding _binding; -#endif - private readonly Func _getPosition; - public Sorted1DList(Func getPos) - { - _getPosition = getPos; - // return; -#if DEBUG - _binding = _items.Bind(); - _binding.OnUpdate((a, b, c) => - { - // GD.PrintS("++++++++++++++++",a,b,c); - }); - // return; - _binding.OnModify(() => - { - for (int i = 1; i < _items.Count; i++) - { - if (_getPosition(_items[i - 1]) >= _getPosition(_items[i])) - { - throw new InvalidOperationException( - $"AutoList not sorted at index {i - 1} → {i}. ({_getPosition(_items[i - 1])},{_getPosition(_items[i])})"); - } - } - }); -#endif - - } - public int Count => _items.Count; - public IAutoList Items => _items; - public IEnumerable EnumerateTowardEnd(int? startIndex = null) - { - if (startIndex.HasValue && startIndex >= Count) - { - throw new IndexOutOfRangeException($"{nameof(startIndex)}:{startIndex} can not be greater then or equal to {nameof(Count)}:{Count}"); - } - for (int i = Mathf.Max(0, startIndex ?? 0); i < _items.Count; i++) - { - bool removed = false; - yield return new(_items[i], - () => - { - if (removed) - { - throw new NotSupportedException($"{nameof(ItemHandle.Remove)} can only be called once per item."); - } - removed = true; - _items.RemoveAt(i); - i--; - }, - (replaced) => - { - if (removed) - { - throw new NotSupportedException("Can not Replace an Item after Removing it"); - } - _items[i] = replaced; - } - ); - - } - } - public IEnumerable EnumerateTowardStart(int? startIndex = null) - { - if (startIndex.HasValue && startIndex < 0) - { - throw new IndexOutOfRangeException($"{nameof(startIndex)}:{startIndex} can not be less than zero"); - } - for (int i = Math.Min(startIndex ?? (_items.Count - 1), _items.Count - 1); i >= 0; i--) - { - bool removed = false; - yield return new(_items[i], - () => - { - if (removed) - { - throw new NotSupportedException($"{nameof(ItemHandle.Remove)} can only be called once per item."); - } - removed = true; - _items.RemoveAt(i); - // i--; - }, - (replaced) => - { - if (removed) - { - throw new NotSupportedException("Can not Replace an Item after Removing it"); - } - - if (i - 1 >= 0 && _getPosition(_items[i - 1]) >= _getPosition(replaced)) - { - throw new Exception(); - } - if (i + 1 < Count && _getPosition(_items[i + 1]) <= _getPosition(replaced)) - { - throw new Exception(); - } - _items[i] = replaced; - } - ); - } - } - public void Insert(T item) - { - float pos = _getPosition(item); - if (_items.Count == 0 || pos >= _getPosition(_items[^1])) - { - _items.Add(item); - return; - } - if (pos <= _getPosition(_items[0])) - { - _items.Insert(0, item); - return; - } - var index = LowerBound(pos); - _items.Insert(index, item); - } - private int LowerBound(float pos) - { - int lo = 0; - int hi = _items.Count; - - while (lo < hi) - { - int mid = (lo + hi) >> 1; - - if (_getPosition(_items[mid]) < pos) - { - lo = mid + 1; - } - else - { - hi = mid; - } - } - - return lo; - } - public (Option lower, Option upper) GetNeighbors(float pos) - { - int index = LowerBound(pos); - - var lower = index > 0 ? Option.Some(_items[index - 1]) : Option.None; - var upper = index < _items.Count ? Option.Some(_items[index]) : Option.None; - - return (lower, upper); - } - public readonly struct ItemHandle - { - private readonly Action _remove; - private readonly Action _replace; - public T Value { get; } - public ItemHandle(T value, Action remove, Action replace) - { - Value = value; - _remove = remove; - _replace = replace; - } - public void Remove() => _remove(); - public void Replace(T slice) => _replace(slice); - } -} [Meta(typeof(IAutoNode))] [Tool] public partial class TestItemConveyor : Node, IMovementConveyor @@ -187,7 +21,8 @@ public partial class TestItemConveyor : Node, IMovementConveyor [Dependency] public IVoxelGridRegistry GridRegistry => this.DependOn(); // private readonly AutoList _items = []; // public IAutoList Items => _items; - public readonly Sorted1DList Items = new(pos => pos.BeltT); + // public readonly Sorted1DList Items = new(pos => pos.BeltT); + private readonly Ordered1DList _items = new(); // private AutoList.Binding _itemsBinding; public IBeltPort StartPort { get; set; } // public IBeltSlotProfile StartPort => new ItemConveyor.ConveyorPort() { @@ -307,14 +142,22 @@ public partial class TestItemConveyor : Node, IMovementConveyor LaneSpan laneSpan) { var sequence = towardStart - ? EnumerateTowardStart() - : EnumerateTowardEnd(); - - return sequence - .Where(i => towardStart ? i.Value.BeltT < itemBeltT : i.Value.BeltT > itemBeltT) - .Where(i => LaneSpan.OverLaps(i.Value.LaneSpan, laneSpan)) - .Select(item => item.Value) - .FirstOrNone(); + ? _items.EnumerateTowardStart(itemBeltT) + : _items.EnumerateTowardEnd(itemBeltT); + while (sequence.MoveNext()) + { + var item = sequence.Current; + if (towardStart ? item.Position < itemBeltT : item.Position > itemBeltT) + { + return Some.Of(new ConveyorSlice(item.Value, item.Position)); + } + } + return None.Of(); + // return sequence + // .Where(i => towardStart ? i.Value.BeltT < itemBeltT : i.Value.BeltT > itemBeltT) + // .Where(i => LaneSpan.OverLaps(i.Value.LaneSpan, laneSpan)) + // .Select(item => item.Value) + // .FirstOrNone(); } //ChatGPT Assisted private BeltObstacle GetDistanceAcrossPort( @@ -453,8 +296,8 @@ public partial class TestItemConveyor : Node, IMovementConveyor } private BeltDirection DirectionAwayFromEnd(ConveyorEnd conveyorEnd) => conveyorEnd switch { ConveyorEnd.Start => BeltDirection.TowardEnd, ConveyorEnd.End => BeltDirection.TowardStart, _ => throw new NotSupportedException() }; - public IEnumerable.ItemHandle> EnumerateTowardEnd() => Items.EnumerateTowardEnd(); - public IEnumerable.ItemHandle> EnumerateTowardStart() => Items.EnumerateTowardStart(); + // public IEnumerable.ItemHandle> EnumerateTowardEnd() => Items.EnumerateTowardEnd(); + // public IEnumerable.ItemHandle> EnumerateTowardStart() => Items.EnumerateTowardStart(); private static readonly Vector3[] _square = [new(-.5f, .5f, -.5f), new(.5f, .5f, -.5f), new(.5f, -.5f, -.5f), new(-.5f, -.5f, -.5f), new(-.5f, .5f, -.5f)]; public const float ITEMSIZE = .2f; private const float ITEMHALFSIZE = ITEMSIZE / 2f; @@ -500,12 +343,14 @@ public partial class TestItemConveyor : Node, IMovementConveyor { if (end.End == ConveyorEnd.End) { - Items.Insert(new(item, Length - offset) { LaneSpan = laneSpan }); + _items.Insert(item, Length - offset); + // Items.Insert(new(item, Length - offset) { LaneSpan = laneSpan }); // _items.Add(new(item, Length-offset)); } else { - Items.Insert(new(item, offset) { LaneSpan = laneSpan }); + _items.Insert(item, offset); + // Items.Insert(new(item, offset) { LaneSpan = laneSpan }); // _items.Insert(0, new(item, offset)); } return true; @@ -517,8 +362,8 @@ public partial class TestItemConveyor : Node, IMovementConveyor { return false; } - - Items.Insert(new(item, endOffset.T) { LaneSpan = laneSpan }); + _items.Insert(item, endOffset.T); + // Items.Insert(new(item, endOffset.T) { LaneSpan = laneSpan }); // int insertIndex = FindInsertIndex(endOffset.T); // _items.Insert(insertIndex, new(item, endOffset.T)); @@ -565,6 +410,8 @@ public partial class TestItemConveyor : Node, IMovementConveyor ITEMSIZE < upperAllowed; } + public Ordered1DList.Enumerator EnumerateTowardEnd() => _items.EnumerateTowardEnd(-1); + public Ordered1DList.Enumerator EnumerateTowardStart() => _items.EnumerateTowardStart(_items.Count); } //TODO Should liklely account for max search distance where the conveyorm may be needed to know public record class BeltObstacle(float Distance); diff --git a/src/VoxelGrid/TestItemConveyor.cs.uid b/src/Conveyors/TestItemConveyor.cs.uid similarity index 100% rename from src/VoxelGrid/TestItemConveyor.cs.uid rename to src/Conveyors/TestItemConveyor.cs.uid diff --git a/src/VoxelGrid/Balancer.cs b/src/Equipment/Balancer.cs similarity index 93% rename from src/VoxelGrid/Balancer.cs rename to src/Equipment/Balancer.cs index 3e7d4d1..6099a15 100644 --- a/src/VoxelGrid/Balancer.cs +++ b/src/Equipment/Balancer.cs @@ -1,4 +1,4 @@ -namespace ChickenGameTest; +namespace FoodFactory.Equipment; using Godot; @@ -6,6 +6,10 @@ using System.Collections.Generic; using System.Linq; using Chickensoft.AutoInject; using Chickensoft.Introspection; +using FoodFactory.Voxel; +using FoodFactory.Math; +using FoodFactory.Conveyors; +using FoodFactory.Items; [Meta(typeof(IAutoNode))] public partial class Balancer : Node3D, IProvide, IProvide diff --git a/src/VoxelGrid/Balancer.cs.uid b/src/Equipment/Balancer.cs.uid similarity index 100% rename from src/VoxelGrid/Balancer.cs.uid rename to src/Equipment/Balancer.cs.uid diff --git a/src/VoxelGrid/BeltPort.cs b/src/Equipment/BeltPort.cs similarity index 93% rename from src/VoxelGrid/BeltPort.cs rename to src/Equipment/BeltPort.cs index 162143e..ef7b8f1 100644 --- a/src/VoxelGrid/BeltPort.cs +++ b/src/Equipment/BeltPort.cs @@ -1,8 +1,12 @@ -namespace ChickenGameTest; +namespace FoodFactory.Equipment; using System; using Chickensoft.AutoInject; using Chickensoft.Introspection; +using FoodFactory.Conveyors; +using FoodFactory.Items; +using FoodFactory.Math; +using FoodFactory.Voxel; using Godot; [Tool] diff --git a/src/VoxelGrid/BeltPort.cs.uid b/src/Equipment/BeltPort.cs.uid similarity index 100% rename from src/VoxelGrid/BeltPort.cs.uid rename to src/Equipment/BeltPort.cs.uid diff --git a/src/VoxelGrid/BeltPortHost.cs b/src/Equipment/BeltPortHost.cs similarity index 95% rename from src/VoxelGrid/BeltPortHost.cs rename to src/Equipment/BeltPortHost.cs index 182b97f..2fcc014 100644 --- a/src/VoxelGrid/BeltPortHost.cs +++ b/src/Equipment/BeltPortHost.cs @@ -1,7 +1,8 @@ -namespace ChickenGameTest; +namespace FoodFactory.Equipment; using System; using System.Collections.Generic; +using FoodFactory.Items; public interface IBeltPortHost { diff --git a/src/VoxelGrid/BeltPortHost.cs.uid b/src/Equipment/BeltPortHost.cs.uid similarity index 100% rename from src/VoxelGrid/BeltPortHost.cs.uid rename to src/Equipment/BeltPortHost.cs.uid diff --git a/src/VoxelGrid/ItemSpawner.cs b/src/Equipment/ItemSpawner.cs similarity index 94% rename from src/VoxelGrid/ItemSpawner.cs rename to src/Equipment/ItemSpawner.cs index 1a2d048..57254b1 100644 --- a/src/VoxelGrid/ItemSpawner.cs +++ b/src/Equipment/ItemSpawner.cs @@ -1,14 +1,14 @@ +namespace FoodFactory.Equipment; + using Godot; -using System; - -namespace FoodFactory; - using Arch.Core; -using ChickenGameTest; using Chickensoft.AutoInject; using Chickensoft.Introspection; using FoodFactory.Recipes; -using Godot; +using FoodFactory.Voxel; +using FoodFactory.Math; +using FoodFactory.Items; +using FoodFactory.Conveyors; [Meta(typeof(IAutoNode))] public partial class ItemSpawner : Node3D, IProvide diff --git a/src/VoxelGrid/ItemSpawner.cs.uid b/src/Equipment/ItemSpawner.cs.uid similarity index 100% rename from src/VoxelGrid/ItemSpawner.cs.uid rename to src/Equipment/ItemSpawner.cs.uid diff --git a/src/VoxelGrid/OvenTest.cs b/src/Equipment/OvenTest.cs similarity index 98% rename from src/VoxelGrid/OvenTest.cs rename to src/Equipment/OvenTest.cs index 5915de8..972aa58 100644 --- a/src/VoxelGrid/OvenTest.cs +++ b/src/Equipment/OvenTest.cs @@ -1,15 +1,16 @@ -namespace ChickenGameTest; +namespace FoodFactory.Equipment; using System; -using System.Collections.Generic; using System.Diagnostics; using Arch.Core; using Arch.Core.Extensions; using Chickensoft.AutoInject; using Chickensoft.Introspection; -using FoodFactory; +using FoodFactory.Conveyors; using FoodFactory.Items; +using FoodFactory.Math; using FoodFactory.Recipes; +using FoodFactory.Voxel; using Godot; using SJK.Functional; diff --git a/src/VoxelGrid/OvenTest.cs.uid b/src/Equipment/OvenTest.cs.uid similarity index 100% rename from src/VoxelGrid/OvenTest.cs.uid rename to src/Equipment/OvenTest.cs.uid diff --git a/src/VoxelGrid/SlicerTest.cs b/src/Equipment/SlicerTest.cs similarity index 97% rename from src/VoxelGrid/SlicerTest.cs rename to src/Equipment/SlicerTest.cs index 1943be0..435055c 100644 --- a/src/VoxelGrid/SlicerTest.cs +++ b/src/Equipment/SlicerTest.cs @@ -1,4 +1,4 @@ -namespace ChickenGameTest; +namespace FoodFactory.Equipment; using System; using System.Collections.Generic; @@ -8,8 +8,11 @@ using Arch.Core.Extensions; using Chickensoft.AutoInject; using Chickensoft.Introspection; using FoodFactory; +using FoodFactory.Conveyors; using FoodFactory.Items; +using FoodFactory.Math; using FoodFactory.Recipes; +using FoodFactory.Voxel; using Godot; using SJK.Functional; diff --git a/src/VoxelGrid/SlicerTest.cs.uid b/src/Equipment/SlicerTest.cs.uid similarity index 100% rename from src/VoxelGrid/SlicerTest.cs.uid rename to src/Equipment/SlicerTest.cs.uid diff --git a/src/Game.cs b/src/Game.cs index 0c62131..21905c4 100644 --- a/src/Game.cs +++ b/src/Game.cs @@ -1,4 +1,4 @@ -namespace ChickenGameTest; +namespace FoodFactory; using Godot; diff --git a/src/Items/Item.cs b/src/Items/Item.cs index 6e395a0..c90400d 100644 --- a/src/Items/Item.cs +++ b/src/Items/Item.cs @@ -1,11 +1,12 @@ -namespace ChickenGameTest; +namespace FoodFactory.Items; using System; using System.Collections.Generic; using System.Linq; using Arch.Core; using Arch.Core.Extensions; -using FoodFactory.Items; +using FoodFactory.Conveyors; +using FoodFactory.Math; using Godot; using SJK.Functional; diff --git a/src/Items/ItemECSTest.cs b/src/Items/ItemECSTest.cs index 5977aed..1745a57 100644 --- a/src/Items/ItemECSTest.cs +++ b/src/Items/ItemECSTest.cs @@ -1,13 +1,11 @@ +namespace FoodFactory; - -using System; using System.Collections.Generic; using Arch.Core; using Arch.Core.Extensions; using Arch.LowLevel; -using FoodFactory; using FoodFactory.Items; -using FoodFactory.Recipes; +using FoodFactory.Math; using Godot; public class Test diff --git a/src/Main.cs b/src/Main.cs index d057d73..4660e21 100644 --- a/src/Main.cs +++ b/src/Main.cs @@ -1,4 +1,4 @@ -namespace ChickenGameTest; +namespace FoodFactory; using Godot; using Chickensoft.GameTools.Displays; diff --git a/src/Math/GridTransform3D.cs b/src/Math/GridTransform3D.cs index a9e1337..b090da8 100644 --- a/src/Math/GridTransform3D.cs +++ b/src/Math/GridTransform3D.cs @@ -1,6 +1,7 @@ +namespace FoodFactory.Math; + using Godot; using System; - public readonly struct GridTransform3D : IEquatable { public readonly Vector3I Origin; diff --git a/src/Math/Ordered1DList.cs b/src/Math/Ordered1DList.cs index 4d250e0..6bf071c 100644 --- a/src/Math/Ordered1DList.cs +++ b/src/Math/Ordered1DList.cs @@ -2,16 +2,19 @@ namespace SJK.Math; using System; using System.Collections.Generic; -using Arch.LowLevel; -public sealed class Ordered1DList : IDisposable where T : unmanaged +public sealed class Ordered1DList// : IDisposable where T : unmanaged { - private readonly UnsafeList _values; - public Ordered1DList(int capacity) + private readonly List _values; + public Ordered1DList(int capacity = 8) { _values = new(capacity); } - public record struct Entry(float Position, T Value); + public record struct Entry(float Position, T Value) : IComparable + { + public readonly int CompareTo(Entry other) => (int)(Position - other.Position); + } + public void Insert(T item, float position) { if (_values.Count == 0 || position >= _values[^1].Position) @@ -30,11 +33,13 @@ public sealed class Ordered1DList : IDisposable where T : unmanaged } public void RemoveAt(int index) => _values.RemoveAt(index); public void Clear() => _values.Clear(); + public int Count => _values.Count; public void MoveAllBy(float offset) { - for (int i = 0; i < _values.Count; i++) + for (var i = 0; i < _values.Count; i++) { - _values[i].Position = _values[i].Position + offset; + _values[i] = new(_values[i].Position + offset, _values[i].Value); + // _values[i].Position = _values[i].Position + offset; } } private void SortFromIndex(int index) @@ -59,12 +64,12 @@ public sealed class Ordered1DList : IDisposable where T : unmanaged private void Swap(int a, int b) => (_values[b], _values[a]) = (_values[a], _values[b]); private int LowerBound(float pos) { - int lo = 0; - int hi = _values.Count; + var lo = 0; + var hi = _values.Count; while (lo < hi) { - int mid = (lo + hi) >> 1; + var mid = (lo + hi) >> 1; if (_values[mid].Position < pos) { @@ -80,6 +85,8 @@ public sealed class Ordered1DList : IDisposable where T : unmanaged } public Enumerator EnumerateTowardEnd(int startIndex) => new(this, towardsEnd: true, startIndex); public Enumerator EnumerateTowardStart(int startIndex) => new(this, towardsEnd: false, startIndex); + public Enumerator EnumerateTowardEnd(float offset) => new(this, towardsEnd: true, LowerBound(offset) - 1); + public Enumerator EnumerateTowardStart(float offset) => new(this, towardsEnd: false, LowerBound(offset) + 1); public ref struct Enumerator { public Enumerator(Ordered1DList list, bool towardsEnd, int index) @@ -102,8 +109,22 @@ public sealed class Ordered1DList : IDisposable where T : unmanaged _list._values.RemoveAt(_index); _index -= _towardsEnd ? 1 : -1; } + public void SortAll() + { + if (_list.Count > 0) + { + _list._values.Sort(); + } + } - public readonly ref Entry Current => ref _list._values[_index]; + public readonly void Set(float newPosition) + { + _list._values[_index] = new(newPosition, _list._values[_index].Value); + // _list.SortFromIndex(_index); + // _list.SortFromIndex(_index); + } + + public readonly Entry Current => _list._values[_index]; } - public void Dispose() => _values.Dispose(); + // public void Dispose() => _values.Dispose(); } diff --git a/src/Math/Temperature.cs b/src/Math/Temperature.cs index 1cd7aa0..2679009 100644 --- a/src/Math/Temperature.cs +++ b/src/Math/Temperature.cs @@ -1,5 +1,5 @@ //https://www.codeproject.com/Articles/311333/A-Csharp-Temperature-Struct -namespace FoodFactory; +namespace FoodFactory.Math; @@ -142,19 +142,19 @@ public struct Temperature : IFormattable, IComparable, /// The value of format is not null, the empty string (""), "G", "C", "F", or /// "K". /// - public readonly string ToString(string? format, IFormatProvider? provider) + public readonly string ToString(string? format, IFormatProvider? formatProvider) { if (string.IsNullOrEmpty(format)) { format = "G"; } - provider ??= CultureInfo.CurrentCulture; + formatProvider ??= CultureInfo.CurrentCulture; return format switch { - "G" or "C" or "g" or "c" => Celsius.ToString("F2", provider) + " °C", - "F" or "f" => Fahrenheit.ToString("F2", provider) + " °F", - "K" or "k" => _kelvin.ToString("F2", provider) + " K", + "G" or "C" or "g" or "c" => Celsius.ToString("F2", formatProvider) + " °C", + "F" or "f" => Fahrenheit.ToString("F2", formatProvider) + " °F", + "K" or "k" => _kelvin.ToString("F2", formatProvider) + " K", _ => throw new FormatException( string.Format("The {0} format string is not supported.", format)), }; diff --git a/src/Math/Weight.cs b/src/Math/Weight.cs index a31fedd..53e5dfa 100644 --- a/src/Math/Weight.cs +++ b/src/Math/Weight.cs @@ -1,3 +1,5 @@ +namespace FoodFactory.Math; + using System; using System.Globalization; diff --git a/src/Recipes/Blueprint.cs b/src/Recipes/Blueprint.cs index 95afa5f..c096ec9 100644 --- a/src/Recipes/Blueprint.cs +++ b/src/Recipes/Blueprint.cs @@ -3,8 +3,9 @@ namespace FoodFactory.Recipes; using System; using System.Collections.Generic; using Arch.Core; -using ChickenGameTest; using FoodFactory.Items; +using FoodFactory.Math; +using FoodFactory.Voxel; public interface IBlueprintManger { diff --git a/src/Recipes/Recipe.cs b/src/Recipes/Recipe.cs index 56ed2f9..0a6ef43 100644 --- a/src/Recipes/Recipe.cs +++ b/src/Recipes/Recipe.cs @@ -8,6 +8,7 @@ using Arch.Core; using Arch.Core.Extensions; using Arch.Core.Extensions.Dangerous; using FoodFactory.Items; +using FoodFactory.Math; using Godot; public abstract record Recipe(string Name, BlueprintId[]? BlueprintIds, bool[] RequireAll, Tags[] Inputs, Tags[] Exclude, RecipeOutput RecipeOutput, RecipeAction Action = default, bool InputsOrdered = true) diff --git a/src/Recipes/Recipes.cs b/src/Recipes/Recipes.cs index 6569051..ba7aed6 100644 --- a/src/Recipes/Recipes.cs +++ b/src/Recipes/Recipes.cs @@ -4,9 +4,8 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using ChickenGameTest; +using FoodFactory.Equipment; using FoodFactory.Items; -using Godot; using SJK.Functional; diff --git a/src/VoxelGrid/VoxelGridNode.cs b/src/VoxelGrid/VoxelGridNode.cs index 127ccc4..dbbebd7 100644 --- a/src/VoxelGrid/VoxelGridNode.cs +++ b/src/VoxelGrid/VoxelGridNode.cs @@ -1,15 +1,15 @@ -namespace ChickenGameTest; +namespace FoodFactory.Voxel; using System; using System.Collections.Generic; -using System.Text.RegularExpressions; using Arch.Core; -using Arch.Core.Extensions; using Arch.LowLevel; using Arch.System; using Chickensoft.AutoInject; using Chickensoft.Introspection; using FoodFactory; +using FoodFactory.Conveyors; +using FoodFactory.Math; using FoodFactory.Recipes; using Godot; public class BacterialSystem : BaseSystem @@ -23,7 +23,7 @@ public class BacterialSystem : BaseSystem public override void Update(in float t) { var delta = t; - World.ParallelQuery(in _desc, (Entity entity, ref Bacteria bacteria, ref Temperature temperature) => + World.Query(in _desc, (Entity entity, ref Bacteria bacteria, ref Temperature temperature) => { var handle = bacteria.Data; var data = Resources.Get(in handle); @@ -94,7 +94,7 @@ public partial class VoxelGridNode : Node3D, IProvide, IProv { if (item is ConveyorBeltStraight conveyor) { - var node = conveyor.GetNode("Node") as TestItemConveyor; + var node = conveyor.ConveyorLogic; node.IsReversed = !node.IsReversed; } } diff --git a/src/VoxelGrid/VoxelRegistry.cs b/src/VoxelGrid/VoxelRegistry.cs index 50e3b2e..9d591b9 100644 --- a/src/VoxelGrid/VoxelRegistry.cs +++ b/src/VoxelGrid/VoxelRegistry.cs @@ -1,10 +1,11 @@ -namespace ChickenGameTest; +namespace FoodFactory.Voxel; using Godot; using System; using System.Collections.Generic; using System.Linq; using SJK.Functional; +using FoodFactory.Items; public interface IVoxelGridRegistry { diff --git a/test/src/GameTest.cs b/test/src/GameTest.cs index 1960bdf..820ad8e 100644 --- a/test/src/GameTest.cs +++ b/test/src/GameTest.cs @@ -1,4 +1,4 @@ -namespace ChickenGameTest; +namespace FoodFactory; using System.Threading.Tasks; using Chickensoft.GoDotTest;