Upgrade structure of code base
This commit is contained in:
@@ -1,39 +1,27 @@
|
||||
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;
|
||||
using Nocturnis.Enigmos.Modules.ComputationalModules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using Nocturnis.GlobalManagement.Constants;
|
||||
using Nocturnis.GlobalManagement.Providers;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
|
||||
public partial class ConstantModule : NullaryComputationalModule, IParameterizedModule
|
||||
public partial class ConstantModule : NullaryComputationalModule, IParameterizedModule, IDuplicateOutputModule
|
||||
{
|
||||
|
||||
[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 IEnumerable<IBasePort> Ports => base.Ports.Union(DataOutPorts);
|
||||
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");
|
||||
this.DataOutInit("Output", 4);
|
||||
this.SetOutputType(EnigmosConstant.DataPortTypes.Real);
|
||||
|
||||
OutputGroup = new HashSet<DataOutPort>(new[] { Output1, Output2, Output3, Output4 });
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
port.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
ConstValue =
|
||||
GlobalProvider.DataStructureProvider.NewDoubleParameter(
|
||||
GlobalProvider.DataStructureProvider!.NewDoubleParameter(
|
||||
"Constant Value",
|
||||
-1,
|
||||
1,
|
||||
@@ -43,11 +31,11 @@ public partial class ConstantModule : NullaryComputationalModule, IParameterized
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IRootModule root)
|
||||
public override void Define()
|
||||
{
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
port.ResultData.Real = ConstValue.ParameterValue;
|
||||
|
||||
this.Define(cache =>
|
||||
(ConstValue!.ParameterValue, EnigmosConstant.DataPortTypes.Real)
|
||||
);
|
||||
}
|
||||
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; } = new();
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
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;
|
||||
using Nocturnis.Enigmos.Modules.ComputationalModules;
|
||||
using Nocturnis.GlobalManagement.Constants;
|
||||
using Nocturnis.GlobalManagement.Providers;
|
||||
using Skeleton.DataStructure;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
public partial class KeyListenerModule : NullaryComputationalModule, IParameterizedModule, IKeyListenerModule
|
||||
public partial class KeyListenerModule : NullaryComputationalModule,
|
||||
IParameterizedModule,
|
||||
IKeyListenerModule,
|
||||
IDuplicateOutputModule
|
||||
{
|
||||
[Export] private StringName? PresetActionName { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
@@ -18,22 +22,11 @@ public partial class KeyListenerModule : NullaryComputationalModule, IParameteri
|
||||
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);
|
||||
this.DataOutInit("Output", 3);
|
||||
this.SetOutputType(EnigmosConstant.DataPortTypes.Bit);
|
||||
ListeningKey = GlobalProvider.DataStructureProvider!.NewKeyParameter(
|
||||
"Listening Key",
|
||||
UsingPreset && (PresetActionName != null) ? PresetActionName : "KeyListenAction"
|
||||
@@ -48,4 +41,10 @@ public partial class KeyListenerModule : NullaryComputationalModule, IParameteri
|
||||
GlobalProvider.SceneProvider!.RootScene.KeyListener.Register(this);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public override void Define()
|
||||
{
|
||||
(object item, StringName type) Func(CacheItem cache) => (Pressed, EnigmosConstant.DataPortTypes.Bit);
|
||||
this.Define(Func);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Modules.ComputationalModules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using Nocturnis.Enigmos.Ports.DataPorts.Directions;
|
||||
using Nocturnis.GlobalManagement.Constants;
|
||||
using Nocturnis.GlobalManagement.Providers;
|
||||
using Skeleton.Utils.RandomEngines;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
|
||||
public partial class NormalDistributionModule : NullaryComputationalModule, IParameterizedModule
|
||||
public partial class NormalDistributionModule : NullaryComputationalModule,
|
||||
IParameterizedModule,
|
||||
IDuplicateOutputModule
|
||||
{
|
||||
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 })!;
|
||||
public override IEnumerable<IBasePort> Ports => base.Ports.Union(DataOutPorts);
|
||||
private IDoubleParameter? Mu { get; set; }
|
||||
private IDoubleParameter? Sigma { get; set; }
|
||||
|
||||
@@ -25,27 +28,24 @@ public partial class NormalDistributionModule : NullaryComputationalModule, IPar
|
||||
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);
|
||||
this.DataOutInit("Output", 4);
|
||||
this.SetOutputType(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)
|
||||
public override void Define()
|
||||
{
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
foreach (IDataOutPort op in DataOutPorts)
|
||||
{
|
||||
port.ResultData.Real = Normal.Get() * Sigma.ParameterValue - Mu.ParameterValue;
|
||||
op.OutData.UpdateCalculation(x =>
|
||||
(Normal.Get() * Sigma!.ParameterValue - Mu!.ParameterValue, EnigmosConstant.DataPortTypes.Real)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; } = new();
|
||||
}
|
||||
Reference in New Issue
Block a user