public override object GetValue(ConnectorViewModel connector, object context) { switch (CastToType) { //case CastType.SByte: // return (SByte)retVal; //case CastType.Int16: // return (Int16)retVal; //case CastType.Int32: // return (Int32)retVal; //case CastType.Int64: // return (Int64)retVal; //case CastType.Byte: // return (Byte)retVal; //case CastType.UInt16: // return (UInt16)retVal; //case CastType.UInt32: // return (UInt32)retVal; //case CastType.UInt64: // return (UInt64)retVal; case CastType.Double: return(NodeDataNumeric.FromDouble(Value)); //case CastType.Single: // return (Single)retVal; //case CastType.Decimal: // return (Decimal)retVal; //case CastType.IConvertable: // return enumeration.Sum(dr => dr); } return(NodeDataNumeric.MakeZero()); }
// Triggered execution public override void Execute(object context) { float l_value = value; if (inputValue.IsConnected) { object newContext = new object(); // new exuction node, new execution context NodeDataNumeric InputVal = inputValue.AttachedConnections.Select(connection => { try { object tmp = connection.SourceConnector.ParentNode.GetValue(connection.SourceConnector, context); if (typeof(NodeDataNumeric).IsAssignableFrom(tmp.GetType())) { return((NodeDataNumeric)tmp); } return(null); } catch { return(null); } }).Where(val => val != null).FirstOrDefault(); if (InputVal != null) { l_value = InputVal.GetSingle(); } } charContext.GetCharacter(0).SetVariable(varName, l_value, frameCount, easing); }
public override object GetValue(ConnectorViewModel connector, object context) { if (conInput.IsConnected) { Cache cache; double retVal; if (context == null || !DataCache.TryGetValue(context, out cache)) { retVal = conInput.AttachedConnections.Sum(connection => { object tmp = connection.SourceConnector.ParentNode.GetValue(connection.SourceConnector, context); try { if (typeof(NodeDataNumeric).IsAssignableFrom(tmp.GetType())) { return(((NodeDataNumeric)tmp).GetDouble()); } } catch { } return(0d); }); DataCache.Add(context, new Cache() { value = retVal }); } else { retVal = cache.value; } switch (CastToType) { //case CastType.SByte: // return (SByte)retVal; //case CastType.Int16: // return (Int16)retVal; //case CastType.Int32: // return (Int32)retVal; //case CastType.Int64: // return (Int64)retVal; //case CastType.Byte: // return (Byte)retVal; //case CastType.UInt16: // return (UInt16)retVal; //case CastType.UInt32: // return (UInt32)retVal; //case CastType.UInt64: // return (UInt64)retVal; case CastType.Double: return(NodeDataNumeric.FromDouble(retVal)); //case CastType.Single: // return (Single)retVal; //case CastType.Decimal: // return (Decimal)retVal; //case CastType.IConvertable: // return enumeration.Sum(dr => dr); } return(NodeDataNumeric.MakeZero()); } return(NodeDataNumeric.MakeZero()); }
public override object GetValue(ConnectorViewModel connector, object context) { if (controller.IsConnected && cState.HasValue) { if (conLeftThumbX == connector) { return(NodeDataNumeric.FromInt16(cState.Value.Gamepad.LeftThumbX)); } if (conLeftThumbY == connector) { return(NodeDataNumeric.FromInt16(cState.Value.Gamepad.LeftThumbY)); } if (conLeftTrigger == connector) { return(NodeDataNumeric.FromByte(cState.Value.Gamepad.LeftTrigger)); } if (conRightThumbX == connector) { return(NodeDataNumeric.FromInt16(cState.Value.Gamepad.RightThumbX)); } if (conRightThumbY == connector) { return(NodeDataNumeric.FromInt16(cState.Value.Gamepad.RightThumbY)); } if (conRightTrigger == connector) { return(NodeDataNumeric.FromByte(cState.Value.Gamepad.RightTrigger)); } //if (conButtons == connector) // return new NodeDataXInputButtons(cState.Value.Gamepad.Buttons); } return(null); }
public override object GetValue(ConnectorViewModel connector, object context) { if (conLeftThumbDeadZone == connector) { return(NodeDataNumeric.FromInt16(SharpDX.XInput.Gamepad.LeftThumbDeadZone)); } if (conRightThumbDeadZone == connector) { return(NodeDataNumeric.FromInt16(SharpDX.XInput.Gamepad.RightThumbDeadZone)); } if (conTriggerThreshold == connector) { return(NodeDataNumeric.FromByte(SharpDX.XInput.Gamepad.TriggerThreshold)); } return(null); }
// called when something tries to ask this node for a value public override object GetValue(ConnectorViewModel connector, object context) { if (conOutX == connector || conOutY == connector) { Cache cache; double outX; double outY; // if the cache context is not set or there is no data cached for that context // ask attached nodes for values so we can calculate our output if (context == null || !DataCache.TryGetValue(context, out cache)) { NodeDataNumeric MinNodeVal = conInMin.AttachedConnections.Select(connection => { try { object tmp = connection.SourceConnector.ParentNode.GetValue(connection.SourceConnector, context); if (typeof(NodeDataNumeric).IsAssignableFrom(tmp.GetType())) { return((NodeDataNumeric)tmp); } return(null); } catch { return(null); } }).Where(val => val != null).FirstOrDefault(); NodeDataNumeric MaxNodeVal = conInMax.AttachedConnections.Select(connection => { try { object tmp = connection.SourceConnector.ParentNode.GetValue(connection.SourceConnector, context); if (typeof(NodeDataNumeric).IsAssignableFrom(tmp.GetType())) { return((NodeDataNumeric)tmp); } return(null); } catch { return(null); } }).Where(val => val != null).FirstOrDefault(); NodeDataNumeric XNodeVal = conInX.AttachedConnections.Select(connection => { try { object tmp = connection.SourceConnector.ParentNode.GetValue(connection.SourceConnector, context); if (typeof(NodeDataNumeric).IsAssignableFrom(tmp.GetType())) { return((NodeDataNumeric)tmp); } return(null); } catch { return(null); } }).Where(val => val != null).FirstOrDefault(); NodeDataNumeric YNodeVal = conInY.AttachedConnections.Select(connection => { try { object tmp = connection.SourceConnector.ParentNode.GetValue(connection.SourceConnector, context); if (typeof(NodeDataNumeric).IsAssignableFrom(tmp.GetType())) { return((NodeDataNumeric)tmp); } return(null); } catch { return(null); } }).Where(val => val != null).FirstOrDefault(); double Min = this.Min; double Max = this.Max; double X = 0; double Y = 0; try { if (MinNodeVal != null) { Min = MinNodeVal.GetDouble(); } } catch { } try { if (MaxNodeVal != null) { Max = MaxNodeVal.GetDouble(); } } catch { } try { if (XNodeVal != null) { X = XNodeVal.GetDouble(); } } catch { } try { if (YNodeVal != null) { Y = YNodeVal.GetDouble(); } } catch { } double MaxMag = Max - Min; double inputMagnitude = System.Math.Sqrt(X * X + Y * Y); if (inputMagnitude < Min) { DataCache.Add(context, new Cache() { X = 0d, Y = 0d }); //Console.WriteLine("Storing data for {0,8:X8}", RuntimeHelpers.GetHashCode(context)); return(NodeDataNumeric.FromDouble(0d)); } if (inputMagnitude > Max) { inputMagnitude = Max; } double newMagnitude = ((inputMagnitude - Min) / MaxMag); outX = System.Math.Min(System.Math.Max(X / inputMagnitude, -1d), 1d) * newMagnitude; outY = System.Math.Min(System.Math.Max(Y / inputMagnitude, -1d), 1d) * newMagnitude; DataCache.Add(context, new Cache() { X = outX, Y = outY }); //Console.WriteLine("Storing data for {0,8:X8}", RuntimeHelpers.GetHashCode(context)); } else // we already have the output for this context cached, re-output it { outX = cache.X; outY = cache.Y; //Console.WriteLine("Loading data for {0,8:X8}", RuntimeHelpers.GetHashCode(context)); } if (conOutX == connector) { return(NodeDataNumeric.FromDouble(outX)); } if (conOutY == connector) { return(NodeDataNumeric.FromDouble(outY)); } } return(null); }