From aaf7afdd659cd09f1a97cb73ee0df383edbb8600 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Wed, 26 Sep 2018 09:08:05 -0500 Subject: [PATCH] Better non-visible regression testing & the close button working. --- EduNetworkBuilder/ListBoxWindow.cs | 6 ++++++ EduNetworkBuilder/NB.cs | 2 +- EduNetworkBuilder/Network.cs | 24 ++++++++++++++++++++++++ EduNetworkBuilder/NetworkBuilder.cs | 14 ++++++++++++-- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/EduNetworkBuilder/ListBoxWindow.cs b/EduNetworkBuilder/ListBoxWindow.cs index 003604d..15b635a 100644 --- a/EduNetworkBuilder/ListBoxWindow.cs +++ b/EduNetworkBuilder/ListBoxWindow.cs @@ -609,6 +609,7 @@ namespace EduNetworkBuilder { AddRoute(); } + //In puzzle mode, this is the cancel button if(MyMode == LBContents.puzzles) { if (oursettings.AutoStartPuzzles != cbLoadPuzzlesAtStart.Checked) @@ -618,6 +619,11 @@ namespace EduNetworkBuilder } Close(); } + //In regression, this is the close button + if (MyMode == LBContents.regressiontest) + { + Close(); + } } private void AddRoute() { diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs index d109a06..6994210 100644 --- a/EduNetworkBuilder/NB.cs +++ b/EduNetworkBuilder/NB.cs @@ -491,7 +491,7 @@ namespace EduNetworkBuilder { BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"]; if (myWin == null) return; - myWin.RegisterInisibleNet(ToRegister); + myWin.RegisterInvisibleNet(ToRegister); } public static void UnregisterInvisibleNetwork() diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index 331d5f3..77a3644 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -84,6 +84,8 @@ namespace EduNetworkBuilder public bool ReplayInProgress = false; public DateTime NextReplayAction = DateTime.UtcNow; public int NextReplayIndex = -1; + public bool StartedNewReplayAction = false; + public bool ProcessingNonVisually = false; /// /// WhatFrom: If we are launched from a homework, we remember it here. @@ -1682,6 +1684,7 @@ namespace EduNetworkBuilder { //we did something. keep replaying NB.MarkToUpdate(); + StartedNewReplayAction = true; } else { @@ -2471,6 +2474,27 @@ namespace EduNetworkBuilder } } + /// + /// This is used when we are doing a replay behind the scenes. + /// We may have many things that we do. We still want to time-out if + /// a packet needs to drop. So we loop through, but have a timeout on each + /// individual action. + /// + public void NonVisualProcessPacketsMultipleTimes() + { + int counter = 0; + while (counter < 1000 && myPackets.Count > 0) + { + Tick(true); //Skip visuals + if(StartedNewReplayAction) + { + counter = 0; //reset counter to zero + StartedNewReplayAction = false; //reset it + } + counter++; + } + } + int BreakNetComponent(NetworkComponent What, HowToBreak How, string Data) { int didit = 0; diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index d1e8c56..fc67131 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -2706,7 +2706,7 @@ namespace EduNetworkBuilder return myNetwork; } - public void RegisterInisibleNet(Network toRegister) + public void RegisterInvisibleNet(Network toRegister) { InvisibleNetwork = toRegister; } @@ -2859,7 +2859,17 @@ namespace EduNetworkBuilder //Disable menuitems & right-click if in replay mode myNetwork.ReplayInProgress = true; myNetwork.NextReplayIndex = 0; - myNetwork.NextReplayAction = DateTime.UtcNow.AddMilliseconds(delay_between); + myNetwork.NextReplayAction = DateTime.UtcNow.AddMilliseconds(delay_between); + + //Now we need to process it. + NB.RegisterInvisibleNetwork(myNetwork); + //while we have actions to do. + while (myNetwork.ReplayInProgress) + { + myNetwork.Tick(true); + myNetwork.NonVisualProcessPacketsMultipleTimes(); + } + NB.UnregisterInvisibleNetwork(); } private void replayToolStripMenuItem_Click(object sender, EventArgs e)