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
[SerializeField] private float _GadgetPhysicalDistance;
#endregion
//TODO: move?
/// <summary> Default Setting for all JSONConvert operations </summary>
public static JsonSerializerSettings JsonConvertDefaultSettings = new() { MaxDepth = 256 };
private void Awake()
{
Instance = this;
if (Instance != this)
return;
JsonConvert.DefaultSettings = () => JsonConvertDefaultSettings;
DontDestroyOnLoad(this);
GetScrollsfromServer();
GetContextfromServer();
......@@ -67,6 +73,7 @@ private void Awake()
public int tryScrollListTimes = 2;
static public List<REST_JSON_API.Scroll> AvailableScrolls;
public static IEnumerator InitiateScrolls = IEnumeratorExtensions.yield_break;
public static bool AttemptScrollList = true; //false;
private void GetScrollsfromServer()
{
......@@ -81,41 +88,48 @@ IEnumerator _GetScrollsfromServer()
System.DateTime requestTime = System.DateTime.UtcNow;
UnityWebRequest request = null;
for (int i = 0; i < this.tryScrollListTimes; i++)
{
request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list");
request.method = UnityWebRequest.kHttpVerbGET;
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
if (AttemptScrollList)
{
for (int i = 0; i < this.tryScrollListTimes; i++)
{
Debug.LogWarning(request.error);
Debug.Log("GET Scroll/list failed. Attempt: " + (i + 1).ToString());
request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list");
request.method = UnityWebRequest.kHttpVerbGET;
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogWarning(request.error);
Debug.Log("GET Scroll/list failed. Attempt: " + (i + 1).ToString());
}
else
break;
}
else
break;
while (request.result == UnityWebRequest.Result.InProgress)
yield return null;
}
while (request.result == UnityWebRequest.Result.InProgress)
yield return null;
System.DateTime answerTime = System.DateTime.UtcNow;
string jsonString = null;
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogWarning(request.error);
}
else
if (AttemptScrollList)
{
CommunicationEvents.ServerRunning = true;
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogWarning(request.error);
}
else
{
CommunicationEvents.ServerRunning = true;
while (!request.downloadHandler.isDone)
yield return null;
jsonString = request.downloadHandler.text;
while (!request.downloadHandler.isDone)
yield return null;
jsonString = request.downloadHandler.text;
}
}
if (string.IsNullOrEmpty(jsonString)
......@@ -127,7 +141,8 @@ IEnumerator _GetScrollsfromServer()
System.DateTime parseTime = System.DateTime.UtcNow;
List<Scroll> _AvailableScrolls = JsonConvert.DeserializeObject<List<Scroll>>(jsonString);
System.DateTime processTime = System.DateTime.UtcNow;
AvailableScrolls = new();
foreach (Scroll scroll in _AvailableScrolls)
AvailableScrolls.Add(IJSONsavable<Scroll>.postprocess(scroll));
......@@ -137,7 +152,8 @@ IEnumerator _GetScrollsfromServer()
$"Summ\t{(System.DateTime.UtcNow - requestTime).TotalMilliseconds}ms\n" +
$"Server\t{(answerTime - requestTime).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;
}
......@@ -146,6 +162,7 @@ IEnumerator _GetScrollsfromServer()
public static FactRecorder Context = new();
public static IEnumerator InitiateContext = IEnumeratorExtensions.yield_break;
public static bool ContextLoaded = false;
public static bool AttemptContextLoad = true; //false;
private void GetContextfromServer()
{
......@@ -157,41 +174,48 @@ IEnumerator _GetContextfromServer()
System.DateTime requestTime = System.DateTime.UtcNow;
UnityWebRequest request = null;
for (int i = 0; i < this.tryScrollListTimes; i++)
{
request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/fact/list");
request.method = UnityWebRequest.kHttpVerbGET;
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
if (AttemptContextLoad)
{
for (int i = 0; i < this.tryScrollListTimes; i++)
{
Debug.LogWarning(request.error);
Debug.Log("GET /fact/list failed. Attempt: " + (i + 1).ToString());
request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/fact/list");
request.method = UnityWebRequest.kHttpVerbGET;
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogWarning(request.error);
Debug.Log("GET /fact/list failed. Attempt: " + (i + 1).ToString());
}
else
break;
}
else
break;
while (request.result == UnityWebRequest.Result.InProgress)
yield return null;
}
while (request.result == UnityWebRequest.Result.InProgress)
yield return null;
System.DateTime answerTime = System.DateTime.UtcNow;
string jsonString = null;
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogWarning(request.error);
}
else
if (AttemptContextLoad)
{
CommunicationEvents.ServerRunning = true;
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogWarning(request.error);
}
else
{
CommunicationEvents.ServerRunning = true;
while (!request.downloadHandler.isDone)
yield return null;
jsonString = request.downloadHandler.text;
while (!request.downloadHandler.isDone)
yield return null;
jsonString = request.downloadHandler.text;
}
}
if (string.IsNullOrEmpty(jsonString)
......@@ -205,8 +229,8 @@ IEnumerator _GetContextfromServer()
MMTFact[] context_facts = JsonConvert.DeserializeObject<MMTFact[]>(jsonString);
System.DateTime parseEnd = System.DateTime.UtcNow;
System.DateTime justParseTime = default;
System.DateTime justAddinTime = default;
System.TimeSpan justParseTime = default;
System.TimeSpan justAddinTime = default;
bool samestep = false;
foreach (MMTFact fact in context_facts)
......@@ -216,9 +240,9 @@ IEnumerator _GetContextfromServer()
|| fact.GetDefines() == null) // Scala rule?
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);
justParseTime += System.DateTime.Now - parse_time;
justParseTime += System.DateTime.UtcNow - parse_time;
if (new_list.Count == 0)
{
......@@ -226,16 +250,16 @@ IEnumerator _GetContextfromServer()
continue;
}
System.DateTime addin_time = System.DateTime.Now;
System.DateTime addin_time = System.DateTime.UtcNow;
foreach (Fact new_fact in new_list)
{
Context.Add(new_fact, out bool exists, samestep, null, null, true, true);
if (!exists)
samestep = true;
yield return null;
//yield return null;
}
justAddinTime += System.DateTime.Now - addin_time;
justAddinTime += System.DateTime.UtcNow - addin_time;
}
Debug.Log(
......@@ -243,9 +267,10 @@ IEnumerator _GetContextfromServer()
$"Summ\t{(System.DateTime.UtcNow - requestTime).TotalMilliseconds}ms\n" +
$"Server\t{(answerTime - requestTime).TotalMilliseconds}ms\n" +
$"Download\t{(parseTime - answerTime).TotalMilliseconds}ms\n" +
$"Parsing\t{(parseEnd - parseTime).TotalMilliseconds}ms\n" +
$"FactParsing\t{justParseTime.Millisecond}ms\n" +
$"FactAdding\t{justAddinTime.Millisecond}ms\n" +
$"JSONParsing\t{(parseEnd - parseTime).TotalMilliseconds}ms\n" +
$"FactCreation\t{(System.DateTime.UtcNow - parseEnd).TotalMilliseconds}ms\n" +
$"FactJustParsing\t{justParseTime.Milliseconds}ms\n" +
$"FactJustAdding\t{justAddinTime.Milliseconds}ms\n" +
"");
ContextLoaded = true;
......
......@@ -438,7 +438,19 @@ protected virtual string generateLabel(FactRecorder name_space)
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>
......@@ -648,7 +660,7 @@ public static List<Fact> MMTFactory(MMTFact ingredient)
if (ret.Count != 0)
return ret;
}
catch(Exception ex)
catch (Exception ex)
{
Debug.LogException(ex);
Debug.Log($"Could not statically parse {nameof(MMTFact)} {nameof(ingredient)}. Using dynamic Fallback...");
......@@ -794,7 +806,7 @@ public override MMTFact MakeMMTDeclaration()
{
throw new NotImplementedException();
}
public override SOMDoc Defines()
{
throw new NotImplementedException();
......
......@@ -398,12 +398,14 @@ private void Init(string[] pid_corners)
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)
{
throw new NotImplementedException();
}
protected override string generateLabel(FactRecorder name_space)
=> "[" + String.Join(",", Points.Select(p => p.GetLabel(name_space)).ToArray()) + "]";
public override MMTFact MakeMMTDeclaration()
{
SOMDoc tp = new OMS(MMTConstants.Wall);
......@@ -506,12 +508,14 @@ private void Init(Vector3[] Verticies)
Normal = Vector3.Cross(Tangents, AltTangents).normalized;
}
/// \copydoc Fact.parseFact(ScrollFact)
public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
{
throw new NotImplementedException();
}
//protected override string generateLabel(FactRecorder name_space)
// => "[" + String.Join(",", Points.Select(p => p.GetLabel(name_space)).ToArray()) + "]";
public override MMTFact MakeMMTDeclaration()
=> new MMTGeneralFact(_LastLabel, GetMMTType(), Defines());
......
......@@ -146,6 +146,9 @@ public bool SetNextEmptyTo(FactObjectUI activator)
public void MagicButtonTrigger()
{
if (ActiveScroll == null)
return;
StartCoroutine(_MagicButton());
IEnumerator _MagicButton()
......@@ -170,7 +173,9 @@ IEnumerator _MagicButton()
if (VerboseURI)
Debug.Log("Magic answers:\n" + currentMmtAnswer);
System.DateTime serializeTime = System.DateTime.UtcNow;
ScrollApplicationInfo pushout = JsonConvert.DeserializeObject<ScrollApplicationInfo>(currentMmtAnswer);
Debug.LogFormat($"Answerd serialized in : {(System.DateTime.UtcNow - serializeTime).TotalMilliseconds}ms");
if (pushout.acquiredFacts.Count == 0
|| pushout.errors.Length > 0)
......@@ -216,10 +221,9 @@ IEnumerator __GeneratePushoutFacts(List<MMTFact> pushoutFacts)
// AnimateExistingFactEvent.Invoke(_new, FactWrapper.FactMaterials.Hint); // Automaticly done in FactRecorder
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");
......@@ -229,6 +233,8 @@ IEnumerator __GeneratePushoutFacts(List<MMTFact> pushoutFacts)
public void NewAssignmentTrigger()
{
//return; //if you read this, delete this line!
if (ActiveScroll?.ScrollReference == null
|| NoDynamicScroll.Contains(ActiveScroll.ScrollReference))
return;
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment