Merge pull request #17291 from Warlaan/master
completed-signal for coroutines with more than one yield
This commit is contained in:
commit
aed2fedd16
2 changed files with 17 additions and 4 deletions
|
@ -1535,15 +1535,21 @@ Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_ar
|
||||||
// then the function did yield again after resuming.
|
// then the function did yield again after resuming.
|
||||||
if (ret.is_ref()) {
|
if (ret.is_ref()) {
|
||||||
GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret);
|
GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret);
|
||||||
if (gdfs && gdfs->function == function)
|
if (gdfs && gdfs->function == function) {
|
||||||
completed = false;
|
completed = false;
|
||||||
|
gdfs->previous_state = Ref<GDScriptFunctionState>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function = NULL; //cleaned up;
|
function = NULL; //cleaned up;
|
||||||
state.result = Variant();
|
state.result = Variant();
|
||||||
|
|
||||||
if (completed) {
|
if (completed) {
|
||||||
emit_signal("completed", ret);
|
GDScriptFunctionState *state = this;
|
||||||
|
while (state != NULL) {
|
||||||
|
state->emit_signal("completed", ret);
|
||||||
|
state = *(state->previous_state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1591,15 +1597,21 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) {
|
||||||
// then the function did yield again after resuming.
|
// then the function did yield again after resuming.
|
||||||
if (ret.is_ref()) {
|
if (ret.is_ref()) {
|
||||||
GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret);
|
GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret);
|
||||||
if (gdfs && gdfs->function == function)
|
if (gdfs && gdfs->function == function) {
|
||||||
completed = false;
|
completed = false;
|
||||||
|
gdfs->previous_state = Ref<GDScriptFunctionState>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function = NULL; //cleaned up;
|
function = NULL; //cleaned up;
|
||||||
state.result = Variant();
|
state.result = Variant();
|
||||||
|
|
||||||
if (completed) {
|
if (completed) {
|
||||||
emit_signal("completed", ret);
|
GDScriptFunctionState *state = this;
|
||||||
|
while (state != NULL) {
|
||||||
|
state->emit_signal("completed", ret);
|
||||||
|
state = *(state->previous_state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -234,6 +234,7 @@ class GDScriptFunctionState : public Reference {
|
||||||
GDScriptFunction *function;
|
GDScriptFunction *function;
|
||||||
GDScriptFunction::CallState state;
|
GDScriptFunction::CallState state;
|
||||||
Variant _signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
|
Variant _signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
|
||||||
|
Ref<GDScriptFunctionState> previous_state;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
Loading…
Reference in a new issue