project update
This commit is contained in:
@@ -15,16 +15,15 @@ namespace Enigmos.Modules;
|
||||
|
||||
public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
{
|
||||
private static readonly Font GnuUni = ResourceLoader.Load<Font>("res://Resources/Fonts/GnuUnifontFull-Pm9P.ttf");
|
||||
[Export] private int PresetPortQuality { get; set; }
|
||||
[Export] private int PresetPortCondition { get; set; }
|
||||
[Export] protected bool UsingPreset { get; set; }
|
||||
[Export] public IPresetModuleConnection[] PresetConnections { get; set; }
|
||||
[Export] public string LabelString { get; set; } = "";
|
||||
public virtual Vector2 PositionToBoard => Position;
|
||||
protected virtual bool Draggable() => true;
|
||||
protected virtual bool HasManual() => true;
|
||||
public bool HasLabel() => HasManual();
|
||||
protected virtual bool Draggable => true;
|
||||
protected virtual bool HasManual => true;
|
||||
public bool HasLabel => HasManual;
|
||||
public virtual IEnumerable<IBasePort> Ports => Array.Empty<BasePort>();
|
||||
|
||||
public IBaseBoard? Board { get; set; }
|
||||
@@ -42,9 +41,9 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
|
||||
public virtual void Init()
|
||||
{
|
||||
if (HasLabel())
|
||||
if (HasLabel)
|
||||
{
|
||||
Label = GlobalProvider.SceneProvider
|
||||
Label = GlobalProvider.SceneProvider!
|
||||
.AssetMapper<ISimpleLabel>()
|
||||
.Instantiate<ISimpleLabel>();
|
||||
Label.Position = new Vector2(0, -25);
|
||||
@@ -84,9 +83,9 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
PresetValueInit();
|
||||
}
|
||||
|
||||
protected virtual void TimeoutCheck(RootModule root)
|
||||
protected virtual void TimeoutCheck(IRootModule root)
|
||||
{
|
||||
if (root.Timer.ElapsedMilliseconds < 25) return;
|
||||
if (root.Timer!.ElapsedMilliseconds < 25) return;
|
||||
root.Timer.Stop();
|
||||
throw ModuleExecutionTimeout.Exception;
|
||||
}
|
||||
@@ -95,11 +94,11 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
|
||||
public override Variant _GetDragData(Vector2 atPosition)
|
||||
{
|
||||
if (!Draggable())
|
||||
if (!Draggable)
|
||||
return default;
|
||||
Board!.ModuleMovingLayer.DraggingModule = this;
|
||||
Board!.ModuleMovingLayer.MouseOffset = GetLocalMousePosition();
|
||||
return GlobalProvider.DataStructureProvider.NewVariantWithType("Module", this);
|
||||
return GlobalProvider.DataStructureProvider!.NewVariantWithType("Module", this);
|
||||
}
|
||||
|
||||
|
||||
@@ -119,13 +118,13 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
{
|
||||
if (eventMouseButton.ButtonIndex == MouseButton.Right && eventMouseButton.Pressed)
|
||||
{
|
||||
if (!HasManual())
|
||||
if (!HasManual)
|
||||
return;
|
||||
if (Board.ManualOpened)
|
||||
return;
|
||||
if (Manual == null)
|
||||
{
|
||||
Manual = GlobalProvider.SceneProvider
|
||||
Manual = GlobalProvider.SceneProvider!
|
||||
.AssetMapper<ModuleManual>()
|
||||
.Instantiate<ModuleManual>();
|
||||
Manual.Init(this);
|
||||
|
||||
63
Modules/ComputationalModules/Binary/AdditionModule.cs
Normal file
63
Modules/ComputationalModules/Binary/AdditionModule.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class AdditionModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? InputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports =>
|
||||
base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public override double MaintenanceAlpha => 0.19572021d;
|
||||
public override double MaintenanceBeta => 0.20151779d;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
|
||||
InputGroup = GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1, Input2 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyTensor
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider!.Add(input1, input2, OutputGroup!.SelectedType);
|
||||
foreach (IDataPort port in OutputGroup)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup!.SelectedType = OutputGroup!.SelectedType;
|
||||
|
||||
public override string GetDescription => GlobalProvider.EnigmosProvider.ModuleDescription<AdditionModule>();
|
||||
}
|
||||
36
Modules/ComputationalModules/Binary/ComparisionModule.cs
Normal file
36
Modules/ComputationalModules/Binary/ComparisionModule.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class ComparisionModule : BinaryComputationalModule, IParameterizedModule
|
||||
{
|
||||
|
||||
private DataOutPort? Output { get; set; }
|
||||
private IBoolParameter Greater { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output });
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; }
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Greater = GlobalProvider.DataStructureProvider.NewBoolParameter("Method", "gt", "lt", true);
|
||||
ConfigurableParameters = new HashSet<IConfigurableParameter>() { Greater };
|
||||
Output = GetPort<DataOutPort>("Output");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
Output!.ResultData.Bit = !(Greater.ParameterValue ^ (input1.Real > input2.Real));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class ControlledOutputModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
[Export] private StringName PresetDataType { get; set; }
|
||||
private DataOutPort Output1 { get; set; }
|
||||
private DataOutPort Output2 { get; set; }
|
||||
private DataOutPort Output3 { get; set; }
|
||||
private DataOutPort Output4 { get; set; }
|
||||
private IDataPortGroup OutputGroup { get; set; }
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 });
|
||||
public void Inference() => Input2.SetDataType(OutputGroup.SelectedType);
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Data Type",
|
||||
UsingPreset ? PresetDataType : EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyType
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
if (input1.Bit)
|
||||
foreach (DataOutPort port in OutputGroup.OfType<DataOutPort>())
|
||||
port.ResultData.Assign(input2, OutputGroup.SelectedType);
|
||||
else
|
||||
foreach (DataOutPort port in OutputGroup.OfType<DataOutPort>())
|
||||
port.ResultData.Assign(
|
||||
GlobalProvider.DataStructureProvider.DefaultDataPackage,
|
||||
OutputGroup.SelectedType
|
||||
);
|
||||
}
|
||||
}
|
||||
61
Modules/ComputationalModules/Binary/DivisionModule.cs
Normal file
61
Modules/ComputationalModules/Binary/DivisionModule.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class DivisionModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? InputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1, Input2 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider.Div(input1, input2, OutputGroup.SelectedType);
|
||||
foreach (DataPort port in OutputGroup)
|
||||
{
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
//(port as DataOutPort)!.DataUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup.SelectedType = OutputGroup.SelectedType;
|
||||
|
||||
}
|
||||
65
Modules/ComputationalModules/Binary/DotProductModule.cs
Normal file
65
Modules/ComputationalModules/Binary/DotProductModule.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class DotProductModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? VectorInputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
VectorInputGroup = GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1, Input2 },
|
||||
"Vector Input Type",
|
||||
EnigmosConstant.DataPortTypes.R2,
|
||||
EnigmosConstant.DataPortTypes.VectorTypes
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { VectorInputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider!.Dot(input1, input2, VectorInputGroup!.SelectedType);
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void Inference()
|
||||
{
|
||||
if (GlobalProvider.DataPackageTypeProvider!.IsComplexTensorType(VectorInputGroup!.SelectedType))
|
||||
OutputGroup!.SelectedType = EnigmosConstant.DataPortTypes.Complex;
|
||||
else
|
||||
OutputGroup!.SelectedType = EnigmosConstant.DataPortTypes.Real;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalAlternativeDenialModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = !input1.Bit | !input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalBiconditionalModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = !(input1.Bit ^ input2.Bit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalConjunctionModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = input1.Bit & input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalDisjunctionModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = input1.Bit | input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalExclusiveDisjunctionModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = input1.Bit ^ input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalImplicationModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = !input1.Bit | input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalJointDenialModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = !input1.Bit & !input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalNonimplicationModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = input1.Bit & !input2.Bit;
|
||||
}
|
||||
}
|
||||
44
Modules/ComputationalModules/Binary/MaxModule.cs
Normal file
44
Modules/ComputationalModules/Binary/MaxModule.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class MaxModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
private DataOutPort Output2 { get; set; }
|
||||
private DataOutPort Output3 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output3.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
if (input1.Real > input2.Real)
|
||||
{
|
||||
Output1.ResultData.Real = input1.Real;
|
||||
Output2.ResultData.Real = input1.Real;
|
||||
Output3.ResultData.Real = input1.Real;
|
||||
}
|
||||
else
|
||||
{
|
||||
Output1.ResultData.Real = input2.Real;
|
||||
Output2.ResultData.Real = input2.Real;
|
||||
Output3.ResultData.Real = input2.Real;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
44
Modules/ComputationalModules/Binary/MinModule.cs
Normal file
44
Modules/ComputationalModules/Binary/MinModule.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class MinModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
private DataOutPort Output2 { get; set; }
|
||||
private DataOutPort Output3 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output3.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
if (input1.Real < input2.Real)
|
||||
{
|
||||
Output1.ResultData.Real = input1.Real;
|
||||
Output2.ResultData.Real = input1.Real;
|
||||
Output3.ResultData.Real = input1.Real;
|
||||
}
|
||||
else
|
||||
{
|
||||
Output1.ResultData.Real = input2.Real;
|
||||
Output2.ResultData.Real = input2.Real;
|
||||
Output3.ResultData.Real = input2.Real;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
56
Modules/ComputationalModules/Binary/MultiplicationModule.cs
Normal file
56
Modules/ComputationalModules/Binary/MultiplicationModule.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class MultiplicationModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup InputGroup { get; set; }
|
||||
private IDataPortGroup OutputGroup { get; set; }
|
||||
private DataOutPort Output1 { get; set; }
|
||||
private DataOutPort Output2 { get; set; }
|
||||
private DataOutPort Output3 { get; set; }
|
||||
private DataOutPort Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 });
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; }
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new DataPort[] { Input1, Input2 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new DataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider.Mul(input1, input2, OutputGroup.SelectedType);
|
||||
foreach (DataPort port in OutputGroup)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup.SelectedType = OutputGroup.SelectedType;
|
||||
|
||||
}
|
||||
63
Modules/ComputationalModules/Binary/PowerModule.cs
Normal file
63
Modules/ComputationalModules/Binary/PowerModule.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class PowerModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? TensorInputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
TensorInputGroup = GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1 },
|
||||
"Base Tensor Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Complex);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { TensorInputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider!.Pow(input1, input2, TensorInputGroup!.SelectedType);
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
{
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
//(port as DataOutPort)!.DataUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Inference() =>
|
||||
OutputGroup!.SelectedType = GlobalProvider.DataPackageTypeProvider!.ComplexVersionOf(TensorInputGroup.SelectedType);
|
||||
|
||||
}
|
||||
123
Modules/ComputationalModules/Binary/ScalarDivisionModule.cs
Normal file
123
Modules/ComputationalModules/Binary/ScalarDivisionModule.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class ScalarDivisionModule : BinaryComputationalModule, IPolymorphismModule, IErrorHandlerModule
|
||||
{
|
||||
private IDataPortGroup? ScalarInputGroup { get; set; }
|
||||
private IDataPortGroup? TensorInputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public override double MaintenanceAlpha => 0.77852142d;
|
||||
public override double MaintenanceBeta => 0.9544432d;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
TensorInputGroup = GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1 },
|
||||
"Tensor Input Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.VectorTypes
|
||||
);
|
||||
ScalarInputGroup =GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input2 },
|
||||
"Scalar Input Type",
|
||||
EnigmosConstant.DataPortTypes.R2,
|
||||
EnigmosConstant.DataPortTypes.VectorTypes
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { ScalarInputGroup, TensorInputGroup };
|
||||
SelectedOption = 0;
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
try
|
||||
{
|
||||
IDataPackage res =
|
||||
GlobalProvider.PolymorphismProvider!.ScalarDiv(
|
||||
input1,
|
||||
input2,
|
||||
TensorInputGroup!.SelectedType,
|
||||
ScalarInputGroup!.SelectedType
|
||||
);
|
||||
foreach (IDataPort port in OutputGroup)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorHandler(e, SelectedOption);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Inference()
|
||||
{
|
||||
if (GlobalProvider.DataPackageTypeProvider.IsComplexTensorType(ScalarInputGroup.SelectedType))
|
||||
OutputGroup.SelectedType = GlobalProvider.DataPackageTypeProvider.ComplexVersionOf(TensorInputGroup.SelectedType);
|
||||
else
|
||||
OutputGroup.SelectedType = TensorInputGroup.SelectedType;
|
||||
}
|
||||
|
||||
public void ErrorHandler(Exception error, int idx)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0:
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData
|
||||
.Assign(GlobalProvider.DataStructureProvider!.DefaultDataPackage, OutputGroup.SelectedType);
|
||||
break;
|
||||
case 1:
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData
|
||||
.Assign(GlobalProvider.DataStructureProvider!.DefaultDataPackage, OutputGroup.SelectedType);
|
||||
break;
|
||||
case 2:
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData
|
||||
.Assign(GlobalProvider.DataStructureProvider!.DefaultDataPackage, OutputGroup.SelectedType);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public string[] HandlingOptions() =>
|
||||
new[]
|
||||
{
|
||||
"Reset Circuit State",
|
||||
"Return Previous Valid Value",
|
||||
"Return Default Value"
|
||||
};
|
||||
|
||||
public int SelectedOption { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class ScalarMultiplicationModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? ScalarInputGroup { get; set; }
|
||||
private IDataPortGroup? TensorInputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
ScalarInputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1 },
|
||||
"Scalar Input Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
TensorInputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input2 },
|
||||
"Tensor Input Type",
|
||||
EnigmosConstant.DataPortTypes.R2,
|
||||
EnigmosConstant.DataPortTypes.VectorTypes
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { ScalarInputGroup, TensorInputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res =
|
||||
GlobalProvider.PolymorphismProvider!
|
||||
.ScalarMul(input1, input2, ScalarInputGroup!.SelectedType, TensorInputGroup!.SelectedType);
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
public void Inference()
|
||||
{
|
||||
if (
|
||||
GlobalProvider.DataPackageTypeProvider!.IsComplexTensorType(ScalarInputGroup!.SelectedType) ||
|
||||
GlobalProvider.DataPackageTypeProvider.IsComplexTensorType(TensorInputGroup!.SelectedType)
|
||||
)
|
||||
OutputGroup!.SelectedType = GlobalProvider.DataPackageTypeProvider.ComplexVersionOf(TensorInputGroup!.SelectedType);
|
||||
else
|
||||
OutputGroup!.SelectedType = TensorInputGroup.SelectedType;
|
||||
}
|
||||
|
||||
}
|
||||
58
Modules/ComputationalModules/Binary/SubtractionModule.cs
Normal file
58
Modules/ComputationalModules/Binary/SubtractionModule.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class SubtractionModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup InputGroup { get; set; }
|
||||
private IDataPortGroup OutputGroup { get; set; }
|
||||
private DataOutPort Output1 { get; set; }
|
||||
private DataOutPort Output2 { get; set; }
|
||||
private DataOutPort Output3 { get; set; }
|
||||
private DataOutPort Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 });
|
||||
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; }
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1, Input2 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyTensor
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider.Sub(input1, input2, OutputGroup.SelectedType);
|
||||
foreach (DataPort port in OutputGroup)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup.SelectedType = OutputGroup.SelectedType;
|
||||
|
||||
}
|
||||
70
Modules/ComputationalModules/Binary/V2Module.cs
Normal file
70
Modules/ComputationalModules/Binary/V2Module.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
using R2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<double>.FVector;
|
||||
using C2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<System.Numerics.Complex>.FVector;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class V2Module : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? ScalarInputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public override double MaintenanceAlpha => 0.77852142d;
|
||||
public override double MaintenanceBeta => 0.9544432d;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
ScalarInputGroup = GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1, Input2 },
|
||||
"Scalar Input Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.R2,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { ScalarInputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
R2 v2R = new R2(input1.Real, input2.Real);
|
||||
C2 v2C = new C2(input1.Complex, input2.Complex);
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
{
|
||||
if (ScalarInputGroup!.SelectedType == EnigmosConstant.DataPortTypes.Real)
|
||||
(port as DataOutPort)!.ResultData.R2 = v2R;
|
||||
else
|
||||
(port as DataOutPort)!.ResultData.C2 = v2C;
|
||||
}
|
||||
}
|
||||
|
||||
public void Inference()
|
||||
{
|
||||
OutputGroup!.SelectedType = GlobalProvider.DataPackageTypeProvider!.BuildType(OutputGroup.SelectedType, 1, 2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules;
|
||||
|
||||
@@ -20,6 +21,6 @@ public abstract partial class BinaryComputationalModule : ComputationalModule
|
||||
|
||||
|
||||
protected abstract void Compute(IDataPackage input1, IDataPackage input2);
|
||||
protected override void Compute(RootModule root) => Compute(Input1.GetData(root), Input2.GetData(root));
|
||||
protected override void Compute(IRootModule root) => Compute(Input1.GetData(root), Input2.GetData(root));
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Enigmos.Exceptions;
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules;
|
||||
|
||||
@@ -13,8 +14,8 @@ public abstract partial class ComputationalModule : BaseModule
|
||||
base.TimeoutHandler(timeout);
|
||||
}
|
||||
|
||||
protected abstract void Compute(RootModule root);
|
||||
public void ComputeWithTimeoutHandle(RootModule root)
|
||||
protected abstract void Compute(IRootModule root);
|
||||
public void ComputeWithTimeoutHandle(IRootModule root)
|
||||
{
|
||||
foreach (DataOutPort port in Ports.OfType<DataOutPort>())
|
||||
port.DataUpdated = true;
|
||||
|
||||
54
Modules/ComputationalModules/Nullary/ConstantModule.cs
Normal file
54
Modules/ComputationalModules/Nullary/ConstantModule.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
|
||||
public partial class ConstantModule : NullaryComputationalModule, IParameterizedModule
|
||||
{
|
||||
|
||||
[Export] private double PresetConstantValue { get; set; }
|
||||
|
||||
private HashSet<DataOutPort> OutputGroup { get; set; } = new();
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
private IDoubleParameter ConstValue { get; set; }
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
|
||||
OutputGroup = new HashSet<DataOutPort>(new[] { Output1, Output2, Output3, Output4 });
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
port.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
ConstValue =
|
||||
GlobalProvider.DataStructureProvider.NewDoubleParameter(
|
||||
"Constant Value",
|
||||
-1,
|
||||
1,
|
||||
UsingPreset ? PresetConstantValue : 0
|
||||
);
|
||||
ConfigurableParameters = new HashSet<IConfigurableParameter> { ConstValue };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IRootModule root)
|
||||
{
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
port.ResultData.Real = ConstValue.ParameterValue;
|
||||
|
||||
}
|
||||
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; } = new();
|
||||
}
|
||||
51
Modules/ComputationalModules/Nullary/KeyListenerModule.cs
Normal file
51
Modules/ComputationalModules/Nullary/KeyListenerModule.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
public partial class KeyListenerModule : NullaryComputationalModule, IParameterizedModule, IKeyListenerModule
|
||||
{
|
||||
[Export] private StringName? PresetActionName { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
public IKeyParameter? ListeningKey { get; set; }
|
||||
public bool Pressed { get; set; }
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; } = new();
|
||||
public override IEnumerable<BasePort> Ports => new[] { Output1, Output2, Output3 }!;
|
||||
protected override void Compute(IRootModule root)
|
||||
{
|
||||
Output1!.ResultData.Bit = Pressed;
|
||||
Output2!.ResultData.Bit = Pressed;
|
||||
Output3!.ResultData.Bit = Pressed;
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output3.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
ListeningKey = GlobalProvider.DataStructureProvider!.NewKeyParameter(
|
||||
"Listening Key",
|
||||
UsingPreset && (PresetActionName != null) ? PresetActionName : "KeyListenAction"
|
||||
);
|
||||
ConfigurableParameters = new HashSet<IConfigurableParameter> { ListeningKey };
|
||||
int i = 0;
|
||||
while (InputMap.HasAction($"{ListeningKey.ParameterValue}{i}") && !UsingPreset)
|
||||
i++;
|
||||
ListeningKey.ParameterValue = $"{ListeningKey.ParameterValue}{i}";
|
||||
if(!UsingPreset)
|
||||
InputMap.AddAction(ListeningKey.ParameterValue);
|
||||
GlobalProvider.SceneProvider!.RootScene.KeyListener.Register(this);
|
||||
PostInit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Skeleton.Utils.RandomEngines;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
|
||||
public partial class NormalDistributionModule : NullaryComputationalModule, IParameterizedModule
|
||||
{
|
||||
private HashSet<DataOutPort> OutputGroup { get; set; } = new();
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
private IDoubleParameter? Mu { get; set; }
|
||||
private IDoubleParameter? Sigma { get; set; }
|
||||
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
|
||||
OutputGroup = new HashSet<DataOutPort>(new[] { Output1, Output2, Output3, Output4 });
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
port.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Mu = GlobalProvider.DataStructureProvider!.NewDoubleParameter("mu", -1, 1, 0);
|
||||
Sigma = GlobalProvider.DataStructureProvider.NewDoubleParameter("sigma", 0, 2, 1);
|
||||
ConfigurableParameters = new HashSet<IConfigurableParameter> { Mu, Sigma };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IRootModule root)
|
||||
{
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
{
|
||||
port.ResultData.Real = Normal.Get() * Sigma.ParameterValue - Mu.ParameterValue;
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; } = new();
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules;
|
||||
|
||||
public abstract partial class QuaternaryComputationalModule : ComputationalModule
|
||||
{
|
||||
protected DataInPort Input1 { get; set; }
|
||||
protected DataInPort Input2 { get; set; }
|
||||
protected DataInPort Input3 { get; set; }
|
||||
protected DataInPort Input4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1, Input2, Input3, Input4 };
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Input1 = GetPort<DataInPort>("Input1");
|
||||
Input2 = GetPort<DataInPort>("Input2");
|
||||
Input3 = GetPort<DataInPort>("Input3");
|
||||
Input4 = GetPort<DataInPort>("Input4");
|
||||
}
|
||||
|
||||
|
||||
protected abstract void Compute(IDataPackage input1, IDataPackage input2, IDataPackage input3, IDataPackage input4);
|
||||
|
||||
protected override void Compute(RootModule root) =>
|
||||
Compute(Input1.GetData(root), Input2.GetData(root), Input3.GetData(root), Input4.GetData(root));
|
||||
}
|
||||
46
Modules/ComputationalModules/Ternary/SelectorModule.cs
Normal file
46
Modules/ComputationalModules/Ternary/SelectorModule.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Ternary;
|
||||
|
||||
public partial class SelectorModule : TernaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private IDataPortGroup? DataTypeGroup { get; set; }
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3 })!;
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
DataTypeGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new DataPort[] { Input2, Input3, Output1, Output2, Output3 },
|
||||
"Data Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyType
|
||||
);
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2, IDataPackage input3)
|
||||
{
|
||||
|
||||
Output1!.ResultData.Assign(input1.Bit ? input2 : input3, DataTypeGroup.SelectedType);
|
||||
Output2!.ResultData.Assign(input1.Bit ? input2 : input3, DataTypeGroup.SelectedType);
|
||||
Output3!.ResultData.Assign(input1.Bit ? input2 : input3, DataTypeGroup.SelectedType);
|
||||
}
|
||||
|
||||
public void Inference()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,16 @@ using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules;
|
||||
|
||||
public abstract partial class TernaryComputationalModule : ComputationalModule
|
||||
{
|
||||
protected DataInPort Input1 { get; set; }
|
||||
protected DataInPort Input2 { get; set; }
|
||||
protected DataInPort Input3 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1, Input2, Input3 };
|
||||
protected DataInPort? Input1 { get; set; }
|
||||
protected DataInPort? Input2 { get; set; }
|
||||
protected DataInPort? Input3 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1, Input2, Input3 }!;
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
@@ -21,6 +22,6 @@ public abstract partial class TernaryComputationalModule : ComputationalModule
|
||||
|
||||
protected abstract void Compute(IDataPackage input1, IDataPackage input2, IDataPackage input3);
|
||||
|
||||
protected override void Compute(RootModule root) =>
|
||||
protected override void Compute(IRootModule root) =>
|
||||
Compute(Input1.GetData(root), Input2.GetData(root), Input3.GetData(root));
|
||||
}
|
||||
56
Modules/ComputationalModules/Unary/CopyModule.cs
Normal file
56
Modules/ComputationalModules/Unary/CopyModule.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Unary;
|
||||
public partial class CopyModule : UnaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
private IDataPortGroup? InputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] {Input1},
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyType
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1)
|
||||
{
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData.Assign(input1, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup!.SelectedType = OutputGroup!.SelectedType;
|
||||
|
||||
}
|
||||
26
Modules/ComputationalModules/Unary/LogicalNegationModule.cs
Normal file
26
Modules/ComputationalModules/Unary/LogicalNegationModule.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Unary;
|
||||
|
||||
public partial class LogicalNegationModule : UnaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1)
|
||||
{
|
||||
Output1.ResultData.Bit = !input1.Bit;
|
||||
}
|
||||
|
||||
}
|
||||
58
Modules/ComputationalModules/Unary/NegationModule.cs
Normal file
58
Modules/ComputationalModules/Unary/NegationModule.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Unary;
|
||||
|
||||
public partial class NegationModule : UnaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
private IDataPortGroup? InputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] {Input1},
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyTensor
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider.Neg(input1, OutputGroup.SelectedType);
|
||||
foreach (IDataPort port in OutputGroup)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup.SelectedType = OutputGroup.SelectedType;
|
||||
}
|
||||
60
Modules/ComputationalModules/Unary/SquareModule.cs
Normal file
60
Modules/ComputationalModules/Unary/SquareModule.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Unary;
|
||||
|
||||
public partial class SquareModule : UnaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
private IDataPortGroup? InputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; }
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] {Input1},
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new DataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider.Square(input1, OutputGroup.SelectedType);
|
||||
foreach (DataOutPort port in OutputGroup.OfType<DataOutPort>())
|
||||
port.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup!.SelectedType = OutputGroup!.SelectedType;
|
||||
|
||||
}
|
||||
61
Modules/ComputationalModules/Unary/V2ComponentModule.cs
Normal file
61
Modules/ComputationalModules/Unary/V2ComponentModule.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Unary;
|
||||
|
||||
public partial class V2ComponentModule : UnaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? VectorInputGroup { get; set; }
|
||||
private IDataPortGroup? ScalarOutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
VectorInputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1 },
|
||||
"Vector Input Type",
|
||||
EnigmosConstant.DataPortTypes.R2,
|
||||
EnigmosConstant.DataPortTypes.VectorTypes
|
||||
);
|
||||
ScalarOutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { VectorInputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1)
|
||||
{
|
||||
if (VectorInputGroup!.SelectedType == EnigmosConstant.DataPortTypes.R2)
|
||||
{
|
||||
Output1!.ResultData.Real = input1.R2[1];
|
||||
Output2!.ResultData.Real = input1.R2[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
Output1!.ResultData.Complex = input1.C2[1];
|
||||
Output2!.ResultData.Complex = input1.C2[2];
|
||||
}
|
||||
}
|
||||
public void Inference() =>
|
||||
ScalarOutputGroup!.SelectedType = GlobalProvider.DataPackageTypeProvider!.GetBaseField(VectorInputGroup.SelectedType);
|
||||
|
||||
}
|
||||
@@ -2,13 +2,14 @@ using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules;
|
||||
|
||||
public abstract partial class UnaryComputationalModule : ComputationalModule
|
||||
{
|
||||
protected DataInPort Input1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1 };
|
||||
protected DataInPort? Input1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1 }!;
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
@@ -16,5 +17,5 @@ public abstract partial class UnaryComputationalModule : ComputationalModule
|
||||
}
|
||||
|
||||
protected abstract void Compute(IDataPackage input1);
|
||||
protected override void Compute(RootModule root) => Compute(Input1.GetData(root));
|
||||
protected override void Compute(IRootModule root) => Compute(Input1.GetData(root));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
|
||||
namespace Enigmos.Modules.ControllingModules.ActionModules;
|
||||
|
||||
public abstract partial class ActionModule : ControllingModule
|
||||
{
|
||||
protected abstract void Execute(RootModule root);
|
||||
protected override void Route(RootModule root)
|
||||
protected abstract void Execute(IRootModule root);
|
||||
protected override void Route(IRootModule root)
|
||||
{
|
||||
if(!root.ActionFinished)
|
||||
Execute(root);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Enigmos.Ports.SignalPorts;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ControllingModules.ActionModules;
|
||||
@@ -29,6 +30,6 @@ public partial class AttackActionModule : ActionModule
|
||||
}
|
||||
|
||||
|
||||
protected override void Execute(RootModule root) =>
|
||||
protected override void Execute(IRootModule root) =>
|
||||
root.ManagedBy.Action.Attack(Input1.GetData(root).R2);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Enigmos.Ports.SignalPorts;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Skeleton.Algebra;
|
||||
using Skeleton.Algebra.DimensionProviders;
|
||||
using TabulaSmaragdina.Constants;
|
||||
@@ -10,11 +11,11 @@ using R2 = CategoryOf<IDim2>.OnField<double>.FVector;
|
||||
public partial class MoveActionModule : ActionModule
|
||||
{
|
||||
|
||||
private DataInPort Input1 { get; set; }
|
||||
private SignalInPort SignalIn1 { get; set; }
|
||||
private SignalInPort SignalIn2 { get; set; }
|
||||
private SignalInPort SignalIn3 { get; set; }
|
||||
private SignalInPort SignalIn4 { get; set; }
|
||||
private DataInPort? Input1 { get; set; }
|
||||
private SignalInPort? SignalIn1 { get; set; }
|
||||
private SignalInPort? SignalIn2 { get; set; }
|
||||
private SignalInPort? SignalIn3 { get; set; }
|
||||
private SignalInPort? SignalIn4 { get; set; }
|
||||
|
||||
public override IEnumerable<BasePort> Ports => new BasePort[] { Input1, SignalIn1, SignalIn2, SignalIn3, SignalIn4 };
|
||||
|
||||
@@ -33,7 +34,7 @@ public partial class MoveActionModule : ActionModule
|
||||
|
||||
public override string GetDescription => "";
|
||||
|
||||
protected override void Execute(RootModule root)
|
||||
protected override void Execute(IRootModule root)
|
||||
{
|
||||
R2 direction = Input1.GetData(root).R2;
|
||||
root.ManagedBy.Action.Move(direction);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using Enigmos.Exceptions;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
|
||||
namespace Enigmos.Modules.ControllingModules;
|
||||
|
||||
public abstract partial class ControllingModule : BaseModule
|
||||
public abstract partial class ControllingModule : BaseModule, IControllingModule
|
||||
{
|
||||
|
||||
protected abstract void Route(RootModule root);
|
||||
protected abstract void Route(IRootModule root);
|
||||
public bool Visited { get; set; }
|
||||
protected override void TimeoutHandler(ModuleExecutionTimeout timeout)
|
||||
{
|
||||
@@ -13,7 +14,7 @@ public abstract partial class ControllingModule : BaseModule
|
||||
base.TimeoutHandler(timeout);
|
||||
}
|
||||
|
||||
public void RouteWithTimeoutHandle(RootModule root)
|
||||
public void RouteWithTimeoutHandle(IRootModule root)
|
||||
{
|
||||
if (Visited)
|
||||
return;
|
||||
|
||||
@@ -2,16 +2,17 @@ using System.Diagnostics;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.SignalPorts;
|
||||
using Nocturnis.Creatures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
|
||||
namespace Enigmos.Modules.ControllingModules;
|
||||
public partial class RootModule : ControllingModule
|
||||
public partial class RootModule : ControllingModule, IRootModule
|
||||
{
|
||||
public bool ActionFinished { get; set; }
|
||||
public IBaseCreature ManagedBy { get; set; }
|
||||
protected override bool Draggable() => false;
|
||||
private SignalOutPort SignalOut1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { SignalOut1 };
|
||||
public Stopwatch Timer { get; set; }
|
||||
public IBaseCreature? ManagedBy { get; set; }
|
||||
protected override bool Draggable => false;
|
||||
private SignalOutPort? SignalOut1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { SignalOut1 }!;
|
||||
public Stopwatch? Timer { get; set; }
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
@@ -21,14 +22,14 @@ public partial class RootModule : ControllingModule
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Route(RootModule r)
|
||||
protected override void Route(IRootModule r)
|
||||
{
|
||||
if(!SignalOut1.Connected)
|
||||
if(!SignalOut1!.Connected)
|
||||
{
|
||||
ActionFinished = true;
|
||||
return;
|
||||
}
|
||||
Visited = true;
|
||||
SignalOut1.ConnectedPort.Module.RouteWithTimeoutHandle(this);
|
||||
SignalOut1.ConnectedPort!.Module.RouteWithTimeoutHandle(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public partial class SinglePoleDoubleThrowSwitchModule : ControllingModule, IPar
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Route(RootModule root)
|
||||
protected override void Route(IRootModule root)
|
||||
{
|
||||
Visited = true;
|
||||
SignalOutPort selectedPort = (LeftPortForTrue.ParameterValue && ControlInput.GetData(root).Bit)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Enigmos.Ports.SignalPorts;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ControllingModules;
|
||||
@@ -24,7 +25,7 @@ public partial class SinglePoleSingleThrowSwitchModule : ControllingModule
|
||||
|
||||
|
||||
|
||||
protected override void Route(RootModule root)
|
||||
protected override void Route(IRootModule root)
|
||||
{
|
||||
Visited = true;
|
||||
if (ControlInput.GetData(root).Bit && SignalOut.Connected)
|
||||
|
||||
24
Modules/InterlayerModules/InterlayerDataInModule.cs
Normal file
24
Modules/InterlayerModules/InterlayerDataInModule.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
|
||||
namespace Enigmos.Modules.InterlayerModules;
|
||||
public partial class InterlayerDataInModule : BaseModule, IInterlayerDataInModule
|
||||
{
|
||||
protected override bool HasManual => false;
|
||||
public override Vector2 PositionToBoard => base.PositionToBoard + (ParentModule?.PositionToBoard ?? Vector2.Zero);
|
||||
public IProgrammableModule? ParentModule { get; set; }
|
||||
protected override bool Draggable => false;
|
||||
public IBasePort? UnderlyingPort => DataIn;
|
||||
public IInterlayerDataOutModule? DualModule { get; set; }
|
||||
public IDataInPort? DataIn { get; set; }
|
||||
public override IEnumerable<IBasePort> Ports => new[] { DataIn }!;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
DataIn = GetPort<DataInPort>("DataIn");
|
||||
PostInit();
|
||||
}
|
||||
}
|
||||
32
Modules/InterlayerModules/InterlayerDataOutModule.cs
Normal file
32
Modules/InterlayerModules/InterlayerDataOutModule.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Enigmos.Modules.ComputationalModules;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
|
||||
namespace Enigmos.Modules.InterlayerModules;
|
||||
|
||||
public partial class InterlayerDataOutModule : ComputationalModule, IInterlayerDataOutModule
|
||||
{
|
||||
public override Vector2 PositionToBoard => base.PositionToBoard + (ParentModule?.PositionToBoard ?? Vector2.Zero);
|
||||
public IProgrammableModule? ParentModule { get; set; }
|
||||
|
||||
protected override bool Draggable => false;
|
||||
protected override bool HasManual => false;
|
||||
public IBasePort UnderlyingPort => DataOut!;
|
||||
public IInterlayerDataInModule? DualModule { get; set; }
|
||||
public IDataOutPort? DataOut { get; set; }
|
||||
public override IEnumerable<IBasePort> Ports => new[] { DataOut }!;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
DataOut = GetPort<DataOutPort>("DataOut");
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IRootModule root)
|
||||
{
|
||||
DataOut!.ResultData = DualModule!.DataIn!.GetData(root);
|
||||
}
|
||||
}
|
||||
28
Modules/InterlayerModules/InterlayerSignalInModule.cs
Normal file
28
Modules/InterlayerModules/InterlayerSignalInModule.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports.SignalPorts;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
|
||||
namespace Enigmos.Modules.InterlayerModules;
|
||||
|
||||
public partial class InterlayerSignalInModule : ControllingModule, IInterlayerSignalInModule
|
||||
{
|
||||
public override Vector2 PositionToBoard => base.PositionToBoard + (ParentModule?.PositionToBoard ?? Vector2.Zero);
|
||||
public IProgrammableModule? ParentModule { get; set; }
|
||||
protected override bool Draggable => false;
|
||||
protected override bool HasManual => false;
|
||||
public IBasePort UnderlyingPort => SignalIn!;
|
||||
public IInterlayerSignalOutModule? DualModule { get; set; }
|
||||
public ISignalInPort? SignalIn { get; set; }
|
||||
public override IEnumerable<IBasePort> Ports => new[] { SignalIn }!;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
SignalIn = GetPort<SignalInPort>("SignalIn");
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Route(IRootModule root) => DualModule!.SignalOut!.Module.RouteWithTimeoutHandle(root);
|
||||
}
|
||||
36
Modules/InterlayerModules/InterlayerSignalOutModule.cs
Normal file
36
Modules/InterlayerModules/InterlayerSignalOutModule.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Modules.ProgrammableModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.SignalPorts;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
|
||||
namespace Enigmos.Modules.InterlayerModules;
|
||||
|
||||
public partial class InterlayerSignalOutModule : ControllingModule, IInterlayerSignalOutModule
|
||||
{
|
||||
public override Vector2 PositionToBoard => base.PositionToBoard + (ParentModule?.PositionToBoard ?? Vector2.Zero);
|
||||
public IProgrammableModule? ParentModule { get; set; }
|
||||
protected override bool Draggable => false;
|
||||
protected override bool HasManual => false;
|
||||
public IBasePort UnderlyingPort => SignalOut!;
|
||||
public IInterlayerSignalInModule? DualModule { get; set; }
|
||||
public ISignalOutPort? SignalOut { get; set; }
|
||||
public override IEnumerable<IBasePort> Ports => new[] { SignalOut }!;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
SignalOut = GetPort<SignalOutPort>("SignalOut");
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Route(IRootModule root)
|
||||
{
|
||||
if (!SignalOut!.Connected)
|
||||
return;
|
||||
SignalOut.ConnectedPort!.Module.RouteWithTimeoutHandle(root);
|
||||
}
|
||||
}
|
||||
53
Modules/Other/EngineControllingModule.cs
Normal file
53
Modules/Other/EngineControllingModule.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.Inventories.ItemSlots.ItemSlots;
|
||||
using Skeleton.Algebra.Extensions;
|
||||
using Skeleton.Utils.Helpers;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.Other;
|
||||
public partial class EngineControllingModule : BaseModule
|
||||
{
|
||||
protected override bool Draggable => false;
|
||||
public DataInPort Throttle { get; set; }
|
||||
public IChemicalItemSlot FuelTank { get; set; }
|
||||
private double MaxPumpSpeed => 2d;
|
||||
private double EnergyConversionEfficiency => 0.5d;
|
||||
public override IEnumerable<BasePort> Ports => new[] { Throttle };
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Throttle = GetPort<DataInPort>("Throttle");
|
||||
Throttle.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
FuelTank = GetNode<IChemicalItemSlot>("FuelTank");
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public double Combust(RootModule root)
|
||||
{
|
||||
if (FuelTank.Item == null)
|
||||
return 0d;
|
||||
if (FuelTank.Item.Amount <= 0)
|
||||
return 0d;
|
||||
double fuelAmount = Mathf.Min(
|
||||
FuelTank.Item.BottomAmount,
|
||||
Throttle.GetData(root).Real.DoubleCut() * MaxPumpSpeed * (1 - FuelTank.Item.BottomViscosity)
|
||||
);
|
||||
if (fuelAmount == 0)
|
||||
{
|
||||
//TODO Drain fuel from pipeline
|
||||
}
|
||||
|
||||
double res =
|
||||
fuelAmount * FuelTank.Item.ContentMaterial.LayerOrder.Last.Value.Energy * EnergyConversionEfficiency;
|
||||
FuelTank.Item.ConsumeFromBottom(fuelAmount);
|
||||
if (FuelTank.Item.Amount.IsEqualApprox(0d))
|
||||
{
|
||||
//TODO Try get fuel
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
37
Modules/Other/FilterOutputModule.cs
Normal file
37
Modules/Other/FilterOutputModule.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
using Enigmos.Modules.ComputationalModules;
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Modules.ProgrammableModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
|
||||
namespace Enigmos.Modules.Other;
|
||||
|
||||
public partial class FilterOutputModule : NullaryComputationalModule, IInterlayerModule
|
||||
{
|
||||
public override Vector2 PositionToBoard => base.PositionToBoard + (ParentModule?.PositionToBoard ?? Vector2.Zero);
|
||||
|
||||
public IFilterModule FilterModule
|
||||
{
|
||||
get => (ParentModule as IFilterModule)!;
|
||||
set => ParentModule = value;
|
||||
}
|
||||
public DataOutPort Output { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Output };
|
||||
protected override bool Draggable => false;
|
||||
protected override bool HasManual => false;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output = GetPort<DataOutPort>("Output");
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IRootModule root) => FilterModule.FilterWithTimeoutHandle(root);
|
||||
public IBasePort UnderlyingPort => Output;
|
||||
public IProgrammableModule? ParentModule { get; set; }
|
||||
}
|
||||
20
Modules/Other/IndicateInputModule.cs
Normal file
20
Modules/Other/IndicateInputModule.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
|
||||
namespace Enigmos.Modules.Other;
|
||||
|
||||
public partial class IndicateInputModule : BaseModule
|
||||
{
|
||||
public DataInPort Input { get; set; }
|
||||
protected override bool Draggable => false;
|
||||
protected override bool HasManual => false;
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input };
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Input = GetPort<DataInPort>("Input");
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
30
Modules/Other/IterativeOutputModule.cs
Normal file
30
Modules/Other/IterativeOutputModule.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Enigmos.Modules.ComputationalModules;
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Modules.ProgrammableModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
|
||||
namespace Enigmos.Modules.Other;
|
||||
|
||||
public partial class IterativeOutputModule : NullaryComputationalModule, IInterlayerModule
|
||||
{
|
||||
protected override bool Draggable => false;
|
||||
protected override bool HasManual => false;
|
||||
public DataOutPort? Output { get; set; }
|
||||
|
||||
public override IEnumerable<BasePort> Ports => new[] { Output }!;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output = GetPort<DataOutPort>("DataOut");
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IRootModule root) => throw new Exception("Should be Handled by Other Module");
|
||||
public IBasePort UnderlyingPort => Output!;
|
||||
public IProgrammableModule? ParentModule { get; set; }
|
||||
}
|
||||
38
Modules/Other/OptimizationItemOutputModule.cs
Normal file
38
Modules/Other/OptimizationItemOutputModule.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
using Enigmos.Modules.ComputationalModules;
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Modules.ProgrammableModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
|
||||
namespace Enigmos.Modules.Other;
|
||||
|
||||
public partial class OptimizationItemOutputModule : NullaryComputationalModule, IInterlayerModule
|
||||
{
|
||||
public override Vector2 PositionToBoard =>
|
||||
base.PositionToBoard + (OptimizationModule?.PositionToBoard ?? Vector2.Zero);
|
||||
protected override bool Draggable => false;
|
||||
protected override bool HasManual => false;
|
||||
|
||||
public IOptimizationModule OptimizationModule
|
||||
{
|
||||
get => ParentModule as IOptimizationModule;
|
||||
set => ParentModule = value;
|
||||
}
|
||||
public DataOutPort DataOut { get; set; }
|
||||
|
||||
public override IEnumerable<BasePort> Ports => new[] { DataOut };
|
||||
protected override void Compute(IRootModule root) => OptimizationModule.OptimizeWithTimeoutHandle(root);
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
DataOut = GetPort<DataOutPort>("DataOut");
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public IBasePort UnderlyingPort => DataOut;
|
||||
public IProgrammableModule? ParentModule { get; set; }
|
||||
}
|
||||
21
Modules/Other/OptimizationValueInputModule.cs
Normal file
21
Modules/Other/OptimizationValueInputModule.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.Other;
|
||||
|
||||
public partial class OptimizationValueInputModule : BaseModule
|
||||
{
|
||||
protected override bool Draggable => false;
|
||||
protected override bool HasManual => false;
|
||||
public DataInPort DataIn { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { DataIn };
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
DataIn = GetPort<DataInPort>("DataIn");
|
||||
DataIn.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
DataIn.Module = this;
|
||||
}
|
||||
}
|
||||
38
Modules/Other/OptimizationValueOutputModule.cs
Normal file
38
Modules/Other/OptimizationValueOutputModule.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Enigmos.Modules.ComputationalModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.Other;
|
||||
|
||||
public partial class OptimizationValueOutputModule : NullaryComputationalModule, IInterlayerModule
|
||||
{
|
||||
public override Vector2 PositionToBoard =>
|
||||
base.PositionToBoard + (OptimizationModule?.PositionToBoard ?? Vector2.Zero);
|
||||
protected override bool Draggable => false;
|
||||
protected override bool HasManual => false;
|
||||
public DataOutPort? DataOut { get; set; }
|
||||
public IOptimizationModule OptimizationModule
|
||||
{
|
||||
get => (ParentModule as IOptimizationModule)!;
|
||||
set => ParentModule = value;
|
||||
}
|
||||
public override IEnumerable<BasePort> Ports => new[] { DataOut }!;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
DataOut = GetPort<DataOutPort>("DataOut");
|
||||
DataOut.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IRootModule root) =>
|
||||
OptimizationModule.OptimizeWithTimeoutHandle(root);
|
||||
|
||||
public IBasePort UnderlyingPort => DataOut;
|
||||
public IProgrammableModule? ParentModule { get; set; }
|
||||
}
|
||||
28
Modules/Other/OutputSubModule.cs
Normal file
28
Modules/Other/OutputSubModule.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Enigmos.Modules.ComputationalModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.Other;
|
||||
|
||||
public partial class OutputSubModule : NullaryComputationalModule
|
||||
{
|
||||
public override Vector2 PositionToBoard =>
|
||||
base.PositionToBoard + (ParentModule?.PositionToBoard ?? Vector2.Zero);
|
||||
protected override bool Draggable => false;
|
||||
protected override bool HasManual => false;
|
||||
public override IEnumerable<BasePort> Ports => new[] { DataOut };
|
||||
public IComputationalCompositeModule ParentModule { get; set; }
|
||||
public DataOutPort DataOut { get; set; }
|
||||
protected override void Compute(IRootModule root) => ParentModule.Compute(root);
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
DataOut = GetPort<DataOutPort>("DataOut");
|
||||
DataOut.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
}
|
||||
91
Modules/TerminalModules/MemoryModule.cs
Normal file
91
Modules/TerminalModules/MemoryModule.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Modules.Other;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.TerminalModules;
|
||||
|
||||
public partial class MemoryModule : TerminalModule, IPolymorphismModule, IComputationalCompositeModule
|
||||
{
|
||||
private DataInPort? Input1 { get; set; }
|
||||
private DataInPort? Input2 { get; set; }
|
||||
private DataInPort? Input3 { get; set; }
|
||||
private IDataPackage? Memory { get; set; }
|
||||
private IDataPortGroup? MemoryPortGroup { get; set; }
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
private OutputSubModule? Output1 { get; set; }
|
||||
private OutputSubModule? Output2 { get; set; }
|
||||
private OutputSubModule? Output3 { get; set; }
|
||||
private OutputSubModule? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new BasePort[] { Input1!, Input2!, Input3! };
|
||||
public IBaseModule[] SubModules() => new IBaseModule[] { Output1!, Output2!, Output3!, Output4! };
|
||||
|
||||
|
||||
protected OutputSubModule GetOutputModule(string path)
|
||||
{
|
||||
OutputSubModule res = GetNode<OutputSubModule>(path);
|
||||
res.Init();
|
||||
res.ParentModule = this;
|
||||
res.Board = Board;
|
||||
return res;
|
||||
}
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Memory = GlobalProvider.DataStructureProvider!.NewDataPackage();
|
||||
Input1 = GetPort<DataInPort>("Input1");
|
||||
Input2 = GetPort<DataInPort>("Input2");
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input3 = GetPort<DataInPort>("Input3");
|
||||
Input3.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1 = GetOutputModule("Output1");
|
||||
Output2 = GetOutputModule("Output2");
|
||||
Output3 = GetOutputModule("Output3");
|
||||
Output4 = GetOutputModule("Output4");
|
||||
MemoryPortGroup =GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1, Output1.DataOut, Output2.DataOut, Output3.DataOut, Output4.DataOut },
|
||||
"Memory Data Type:",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyType
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup>() { MemoryPortGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public void Inference()
|
||||
{
|
||||
}
|
||||
|
||||
public void Compute(IRootModule root)
|
||||
{
|
||||
Output1!.DataOut.ResultData.Assign(Memory!, MemoryPortGroup!.SelectedType);
|
||||
Output2!.DataOut.ResultData.Assign(Memory!, MemoryPortGroup.SelectedType);
|
||||
Output3!.DataOut.ResultData.Assign(Memory!, MemoryPortGroup.SelectedType);
|
||||
Output4!.DataOut.ResultData.Assign(Memory!, MemoryPortGroup.SelectedType);
|
||||
}
|
||||
|
||||
protected override void Consume(RootModule root)
|
||||
{
|
||||
bool setValue = Input2!.GetData(root).Bit;
|
||||
bool resetValue = Input3!.GetData(root).Bit;
|
||||
if (setValue)
|
||||
Memory!.Assign(Input1!.GetData(root), MemoryPortGroup!.SelectedType);
|
||||
else if(resetValue)
|
||||
Memory!.Assign(GlobalProvider.DataStructureProvider!.DefaultDataPackage, MemoryPortGroup!.SelectedType);
|
||||
Finished = true;
|
||||
}
|
||||
|
||||
public override void UpdateCables()
|
||||
{
|
||||
base.UpdateCables();
|
||||
foreach (BaseModule subModule in SubModules())
|
||||
subModule.UpdateCables();
|
||||
|
||||
}
|
||||
}
|
||||
66
Modules/TerminalModules/SRLatchModule.cs
Normal file
66
Modules/TerminalModules/SRLatchModule.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Modules.Other;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.TerminalModules;
|
||||
|
||||
public partial class SRLatchModule : TerminalModule, IComputationalCompositeModule
|
||||
{
|
||||
private DataInPort? Input1 { get; set; }
|
||||
private DataInPort? Input2 { get; set; }
|
||||
public OutputSubModule? Output1 { get; set; }
|
||||
public OutputSubModule? Output2 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1, Input2 }!;
|
||||
|
||||
private bool State { get; set; }
|
||||
public IBaseModule[] SubModules() => new IBaseModule[] { Output1, Output2 };
|
||||
public void Compute(IRootModule root)
|
||||
{
|
||||
Output1!.DataOut.ResultData.Bit = State;
|
||||
Output2!.DataOut.ResultData.Bit = State;
|
||||
}
|
||||
|
||||
protected override void Consume(RootModule root)
|
||||
{
|
||||
bool set = Input1!.GetData(root).Bit;
|
||||
bool reset = Input2!.GetData(root).Bit;
|
||||
if (set && reset)
|
||||
State = false;
|
||||
else if (set)
|
||||
State = true;
|
||||
else if (reset)
|
||||
State = false;
|
||||
}
|
||||
protected OutputSubModule GetOutputModule(string path)
|
||||
{
|
||||
OutputSubModule res = GetNode<OutputSubModule>(path);
|
||||
res.Init();
|
||||
res.ParentModule = this;
|
||||
res.Board = Board;
|
||||
return res;
|
||||
}
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Input1 = GetPort<DataInPort>("Input1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2 = GetPort<DataInPort>("Input2");
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1 = GetOutputModule("Output1");
|
||||
Output1.DataOut.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output2 = GetOutputModule("Output2");
|
||||
Output2.DataOut.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public override void UpdateCables()
|
||||
{
|
||||
base.UpdateCables();
|
||||
foreach (IBaseModule subModule in SubModules())
|
||||
subModule.UpdateCables();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.TerminalModules.TestingModules;
|
||||
|
||||
public partial class LightEmittingDiodeModule : TerminalModule
|
||||
{
|
||||
private Sprite2D LightEmittingDiode { get; set; }
|
||||
private DataInPort Input { get; set; }
|
||||
public override IEnumerable<IBasePort> Ports => new[] { Input };
|
||||
|
||||
private static readonly Texture2D TrueTexture =
|
||||
ResourceLoader.Load<Texture2D>("res://Resources/Circuits/Modules/Terminal/Testing/LEDBubble-T.png");
|
||||
private static readonly Texture2D FalseTexture =
|
||||
ResourceLoader.Load<Texture2D>("res://Resources/Circuits/Modules/Terminal/Testing/LEDBubble-F.png");
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Finished = true;
|
||||
LightEmittingDiode = GetNode<Sprite2D>("LightEmittingDiode");
|
||||
Input = GetPort<DataInPort>("Input");
|
||||
Input.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Consume(RootModule root)
|
||||
{
|
||||
if (Input.GetData(root).Bit)
|
||||
LightEmittingDiode.Texture = TrueTexture;
|
||||
else
|
||||
LightEmittingDiode.Texture = FalseTexture;
|
||||
Finished = true;
|
||||
}
|
||||
}
|
||||
34
Modules/TerminalModules/TestingModules/R2Reader.cs
Normal file
34
Modules/TerminalModules/TestingModules/R2Reader.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Godot;
|
||||
using Skeleton.Utils.Helpers;
|
||||
using R2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<double>.FVector;
|
||||
|
||||
namespace Enigmos.Modules.TerminalModules.TestingModules;
|
||||
|
||||
public partial class R2Reader : Control
|
||||
{
|
||||
private AnimatedSprite2D Direction { get; set; }
|
||||
private AnimatedSprite2D Magnitude { get; set; }
|
||||
public R2 UnderlyingVector { get; set; }
|
||||
private double TargetPhase() => Math.Atan2(UnderlyingVector[2], UnderlyingVector[1]);
|
||||
private double TargetLength() => UnderlyingVector.Magnitude;
|
||||
|
||||
private int TargetPhaseFrame =>
|
||||
Mathf.FloorToInt((TargetPhase() % (2d * Math.PI) + 2d * Math.PI) % (2d * Math.PI) * 44d / (2d * Math.PI));
|
||||
|
||||
private int TargetLengthFrame =>
|
||||
Mathf.FloorToInt(TargetLength().DoubleCut() * 9d);
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
Magnitude.SpeedScale = (TargetLengthFrame - Magnitude.Frame) / 7f;
|
||||
var debug = new[] { TargetPhaseFrame - Direction.Frame, TargetPhaseFrame + 44 - Direction.Frame };
|
||||
Direction.SpeedScale = debug.MinBy(Math.Abs) / 25f;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
Direction = GetNode<AnimatedSprite2D>("Direction");
|
||||
Magnitude = GetNode<AnimatedSprite2D>("Magnitude");
|
||||
Direction.Play();
|
||||
Magnitude.Play();
|
||||
}
|
||||
}
|
||||
29
Modules/TerminalModules/TestingModules/R2ReaderModule.cs
Normal file
29
Modules/TerminalModules/TestingModules/R2ReaderModule.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.TerminalModules.TestingModules;
|
||||
|
||||
public partial class R2ReaderModule : TerminalModule
|
||||
{
|
||||
private DataInPort DataIn { get; set; }
|
||||
private R2Reader R2Reader { get; set; }
|
||||
|
||||
public override IEnumerable<BasePort> Ports => new[] { DataIn };
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
DataIn = GetPort<DataInPort>("DataIn");
|
||||
DataIn.SetDataType(EnigmosConstant.DataPortTypes.R2);
|
||||
R2Reader = GetNode<R2Reader>("R2Reader");
|
||||
R2Reader.Init();
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Consume(RootModule root)
|
||||
{
|
||||
R2Reader.UnderlyingVector = DataIn.GetData(root).R2;
|
||||
}
|
||||
}
|
||||
45
Modules/TerminalModules/TestingModules/RealReaderModule.cs
Normal file
45
Modules/TerminalModules/TestingModules/RealReaderModule.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Skeleton.Utils.Helpers;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.TerminalModules.TestingModules;
|
||||
|
||||
public partial class RealReaderModule : TerminalModule
|
||||
{
|
||||
private DataInPort Input1 { get; set; }
|
||||
private DataInPort Input2 { get; set; }
|
||||
private DataInPort Input3 { get; set; }
|
||||
private AnimatedSprite2D RealReader { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1, Input2, Input3 };
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Input1 = GetPort<DataInPort>("Input1");
|
||||
Input2 = GetPort<DataInPort>("Input2");
|
||||
Input3 = GetPort<DataInPort>("Input3");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Input3.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
RealReader = GetNode<AnimatedSprite2D>("RealReader");
|
||||
RealReader.SpeedScale = 0;
|
||||
RealReader.Play();
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Consume(RootModule root)
|
||||
{
|
||||
double max = Input1.GetData(root).Real;
|
||||
double min = Input3.GetData(root).Real;
|
||||
double value = Input2.GetData(root).Real;
|
||||
//DebugToolWindow.FreeInfo = $"{value}";
|
||||
double range = max - min;
|
||||
double percentage = (range == 0 ? 0d : value / range).DoubleCut();
|
||||
int frame = Mathf.FloorToInt(percentage * 122);
|
||||
RealReader.SpeedScale = (frame - RealReader.Frame) / 60f;
|
||||
Finished = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user