- // move a running action up in the stack
- if (o<RS_MAXACTIONS && currentActions[o]!=NULL) {
- if (n!=o) {
- currentActions[n] = currentActions[o];
- resume = n;
- currentActions[o] = NULL;
- } else {
- if (o<RS_MAXACTIONS) {
- o++;
- }
- }
- actionIndex = n;
- if (n<RS_MAXACTIONS-1) {
- n++;
- }
- }
- } while (o<RS_MAXACTIONS);
-
- debugActions();
-
- // Resume last used action:
- if (doResume) {
- if (currentActions[resume]!=NULL &&
- !currentActions[resume]->isFinished()) {
-
- currentActions[resume]->resume();
- currentActions[resume]->showOptions();
- } else {
- if (defaultAction!=NULL) {
- defaultAction->resume();
- defaultAction->showOptions();
- }
- }
- }
- RS_DEBUG->print("RS_EventHandler::cleanUp: OK");
+ do
+ {
+ // search first used action (o)
+ while (currentActions[o] == NULL && o < RS_MAXACTIONS)
+ o++;
+
+ // delete action if it is finished
+ if (o < RS_MAXACTIONS && currentActions[o] != NULL
+ && currentActions[o]->isFinished())
+ {
+ delete currentActions[o];
+ currentActions[o] = NULL;
+ doResume = true;
+ }
+
+ // move a running action up in the stack
+ if (o < RS_MAXACTIONS && currentActions[o] != NULL)
+ {
+ if (n != o)
+ {
+ currentActions[n] = currentActions[o];
+ resume = n;
+ currentActions[o] = NULL;
+ }
+ else
+ {
+ if (o < RS_MAXACTIONS)
+ o++;
+ }
+
+ actionIndex = n;
+
+ if (n < RS_MAXACTIONS - 1)
+ n++;
+ }
+ }
+ while (o < RS_MAXACTIONS);
+
+ debugActions();
+
+ // Resume last used action:
+ if (doResume)
+ {
+ if (currentActions[resume] && !currentActions[resume]->isFinished())
+ {
+ currentActions[resume]->resume();
+ currentActions[resume]->showOptions();
+ }
+ else
+ {
+ if (defaultAction)
+ {
+ defaultAction->resume();
+ defaultAction->showOptions();
+ }
+ }
+ }
+
+ RS_DEBUG->print("RS_EventHandler::cleanUp: OK");