Robust timeout and null handling in SceneController.

parent 22b7683f
......@@ -20,6 +20,9 @@ public class SceneController : MonoBehaviour
public bool captureVideo = true;
private FFmpegCapture videoCapture;
public int timeoutAfterSeconds = 20;
private int timeToTimeout = 0;
public void Start()
{
if (!SceneManager.GetSceneByName(contextScene).isLoaded)
......@@ -165,6 +168,7 @@ public class SceneController : MonoBehaviour
iTween.MoveTo(participantGO, arguments);
}
timeToTimeout = timeoutAfterSeconds;
yield return WaitForActionsOrTimeout();
}
......@@ -182,31 +186,49 @@ public class SceneController : MonoBehaviour
allDone &= status;
}
if (!allDone)
timeToTimeout -= 1;
if (!allDone && timeToTimeout > 0)
{
yield return new WaitForSeconds(1);
yield return WaitForActionsOrTimeout();
}
else
{
yield return new WaitForSeconds(5);
string videoPath = null;
if (captureVideo)
{
videoPath = videoCapture.StopCapture();
string dir = Directory.GetCurrentDirectory();
videoPath = Path.Combine(dir, videoPath);
}
// TODO: record trajectories of objects etc. and append them
string response = PrepareResponse(videoPath).ToString();
yield return replyToRequest(response);
yield return StopWaiting();
}
}
private IEnumerator StopWaiting()
{
yield return new WaitForSeconds(5);
string videoPath = null;
if (captureVideo)
{
videoPath = videoCapture.StopCapture();
string dir = Directory.GetCurrentDirectory();
videoPath = Path.Combine(dir, videoPath);
}
// TODO: record trajectories of objects etc. and append them
JSONObject errorResponse = new JSONObject();
errorResponse.Add("result", "Error!");
string response = errorResponse.ToString();
try
{
response = PrepareResponse(videoPath).ToString();
} catch (NullReferenceException e) {
Debug.LogWarning(e.ToString());
}
yield return replyToRequest(response);
}
private JSONObject PrepareResponse(string videoPath)
{
JSONObject response = new JSONObject();
response.Add("video_file", videoPath);
if (videoPath != null)
{
response.Add("video_file", videoPath);
}
response.Add("trajectories.log", GetSchemasimLog());
response.Add("context", JSONHandler.instance.GenerateContextJSON());
response.Add("result", "Success!");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment