Changed Namespaces, Move files
This commit is contained in:
@@ -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<IVoxelGridRegistry>
|
||||
|
||||
@@ -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<IItemRenderer>();
|
||||
private Chickensoft.Sync.Primitives.AutoList<ConveyorSlice>.Binding _binding = default!;
|
||||
// private Chickensoft.Sync.Primitives.AutoList<ConveyorSlice>.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<Timer>().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<IBeltItem, Node3D> _items = [];
|
||||
private Dictionary<IBeltItem, Node3D> _items = [];
|
||||
public void Remove(IBeltItem beltItem)
|
||||
{
|
||||
if (_items.TryGetValue(beltItem, out var node))
|
||||
@@ -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<ConveyorSlice> GetItemTowardEnd();
|
||||
// Option<ConveyorSlice> GetItemTowardInput();
|
||||
// Option<ConveyorSlice> GetItemTowardOutput();
|
||||
IEnumerable<Sorted1DList<ConveyorSlice>.ItemHandle> EnumerateTowardEnd();
|
||||
IEnumerable<Sorted1DList<ConveyorSlice>.ItemHandle> EnumerateTowardStart();
|
||||
Ordered1DList<IBeltItem>.Enumerator EnumerateTowardEnd();
|
||||
Ordered1DList<IBeltItem>.Enumerator EnumerateTowardStart();
|
||||
IBeltMovement GetMovementPolicy();
|
||||
// IList<ConveyorSlice> Items { get; }
|
||||
IOption<IBeltPort> 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
|
||||
@@ -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<T>
|
||||
{
|
||||
private readonly AutoList<T> _items = [];
|
||||
#if DEBUG
|
||||
private readonly AutoList<T>.Binding _binding;
|
||||
#endif
|
||||
private readonly Func<T, float> _getPosition;
|
||||
public Sorted1DList(Func<T, float> 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<T> Items => _items;
|
||||
public IEnumerable<ItemHandle> 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<ItemHandle> 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<T> lower, Option<T> upper) GetNeighbors(float pos)
|
||||
{
|
||||
int index = LowerBound(pos);
|
||||
|
||||
var lower = index > 0 ? Option<T>.Some(_items[index - 1]) : Option<T>.None;
|
||||
var upper = index < _items.Count ? Option<T>.Some(_items[index]) : Option<T>.None;
|
||||
|
||||
return (lower, upper);
|
||||
}
|
||||
public readonly struct ItemHandle
|
||||
{
|
||||
private readonly Action _remove;
|
||||
private readonly Action<T> _replace;
|
||||
public T Value { get; }
|
||||
public ItemHandle(T value, Action remove, Action<T> 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<IVoxelGridRegistry>();
|
||||
// private readonly AutoList<ConveyorSlice> _items = [];
|
||||
// public IAutoList<ConveyorSlice> Items => _items;
|
||||
public readonly Sorted1DList<ConveyorSlice> Items = new(pos => pos.BeltT);
|
||||
// public readonly Sorted1DList<ConveyorSlice> Items = new(pos => pos.BeltT);
|
||||
private readonly Ordered1DList<IBeltItem> _items = new();
|
||||
// private AutoList<ConveyorSlice>.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<ConveyorSlice>.Of(new ConveyorSlice(item.Value, item.Position));
|
||||
}
|
||||
}
|
||||
return None<ConveyorSlice>.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<Sorted1DList<ConveyorSlice>.ItemHandle> EnumerateTowardEnd() => Items.EnumerateTowardEnd();
|
||||
public IEnumerable<Sorted1DList<ConveyorSlice>.ItemHandle> EnumerateTowardStart() => Items.EnumerateTowardStart();
|
||||
// public IEnumerable<Sorted1DList<ConveyorSlice>.ItemHandle> EnumerateTowardEnd() => Items.EnumerateTowardEnd();
|
||||
// public IEnumerable<Sorted1DList<ConveyorSlice>.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<IBeltItem>.Enumerator EnumerateTowardEnd() => _items.EnumerateTowardEnd(-1);
|
||||
public Ordered1DList<IBeltItem>.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);
|
||||
@@ -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<IBeltPortHost>, IProvide<IVoxelGridRegistry>
|
||||
@@ -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]
|
||||
@@ -1,7 +1,8 @@
|
||||
namespace ChickenGameTest;
|
||||
namespace FoodFactory.Equipment;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FoodFactory.Items;
|
||||
|
||||
public interface IBeltPortHost
|
||||
{
|
||||
@@ -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<IBeltPortHost>
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace ChickenGameTest;
|
||||
namespace FoodFactory;
|
||||
|
||||
using Godot;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace ChickenGameTest;
|
||||
namespace FoodFactory;
|
||||
|
||||
using Godot;
|
||||
using Chickensoft.GameTools.Displays;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace FoodFactory.Math;
|
||||
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public readonly struct GridTransform3D : IEquatable<GridTransform3D>
|
||||
{
|
||||
public readonly Vector3I Origin;
|
||||
|
||||
@@ -2,16 +2,19 @@ namespace SJK.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Arch.LowLevel;
|
||||
|
||||
public sealed class Ordered1DList<T> : IDisposable where T : unmanaged
|
||||
public sealed class Ordered1DList<T>// : IDisposable where T : unmanaged
|
||||
{
|
||||
private readonly UnsafeList<Entry> _values;
|
||||
public Ordered1DList(int capacity)
|
||||
private readonly List<Entry> _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<Entry>
|
||||
{
|
||||
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<T> : 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<T> : 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<T> : 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<T> list, bool towardsEnd, int index)
|
||||
@@ -102,8 +109,22 @@ public sealed class Ordered1DList<T> : IDisposable where T : unmanaged
|
||||
_list._values.RemoveAt(_index);
|
||||
_index -= _towardsEnd ? 1 : -1;
|
||||
}
|
||||
|
||||
public readonly ref Entry Current => ref _list._values[_index];
|
||||
public void SortAll()
|
||||
{
|
||||
if (_list.Count > 0)
|
||||
{
|
||||
_list._values.Sort();
|
||||
}
|
||||
public void Dispose() => _values.Dispose();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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".
|
||||
/// </exception>
|
||||
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)),
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
namespace FoodFactory.Math;
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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<World, float>
|
||||
@@ -23,7 +23,7 @@ public class BacterialSystem : BaseSystem<World, float>
|
||||
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<IVoxelGridRegistry>, IProv
|
||||
{
|
||||
if (item is ConveyorBeltStraight conveyor)
|
||||
{
|
||||
var node = conveyor.GetNode("Node") as TestItemConveyor;
|
||||
var node = conveyor.ConveyorLogic;
|
||||
node.IsReversed = !node.IsReversed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace ChickenGameTest;
|
||||
namespace FoodFactory;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Chickensoft.GoDotTest;
|
||||
|
||||
Reference in New Issue
Block a user