Skip to content
Snippets Groups Projects
Commit 82fa06b4 authored by MaZiFAU's avatar MaZiFAU
Browse files

Toggle for prefatching from Server/Json; Fact naming; updated scrolls.json;...

Toggle for prefatching from Server/Json; Fact naming; updated scrolls.json; Fact pushout now blocking;
parent bb945319
No related branches found
No related tags found
No related merge requests found
Pipeline #6000 passed
...@@ -51,12 +51,18 @@ public static GlobalBehaviour Instance ...@@ -51,12 +51,18 @@ public static GlobalBehaviour Instance
[SerializeField] private float _GadgetPhysicalDistance; [SerializeField] private float _GadgetPhysicalDistance;
#endregion #endregion
//TODO: move?
/// <summary> Default Setting for all JSONConvert operations </summary>
public static JsonSerializerSettings JsonConvertDefaultSettings = new() { MaxDepth = 256 };
private void Awake() private void Awake()
{ {
Instance = this; Instance = this;
if (Instance != this) if (Instance != this)
return; return;
JsonConvert.DefaultSettings = () => JsonConvertDefaultSettings;
DontDestroyOnLoad(this); DontDestroyOnLoad(this);
GetScrollsfromServer(); GetScrollsfromServer();
GetContextfromServer(); GetContextfromServer();
...@@ -67,6 +73,7 @@ private void Awake() ...@@ -67,6 +73,7 @@ private void Awake()
public int tryScrollListTimes = 2; public int tryScrollListTimes = 2;
static public List<REST_JSON_API.Scroll> AvailableScrolls; static public List<REST_JSON_API.Scroll> AvailableScrolls;
public static IEnumerator InitiateScrolls = IEnumeratorExtensions.yield_break; public static IEnumerator InitiateScrolls = IEnumeratorExtensions.yield_break;
public static bool AttemptScrollList = true; //false;
private void GetScrollsfromServer() private void GetScrollsfromServer()
{ {
...@@ -81,6 +88,9 @@ IEnumerator _GetScrollsfromServer() ...@@ -81,6 +88,9 @@ IEnumerator _GetScrollsfromServer()
System.DateTime requestTime = System.DateTime.UtcNow; System.DateTime requestTime = System.DateTime.UtcNow;
UnityWebRequest request = null; UnityWebRequest request = null;
if (AttemptScrollList)
{
for (int i = 0; i < this.tryScrollListTimes; i++) for (int i = 0; i < this.tryScrollListTimes; i++)
{ {
request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list"); request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list");
...@@ -99,11 +109,14 @@ IEnumerator _GetScrollsfromServer() ...@@ -99,11 +109,14 @@ IEnumerator _GetScrollsfromServer()
} }
while (request.result == UnityWebRequest.Result.InProgress) while (request.result == UnityWebRequest.Result.InProgress)
yield return null; yield return null;
}
System.DateTime answerTime = System.DateTime.UtcNow; System.DateTime answerTime = System.DateTime.UtcNow;
string jsonString = null; string jsonString = null;
if (AttemptScrollList)
{
if (request.result == UnityWebRequest.Result.ConnectionError if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError) || request.result == UnityWebRequest.Result.ProtocolError)
{ {
...@@ -117,6 +130,7 @@ IEnumerator _GetScrollsfromServer() ...@@ -117,6 +130,7 @@ IEnumerator _GetScrollsfromServer()
yield return null; yield return null;
jsonString = request.downloadHandler.text; jsonString = request.downloadHandler.text;
} }
}
if (string.IsNullOrEmpty(jsonString) if (string.IsNullOrEmpty(jsonString)
|| jsonString.Equals("[]")) || jsonString.Equals("[]"))
...@@ -128,6 +142,7 @@ IEnumerator _GetScrollsfromServer() ...@@ -128,6 +142,7 @@ IEnumerator _GetScrollsfromServer()
System.DateTime parseTime = System.DateTime.UtcNow; System.DateTime parseTime = System.DateTime.UtcNow;
List<Scroll> _AvailableScrolls = JsonConvert.DeserializeObject<List<Scroll>>(jsonString); List<Scroll> _AvailableScrolls = JsonConvert.DeserializeObject<List<Scroll>>(jsonString);
System.DateTime processTime = System.DateTime.UtcNow;
AvailableScrolls = new(); AvailableScrolls = new();
foreach (Scroll scroll in _AvailableScrolls) foreach (Scroll scroll in _AvailableScrolls)
AvailableScrolls.Add(IJSONsavable<Scroll>.postprocess(scroll)); AvailableScrolls.Add(IJSONsavable<Scroll>.postprocess(scroll));
...@@ -137,7 +152,8 @@ IEnumerator _GetScrollsfromServer() ...@@ -137,7 +152,8 @@ IEnumerator _GetScrollsfromServer()
$"Summ\t{(System.DateTime.UtcNow - requestTime).TotalMilliseconds}ms\n" + $"Summ\t{(System.DateTime.UtcNow - requestTime).TotalMilliseconds}ms\n" +
$"Server\t{(answerTime - requestTime).TotalMilliseconds}ms\n" + $"Server\t{(answerTime - requestTime).TotalMilliseconds}ms\n" +
$"Download\t{(parseTime - answerTime).TotalMilliseconds}ms\n" + $"Download\t{(parseTime - answerTime).TotalMilliseconds}ms\n" +
$"Parsing\t{(System.DateTime.UtcNow - parseTime).TotalMilliseconds}ms"); $"JSONParsing\t{(processTime - parseTime).TotalMilliseconds}ms\n" +
$"Processing\t{(System.DateTime.UtcNow - processTime).TotalMilliseconds}ms");
yield break; yield break;
} }
...@@ -146,6 +162,7 @@ IEnumerator _GetScrollsfromServer() ...@@ -146,6 +162,7 @@ IEnumerator _GetScrollsfromServer()
public static FactRecorder Context = new(); public static FactRecorder Context = new();
public static IEnumerator InitiateContext = IEnumeratorExtensions.yield_break; public static IEnumerator InitiateContext = IEnumeratorExtensions.yield_break;
public static bool ContextLoaded = false; public static bool ContextLoaded = false;
public static bool AttemptContextLoad = true; //false;
private void GetContextfromServer() private void GetContextfromServer()
{ {
...@@ -157,6 +174,9 @@ IEnumerator _GetContextfromServer() ...@@ -157,6 +174,9 @@ IEnumerator _GetContextfromServer()
System.DateTime requestTime = System.DateTime.UtcNow; System.DateTime requestTime = System.DateTime.UtcNow;
UnityWebRequest request = null; UnityWebRequest request = null;
if (AttemptContextLoad)
{
for (int i = 0; i < this.tryScrollListTimes; i++) for (int i = 0; i < this.tryScrollListTimes; i++)
{ {
request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/fact/list"); request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/fact/list");
...@@ -175,11 +195,14 @@ IEnumerator _GetContextfromServer() ...@@ -175,11 +195,14 @@ IEnumerator _GetContextfromServer()
} }
while (request.result == UnityWebRequest.Result.InProgress) while (request.result == UnityWebRequest.Result.InProgress)
yield return null; yield return null;
}
System.DateTime answerTime = System.DateTime.UtcNow; System.DateTime answerTime = System.DateTime.UtcNow;
string jsonString = null; string jsonString = null;
if (AttemptContextLoad)
{
if (request.result == UnityWebRequest.Result.ConnectionError if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError) || request.result == UnityWebRequest.Result.ProtocolError)
{ {
...@@ -193,6 +216,7 @@ IEnumerator _GetContextfromServer() ...@@ -193,6 +216,7 @@ IEnumerator _GetContextfromServer()
yield return null; yield return null;
jsonString = request.downloadHandler.text; jsonString = request.downloadHandler.text;
} }
}
if (string.IsNullOrEmpty(jsonString) if (string.IsNullOrEmpty(jsonString)
|| jsonString.Equals("[]")) || jsonString.Equals("[]"))
...@@ -205,8 +229,8 @@ IEnumerator _GetContextfromServer() ...@@ -205,8 +229,8 @@ IEnumerator _GetContextfromServer()
MMTFact[] context_facts = JsonConvert.DeserializeObject<MMTFact[]>(jsonString); MMTFact[] context_facts = JsonConvert.DeserializeObject<MMTFact[]>(jsonString);
System.DateTime parseEnd = System.DateTime.UtcNow; System.DateTime parseEnd = System.DateTime.UtcNow;
System.DateTime justParseTime = default; System.TimeSpan justParseTime = default;
System.DateTime justAddinTime = default; System.TimeSpan justAddinTime = default;
bool samestep = false; bool samestep = false;
foreach (MMTFact fact in context_facts) foreach (MMTFact fact in context_facts)
...@@ -216,9 +240,9 @@ IEnumerator _GetContextfromServer() ...@@ -216,9 +240,9 @@ IEnumerator _GetContextfromServer()
|| fact.GetDefines() == null) // Scala rule? || fact.GetDefines() == null) // Scala rule?
continue; continue;
System.DateTime parse_time = System.DateTime.Now; System.DateTime parse_time = System.DateTime.UtcNow;
List<Fact> new_list = Fact.MMTFactory(fact); // old but IEnumerator: yield return ParsingDictionary.parseFactDictionary[fact.getType()](new_list, fact); List<Fact> new_list = Fact.MMTFactory(fact); // old but IEnumerator: yield return ParsingDictionary.parseFactDictionary[fact.getType()](new_list, fact);
justParseTime += System.DateTime.Now - parse_time; justParseTime += System.DateTime.UtcNow - parse_time;
if (new_list.Count == 0) if (new_list.Count == 0)
{ {
...@@ -226,16 +250,16 @@ IEnumerator _GetContextfromServer() ...@@ -226,16 +250,16 @@ IEnumerator _GetContextfromServer()
continue; continue;
} }
System.DateTime addin_time = System.DateTime.Now; System.DateTime addin_time = System.DateTime.UtcNow;
foreach (Fact new_fact in new_list) foreach (Fact new_fact in new_list)
{ {
Context.Add(new_fact, out bool exists, samestep, null, null, true, true); Context.Add(new_fact, out bool exists, samestep, null, null, true, true);
if (!exists) if (!exists)
samestep = true; samestep = true;
yield return null; //yield return null;
} }
justAddinTime += System.DateTime.Now - addin_time; justAddinTime += System.DateTime.UtcNow - addin_time;
} }
Debug.Log( Debug.Log(
...@@ -243,9 +267,10 @@ IEnumerator _GetContextfromServer() ...@@ -243,9 +267,10 @@ IEnumerator _GetContextfromServer()
$"Summ\t{(System.DateTime.UtcNow - requestTime).TotalMilliseconds}ms\n" + $"Summ\t{(System.DateTime.UtcNow - requestTime).TotalMilliseconds}ms\n" +
$"Server\t{(answerTime - requestTime).TotalMilliseconds}ms\n" + $"Server\t{(answerTime - requestTime).TotalMilliseconds}ms\n" +
$"Download\t{(parseTime - answerTime).TotalMilliseconds}ms\n" + $"Download\t{(parseTime - answerTime).TotalMilliseconds}ms\n" +
$"Parsing\t{(parseEnd - parseTime).TotalMilliseconds}ms\n" + $"JSONParsing\t{(parseEnd - parseTime).TotalMilliseconds}ms\n" +
$"FactParsing\t{justParseTime.Millisecond}ms\n" + $"FactCreation\t{(System.DateTime.UtcNow - parseEnd).TotalMilliseconds}ms\n" +
$"FactAdding\t{justAddinTime.Millisecond}ms\n" + $"FactJustParsing\t{justParseTime.Milliseconds}ms\n" +
$"FactJustAdding\t{justAddinTime.Milliseconds}ms\n" +
""); "");
ContextLoaded = true; ContextLoaded = true;
......
...@@ -438,7 +438,19 @@ protected virtual string generateLabel(FactRecorder name_space) ...@@ -438,7 +438,19 @@ protected virtual string generateLabel(FactRecorder name_space)
name_space.UnusedLabelIds.Remove(LabelId); name_space.UnusedLabelIds.Remove(LabelId);
} }
return ((char)(64 + LabelId)).ToString(); int LabelIdMod, LabelIdRes = LabelId;
string label = "";
while (true)
{
LabelIdMod = LabelIdRes % 26;
label = (char)(65 + LabelIdMod) + label;
if (LabelIdRes < 26)
break;
LabelIdRes /= 26;
}
return "(" + label + ")";
} }
/// <summary> /// <summary>
......
...@@ -398,12 +398,14 @@ private void Init(string[] pid_corners) ...@@ -398,12 +398,14 @@ private void Init(string[] pid_corners)
throw new ArgumentException("All Points must lie on the same Plane!"); throw new ArgumentException("All Points must lie on the same Plane!");
} }
/// \copydoc Fact.parseFact(ScrollFact)
public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact) public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
protected override string generateLabel(FactRecorder name_space)
=> "[" + String.Join(",", Points.Select(p => p.GetLabel(name_space)).ToArray()) + "]";
public override MMTFact MakeMMTDeclaration() public override MMTFact MakeMMTDeclaration()
{ {
SOMDoc tp = new OMS(MMTConstants.Wall); SOMDoc tp = new OMS(MMTConstants.Wall);
...@@ -506,12 +508,14 @@ private void Init(Vector3[] Verticies) ...@@ -506,12 +508,14 @@ private void Init(Vector3[] Verticies)
Normal = Vector3.Cross(Tangents, AltTangents).normalized; Normal = Vector3.Cross(Tangents, AltTangents).normalized;
} }
/// \copydoc Fact.parseFact(ScrollFact)
public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact) public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
//protected override string generateLabel(FactRecorder name_space)
// => "[" + String.Join(",", Points.Select(p => p.GetLabel(name_space)).ToArray()) + "]";
public override MMTFact MakeMMTDeclaration() public override MMTFact MakeMMTDeclaration()
=> new MMTGeneralFact(_LastLabel, GetMMTType(), Defines()); => new MMTGeneralFact(_LastLabel, GetMMTType(), Defines());
......
...@@ -146,6 +146,9 @@ public bool SetNextEmptyTo(FactObjectUI activator) ...@@ -146,6 +146,9 @@ public bool SetNextEmptyTo(FactObjectUI activator)
public void MagicButtonTrigger() public void MagicButtonTrigger()
{ {
if (ActiveScroll == null)
return;
StartCoroutine(_MagicButton()); StartCoroutine(_MagicButton());
IEnumerator _MagicButton() IEnumerator _MagicButton()
...@@ -170,7 +173,9 @@ IEnumerator _MagicButton() ...@@ -170,7 +173,9 @@ IEnumerator _MagicButton()
if (VerboseURI) if (VerboseURI)
Debug.Log("Magic answers:\n" + currentMmtAnswer); Debug.Log("Magic answers:\n" + currentMmtAnswer);
System.DateTime serializeTime = System.DateTime.UtcNow;
ScrollApplicationInfo pushout = JsonConvert.DeserializeObject<ScrollApplicationInfo>(currentMmtAnswer); ScrollApplicationInfo pushout = JsonConvert.DeserializeObject<ScrollApplicationInfo>(currentMmtAnswer);
Debug.LogFormat($"Answerd serialized in : {(System.DateTime.UtcNow - serializeTime).TotalMilliseconds}ms");
if (pushout.acquiredFacts.Count == 0 if (pushout.acquiredFacts.Count == 0
|| pushout.errors.Length > 0) || pushout.errors.Length > 0)
...@@ -216,10 +221,9 @@ IEnumerator __GeneratePushoutFacts(List<MMTFact> pushoutFacts) ...@@ -216,10 +221,9 @@ IEnumerator __GeneratePushoutFacts(List<MMTFact> pushoutFacts)
// AnimateExistingFactEvent.Invoke(_new, FactWrapper.FactMaterials.Hint); // Automaticly done in FactRecorder // AnimateExistingFactEvent.Invoke(_new, FactWrapper.FactMaterials.Hint); // Automaticly done in FactRecorder
old_to_new.Add(new_fact.Id, added.Id); old_to_new.Add(new_fact.Id, added.Id);
} }
} }
yield return null; //yield return null;
} }
Debug.Log($"Facts parsed within {(System.DateTime.UtcNow - parseTime).TotalMilliseconds}ms"); Debug.Log($"Facts parsed within {(System.DateTime.UtcNow - parseTime).TotalMilliseconds}ms");
...@@ -229,6 +233,8 @@ IEnumerator __GeneratePushoutFacts(List<MMTFact> pushoutFacts) ...@@ -229,6 +233,8 @@ IEnumerator __GeneratePushoutFacts(List<MMTFact> pushoutFacts)
public void NewAssignmentTrigger() public void NewAssignmentTrigger()
{ {
//return; //if you read this, delete this line!
if (ActiveScroll?.ScrollReference == null if (ActiveScroll?.ScrollReference == null
|| NoDynamicScroll.Contains(ActiveScroll.ScrollReference)) || NoDynamicScroll.Contains(ActiveScroll.ScrollReference))
return; return;
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment