Upgrade structure of code base
This commit is contained in:
140
Modules/ProgrammableModules/FilterModule.cs
Normal file
140
Modules/ProgrammableModules/FilterModule.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using Enigmos.Boards;
|
||||
using Enigmos.Exceptions;
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Modules.InterlayerModules;
|
||||
using Enigmos.Modules.Other;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.DataStructures.DataPortGroups;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Modules.InterlayerModules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using Nocturnis.Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.Enigmos.Ports.DataPorts.Directions;
|
||||
using Nocturnis.GlobalManagement.Constants;
|
||||
using Nocturnis.GlobalManagement.Providers;
|
||||
|
||||
namespace Enigmos.Modules.ProgrammableModules;
|
||||
|
||||
public partial class FilterModule : ProgrammableModule, IPolymorphismModule, IFilterModule
|
||||
{
|
||||
|
||||
private IDataInPort? Input { get; set; }
|
||||
private IInterlayerDataInModule[] ExplicitInputs { get; set; } = Array.Empty<IInterlayerDataInModule>();
|
||||
private FilterOutputModule? Output { get; set; }
|
||||
private IterativeOutputModule? IterativeOutput { get; set; }
|
||||
private IndicateInputModule? Indicate { get; set; }
|
||||
private IDataPortGroup[] InterLayerGroups { get; set; } = Array.Empty<IDataPortGroup>();
|
||||
private IDataPortGroup? ArrayGroup { get; set; }
|
||||
private bool FilterEnded { get; set; }
|
||||
private IData[] CachedInputArray { get; set; } = Array.Empty<IData>();
|
||||
public IData[] CachedResult { get; set; } = Array.Empty<IData>();
|
||||
|
||||
private List<IData> CachedListResult { get; set; } = new();
|
||||
|
||||
//private List<IData> CachedResult { get; set; } = new();
|
||||
private int CachedIndex { get; set; }
|
||||
|
||||
public new FilterModuleBoard UnderlyingBoard
|
||||
{
|
||||
get => (base.UnderlyingBoard as FilterModuleBoard)!;
|
||||
set => base.UnderlyingBoard = value;
|
||||
}
|
||||
|
||||
public override IEnumerable<IBasePort> Ports => new[] { Input! };
|
||||
|
||||
public override IBaseModule[] SubModules() => ExplicitInputs.Union<IBaseModule>(new[] { Output! }).ToArray();
|
||||
|
||||
public override IEnumerable<IBasePort> ExplicitPorts =>
|
||||
new IBasePort[] { Output!.Output! }
|
||||
.Union(ExplicitInputs.Select(c => c.DataIn))!
|
||||
.ToArray<IBasePort>();
|
||||
|
||||
public override IEnumerable<IBasePort> ImplicitPorts =>
|
||||
new IBasePort[] { IterativeOutput!.Output!, Indicate!.Input! }
|
||||
.Union(UnderlyingBoard.Outputs.Select(c => c.DataOut))
|
||||
.ToArray()!;
|
||||
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public void Inference() => IterativeOutput!.Output!
|
||||
.SetDataType(GlobalProvider.DataStructureProvider!.ArrayToElement(ArrayGroup!.SelectedType));
|
||||
|
||||
|
||||
public void Filter()
|
||||
{
|
||||
if (FilterEnded)
|
||||
{
|
||||
CachedInputArray = Input!.GetData.Get!.Array;
|
||||
CachedIndex = 0;
|
||||
CachedListResult = new List<IData>();
|
||||
}
|
||||
|
||||
while (CachedIndex < CachedInputArray.Length)
|
||||
{
|
||||
SoftReset();
|
||||
IterativeOutput!.Output!.OutData.UpdateCalculation(cache =>
|
||||
(CachedInputArray[CachedIndex].Data, IterativeOutput.Output.DataType)!);
|
||||
IterativeOutput.Output.OutData.Expire();
|
||||
if(Indicate!.Input!.GetData.Get!.Bit)
|
||||
CachedListResult.Add(CachedInputArray[CachedIndex]);
|
||||
CachedIndex += 1;
|
||||
}
|
||||
|
||||
CachedResult = CachedListResult.ToArray();
|
||||
FilterEnded = true;
|
||||
}
|
||||
|
||||
private void SoftReset() => UnderlyingBoard.Reset();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
UnderlyingBoard = GlobalProvider.SceneProvider!
|
||||
.AssetMapper<FilterModuleBoard>()
|
||||
.Instantiate<FilterModuleBoard>();
|
||||
UnderlyingBoard.Init();
|
||||
ExplicitInputs = new InterlayerDataInModule[3];
|
||||
InterLayerGroups = new IDataPortGroup[3];
|
||||
IterativeOutput = UnderlyingBoard.IterativeOutput;
|
||||
IterativeOutput.Output.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Indicate = UnderlyingBoard.Indicate;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
ExplicitInputs[i] = GetModule<InterlayerDataInModule>($"EI{i + 1}");
|
||||
ExplicitInputs[i].DualModule = UnderlyingBoard.Outputs[i];
|
||||
UnderlyingBoard.Outputs[i].DualModule = ExplicitInputs[i];
|
||||
}
|
||||
|
||||
FilterEnded = true;
|
||||
|
||||
Input = this.GetPort<DataInPort>("Input");
|
||||
Output = GetModule<FilterOutputModule>("Output");
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
InterLayerGroups[i] = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { ExplicitInputs[i].DataIn, UnderlyingBoard.Outputs[i].DataOut },
|
||||
$"Exterior In -> Interior Out{i}",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyType
|
||||
);
|
||||
ExplicitInputs[i].Board = Board;
|
||||
}
|
||||
|
||||
ArrayGroup = GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input, Output.Output! },
|
||||
"Array Type",
|
||||
EnigmosConstant.DataPortTypes.RealArray,
|
||||
EnigmosConstant.DataPortTypes.AnyArray
|
||||
);
|
||||
|
||||
ConfigurablePortGroups = InterLayerGroups.Union(new[] { ArrayGroup }).ToHashSet();
|
||||
|
||||
PostInit();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user