Merge from branch giga

This commit is contained in:
Nitload
2025-08-31 10:42:51 +08:00
parent 1fc687f7d0
commit 1a0ccdd8cb
1619 changed files with 2812 additions and 733136 deletions
+134 -15
View File
@@ -29,51 +29,170 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.PipeLine;
using StgSharp.Script.Express;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.Marshalling;
using System.Text;
using System.Xml.Linq;
namespace StgSharp.Modeling.Step
namespace StgSharp.Model.Step
{
public class StepModel
{
private BlueprintScheduler _builder;
private Dictionary<int, StepUncertainEntity> _nodes
= new Dictionary<int, StepUncertainEntity>();
private Dictionary<int, StepEntityBase> _nodes
= new Dictionary<int, StepEntityBase>();
private PipelineScheduler _builder;
private PipelineScheduler _initScheduler = new PipelineScheduler();
private StepInfo _header;
internal StepModel( StepInfo header )
{
_header = header;
_builder = new BlueprintScheduler();
_builder = new PipelineScheduler();
}
public StepUncertainEntity this[ int id ]
public StepEntityBase? this[ int id ]
{
get
{
if( _nodes.TryGetValue( id, out StepUncertainEntity? node ) ) {
if( id == 0 ) {
return null;
}
if( _nodes.TryGetValue( id, out StepEntityBase? node ) )
{
if( node is StepUnsupportedEntity ) {
throw new StepEntityUnsupportedException();
}
return node;
}
node = StepUncertainEntity.Create( id );
node = new StepUninitializedEntity( this, id );
_nodes.Add( id, node );
return node;
}
private set { _nodes[ id ] = value!; }
}
public void AddUncertainEntity( int id, StepUncertainEntity entity )
internal StepEntityBase? this[ ExpSyntaxNode node ]
{
if( _nodes.ContainsKey( id ) ) {
throw new InvalidOperationException(
"Attempt to add entity with same id more than once" );
get
{
if( node is not StepEntityInstanceNode instance ) {
throw new InvalidCastException();
}
return this[ instance.Id ];
}
set
{
if( node is not StepEntityInstanceNode instance ) {
throw new InvalidCastException();
}
this[ instance.Id ] = value;
}
_nodes.Add( id, entity );
}
public void OrganizeNode()
public void BindValue( ExpSyntaxNode node, Action<StepEntityBase> action ) { }
public StepUninitializedEntity FromInitSequence( StepEntityDefineSequence sequence )
{
foreach( KeyValuePair<int, StepUncertainEntity> node in _nodes ) { }
int id = ( sequence.Expression.Left as StepEntityInstanceNode )!.Id;
PipelineNode node;
if( _nodes.TryGetValue( id, out StepEntityBase? e ) && e is StepUninitializedEntity u )
{
u.FromSequence( sequence );
node = _initScheduler.GetNode( u.Label );
} else
{
u = new StepUninitializedEntity( this, id );
u.FromSequenceUnsafe( sequence );
_nodes.Add( id, u );
node = _initScheduler.Create( u.Label, u );
}
PipelineNodeInPort port = node.GetInputPort( StepUninitializedEntity.InName );
if( sequence.Dependencies.Count() == 0 )
{
_initScheduler.LinkToInput( port );
} else
{
foreach( int i in sequence.Dependencies )
{
PipelineNode dNode;
StepEntityLabel label = new StepEntityLabel( i );
if( _nodes.TryGetValue( i, out e ) )
{
dNode = _initScheduler.GetNode( label );
} else
{
u = new StepUninitializedEntity( this, i );
_nodes.Add( i, u );
dNode = _initScheduler.Create( u.Label, u );
}
port.Connect( dNode.GetOutputPort( StepUninitializedEntity.OutName ) );
}
}
return u;
}
public void InitEntity()
{
if( _initScheduler is null ) {
return;
}
_initScheduler.ArrangeNodes();
PipeLineRunner.Run( _initScheduler );
_initScheduler = null!;
}
public void ReplaceEntity(
StepUninitializedEntity uninitialized,
StepEntityBase accurateEntity )
{
ArgumentNullException.ThrowIfNull( uninitialized );
if( uninitialized.Context != this || accurateEntity.Context != this ) {
throw new InvalidOperationException();
}
if( uninitialized.Id != accurateEntity.Id ) {
throw new InvalidOperationException();
}
_nodes[ uninitialized.Id ] = accurateEntity;
}
public string[] ShowStructure( int depth )
{
_initScheduler.ArrangeNodes();
IEnumerable<PipelineNode> nodes = PipelineMarshal.GetNodeSortedEnumeration(
_initScheduler );
int count = 0;
List<string> info = [
@$"Step model root",
];
foreach( PipelineNode node in nodes )
{
count++;
StepUninitializedEntity uncertain = ( node.NodeOperation as StepUninitializedEntity )!;
string[] strings = uncertain.GetEntityDescription( depth - 1 );
if( count < nodes.Count() )
{
info.Add( $" ├-{strings[0]}" );
for( int i = 1; i < strings.Length; i++ ) {
info.Add( $" | {strings[i]}" );
}
} else
{
info.Add( $" └-{strings[0]}" );
for( int i = 1; i < strings.Length; i++ ) {
info.Add( $" {strings[i]}" );
}
}
}
return info.ToArray();
}
}