Skip to content

Commit 9d4f4d7

Browse files
committed
allow non-blocking api call to run(0) (run forever). this call now returns immediately.
1 parent f45c0c1 commit 9d4f4d7

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
lines changed

Assets/Scripts/Api/ApiManager.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ private enum MessageType
5555
[NonSerialized]
5656
public int FrameLimit;
5757

58+
[NonSerialized]
59+
public bool API_Notified = true;
60+
5861
[NonSerialized]
5962
public float TimeScale;
6063

@@ -591,11 +594,17 @@ void FixedUpdate()
591594
{
592595
if (FrameLimit != 0 && CurrentFrame >= FrameLimit)
593596
{
597+
// pause and notify API
594598
SimulatorManager.SetTimeScale(0.0f);
595599
SendResult();
596600
}
597601
else
598602
{
603+
if (FrameLimit == 0 && !API_Notified)
604+
{
605+
SendResult();
606+
API_Notified = true;
607+
}
599608
CurrentTime += Time.fixedDeltaTime;
600609
CurrentFrame += 1;
601610

Assets/Scripts/Api/Commands/Run.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@ public void Execute(JSONNode args)
1919
var api = ApiManager.Instance;
2020
var sim = SimulatorManager.Instance;
2121

22-
var timeScale = args["time_scale"];
23-
if (timeScale == null || timeScale.IsNull)
22+
var timeLimit = args["time_limit"].AsFloat;
23+
if (timeLimit != 0)
2424
{
25-
api.TimeScale = 1f;
25+
var frameLimit = (int)(timeLimit / Time.fixedDeltaTime);
26+
api.FrameLimit = api.CurrentFrame + frameLimit;
2627
}
2728
else
2829
{
29-
api.TimeScale = timeScale.AsFloat;
30+
api.FrameLimit = 0;
31+
api.API_Notified = false;
3032
}
3133

32-
SimulatorManager.SetTimeScale(api.TimeScale);
33-
34-
var timeLimit = args["time_limit"].AsFloat;
35-
if (timeLimit != 0)
34+
var timeScale = args["time_scale"];
35+
if (timeScale == null || timeScale.IsNull)
3636
{
37-
var frameLimit = (int)(timeLimit / Time.fixedDeltaTime);
38-
api.FrameLimit = api.CurrentFrame + frameLimit;
37+
api.TimeScale = 1f;
3938
}
4039
else
4140
{
42-
api.FrameLimit = 0;
41+
api.TimeScale = timeScale.AsFloat;
4342
}
43+
SimulatorManager.SetTimeScale(api.TimeScale);
4444

4545
sim.AnalysisManager.AnalysisInit();
4646
}

Packages/manifest.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
"com.unity.burst": "1.6.6",
66
"com.unity.editorcoroutines": "1.0.0",
77
"com.unity.formats.fbx": "4.2.1",
8-
"com.unity.ide.rider": "3.0.24",
9-
"com.unity.ide.visualstudio": "2.0.18",
8+
"com.unity.ide.rider": "3.0.27",
9+
"com.unity.ide.visualstudio": "2.0.22",
1010
"com.unity.ide.vscode": "1.2.5",
1111
"com.unity.inputsystem": "1.5.1",
1212
"com.unity.mathematics": "1.2.6",
1313
"com.unity.postprocessing": "3.2.2",
1414
"com.unity.render-pipelines.high-definition": "10.10.1",
1515
"com.unity.test-framework": "1.1.33",
1616
"com.unity.textmeshpro": "3.0.6",
17-
"com.unity.timeline": "1.7.5",
18-
"com.unity.toolchain.linux-x86_64": "2.0.5",
19-
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.5",
17+
"com.unity.timeline": "1.7.6",
18+
"com.unity.toolchain.linux-x86_64": "2.0.6",
19+
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.6",
2020
"com.unity.ugui": "1.0.0",
2121
"com.unity.visualeffectgraph": "10.10.1",
2222
"com.unity.modules.ai": "1.0.0",

Packages/packages-lock.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"url": "https://packages.unity.com"
6060
},
6161
"com.unity.ide.rider": {
62-
"version": "3.0.24",
62+
"version": "3.0.27",
6363
"depth": 0,
6464
"source": "registry",
6565
"dependencies": {
@@ -68,7 +68,7 @@
6868
"url": "https://packages.unity.com"
6969
},
7070
"com.unity.ide.visualstudio": {
71-
"version": "2.0.18",
71+
"version": "2.0.22",
7272
"depth": 0,
7373
"source": "registry",
7474
"dependencies": {
@@ -157,18 +157,18 @@
157157
"url": "https://packages.unity.com"
158158
},
159159
"com.unity.sysroot": {
160-
"version": "2.0.6",
160+
"version": "2.0.7",
161161
"depth": 1,
162162
"source": "registry",
163163
"dependencies": {},
164164
"url": "https://packages.unity.com"
165165
},
166166
"com.unity.sysroot.linux-x86_64": {
167-
"version": "2.0.5",
167+
"version": "2.0.6",
168168
"depth": 1,
169169
"source": "registry",
170170
"dependencies": {
171-
"com.unity.sysroot": "2.0.6"
171+
"com.unity.sysroot": "2.0.7"
172172
},
173173
"url": "https://packages.unity.com"
174174
},
@@ -193,7 +193,7 @@
193193
"url": "https://packages.unity.com"
194194
},
195195
"com.unity.timeline": {
196-
"version": "1.7.5",
196+
"version": "1.7.6",
197197
"depth": 0,
198198
"source": "registry",
199199
"dependencies": {
@@ -205,22 +205,22 @@
205205
"url": "https://packages.unity.com"
206206
},
207207
"com.unity.toolchain.linux-x86_64": {
208-
"version": "2.0.5",
208+
"version": "2.0.6",
209209
"depth": 0,
210210
"source": "registry",
211211
"dependencies": {
212-
"com.unity.sysroot": "2.0.6",
213-
"com.unity.sysroot.linux-x86_64": "2.0.5"
212+
"com.unity.sysroot": "2.0.7",
213+
"com.unity.sysroot.linux-x86_64": "2.0.6"
214214
},
215215
"url": "https://packages.unity.com"
216216
},
217217
"com.unity.toolchain.win-x86_64-linux-x86_64": {
218-
"version": "2.0.5",
218+
"version": "2.0.6",
219219
"depth": 0,
220220
"source": "registry",
221221
"dependencies": {
222-
"com.unity.sysroot": "2.0.6",
223-
"com.unity.sysroot.linux-x86_64": "2.0.5"
222+
"com.unity.sysroot": "2.0.7",
223+
"com.unity.sysroot.linux-x86_64": "2.0.6"
224224
},
225225
"url": "https://packages.unity.com"
226226
},

0 commit comments

Comments
 (0)