Exemple #1
0
        /// <summary>
        ///     Returns information about the given stack frame for the given process and thread ID.
        ///     If the process, thread, or frame are unknown the null is returned.
        ///     New in 1.5.
        /// </summary>
        public static IDebugDocumentContext2 GetCodeMappingDocument(int processId, int threadId, int frame)
        {
            if (frame >= 0)
            {
                foreach (WeakReference engineRef in Engines)
                {
                    var engine = engineRef.Target as AD7Engine;
                    if (engine != null)
                    {
                        if (engine._process.Id == processId)
                        {
                            NodeThread thread = engine._threads.Item1;

                            if (thread.Id == threadId)
                            {
                                IList <NodeStackFrame> frames = thread.Frames;

                                if (frame < frames.Count)
                                {
                                    NodeStackFrame curFrame = thread.Frames[frame];
                                    return(null);
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
        /// <summary>
        /// Handles backtrace response message.
        /// </summary>
        /// <param name="thread">Thread.</param>
        /// <param name="message">Message.</param>
        /// <returns>Array of stack frames.</returns>
        public void ProcessBacktrace(NodeThread thread, Dictionary<int, NodeModule> modules, JsonValue message, Action<NodeStackFrame[]> successHandler) {
            Utilities.ArgumentNotNull("thread", thread);
            Utilities.ArgumentNotNull("message", message);

            // Extract scripts (if not provided)
            if (modules == null) {
                JsonArray refs = message.GetArray("refs");
                modules = GetScripts(thread.Process, refs);
            }

            // Extract frames
            JsonValue body = message["body"];
            JsonArray frames = body.GetArray("frames");
            if (frames == null) {
                if (successHandler != null) {
                    successHandler(new NodeStackFrame[] { });
                }
                return;
            }

            var stackFrames = new List<NodeStackFrame>(frames.Count);

            for (int i = 0; i < frames.Count; i++) {
                JsonValue frame = frames[i];

                // Create stack frame
                string name = GetFrameName(frame);
                var moduleId = frame["func"].GetValue<int>("scriptId");
                NodeModule module;
                if (!modules.TryGetValue(moduleId, out module)) {
                    module = _unknownModule;
                }

                int line = frame.GetValue<int>("line") + 1;
                var stackFrameId = frame.GetValue<int>("index");

                var stackFrame = new NodeStackFrame(thread, module, name, line, line, line, stackFrameId);

                // Locals
                JsonArray variables = frame.GetArray("locals");
                List<NodeEvaluationResult> locals = GetVariables(stackFrame, variables);

                // Arguments
                variables = frame.GetArray("arguments");
                List<NodeEvaluationResult> parameters = GetVariables(stackFrame, variables);

                stackFrame.Locals = locals;
                stackFrame.Parameters = parameters;

                stackFrames.Add(stackFrame);
            }

            if (successHandler != null) {
                successHandler(stackFrames.ToArray());
            }
        }
    public void BeginRepeater()
    {
        //ApplyPendingDataToVariable(currLoop);

        //Debug.Log("Repeater running.");

        // Fires a phantom thread.
        NodeThread trdInst = new NodeThread(0);

        trdInst.SetNodeData(GetNodeId(), GetCentralInst().GetNodeBranchData(GetNodeId()));

        int threadToUse = GetCentralInst().AddNewThread(trdInst);

        SetVariable <float>(threadToUse, "Time Interval");
    }
Exemple #4
0
        private void OnThreadCreated(object sender, EventArgs e)
        {
            var nodeThread = new NodeThread(_process, _process.Id);
            var newThread  = new AD7Thread(this, nodeThread);

            _threads = new Tuple <NodeThread, AD7Thread>(nodeThread, newThread);

            lock (_syncLock)
            {
                if (_programCreated)
                {
                    SendThreadStart(newThread);
                }
                else
                {
                    _startThread = newThread;
                }
            }
        }
Exemple #5
0
        internal void ExecTest(
            NodeThread thread,
            int frameIndex           = 0,
            string expression        = null,
            string expectedType      = null,
            string expectedValue     = null,
            string expectedException = null,
            string expectedFrame     = null
            )
        {
            var frame = thread.Frames[frameIndex];
            NodeEvaluationResult evaluationResult = null;
            Exception            exception        = null;

            try
            {
                evaluationResult = frame.ExecuteTextAsync(expression).WaitAndUnwrapExceptions();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (expectedType != null)
            {
                Assert.IsNotNull(evaluationResult);
                Assert.AreEqual(expectedType, evaluationResult.TypeName);
            }
            if (expectedValue != null)
            {
                Assert.IsNotNull(evaluationResult);
                Assert.AreEqual(expectedValue, evaluationResult.StringValue);
            }
            if (expectedException != null)
            {
                Assert.IsNotNull(exception);
                Assert.AreEqual(expectedException, exception.Message);
            }
            if (expectedFrame != null)
            {
                Assert.AreEqual(expectedFrame, frame.FunctionName);
            }
        }
Exemple #6
0
        internal void TestDebuggerSteps(
            string filename,
            IEnumerable <TestStep> steps,
            string interpreterOptions = null,
            Action <NodeDebugger> onProcessCreated          = null,
            ExceptionHitTreatment?defaultExceptionTreatment = null,
            ICollection <KeyValuePair <string, ExceptionHitTreatment> > exceptionTreatments = null,
            string scriptArguments = null
            )
        {
            if (!Path.IsPathRooted(filename))
            {
                filename = DebuggerTestPath + filename;
            }

            NodeThread thread = null;

            using (var process = DebugProcess(
                       filename,
                       onProcessCreated: onProcessCreated,
                       onLoadComplete: (newproc, newthread) =>
            {
                thread = newthread;
            },
                       interpreterOptions: interpreterOptions,
                       arguments: scriptArguments,
                       resumeOnProcessLoad: false
                       ))
            {
                TestDebuggerSteps(
                    process,
                    thread,
                    filename,
                    steps,
                    defaultExceptionTreatment,
                    exceptionTreatments,
                    waitForExit: true);
            }
        }
        /// <summary>
        /// Handles backtrace response message.
        /// </summary>
        /// <param name="thread">Thread.</param>
        /// <param name="message">Message.</param>
        /// <returns>Array of stack frames.</returns>
        public void ProcessBacktrace(NodeThread thread, Dictionary <int, NodeModule> modules, JsonValue message, Action <NodeStackFrame[]> successHandler)
        {
            Utilities.ArgumentNotNull("thread", thread);
            Utilities.ArgumentNotNull("message", message);

            // Extract scripts (if not provided)
            if (modules == null)
            {
                JsonArray refs = message.GetArray("refs");
                modules = GetScripts(thread.Process, refs);
            }

            // Extract frames
            JsonValue body   = message["body"];
            JsonArray frames = body.GetArray("frames");

            if (frames == null)
            {
                if (successHandler != null)
                {
                    successHandler(new NodeStackFrame[] { });
                }
                return;
            }

            var stackFrames = new List <NodeStackFrame>(frames.Count);

            for (int i = 0; i < frames.Count; i++)
            {
                JsonValue frame = frames[i];

                // Create stack frame
                string     name     = GetFrameName(frame);
                var        moduleId = frame["func"].GetValue <int>("scriptId");
                NodeModule module;
                if (!modules.TryGetValue(moduleId, out module))
                {
                    module = _unknownModule;
                }

                int line         = frame.GetValue <int>("line") + 1;
                var stackFrameId = frame.GetValue <int>("index");

                var stackFrame = new NodeStackFrame(thread, module, name, line, line, line, stackFrameId);

                // Locals
                JsonArray variables = frame.GetArray("locals");
                List <NodeEvaluationResult> locals = GetVariables(stackFrame, variables);

                // Arguments
                variables = frame.GetArray("arguments");
                List <NodeEvaluationResult> parameters = GetVariables(stackFrame, variables);

                stackFrame.Locals     = locals;
                stackFrame.Parameters = parameters;

                stackFrames.Add(stackFrame);
            }

            if (successHandler != null)
            {
                successHandler(stackFrames.ToArray());
            }
        }
Exemple #8
0
 public AD7Thread(AD7Engine engine, NodeThread debuggedThread)
 {
     this._engine         = engine;
     this._debuggedThread = debuggedThread;
 }
 public AD7Thread(AD7Engine engine, NodeThread debuggedThread) {
     _engine = engine;
     _debuggedThread = debuggedThread;
 }
Exemple #10
0
 public AD7Thread(AD7Engine engine, NodeThread debuggedThread)
 {
     _engine         = engine;
     _debuggedThread = debuggedThread;
 }
Exemple #11
0
 public AD7Thread(AD7Engine engine, NodeThread thread)
 {
     _engine = engine;
     _thread = thread;
 }
        internal void TestDebuggerSteps(
            NodeDebugger process,
            NodeThread thread,
            string filename,
            IEnumerable <TestStep> steps,
            ExceptionHitTreatment?defaultExceptionTreatment = null,
            ICollection <KeyValuePair <string, ExceptionHitTreatment> > exceptionTreatments = null,
            bool waitForExit = false
            )
        {
            if (!Path.IsPathRooted(filename))
            {
                filename = DebuggerTestPath + filename;
            }

            // Since Alpha does not support break on unhandled, and the commonly used Express module has handled SyntaxError exceptions,
            // for alpha we have SyntaxErrors set to BreakNever by default.  Here we set it to BreakAlways so unit tests can run
            // assuming BreakAlways is the default.
            // TODO: Remove once exception treatment is updated for just my code support when it is added after Alpha
            process.SetExceptionTreatment(null, CollectExceptionTreatments(ExceptionHitTreatment.BreakAlways, "SyntaxError"));

            if (defaultExceptionTreatment != null || exceptionTreatments != null)
            {
                process.SetExceptionTreatment(defaultExceptionTreatment, exceptionTreatments);
            }

            Dictionary <Breakpoint, NodeBreakpoint> breakpoints = new Dictionary <Breakpoint, NodeBreakpoint>();

            AutoResetEvent entryPointHit = new AutoResetEvent(false);

            process.EntryPointHit += (sender, e) => {
                Console.WriteLine("EntryPointHit");
                Assert.AreEqual(e.Thread, thread);
                entryPointHit.Set();
            };

            AutoResetEvent breakpointBound = new AutoResetEvent(false);

            process.BreakpointBound += (sender, e) => {
                Console.WriteLine("BreakpointBound {0} {1}", e.BreakpointBinding.Position.FileName, e.BreakpointBinding.Position.Line);
                breakpointBound.Set();
            };

            AutoResetEvent breakpointUnbound = new AutoResetEvent(false);

            process.BreakpointUnbound += (sender, e) => {
                Console.WriteLine("BreakpointUnbound");
                breakpointUnbound.Set();
            };

            AutoResetEvent breakpointBindFailure = new AutoResetEvent(false);

            process.BreakpointBindFailure += (sender, e) => {
                Console.WriteLine("BreakpointBindFailure");
                breakpointBindFailure.Set();
            };

            AutoResetEvent breakpointHit = new AutoResetEvent(false);

            process.BreakpointHit += (sender, e) => {
                Console.WriteLine("BreakpointHit {0}", e.BreakpointBinding.Target.Line);
                Assert.AreEqual(e.Thread, thread);
                Assert.AreEqual(e.BreakpointBinding.Target.Line, thread.Frames.First().Line);
                breakpointHit.Set();
            };

            AutoResetEvent stepComplete = new AutoResetEvent(false);

            process.StepComplete += (sender, e) => {
                Console.WriteLine("StepComplete");
                Assert.AreEqual(e.Thread, thread);
                stepComplete.Set();
            };

            AutoResetEvent exceptionRaised = new AutoResetEvent(false);
            NodeException  exception       = null;

            process.ExceptionRaised += (sender, e) => {
                Console.WriteLine("ExceptionRaised");
                Assert.AreEqual(e.Thread, thread);
                exception = e.Exception;
                exceptionRaised.Set();
            };

            AutoResetEvent processExited = new AutoResetEvent(false);
            int            exitCode      = 0;

            process.ProcessExited += (sender, e) => {
                Console.WriteLine("ProcessExited {0}", e.ExitCode);
                exitCode = e.ExitCode;
                processExited.Set();
            };

            Console.WriteLine("-----------------------------------------");
            Console.WriteLine("Begin debugger step test");
            foreach (var step in steps)
            {
                Console.WriteLine("Step: {0}", step._action);
                Assert.IsFalse(
                    ((step._expectedEntryPointHit != null ? 1 : 0) +
                     (step._expectedBreakpointHit != null ? 1 : 0) +
                     (step._expectedStepComplete != null ? 1 : 0) +
                     (step._expectedExceptionRaised != null ? 1 : 0)) > 1);
                bool           wait = false;
                NodeBreakpoint nodeBreakpoint;
                switch (step._action)
                {
                case TestAction.None:
                    break;

                case TestAction.Wait:
                    wait = true;
                    break;

                case TestAction.ResumeThread:
                    thread.Resume();
                    wait = true;
                    break;

                case TestAction.ResumeProcess:
                    process.Resume();
                    wait = true;
                    break;

                case TestAction.StepOver:
                    thread.StepOver();
                    wait = true;
                    break;

                case TestAction.StepInto:
                    thread.StepInto();
                    wait = true;
                    break;

                case TestAction.StepOut:
                    thread.StepOut();
                    wait = true;
                    break;

                case TestAction.AddBreakpoint:
                    string breakpointFileName = step._targetBreakpointFile;
                    if (breakpointFileName != null)
                    {
                        if (!step._builtin && !Path.IsPathRooted(breakpointFileName))
                        {
                            breakpointFileName = DebuggerTestPath + breakpointFileName;
                        }
                    }
                    else
                    {
                        breakpointFileName = filename;
                    }
                    int        breakpointLine   = step._targetBreakpoint.Value;
                    int        breakpointColumn = step._targetBreakpointColumn.HasValue ? step._targetBreakpointColumn.Value : 0;
                    Breakpoint breakpoint       = new Breakpoint(breakpointFileName, breakpointLine, breakpointColumn);
                    Assert.IsFalse(breakpoints.TryGetValue(breakpoint, out nodeBreakpoint));
                    breakpoints[breakpoint] =
                        AddBreakPoint(
                            process,
                            breakpointFileName,
                            breakpointLine,
                            breakpointColumn,
                            step._enabled ?? true,
                            step._breakOn ?? new BreakOn(),
                            step._condition
                            );
                    if (step._expectFailure)
                    {
                        AssertWaited(breakpointBindFailure);
                        AssertNotSet(breakpointBound);
                        breakpointBindFailure.Reset();
                    }
                    else
                    {
                        AssertWaited(breakpointBound);
                        AssertNotSet(breakpointBindFailure);
                        breakpointBound.Reset();
                    }
                    break;

                case TestAction.RemoveBreakpoint:
                    breakpointFileName = step._targetBreakpointFile ?? filename;
                    breakpointLine     = step._targetBreakpoint.Value;
                    breakpointColumn   = step._targetBreakpointColumn.HasValue ? step._targetBreakpointColumn.Value : 0;
                    breakpoint         = new Breakpoint(breakpointFileName, breakpointLine, breakpointColumn);
                    breakpoints[breakpoint].Remove().WaitAndUnwrapExceptions();
                    breakpoints.Remove(breakpoint);
                    AssertWaited(breakpointUnbound);
                    breakpointUnbound.Reset();
                    break;

                case TestAction.UpdateBreakpoint:
                    breakpointFileName = step._targetBreakpointFile ?? filename;
                    breakpointLine     = step._targetBreakpoint.Value;
                    breakpointColumn   = step._targetBreakpointColumn.HasValue ? step._targetBreakpointColumn.Value : 0;
                    breakpoint         = new Breakpoint(breakpointFileName, breakpointLine, breakpointColumn);
                    nodeBreakpoint     = breakpoints[breakpoint];
                    foreach (var breakpointBinding in nodeBreakpoint.GetBindings())
                    {
                        if (step._hitCount != null)
                        {
                            Assert.IsTrue(breakpointBinding.SetHitCountAsync(step._hitCount.Value).WaitAndUnwrapExceptions());
                        }
                        if (step._enabled != null)
                        {
                            Assert.IsTrue(breakpointBinding.SetEnabledAsync(step._enabled.Value).WaitAndUnwrapExceptions());
                        }
                        if (step._breakOn != null)
                        {
                            Assert.IsTrue(breakpointBinding.SetBreakOnAsync(step._breakOn.Value).WaitAndUnwrapExceptions());
                        }
                        if (step._condition != null)
                        {
                            Assert.IsTrue(breakpointBinding.SetConditionAsync(step._condition).WaitAndUnwrapExceptions());
                        }
                    }
                    break;

                case TestAction.KillProcess:
                    process.Terminate();
                    break;

                case TestAction.Detach:
                    process.Detach();
                    break;
                }

                if (wait)
                {
                    if (step._expectedEntryPointHit != null)
                    {
                        AssertWaited(entryPointHit);
                        AssertNotSet(breakpointHit);
                        AssertNotSet(stepComplete);
                        AssertNotSet(exceptionRaised);
                        Assert.IsNull(exception);
                        entryPointHit.Reset();
                    }
                    else if (step._expectedBreakpointHit != null)
                    {
                        if (step._expectReBind)
                        {
                            AssertWaited(breakpointUnbound);
                            AssertWaited(breakpointBound);
                            breakpointUnbound.Reset();
                            breakpointBound.Reset();
                        }
                        AssertWaited(breakpointHit);
                        AssertNotSet(entryPointHit);
                        AssertNotSet(stepComplete);
                        AssertNotSet(exceptionRaised);
                        Assert.IsNull(exception);
                        breakpointHit.Reset();
                    }
                    else if (step._expectedStepComplete != null)
                    {
                        AssertWaited(stepComplete);
                        AssertNotSet(entryPointHit);
                        AssertNotSet(breakpointHit);
                        AssertNotSet(exceptionRaised);
                        Assert.IsNull(exception);
                        stepComplete.Reset();
                    }
                    else if (step._expectedExceptionRaised != null)
                    {
                        AssertWaited(exceptionRaised);
                        AssertNotSet(entryPointHit);
                        AssertNotSet(breakpointHit);
                        AssertNotSet(stepComplete);
                        exceptionRaised.Reset();
                    }
                    else
                    {
                        AssertNotSet(entryPointHit);
                        AssertNotSet(breakpointHit);
                        AssertNotSet(stepComplete);
                        AssertNotSet(exceptionRaised);
                        Assert.IsNull(exception);
                    }
                }

                if (step._expectedEntryPointHit != null)
                {
                    Assert.AreEqual(step._expectedEntryPointHit.Value, thread.Frames.First().Line);
                }
                else if (step._expectedBreakpointHit != null)
                {
                    Assert.AreEqual(step._expectedBreakpointHit.Value, thread.Frames.First().Line);
                }
                else if (step._expectedStepComplete != null)
                {
                    Assert.AreEqual(step._expectedStepComplete.Value, thread.Frames.First().Line);
                }
                else if (step._expectedExceptionRaised != null)
                {
                    Assert.AreEqual(step._expectedExceptionRaised.TypeName, exception.TypeName);
                    Assert.AreEqual(step._expectedExceptionRaised.Description, exception.Description);
                    if (step._expectedExceptionRaised.LineNo != null)
                    {
                        Assert.AreEqual(step._expectedExceptionRaised.LineNo.Value, thread.Frames[0].Line);
                    }
                    exception = null;
                }
                var expectedBreakFile = step._expectedBreakFile;
                if (expectedBreakFile != null)
                {
                    if (!step._builtin && !Path.IsPathRooted(expectedBreakFile))
                    {
                        expectedBreakFile = DebuggerTestPath + expectedBreakFile;
                    }
                    Assert.AreEqual(expectedBreakFile, thread.Frames.First().FileName);
                }
                var expectedBreakFunction = step._expectedBreakFunction;
                if (expectedBreakFunction != null)
                {
                    Assert.AreEqual(expectedBreakFunction, thread.Frames.First().FunctionName);
                }

                if (step._expectedHitCount != null)
                {
                    string breakpointFileName = step._targetBreakpointFile ?? filename;
                    if (!step._builtin && !Path.IsPathRooted(breakpointFileName))
                    {
                        breakpointFileName = DebuggerTestPath + breakpointFileName;
                    }
                    int breakpointLine   = step._targetBreakpoint.Value;
                    int breakpointColumn = step._targetBreakpointColumn.HasValue ? step._targetBreakpointColumn.Value : 0;
                    var breakpoint       = new Breakpoint(breakpointFileName, breakpointLine, breakpointColumn);
                    nodeBreakpoint = breakpoints[breakpoint];
                    foreach (var breakpointBinding in nodeBreakpoint.GetBindings())
                    {
                        Assert.AreEqual(step._expectedHitCount.Value, breakpointBinding.GetHitCount());
                    }
                }

                if (step._validation != null)
                {
                    step._validation(process, thread);
                }

                if (step._expectedExitCode != null)
                {
                    AssertWaited(processExited);
                    Assert.AreEqual(step._expectedExitCode.Value, exitCode);
                }
            }

            if (waitForExit)
            {
                process.WaitForExit(10000);
            }

            AssertNotSet(entryPointHit);
            AssertNotSet(breakpointHit);
            AssertNotSet(stepComplete);
            AssertNotSet(exceptionRaised);
            Assert.IsNull(exception);
        }
    /*public void NodeVariableCallback<T>(int threadId, int variableId) {
     *
     *  if(threadId == -1)
     *      return;
     *
     *  int currNode = activeThreads.l[threadId].GetCurrentNodeID();
     *  NETWORK_CLIENT_ELIGIBILITY nCE = CheckEligibility(currNode, variableId);
     *
     *
     *  switch(nCE) {
     *      case NETWORK_CLIENT_ELIGIBILITY.GRANTED:
     *          //Debug.Log("Curr Node sent out: " + currNode);
     *          RuntimeParameters<T> paramInst = runtimeParameters[currNode][variableId].field as RuntimeParameters<T>;
     *
     *          AbilityNodeNetworkData dataPacket =new AbilityNodeNetworkData<T>(currNode, variableId, paramInst.v);
     *          INodeNetworkPoint nwPointInst = nodes[progenitorData[currNode]] as INodeNetworkPoint;
     *          nwPointInst.ModifyDataPacket(dataPacket);
     *          AddVariableNetworkData(dataPacket);
     *          break;
     *
     *      case NETWORK_CLIENT_ELIGIBILITY.DENIED:
     *          return;
     *  }
     *
     *  UpdateVariableData<T>(threadId, variableId);
     * }*/

    public void UpdateVariableData <T>(int currNode, int variableId, int threadId = -1, RuntimeParameters <T> var = null, bool runOnCalled = true)
    {
        //if(threadId == -1)
        //return;

        //int currNode = activeThreads.l[threadId].GetCurrentNodeID();

        //if(CheckEligibility(currNode, variableId) == NETWORK_CLIENT_ELIGIBILITY.DENIED)
        //return;

        if (var == null)
        {
            var = ReturnRuntimeParameter(currNode, variableId) as RuntimeParameters <T>;
        }
        //Debug.LogFormat("Curr updatevardata: {0},{1},{2}", castingPlayer, centralId, currNode);

        if (threadId == -1)
        {
            threadId = nodes[currNode].GetNodeThreadId();
        }

        //Debug.LogFormat("Variable it has: {0}, threadID {1}, currNode {2}, varId{3}", var.v ,threadId , currNode, variableId);


        if (threadId > -1)
        {
            int[][] links             = linkMap[activeThreads.l[threadId].GetThreadChannel()][currNode][variableId];
            int     currPossiblePaths = activeThreads.l[threadId].GetPossiblePaths();

            for (int i = 0; i < links.Length; i++)
            {
                int        nodeId         = links[i][0];
                int        nodeVariableId = links[i][1];
                int        linkType       = links[i][2];
                int        threadIdToUse  = threadId;
                NodeThread newThread      = activeThreads.l[threadId].CreateNewThread();

                if (newThread != null)
                {
                    threadIdToUse = activeThreads.Add(newThread);
                }
                else
                {
                    AbilityTreeNode currNodeInst = CreateNewNodeIfNull(currNode);

                    if (currNodeInst.GetNodeThreadId() == threadIdToUse)
                    {
                        currNodeInst.SetNodeThreadId(-1);
                    }
                }

                activeThreads.l[threadIdToUse].SetNodeData(nodeId, nodeBranchingData[nodeId]);

                AbilityTreeNode nextNodeInst = CreateNewNodeIfNull(nodeId);

                int existingThread = nextNodeInst.GetNodeThreadId();

                if (existingThread > -1)
                {
                    HandleThreadRemoval(existingThread);
                }
                //activeThreads.l[threadIdToUse](existingThread);

                //Debug.LogFormat("Thread travelling from {0},{1} to {2},{3} with variable {4}", nodes[currNode], runtimeParameters[currNode][variableId].n, nextNodeInst, runtimeParameters[nodeId][nodeVariableId].n, var.v);
                nextNodeInst.SetNodeThreadId(threadIdToUse);

                /*if(CheckIfReferenced(nodeId, nodeVariableId)) {
                 *
                 *  // Only adds calledcallback if there is a need to.
                 *  if(nodeBranchingData[nodeId] > 0)
                 *      GetRootReferenceCentral(nodeId).AddCalledCallback(instancedNodes[nodeId].Item3, Tuple.Create(castingPlayer, centralId, nodeId));
                 *
                 *  GetRootReferenceCentral(nodeId).UpdateLinkEndPointData<T>(instancedNodes[nodeId].Item3, nodeVariableId, linkType, var, runOnCalled);
                 * } else
                 *  UpdateLinkEndPointData<T>(nodeId, nodeVariableId, linkType, var, runOnCalled);*/

                /*if(runOnCalled) {
                 *
                 *  int totalOnCalled = RunTargettedNodes<T>(nodeId, nodeVariableId, ON_VARIABLE_CATERGORY.ON_CALLED, var.v);
                 *
                 *  // Runs other instances OVC too
                 *  if(onCallbacks.ContainsKey(nodeId))
                 *      foreach(var id in onCallbacks[nodeId][ON_VARIABLE_CATERGORY.ON_CALLED]) {
                 *          AbilityCentralThreadPool centralInst = AbilitiesManager.aData[id.Item1].playerSpawnedCentrals.GetElementAt(id.Item2);
                 *          totalOnCalled += centralInst.RunTargettedNodes<T>(id.Item3, nodeVariableId, ON_VARIABLE_CATERGORY.ON_CALLED, var.v);
                 *      }
                 *
                 *  if(totalOnCalled > 0)
                 *      return;
                 * }*/

                if ((LinkMode)linkType == LinkMode.NORMAL)
                {
                    //Debug.Log("Variable was set.");
                    UpdateVariableValue <T>(nodeId, nodeVariableId, var.v);
                }

                if (networkVariableData.ContainsKey(nodeId))
                {
                    networkVariableData[nodeId].nodeCallbackCount++;


                    for (int j = 0; j < networkVariableData[nodeId].networkVariables.Length; j++)
                    {
                        int networkVarId = networkVariableData[nodeId].networkVariables[j];
                        Tuple <int, int, int> pendingDataKey = Tuple.Create(nodeId, networkVarId, networkVariableData[nodeId].nodeCallbackCount);
                        //Debug.LogWarning("Pending data waiting #2, " + pendingDataKey);

                        if (pendingApplyData.ContainsKey(pendingDataKey))
                        {
                            pendingApplyData[pendingDataKey].ApplyDataToTargetVariable(this);
                        }
                    }
                }

                CreateNewNodeIfNull(nodeId).NodeCallback();

                // Automatically callback all auto managed nodes.
                for (int j = 0; j < autoManagedVar[nodeId].Length; j++)
                {
                    // Callback those that are not blocked.
                    if (!booleanData[nodeId][autoManagedVar[nodeId][j]])
                    {
                        runtimeParameters[nodeId][autoManagedVar[nodeId][j]].RunGenericBasedOnRP <int[]>(this, new int[] { nodeId, autoManagedVar[nodeId][j] });
                    }
                }

                if (nodeBranchingData[nodeId] == 0)
                {
                    HandleThreadRemoval(threadIdToUse);
                }
            }
        }

        // Updates all marked instance.

        /*if(instanceUpdateVarDataCallback.ContainsKey(currNode)) {
         *
         *  HashSet<Tuple<int, int, int>> nodeDataToRm = new HashSet<Tuple<int, int, int>>();
         *
         *  foreach(var item in instanceUpdateVarDataCallback[currNode].ToArray()) {
         *      AbilityCentralThreadPool centralInst = AbilitiesManager.aData[item.Item1].playerSpawnedCentrals.GetElementAt(item.Item2);
         *      centralInst.UpdateVariableData<T>(item.Item3, variableId, -1, var, runOnCalled);
         *
         *      // Checks if node still has any thread on it. If not, removes it.
         *      if(centralInst.GetNode(item.Item3).GetNodeThreadId() == -1)
         *          nodeDataToRm.Add(item);
         *  }
         *
         *  instanceUpdateVarDataCallback[currNode].ExceptWith(nodeDataToRm);
         * }*/

        // Needs to be removed from instance side.
        //markedNodes.Remove(currNode);

        // Updates the other instances.

        /*if(sharedInstance.ContainsKey(currNode))
         *  foreach(var inst in sharedInstance[currNode]) {
         *      //Debug.LogFormat("Central {0} Node {1} is a instance to be set.", inst.Item1, inst.Item2);
         *      AbilityCentralThreadPool centralInst = AbilitiesManager.aData[inst.Item1].playerSpawnedCentrals.GetElementAt(inst.Item2);
         *
         *      centralInst.UpdateVariableData<T>(centralInst.GetNode(inst.Item3).GetNodeThreadId(), variableId, var, runOnCalled);
         *  }*/
    }
 public int AddNewThread(NodeThread inst)
 {
     return(activeThreads.Add(inst));
 }