-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pause and resume #30
base: master
Are you sure you want to change the base?
Pause and resume #30
Changes from all commits
419c6ef
4e30598
8cae75b
e6a7674
ff15f4d
c00c3d2
b9cb9b7
47f81b8
3523ae5
84448e2
628397b
7abf31e
0ebe056
83ba8a2
c3567de
cd2af20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace NPBehave | ||
{ | ||
public class MockTask : Task | ||
{ | ||
private bool suceedsOnExplicitStop; | ||
|
||
public MockTask(bool suceedsOnExplicitStop) : base("MockTask") | ||
{ | ||
this.suceedsOnExplicitStop = suceedsOnExplicitStop; | ||
} | ||
|
||
protected override void DoStop() | ||
{ | ||
this.Stopped(suceedsOnExplicitStop); | ||
} | ||
|
||
public void Finish(bool success) | ||
{ | ||
this.Stopped(success); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,35 @@ public Service(System.Action service, Node decoratee) : base("Service", decorate | |
} | ||
|
||
protected override void DoStart() | ||
{ | ||
startService(); | ||
Decoratee.Start(); | ||
} | ||
|
||
override protected void DoStop() | ||
{ | ||
Decoratee.Stop(); | ||
} | ||
|
||
protected override void DoChildStopped(Node child, bool result) | ||
{ | ||
stopService(); | ||
Stopped(result); | ||
} | ||
|
||
public override void Pause() | ||
{ | ||
base.Pause(); | ||
stopService(); | ||
} | ||
|
||
public override void Resume() | ||
{ | ||
startService(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You maybe want to check that the CurrentState is |
||
base.Resume(); | ||
} | ||
|
||
private void startService() | ||
{ | ||
if (this.interval <= 0f) | ||
{ | ||
|
@@ -46,15 +75,9 @@ protected override void DoStart() | |
{ | ||
InvokeServiceMethodWithRandomVariation(); | ||
} | ||
Decoratee.Start(); | ||
} | ||
|
||
override protected void DoStop() | ||
{ | ||
Decoratee.Stop(); | ||
} | ||
|
||
protected override void DoChildStopped(Node child, bool result) | ||
private void stopService() | ||
{ | ||
if (this.interval <= 0f) | ||
{ | ||
|
@@ -68,9 +91,8 @@ protected override void DoChildStopped(Node child, bool result) | |
{ | ||
this.Clock.RemoveTimer(InvokeServiceMethodWithRandomVariation); | ||
} | ||
Stopped(result); | ||
} | ||
|
||
private void InvokeServiceMethodWithRandomVariation() | ||
{ | ||
serviceMethod(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,23 @@ public WaitForCondition(Func<bool> condition, Node decoratee) : base("WaitForCon | |
} | ||
|
||
protected override void DoStart() | ||
{ | ||
addTimerOrStartImmediately(); | ||
} | ||
|
||
public override void Pause() | ||
{ | ||
base.Pause(); | ||
Clock.RemoveTimer(checkCondition); | ||
} | ||
|
||
public override void Resume() | ||
{ | ||
addTimerOrStartImmediately(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might cause it to start the child node even though the |
||
base.Resume(); | ||
} | ||
|
||
private void addTimerOrStartImmediately() | ||
{ | ||
if (!condition.Invoke()) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as for the service, I think it's safer to either call
StartObserving()
before callingbase.Resume()
or to check the Node's current state for being Active when callingStartObserving()
(although I'm still not quite sure what's better tbh)